source: branches/libIGCM_MPI_OpenMP/libIGCM_sys/libIGCM_sys_mercure.ksh @ 596

Last change on this file since 596 was 596, checked in by mafoipsl, 12 years ago

Use $TMPDIR as RUN_DIR on mercure SX9 front-end.

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