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

Last change on this file since 782 was 782, checked in by labetoulle, 11 years ago
  • Move REBUILD_DIR initialization into IGCM_config_CommonConfiguration function ;
  • Delete not used variable R_OUT_POST.
  • Property svn:keywords set to Revision Author Date
File size: 56.9 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#- IN
122typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
123typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
124
125#====================================================
126#- R_OUT
127typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
128
129#====================================================
130#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
131typeset -r R_FIG=${STORAGE}/IGCM_OUT
132
133#====================================================
134#- R_BUF (ONLY FOR double copy an scratch)
135typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
136
137#====================================================
138#- RUN_DIR_PATH : Temporary working directory (=> TMP)
139PBS_JOBID=${PBS_JOBID:=TEMPDIR$$}
140typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/${PBS_JOBID}}
141
142#====================================================
143#- Max number of arguments passed to nco operator or demigration command
144UNIX_MAX_LIMIT=360
145
146#- set PackDefault true on NEC front-end
147PackDefault=true
148
149#D-#==================================================
150#D-function IGCM_sys_RshMaster
151#D-* Purpose: Just a fake command to wrapp
152#D-           IGCM_card call in post-treatment
153#D-           Ulam do not see brodie filesystem
154#D-           Cesium do not see all mercure filesystem
155#D-           That's why we need this hack.
156#D-* Examples:
157#D-
158function IGCM_sys_RshMaster {
159  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
160  typeset NB_ESSAI DELAI status i
161  # number of tentative
162  NB_ESSAI=10
163  # time delay between tentative
164  DELAI=10
165  #
166  (( i = 0 ))
167  while [ $i -lt $NB_ESSAI ] ; do
168    ssh ${MASTER} exec /bin/ksh <<-EOF
169    export libIGCM=${libIGCM_SX}
170    export DEBUG_debug=${DEBUG_debug}
171    . ${libIGCM_SX}/libIGCM_debug/libIGCM_debug.ksh
172    . ${libIGCM_SX}/libIGCM_card/libIGCM_card.ksh
173    ${@}
174EOF
175    status=$?
176    if [ ${status} -gt 0 ]; then
177      IGCM_debug_Print 2 "IGCM_sys_RshMaster : ssh failed ${i}/${NB_ESSAI}"
178      IGCM_debug_Print 2 "IGCM_sys_RshMaster : sleep ${DELAI} seconds and try again."
179      sleep $DELAI
180    else
181      break
182    fi
183    (( i = i + 1 ))
184  done
185
186  IGCM_debug_PopStack "IGCM_sys_RshMaster"
187}
188
189#D-#==================================================
190#D-function IGCM_sys_RshArchive
191#D-* Purpose: Archive rsh command
192#D-* Examples:
193#D-
194function IGCM_sys_RshArchive {
195  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
196  /bin/ksh <<-EOF
197    ${@}
198EOF
199  if [ $? -gt 0 ] ; then
200    echo "IGCM_sys_RshArchive : erreur."
201    IGCM_debug_Exit "IGCM_sys_RshArchive"
202  fi
203  IGCM_debug_PopStack "IGCM_sys_RshArchive"
204}
205
206#D-#==================================================
207#D-function IGCM_sys_RshPost
208#D-* Purpose: Post-process rsh command
209#D-* Examples:
210#D-
211function IGCM_sys_RshPost {
212  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
213  if ( $DEBUG_sys ) ; then
214    echo "IGCM_sys_RshPost :" $@
215  fi
216
217  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
218  #cat tmp_IGCM_sys_RshPost_$$
219  # keep standard input (stdin) for the loop onto temporary file
220  cat >tmp_IGCM_sys_RshPost_$$
221
222  /bin/ksh <tmp_IGCM_sys_RshPost_$$
223  if [ $? -gt 0 ] ; then
224    echo "IGCM_sys_RshPost : erreur."
225    IGCM_debug_Exit "IGCM_sys_RshPost"
226    cat tmp_IGCM_sys_RshPost_$$
227  fi
228  # delete temporary file
229  \rm tmp_IGCM_sys_RshPost_$$
230
231  IGCM_debug_PopStack "IGCM_sys_RshPost"
232}
233
234#D-#==================================================
235#D-function IGCM_sys_SendMail
236#D-* Purpose: Send mail when simulation is over
237#D-* Examples:
238#D-
239function IGCM_sys_SendMail {
240  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
241  if ( $DEBUG_sys ) ; then
242    echo "IGCM_sys_SendMail :" $@
243  fi
244
245  if ( ${ExitFlag} ) ; then
246    status=failed
247  else
248    status=completed
249  fi
250
251  ssh mercure <<-EOF
252    export LOGIN=${LOGIN}
253    export config_UserChoices_JobName=${config_UserChoices_JobName}
254    export config_UserChoices_MailName=${config_UserChoices_MailName}
255    export DateBegin=${DateBegin}
256    export DateEnd=${DateEnd}
257    export R_SAVE=${R_SAVE}
258    export SUBMIT_DIR=${SUBMIT_DIR}
259    export status=${status}
260
261    cat  << END_MAIL > job_end.mail
262Dear ${LOGIN},
263
264  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
265  Job started : ${DateBegin}
266  Job ended   : ${DateEnd}
267  Output files are available in ${R_SAVE}
268  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
269END_MAIL
270
271    if [ ! -z ${config_UserChoices_MailName} ] ; then
272       mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
273    elif [ -f ~/.forward ] ; then
274       mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
275    fi
276    sleep 10
277    rm -f job_end.mail
278EOF
279
280  if [ $? -gt 0 ] ; then
281    echo "IGCM_sys_SendMail : erreur."
282    IGCM_debug_Exit "IGCM_sys_SendMail"
283  fi
284  IGCM_debug_PopStack "IGCM_sys_SendMail"
285}
286
287#D-#==================================================
288#D-function IGCM_sys_Mkdir
289#D-* Purpose: Master locale mkdir command
290#D-* Examples:
291#D-
292function IGCM_sys_Mkdir {
293  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
294  if ( $DEBUG_sys ) ; then
295    echo "IGCM_sys_Mkdir :" $@
296  fi
297  if [ ! -d ${1} ]; then
298    \mkdir -p $1
299    if [ $? -gt 0 ] ; then
300      echo "IGCM_sys_Mkdir : erreur."
301      IGCM_debug_Exit "IGCM_sys_Mkdir"
302    fi
303  fi
304  # vérification :
305  if [ ! -d ${1} ] ; then
306    echo "IGCM_sys_Mkdir : erreur."
307    IGCM_debug_Exit "IGCM_sys_Mkdir"
308  fi
309  IGCM_debug_PopStack "IGCM_sys_Mkdir"
310}
311
312#D-#==================================================
313#D-function IGCM_sys_MkdirArchive
314#D-* Purpose: Mkdir on Archive
315#D-* Examples:
316#D-
317function IGCM_sys_MkdirArchive {
318  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
319  if ( $DEBUG_sys ) ; then
320    echo "IGCM_sys_MkdirArchive :" $@
321  fi
322  #- creation de repertoire sur le serveur fichier
323  if [ ! -d ${1} ]; then
324    \mkdir -p $1
325    if [ $? -gt 0 ] ; then
326      echo "IGCM_sys_MkdirArchive : erreur."
327      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
328    fi
329  fi
330  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
331}
332
333#D-#==================================================
334#D-function IGCM_sys_MkdirWork
335#D-* Purpose: Mkdir on Work
336#D-* Examples:
337#D-
338function IGCM_sys_MkdirWork {
339  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
340  if ( $DEBUG_sys ) ; then
341    echo "IGCM_sys_MkdirWork :" $@
342  fi
343  #- creation de repertoire sur le serveur fichier
344  if [ ! -d ${1} ]; then
345    \mkdir -p $1
346    if [ $? -gt 0 ] ; then
347      echo "IGCM_sys_MkdirWork : erreur."
348      IGCM_debug_Exit "IGCM_sys_MkdirWork"
349    fi
350  fi
351  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
352}
353
354#D-#==================================================
355#D-function IGCM_sys_Cd
356#D-* Purpose: master cd command
357#D-* Examples:
358#D-
359function IGCM_sys_Cd {
360  IGCM_debug_PushStack "IGCM_sys_Cd" $@
361  if ( $DEBUG_sys ) ; then
362    echo "IGCM_sys_Cd :" $@
363  fi
364  \cd $1
365  if [ $? -gt 0 ] ; then
366    echo "IGCM_sys_Cd : erreur."
367    IGCM_debug_Exit "IGCM_sys_Cd"
368  fi
369  IGCM_debug_PopStack "IGCM_sys_Cd"
370}
371
372#D-#==================================================
373#D-function IGCM_sys_Chmod
374#D-* Purpose: Chmod
375#D-* Examples:
376#D-
377function IGCM_sys_Chmod {
378  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
379  if ( $DEBUG_sys ) ; then
380    echo "IGCM_sys_Chmod :" $@
381  fi
382  if [ $DRYRUN -le 1 ]; then
383    \chmod $@
384    if [ $? -gt 0 ] ; then
385      echo "IGCM_sys_Chmod : erreur."
386      IGCM_debug_Exit "IGCM_sys_Chmod"
387    fi
388  else
389    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
390  fi
391  IGCM_debug_PopStack "IGCM_sys_Chmod"
392}
393
394#D-#==================================================
395#D-function IGCM_sys_FileSize
396#D-* Purpose: Filesize
397#D-* Examples:
398#D-
399function IGCM_sys_FileSize {
400  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
401
402  typeset sizeF
403  set +A sizeF -- $( ls -la ${1} )
404  if [ $? -gt 0 ] ; then
405    IGCM_debug_Exit "IGCM_sys_FileSize"
406  fi
407  eval ${2}=${sizeF[4]}
408
409  IGCM_debug_PopStack "IGCM_sys_FileSize"
410}
411
412#D-#==================================================
413#D-function IGCM_sys_TestDir
414#D-* Purpose: Test Directory that must exists
415#D-* Examples:
416#D-
417function IGCM_sys_TestDir {
418  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
419  if ( $DEBUG_sys ) ; then
420    echo "IGCM_sys_TestDir :" $@
421  fi
422  typeset ExistFlag
423  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
424  IGCM_debug_PopStack "IGCM_sys_TestDir"
425
426  return ${ExistFlag}
427}
428
429#D-#==================================================
430#D-function IGCM_sys_TestDirArchive
431#D-* Purpose: Test Directory that must exists on Archive
432#D-* Examples:
433#D-
434function IGCM_sys_TestDirArchive {
435  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
436  if ( $DEBUG_sys ) ; then
437    echo "IGCM_sys_TestDirArchive :" $@
438  fi
439  typeset ExistFlag
440  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
441  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
442
443  return ${ExistFlag}
444}
445
446#D-#==================================================
447#D-function IGCM_sys_IsFileArchived
448#D-* Purpose: Test file that must NOT EXISTS on Archive
449#D-* Examples:
450#D-
451function IGCM_sys_IsFileArchived {
452  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
453  if ( $DEBUG_sys ) ; then
454    echo "IGCM_sys_IsFileArchived :" $@
455  fi
456  typeset IsArchivedFlag
457  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
458  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
459
460  return ${IsArchivedFlag}
461}
462
463#D-#==================================================
464#D-function IGCM_sys_TestFileArchive
465#D-* Purpose: Test file that must NOT EXISTS on Archive
466#D-* Examples:
467#D-
468function IGCM_sys_TestFileArchive {
469  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
470  typeset ExistFlag
471  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
472  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
473
474  return ${ExistFlag}
475}
476
477#D-#==================================================
478#D-function IGCM_sys_TestFileBuffer
479#D-* Purpose: Test file that must NOT EXISTS on Buffer
480#D-* Examples:
481#D-
482function IGCM_sys_TestFileBuffer {
483  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
484  typeset ExistFlag
485  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
486  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
487
488  return ${ExistFlag}
489}
490
491#D-#==================================================
492#D-function IGCM_sys_CountFileArchive
493#D-* Purpose: Count files on Archive filesystem
494#D-* Examples:
495#D-
496function IGCM_sys_CountFileArchive {
497  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
498  ls ${@} 2>/dev/null | wc -l
499  if [ $? -gt 0 ] ; then
500    echo "IGCM_sys_CountFileArchive : erreur."
501  fi
502  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
503}
504
505#D-#==================================================
506#D-function IGCM_sys_CountFileBuffer
507#D-* Purpose: Count files on Scratch filesystem
508#D-* Examples:
509#D-
510function IGCM_sys_CountFileBuffer {
511  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
512  ls ${@} 2>/dev/null | wc -l
513  if [ $? -gt 0 ] ; then
514    echo "IGCM_sys_CountFileBuffer : erreur."
515  fi
516  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
517}
518
519#D-#==================================================
520#D-function IGCM_sys_Tree
521#D-* Purpose: Tree directories with files on ${ARCHIVE}
522#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
523#D-
524function IGCM_sys_Tree {
525  IGCM_debug_PushStack "IGCM_sys_Tree" $@
526  if ( $DEBUG_sys ) ; then
527    echo "IGCM_sys_Tree :" $@
528  fi
529
530  \tree -f $@
531
532  IGCM_debug_PopStack "IGCM_sys_Tree"
533}
534
535#D-#==================================================
536#D-function IGCM_sys_Tar
537#D-* Purpose: master tar command
538#D-* Examples:
539#D-
540function IGCM_sys_Tar {
541  IGCM_debug_PushStack "IGCM_sys_Tar" $@
542  if ( $DEBUG_sys ) ; then
543    echo "IGCM_sys_Tar :" $@
544  fi
545  \tar cf $@
546  if [ $? -gt 0 ] ; then
547    echo "IGCM_sys_Tar : erreur."
548    IGCM_debug_Exit "IGCM_sys_Tar"
549  fi
550  IGCM_debug_PopStack "IGCM_sys_Tar"
551}
552
553#D-#==================================================
554#D-function IGCM_sys_UnTar
555#D-* Purpose: master un-tar command
556#D-* Examples:
557#D-
558function IGCM_sys_UnTar {
559  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
560  if ( $DEBUG_sys ) ; then
561    echo "IGCM_sys_UnTar :" $@
562  fi
563  \tar xvf $1
564  if [ $? -gt 0 ] ; then
565    echo "IGCM_sys_UnTar : erreur."
566    IGCM_debug_Exit "IGCM_sys_UnTar"
567  fi
568  IGCM_debug_PopStack "IGCM_sys_UnTar"
569}
570
571#D-#==================================================
572#D-function IGCM_sys_Qsub
573#D-* Purpose: Qsub new job
574#D-* Examples:
575#D-
576function IGCM_sys_Qsub {
577  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
578  if ( $DEBUG_sys ) ; then
579    echo "IGCM_sys_Qsub :" $@
580  fi
581  /usr/local/bin/ccc_msub -o ${Script_Output} -e ${Script_Output}.e < $1
582  if [ $? -gt 0 ] ; then
583    echo "IGCM_sys_Qsub : erreur  -o ${Script_Output} -e ${Script_Output}.e $@"
584    IGCM_debug_Exit "IGCM_sys_Qsub"
585  fi
586  IGCM_debug_PopStack "IGCM_sys_Qsub"
587}
588
589#D-#==================================================
590#D-function IGCM_sys_QsubPost
591#D-* Purpose: Qsub new job on scalaire
592#D-* Examples:
593#D-
594function IGCM_sys_QsubPost {
595  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
596  if ( $DEBUG_sys ) ; then
597    echo "IGCM_sys_QsubPost :" $@
598  fi
599  /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
600  if [ $? -gt 0 ] ; then
601    echo "IGCM_sys_QsubPost : erreur " $@
602    IGCM_debug_Exit "IGCM_sys_QsubPost"
603  fi
604  IGCM_debug_PopStack "IGCM_sys_QsubPost"
605}
606
607#D-*************************
608#D- File transfer functions
609#D-*************************
610#D-
611
612#D-#==================================================
613#D-function IGCM_sys_Rsync_out
614#D-* Purpose: treat return val of rsync
615#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
616#D-  Error values and explanations can depend on your system version.
617function IGCM_sys_Rsync_out {
618  RET=$1
619  if [ ! $RET ] ; then
620    echo "rsync error !"
621  fi
622
623  if [ $MYLANG = "fr" ]; then
624    case $RET in
625    0)  return ;;
626    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
627      echo "Erreur de syntaxe ou d'utilisation."
628      return;;
629    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
630      echo "Incompatibilité de protocole."
631      return;;
632    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
633      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
634      echo "répertoires"
635      return;;
636    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
637      echo "Action demandée non supportée : une tentative de manipulation de"
638      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
639      echo "été faite ; ou une option qui est supportée par le  client  mais"
640      echo "pas par le serveur a été spécifiée."
641      return;;
642    10) echo "Erreur de rsync ; RERR_SOCKETIO"
643      echo "Erreur dans le socket d'entrée sortie"
644      return;;
645    11) echo "Erreur de rsync ; RERR_FILEIO"
646      echo "Erreur d'entrée sortie fichier"
647      return;;
648    12) echo "Erreur de rsync ; RERR_STREAMIO"
649      echo "Erreur dans flux de donnée du protocole rsync"
650      return;;
651    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
652      echo "Erreur avec les diagnostics du programme"
653      return;;
654    14) echo "Erreur de rsync ; RERR_IPC"
655      echo "Erreur dans le code IPC"
656      return;;
657    20) echo "Erreur de rsync ; RERR_SIGNAL"
658      echo "SIGUSR1 ou SIGINT reçu"
659      return;;
660    21) echo "Erreur de rsync ; RERR_WAITCHILD"
661      echo "Une erreur retournée par waitpid()"
662      return;;
663    22) echo "Erreur de rsync ; RERR_MALLOC"
664      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
665      return;;
666    23) echo ""
667      echo "Erreur fichier inexistant"
668      return;;
669    30) echo "Erreur de rsync ; RERR_TIMEOUT"
670      echo "Temps d'attente écoulé dans l'envoi/réception de données"
671      return;;
672    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
673      return;;
674    esac
675  elif [ $MYLANG = "en" ] ; then
676    case $RET in
677    0)  return;;
678    1)  echo "rsync error : Syntax or usage error "
679      return;;
680    2)  echo "rsync error : Protocol incompatibility "
681      return;;
682    3)  echo "rsync error : Errors selecting input/output files, dirs"
683      return;;
684    4)  echo "rsync error : Requested action not supported: an attempt"
685      echo "was made to manipulate 64-bit files on a platform that cannot support"
686      echo "them; or an option was specified that is supported by the client and"
687      echo "not by the server."
688      return;;
689    5)  echo "rsync error : Error starting client-server protocol"
690      return;;
691    10) echo "rsync error : Error in socket I/O "
692      return;;
693    11) echo "rsync error : Error in file I/O "
694      return;;
695    12) echo "rsync error : Error in rsync protocol data stream "
696      return;;
697    13) echo "rsync error : Errors with program diagnostics "
698      return;;
699    14) echo "rsync error : Error in IPC code "
700      return;;
701    20) echo "rsync error : Received SIGUSR1 or SIGINT "
702      return;;
703    21) echo "rsync error : Some error returned by waitpid() "
704      return;;
705    22) echo "rsync error : Error allocating core memory buffers "
706      return;;
707    23) echo "rsync error : Partial transfer due to error"
708      return;;
709    24) echo "rsync error : Partial transfer due to vanished source files"
710      return;;
711    30) echo "rsync error : Timeout in data send/receive "
712      return;;
713    *)  echo "rsync error : return code of rsync unknown :" $RET
714      return;;
715    esac
716  else
717    echo "unknown language $MYLANG."
718    return
719  fi
720}
721
722#D-#==================================================
723#D-function IGCM_sys_Cp
724#D-* Purpose: generic cp
725#D-* Examples:
726#D-
727function IGCM_sys_Cp {
728  IGCM_debug_PushStack "IGCM_sys_Cp" $@
729  if ( $DEBUG_sys ) ; then
730    echo "IGCM_sys_Cp :" $@
731  fi
732
733  typeset RET
734
735  echo cp $@ > out_rsync 2>&1
736  \cp $@ >> out_rsync 2>&1
737  RET=$?
738
739  if [ ${RET} -gt 0 ] ; then
740    echo "IGCM_sys_Cp : error."
741    cat out_rsync
742    IGCM_debug_Exit "IGCM_sys_Cp"
743  else
744    \rm out_rsync
745  fi
746  IGCM_debug_PopStack "IGCM_sys_Cp"
747}
748
749#D-#==================================================
750#D-function IGCM_sys_Rm
751#D-* Purpose: generic rm
752#D-* Examples:
753#D-
754function IGCM_sys_Rm {
755  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
756  if ( $DEBUG_sys ) ; then
757    echo "IGCM_sys_Rm :" $@
758  fi
759
760  typeset RET
761
762  echo rm $@ > out_rsync 2>&1
763  \rm $@ >> out_rsync 2>&1
764  RET=$?
765
766  if [ ${RET} -gt 0 ] ; then
767    echo "IGCM_sys_Rm : error."
768    cat out_rsync
769    IGCM_debug_Exit "IGCM_sys_Rm"
770  else
771    \rm out_rsync
772  fi
773  IGCM_debug_PopStack "IGCM_sys_Rm"
774}
775
776#D-#==================================================
777#D-function IGCM_sys_RmRunDir
778#D-* Purpose: rm tmpdir (dummy function most of the time batch
779#D-                      scheduler will do the job)
780#D-* Examples:
781#D-
782function IGCM_sys_RmRunDir {
783  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
784  if ( $DEBUG_sys ) ; then
785    echo "IGCM_sys_RmRunDir :" $@
786  fi
787
788  typeset RET
789
790  echo rm $@ > out_rsync 2>&1
791  \rm $@ >> out_rsync 2>&1
792  RET=$?
793
794  if [ ${RET} -gt 0 ] ; then
795    echo "IGCM_sys_RmRunDir : error."
796    cat out_rsync
797    IGCM_debug_Exit "IGCM_sys_RmRunDir"
798  else
799    \rm out_rsync
800  fi
801  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
802}
803
804#D-#==================================================
805#D-function IGCM_sys_Mv
806#D-* Purpose: generic move
807#D-* Examples:
808#D-
809function IGCM_sys_Mv {
810  IGCM_debug_PushStack "IGCM_sys_Mv" $@
811  if ( $DEBUG_sys ) ; then
812    echo "IGCM_sys_Mv :" $@
813  fi
814
815  if [ $DRYRUN = 0 ]; then
816
817    typeset RET
818
819    echo mv $@ > out_rsync 2>&1
820    \mv $@ >> out_rsync 2>&1
821    RET=$?
822
823    if [ ${RET} -gt 0 ] ; then
824      echo "IGCM_sys_Mv : error in mv."
825      cat out_rsync
826      IGCM_debug_Exit "IGCM_sys_Mv"
827    else
828      \rm out_rsync
829    fi
830  else
831    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
832  fi
833
834  IGCM_debug_PopStack "IGCM_sys_Mv"
835}
836
837#D-#==================================================
838#D-function IGCM_sys_Put_Dir
839#D-* Purpose: Copy a complete directory on $(ARCHIVE)
840#D-* Examples:
841#D-
842function IGCM_sys_Put_Dir {
843  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
844  if ( $DEBUG_sys ) ; then
845    echo "IGCM_sys_Put_Dir :" $@
846  fi
847  if [ $DRYRUN = 0 ]; then
848    if [ ! -d ${1} ] ; then
849      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
850      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
851      return
852    fi
853
854    typeset RET
855
856    # Only if we use rsync
857    #IGCM_sys_TestDirArchive $( dirname $2 )
858    #
859    #USUAL WAY
860    \cp -r $1 $2 > out_rsync 2>&1
861    RET=$?
862
863    if [ ${RET} -gt 0 ] ; then
864      echo "IGCM_sys_Put_Dir : error."
865      cat out_rsync
866      IGCM_debug_Exit "IGCM_sys_Put_Dir"
867    else
868      \rm out_rsync
869    fi
870  else
871    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
872  fi
873  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
874}
875
876#D-#==================================================
877#D-function IGCM_sys_Get_Dir
878#D-* Purpose: Copy a complete directory from ${ARCHIVE}
879#D-* Examples:
880#D-
881function IGCM_sys_Get_Dir {
882  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
883  if ( $DEBUG_sys ) ; then
884    echo "IGCM_sys_Get_Dir :" $@
885  fi
886  if [ $DRYRUN = 0 ]; then
887#    if [ ! -d ${1} ] ; then
888#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
889#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
890#      return
891#    fi
892
893    typeset RET
894
895    # Only if we use rsync
896    #IGCM_sys_TestDirArchive $( dirname $2 )
897    #
898    # USUAL WAY
899    # add dmfind/dmget (to demigrate all offline files) :
900    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
901    \cp -r $1 $2 > out_rsync 2>&1
902    RET=$?
903
904    if [ ${RET} -gt 0 ] ; then
905      echo "IGCM_sys_Get_Dir : error."
906      cat out_rsync
907      IGCM_debug_Exit "IGCM_sys_Get_Dir"
908    else
909      \rm out_rsync
910    fi
911  else
912    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
913  fi
914  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
915}
916
917#D-#==================================================
918#D-function IGCM_sys_Get_Master
919#D-* Purpose: Copy a complete directory from MASTER filesystem
920#D-* Examples:
921#D-
922function IGCM_sys_Get_Master {
923  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
924  if ( $DEBUG_sys ) ; then
925    echo "IGCM_sys_Get_Master :" $@
926  fi
927  if [ $DRYRUN = 0 ]; then
928
929    typeset TEST NB_ESSAI DELAI status i
930
931    TEST=$( IGCM_sys_RshMaster ( [ -d $1 ] || [ -f $1 ] ) && echo 1 || echo 0 )
932    if [ ${TEST} -ne 1 ] ; then
933      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ON ${MASTER}."
934      IGCM_debug_PopStack "IGCM_sys_Get_Master"
935      return
936    fi
937
938    # number of tentative
939    NB_ESSAI=10
940    # time delay between tentative
941    DELAI=10
942    #
943    (( i = 0 ))
944    while [ $i -lt $NB_ESSAI ] ; do
945            #USUAL WAY
946      scp -r ${MASTER}:$1 $2 > out_rsync 2>&1
947      status=$?
948      if [ ${status} -gt 0 ]; then
949        IGCM_debug_Print 2 "IGCM_sys_Get_Master : scp failed ${i}/${NB_ESSAI}"
950        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
951        sleep $DELAI
952      else
953        break
954      fi
955      (( i = i + 1 ))
956    done
957
958    if [ ${status} -gt 0 ] ; then
959      echo "IGCM_sys_Get_Master : error."
960      cat out_rsync
961      IGCM_debug_Exit "IGCM_sys_Get_Master"
962    else
963      \rm out_rsync
964    fi
965  else
966    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
967  fi
968  IGCM_debug_PopStack "IGCM_sys_Get_Master"
969}
970
971#D-#==================================================
972#D-function IGCM_sys_Put_Rest
973#D-* Purpose: Put computied restarts on ${ARCHIVE}.
974#D-           File and target directory must exist.
975#D-* Examples:
976#D-
977function IGCM_sys_Put_Rest {
978  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
979  if ( $DEBUG_sys ) ; then
980    echo "IGCM_sys_Put_Rest :" $@
981  fi
982  if [ $DRYRUN = 0 ]; then
983    if [ ! -f ${1} ] ; then
984      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
985      IGCM_debug_Exit "IGCM_sys_Put_Rest"
986    fi
987
988    typeset RET
989    #
990    if [ X${JobType} = XRUN ] ; then
991      IGCM_sys_Chmod 444 ${1}
992    fi
993
994    #
995    # USUAL WAY
996    \cp $1 $2 > out_rsync 2>&1
997    RET=$?
998
999#       #RSYNC WITH NETWORK SSH CALL
1000#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1001#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1002
1003#       #RSYNC WITH NFS USE
1004#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1005#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1006
1007#       RET=$?
1008#       IGCM_sys_Rsync_out $RET
1009
1010#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1011#       (( RET=RET+$? ))
1012
1013    if [ ${RET} -gt 0 ] ; then
1014      echo "IGCM_sys_Put_Rest : error."
1015      cat out_rsync
1016      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1017    else
1018      \rm out_rsync
1019    fi
1020  else
1021    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1022  fi
1023  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1024}
1025
1026#D-#==================================================
1027#D-function IGCM_sys_Put_Out
1028#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1029#D-* Examples:
1030#D-
1031function IGCM_sys_Put_Out {
1032  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1033  if ( $DEBUG_sys ) ; then
1034    echo "IGCM_sys_Put_Out :" $@
1035  fi
1036
1037  typeset NB_ESSAI DELAI RET i exist skip
1038
1039  # number of tentative
1040  NB_ESSAI=3
1041  # time delay between tentative
1042  DELAI=2
1043
1044  if [ $DRYRUN = 0 ]; then
1045    if [ ! -f ${1} ] ; then
1046      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1047      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1048      return 1
1049    fi
1050    #
1051    IGCM_sys_MkdirArchive $( dirname $2 )
1052    #
1053
1054    #=====================================================
1055    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1056    #=====================================================
1057
1058    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1059    #if [ $? -eq 0 ] ; then
1060    #    typeset WORKPATH FILEPATH
1061    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1062    #    IGCM_sys_MkdirWork ${WORKPATH}
1063    #    FILEPATH=${WORKPATH}/$( basename $2 )
1064    #    #
1065    #    IGCM_sys_Cp ${1} ${FILEPATH}
1066    #fi
1067
1068    if [ X${JobType} = XRUN ] ; then
1069      if [ X${3} = X ] ; then
1070        IGCM_sys_Chmod 444 ${1}
1071      fi
1072    fi
1073    #
1074
1075    exist=false
1076    skip=false
1077    if [ -f $2 ] ; then
1078      IGCM_debug_Print 1 "$2 already exist"
1079      #dmget $2
1080      ccc_hsm get $2
1081      exist=true
1082      if [ "X$( diff $1 $2 )" = X ] ; then
1083        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1084        skip=true
1085      else
1086        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1087        skip=false
1088      fi
1089    fi
1090    #
1091    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1092      IGCM_sys_Chmod u+w $2
1093    fi
1094
1095    if [ X${skip} = Xfalse ] ; then
1096      (( i = 0 ))
1097      while [ $i -lt $NB_ESSAI ] ; do
1098        # USUAL WAY
1099        \cp $1 $2 > out_rsync 2>&1
1100        RET=$?
1101        if [ ${RET} -gt 0 ]; then
1102          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed ${i}/${NB_ESSAI}"
1103          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1104          sleep $DELAI
1105        else
1106          break
1107        fi
1108        (( i = i + 1 ))
1109      done
1110    fi
1111
1112#       #RSYNC WITH NETWORK RSH CALL
1113#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
1114#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
1115
1116#       #RSYNC WITH NFS USE
1117#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1118#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1119
1120#       RET=$?
1121#       IGCM_sys_Rsync_out $RET
1122
1123#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1124#       (( RET=RET+$? ))
1125
1126    if [ ${RET} -gt 0 ] ; then
1127      echo "IGCM_sys_Put_Out : error."
1128      cat out_rsync
1129      IGCM_debug_Exit "IGCM_sys_Put_Out"
1130    else
1131      \rm out_rsync
1132    fi
1133  else
1134    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1135  fi
1136  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1137  return 0
1138}
1139
1140#D-#==================================================
1141#D-function IGCM_sys_Get
1142#D-* Purpose: Get a file from ${ARCHIVE}
1143#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1144#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1145function IGCM_sys_Get {
1146  IGCM_debug_PushStack "IGCM_sys_Get" $@
1147
1148  typeset DEST RET dm_liste ifile target file_work
1149  typeset NB_ESSAI DELAI status i
1150
1151  if ( $DEBUG_sys ) ; then
1152    echo "IGCM_sys_Get :" $@
1153  fi
1154
1155  # number of tentative
1156  NB_ESSAI=3
1157  # time delay between tentative
1158  DELAI=2
1159
1160  if [ $DRYRUN -le 2 ]; then
1161    if [ X${1} = X'/l' ] ; then
1162      # test if the first file is present in the old computation :
1163      eval set +A dm_liste \${${2}}
1164    else
1165      eval set +A dm_liste ${1}
1166    fi
1167    eval DEST=\${${#}}
1168
1169    #=====================================================
1170    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1171    #=====================================================
1172
1173    # Is it an R_OUT file (not R_IN) ?
1174    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1175    #if [ $? -eq 0 ] ; then
1176    #    # Yes  ? then we try to get it in SCRATCHDIR
1177    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1178    #    if [ -f ${file_work[0]} ] ; then
1179    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1180    #   IGCM_debug_PopStack "IGCM_sys_Get"
1181    #   return
1182    #    fi
1183    #fi
1184
1185    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1186    RET=$?
1187    if [ ${RET} -gt 0 ] ; then
1188      echo "WARNING IGCM_sys_Get : demigration error."
1189      cat out_rsync
1190      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1191    fi
1192
1193    #if [ ${RET} -gt 0 ] ; then
1194    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1195    #   cat out_rsync
1196    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1197    #   sleep 30
1198    #   echo "We try another time"
1199    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1200    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1201    #   RET=$?
1202    #   if [ ${RET} -gt 0 ] ; then
1203    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1204    #       cat out_rsync
1205    #       IGCM_debug_Exit "IGCM_sys_Get"
1206    #   fi
1207    #    else
1208    #   echo "ERROR IGCM_sys_Get : demigration error :"
1209    #   cat out_rsync
1210    #   IGCM_debug_Exit "IGCM_sys_Get"
1211    #    fi
1212    #fi
1213
1214    #USUAL WAY
1215    if [ X${1} = X'/l' ] ; then
1216      (( RET=0 ))
1217      for target in ${dm_liste[*]} ; do
1218        local_file=$( basename ${target} )
1219        (( i = 0 ))
1220        # test if the target file is present before the loop
1221        IGCM_sys_TestFileArchive ${target}
1222        RET=$?
1223        if [ ${RET} -gt 0 ] ; then
1224          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1225          IGCM_debug_Exit "IGCM_sys_Get"
1226        else
1227          while [ $i -lt $NB_ESSAI ] ; do
1228            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1229            status=$?
1230            if [ ${status} -gt 0 ]; then
1231              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed ${i}/${NB_ESSAI}"
1232              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1233              sleep $DELAI
1234            else
1235              break
1236            fi
1237            (( i = i + 1 ))
1238          done
1239          (( RET = RET + status ))
1240        fi
1241      done
1242    else
1243      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1244      RET=$?
1245    fi
1246
1247#       #RSYNC WITH NETWORK SSH CALL
1248#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1249#       ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1250
1251#       #RSYNC WITH NFS USE
1252#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1253#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1254
1255#       RET=$?
1256#       IGCM_sys_Rsync_out $RET
1257
1258#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1259#       (( RET=RET+$? ))
1260
1261    if [ ${RET} -gt 0 ] ; then
1262      echo "IGCM_sys_Get : copy error."
1263      cat out_rsync
1264      IGCM_debug_Exit "IGCM_sys_Get"
1265    else
1266      \rm out_rsync
1267    fi
1268  else
1269    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1270  fi
1271  IGCM_debug_PopStack "IGCM_sys_Get"
1272}
1273
1274#D-#==================================================
1275#D-function IGCM_sys_GetBuffer
1276#D-* Purpose: Get a file from ${SCRATCHDIR}
1277#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1278#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1279function IGCM_sys_GetBuffer {
1280  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1281
1282  typeset DEST RET buf_liste ifile target file_work
1283
1284  if ( $DEBUG_sys ) ; then
1285    echo "IGCM_sys_GetBuffer :" $@
1286  fi
1287  if [ $DRYRUN -le 2 ]; then
1288    if [ X${1} = X'/l' ] ; then
1289      # test if the first file is present in the old computation :
1290      eval set +A buf_liste \${${2}}
1291    else
1292      eval set +A buf_liste ${1}
1293    fi
1294    eval DEST=\${${#}}
1295
1296    #USUAL WAY
1297    if [ X${1} = X'/l' ] ; then
1298      (( RET=0 ))
1299      for target in ${buf_liste[*]} ; do
1300        local_file=$( basename ${target} )
1301        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1302        (( RET = RET + $? ))
1303      done
1304    else
1305      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1306      RET=$?
1307    fi
1308
1309    if [ ${RET} -gt 0 ] ; then
1310      echo "IGCM_sys_GetBuffer : copy error."
1311      cat out_rsync
1312      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1313    else
1314      \rm out_rsync
1315    fi
1316  else
1317    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1318  fi
1319  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1320}
1321
1322#D-#==================================================
1323#D-function IGCM_sys_GetDate_FichWork
1324#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1325#D-* Examples:
1326#D-
1327function IGCM_sys_GetDate_FichWork {
1328  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1329  if ( $DEBUG_sys ) ; then
1330    echo "IGCM_sys_GetDate_FichWork :" $@
1331  fi
1332  # donne la date filesys d'un fichier sur la machine work
1333  IGCM_debug_PopStack "IGCM_sys_FichWork"
1334}
1335
1336#D-#==================================================
1337#D-function IGCM_sys_GetDate_FichArchive
1338#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1339#D-* Examples:
1340#D-
1341function IGCM_sys_GetDate_FichArchive {
1342  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1343  if ( $DEBUG_sys ) ; then
1344    echo "IGCM_sys_GetDate_FichArchive :" $@
1345  fi
1346  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1347}
1348
1349#D-#==================================================
1350#D-function IGCM_sys_Dods_Rm
1351#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1352#D-* Examples:
1353#D-
1354function IGCM_sys_Dods_Rm {
1355  if ( $DEBUG_sys ) ; then
1356    echo "IGCM_sys_Dods_Rm :" $@
1357  fi
1358  typeset RET
1359  RET=0
1360  if [ $DRYRUN = 0 ]; then
1361
1362#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1363#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1364#      echo "Nothing has been done."
1365#      return
1366#    fi
1367
1368    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1369    RET=$?
1370
1371#       if [ ${RET} -gt 0 ] ; then
1372#           echo "IGCM_sys_Dods_Rm : error."
1373#           cat out_dods_rm
1374#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1375#       else
1376#           rm out_dods_rm
1377#       fi
1378
1379  else
1380    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1381  fi
1382  return $RET
1383}
1384
1385#D-#==================================================
1386#D-function IGCM_sys_Dods_Cp
1387#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1388#D-* Examples:
1389#D-
1390function IGCM_sys_Dods_Cp {
1391  if ( $DEBUG_sys ) ; then
1392    echo "IGCM_sys_Dods_Cp :" $@
1393  fi
1394  typeset RET
1395  RET=0
1396  if [ $DRYRUN = 0 ]; then
1397
1398#    if [ ! -d ${R_SAVE}/${1} ] ; then
1399#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1400#      echo "Nothing has been done."
1401#      return
1402#    fi
1403
1404    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1405    RET=$?
1406
1407#       if [ ${RET} -gt 0 ] ; then
1408#           echo "IGCM_sys_Dods_Cp : error."
1409#           cat out_dods_cp
1410#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1411#       else
1412#           rm out_dods_cp
1413#       fi
1414
1415  else
1416    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1417  fi
1418  return $RET
1419}
1420
1421#D-#==================================================
1422#D-function IGCM_sys_Put_Dods
1423#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1424#D-* Examples:
1425#D-
1426function IGCM_sys_Put_Dods {
1427  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1428  if ( $DEBUG_sys ) ; then
1429    echo "IGCM_sys_Put_Dods :" $@
1430  fi
1431  typeset RET
1432  if [ $DRYRUN = 0 ]; then
1433    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1434      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1435      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1436      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1437      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1438      return
1439    fi
1440
1441    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1442      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1443      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1444      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1445      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1446      return
1447    fi
1448    #
1449    if [ -d ${R_SAVE}/${1} ] ; then
1450      cd ${R_SAVE}
1451    elif [ -d ${R_FIGR}/${1} ] ; then
1452      cd ${R_FIGR}
1453    fi
1454
1455    IGCM_sys_Dods_Rm ${1}
1456    IGCM_sys_Dods_Cp ${1}
1457    RET=0
1458
1459    if [ ${RET} -gt 0 ] ; then
1460      echo "IGCM_sys_Put_Dods : error."
1461      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1462    fi
1463  else
1464    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1465  fi
1466  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1467}
1468
1469##############################################################
1470# REBUILD OPERATOR
1471
1472function IGCM_sys_rebuild {
1473  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1474  if ( $DEBUG_sys ) ; then
1475    echo "IGCM_sys_rebuild :" $@
1476  fi
1477  /home/cont003/p86ipsl/CESIUM/bin/rebuild -f -o $@
1478  if [ $? -gt 0 ] ; then
1479    echo "IGCM_sys_rebuild : erreur ${@}."
1480    IGCM_debug_Exit "rebuild"
1481  fi
1482
1483  IGCM_debug_PopStack "IGCM_sys_rebuild"
1484}
1485
1486function IGCM_sys_rebuild_station {
1487  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1488  typeset i list_opt file_in file_out prefix_invert list_invert
1489  if ( $DEBUG_sys ) ; then
1490    echo "IGCM_sys_rebuild_station :" $@
1491  fi
1492  list_opt=$@
1493
1494  # Invert Axis : t,x -> x,t
1495  #               t,pres,x -> x,t,pres
1496  # So that we can concatenate along x
1497  i=0
1498  for file_in in ${list_opt} ; do
1499    (( i = i + 1))
1500    [ ${i} = 1 ] && file_out=${file_in} && continue
1501    prefix_invert=$( basename ${file_in} .nc )
1502    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1503    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1504  done
1505
1506  # Concatenate
1507  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1508
1509  # Re-ivert file
1510  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1511
1512  # Station re-ordering is too expansive to be run within libICGM
1513  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1514  # This re-ordering must be done "in memory" by the cmorization process
1515  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1516  # BEGIN reordering
1517
1518  # Only LMDZ text output contains the exact ordering of the station.
1519  # We isolate this in the code below:
1520  #  0  38  -157.5000000000000  70.98591549295774
1521  #  0  54  27.49999999999999   67.18309859154928
1522  #  0  56  -62.50000000000001  82.39436619718309
1523  #  0  79  12.49999999999999   78.59154929577466
1524  #  0  116 -165.0000000000000  76.05633802816901
1525  #  0  117 130.0000000000000   70.98591549295774
1526  #  0  118 110.0000000000000   87.46478873239437
1527  #  1  40  4.999999999999995   51.97183098591550
1528#  typeset iStation iProc list_opt file_in file_out prefix_invert
1529#  typeset -Z4 j4
1530#  typeset -Z3 j3
1531
1532#  unset list_opt
1533#  set +A list_opt $@
1534
1535  # Filename after rebuild
1536#  file_out=${list_opt[0]}
1537  # Prefix of output files
1538#  prefix_invert=$( basename ${file_out} .nc )
1539  # Number of procs
1540#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1541
1542#  iProc=0
1543#  while [ ${iProc} -lt ${num_proc} ] ; do
1544    # Array containing Station as a number
1545#    unset proc_stn
1546#    set +A proc_stn $( grep "iophy_mpi rank ip lon lat  $iProc" ${PREFIX}_${Exe_Output} | sed -e "s/iophy_mpi rank ip lon lat //g" | awk ' {print $2}' )
1547    # Number of stations produced by processor proc
1548#    stationLast=${#proc_stn[*]}
1549    # Proc number on 4 digits
1550#    j4=${iProc}
1551    # Init
1552#    iStation=0
1553#    while [ ${iStation} -lt ${stationLast} ] ; do
1554      # Station number on 3 digits
1555#      j3=${proc_stn[${iStation}]}
1556      # Extract station
1557      # Invert Axis : t,x -> x,t
1558      #               t,pres,x -> x,t,pres
1559      # So that we can concatenate along x
1560#      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs -d x,$iStation,$iStation ${prefix_invert}_${j4}.nc ${prefix_invert}_stn_${j3}.nc
1561#      (( iStation = iStation + 1 ))
1562#    done
1563#    (( iProc = iProc + 1 ))
1564#  done
1565
1566  # Concatenate all station along x
1567#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1568
1569  # Re-invert file
1570#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1571
1572  # END reordering
1573
1574  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1575}
1576
1577############################################################
1578# Activate Running Environnment Variables
1579
1580function IGCM_sys_activ_variables {
1581  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1582  if ( $DEBUG_sys ) ; then
1583    echo "IGCM_sys_activ_variables"
1584  fi
1585  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1586}
1587
1588############################################################
1589# Desactivate Running Environnment Variables
1590
1591function IGCM_sys_desactiv_variables {
1592  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1593  if ( $DEBUG_sys ) ; then
1594    echo "IGCM_sys_desactiv_variables"
1595  fi
1596  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1597}
1598
1599############################################################
1600# Build run file
1601
1602function IGCM_sys_build_run_file {
1603  IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1604  if ( $DEBUG_sys ) ; then
1605    echo "IGCM_sys_build_run_file"
1606  fi
1607  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1608}
1609
1610############################################################
1611# Check of space available on temporary filesytems
1612function IGCM_sys_check_quota {
1613    IGCM_debug_PushStack "IGCM_sys_check_quota"
1614    if ( $DEBUG_sys ) ; then
1615        echo "IGCM_sys_check_quota"
1616    fi
1617    IGCM_debug_PopStack "IGCM_sys_check_quota"
1618}
1619
1620##############################################################
1621# NCO OPERATOR
1622
1623function IGCM_sys_ncap2 {
1624  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1625  if ( $DEBUG_sys ) ; then
1626    echo "IGCM_sys_ncap2 :" $@
1627  fi
1628
1629  typeset NB_ESSAI DELAI status i
1630  # number of tentative
1631  NB_ESSAI=3
1632  # time delay between tentative
1633  DELAI=2
1634
1635  i=0
1636  while [ $i -lt $NB_ESSAI ] ; do
1637    ncap2 "$@" > out_rsync 2>&1
1638    status=$?
1639    if [ ${status} -gt 0 ] ; then
1640      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1641      cat out_rsync
1642      \rm out_rsync
1643      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1644    else
1645      \rm out_rsync
1646      break
1647    fi
1648    (( i = i + 1 ))
1649  done
1650
1651  if [ ${status} -gt 0 ] ; then
1652      echo "IGCM_sys_ncap2 : ncap2 error"
1653      IGCM_debug_Exit "ncap2"
1654  fi
1655
1656  IGCM_debug_PopStack "IGCM_sys_ncap2"
1657}
1658
1659function IGCM_sys_ncatted {
1660  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1661  if ( $DEBUG_sys ) ; then
1662    echo "IGCM_sys_ncatted :" $@
1663  fi
1664
1665  typeset NB_ESSAI DELAI status i
1666  # number of tentative
1667  NB_ESSAI=3
1668  # time delay between tentative
1669  DELAI=2
1670
1671  i=0
1672  while [ $i -lt $NB_ESSAI ] ; do
1673    ncatted "$@" > out_rsync 2>&1
1674    status=$?
1675    if [ ${status} -gt 0 ] ; then
1676      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1677      cat out_rsync
1678      \rm out_rsync
1679      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1680    else
1681      \rm out_rsync
1682      break
1683    fi
1684    (( i = i + 1 ))
1685  done
1686
1687  if [ ${status} -gt 0 ] ; then
1688      echo "IGCM_sys_ncatted : ncatted error"
1689      IGCM_debug_Exit "ncatted"
1690  fi
1691
1692  IGCM_debug_PopStack "IGCM_sys_ncatted"
1693}
1694
1695function IGCM_sys_ncbo {
1696  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1697  if ( $DEBUG_sys ) ; then
1698    echo "IGCM_sys_ncbo :" $@
1699  fi
1700
1701  typeset NB_ESSAI DELAI status i
1702  # number of tentative
1703  NB_ESSAI=3
1704  # time delay between tentative
1705  DELAI=2
1706
1707  i=0
1708  while [ $i -lt $NB_ESSAI ] ; do
1709    ncbo $@ > out_rsync 2>&1
1710    status=$?
1711    if [ ${status} -gt 0 ] ; then
1712      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1713      cat out_rsync
1714      \rm out_rsync
1715      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1716    else
1717      \rm out_rsync
1718      break
1719    fi
1720    (( i = i + 1 ))
1721  done
1722
1723  if [ ${status} -gt 0 ] ; then
1724      echo "IGCM_sys_ncbo : ncbo error"
1725      IGCM_debug_Exit "ncbo"
1726  fi
1727
1728  IGCM_debug_PopStack "IGCM_sys_ncbo"
1729}
1730
1731function IGCM_sys_ncdiff {
1732  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1733  if ( $DEBUG_sys ) ; then
1734    echo "IGCM_sys_ncdiff :" $@
1735  fi
1736
1737  typeset NB_ESSAI DELAI status i
1738  # number of tentative
1739  NB_ESSAI=3
1740  # time delay between tentative
1741  DELAI=2
1742
1743  i=0
1744  while [ $i -lt $NB_ESSAI ] ; do
1745    ncdiff $@ > out_rsync 2>&1
1746    status=$?
1747    if [ ${status} -gt 0 ] ; then
1748      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1749      cat out_rsync
1750      \rm out_rsync
1751      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1752    else
1753      \rm out_rsync
1754      break
1755    fi
1756    (( i = i + 1 ))
1757  done
1758
1759  if [ ${status} -gt 0 ] ; then
1760      echo "IGCM_sys_ncdiff : ncdiff error"
1761      IGCM_debug_Exit "ncdiff"
1762  fi
1763
1764  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1765}
1766
1767function IGCM_sys_ncea {
1768  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1769  if ( $DEBUG_sys ) ; then
1770    echo "IGCM_sys_ncea :" $@
1771  fi
1772
1773  typeset NB_ESSAI DELAI status i
1774  # number of tentative
1775  NB_ESSAI=3
1776  # time delay between tentative
1777  DELAI=2
1778
1779  i=0
1780  while [ $i -lt $NB_ESSAI ] ; do
1781    ncea $@ > out_rsync 2>&1
1782    status=$?
1783    if [ ${status} -gt 0 ] ; then
1784      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1785      cat out_rsync
1786      \rm out_rsync
1787      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1788    else
1789      \rm out_rsync
1790      break
1791    fi
1792    (( i = i + 1 ))
1793  done
1794
1795  if [ ${status} -gt 0 ] ; then
1796      echo "IGCM_sys_ncea : ncea error"
1797      IGCM_debug_Exit "ncea"
1798  fi
1799
1800  IGCM_debug_PopStack "IGCM_sys_ncea"
1801}
1802
1803function IGCM_sys_ncecat {
1804  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1805  if ( $DEBUG_sys ) ; then
1806    echo "IGCM_sys_ncecat :" $@
1807  fi
1808
1809  typeset NB_ESSAI DELAI status i
1810  # number of tentative
1811  NB_ESSAI=3
1812  # time delay between tentative
1813  DELAI=2
1814
1815  i=0
1816  while [ $i -lt $NB_ESSAI ] ; do
1817    ncecat $@ > out_rsync 2>&1
1818    status=$?
1819    if [ ${status} -gt 0 ] ; then
1820      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1821      cat out_rsync
1822      \rm out_rsync
1823      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1824    else
1825      \rm out_rsync
1826      break
1827    fi
1828    (( i = i + 1 ))
1829  done
1830
1831  if [ ${status} -gt 0 ] ; then
1832      echo "IGCM_sys_ncecat : ncecat error"
1833      IGCM_debug_Exit "ncecat"
1834  fi
1835
1836  IGCM_debug_PopStack "IGCM_sys_ncecat"
1837}
1838
1839function IGCM_sys_ncflint {
1840  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1841  if ( $DEBUG_sys ) ; then
1842    echo "IGCM_sys_ncflint :" $@
1843  fi
1844
1845  typeset NB_ESSAI DELAI status i
1846  # number of tentative
1847  NB_ESSAI=3
1848  # time delay between tentative
1849  DELAI=2
1850
1851  i=0
1852  while [ $i -lt $NB_ESSAI ] ; do
1853    ncflint $@ > out_rsync 2>&1
1854    status=$?
1855    if [ ${status} -gt 0 ] ; then
1856      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1857      cat out_rsync
1858      \rm out_rsync
1859      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1860    else
1861      \rm out_rsync
1862      break
1863    fi
1864    (( i = i + 1 ))
1865  done
1866
1867  if [ ${status} -gt 0 ] ; then
1868      echo "IGCM_sys_ncflint : ncflint error"
1869      IGCM_debug_Exit "ncflint"
1870  fi
1871
1872  IGCM_debug_PopStack "IGCM_sys_ncflint"
1873}
1874
1875function IGCM_sys_ncks {
1876  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1877  if ( $DEBUG_sys ) ; then
1878    echo "IGCM_sys_ncks :" $@
1879  fi
1880
1881  typeset NB_ESSAI DELAI status i
1882  # number of tentative
1883  NB_ESSAI=3
1884  # time delay between tentative
1885  DELAI=2
1886
1887  i=0
1888  while [ $i -lt $NB_ESSAI ] ; do
1889    ncks $@ > out_rsync 2>&1
1890    status=$?
1891    if [ ${status} -gt 0 ] ; then
1892      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
1893      cat out_rsync
1894      \rm out_rsync
1895      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1896    else
1897      \rm out_rsync
1898      break
1899    fi
1900    (( i = i + 1 ))
1901  done
1902
1903  if [ ${status} -gt 0 ] ; then
1904      echo "IGCM_sys_ncks : ncks error"
1905      IGCM_debug_Exit "ncks"
1906  fi
1907
1908  IGCM_debug_PopStack "IGCM_sys_ncks"
1909}
1910
1911function IGCM_sys_ncpdq {
1912  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1913  if ( $DEBUG_sys ) ; then
1914    echo "IGCM_sys_ncpdq :" $@
1915  fi
1916
1917  typeset NB_ESSAI DELAI status i
1918  # number of tentative
1919  NB_ESSAI=3
1920  # time delay between tentative
1921  DELAI=2
1922
1923  i=0
1924  while [ $i -lt $NB_ESSAI ] ; do
1925    ncpdq $@ > out_rsync 2>&1
1926    status=$?
1927    if [ ${status} -gt 0 ] ; then
1928      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
1929      cat out_rsync
1930      \rm out_rsync
1931      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1932    else
1933      \rm out_rsync
1934      break
1935    fi
1936    (( i = i + 1 ))
1937  done
1938
1939  if [ ${status} -gt 0 ] ; then
1940      echo "IGCM_sys_ncpdq : ncpdq error"
1941      IGCM_debug_Exit "ncpdq"
1942  fi
1943
1944  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1945}
1946
1947function IGCM_sys_ncra {
1948  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1949  if ( $DEBUG_sys ) ; then
1950    echo "IGCM_sys_ncra :" $@
1951  fi
1952
1953  typeset NB_ESSAI DELAI status i
1954  # number of tentative
1955  NB_ESSAI=3
1956  # time delay between tentative
1957  DELAI=2
1958
1959  i=0
1960  while [ $i -lt $NB_ESSAI ] ; do
1961    ncra $@ > out_rsync 2>&1
1962    status=$?
1963    if [ ${status} -gt 0 ] ; then
1964      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
1965      cat out_rsync
1966      \rm out_rsync
1967      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1968    else
1969      \rm out_rsync
1970      break
1971    fi
1972    (( i = i + 1 ))
1973  done
1974
1975  if [ ${status} -gt 0 ] ; then
1976      echo "IGCM_sys_ncra : ncra error"
1977      IGCM_debug_Exit "ncra"
1978  fi
1979
1980  IGCM_debug_PopStack "IGCM_sys_ncra"
1981}
1982
1983function IGCM_sys_ncrcat {
1984  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1985  if ( $DEBUG_sys ) ; then
1986    echo "IGCM_sys_ncrcat :" $@
1987  fi
1988
1989  typeset NB_ESSAI DELAI status i
1990  # number of tentative
1991  NB_ESSAI=3
1992  # time delay between tentative
1993  DELAI=2
1994
1995  i=0
1996  while [ $i -lt $NB_ESSAI ] ; do
1997    ncrcat $@ > out_rsync 2>&1
1998    status=$?
1999    if [ ${status} -gt 0 ] ; then
2000      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2001      cat out_rsync
2002      \rm out_rsync
2003      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2004    else
2005      \rm out_rsync
2006      break
2007    fi
2008    (( i = i + 1 ))
2009  done
2010
2011  if [ ${status} -gt 0 ] ; then
2012      echo "IGCM_sys_ncrcat : ncrcat error"
2013      #IGCM_debug_Exit "ncrcat"
2014  fi
2015
2016  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2017}
2018
2019function IGCM_sys_ncrename {
2020  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2021  if ( $DEBUG_sys ) ; then
2022    echo "IGCM_sys_ncrename :" $@
2023  fi
2024
2025  typeset NB_ESSAI DELAI status i
2026  # number of tentative
2027  NB_ESSAI=3
2028  # time delay between tentative
2029  DELAI=2
2030
2031  i=0
2032  while [ $i -lt $NB_ESSAI ] ; do
2033    ncrename $@ > out_rsync 2>&1
2034    status=$?
2035    if [ ${status} -gt 0 ] ; then
2036      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2037      cat out_rsync
2038      \rm out_rsync
2039      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2040    else
2041      \rm out_rsync
2042      break
2043    fi
2044    (( i = i + 1 ))
2045  done
2046
2047  if [ ${status} -gt 0 ] ; then
2048      echo "IGCM_sys_ncrename : ncrename error"
2049      IGCM_debug_Exit "ncrename"
2050  fi
2051
2052  IGCM_debug_PopStack "IGCM_sys_ncrename"
2053}
2054
2055function IGCM_sys_ncwa {
2056  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2057  if ( $DEBUG_sys ) ; then
2058    echo "IGCM_sys_ncwa :" $@
2059  fi
2060
2061  typeset NB_ESSAI DELAI status i
2062  # number of tentative
2063  NB_ESSAI=3
2064  # time delay between tentative
2065  DELAI=2
2066
2067  i=0
2068  while [ $i -lt $NB_ESSAI ] ; do
2069    ncwa $@ > out_rsync 2>&1
2070    status=$?
2071    if [ ${status} -gt 0 ] ; then
2072      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2073      cat out_rsync
2074      \rm out_rsync
2075      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2076    else
2077      \rm out_rsync
2078      break
2079    fi
2080    (( i = i + 1 ))
2081  done
2082
2083  if [ ${status} -gt 0 ] ; then
2084      echo "IGCM_sys_ncwa : ncwa error"
2085      IGCM_debug_Exit "ncwa"
2086  fi
2087
2088  IGCM_debug_PopStack "IGCM_sys_ncwa"
2089}
2090
2091##############################################################
2092# CDO OPERATOR
2093
2094function IGCM_sys_cdo {
2095  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2096  if ( $DEBUG_sys ) ; then
2097    echo "IGCM_sys_cdo :" $@
2098  fi
2099
2100  typeset status
2101
2102  \cdo $@ > out_rsync 2>&1
2103  status=$?
2104  if [ ${status} -gt 0 ] ; then
2105    echo "IGCM_sys_cdo : error code ${status}"
2106    cat out_rsync
2107    \rm out_rsync
2108    IGCM_debug_PopStack "IGCM_sys_cdo"
2109    return 1
2110  else
2111    IGCM_debug_PopStack "IGCM_sys_cdo"
2112    return 0
2113  fi
2114
2115  IGCM_debug_PopStack "IGCM_sys_cdo"
2116}
Note: See TracBrowser for help on using the repository browser.