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

Last change on this file since 637 was 618, checked in by sdipsl, 12 years ago
  • Bugfix in IGCM_sys_IsFileArchived
  • Property svn:keywords set to Revision Author Date
File size: 45.8 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  if ( $DEBUG_sys ) ; then
474    echo "IGCM_sys_TestFileArchive :" $@
475  fi
476  typeset ExistFlag
477  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
478  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
479
480  return ${ExistFlag}
481}
482
483#D-#==================================================
484#D-function IGCM_sys_TestFileBuffer
485#D-* Purpose: Test file that must NOT EXISTS on Buffer
486#D-* Examples:
487#D-
488function IGCM_sys_TestFileBuffer {
489  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
490  typeset ExistFlag
491  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
492  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
493
494  return ${ExistFlag}
495}
496
497#D-#==================================================
498#D-function IGCM_sys_CountFileArchive
499#D-* Purpose: Count files on Archive filesystem
500#D-* Examples:
501#D-
502function IGCM_sys_CountFileArchive {
503  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
504  ls ${@} 2>/dev/null | wc -l
505  if [ $? -gt 0 ] ; then
506    echo "IGCM_sys_CountFileArchive : erreur."
507  fi
508  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
509}
510
511#D-#==================================================
512#D-function IGCM_sys_CountFileBuffer
513#D-* Purpose: Count files on Master Scratch filesystem
514#D-* Examples:
515#D-
516function IGCM_sys_CountFileBuffer {
517  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
518  ls ${@} 2>/dev/null | wc -l
519  if [ $? -gt 0 ] ; then
520    echo "IGCM_sys_CountFileBuffer : erreur."
521  fi
522  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
523}
524
525#D-#==================================================
526#D-function IGCM_sys_Tree
527#D-* Purpose: Tree directories with files on ${ARCHIVE}
528#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
529#D-
530function IGCM_sys_Tree {
531  IGCM_debug_PushStack "IGCM_sys_Tree" $@
532  if ( $DEBUG_sys ) ; then
533    echo "IGCM_sys_Tree :" $@
534  fi
535
536  \tree -f $@
537
538  IGCM_debug_PopStack "IGCM_sys_Tree"
539}
540
541#D-#==================================================
542#D-function IGCM_sys_Tar
543#D-* Purpose: master tar command
544#D-* Examples:
545#D-
546function IGCM_sys_Tar {
547  IGCM_debug_PushStack "IGCM_sys_Tar" $@
548  if ( $DEBUG_sys ) ; then
549    echo "IGCM_sys_Tar :" $@
550  fi
551  \tar cf $@
552  if [ $? -gt 0 ] ; then
553    echo "IGCM_sys_Tar : erreur."
554    IGCM_debug_Exit "IGCM_sys_Tar"
555  fi
556  IGCM_debug_PopStack "IGCM_sys_Tar"
557}
558
559#D-#==================================================
560#D-function IGCM_sys_UnTar
561#D-* Purpose: master un-tar command
562#D-* Examples:
563#D-
564function IGCM_sys_UnTar {
565  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
566  if ( $DEBUG_sys ) ; then
567    echo "IGCM_sys_UnTar :" $@
568  fi
569  \tar xvf $1
570  if [ $? -gt 0 ] ; then
571    echo "IGCM_sys_UnTar : erreur."
572    IGCM_debug_Exit "IGCM_sys_UnTar"
573  fi
574  IGCM_debug_PopStack "IGCM_sys_UnTar"
575}
576
577#D-#==================================================
578#D-function IGCM_sys_Qsub
579#D-* Purpose: Qsub new job
580#D-* Examples:
581#D-
582function IGCM_sys_Qsub {
583  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
584  if ( $DEBUG_sys ) ; then
585    echo "IGCM_sys_Qsub :" $@
586  fi
587  /usr/local/bin/ccc_msub -o ${Script_Output} -e ${Script_Output}.e < $1
588  if [ $? -gt 0 ] ; then
589    echo "IGCM_sys_Qsub : erreur  -o ${Script_Output} -e ${Script_Output}.e $@"
590    IGCM_debug_Exit "IGCM_sys_Qsub"
591  fi
592  IGCM_debug_PopStack "IGCM_sys_Qsub"
593}
594
595#D-#==================================================
596#D-function IGCM_sys_QsubPost
597#D-* Purpose: Qsub new job on scalaire
598#D-* Examples:
599#D-
600function IGCM_sys_QsubPost {
601  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
602  if ( $DEBUG_sys ) ; then
603    echo "IGCM_sys_QsubPost :" $@
604  fi
605  /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
606  if [ $? -gt 0 ] ; then
607    echo "IGCM_sys_QsubPost : erreur " $@
608    IGCM_debug_Exit "IGCM_sys_QsubPost"
609  fi
610  IGCM_debug_PopStack "IGCM_sys_QsubPost"
611}
612
613#D-*************************
614#D- File transfer functions
615#D-*************************
616#D-
617
618#D-#==================================================
619#D-function IGCM_sys_Rsync_out
620#D-* Purpose: treat return val of rsync
621#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
622#D-  Error values and explanations can depend on your system version.
623function IGCM_sys_Rsync_out {
624  RET=$1
625  if [ ! $RET ] ; then
626    echo "rsync error !"
627  fi
628
629  if [ $MYLANG = "fr" ]; then
630    case $RET in
631    0)  return ;;
632    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
633      echo "Erreur de syntaxe ou d'utilisation."
634      return;;
635    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
636      echo "Incompatibilité de protocole."
637      return;;
638    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
639      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
640      echo "répertoires"
641      return;;
642    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
643      echo "Action demandée non supportée : une tentative de manipulation de"
644      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
645      echo "été faite ; ou une option qui est supportée par le  client  mais"
646      echo "pas par le serveur a été spécifiée."
647      return;;
648    10) echo "Erreur de rsync ; RERR_SOCKETIO"
649      echo "Erreur dans le socket d'entrée sortie"
650      return;;
651    11) echo "Erreur de rsync ; RERR_FILEIO"
652      echo "Erreur d'entrée sortie fichier"
653      return;;
654    12) echo "Erreur de rsync ; RERR_STREAMIO"
655      echo "Erreur dans flux de donnée du protocole rsync"
656      return;;
657    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
658      echo "Erreur avec les diagnostics du programme"
659      return;;
660    14) echo "Erreur de rsync ; RERR_IPC"
661      echo "Erreur dans le code IPC"
662      return;;
663    20) echo "Erreur de rsync ; RERR_SIGNAL"
664      echo "SIGUSR1 ou SIGINT reçu"
665      return;;
666    21) echo "Erreur de rsync ; RERR_WAITCHILD"
667      echo "Une erreur retournée par waitpid()"
668      return;;
669    22) echo "Erreur de rsync ; RERR_MALLOC"
670      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
671      return;;
672    23) echo ""
673      echo "Erreur fichier inexistant"
674      return;;
675    30) echo "Erreur de rsync ; RERR_TIMEOUT"
676      echo "Temps d'attente écoulé dans l'envoi/réception de données"
677      return;;
678    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
679      return;;
680    esac
681  elif [ $MYLANG = "en" ] ; then
682    case $RET in
683    0)  return;;               
684    1)  echo "rsync error : Syntax or usage error "
685      return;;
686    2)  echo "rsync error : Protocol incompatibility "
687      return;;
688    3)  echo "rsync error : Errors selecting input/output files, dirs"
689      return;;
690    4)  echo "rsync error : Requested action not supported: an attempt"
691      echo "was made to manipulate 64-bit files on a platform that cannot support"
692      echo "them; or an option was specified that is supported by the client and"
693      echo "not by the server."
694      return;;
695    5)  echo "rsync error : Error starting client-server protocol"
696      return;;
697    10) echo "rsync error : Error in socket I/O "
698      return;;
699    11) echo "rsync error : Error in file I/O "
700      return;;
701    12) echo "rsync error : Error in rsync protocol data stream "
702      return;;
703    13) echo "rsync error : Errors with program diagnostics "
704      return;;
705    14) echo "rsync error : Error in IPC code "
706      return;;
707    20) echo "rsync error : Received SIGUSR1 or SIGINT "
708      return;;
709    21) echo "rsync error : Some error returned by waitpid() "
710      return;;
711    22) echo "rsync error : Error allocating core memory buffers "
712      return;;
713    23) echo "rsync error : Partial transfer due to error"
714      return;;
715    24) echo "rsync error : Partial transfer due to vanished source files"
716      return;;
717    30) echo "rsync error : Timeout in data send/receive "
718      return;;
719    *)  echo "rsync error : return code of rsync unknown :" $RET
720      return;;
721    esac
722  else
723    echo "unknown language $MYLANG."
724    return
725  fi
726}
727
728#D-#==================================================
729#D-function IGCM_sys_Cp
730#D-* Purpose: generic cp
731#D-* Examples:
732#D-
733function IGCM_sys_Cp {
734  IGCM_debug_PushStack "IGCM_sys_Cp" $@
735  if ( $DEBUG_sys ) ; then
736    echo "IGCM_sys_Cp :" $@
737  fi
738
739  typeset RET
740
741  echo cp $@ > out_rsync 2>&1
742  \cp $@ >> out_rsync 2>&1
743  RET=$?
744
745  if [ ${RET} -gt 0 ] ; then
746    echo "IGCM_sys_Cp : error."
747    cat out_rsync
748    IGCM_debug_Exit "IGCM_sys_Cp"
749  else
750    \rm out_rsync
751  fi
752  IGCM_debug_PopStack "IGCM_sys_Cp"
753}
754
755#D-#==================================================
756#D-function IGCM_sys_Rm
757#D-* Purpose: generic rm
758#D-* Examples:
759#D-
760function IGCM_sys_Rm {
761  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
762  if ( $DEBUG_sys ) ; then
763    echo "IGCM_sys_Rm :" $@
764  fi
765
766  typeset RET
767
768  echo rm $@ > out_rsync 2>&1
769  \rm $@ >> out_rsync 2>&1
770  RET=$?
771
772  if [ ${RET} -gt 0 ] ; then
773    echo "IGCM_sys_Rm : error."
774    cat out_rsync
775    IGCM_debug_Exit "IGCM_sys_Rm"
776  else
777    \rm out_rsync
778  fi
779  IGCM_debug_PopStack "IGCM_sys_Rm"
780}
781
782#D-#==================================================
783#D-function IGCM_sys_RmRunDir
784#D-* Purpose: rm tmpdir (dummy function most of the time batch
785#D-                      scheduler will do the job)
786#D-* Examples:
787#D-
788function IGCM_sys_RmRunDir {
789  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
790  if ( $DEBUG_sys ) ; then
791    echo "IGCM_sys_RmRunDir :" $@
792  fi
793
794  typeset RET
795
796  echo rm $@ > out_rsync 2>&1
797  \rm $@ >> out_rsync 2>&1
798  RET=$?
799
800  if [ ${RET} -gt 0 ] ; then
801    echo "IGCM_sys_RmRunDir : error."
802    cat out_rsync
803    IGCM_debug_Exit "IGCM_sys_RmRunDir"
804  else
805    \rm out_rsync
806  fi
807  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
808}
809
810#D-#==================================================
811#D-function IGCM_sys_Mv
812#D-* Purpose: generic move
813#D-* Examples:
814#D-
815function IGCM_sys_Mv {
816  IGCM_debug_PushStack "IGCM_sys_Mv" $@
817  if ( $DEBUG_sys ) ; then
818    echo "IGCM_sys_Mv :" $@
819  fi
820
821  if [ $DRYRUN = 0 ]; then
822
823    typeset RET
824   
825    echo mv $@ > out_rsync 2>&1
826    \mv $@ >> out_rsync 2>&1
827    RET=$?
828   
829    if [ ${RET} -gt 0 ] ; then
830      echo "IGCM_sys_Mv : error in mv."
831      cat out_rsync
832      IGCM_debug_Exit "IGCM_sys_Mv"
833    else
834      \rm out_rsync
835    fi
836  else
837    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
838  fi
839
840  IGCM_debug_PopStack "IGCM_sys_Mv"
841}
842
843#D-#==================================================
844#D-function IGCM_sys_Put_Dir
845#D-* Purpose: Copy a complete directory on $(ARCHIVE)
846#D-* Examples:
847#D-
848function IGCM_sys_Put_Dir {
849  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
850  if ( $DEBUG_sys ) ; then
851    echo "IGCM_sys_Put_Dir :" $@
852  fi
853  if [ $DRYRUN = 0 ]; then
854    if [ ! -d ${1} ] ; then
855      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
856      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
857      return
858    fi
859
860    typeset RET
861
862    # Only if we use rsync
863    #IGCM_sys_TestDirArchive $( dirname $2 )
864    #
865    #USUAL WAY
866    \cp -r $1 $2 > out_rsync 2>&1
867    RET=$?
868
869    if [ ${RET} -gt 0 ] ; then
870      echo "IGCM_sys_Put_Dir : error."
871      cat out_rsync
872      IGCM_debug_Exit "IGCM_sys_Put_Dir"
873    else
874      \rm out_rsync
875    fi
876  else
877    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
878  fi
879  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
880}
881
882#D-#==================================================
883#D-function IGCM_sys_Get_Dir
884#D-* Purpose: Copy a complete directory from ${ARCHIVE}
885#D-* Examples:
886#D-
887function IGCM_sys_Get_Dir {
888  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
889  if ( $DEBUG_sys ) ; then
890    echo "IGCM_sys_Get_Dir :" $@
891  fi
892  if [ $DRYRUN = 0 ]; then
893#    if [ ! -d ${1} ] ; then
894#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
895#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
896#      return
897#    fi
898
899    typeset RET
900
901    # Only if we use rsync
902    #IGCM_sys_TestDirArchive $( dirname $2 )
903    #
904    # USUAL WAY
905    # add dmfind/dmget (to demigrate all offline files) :
906    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
907    \cp -r $1 $2 > out_rsync 2>&1
908    RET=$?
909
910    if [ ${RET} -gt 0 ] ; then
911      echo "IGCM_sys_Get_Dir : error."
912      cat out_rsync
913      IGCM_debug_Exit "IGCM_sys_Get_Dir"
914    else
915      \rm out_rsync
916    fi
917  else
918    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
919  fi
920  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
921}
922
923#D-#==================================================
924#D-function IGCM_sys_Get_Master
925#D-* Purpose: Copy a complete directory from MASTER filesystem
926#D-* Examples:
927#D-
928function IGCM_sys_Get_Master {
929  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
930  if ( $DEBUG_sys ) ; then
931    echo "IGCM_sys_Get_Master :" $@
932  fi
933  if [ $DRYRUN = 0 ]; then
934
935    typeset TEST NB_ESSAI DELAI status i
936   
937    TEST=$( IGCM_sys_RshMaster [ -d $1 ] && echo 1 || echo 0 )
938    if [ ${TEST} -ne 1 ] ; then
939      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ON ${MASTER}."
940      IGCM_debug_PopStack "IGCM_sys_Get_Master"
941      return
942    fi
943
944    # number of tentative
945    NB_ESSAI=10
946    # time delay between tentative
947    DELAI=10
948    #
949    (( i = 0 ))
950    while [ $i -lt $NB_ESSAI ] ; do
951            #USUAL WAY
952      scp -r ${MASTER}:$1 $2 > out_rsync 2>&1
953      status=$?
954      if [ ${status} -gt 0 ]; then
955        IGCM_debug_Print 2 "IGCM_sys_Get_Master : scp failed ${i}/${NB_ESSAI}"
956        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
957        sleep $DELAI
958      else
959        break
960      fi
961      (( i = i + 1 ))
962    done
963
964    if [ ${status} -gt 0 ] ; then
965      echo "IGCM_sys_Get_Master : error."
966      cat out_rsync
967      IGCM_debug_Exit "IGCM_sys_Get_Master"
968    else
969      \rm out_rsync
970    fi
971  else
972    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
973  fi
974  IGCM_debug_PopStack "IGCM_sys_Get_Master"
975}
976
977#D-#==================================================
978#D-function IGCM_sys_Put_Rest
979#D-* Purpose: Put computied restarts on ${ARCHIVE}.
980#D-           File and target directory must exist.
981#D-* Examples:
982#D-
983function IGCM_sys_Put_Rest {
984  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
985  if ( $DEBUG_sys ) ; then
986    echo "IGCM_sys_Put_Rest :" $@
987  fi
988  if [ $DRYRUN = 0 ]; then
989    if [ ! -f ${1} ] ; then
990      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
991      IGCM_debug_Exit "IGCM_sys_Put_Rest"
992    fi
993
994    typeset RET
995    #
996    if [ X${JobType} = XRUN ] ; then
997      IGCM_sys_Chmod 444 ${1}
998    fi
999
1000    #
1001    # USUAL WAY
1002    \cp $1 $2 > out_rsync 2>&1
1003    RET=$?
1004
1005#       #RSYNC WITH NETWORK SSH CALL
1006#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1007#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1008
1009#       #RSYNC WITH NFS USE
1010#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1011#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1012
1013#       RET=$?
1014#       IGCM_sys_Rsync_out $RET
1015
1016#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1017#       (( RET=RET+$? ))
1018
1019    if [ ${RET} -gt 0 ] ; then
1020      echo "IGCM_sys_Put_Rest : error."
1021      cat out_rsync
1022      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1023    else
1024      \rm out_rsync
1025    fi
1026  else
1027    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1028  fi
1029  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1030}
1031
1032#D-#==================================================
1033#D-function IGCM_sys_Put_Out
1034#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1035#D-* Examples:
1036#D-
1037function IGCM_sys_Put_Out {
1038  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1039  if ( $DEBUG_sys ) ; then
1040    echo "IGCM_sys_Put_Out :" $@
1041  fi
1042  if [ $DRYRUN = 0 ]; then
1043    if [ ! -f ${1} ] ; then
1044      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1045      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1046      return 1
1047    fi
1048    #
1049    IGCM_sys_MkdirArchive $( dirname $2 )
1050    #
1051    typeset RET exist skip
1052
1053    #=====================================================
1054    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1055    #=====================================================
1056
1057    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1058    #if [ $? -eq 0 ] ; then
1059    #    typeset WORKPATH FILEPATH
1060    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1061    #    IGCM_sys_MkdirWork ${WORKPATH}
1062    #    FILEPATH=${WORKPATH}/$( basename $2 )
1063    #    #
1064    #    IGCM_sys_Cp ${1} ${FILEPATH}
1065    #fi
1066
1067    if [ X${JobType} = XRUN ] ; then
1068      if [ X${3} = X ] ; then
1069        IGCM_sys_Chmod 444 ${1}
1070      fi
1071    fi
1072
1073    exist=false
1074    skip=false
1075    if [ -f $2 ] ; then
1076      IGCM_debug_Print 1 "$2 already exist"
1077      #dmget $2
1078      ccc_hsm get $2
1079      exist=true
1080      if [ "X$( diff $1 $2 )" = X ] ; then
1081        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1082        skip=true
1083      else
1084        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1085        skip=false
1086      fi
1087    fi
1088        #
1089    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1090      IGCM_sys_Chmod u+w $2
1091    fi
1092        # USUAL WAY
1093    if [ X${skip} = Xfalse ] ; then
1094      cp $1 $2 > out_rsync 2>&1
1095      RET=$?
1096      if [ ${RET} -gt 0 ] ; then
1097        echo "IGCM_sys_Put_Out : error."
1098        cat out_rsync
1099        IGCM_debug_Exit "IGCM_sys_Put_Out"
1100      else
1101        \rm out_rsync
1102      fi
1103    fi
1104
1105#       #RSYNC WITH NETWORK RSH CALL
1106#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
1107#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
1108
1109#       #RSYNC WITH NFS USE
1110#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1111#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1112
1113#       RET=$?
1114#       IGCM_sys_Rsync_out $RET
1115
1116#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1117#       (( RET=RET+$? ))
1118
1119
1120  else
1121    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1122  fi
1123  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1124  return 0
1125}
1126
1127#D-#==================================================
1128#D-function IGCM_sys_Get
1129#D-* Purpose: Get a file from ${ARCHIVE}
1130#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1131#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1132function IGCM_sys_Get {
1133  IGCM_debug_PushStack "IGCM_sys_Get" $@
1134
1135  typeset DEST RET dm_liste ifile target file_work
1136
1137  if ( $DEBUG_sys ) ; then
1138    echo "IGCM_sys_Get :" $@
1139  fi
1140  if [ $DRYRUN -le 2 ]; then
1141    if [ X${1} = X'/l' ] ; then
1142      # test if the first file is present in the old computation :
1143      eval set +A dm_liste \${${2}}
1144    else
1145      eval set +A dm_liste ${1}
1146    fi
1147    eval DEST=\${${#}}
1148
1149    #=====================================================
1150    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1151    #=====================================================
1152
1153    # Is it an R_OUT file (not R_IN) ?
1154    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1155    #if [ $? -eq 0 ] ; then
1156    #    # Yes  ? then we try to get it in SCRATCHDIR
1157    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1158    #    if [ -f ${file_work[0]} ] ; then
1159    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1160    #   IGCM_debug_PopStack "IGCM_sys_Get"
1161    #   return
1162    #    fi
1163    #fi
1164
1165    # test if the (first) file is present in the old computation :
1166    IGCM_sys_TestFileArchive ${dm_liste[0]}
1167    RET=$?
1168    if [ ${RET} -gt 0 ] ; then
1169      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1170      IGCM_debug_Exit "IGCM_sys_Get"
1171    fi
1172
1173    #dmget ${dm_liste[*]} > out_rsync 2>&1
1174    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1175    RET=$?
1176    if [ ${RET} -gt 0 ] ; then
1177      echo "WARNING IGCM_sys_Get : demigration error."
1178      cat out_rsync
1179      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1180    fi
1181
1182    #if [ ${RET} -gt 0 ] ; then
1183    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1184    #   cat out_rsync
1185    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1186    #   sleep 30
1187    #   echo "We try another time"
1188    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1189    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1190    #   RET=$?
1191    #   if [ ${RET} -gt 0 ] ; then
1192    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1193    #       cat out_rsync
1194    #       IGCM_debug_Exit "IGCM_sys_Get"
1195    #   fi
1196    #    else
1197    #   echo "ERROR IGCM_sys_Get : demigration error :"
1198    #   cat out_rsync
1199    #   IGCM_debug_Exit "IGCM_sys_Get"
1200    #    fi
1201    #fi
1202
1203    #USUAL WAY
1204    if [ X${1} = X'/l' ] ; then
1205      (( RET=0 ))
1206      for target in ${dm_liste[*]} ; do
1207        local_file=$( basename ${target} )
1208        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1209        (( RET = RET + $? ))
1210      done
1211    else
1212      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1213      RET=$?
1214    fi
1215
1216#       #RSYNC WITH NETWORK SSH CALL
1217#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1218#       ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1219
1220#       #RSYNC WITH NFS USE
1221#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1222#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1223
1224#       RET=$?
1225#       IGCM_sys_Rsync_out $RET
1226
1227#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1228#       (( RET=RET+$? ))
1229
1230    if [ ${RET} -gt 0 ] ; then
1231      echo "IGCM_sys_Get : copy error."
1232      cat out_rsync
1233      IGCM_debug_Exit "IGCM_sys_Get"
1234    else
1235      \rm out_rsync
1236    fi
1237  else
1238    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1239  fi
1240  IGCM_debug_PopStack "IGCM_sys_Get"
1241}
1242
1243#D-#==================================================
1244#D-function IGCM_sys_GetBuffer
1245#D-* Purpose: Get a file from ${SCRATCHDIR}
1246#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1247#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1248function IGCM_sys_GetBuffer {
1249  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1250
1251  typeset DEST RET buf_liste ifile target file_work
1252
1253  if ( $DEBUG_sys ) ; then
1254    echo "IGCM_sys_GetBuffer :" $@
1255  fi
1256  if [ $DRYRUN -le 2 ]; then
1257    if [ X${1} = X'/l' ] ; then
1258      # test if the first file is present in the old computation :
1259      eval set +A buf_liste \${${2}}
1260    else
1261      eval set +A buf_liste ${1}
1262    fi
1263    eval DEST=\${${#}}
1264
1265    #USUAL WAY
1266    if [ X${1} = X'/l' ] ; then
1267      (( RET=0 ))
1268      for target in ${buf_liste[*]} ; do
1269        local_file=$( basename ${target} )
1270        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1271        (( RET = RET + $? ))
1272      done
1273    else
1274      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1275      RET=$?
1276    fi
1277
1278    if [ ${RET} -gt 0 ] ; then
1279      echo "IGCM_sys_GetBuffer : copy error."
1280      cat out_rsync
1281      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1282    else
1283      \rm out_rsync
1284    fi
1285  else
1286    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1287  fi
1288  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1289}
1290
1291#D-#==================================================
1292#D-function IGCM_sys_GetDate_FichWork
1293#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1294#D-* Examples:
1295#D-
1296function IGCM_sys_GetDate_FichWork {
1297  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1298  if ( $DEBUG_sys ) ; then
1299    echo "IGCM_sys_GetDate_FichWork :" $@
1300  fi
1301    # donne la date filesys d'un fichier sur la machine work
1302  IGCM_debug_PopStack "IGCM_sys_FichWork"
1303}
1304
1305#D-#==================================================
1306#D-function IGCM_sys_GetDate_FichArchive
1307#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1308#D-* Examples:
1309#D-
1310function IGCM_sys_GetDate_FichArchive {
1311  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1312  if ( $DEBUG_sys ) ; then
1313    echo "IGCM_sys_GetDate_FichArchive :" $@
1314  fi
1315  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1316}
1317
1318#D-#==================================================
1319#D-function IGCM_sys_Dods_Rm
1320#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1321#D-* Examples:
1322#D-
1323function IGCM_sys_Dods_Rm {
1324  if ( $DEBUG_sys ) ; then
1325    echo "IGCM_sys_Dods_Rm :" $@
1326  fi
1327  typeset RET
1328  RET=0
1329  if [ $DRYRUN = 0 ]; then
1330
1331#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1332#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1333#      echo "Nothing has been done."
1334#      return
1335#    fi
1336
1337    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1338    RET=$?
1339   
1340#       if [ ${RET} -gt 0 ] ; then
1341#           echo "IGCM_sys_Dods_Rm : error."
1342#           cat out_dods_rm
1343#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1344#       else
1345#           rm out_dods_rm
1346#       fi
1347
1348  else
1349    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1350  fi
1351  return $RET
1352}
1353
1354#D-#==================================================
1355#D-function IGCM_sys_Dods_Cp
1356#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1357#D-* Examples:
1358#D-
1359function IGCM_sys_Dods_Cp {
1360  if ( $DEBUG_sys ) ; then
1361    echo "IGCM_sys_Dods_Cp :" $@
1362  fi
1363  typeset RET
1364  RET=0
1365
1366  if [ $DRYRUN = 0 ]; then
1367
1368#    if [ ! -d ${R_SAVE}/${1} ] ; then
1369#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1370#      echo "Nothing has been done."
1371#      return
1372#    fi
1373
1374    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1375    RET=$?
1376
1377#       if [ ${RET} -gt 0 ] ; then
1378#           echo "IGCM_sys_Dods_Cp : error."
1379#           cat out_dods_cp
1380#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1381#       else
1382#           rm out_dods_cp
1383#       fi
1384
1385  else
1386    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1387  fi
1388  return $RET
1389}
1390
1391#D-#==================================================
1392#D-function IGCM_sys_Put_Dods
1393#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1394#D-* Examples:
1395#D-
1396function IGCM_sys_Put_Dods {
1397  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1398  if ( $DEBUG_sys ) ; then
1399    echo "IGCM_sys_Put_Dods :" $@
1400  fi
1401  typeset RET
1402  if [ $DRYRUN = 0 ]; then
1403
1404    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1405      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1406      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1407      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1408      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1409      return
1410    fi
1411
1412    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1413      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1414      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1415      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1416      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1417      return
1418    fi
1419    #
1420    if [ -d ${R_SAVE}/${1} ] ; then
1421      cd ${R_SAVE}
1422    elif [ -d ${R_FIGR}/${1} ] ; then
1423      cd ${R_FIGR}
1424    fi
1425
1426    IGCM_sys_Dods_Rm ${1}
1427    IGCM_sys_Dods_Cp ${1}
1428    RET=0
1429   
1430    if [ ${RET} -gt 0 ] ; then
1431      echo "IGCM_sys_Put_Dods : error."
1432      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1433    fi
1434  else
1435    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1436  fi
1437  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1438}
1439
1440##############################################################
1441# REBUILD OPERATOR
1442
1443function IGCM_sys_rebuild {
1444  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1445  if ( $DEBUG_sys ) ; then
1446    echo "IGCM_sys_rebuild :" $@
1447  fi
1448  /home/cont003/p86ipsl/CESIUM/bin/rebuild -f -o $@
1449  if [ $? -gt 0 ] ; then
1450    echo "IGCM_sys_rebuild : erreur ${@}."
1451    IGCM_debug_Exit "rebuild"
1452  fi
1453
1454  IGCM_debug_PopStack "IGCM_sys_rebuild"
1455}
1456
1457
1458############################################################
1459# Activate Running Environnment Variables
1460
1461function IGCM_sys_activ_variables {
1462  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1463  if ( $DEBUG_sys ) ; then
1464    echo "IGCM_sys_activ_variables"
1465  fi
1466  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1467}
1468
1469############################################################
1470# Desactivate Running Environnment Variables
1471
1472function IGCM_sys_desactiv_variables {
1473  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1474  if ( $DEBUG_sys ) ; then
1475    echo "IGCM_sys_desactiv_variables"
1476  fi
1477  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1478}
1479
1480############################################################
1481# Build run file
1482
1483function IGCM_sys_build_run_file {
1484  IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1485  if ( $DEBUG_sys ) ; then
1486    echo "IGCM_sys_build_run_file"
1487  fi
1488  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1489}
1490
1491##############################################################
1492# NCO OPERATOR
1493
1494function IGCM_sys_ncap2 {
1495  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1496  if ( $DEBUG_sys ) ; then
1497    echo "IGCM_sys_ncap2 :" $@
1498  fi
1499  ncap2 "$@"
1500  if [ $? -gt 0 ] ; then
1501    echo "IGCM_sys_ncap2 : erreur ${@}."
1502    IGCM_debug_Exit "ncap2"
1503  fi
1504
1505  IGCM_debug_PopStack "IGCM_sys_ncap2"
1506}
1507
1508function IGCM_sys_ncatted {
1509  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1510  if ( $DEBUG_sys ) ; then
1511    echo "IGCM_sys_ncatted :" $@
1512  fi
1513  ncatted "$@"
1514  if [ $? -gt 0 ] ; then
1515    echo "IGCM_sys_ncatted : erreur ${@}."
1516    IGCM_debug_Exit "ncatted"
1517  fi
1518
1519  IGCM_debug_PopStack "IGCM_sys_ncatted"
1520}
1521
1522function IGCM_sys_ncbo {
1523  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1524  if ( $DEBUG_sys ) ; then
1525    echo "IGCM_sys_ncbo :" $@
1526  fi
1527  ncbo $@
1528  if [ $? -gt 0 ] ; then
1529    echo "IGCM_sys_ncbo : erreur ${@}."
1530    IGCM_debug_Exit "ncbo"
1531  fi
1532
1533  IGCM_debug_PopStack "IGCM_sys_ncbo"
1534}
1535
1536function IGCM_sys_ncdiff {
1537  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1538  if ( $DEBUG_sys ) ; then
1539    echo "IGCM_sys_ncdiff :" $@
1540  fi
1541  ncdiff $@
1542  if [ $? -gt 0 ] ; then
1543    echo "IGCM_sys_ncdiff : erreur ${@}."
1544    IGCM_debug_Exit "ncdiff"
1545  fi
1546
1547  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1548}
1549
1550function IGCM_sys_ncea {
1551  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1552  if ( $DEBUG_sys ) ; then
1553    echo "IGCM_sys_ncea :" $@
1554  fi
1555  ncea $@
1556  if [ $? -gt 0 ] ; then
1557    echo "IGCM_sys_ncea : erreur ${@}."
1558    IGCM_debug_Exit "ncea"
1559  fi
1560
1561  IGCM_debug_PopStack "IGCM_sys_ncea"
1562}
1563
1564function IGCM_sys_ncecat {
1565  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1566  if ( $DEBUG_sys ) ; then
1567    echo "IGCM_sys_ncecat :" $@
1568  fi
1569  ncecat $@
1570  if [ $? -gt 0 ] ; then
1571    echo "IGCM_sys_ncecat : erreur ${@}."
1572    IGCM_debug_Exit "ncecat"
1573  fi
1574
1575  IGCM_debug_PopStack "IGCM_sys_ncecat"
1576}
1577
1578function IGCM_sys_ncflint {
1579  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1580  if ( $DEBUG_sys ) ; then
1581    echo "IGCM_sys_ncflint :" $@
1582  fi
1583  ncflint $@
1584  if [ $? -gt 0 ] ; then
1585    echo "IGCM_sys_ncflint : erreur ${@}."
1586    IGCM_debug_Exit "ncflint"
1587  fi
1588
1589  IGCM_debug_PopStack "IGCM_sys_ncflint"
1590}
1591
1592function IGCM_sys_ncks {
1593  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1594  if ( $DEBUG_sys ) ; then
1595    echo "IGCM_sys_ncks :" $@
1596  fi
1597  ncks $@
1598  if [ $? -gt 0 ] ; then
1599    echo "IGCM_sys_ncks : erreur ${@}."
1600    IGCM_debug_Exit "ncks"
1601  fi
1602
1603  IGCM_debug_PopStack "IGCM_sys_ncks"
1604}
1605
1606function IGCM_sys_ncpdq {
1607  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1608  if ( $DEBUG_sys ) ; then
1609    echo "IGCM_sys_ncpdq :" $@
1610  fi
1611  ncpdq $@
1612  if [ $? -gt 0 ] ; then
1613    echo "IGCM_sys_ncpdq : erreur ${@}."
1614    IGCM_debug_Exit "ncpdq"
1615  fi
1616
1617  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1618}
1619
1620function IGCM_sys_ncra {
1621  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1622  if ( $DEBUG_sys ) ; then
1623    echo "IGCM_sys_ncra :" $@
1624  fi
1625  ncra $@
1626  if [ $? -gt 0 ] ; then
1627    echo "IGCM_sys_ncra : erreur ${@}."
1628    IGCM_debug_Exit "ncra"
1629  fi
1630
1631  IGCM_debug_PopStack "IGCM_sys_ncra"
1632}
1633
1634function IGCM_sys_ncrcat {
1635  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1636  if ( $DEBUG_sys ) ; then
1637    echo "IGCM_sys_ncrcat :" $@
1638  fi
1639  ncrcat $@
1640  if [ $? -gt 0 ] ; then
1641    echo "IGCM_sys_ncrcat : erreur ${@}."
1642#       IGCM_debug_Exit "ncrcat"
1643  fi
1644
1645  IGCM_debug_PopStack "IGCM_sys_ncrcat"
1646}
1647
1648function IGCM_sys_ncrename {
1649  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1650  if ( $DEBUG_sys ) ; then
1651    echo "IGCM_sys_ncrename :" $@
1652  fi
1653  ncrename $@
1654  if [ $? -gt 0 ] ; then
1655    echo "IGCM_sys_ncrename : erreur ${@}."
1656    IGCM_debug_Exit "ncrename"
1657  fi
1658
1659  IGCM_debug_PopStack "IGCM_sys_ncrename"
1660}
1661
1662function IGCM_sys_ncwa {
1663  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1664  if ( $DEBUG_sys ) ; then
1665    echo "IGCM_sys_ncwa :" $@
1666  fi
1667  ncwa $@
1668  if [ $? -gt 0 ] ; then
1669    echo "IGCM_sys_ncwa : erreur ${@}."
1670    IGCM_debug_Exit "ncwa"
1671  fi
1672
1673  IGCM_debug_PopStack "IGCM_sys_ncwa"
1674}
1675
1676##############################################################
1677# CDO OPERATOR
1678
1679function IGCM_sys_cdo {
1680  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
1681  if ( $DEBUG_sys ) ; then
1682    echo "IGCM_sys_cdo :" $@
1683  fi
1684  \cdo $@
1685  if [ $? -gt 0 ] ; then
1686    echo "IGCM_sys_cdo : erreur ${@}."
1687    IGCM_debug_PopStack "IGCM_sys_cdo"
1688    return 1
1689  else
1690    IGCM_debug_PopStack "IGCM_sys_cdo"
1691    return 0
1692  fi
1693
1694  IGCM_debug_PopStack "IGCM_sys_cdo"
1695}
Note: See TracBrowser for help on using the repository browser.