source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_cesium.ksh @ 651

Last change on this file since 651 was 651, checked in by aclsce, 12 years ago

Added check to be sure there is enough space on temporary filesystems (only on vargas, titane and mercure sx9).
If there is not enough space, we stop.

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