source: tags/libIGCM_v2.0/libIGCM_sys/libIGCM_sys_cesium.ksh @ 1170

Last change on this file since 1170 was 801, checked in by sdipsl, 11 years ago
  • Some adaptation so as to find and prepare tared restart on Ada.
  • Property svn:keywords set to Revision Author Date
File size: 57.3 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_PrepareTaredRestart
1028#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1029#D-* Examples:
1030#D-
1031function IGCM_sys_PrepareTaredRestart {
1032  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1033  echo $1
1034  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1035}
1036
1037#D-#==================================================
1038#D-function IGCM_sys_Put_Out
1039#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1040#D-* Examples:
1041#D-
1042function IGCM_sys_Put_Out {
1043  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1044  if ( $DEBUG_sys ) ; then
1045    echo "IGCM_sys_Put_Out :" $@
1046  fi
1047
1048  typeset NB_ESSAI DELAI RET i exist skip
1049
1050  # number of tentative
1051  NB_ESSAI=3
1052  # time delay between tentative
1053  DELAI=2
1054
1055  if [ $DRYRUN = 0 ]; then
1056    if [ ! -f ${1} ] ; then
1057      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1058      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1059      return 1
1060    fi
1061    #
1062    IGCM_sys_MkdirArchive $( dirname $2 )
1063    #
1064
1065    #=====================================================
1066    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1067    #=====================================================
1068
1069    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1070    #if [ $? -eq 0 ] ; then
1071    #    typeset WORKPATH FILEPATH
1072    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1073    #    IGCM_sys_MkdirWork ${WORKPATH}
1074    #    FILEPATH=${WORKPATH}/$( basename $2 )
1075    #    #
1076    #    IGCM_sys_Cp ${1} ${FILEPATH}
1077    #fi
1078
1079    if [ X${JobType} = XRUN ] ; then
1080      if [ X${3} = X ] ; then
1081        IGCM_sys_Chmod 444 ${1}
1082      fi
1083    fi
1084    #
1085
1086    exist=false
1087    skip=false
1088    if [ -f $2 ] ; then
1089      IGCM_debug_Print 1 "$2 already exist"
1090      #dmget $2
1091      ccc_hsm get $2
1092      exist=true
1093      if [ "X$( diff $1 $2 )" = X ] ; then
1094        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1095        skip=true
1096      else
1097        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1098        skip=false
1099      fi
1100    fi
1101    #
1102    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1103      IGCM_sys_Chmod u+w $2
1104    fi
1105
1106    if [ X${skip} = Xfalse ] ; then
1107      (( i = 0 ))
1108      while [ $i -lt $NB_ESSAI ] ; do
1109        # USUAL WAY
1110        \cp $1 $2 > out_rsync 2>&1
1111        RET=$?
1112        if [ ${RET} -gt 0 ]; then
1113          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed ${i}/${NB_ESSAI}"
1114          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1115          sleep $DELAI
1116        else
1117          break
1118        fi
1119        (( i = i + 1 ))
1120      done
1121    fi
1122
1123#       #RSYNC WITH NETWORK RSH CALL
1124#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
1125#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
1126
1127#       #RSYNC WITH NFS USE
1128#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1129#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1130
1131#       RET=$?
1132#       IGCM_sys_Rsync_out $RET
1133
1134#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1135#       (( RET=RET+$? ))
1136
1137    if [ ${RET} -gt 0 ] ; then
1138      echo "IGCM_sys_Put_Out : error."
1139      cat out_rsync
1140      IGCM_debug_Exit "IGCM_sys_Put_Out"
1141    else
1142      \rm out_rsync
1143    fi
1144  else
1145    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1146  fi
1147  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1148  return 0
1149}
1150
1151#D-#==================================================
1152#D-function IGCM_sys_Get
1153#D-* Purpose: Get a file from ${ARCHIVE}
1154#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1155#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1156function IGCM_sys_Get {
1157  IGCM_debug_PushStack "IGCM_sys_Get" $@
1158
1159  typeset DEST RET dm_liste ifile target file_work
1160  typeset NB_ESSAI DELAI status i
1161
1162  if ( $DEBUG_sys ) ; then
1163    echo "IGCM_sys_Get :" $@
1164  fi
1165
1166  # number of tentative
1167  NB_ESSAI=3
1168  # time delay between tentative
1169  DELAI=2
1170
1171  if [ $DRYRUN -le 2 ]; then
1172    if [ X${1} = X'/l' ] ; then
1173      # test if the first file is present in the old computation :
1174      eval set +A dm_liste \${${2}}
1175    else
1176      eval set +A dm_liste ${1}
1177    fi
1178    eval DEST=\${${#}}
1179
1180    #=====================================================
1181    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1182    #=====================================================
1183
1184    # Is it an R_OUT file (not R_IN) ?
1185    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1186    #if [ $? -eq 0 ] ; then
1187    #    # Yes  ? then we try to get it in SCRATCHDIR
1188    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1189    #    if [ -f ${file_work[0]} ] ; then
1190    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1191    #   IGCM_debug_PopStack "IGCM_sys_Get"
1192    #   return
1193    #    fi
1194    #fi
1195
1196    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1197    RET=$?
1198    if [ ${RET} -gt 0 ] ; then
1199      echo "WARNING IGCM_sys_Get : demigration error."
1200      cat out_rsync
1201      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1202    fi
1203
1204    #if [ ${RET} -gt 0 ] ; then
1205    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1206    #   cat out_rsync
1207    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1208    #   sleep 30
1209    #   echo "We try another time"
1210    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1211    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1212    #   RET=$?
1213    #   if [ ${RET} -gt 0 ] ; then
1214    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1215    #       cat out_rsync
1216    #       IGCM_debug_Exit "IGCM_sys_Get"
1217    #   fi
1218    #    else
1219    #   echo "ERROR IGCM_sys_Get : demigration error :"
1220    #   cat out_rsync
1221    #   IGCM_debug_Exit "IGCM_sys_Get"
1222    #    fi
1223    #fi
1224
1225    #USUAL WAY
1226    if [ X${1} = X'/l' ] ; then
1227      (( RET=0 ))
1228      for target in ${dm_liste[*]} ; do
1229        local_file=$( basename ${target} )
1230        (( i = 0 ))
1231        # test if the target file is present before the loop
1232        IGCM_sys_TestFileArchive ${target}
1233        RET=$?
1234        if [ ${RET} -gt 0 ] ; then
1235          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1236          IGCM_debug_Exit "IGCM_sys_Get"
1237        else
1238          while [ $i -lt $NB_ESSAI ] ; do
1239            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1240            status=$?
1241            if [ ${status} -gt 0 ]; then
1242              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed ${i}/${NB_ESSAI}"
1243              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1244              sleep $DELAI
1245            else
1246              break
1247            fi
1248            (( i = i + 1 ))
1249          done
1250          (( RET = RET + status ))
1251        fi
1252      done
1253    else
1254      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1255      RET=$?
1256    fi
1257
1258#       #RSYNC WITH NETWORK SSH CALL
1259#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1260#       ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1261
1262#       #RSYNC WITH NFS USE
1263#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1264#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1265
1266#       RET=$?
1267#       IGCM_sys_Rsync_out $RET
1268
1269#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1270#       (( RET=RET+$? ))
1271
1272    if [ ${RET} -gt 0 ] ; then
1273      echo "IGCM_sys_Get : copy error."
1274      cat out_rsync
1275      IGCM_debug_Exit "IGCM_sys_Get"
1276    else
1277      \rm out_rsync
1278    fi
1279  else
1280    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1281  fi
1282  IGCM_debug_PopStack "IGCM_sys_Get"
1283}
1284
1285#D-#==================================================
1286#D-function IGCM_sys_GetBuffer
1287#D-* Purpose: Get a file from ${SCRATCHDIR}
1288#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1289#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1290function IGCM_sys_GetBuffer {
1291  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1292
1293  typeset DEST RET buf_liste ifile target file_work
1294
1295  if ( $DEBUG_sys ) ; then
1296    echo "IGCM_sys_GetBuffer :" $@
1297  fi
1298  if [ $DRYRUN -le 2 ]; then
1299    if [ X${1} = X'/l' ] ; then
1300      # test if the first file is present in the old computation :
1301      eval set +A buf_liste \${${2}}
1302    else
1303      eval set +A buf_liste ${1}
1304    fi
1305    eval DEST=\${${#}}
1306
1307    #USUAL WAY
1308    if [ X${1} = X'/l' ] ; then
1309      (( RET=0 ))
1310      for target in ${buf_liste[*]} ; do
1311        local_file=$( basename ${target} )
1312        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1313        (( RET = RET + $? ))
1314      done
1315    else
1316      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1317      RET=$?
1318    fi
1319
1320    if [ ${RET} -gt 0 ] ; then
1321      echo "IGCM_sys_GetBuffer : copy error."
1322      cat out_rsync
1323      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1324    else
1325      \rm out_rsync
1326    fi
1327  else
1328    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1329  fi
1330  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1331}
1332
1333#D-#==================================================
1334#D-function IGCM_sys_GetDate_FichWork
1335#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1336#D-* Examples:
1337#D-
1338function IGCM_sys_GetDate_FichWork {
1339  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1340  if ( $DEBUG_sys ) ; then
1341    echo "IGCM_sys_GetDate_FichWork :" $@
1342  fi
1343  # donne la date filesys d'un fichier sur la machine work
1344  IGCM_debug_PopStack "IGCM_sys_FichWork"
1345}
1346
1347#D-#==================================================
1348#D-function IGCM_sys_GetDate_FichArchive
1349#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1350#D-* Examples:
1351#D-
1352function IGCM_sys_GetDate_FichArchive {
1353  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1354  if ( $DEBUG_sys ) ; then
1355    echo "IGCM_sys_GetDate_FichArchive :" $@
1356  fi
1357  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1358}
1359
1360#D-#==================================================
1361#D-function IGCM_sys_Dods_Rm
1362#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1363#D-* Examples:
1364#D-
1365function IGCM_sys_Dods_Rm {
1366  if ( $DEBUG_sys ) ; then
1367    echo "IGCM_sys_Dods_Rm :" $@
1368  fi
1369  typeset RET
1370  RET=0
1371  if [ $DRYRUN = 0 ]; then
1372
1373#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1374#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1375#      echo "Nothing has been done."
1376#      return
1377#    fi
1378
1379    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1380    RET=$?
1381
1382#       if [ ${RET} -gt 0 ] ; then
1383#           echo "IGCM_sys_Dods_Rm : error."
1384#           cat out_dods_rm
1385#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1386#       else
1387#           rm out_dods_rm
1388#       fi
1389
1390  else
1391    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1392  fi
1393  return $RET
1394}
1395
1396#D-#==================================================
1397#D-function IGCM_sys_Dods_Cp
1398#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1399#D-* Examples:
1400#D-
1401function IGCM_sys_Dods_Cp {
1402  if ( $DEBUG_sys ) ; then
1403    echo "IGCM_sys_Dods_Cp :" $@
1404  fi
1405  typeset RET
1406  RET=0
1407  if [ $DRYRUN = 0 ]; then
1408
1409#    if [ ! -d ${R_SAVE}/${1} ] ; then
1410#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1411#      echo "Nothing has been done."
1412#      return
1413#    fi
1414
1415    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1416    RET=$?
1417
1418#       if [ ${RET} -gt 0 ] ; then
1419#           echo "IGCM_sys_Dods_Cp : error."
1420#           cat out_dods_cp
1421#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1422#       else
1423#           rm out_dods_cp
1424#       fi
1425
1426  else
1427    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1428  fi
1429  return $RET
1430}
1431
1432#D-#==================================================
1433#D-function IGCM_sys_Put_Dods
1434#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1435#D-* Examples:
1436#D-
1437function IGCM_sys_Put_Dods {
1438  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1439  if ( $DEBUG_sys ) ; then
1440    echo "IGCM_sys_Put_Dods :" $@
1441  fi
1442  typeset RET
1443  if [ $DRYRUN = 0 ]; then
1444    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1445      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1446      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1447      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1448      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1449      return
1450    fi
1451
1452    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1453      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1454      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1455      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1456      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1457      return
1458    fi
1459    #
1460    if [ -d ${R_SAVE}/${1} ] ; then
1461      cd ${R_SAVE}
1462    elif [ -d ${R_FIGR}/${1} ] ; then
1463      cd ${R_FIGR}
1464    fi
1465
1466    IGCM_sys_Dods_Rm ${1}
1467    IGCM_sys_Dods_Cp ${1}
1468    RET=0
1469
1470    if [ ${RET} -gt 0 ] ; then
1471      echo "IGCM_sys_Put_Dods : error."
1472      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1473    fi
1474  else
1475    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1476  fi
1477  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1478}
1479
1480##############################################################
1481# REBUILD OPERATOR
1482
1483function IGCM_sys_rebuild {
1484  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1485  if ( $DEBUG_sys ) ; then
1486    echo "IGCM_sys_rebuild :" $@
1487  fi
1488  /home/cont003/p86ipsl/CESIUM/bin/rebuild -f -o $@
1489  if [ $? -gt 0 ] ; then
1490    echo "IGCM_sys_rebuild : erreur ${@}."
1491    IGCM_debug_Exit "rebuild"
1492  fi
1493
1494  IGCM_debug_PopStack "IGCM_sys_rebuild"
1495}
1496
1497function IGCM_sys_rebuild_station {
1498  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1499  typeset i list_opt file_in file_out prefix_invert list_invert
1500  if ( $DEBUG_sys ) ; then
1501    echo "IGCM_sys_rebuild_station :" $@
1502  fi
1503  list_opt=$@
1504
1505  # Invert Axis : t,x -> x,t
1506  #               t,pres,x -> x,t,pres
1507  # So that we can concatenate along x
1508  i=0
1509  for file_in in ${list_opt} ; do
1510    (( i = i + 1))
1511    [ ${i} = 1 ] && file_out=${file_in} && continue
1512    prefix_invert=$( basename ${file_in} .nc )
1513    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1514    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1515  done
1516
1517  # Concatenate
1518  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1519
1520  # Re-ivert file
1521  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1522
1523  # Station re-ordering is too expansive to be run within libICGM
1524  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1525  # This re-ordering must be done "in memory" by the cmorization process
1526  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1527  # BEGIN reordering
1528
1529  # Only LMDZ text output contains the exact ordering of the station.
1530  # We isolate this in the code below:
1531  #  0  38  -157.5000000000000  70.98591549295774
1532  #  0  54  27.49999999999999   67.18309859154928
1533  #  0  56  -62.50000000000001  82.39436619718309
1534  #  0  79  12.49999999999999   78.59154929577466
1535  #  0  116 -165.0000000000000  76.05633802816901
1536  #  0  117 130.0000000000000   70.98591549295774
1537  #  0  118 110.0000000000000   87.46478873239437
1538  #  1  40  4.999999999999995   51.97183098591550
1539#  typeset iStation iProc list_opt file_in file_out prefix_invert
1540#  typeset -Z4 j4
1541#  typeset -Z3 j3
1542
1543#  unset list_opt
1544#  set +A list_opt $@
1545
1546  # Filename after rebuild
1547#  file_out=${list_opt[0]}
1548  # Prefix of output files
1549#  prefix_invert=$( basename ${file_out} .nc )
1550  # Number of procs
1551#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1552
1553#  iProc=0
1554#  while [ ${iProc} -lt ${num_proc} ] ; do
1555    # Array containing Station as a number
1556#    unset proc_stn
1557#    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}' )
1558    # Number of stations produced by processor proc
1559#    stationLast=${#proc_stn[*]}
1560    # Proc number on 4 digits
1561#    j4=${iProc}
1562    # Init
1563#    iStation=0
1564#    while [ ${iStation} -lt ${stationLast} ] ; do
1565      # Station number on 3 digits
1566#      j3=${proc_stn[${iStation}]}
1567      # Extract station
1568      # Invert Axis : t,x -> x,t
1569      #               t,pres,x -> x,t,pres
1570      # So that we can concatenate along x
1571#      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
1572#      (( iStation = iStation + 1 ))
1573#    done
1574#    (( iProc = iProc + 1 ))
1575#  done
1576
1577  # Concatenate all station along x
1578#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1579
1580  # Re-invert file
1581#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1582
1583  # END reordering
1584
1585  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1586}
1587
1588############################################################
1589# Activate Running Environnment Variables
1590
1591function IGCM_sys_activ_variables {
1592  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1593  if ( $DEBUG_sys ) ; then
1594    echo "IGCM_sys_activ_variables"
1595  fi
1596  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1597}
1598
1599############################################################
1600# Desactivate Running Environnment Variables
1601
1602function IGCM_sys_desactiv_variables {
1603  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1604  if ( $DEBUG_sys ) ; then
1605    echo "IGCM_sys_desactiv_variables"
1606  fi
1607  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1608}
1609
1610############################################################
1611# Build run file
1612
1613function IGCM_sys_build_run_file {
1614  IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1615  if ( $DEBUG_sys ) ; then
1616    echo "IGCM_sys_build_run_file"
1617  fi
1618  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1619}
1620
1621############################################################
1622# Check of space available on temporary filesytems
1623function IGCM_sys_check_quota {
1624    IGCM_debug_PushStack "IGCM_sys_check_quota"
1625    if ( $DEBUG_sys ) ; then
1626        echo "IGCM_sys_check_quota"
1627    fi
1628    IGCM_debug_PopStack "IGCM_sys_check_quota"
1629}
1630
1631##############################################################
1632# NCO OPERATOR
1633
1634function IGCM_sys_ncap2 {
1635  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1636  if ( $DEBUG_sys ) ; then
1637    echo "IGCM_sys_ncap2 :" $@
1638  fi
1639
1640  typeset NB_ESSAI DELAI status i
1641  # number of tentative
1642  NB_ESSAI=3
1643  # time delay between tentative
1644  DELAI=2
1645
1646  i=0
1647  while [ $i -lt $NB_ESSAI ] ; do
1648    ncap2 "$@" > out_rsync 2>&1
1649    status=$?
1650    if [ ${status} -gt 0 ] ; then
1651      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1652      cat out_rsync
1653      \rm out_rsync
1654      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1655    else
1656      \rm out_rsync
1657      break
1658    fi
1659    (( i = i + 1 ))
1660  done
1661
1662  if [ ${status} -gt 0 ] ; then
1663      echo "IGCM_sys_ncap2 : ncap2 error"
1664      IGCM_debug_Exit "ncap2"
1665  fi
1666
1667  IGCM_debug_PopStack "IGCM_sys_ncap2"
1668}
1669
1670function IGCM_sys_ncatted {
1671  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1672  if ( $DEBUG_sys ) ; then
1673    echo "IGCM_sys_ncatted :" $@
1674  fi
1675
1676  typeset NB_ESSAI DELAI status i
1677  # number of tentative
1678  NB_ESSAI=3
1679  # time delay between tentative
1680  DELAI=2
1681
1682  i=0
1683  while [ $i -lt $NB_ESSAI ] ; do
1684    ncatted "$@" > out_rsync 2>&1
1685    status=$?
1686    if [ ${status} -gt 0 ] ; then
1687      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1688      cat out_rsync
1689      \rm out_rsync
1690      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1691    else
1692      \rm out_rsync
1693      break
1694    fi
1695    (( i = i + 1 ))
1696  done
1697
1698  if [ ${status} -gt 0 ] ; then
1699      echo "IGCM_sys_ncatted : ncatted error"
1700      IGCM_debug_Exit "ncatted"
1701  fi
1702
1703  IGCM_debug_PopStack "IGCM_sys_ncatted"
1704}
1705
1706function IGCM_sys_ncbo {
1707  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1708  if ( $DEBUG_sys ) ; then
1709    echo "IGCM_sys_ncbo :" $@
1710  fi
1711
1712  typeset NB_ESSAI DELAI status i
1713  # number of tentative
1714  NB_ESSAI=3
1715  # time delay between tentative
1716  DELAI=2
1717
1718  i=0
1719  while [ $i -lt $NB_ESSAI ] ; do
1720    ncbo $@ > out_rsync 2>&1
1721    status=$?
1722    if [ ${status} -gt 0 ] ; then
1723      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1724      cat out_rsync
1725      \rm out_rsync
1726      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1727    else
1728      \rm out_rsync
1729      break
1730    fi
1731    (( i = i + 1 ))
1732  done
1733
1734  if [ ${status} -gt 0 ] ; then
1735      echo "IGCM_sys_ncbo : ncbo error"
1736      IGCM_debug_Exit "ncbo"
1737  fi
1738
1739  IGCM_debug_PopStack "IGCM_sys_ncbo"
1740}
1741
1742function IGCM_sys_ncdiff {
1743  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1744  if ( $DEBUG_sys ) ; then
1745    echo "IGCM_sys_ncdiff :" $@
1746  fi
1747
1748  typeset NB_ESSAI DELAI status i
1749  # number of tentative
1750  NB_ESSAI=3
1751  # time delay between tentative
1752  DELAI=2
1753
1754  i=0
1755  while [ $i -lt $NB_ESSAI ] ; do
1756    ncdiff $@ > out_rsync 2>&1
1757    status=$?
1758    if [ ${status} -gt 0 ] ; then
1759      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1760      cat out_rsync
1761      \rm out_rsync
1762      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1763    else
1764      \rm out_rsync
1765      break
1766    fi
1767    (( i = i + 1 ))
1768  done
1769
1770  if [ ${status} -gt 0 ] ; then
1771      echo "IGCM_sys_ncdiff : ncdiff error"
1772      IGCM_debug_Exit "ncdiff"
1773  fi
1774
1775  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1776}
1777
1778function IGCM_sys_ncea {
1779  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1780  if ( $DEBUG_sys ) ; then
1781    echo "IGCM_sys_ncea :" $@
1782  fi
1783
1784  typeset NB_ESSAI DELAI status i
1785  # number of tentative
1786  NB_ESSAI=3
1787  # time delay between tentative
1788  DELAI=2
1789
1790  i=0
1791  while [ $i -lt $NB_ESSAI ] ; do
1792    ncea $@ > out_rsync 2>&1
1793    status=$?
1794    if [ ${status} -gt 0 ] ; then
1795      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1796      cat out_rsync
1797      \rm out_rsync
1798      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1799    else
1800      \rm out_rsync
1801      break
1802    fi
1803    (( i = i + 1 ))
1804  done
1805
1806  if [ ${status} -gt 0 ] ; then
1807      echo "IGCM_sys_ncea : ncea error"
1808      IGCM_debug_Exit "ncea"
1809  fi
1810
1811  IGCM_debug_PopStack "IGCM_sys_ncea"
1812}
1813
1814function IGCM_sys_ncecat {
1815  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1816  if ( $DEBUG_sys ) ; then
1817    echo "IGCM_sys_ncecat :" $@
1818  fi
1819
1820  typeset NB_ESSAI DELAI status i
1821  # number of tentative
1822  NB_ESSAI=3
1823  # time delay between tentative
1824  DELAI=2
1825
1826  i=0
1827  while [ $i -lt $NB_ESSAI ] ; do
1828    ncecat $@ > out_rsync 2>&1
1829    status=$?
1830    if [ ${status} -gt 0 ] ; then
1831      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1832      cat out_rsync
1833      \rm out_rsync
1834      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1835    else
1836      \rm out_rsync
1837      break
1838    fi
1839    (( i = i + 1 ))
1840  done
1841
1842  if [ ${status} -gt 0 ] ; then
1843      echo "IGCM_sys_ncecat : ncecat error"
1844      IGCM_debug_Exit "ncecat"
1845  fi
1846
1847  IGCM_debug_PopStack "IGCM_sys_ncecat"
1848}
1849
1850function IGCM_sys_ncflint {
1851  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1852  if ( $DEBUG_sys ) ; then
1853    echo "IGCM_sys_ncflint :" $@
1854  fi
1855
1856  typeset NB_ESSAI DELAI status i
1857  # number of tentative
1858  NB_ESSAI=3
1859  # time delay between tentative
1860  DELAI=2
1861
1862  i=0
1863  while [ $i -lt $NB_ESSAI ] ; do
1864    ncflint $@ > out_rsync 2>&1
1865    status=$?
1866    if [ ${status} -gt 0 ] ; then
1867      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1868      cat out_rsync
1869      \rm out_rsync
1870      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1871    else
1872      \rm out_rsync
1873      break
1874    fi
1875    (( i = i + 1 ))
1876  done
1877
1878  if [ ${status} -gt 0 ] ; then
1879      echo "IGCM_sys_ncflint : ncflint error"
1880      IGCM_debug_Exit "ncflint"
1881  fi
1882
1883  IGCM_debug_PopStack "IGCM_sys_ncflint"
1884}
1885
1886function IGCM_sys_ncks {
1887  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1888  if ( $DEBUG_sys ) ; then
1889    echo "IGCM_sys_ncks :" $@
1890  fi
1891
1892  typeset NB_ESSAI DELAI status i
1893  # number of tentative
1894  NB_ESSAI=3
1895  # time delay between tentative
1896  DELAI=2
1897
1898  i=0
1899  while [ $i -lt $NB_ESSAI ] ; do
1900    ncks $@ > out_rsync 2>&1
1901    status=$?
1902    if [ ${status} -gt 0 ] ; then
1903      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
1904      cat out_rsync
1905      \rm out_rsync
1906      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1907    else
1908      \rm out_rsync
1909      break
1910    fi
1911    (( i = i + 1 ))
1912  done
1913
1914  if [ ${status} -gt 0 ] ; then
1915      echo "IGCM_sys_ncks : ncks error"
1916      IGCM_debug_Exit "ncks"
1917  fi
1918
1919  IGCM_debug_PopStack "IGCM_sys_ncks"
1920}
1921
1922function IGCM_sys_ncpdq {
1923  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1924  if ( $DEBUG_sys ) ; then
1925    echo "IGCM_sys_ncpdq :" $@
1926  fi
1927
1928  typeset NB_ESSAI DELAI status i
1929  # number of tentative
1930  NB_ESSAI=3
1931  # time delay between tentative
1932  DELAI=2
1933
1934  i=0
1935  while [ $i -lt $NB_ESSAI ] ; do
1936    ncpdq $@ > out_rsync 2>&1
1937    status=$?
1938    if [ ${status} -gt 0 ] ; then
1939      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
1940      cat out_rsync
1941      \rm out_rsync
1942      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1943    else
1944      \rm out_rsync
1945      break
1946    fi
1947    (( i = i + 1 ))
1948  done
1949
1950  if [ ${status} -gt 0 ] ; then
1951      echo "IGCM_sys_ncpdq : ncpdq error"
1952      IGCM_debug_Exit "ncpdq"
1953  fi
1954
1955  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1956}
1957
1958function IGCM_sys_ncra {
1959  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1960  if ( $DEBUG_sys ) ; then
1961    echo "IGCM_sys_ncra :" $@
1962  fi
1963
1964  typeset NB_ESSAI DELAI status i
1965  # number of tentative
1966  NB_ESSAI=3
1967  # time delay between tentative
1968  DELAI=2
1969
1970  i=0
1971  while [ $i -lt $NB_ESSAI ] ; do
1972    ncra $@ > out_rsync 2>&1
1973    status=$?
1974    if [ ${status} -gt 0 ] ; then
1975      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
1976      cat out_rsync
1977      \rm out_rsync
1978      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1979    else
1980      \rm out_rsync
1981      break
1982    fi
1983    (( i = i + 1 ))
1984  done
1985
1986  if [ ${status} -gt 0 ] ; then
1987      echo "IGCM_sys_ncra : ncra error"
1988      IGCM_debug_Exit "ncra"
1989  fi
1990
1991  IGCM_debug_PopStack "IGCM_sys_ncra"
1992}
1993
1994function IGCM_sys_ncrcat {
1995  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1996  if ( $DEBUG_sys ) ; then
1997    echo "IGCM_sys_ncrcat :" $@
1998  fi
1999
2000  typeset NB_ESSAI DELAI status i
2001  # number of tentative
2002  NB_ESSAI=3
2003  # time delay between tentative
2004  DELAI=2
2005
2006  i=0
2007  while [ $i -lt $NB_ESSAI ] ; do
2008    ncrcat $@ > out_rsync 2>&1
2009    status=$?
2010    if [ ${status} -gt 0 ] ; then
2011      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2012      cat out_rsync
2013      \rm out_rsync
2014      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2015    else
2016      \rm out_rsync
2017      break
2018    fi
2019    (( i = i + 1 ))
2020  done
2021
2022  if [ ${status} -gt 0 ] ; then
2023      echo "IGCM_sys_ncrcat : ncrcat error"
2024      #IGCM_debug_Exit "ncrcat"
2025  fi
2026
2027  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2028}
2029
2030function IGCM_sys_ncrename {
2031  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2032  if ( $DEBUG_sys ) ; then
2033    echo "IGCM_sys_ncrename :" $@
2034  fi
2035
2036  typeset NB_ESSAI DELAI status i
2037  # number of tentative
2038  NB_ESSAI=3
2039  # time delay between tentative
2040  DELAI=2
2041
2042  i=0
2043  while [ $i -lt $NB_ESSAI ] ; do
2044    ncrename $@ > out_rsync 2>&1
2045    status=$?
2046    if [ ${status} -gt 0 ] ; then
2047      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2048      cat out_rsync
2049      \rm out_rsync
2050      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2051    else
2052      \rm out_rsync
2053      break
2054    fi
2055    (( i = i + 1 ))
2056  done
2057
2058  if [ ${status} -gt 0 ] ; then
2059      echo "IGCM_sys_ncrename : ncrename error"
2060      IGCM_debug_Exit "ncrename"
2061  fi
2062
2063  IGCM_debug_PopStack "IGCM_sys_ncrename"
2064}
2065
2066function IGCM_sys_ncwa {
2067  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2068  if ( $DEBUG_sys ) ; then
2069    echo "IGCM_sys_ncwa :" $@
2070  fi
2071
2072  typeset NB_ESSAI DELAI status i
2073  # number of tentative
2074  NB_ESSAI=3
2075  # time delay between tentative
2076  DELAI=2
2077
2078  i=0
2079  while [ $i -lt $NB_ESSAI ] ; do
2080    ncwa $@ > out_rsync 2>&1
2081    status=$?
2082    if [ ${status} -gt 0 ] ; then
2083      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2084      cat out_rsync
2085      \rm out_rsync
2086      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2087    else
2088      \rm out_rsync
2089      break
2090    fi
2091    (( i = i + 1 ))
2092  done
2093
2094  if [ ${status} -gt 0 ] ; then
2095      echo "IGCM_sys_ncwa : ncwa error"
2096      IGCM_debug_Exit "ncwa"
2097  fi
2098
2099  IGCM_debug_PopStack "IGCM_sys_ncwa"
2100}
2101
2102##############################################################
2103# CDO OPERATOR
2104
2105function IGCM_sys_cdo {
2106  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2107  if ( $DEBUG_sys ) ; then
2108    echo "IGCM_sys_cdo :" $@
2109  fi
2110
2111  typeset status
2112
2113  \cdo $@ > out_rsync 2>&1
2114  status=$?
2115  if [ ${status} -gt 0 ] ; then
2116    echo "IGCM_sys_cdo : error code ${status}"
2117    cat out_rsync
2118    \rm out_rsync
2119    IGCM_debug_PopStack "IGCM_sys_cdo"
2120    return 1
2121  else
2122    IGCM_debug_PopStack "IGCM_sys_cdo"
2123    return 0
2124  fi
2125
2126  IGCM_debug_PopStack "IGCM_sys_cdo"
2127}
Note: See TracBrowser for help on using the repository browser.