source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_mercure.ksh @ 615

Last change on this file since 615 was 615, checked in by sdipsl, 12 years ago
  • on SX9 find needs -print to do something
  • Bugfix with a print
  • Property svn:keywords set to Revision Author Date
File size: 45.5 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for Mercure X64
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69
70#D-
71#D-#==================================================
72#D-Program used in libIGCM
73#D-#==================================================
74
75# rsync with path
76typeset -r RSYNC=/usr/bin/rsync
77# RSYNC_opt args to rsync
78typeset -r RSYNC_opt="-va"
79# ie storage filesystem
80typeset -r RHOST=mercure
81
82#====================================================
83# Set environment tools (ferret, nco, cdo)
84#====================================================
85. /home/cont003/p86ipsl/.atlas_env_mercure01_ksh
86
87#====================================================
88# Host specific DIRECTORIES
89#====================================================
90
91#====================================================
92#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
93typeset -r R_EXE="${MODIPSL}/bin"
94
95#====================================================
96# For interactive jobs on mercure
97PBS_O_WORKDIR=${PBS_O_WORKDIR:=$(pwd)}
98
99#====================================================
100#- SUBMIT_DIR : submission dir
101typeset SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
102
103#====================================================
104#- ARCHIVE (dedicated to large files)
105typeset -r ARCHIVE=${CCCSTOREDIR}
106
107#- ARCHIVE (dedicated to small/medium files)
108typeset -r STORAGE=${CCCWORKDIR}
109
110#====================================================
111#- IN
112typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
113typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
114
115#====================================================
116#- R_OUT
117typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
118
119#====================================================
120#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
121typeset -r R_FIG=${STORAGE}/IGCM_OUT
122
123#====================================================
124#- R_BUF (ONLY FOR double copy an scratch)
125typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
126
127#====================================================
128#- BIG_DIR : BIG_DIR to store files waiting for rebuild
129typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
130
131#====================================================
132#- OUT_POST
133typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
134
135#====================================================
136#- RUN_DIR_PATH : Temporary working directory (=> TMP)
137#typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${CSCRATCHDIR}/TMPDIR_IGCM/${JOBID}}
138typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${TMPDIR}}
139
140#====================================================
141#- Max number of arguments passed to nco operator or demigration command
142UNIX_MAX_LIMIT=360
143
144#D-#==================================================
145#D-function IGCM_sys_RshMaster
146#D-* Purpose: Just a fake command to wrapp
147#D-           IGCM_card call in post-treatment
148#D-           Ulam do not see brodie filesystem
149#D-           Cesium do not see all mercure filesystem
150#D-           That's why we need this hack.
151#D-* Examples:
152#D-
153function IGCM_sys_RshMaster {
154  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
155  /bin/ksh <<-EOF
156    export libIGCM=${libIGCM}
157    export DEBUG_debug=${DEBUG_debug}
158    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
159    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
160    ${@}
161EOF
162  if [ $? -gt 0 ] ; then
163    echo "IGCM_sys_RshMaster : erreur."
164    IGCM_debug_Exit "IGCM_sys_RshMaster"
165  fi
166  IGCM_debug_PopStack "IGCM_sys_RshMaster"
167}
168
169#D-#==================================================
170#D-function IGCM_sys_RshArchive
171#D-* Purpose: Archive rsh command
172#D-* Examples:
173#D-
174function IGCM_sys_RshArchive {
175  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
176  /bin/ksh <<-EOF
177    ${@}
178EOF
179  if [ $? -gt 0 ] ; then
180    echo "IGCM_sys_RshArchive : erreur."
181    IGCM_debug_Exit "IGCM_sys_RshArchive"
182  fi
183  IGCM_debug_PopStack "IGCM_sys_RshArchive"
184}
185
186#D-#==================================================
187#D-function IGCM_sys_RshPost
188#D-* Purpose: Post-process rsh command
189#D-* Examples:
190#D-
191function IGCM_sys_RshPost {
192  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
193  if ( $DEBUG_sys ) ; then
194    echo "IGCM_sys_RshPost :" $@
195  fi
196  /bin/ksh ${@}
197  if [ $? -gt 0 ] ; then
198    echo "IGCM_sys_RshPost : erreur."
199    IGCM_debug_Exit "IGCM_sys_RshPost"
200  fi
201  IGCM_debug_PopStack "IGCM_sys_RshPost"
202}
203
204#D-#==================================================
205#D-function IGCM_sys_SendMail
206#D-* Purpose: Send mail when simulation is over
207#D-* Examples:
208#D-
209function IGCM_sys_SendMail {
210  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
211  if ( $DEBUG_sys ) ; then
212    echo "IGCM_sys_SendMail :" $@
213  fi
214
215  if ( ${ExitFlag} ) ; then
216    status=failed
217  else
218    status=completed
219  fi
220  cat  << END_MAIL > job_end.mail
221Dear ${LOGIN},
222
223  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
224  Job started : ${DateBegin}
225  Job ended   : ${DateEnd}
226  Output files are available in ${R_SAVE}
227  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
228END_MAIL
229
230  if  [ X"${config_UserChoices_MailName}" != X ] ; then
231    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
232  elif [ -f ~/.forward ] ; then
233    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
234  else
235    mailx -s "${config_UserChoices_JobName} ${status}" ${LOGIN} < job_end.mail
236  fi
237
238  if [ $? -gt 0 ] ; then
239    echo "IGCM_sys_SendMail : erreur."
240    IGCM_debug_Exit "IGCM_sys_SendMail"
241  fi
242  IGCM_debug_PopStack "IGCM_sys_SendMail"
243}
244
245#D-#==================================================
246#D-function IGCM_sys_Mkdir
247#D-* Purpose: Master locale mkdir command
248#D-* Examples:
249#D-
250function IGCM_sys_Mkdir {
251  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
252  if ( $DEBUG_sys ) ; then
253    echo "IGCM_sys_Mkdir :" $@
254  fi
255  if [ ! -d ${1} ]; then
256    \mkdir -p $1
257    if [ $? -gt 0 ] ; then
258      echo "IGCM_sys_Mkdir : erreur."
259      IGCM_debug_Exit "IGCM_sys_Mkdir"
260    fi
261  fi
262  # vérification :
263  if [ ! -d ${1} ] ; then
264    echo "IGCM_sys_Mkdir : erreur."
265    IGCM_debug_Exit "IGCM_sys_Mkdir"
266  fi
267  IGCM_debug_PopStack "IGCM_sys_Mkdir"
268}
269
270#D-#==================================================
271#D-function IGCM_sys_MkdirArchive
272#D-* Purpose: Mkdir on Archive
273#D-* Examples:
274#D-
275function IGCM_sys_MkdirArchive {
276  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
277  if ( $DEBUG_sys ) ; then
278    echo "IGCM_sys_MkdirArchive :" $@
279  fi
280  #- creation de repertoire sur le serveur fichier
281  if [ ! -d ${1} ]; then 
282    \mkdir -p $1
283    if [ $? -gt 0 ] ; then
284      echo "IGCM_sys_MkdirArchive : erreur."
285      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
286    fi
287  fi
288  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
289}
290
291#D-#==================================================
292#D-function IGCM_sys_MkdirWork
293#D-* Purpose: Mkdir on Work
294#D-* Examples:
295#D-
296function IGCM_sys_MkdirWork {
297  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
298  if ( $DEBUG_sys ) ; then
299    echo "IGCM_sys_MkdirWork :" $@
300  fi
301  #- creation de repertoire sur le serveur fichier
302  if [ ! -d ${1} ]; then 
303    \mkdir -p $1
304    if [ $? -gt 0 ] ; then
305      echo "IGCM_sys_MkdirWork : erreur."
306      IGCM_debug_Exit "IGCM_sys_MkdirWork"
307    fi
308  fi
309  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
310}
311
312#D-#==================================================
313#D-function IGCM_sys_Cd
314#D-* Purpose: master cd command
315#D-* Examples:
316#D-
317function IGCM_sys_Cd {
318  IGCM_debug_PushStack "IGCM_sys_Cd" $@
319  if ( $DEBUG_sys ) ; then
320    echo "IGCM_sys_Cd :" $@
321  fi
322  \cd $1
323  if [ $? -gt 0 ] ; then
324    echo "IGCM_sys_Cd : erreur."
325    IGCM_debug_Exit "IGCM_sys_Cd"
326  fi
327  IGCM_debug_PopStack "IGCM_sys_Cd"
328}
329
330#D-#==================================================
331#D-function IGCM_sys_Chmod
332#D-* Purpose: Chmod
333#D-* Examples:
334#D-
335function IGCM_sys_Chmod {
336  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
337  if ( $DEBUG_sys ) ; then
338    echo "IGCM_sys_Chmod :" $@
339  fi
340  if [ $DRYRUN -le 1 ]; then
341    \chmod $@
342    if [ $? -gt 0 ] ; then
343      echo "IGCM_sys_Chmod : erreur."
344      IGCM_debug_Exit "IGCM_sys_Chmod"
345    fi
346  else
347    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
348  fi
349  IGCM_debug_PopStack "IGCM_sys_Chmod"
350}
351
352#D-#==================================================
353#D-function IGCM_sys_FileSize
354#D-* Purpose: Filesize
355#D-* Examples:
356#D-
357function IGCM_sys_FileSize {
358  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
359
360  typeset sizeF
361  set +A sizeF -- $( ls -la ${1} )
362  if [ $? -gt 0 ] ; then
363    IGCM_debug_Exit "IGCM_sys_FileSize"
364  fi
365  eval ${2}=${sizeF[4]}
366
367  IGCM_debug_PopStack "IGCM_sys_FileSize"
368}
369
370#D-#==================================================
371#D-function IGCM_sys_TestDir
372#D-* Purpose: Test Directory that must exists
373#D-* Examples:
374#D-
375function IGCM_sys_TestDir {
376  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
377  if ( $DEBUG_sys ) ; then
378    echo "IGCM_sys_TestDir :" $@
379  fi
380  typeset ExistFlag
381  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
382  IGCM_debug_PopStack "IGCM_sys_TestDir"
383
384  return ${ExistFlag}
385}
386
387#D-#==================================================
388#D-function IGCM_sys_TestDirArchive
389#D-* Purpose: Test Directory that must exists on Archive
390#D-* Examples:
391#D-
392function IGCM_sys_TestDirArchive {
393  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
394  if ( $DEBUG_sys ) ; then
395    echo "IGCM_sys_TestDirArchive :" $@
396  fi
397  typeset ExistFlag
398  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
399  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
400
401  return ${ExistFlag}
402}
403
404#D-#==================================================
405#D-function IGCM_sys_IsFileArchived
406#D-* Purpose: Test file that must NOT EXISTS on Archive
407#D-* Examples:
408#D-
409function IGCM_sys_IsFileArchived {
410  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
411  if ( $DEBUG_sys ) ; then
412    echo "IGCM_sys_IsFileArchived :" $@
413  fi
414  typeset IsArchivedFlag
415  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/dmnfs ) != X ] && echo 0 || echo 1 )
416  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
417
418  return ${IsArchivedFlag}
419}
420
421#D-#==================================================
422#D-function IGCM_sys_TestFileArchive
423#D-* Purpose: Test file that must NOT EXISTS on Archive
424#D-* Examples:
425#D-
426function IGCM_sys_TestFileArchive {
427  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
428  if ( $DEBUG_sys ) ; then
429    echo "IGCM_sys_TestFileArchive :" $@
430  fi
431  typeset ExistFlag
432  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
433  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
434
435  return ${ExistFlag}
436}
437
438#D-#==================================================
439#D-function IGCM_sys_TestFileBuffer
440#D-* Purpose: Test file that must NOT EXISTS on Buffer
441#D-* Examples:
442#D-
443function IGCM_sys_TestFileBuffer {
444  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
445  typeset ExistFlag
446  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
447  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
448
449  return ${ExistFlag}
450}
451
452#D-#==================================================
453#D-function IGCM_sys_CountFileArchive
454#D-* Purpose: Count files on Archive filesystem
455#D-* Examples:
456#D-
457function IGCM_sys_CountFileArchive {
458  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
459  ls ${@} 2>/dev/null | wc -l
460  if [ $? -gt 0 ] ; then
461    echo "IGCM_sys_CountFileArchive : erreur."
462  fi
463  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
464}
465
466#D-#==================================================
467#D-function IGCM_sys_CountFileBuffer
468#D-* Purpose: Count files on Scratch filesystem
469#D-* Examples:
470#D-
471function IGCM_sys_CountFileBuffer {
472  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
473  ls ${@} 2>/dev/null | wc -l
474  if [ $? -gt 0 ] ; then
475    echo "IGCM_sys_CountFileBuffer : erreur."
476  fi
477  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
478}
479
480#D-#==================================================
481#D-function IGCM_sys_Tree
482#D-* Purpose: Tree directories with files on ${ARCHIVE}
483#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
484#D-
485function IGCM_sys_Tree {
486  IGCM_debug_PushStack "IGCM_sys_Tree" $@
487  if ( $DEBUG_sys ) ; then
488    echo "IGCM_sys_Tree :" $@
489  fi
490
491  \tree -f $@
492
493  IGCM_debug_PopStack "IGCM_sys_Tree"
494}
495
496#D-#==================================================
497#D-function IGCM_sys_Tar
498#D-* Purpose: master tar command
499#D-* Examples:
500#D-
501function IGCM_sys_Tar {
502  IGCM_debug_PushStack "IGCM_sys_Tar" $@
503  if ( $DEBUG_sys ) ; then
504    echo "IGCM_sys_Tar :" $@
505  fi
506  \tar cf $@
507  if [ $? -gt 0 ] ; then
508    echo "IGCM_sys_Tar : erreur."
509    IGCM_debug_Exit "IGCM_sys_Tar"
510  fi
511  IGCM_debug_PopStack "IGCM_sys_Tar"
512}
513
514#D-#==================================================
515#D-function IGCM_sys_UnTar
516#D-* Purpose: master un-tar command
517#D-* Examples:
518#D-
519function IGCM_sys_UnTar {
520  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
521  if ( $DEBUG_sys ) ; then
522    echo "IGCM_sys_UnTar :" $@
523  fi
524  \tar xvf $1
525  if [ $? -gt 0 ] ; then
526    echo "IGCM_sys_UnTar : erreur."
527    IGCM_debug_Exit "IGCM_sys_UnTar"
528  fi
529  IGCM_debug_PopStack "IGCM_sys_UnTar"
530}
531
532#D-#==================================================
533#D-function IGCM_sys_QsubPost
534#D-* Purpose: Qsub new job on scalaire
535#D-* Examples:
536#D-
537function IGCM_sys_QsubPost {
538  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
539  if ( $DEBUG_sys ) ; then
540    echo "IGCM_sys_QsubPost :" $@
541  fi
542  /usr/bin/nqsII/qsub -q scalaire -o ${POST_DIR}/${Script_Post_Output}.out ${libIGCM}/$1.job -v ${listVarEnv}
543  if [ $? -gt 0 ] ; then
544    echo "IGCM_sys_QsubPost : erreur " $@
545    IGCM_debug_Exit "IGCM_sys_QsubPost"
546  fi
547  IGCM_debug_PopStack "IGCM_sys_QsubPost"
548}
549
550#D-*************************
551#D- File transfer functions
552#D-*************************
553#D-
554
555#D-#==================================================
556#D-function IGCM_sys_Rsync_out
557#D-* Purpose: treat return val of rsync
558#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
559#D-  Error values and explanations can depend on your system version.
560function IGCM_sys_Rsync_out {
561  RET=$1
562  if [ ! $RET ] ; then
563    echo "rsync error !"
564  fi
565
566  if [ $MYLANG = "fr" ]; then
567    case $RET in
568    0)  return ;;
569    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
570      echo "Erreur de syntaxe ou d'utilisation."
571      return;;
572    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
573      echo "Incompatibilité de protocole."
574      return;;
575    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
576      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
577      echo "répertoires"
578      return;;
579    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
580      echo "Action demandée non supportée : une tentative de manipulation de"
581      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
582      echo "été faite ; ou une option qui est supportée par le  client  mais"
583      echo "pas par le serveur a été spécifiée."
584      return;;
585    10) echo "Erreur de rsync ; RERR_SOCKETIO"
586      echo "Erreur dans le socket d'entrée sortie"
587      return;;
588    11) echo "Erreur de rsync ; RERR_FILEIO"
589      echo "Erreur d'entrée sortie fichier"
590      return;;
591    12) echo "Erreur de rsync ; RERR_STREAMIO"
592      echo "Erreur dans flux de donnée du protocole rsync"
593      return;;
594    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
595      echo "Erreur avec les diagnostics du programme"
596      return;;
597    14) echo "Erreur de rsync ; RERR_IPC"
598      echo "Erreur dans le code IPC"
599      return;;
600    20) echo "Erreur de rsync ; RERR_SIGNAL"
601      echo "SIGUSR1 ou SIGINT reçu"
602      return;;
603    21) echo "Erreur de rsync ; RERR_WAITCHILD"
604      echo "Une erreur retournée par waitpid()"
605      return;;
606    22) echo "Erreur de rsync ; RERR_MALLOC"
607      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
608      return;;
609    23) echo ""
610      echo "Erreur fichier inexistant"
611      return;;
612    30) echo "Erreur de rsync ; RERR_TIMEOUT"
613      echo "Temps d'attente écoulé dans l'envoi/réception de données"
614      return;;
615    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
616      return;;
617    esac
618  elif [ $MYLANG = "en" ] ; then
619    case $RET in
620    0)  return;;               
621    1)  echo "rsync error : Syntax or usage error "
622      return;;
623    2)  echo "rsync error : Protocol incompatibility "
624      return;;
625    3)  echo "rsync error : Errors selecting input/output files, dirs"
626      return;;
627    4)  echo "rsync error : Requested action not supported: an attempt"
628      echo "was made to manipulate 64-bit files on a platform that cannot support"
629      echo "them; or an option was specified that is supported by the client and"
630      echo "not by the server."
631      return;;
632    5)  echo "rsync error : Error starting client-server protocol"
633      return;;
634    10) echo "rsync error : Error in socket I/O "
635      return;;
636    11) echo "rsync error : Error in file I/O "
637      return;;
638    12) echo "rsync error : Error in rsync protocol data stream "
639      return;;
640    13) echo "rsync error : Errors with program diagnostics "
641      return;;
642    14) echo "rsync error : Error in IPC code "
643      return;;
644    20) echo "rsync error : Received SIGUSR1 or SIGINT "
645      return;;
646    21) echo "rsync error : Some error returned by waitpid() "
647      return;;
648    22) echo "rsync error : Error allocating core memory buffers "
649      return;;
650    23) echo "rsync error : Partial transfer due to error"
651      return;;
652    24) echo "rsync error : Partial transfer due to vanished source files"
653      return;;
654    30) echo "rsync error : Timeout in data send/receive "
655      return;;
656    *)  echo "rsync error : return code of rsync unknown :" $RET
657      return;;
658    esac
659  else
660    echo "unknown language $MYLANG."
661    return
662  fi
663}
664
665#D-#==================================================
666#D-function IGCM_sys_Cp
667#D-* Purpose: generic cp
668#D-* Examples:
669#D-
670function IGCM_sys_Cp {
671  IGCM_debug_PushStack "IGCM_sys_Cp" $@
672  if ( $DEBUG_sys ) ; then
673    echo "IGCM_sys_Cp :" $@
674  fi
675
676  typeset RET
677
678  echo cp $@ > out_rsync 2>&1
679  \cp $@ >> out_rsync 2>&1
680  RET=$?
681
682  if [ ${RET} -gt 0 ] ; then
683    echo "IGCM_sys_Cp : error."
684    cat out_rsync
685    IGCM_debug_Exit "IGCM_sys_Cp"
686  else
687    \rm out_rsync
688  fi
689  IGCM_debug_PopStack "IGCM_sys_Cp"
690}
691
692#D-#==================================================
693#D-function IGCM_sys_Rm
694#D-* Purpose: generic rm
695#D-* Examples:
696#D-
697function IGCM_sys_Rm {
698  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
699  if ( $DEBUG_sys ) ; then
700    echo "IGCM_sys_Rm :" $@
701  fi
702
703  typeset RET
704
705  echo rm $@ > out_rsync 2>&1
706  \rm $@ >> out_rsync 2>&1
707  RET=$?
708
709  if [ ${RET} -gt 0 ] ; then
710    echo "IGCM_sys_Rm : error."
711    cat out_rsync
712    IGCM_debug_Exit "IGCM_sys_Rm"
713  else
714    \rm out_rsync
715  fi
716  IGCM_debug_PopStack "IGCM_sys_Rm"
717}
718
719#D-#==================================================
720#D-function IGCM_sys_RmRunDir
721#D-* Purpose: rm tmpdir (dummy function most of the time batch
722#D-                      scheduler will do the job)
723#D-* Examples:
724#D-
725function IGCM_sys_RmRunDir {
726  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
727  if ( $DEBUG_sys ) ; then
728    echo "IGCM_sys_RmRunDir :" $@
729  fi
730
731  typeset RET
732
733  echo rm $@ > out_rsync 2>&1
734  \rm $@ >> out_rsync 2>&1
735  RET=$?
736
737  if [ ${RET} -gt 0 ] ; then
738    echo "IGCM_sys_RmRunDir : error."
739    cat out_rsync
740    IGCM_debug_Exit "IGCM_sys_RmRunDir"
741  else
742    \rm out_rsync
743  fi
744  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
745}
746
747#D-#==================================================
748#D-function IGCM_sys_Mv
749#D-* Purpose: generic move
750#D-* Examples:
751#D-
752function IGCM_sys_Mv {
753  IGCM_debug_PushStack "IGCM_sys_Mv" $@
754  if ( $DEBUG_sys ) ; then
755    echo "IGCM_sys_Mv :" $@
756  fi
757
758  if [ $DRYRUN = 0 ]; then
759
760    typeset RET
761   
762    echo mv $@ > out_rsync 2>&1
763    \mv $@ >> out_rsync 2>&1
764    RET=$?
765   
766    if [ ${RET} -gt 0 ] ; then
767      echo "IGCM_sys_Mv : error in mv."
768      cat out_rsync
769      IGCM_debug_Exit "IGCM_sys_Mv"
770    else
771      \rm out_rsync
772    fi
773  else
774    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
775  fi
776
777  IGCM_debug_PopStack "IGCM_sys_Mv"
778}
779
780#D-#==================================================
781#D-function IGCM_sys_Put_Dir
782#D-* Purpose: Copy a complete directory on $(ARCHIVE)
783#D-* Examples:
784#D-
785function IGCM_sys_Put_Dir {
786  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
787  if ( $DEBUG_sys ) ; then
788    echo "IGCM_sys_Put_Dir :" $@
789  fi
790  if [ $DRYRUN = 0 ]; then
791    if [ ! -d ${1} ] ; then
792      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
793      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
794      return
795    fi
796
797    typeset RET
798
799    # Only if we use rsync
800    #IGCM_sys_TestDirArchive $( dirname $2 )
801    #
802    #USUAL WAY
803    \cp -r $1 $2 > out_rsync 2>&1
804    RET=$?
805
806    if [ ${RET} -gt 0 ] ; then
807      echo "IGCM_sys_Put_Dir : error."
808      cat out_rsync
809      IGCM_debug_Exit "IGCM_sys_Put_Dir"
810    else
811      \rm out_rsync
812    fi
813  else
814    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
815  fi
816  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
817}
818
819#D-#==================================================
820#D-function IGCM_sys_Get_Dir
821#D-* Purpose: Copy a complete directory from $(ARCHIVE)
822#D-* Examples:
823#D-
824function IGCM_sys_Get_Dir {
825  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
826  if ( $DEBUG_sys ) ; then
827    echo "IGCM_sys_Get_Dir :" $@
828  fi
829  if [ $DRYRUN = 0 ]; then
830#       if [ ! -d ${1} ] ; then
831#           echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
832#           IGCM_debug_PopStack "IGCM_sys_Get_Dir"
833#           return
834#       fi
835
836    typeset RET
837
838    # Only if we use rsync
839    #IGCM_sys_TestDirArchive $( dirname $2 )
840    #
841    #USUAL WAY
842    # add dmget (to demigrate all offline files) to reduce time of this command :
843    #dmget $1/*
844    ccc_hsm get $1/*
845    \cp -r $1 $2 > out_rsync 2>&1
846    RET=$?
847
848    if [ ${RET} -gt 0 ] ; then
849      echo "IGCM_sys_Get_Dir : error."
850      cat out_rsync
851      IGCM_debug_Exit "IGCM_sys_Get_Dir"
852    else
853      \rm out_rsync
854    fi
855  else
856    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
857  fi
858  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
859}
860
861#D-#==================================================
862#D-function IGCM_sys_Get_Master
863#D-* Purpose: Copy a complete directory from MASTER filesystem
864#D-* Examples:
865#D-
866function IGCM_sys_Get_Master {
867  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
868  if ( $DEBUG_sys ) ; then
869    echo "IGCM_sys_Get_Master :" $@
870  fi
871  if [ $DRYRUN = 0 ]; then
872    if [ ! -d ${1} ] ; then
873      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
874      IGCM_debug_PopStack "IGCM_sys_Get_Master"
875      return
876    fi
877
878    typeset RET
879
880    #USUAL WAY
881    \cp -r $1 $2 > out_rsync 2>&1
882    RET=$?
883
884    if [ ${RET} -gt 0 ] ; then
885      echo "IGCM_sys_Get_Master : error."
886      cat out_rsync
887      IGCM_debug_Exit "IGCM_sys_Get_Master"
888    else
889      \rm out_rsync
890    fi
891  else
892    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
893  fi
894  IGCM_debug_PopStack "IGCM_sys_Get_Master"
895}
896
897#D-#==================================================
898#D-function IGCM_sys_Put_Rest
899#D-* Purpose: Put computied restarts on ${ARCHIVE}.
900#D-           File and target directory must exist.
901#D-* Examples:
902#D-
903function IGCM_sys_Put_Rest {
904  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
905  if ( $DEBUG_sys ) ; then
906    echo "IGCM_sys_Put_Rest :" $@
907  fi
908  if [ $DRYRUN = 0 ]; then
909    if [ ! -f ${1} ] ; then
910      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
911      IGCM_debug_Exit "IGCM_sys_Put_Rest"
912    fi
913
914    typeset RET
915    #
916    if [ X${JobType} = XRUN ] ; then
917      IGCM_sys_Chmod 444 ${1}
918    fi
919
920    #
921    # USUAL WAY
922    \cp $1 $2 > out_rsync 2>&1
923    RET=$?
924
925#       #RSYNC WITH NETWORK SSH CALL
926#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
927#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
928
929#       #RSYNC WITH NFS USE
930#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
931#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
932
933#       RET=$?
934#       IGCM_sys_Rsync_out $RET
935
936#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
937#       (( RET=RET+$? ))
938
939    if [ ${RET} -gt 0 ] ; then
940      echo "IGCM_sys_Put_Rest : error."
941      cat out_rsync
942      IGCM_debug_Exit "IGCM_sys_Put_Rest"
943    else
944      \rm out_rsync
945    fi
946  else
947    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
948  fi
949  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
950}
951
952#D-#==================================================
953#D-function IGCM_sys_PutBuffer_Rest
954#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
955#D-           File and target directory must exist.
956#D-* Examples:
957#D-
958function IGCM_sys_PutBuffer_Rest {
959  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
960  if ( $DEBUG_sys ) ; then
961    echo "IGCM_sys_PutBuffer_Rest :" $@
962  fi
963  if [ $DRYRUN = 0 ]; then
964    if [ ! -f ${1} ] ; then
965      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
966      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
967    fi
968
969    typeset RET
970    #
971    if [ X${JobType} = XRUN ] ; then
972      IGCM_sys_Chmod 444 ${1}
973    fi
974
975    #
976    # USUAL WAY
977    \cp $1 $2 > out_rsync 2>&1
978    RET=$?
979
980    if [ ${RET} -gt 0 ] ; then
981      echo "IGCM_sys_PutBuffer_Rest : error."
982      cat out_rsync
983      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
984    else
985      \rm out_rsync
986    fi
987  else
988    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
989  fi
990  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
991}
992
993#D-#==================================================
994#D-function IGCM_sys_Put_Out
995#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
996#D-* Examples:
997#D-
998function IGCM_sys_Put_Out {
999  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1000  if ( $DEBUG_sys ) ; then
1001    echo "IGCM_sys_Put_Out :" $@
1002  fi
1003  if [ $DRYRUN = 0 ]; then
1004    if [ ! -f ${1} ] ; then
1005      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1006      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1007      return 1
1008    fi
1009    #
1010    IGCM_sys_MkdirArchive $( dirname $2 )
1011    #
1012    typeset RET exist skip
1013
1014    #=====================================================
1015    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1016    #=====================================================
1017
1018    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1019    #if [ $? -eq 0 ] ; then
1020    #    typeset WORKPATH FILEPATH
1021    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1022    #    IGCM_sys_MkdirWork ${WORKPATH}
1023    #    FILEPATH=${WORKPATH}/$( basename $2 )
1024    #    #
1025    #    IGCM_sys_Cp ${1} ${FILEPATH}
1026    #fi
1027
1028    if [ X${JobType} = XRUN ] ; then
1029      if [ X${3} = X ] ; then
1030        IGCM_sys_Chmod 444 ${1}
1031      fi
1032    fi
1033
1034    exist=false
1035    skip=false
1036    if [ -f $2 ] ; then
1037      IGCM_debug_Print 1 "$2 already exist"
1038      #dmget $2
1039      ccc_hsm get $2
1040      exist=true
1041      if [ "X$( diff $1 $2 )" = X ] ; then
1042        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1043        skip=true
1044      else
1045        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1046        skip=false
1047      fi
1048    fi
1049    #
1050    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1051      IGCM_sys_Chmod u+w $2
1052    fi
1053    # USUAL WAY
1054    if [ X${skip} = Xfalse ] ; then
1055      \cp $1 $2 > out_rsync 2>&1
1056      RET=$?
1057      if [ ${RET} -gt 0 ] ; then
1058        echo "IGCM_sys_Put_Out : error."
1059        cat out_rsync
1060        IGCM_debug_Exit "IGCM_sys_Put_Out"
1061      else
1062        \rm out_rsync
1063      fi
1064    fi
1065
1066#       #RSYNC WITH NETWORK SSH CALL
1067#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1068#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1069
1070#       #RSYNC WITH NFS USE
1071#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1072#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1073
1074#       RET=$?
1075#       IGCM_sys_Rsync_out $RET
1076
1077#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1078#       (( RET=RET+$? ))
1079
1080  else
1081    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1082  fi
1083  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1084  return 0
1085}
1086
1087#D-#==================================================
1088#D-function IGCM_sys_PutBuffer_Out
1089#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1090#D-* Examples:
1091#D-
1092function IGCM_sys_PutBuffer_Out {
1093  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1094  if ( $DEBUG_sys ) ; then
1095    echo "IGCM_sys_PutBuffer_Out :" $@
1096  fi
1097  if [ $DRYRUN = 0 ]; then
1098    if [ ! -f ${1} ] ; then
1099      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1100      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1101      return 1
1102    fi
1103    #
1104    IGCM_sys_Mkdir $( dirname $2 )
1105    #
1106    typeset RET
1107
1108    if [ X${JobType} = XRUN ] ; then
1109      if [ X${3} = X ] ; then
1110        IGCM_sys_Chmod 444 ${1}
1111      fi
1112    fi
1113    #
1114    # USUAL WAY
1115    \cp $1 $2 > out_rsync 2>&1
1116    RET=$?
1117
1118    if [ ${RET} -gt 0 ] ; then
1119      echo "IGCM_sys_PutBuffer_Out : error."
1120      cat out_rsync
1121      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1122    else
1123      \rm out_rsync
1124    fi
1125  else
1126    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1127  fi
1128  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1129  return 0
1130}
1131
1132#D-#==================================================
1133#D-function IGCM_sys_Get
1134#D-* Purpose: Get a file from ${ARCHIVE}
1135#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1136#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1137function IGCM_sys_Get {
1138  IGCM_debug_PushStack "IGCM_sys_Get" $@
1139
1140  typeset DEST RET dm_liste ifile target file_work
1141
1142  if ( $DEBUG_sys ) ; then
1143    echo "IGCM_sys_Get :" $@
1144  fi
1145  if [ $DRYRUN -le 2 ]; then
1146    if [ X${1} = X'/l' ] ; then
1147      # test if the first file is present in the old computation :
1148      eval set +A dm_liste \${${2}}
1149    else
1150      eval set +A dm_liste ${1}
1151    fi
1152    eval DEST=\${${#}}
1153
1154    #=====================================================
1155    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1156    #=====================================================
1157
1158    # Is it an R_OUT file (not R_IN) ?
1159    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1160    #if [ $? -eq 0 ] ; then
1161    #    # Yes  ? then we try to get it in SCRATCHDIR
1162    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1163    #    if [ -f ${file_work[0]} ] ; then
1164    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1165    #   IGCM_debug_PopStack "IGCM_sys_Get"
1166    #   return
1167    #    fi
1168    #fi
1169
1170    # test if the (first) file is present in the old computation :
1171    IGCM_sys_TestFileArchive ${dm_liste[0]}
1172    RET=$?
1173    if [ ${RET} -gt 0 ] ; then
1174      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1175      IGCM_debug_Exit "IGCM_sys_Get"
1176    fi
1177
1178    #dmget ${dm_liste[*]} > out_rsync 2>&1
1179    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1180    RET=$?
1181
1182    if [ ${RET} -gt 0 ] ; then
1183      echo "WARNING IGCM_sys_Get : demigration error."
1184      cat out_rsync
1185      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1186    fi
1187
1188    #if [ ${RET} -gt 0 ] ; then
1189    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1190    #   cat out_rsync
1191    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1192    #   sleep 30
1193    #   echo "We try another time"
1194    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1195    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1196    #   RET=$?
1197    #   if [ ${RET} -gt 0 ] ; then
1198    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1199    #       cat out_rsync
1200    #       IGCM_debug_Exit "IGCM_sys_Get"
1201    #   fi
1202    #    else
1203    #   echo "ERROR IGCM_sys_Get : demigration error :"
1204    #   cat out_rsync
1205    #   IGCM_debug_Exit "IGCM_sys_Get"
1206    #    fi
1207    #fi
1208
1209    #USUAL WAY
1210    if [ X${1} = X'/l' ] ; then
1211      (( RET=0 ))
1212      for target in ${dm_liste[*]} ; do
1213        local_file=$( basename ${target} )
1214        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1215        (( RET = RET + $? ))
1216      done
1217    else
1218      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1219      RET=$?
1220    fi
1221
1222#       #RSYNC WITH NETWORK SSH CALL
1223#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1224#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1225
1226#       #RSYNC WITH NFS USE
1227#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1228#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1229
1230#       RET=$?
1231#       IGCM_sys_Rsync_out $RET
1232
1233#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1234#       (( RET=RET+$? ))
1235
1236    if [ ${RET} -gt 0 ] ; then
1237      echo "IGCM_sys_Get : copy error."
1238      cat out_rsync
1239#      IGCM_debug_Exit "IGCM_sys_Get"
1240    else
1241      \rm out_rsync
1242    fi
1243  else
1244    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1245  fi
1246  IGCM_debug_PopStack "IGCM_sys_Get"
1247}
1248
1249#D-#==================================================
1250#D-function IGCM_sys_GetBuffer
1251#D-* Purpose: Get a file from ${SCRATCHDIR}
1252#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1253#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1254function IGCM_sys_GetBuffer {
1255  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1256
1257  typeset DEST RET buf_liste ifile target file_work
1258
1259  if ( $DEBUG_sys ) ; then
1260    echo "IGCM_sys_GetBuffer :" $@
1261  fi
1262  if [ $DRYRUN -le 2 ]; then
1263    if [ X${1} = X'/l' ] ; then
1264      # test if the first file is present in the old computation :
1265      eval set +A buf_liste \${${2}}
1266    else
1267      eval set +A buf_liste ${1}
1268    fi
1269    eval DEST=\${${#}}
1270
1271    #USUAL WAY
1272    if [ X${1} = X'/l' ] ; then
1273      (( RET=0 ))
1274      for target in ${buf_liste[*]} ; do
1275        local_file=$( basename ${target} )
1276        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1277        (( RET = RET + $? ))
1278      done
1279    else
1280      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1281      RET=$?
1282    fi
1283
1284    if [ ${RET} -gt 0 ] ; then
1285      echo "IGCM_sys_GetBuffer : copy error."
1286      cat out_rsync
1287      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1288    else
1289      \rm out_rsync
1290    fi
1291  else
1292    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1293  fi
1294  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1295}
1296
1297#D-#==================================================
1298#D-function IGCM_sys_GetDate_FichWork
1299#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1300#D-* Examples:
1301#D-
1302function IGCM_sys_GetDate_FichWork {
1303  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1304  if ( $DEBUG_sys ) ; then
1305    echo "IGCM_sys_GetDate_FichWork :" $@
1306  fi
1307  # donne la date filesys d'un fichier sur la machine work
1308  IGCM_debug_PopStack "IGCM_sys_FichWork"
1309}
1310
1311#D-#==================================================
1312#D-function IGCM_sys_GetDate_FichArchive
1313#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1314#D-* Examples:
1315#D-
1316function IGCM_sys_GetDate_FichArchive {
1317  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1318  if ( $DEBUG_sys ) ; then
1319    echo "IGCM_sys_GetDate_FichArchive :" $@
1320  fi
1321  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1322}
1323
1324#D-#==================================================
1325#D-function IGCM_sys_Dods_Rm
1326#D-* Purpose: DO NOTHING ! Put $(ARCHIVE) files on DODS internet protocole.
1327#D-* Examples:
1328#D-
1329function IGCM_sys_Dods_Rm {
1330  if ( $DEBUG_sys ) ; then
1331    echo "IGCM_sys_Dods_Rm :" $@
1332  fi
1333  typeset RET
1334  RET=0
1335  if [ $DRYRUN = 0 ]; then
1336
1337#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1338#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1339#      echo "Nothing has been done."
1340#      return
1341#    fi
1342
1343    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1344    RET=$?
1345   
1346#       if [ ${RET} -gt 0 ] ; then
1347#           echo "IGCM_sys_Dods_Rm : error."
1348#           cat out_dods_rm
1349#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1350#       else
1351#           rm out_dods_rm
1352#       fi
1353
1354  else
1355    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1356  fi
1357  return $RET
1358}
1359
1360#D-#==================================================
1361#D-function IGCM_sys_Dods_Cp
1362#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1363#D-* Examples:
1364#D-
1365function IGCM_sys_Dods_Cp {
1366  if ( $DEBUG_sys ) ; then
1367    echo "IGCM_sys_Dods_Cp :" $@
1368  fi
1369  typeset RET
1370  RET=0
1371  if [ $DRYRUN = 0 ]; then
1372
1373#    if [ ! -d ${R_SAVE}/${1} ] ; then
1374#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1375#      echo "Nothing has been done."
1376#      return
1377#    fi
1378
1379    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1380    RET=$?
1381
1382#       if [ ${RET} -gt 0 ] ; then
1383#           echo "IGCM_sys_Dods_Cp : error."
1384#           cat out_dods_cp
1385#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1386#       else
1387#           rm out_dods_cp
1388#       fi
1389
1390  else
1391    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1392  fi
1393  return $RET
1394}
1395
1396#D-#==================================================
1397#D-function IGCM_sys_Put_Dods
1398#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1399#D-* Examples:
1400#D-
1401function IGCM_sys_Put_Dods {
1402  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1403  if ( $DEBUG_sys ) ; then
1404    echo "IGCM_sys_Put_Dods :" $@
1405  fi
1406  typeset RET
1407  if [ $DRYRUN = 0 ]; then
1408    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1409      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1410      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1411      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1412      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1413      return
1414    fi
1415
1416    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1417      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1418      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1419      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1420      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1421      return
1422    fi
1423    #
1424    if [ -d ${R_SAVE}/${1} ] ; then
1425      cd ${R_SAVE}
1426    elif [ -d ${R_FIGR}/${1} ] ; then
1427      cd ${R_FIGR}
1428    fi
1429
1430    IGCM_sys_Dods_Rm ${1}
1431    IGCM_sys_Dods_Cp ${1}
1432    RET=0
1433   
1434    if [ ${RET} -gt 0 ] ; then
1435      echo "IGCM_sys_Put_Dods : error."
1436      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1437    fi
1438  else
1439    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1440  fi
1441  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1442}
1443
1444##############################################################
1445# REBUILD OPERATOR
1446
1447function IGCM_sys_rebuild {
1448  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1449  if ( $DEBUG_sys ) ; then
1450    echo "IGCM_sys_rebuild :" $@
1451  fi
1452  /home/cont003/p86ipsl/X86_64/bin/rebuild -f -o $@
1453  if [ $? -gt 0 ] ; then
1454    echo "IGCM_sys_rebuild : erreur ${@}."
1455    IGCM_debug_Exit "rebuild"
1456  fi
1457
1458  IGCM_debug_PopStack "IGCM_sys_rebuild"
1459}
1460
1461##############################################################
1462# NCO OPERATOR
1463
1464function IGCM_sys_ncap2 {
1465  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1466  if ( $DEBUG_sys ) ; then
1467    echo "IGCM_sys_ncap2 :" $@
1468  fi
1469  ncap2 "$@"
1470  if [ $? -gt 0 ] ; then
1471    echo "IGCM_sys_ncap2 : erreur ${@}."
1472    IGCM_debug_Exit "ncap2"
1473  fi
1474
1475  IGCM_debug_PopStack "IGCM_sys_ncap2"
1476}
1477
1478function IGCM_sys_ncatted {
1479  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1480  if ( $DEBUG_sys ) ; then
1481    echo "IGCM_sys_ncatted :" $@
1482  fi
1483  ncatted "$@"
1484  if [ $? -gt 0 ] ; then
1485    echo "IGCM_sys_ncatted : erreur ${@}."
1486    IGCM_debug_Exit "ncatted"
1487  fi
1488
1489  IGCM_debug_PopStack "IGCM_sys_ncatted"
1490}
1491
1492function IGCM_sys_ncbo {
1493  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1494  if ( $DEBUG_sys ) ; then
1495    echo "IGCM_sys_ncbo :" $@
1496  fi
1497  ncbo $@
1498  if [ $? -gt 0 ] ; then
1499    echo "IGCM_sys_ncbo : erreur ${@}."
1500    IGCM_debug_Exit "ncbo"
1501  fi
1502
1503  IGCM_debug_PopStack "IGCM_sys_ncbo"
1504}
1505
1506function IGCM_sys_ncdiff {
1507  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1508  if ( $DEBUG_sys ) ; then
1509    echo "IGCM_sys_ncdiff :" $@
1510  fi
1511  ncdiff $@
1512  if [ $? -gt 0 ] ; then
1513    echo "IGCM_sys_ncdiff : erreur ${@}."
1514    IGCM_debug_Exit "ncdiff"
1515  fi
1516
1517  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1518}
1519
1520function IGCM_sys_ncea {
1521  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1522  if ( $DEBUG_sys ) ; then
1523    echo "IGCM_sys_ncea :" $@
1524  fi
1525  ncea $@
1526  if [ $? -gt 0 ] ; then
1527    echo "IGCM_sys_ncea : erreur ${@}."
1528    IGCM_debug_Exit "ncea"
1529  fi
1530
1531  IGCM_debug_PopStack "IGCM_sys_ncea"
1532}
1533
1534function IGCM_sys_ncecat {
1535  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1536  if ( $DEBUG_sys ) ; then
1537    echo "IGCM_sys_ncecat :" $@
1538  fi
1539  ncecat $@
1540  if [ $? -gt 0 ] ; then
1541    echo "IGCM_sys_ncecat : erreur ${@}."
1542    IGCM_debug_Exit "ncecat"
1543  fi
1544
1545  IGCM_debug_PopStack "IGCM_sys_ncecat"
1546}
1547
1548function IGCM_sys_ncflint {
1549  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1550  if ( $DEBUG_sys ) ; then
1551    echo "IGCM_sys_ncflint :" $@
1552  fi
1553  ncflint $@
1554  if [ $? -gt 0 ] ; then
1555    echo "IGCM_sys_ncflint : erreur ${@}."
1556    IGCM_debug_Exit "ncflint"
1557  fi
1558
1559  IGCM_debug_PopStack "IGCM_sys_ncflint"
1560}
1561
1562function IGCM_sys_ncks {
1563  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1564  if ( $DEBUG_sys ) ; then
1565    echo "IGCM_sys_ncks :" $@
1566  fi
1567  ncks $@
1568  if [ $? -gt 0 ] ; then
1569    echo "IGCM_sys_ncks : erreur ${@}."
1570    IGCM_debug_Exit "ncks"
1571  fi
1572
1573  IGCM_debug_PopStack "IGCM_sys_ncks"
1574}
1575
1576function IGCM_sys_ncpdq {
1577  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1578  if ( $DEBUG_sys ) ; then
1579    echo "IGCM_sys_ncpdq :" $@
1580  fi
1581  ncpdq $@
1582  if [ $? -gt 0 ] ; then
1583    echo "IGCM_sys_ncpdq : erreur ${@}."
1584    IGCM_debug_Exit "ncpdq"
1585  fi
1586
1587  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1588}
1589
1590function IGCM_sys_ncra {
1591  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1592  if ( $DEBUG_sys ) ; then
1593    echo "IGCM_sys_ncra :" $@
1594  fi
1595  ncra $@
1596  if [ $? -gt 0 ] ; then
1597    echo "IGCM_sys_ncra : erreur ${@}."
1598    IGCM_debug_Exit "ncra"
1599  fi
1600
1601  IGCM_debug_PopStack "IGCM_sys_ncra"
1602}
1603
1604function IGCM_sys_ncrcat {
1605  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1606  if ( $DEBUG_sys ) ; then
1607    echo "IGCM_sys_ncrcat :" $@
1608  fi
1609  ncrcat $@
1610  if [ $? -gt 0 ] ; then
1611    echo "IGCM_sys_ncrcat : erreur ${@}."
1612#       IGCM_debug_Exit "ncrcat"
1613  fi
1614
1615  IGCM_debug_PopStack "IGCM_sys_ncrcat"
1616}
1617
1618function IGCM_sys_ncrename {
1619  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1620  if ( $DEBUG_sys ) ; then
1621    echo "IGCM_sys_ncrename :" $@
1622  fi
1623  ncrename $@
1624  if [ $? -gt 0 ] ; then
1625    echo "IGCM_sys_ncrename : erreur ${@}."
1626    IGCM_debug_Exit "ncrename"
1627  fi
1628
1629  IGCM_debug_PopStack "IGCM_sys_ncrename"
1630}
1631
1632function IGCM_sys_ncwa {
1633  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1634  if ( $DEBUG_sys ) ; then
1635    echo "IGCM_sys_ncwa :" $@
1636  fi
1637  ncwa $@
1638  if [ $? -gt 0 ] ; then
1639    echo "IGCM_sys_ncwa : erreur ${@}."
1640    IGCM_debug_Exit "ncwa"
1641  fi
1642
1643  IGCM_debug_PopStack "IGCM_sys_ncwa"
1644}
1645
1646##############################################################
1647# CDO OPERATOR
1648
1649function IGCM_sys_cdo {
1650  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
1651  if ( $DEBUG_sys ) ; then
1652    echo "IGCM_sys_cdo :" $@
1653  fi
1654  \cdo $@
1655  if [ $? -gt 0 ] ; then
1656    echo "IGCM_sys_cdo : erreur ${@}."
1657    IGCM_debug_PopStack "IGCM_sys_cdo"
1658    return 1
1659  else
1660    IGCM_debug_PopStack "IGCM_sys_cdo"
1661    return 0
1662  fi
1663
1664  IGCM_debug_PopStack "IGCM_sys_cdo"
1665}
1666
1667############################################################
1668# Activate Running Environnment Variables
1669
1670function IGCM_sys_activ_variables {
1671  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1672  if ( $DEBUG_sys ) ; then
1673    echo "IGCM_sys_activ_variables"
1674  fi
1675  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1676}
1677
1678############################################################
1679# Desactivate Running Environnment Variables
1680
1681function IGCM_sys_desactiv_variables {
1682  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1683  if ( $DEBUG_sys ) ; then
1684    echo "IGCM_sys_desactiv_variables"
1685  fi
1686  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1687}
1688
1689############################################################
1690# Build run file
1691
1692function IGCM_sys_build_run_file {
1693  IGCM_debug_PushStack "IGCM_sys_build_run_file"
1694  if ( $DEBUG_sys ) ; then
1695    echo "IGCM_sys_build_run_file"
1696  fi
1697  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1698}
Note: See TracBrowser for help on using the repository browser.