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

Last change on this file since 591 was 591, checked in by sdipsl, 12 years ago
  • adapt TSC and create_ts to work with packed files
  • adapt dods related functions to work with work/store
  • bugfixes
  • replace tabulation by 2 space in TSC (svn diff -x -w)
    • sorry for the inconvenience but it will really help on the long run.
  • 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:=${CSCRATCHDIR}/TMPDIR_IGCM/${JOBID}}
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
1181    if [ ${RET} -gt 0 ] ; then
1182      echo "WARNING IGCM_sys_Get : demigration error."
1183      cat out_rsync
1184      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1185    fi
1186
1187    #if [ ${RET} -gt 0 ] ; then
1188    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1189    #   cat out_rsync
1190    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1191    #   sleep 30
1192    #   echo "We try another time"
1193    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1194    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1195    #   RET=$?
1196    #   if [ ${RET} -gt 0 ] ; then
1197    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1198    #       cat out_rsync
1199    #       IGCM_debug_Exit "IGCM_sys_Get"
1200    #   fi
1201    #    else
1202    #   echo "ERROR IGCM_sys_Get : demigration error :"
1203    #   cat out_rsync
1204    #   IGCM_debug_Exit "IGCM_sys_Get"
1205    #    fi
1206    #fi
1207
1208    #USUAL WAY
1209    if [ X${1} = X'/l' ] ; then
1210      (( RET=0 ))
1211      for target in ${dm_liste[*]} ; do
1212        local_file=$( basename ${target} )
1213        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1214        (( RET = RET + $? ))
1215      done
1216    else
1217      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1218      RET=$?
1219    fi
1220
1221#       #RSYNC WITH NETWORK SSH CALL
1222#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1223#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1224
1225#       #RSYNC WITH NFS USE
1226#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1227#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1228
1229#       RET=$?
1230#       IGCM_sys_Rsync_out $RET
1231
1232#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1233#       (( RET=RET+$? ))
1234
1235    if [ ${RET} -gt 0 ] ; then
1236      echo "IGCM_sys_Get : copy error."
1237      cat out_rsync
1238#      IGCM_debug_Exit "IGCM_sys_Get"
1239    else
1240      \rm out_rsync
1241    fi
1242  else
1243    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1244  fi
1245  IGCM_debug_PopStack "IGCM_sys_Get"
1246}
1247
1248#D-#==================================================
1249#D-function IGCM_sys_GetBuffer
1250#D-* Purpose: Get a file from ${SCRATCHDIR}
1251#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1252#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1253function IGCM_sys_GetBuffer {
1254  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1255
1256  typeset DEST RET buf_liste ifile target file_work
1257
1258  if ( $DEBUG_sys ) ; then
1259    echo "IGCM_sys_GetBuffer :" $@
1260  fi
1261  if [ $DRYRUN -le 2 ]; then
1262    if [ X${1} = X'/l' ] ; then
1263      # test if the first file is present in the old computation :
1264      eval set +A buf_liste \${${2}}
1265    else
1266      eval set +A buf_liste ${1}
1267    fi
1268    eval DEST=\${${#}}
1269
1270    #USUAL WAY
1271    if [ X${1} = X'/l' ] ; then
1272      (( RET=0 ))
1273      for target in ${buf_liste[*]} ; do
1274        local_file=$( basename ${target} )
1275        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1276        (( RET = RET + $? ))
1277      done
1278    else
1279      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1280      RET=$?
1281    fi
1282
1283    if [ ${RET} -gt 0 ] ; then
1284      echo "IGCM_sys_GetBuffer : copy error."
1285      cat out_rsync
1286      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1287    else
1288      \rm out_rsync
1289    fi
1290  else
1291    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1292  fi
1293  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1294}
1295
1296#D-#==================================================
1297#D-function IGCM_sys_GetDate_FichWork
1298#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1299#D-* Examples:
1300#D-
1301function IGCM_sys_GetDate_FichWork {
1302  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1303  if ( $DEBUG_sys ) ; then
1304    echo "IGCM_sys_GetDate_FichWork :" $@
1305  fi
1306  # donne la date filesys d'un fichier sur la machine work
1307  IGCM_debug_PopStack "IGCM_sys_FichWork"
1308}
1309
1310#D-#==================================================
1311#D-function IGCM_sys_GetDate_FichArchive
1312#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1313#D-* Examples:
1314#D-
1315function IGCM_sys_GetDate_FichArchive {
1316  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1317  if ( $DEBUG_sys ) ; then
1318    echo "IGCM_sys_GetDate_FichArchive :" $@
1319  fi
1320  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1321}
1322
1323#D-#==================================================
1324#D-function IGCM_sys_Dods_Rm
1325#D-* Purpose: DO NOTHING ! Put $(ARCHIVE) files on DODS internet protocole.
1326#D-* Examples:
1327#D-
1328function IGCM_sys_Dods_Rm {
1329  if ( $DEBUG_sys ) ; then
1330    echo "IGCM_sys_Dods_Rm :" $@
1331  fi
1332  typeset RET
1333  RET=0
1334  if [ $DRYRUN = 0 ]; then
1335
1336#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1337#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1338#      echo "Nothing has been done."
1339#      return
1340#    fi
1341
1342    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1343    RET=$?
1344   
1345#       if [ ${RET} -gt 0 ] ; then
1346#           echo "IGCM_sys_Dods_Rm : error."
1347#           cat out_dods_rm
1348#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1349#       else
1350#           rm out_dods_rm
1351#       fi
1352
1353  else
1354    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1355  fi
1356  return $RET
1357}
1358
1359#D-#==================================================
1360#D-function IGCM_sys_Dods_Cp
1361#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1362#D-* Examples:
1363#D-
1364function IGCM_sys_Dods_Cp {
1365  if ( $DEBUG_sys ) ; then
1366    echo "IGCM_sys_Dods_Cp :" $@
1367  fi
1368  typeset RET
1369  RET=0
1370  if [ $DRYRUN = 0 ]; then
1371
1372#    if [ ! -d ${R_SAVE}/${1} ] ; then
1373#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1374#      echo "Nothing has been done."
1375#      return
1376#    fi
1377
1378    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1379    RET=$?
1380
1381#       if [ ${RET} -gt 0 ] ; then
1382#           echo "IGCM_sys_Dods_Cp : error."
1383#           cat out_dods_cp
1384#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1385#       else
1386#           rm out_dods_cp
1387#       fi
1388
1389  else
1390    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1391  fi
1392  return $RET
1393}
1394
1395#D-#==================================================
1396#D-function IGCM_sys_Put_Dods
1397#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1398#D-* Examples:
1399#D-
1400function IGCM_sys_Put_Dods {
1401  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1402  if ( $DEBUG_sys ) ; then
1403    echo "IGCM_sys_Put_Dods :" $@
1404  fi
1405  typeset RET
1406  if [ $DRYRUN = 0 ]; then
1407    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1408      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1409      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1410      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1411      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1412      return
1413    fi
1414
1415    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1416      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1417      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1418      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1419      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1420      return
1421    fi
1422    #
1423    if [ -d ${R_SAVE}/${1} ] ; then
1424      cd ${R_SAVE}
1425    elif [ -d ${R_FIGR}/${1} ] ; then
1426      cd ${R_FIGR}
1427    fi
1428
1429    IGCM_sys_Dods_Rm ${1}
1430    IGCM_sys_Dods_Cp ${1}
1431    RET=0
1432   
1433    if [ ${RET} -gt 0 ] ; then
1434      echo "IGCM_sys_Put_Dods : error."
1435      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1436    fi
1437  else
1438    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1439  fi
1440  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1441}
1442
1443##############################################################
1444# REBUILD OPERATOR
1445
1446function IGCM_sys_rebuild {
1447  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1448  if ( $DEBUG_sys ) ; then
1449    echo "IGCM_sys_rebuild :" $@
1450  fi
1451  /home/cont003/p86ipsl/X86_64/bin/rebuild -f -o $@
1452  if [ $? -gt 0 ] ; then
1453    echo "IGCM_sys_rebuild : erreur ${@}."
1454    IGCM_debug_Exit "rebuild"
1455  fi
1456
1457  IGCM_debug_PopStack "IGCM_sys_rebuild"
1458}
1459
1460##############################################################
1461# NCO OPERATOR
1462
1463function IGCM_sys_ncap2 {
1464  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1465  if ( $DEBUG_sys ) ; then
1466    echo "IGCM_sys_ncap2 :" $@
1467  fi
1468  ncap2 "$@"
1469  if [ $? -gt 0 ] ; then
1470    echo "IGCM_sys_ncap2 : erreur ${@}."
1471    IGCM_debug_Exit "ncap2"
1472  fi
1473
1474  IGCM_debug_PopStack "IGCM_sys_ncap2"
1475}
1476
1477function IGCM_sys_ncatted {
1478  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1479  if ( $DEBUG_sys ) ; then
1480    echo "IGCM_sys_ncatted :" $@
1481  fi
1482  ncatted "$@"
1483  if [ $? -gt 0 ] ; then
1484    echo "IGCM_sys_ncatted : erreur ${@}."
1485    IGCM_debug_Exit "ncatted"
1486  fi
1487
1488  IGCM_debug_PopStack "IGCM_sys_ncatted"
1489}
1490
1491function IGCM_sys_ncbo {
1492  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1493  if ( $DEBUG_sys ) ; then
1494    echo "IGCM_sys_ncbo :" $@
1495  fi
1496  ncbo $@
1497  if [ $? -gt 0 ] ; then
1498    echo "IGCM_sys_ncbo : erreur ${@}."
1499    IGCM_debug_Exit "ncbo"
1500  fi
1501
1502  IGCM_debug_PopStack "IGCM_sys_ncbo"
1503}
1504
1505function IGCM_sys_ncdiff {
1506  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1507  if ( $DEBUG_sys ) ; then
1508    echo "IGCM_sys_ncdiff :" $@
1509  fi
1510  ncdiff $@
1511  if [ $? -gt 0 ] ; then
1512    echo "IGCM_sys_ncdiff : erreur ${@}."
1513    IGCM_debug_Exit "ncdiff"
1514  fi
1515
1516  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1517}
1518
1519function IGCM_sys_ncea {
1520  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1521  if ( $DEBUG_sys ) ; then
1522    echo "IGCM_sys_ncea :" $@
1523  fi
1524  ncea $@
1525  if [ $? -gt 0 ] ; then
1526    echo "IGCM_sys_ncea : erreur ${@}."
1527    IGCM_debug_Exit "ncea"
1528  fi
1529
1530  IGCM_debug_PopStack "IGCM_sys_ncea"
1531}
1532
1533function IGCM_sys_ncecat {
1534  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1535  if ( $DEBUG_sys ) ; then
1536    echo "IGCM_sys_ncecat :" $@
1537  fi
1538  ncecat $@
1539  if [ $? -gt 0 ] ; then
1540    echo "IGCM_sys_ncecat : erreur ${@}."
1541    IGCM_debug_Exit "ncecat"
1542  fi
1543
1544  IGCM_debug_PopStack "IGCM_sys_ncecat"
1545}
1546
1547function IGCM_sys_ncflint {
1548  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1549  if ( $DEBUG_sys ) ; then
1550    echo "IGCM_sys_ncflint :" $@
1551  fi
1552  ncflint $@
1553  if [ $? -gt 0 ] ; then
1554    echo "IGCM_sys_ncflint : erreur ${@}."
1555    IGCM_debug_Exit "ncflint"
1556  fi
1557
1558  IGCM_debug_PopStack "IGCM_sys_ncflint"
1559}
1560
1561function IGCM_sys_ncks {
1562  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1563  if ( $DEBUG_sys ) ; then
1564    echo "IGCM_sys_ncks :" $@
1565  fi
1566  ncks $@
1567  if [ $? -gt 0 ] ; then
1568    echo "IGCM_sys_ncks : erreur ${@}."
1569    IGCM_debug_Exit "ncks"
1570  fi
1571
1572  IGCM_debug_PopStack "IGCM_sys_ncks"
1573}
1574
1575function IGCM_sys_ncpdq {
1576  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1577  if ( $DEBUG_sys ) ; then
1578    echo "IGCM_sys_ncpdq :" $@
1579  fi
1580  ncpdq $@
1581  if [ $? -gt 0 ] ; then
1582    echo "IGCM_sys_ncpdq : erreur ${@}."
1583    IGCM_debug_Exit "ncpdq"
1584  fi
1585
1586  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1587}
1588
1589function IGCM_sys_ncra {
1590  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1591  if ( $DEBUG_sys ) ; then
1592    echo "IGCM_sys_ncra :" $@
1593  fi
1594  ncra $@
1595  if [ $? -gt 0 ] ; then
1596    echo "IGCM_sys_ncra : erreur ${@}."
1597    IGCM_debug_Exit "ncra"
1598  fi
1599
1600  IGCM_debug_PopStack "IGCM_sys_ncra"
1601}
1602
1603function IGCM_sys_ncrcat {
1604  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1605  if ( $DEBUG_sys ) ; then
1606    echo "IGCM_sys_ncrcat :" $@
1607  fi
1608  ncrcat $@
1609  if [ $? -gt 0 ] ; then
1610    echo "IGCM_sys_ncrcat : erreur ${@}."
1611#       IGCM_debug_Exit "ncrcat"
1612  fi
1613
1614  IGCM_debug_PopStack "IGCM_sys_ncrcat"
1615}
1616
1617function IGCM_sys_ncrename {
1618  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1619  if ( $DEBUG_sys ) ; then
1620    echo "IGCM_sys_ncrename :" $@
1621  fi
1622  ncrename $@
1623  if [ $? -gt 0 ] ; then
1624    echo "IGCM_sys_ncrename : erreur ${@}."
1625    IGCM_debug_Exit "ncrename"
1626  fi
1627
1628  IGCM_debug_PopStack "IGCM_sys_ncrename"
1629}
1630
1631function IGCM_sys_ncwa {
1632  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1633  if ( $DEBUG_sys ) ; then
1634    echo "IGCM_sys_ncwa :" $@
1635  fi
1636  ncwa $@
1637  if [ $? -gt 0 ] ; then
1638    echo "IGCM_sys_ncwa : erreur ${@}."
1639    IGCM_debug_Exit "ncwa"
1640  fi
1641
1642  IGCM_debug_PopStack "IGCM_sys_ncwa"
1643}
1644
1645##############################################################
1646# CDO OPERATOR
1647
1648function IGCM_sys_cdo {
1649  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
1650  if ( $DEBUG_sys ) ; then
1651    echo "IGCM_sys_cdo :" $@
1652  fi
1653  \cdo $@
1654  if [ $? -gt 0 ] ; then
1655    echo "IGCM_sys_cdo : erreur ${@}."
1656    IGCM_debug_PopStack "IGCM_sys_cdo"
1657    return 1
1658  else
1659    IGCM_debug_PopStack "IGCM_sys_cdo"
1660    return 0
1661  fi
1662
1663  IGCM_debug_PopStack "IGCM_sys_cdo"
1664}
1665
1666############################################################
1667# Activate Running Environnment Variables
1668
1669function IGCM_sys_activ_variables {
1670  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1671  if ( $DEBUG_sys ) ; then
1672    echo "IGCM_sys_activ_variables"
1673  fi
1674  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1675}
1676
1677############################################################
1678# Desactivate Running Environnment Variables
1679
1680function IGCM_sys_desactiv_variables {
1681  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1682  if ( $DEBUG_sys ) ; then
1683    echo "IGCM_sys_desactiv_variables"
1684  fi
1685  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1686}
1687
1688############################################################
1689# Build run file
1690
1691function IGCM_sys_build_run_file {
1692  IGCM_debug_PushStack "IGCM_sys_build_run_file"
1693  if ( $DEBUG_sys ) ; then
1694    echo "IGCM_sys_build_run_file"
1695  fi
1696  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1697}
Note: See TracBrowser for help on using the repository browser.