source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh @ 900

Last change on this file since 900 was 900, checked in by labetoulle, 11 years ago

Remove suffix ${CumulPeriod?} from ${JobName?} when resubmitting (#144).

  • Property svn:keywords set to Revision Author Date
File size: 82.7 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.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 Curie
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 |            |         |                           |
46# |          |  Chmod 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# $hostname of the MASTER job
70typeset MASTER=curie
71# add default project on curie
72typeset DEFAULT_PROJECT=gen0826
73
74#D-
75#D-#==================================================
76#D-Program used in libIGCM
77#D-#==================================================
78
79# Submit command
80typeset SUBMIT=${SUBMIT:=ccc_msub}
81# rsync with path
82typeset -r RSYNC=/usr/bin/rsync
83# RSYNC_opt args to rsync
84typeset -r RSYNC_opt="-va"
85# ie storage filesystem
86typeset -r STOREHOST=${MASTER}
87
88#====================================================
89# Source default environment
90#====================================================
91##. /etc/profile
92
93#====================================================
94# Set environment tools (ferret, nco, cdo)
95#====================================================
96if [ X${TaskType} = Xcomputing ] ; then
97  . /ccc/cont003/home/dsm/p86ipsl/.atlas_env_calcul_curie_ksh
98  export PATH=${PATH}:/ccc/cont003/home/dsm/p86ipsl/AddNoise/src_X64/bin
99else
100  . /ccc/cont003/home/dsm/p86ipsl/.atlas_env_post_curie_ksh
101fi
102
103#====================================================
104# Specific for ocean additionnal diagnostic
105export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
106export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
107
108#====================================================
109# Host specific DIRECTORIES
110#====================================================
111
112# ============ CESIUM START ============ #
113
114#====================================================
115#- Mirror libIGCM from titane to cesium if needed
116#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
117#if [ ! ${ROOTSYS} = "home" ] ; then
118#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
119#else
120#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
121#fi
122
123#====================================================
124#- libIGCM_POST
125#if ( ${MirrorlibIGCM} ) ; then
126#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
127#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
128#else
129#  typeset -r libIGCM_POST=${libIGCM}
130#fi
131
132# ============ CESIUM  END  ============ #
133
134#====================================================
135#- MirrorlibIGCM for frontend
136typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
137
138#====================================================
139#- libIGCM_POST for frontend
140typeset -r libIGCM_POST=${libIGCM}
141
142#====================================================
143#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
144typeset -r R_EXE="${MODIPSL}/bin"
145
146#====================================================
147#- SUBMIT_DIR : submission dir
148typeset SUBMIT_DIR=${SUBMIT_DIR:=${BRIDGE_MSUB_PWD}}
149
150#====================================================
151#- IN
152typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
153typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/ccc/work/cont003/dsm/p24data}
154
155#====================================================
156#- ARCHIVE (dedicated to large files)
157typeset ARCHIVE=${CCCSTOREDIR}
158
159#====================================================
160#- STORAGE (dedicated to small/medium files)
161typeset STORAGE=${CCCWORKDIR}
162
163#====================================================
164#- R_OUT
165typeset R_OUT=${ARCHIVE}/IGCM_OUT
166
167#====================================================
168#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
169typeset R_FIG=${STORAGE}/IGCM_OUT
170
171#====================================================
172#- R_BUF (ONLY FOR double copy an scratch)
173typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
174
175#====================================================
176#- RUN_DIR_PATH : Temporary working directory (=> TMP)
177typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${BRIDGE_MSUB_JOBID}_${$}}
178
179#====================================================
180#- HOST_MPIRUN_COMMAND
181typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="/usr/bin/time ccc_mprun -E-K1"}
182
183#====================================================
184#- Max number of arguments passed to nco operator or demigration command
185UNIX_MAX_LIMIT=360
186
187#====================================================
188#- set PackDefault true on curie
189PackDefault=true
190
191#====================================================
192#- Number of core per node (max number of OpenMP task)
193NUM_COREPERNODE=8
194
195#====================================================
196#- Default number of MPI task for IPSL coupled model
197#- required for backward compatibility
198#-
199DEFAULT_NUM_PROC_OCE=5
200DEFAULT_NUM_PROC_CPL=1
201(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
202DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
203
204#D-#==================================================
205#D-function IGCM_sys_ChangeArchive
206#D-* Purpose: if SpaceName=TEST everything is stored on SCRATCHDIR
207#D-* Examples:
208#D-
209function IGCM_sys_ChangeArchive {
210  IGCM_debug_PushStack "IGCM_sys_ChangeArchive"
211
212  R_OUT=${SCRATCHDIR}/IGCM_OUT
213  R_FIG=${SCRATCHDIR}/IGCM_OUT
214
215  IGCM_debug_Print 1 "R_OUT   has been redefined = ${R_OUT}"
216  IGCM_debug_Print 1 "R_FIG   has been redefined = ${R_FIG}"
217
218  IGCM_debug_PopStack "IGCM_sys_ChangeArchive"
219}
220
221#D-#==================================================
222#D-function IGCM_sys_RshMaster
223#D-* Purpose: Connection to frontend machine.
224#D-* Examples:
225#D-
226function IGCM_sys_RshMaster {
227  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
228  /bin/ksh <<-EOF
229    export libIGCM=${libIGCM}
230    export DEBUG_debug=${DEBUG_debug}
231    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
232    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
233    ${@}
234EOF
235  if [ $? -gt 0 ] ; then
236    echo "IGCM_sys_RshMaster : erreur."
237    IGCM_debug_Exit "IGCM_sys_RshMaster"
238  fi
239  IGCM_debug_PopStack "IGCM_sys_RshMaster"
240}
241
242#D-#==================================================
243#D-function IGCM_sys_RshArchive
244#D-* Purpose: Archive rsh command
245#D-* Examples:
246#D-
247function IGCM_sys_RshArchive {
248  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
249  /bin/ksh <<-EOF
250    ${@}
251EOF
252  status=$?
253  if [ ${status} -gt 0 ] ; then
254    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
255    IGCM_debug_Exit "IGCM_sys_RshArchive"
256  fi
257  IGCM_debug_PopStack "IGCM_sys_RshArchive"
258}
259
260#D-#==================================================
261#D-function IGCM_sys_RshArchive_NoError
262#D-* Purpose: Archive rsh command, without error
263#D-*          used only in monitoring.job
264#D-* Examples:
265#D-
266function IGCM_sys_RshArchive_NoError {
267  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
268  /bin/ksh <<-EOF
269    ${@} 2> \dev\null
270EOF
271  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
272}
273
274#D-#==================================================
275#D-function IGCM_sys_RshPost
276#D-* Purpose: Post-process rsh command
277#D-* Examples:
278#D-
279function IGCM_sys_RshPost {
280  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
281  if ( $DEBUG_sys ) ; then
282    echo "IGCM_sys_RshPost :" $@
283  fi
284  # keep standard input (stdin) for the loop onto temporary file
285  cat >/tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
286
287  /bin/ksh </tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
288  if [ $? -gt 0 ] ; then
289    echo "IGCM_sys_RshPost : erreur."
290    IGCM_debug_Exit "IGCM_sys_RshPost"
291  fi
292  # delete temporary file
293  \rm /tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
294
295# ============ FRONTEND  END  ============ #
296
297# ============ CESIUM START ============ #
298#  typeset NB_ESSAI DELAI status i
299#  if [ "X$( grep rebuild_from tmp_IGCM_sys_RshPost_$$ )" != "X" ] ; then
300#    #little hack so that rebuild submission is done on titane not an cesium
301#
302#    libIGCM_POST_sed=$( echo $libIGCM_POST | sed 's/\//\\\//g' )
303#    POST_DIR_sed=$( echo ${POST_DIR} | sed 's/\//\\\//g' )
304#    sed "s/IGCM_sys_QsubPost/IGCM_sys_Qsub/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
305#    sed "s/ rebuild_fromWorkdir/ ${libIGCM_POST_sed}\/rebuild_fromWorkdir.job/g" tmp.txt > tmp_IGCM_sys_RshPost_$$
306#    sed "s/ rebuild_fromArchive/ ${libIGCM_POST_sed}\/rebuild_fromArchive.job/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
307#    sed "s/Script_Post_Output=/Script_Output=${POST_DIR_sed}\//g" tmp.txt > tmp_IGCM_sys_RshPost_$$
308#    \mv tmp.txt tmp_IGCM_sys_RshPost_$$
309#
310#    echo cat tmp_IGCM_sys_RshPost_$$ AFTER
311#    cat tmp_IGCM_sys_RshPost_$$
312#
313#    /bin/ksh <tmp_IGCM_sys_RshPost_$$
314#    if [ $? -gt 0 ] ; then
315#      echo "IGCM_sys_RshPost : erreur."
316#      IGCM_debug_Exit "IGCM_sys_RshPost"
317#    fi
318#    # delete temporary file
319#    \rm tmp_IGCM_sys_RshPost_$$
320#
321#  else
322#    # number of tentative
323#    NB_ESSAI=10
324#    # time delay between tentative
325#    DELAI=10
326#    i=0
327#    while [ $i -ne $NB_ESSAI ] ; do
328#      ssh -t titane996 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
329#      status=$?
330#      if [ ${status} -ne 0 ];
331#      then
332#        sleep $DELAI
333#      else
334#        break
335#      fi
336#      let i=$i+1
337#    done
338#    # delete temporary file
339#    \rm tmp_IGCM_sys_RshPost_$$
340#
341#    if [ ${status} -gt 0 ] ; then
342#      echo "IGCM_sys_RshPost : erreur."
343#      IGCM_debug_Exit "IGCM_sys_RshPost"
344#    fi
345#  fi
346
347# ============ CESIUM  END  ============ #
348
349  IGCM_debug_PopStack "IGCM_sys_RshPost"
350}
351
352#D-#==================================================
353#D-function IGCM_sys_SendMail
354#D-* Purpose: Send mail when simulation is over
355#D-* Examples:
356#D-
357function IGCM_sys_SendMail {
358  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
359  if ( $DEBUG_sys ) ; then
360    echo "IGCM_sys_SendMail :" $@
361  fi
362
363  if ( ${ExitFlag} ) ; then
364    status=failed
365  else
366    status=completed
367  fi
368
369  cat  << END_MAIL > job_end.mail
370Dear ${LOGIN},
371
372  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
373  Job started : ${DateBegin}
374  Job ended   : ${DateEnd}
375  Output files are available in ${R_SAVE}
376  Files to be rebuild are temporarily available in ${REBUILD_DIR}
377  Pre-packed files are temporarily available in ${R_BUFR}
378  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
379END_MAIL
380
381  if [ ! -z ${config_UserChoices_MailName} ] ; then
382    mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < job_end.mail
383  elif [ -f ~/.forward ] ; then
384    mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
385  fi
386
387  sleep 10
388  rm -f job_end.mail
389
390  if [ $? -gt 0 ] ; then
391    echo "IGCM_sys_SendMail : erreur."
392    IGCM_debug_Exit "IGCM_sys_SendMail"
393  fi
394  IGCM_debug_PopStack "IGCM_sys_SendMail"
395}
396
397#D-#==================================================
398#D-function IGCM_sys_Mkdir
399#D-* Purpose: Master locale mkdir command
400#D-* Examples:
401#D-
402function IGCM_sys_Mkdir {
403  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
404  if ( $DEBUG_sys ) ; then
405    echo "IGCM_sys_Mkdir :" $@
406  fi
407  if [ ! -d ${1} ]; then
408    \mkdir -p $1
409    if [ $? -gt 0 ] ; then
410      echo "IGCM_sys_Mkdir : erreur."
411      IGCM_debug_Exit "IGCM_sys_Mkdir"
412    fi
413  fi
414  # vérification :
415  if [ ! -d ${1} ] ; then
416    echo "IGCM_sys_Mkdir : erreur."
417    IGCM_debug_Exit "IGCM_sys_Mkdir"
418  fi
419  IGCM_debug_PopStack "IGCM_sys_Mkdir"
420}
421
422#D-#==================================================
423#D-function IGCM_sys_MkdirArchive
424#D-* Purpose: Mkdir on Archive
425#D-* Examples:
426#D-
427function IGCM_sys_MkdirArchive {
428  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
429  if ( $DEBUG_sys ) ; then
430    echo "IGCM_sys_MkdirArchive :" $@
431  fi
432  #- creation de repertoire sur le serveur fichier
433  if [ ! -d ${1} ]; then
434    \mkdir -p $1
435    status=$?
436
437    if [ ${status} -gt 0 ] ; then
438      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
439      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
440    fi
441  fi
442  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
443}
444
445#D-#==================================================
446#D-function IGCM_sys_MkdirWork
447#D-* Purpose: Mkdir on Work
448#D-* Examples:
449#D-
450function IGCM_sys_MkdirWork {
451  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
452  if ( $DEBUG_sys ) ; then
453    echo "IGCM_sys_MkdirWork :" $@
454  fi
455  #- creation de repertoire sur le serveur fichier
456  if [ ! -d ${1} ]; then
457    \mkdir -p $1
458    if [ $? -gt 0 ] ; then
459      echo "IGCM_sys_MkdirWork : erreur."
460      IGCM_debug_Exit "IGCM_sys_MkdirWork"
461    fi
462  fi
463  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
464}
465
466#D-#==================================================
467#D-function IGCM_sys_Cd
468#D-* Purpose: master cd command
469#D-* Examples:
470#D-
471function IGCM_sys_Cd {
472  IGCM_debug_PushStack "IGCM_sys_Cd" $@
473  if ( $DEBUG_sys ) ; then
474    echo "IGCM_sys_Cd :" $@
475  fi
476  \cd $1
477  if [ $? -gt 0 ] ; then
478    echo "IGCM_sys_Cd : erreur."
479    IGCM_debug_Exit "IGCM_sys_Cd"
480  fi
481  IGCM_debug_PopStack "IGCM_sys_Cd"
482}
483
484#D-#==================================================
485#D-function IGCM_sys_Chmod
486#D-* Purpose: Chmod
487#D-* Examples:
488#D-
489function IGCM_sys_Chmod {
490  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
491  if ( $DEBUG_sys ) ; then
492    echo "IGCM_sys_Chmod :" $@
493  fi
494  \chmod $@
495  if [ $? -gt 0 ] ; then
496    echo "IGCM_sys_Chmod : erreur."
497    IGCM_debug_Exit "IGCM_sys_Chmod"
498  fi
499  IGCM_debug_PopStack "IGCM_sys_Chmod"
500}
501
502#D-#==================================================
503#D-function IGCM_sys_FileSize
504#D-* Purpose: Filesize
505#D-* Examples:
506#D-
507function IGCM_sys_FileSize {
508  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
509
510  typeset sizeF
511  set +A sizeF -- $( ls -la ${1} )
512  if [ $? -gt 0 ] ; then
513    IGCM_debug_Exit "IGCM_sys_FileSize"
514  fi
515  eval ${2}=${sizeF[4]}
516
517  IGCM_debug_PopStack "IGCM_sys_FileSize"
518}
519
520#D-#==================================================
521#D-function IGCM_sys_TestDir
522#D-* Purpose: Test Directory that must exists
523#D-* Examples:
524#D-
525function IGCM_sys_TestDir {
526  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
527  if ( $DEBUG_sys ) ; then
528    echo "IGCM_sys_TestDir :" $@
529  fi
530  typeset ExistFlag
531  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
532  IGCM_debug_PopStack "IGCM_sys_TestDir"
533
534  return ${ExistFlag}
535}
536
537#D-#==================================================
538#D-function IGCM_sys_TestDirArchive
539#D-* Purpose: Test Directory that must exists on Archive
540#D-* Examples:
541#D-
542function IGCM_sys_TestDirArchive {
543  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
544  if ( $DEBUG_sys ) ; then
545    echo "IGCM_sys_TestDirArchive :" $@
546  fi
547  typeset ExistFlag
548  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
549  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
550  return ${ExistFlag}
551}
552
553#D-#==================================================
554#D-function IGCM_sys_IsFileArchived
555#D-* Purpose: Test file that must NOT EXISTS on Archive
556#D-* Examples:
557#D-
558function IGCM_sys_IsFileArchived {
559  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
560  if ( $DEBUG_sys ) ; then
561    echo "IGCM_sys_IsFileArchived :" $@
562  fi
563  typeset IsArchivedFlag
564  IsArchivedFlag=$( [ X$( echo $@ | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
565  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
566
567  return ${IsArchivedFlag}
568}
569
570#D-#==================================================
571#D-function IGCM_sys_TestFileArchive
572#D-* Purpose: Test file that must NOT EXISTS on Archive
573#D-* Examples:
574#D-
575function IGCM_sys_TestFileArchive {
576  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
577  typeset ExistFlag
578  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
579  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
580
581  return ${ExistFlag}
582}
583
584#D-#==================================================
585#D-function IGCM_sys_TestFileBuffer
586#D-* Purpose: Test file that must NOT EXISTS on Buffer
587#D-* Examples:
588#D-
589function IGCM_sys_TestFileBuffer {
590  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
591  typeset ExistFlag
592  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
593  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
594
595  return ${ExistFlag}
596}
597
598#D-#==================================================
599#D-function IGCM_sys_CountFileArchive
600#D-* Purpose: Count files on Archive filesystem
601#D-* Examples:
602#D-
603function IGCM_sys_CountFileArchive {
604  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
605  ls ${@} 2>/dev/null | wc -l
606  if [ $? -gt 0 ] ; then
607    echo "IGCM_sys_CountFileArchive : erreur."
608  fi
609  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
610}
611
612#D-#==================================================
613#D-function IGCM_sys_CountFileBuffer
614#D-* Purpose: Count files on Scratch filesystem
615#D-* Examples:
616#D-
617function IGCM_sys_CountFileBuffer {
618  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
619  ls ${@} 2>/dev/null | wc -l
620  if [ $? -gt 0 ] ; then
621    echo "IGCM_sys_CountFileBuffer : erreur."
622  fi
623  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
624}
625
626#D-#==================================================
627#D-function IGCM_sys_Tree
628#D-* Purpose: Tree directories with files on ${ARCHIVE}
629#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
630#D-
631function IGCM_sys_Tree {
632  IGCM_debug_PushStack "IGCM_sys_Tree" $@
633  if ( $DEBUG_sys ) ; then
634    echo "IGCM_sys_Tree :" $@
635  fi
636
637  \ls -lR ${@}
638
639  IGCM_debug_PopStack "IGCM_sys_Tree"
640}
641
642#D-#==================================================
643#D-function IGCM_sys_Tar
644#D-* Purpose: master tar command
645#D-* Examples:
646#D-
647function IGCM_sys_Tar {
648  IGCM_debug_PushStack "IGCM_sys_Tar" $@
649  if ( $DEBUG_sys ) ; then
650    echo "IGCM_sys_Tar :" $@
651  fi
652  \tar cf $@
653  if [ $? -gt 0 ] ; then
654    echo "IGCM_sys_Tar : erreur."
655    IGCM_debug_Exit "IGCM_sys_Tar"
656  fi
657  IGCM_debug_PopStack "IGCM_sys_Tar"
658}
659
660#D-#==================================================
661#D-function IGCM_sys_UnTar
662#D-* Purpose: master un-tar command
663#D-* Examples:
664#D-
665function IGCM_sys_UnTar {
666  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
667  if ( $DEBUG_sys ) ; then
668    echo "IGCM_sys_UnTar :" $@
669  fi
670  \tar xvf $1
671  if [ $? -gt 0 ] ; then
672    echo "IGCM_sys_UnTar : erreur."
673    IGCM_debug_Exit "IGCM_sys_UnTar"
674  fi
675  IGCM_debug_PopStack "IGCM_sys_UnTar"
676}
677
678#D-#==================================================
679#D-function IGCM_sys_Qsub
680#D-* Purpose: Qsub new job
681#D-* Examples:
682#D-
683function IGCM_sys_Qsub {
684  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
685  if ( $DEBUG_sys ) ; then
686    echo "IGCM_sys_Qsub :" $@
687  fi
688  typeset options status
689#  if [ ${config_UserChoices_JobName}.${CumulPeriod} = "." ] ; then
690    options=" -o ${SUBMIT_DIR}/${Script_Output} -e ${SUBMIT_DIR}/${Script_Output}"
691#  else
692#    options=" -o ${SUBMIT_DIR}/${Script_Output} -e ${SUBMIT_DIR}/${Script_Output} -r ${config_UserChoices_JobName}.${CumulPeriod}"
693#  fi
694
695  /usr/bin/ccc_msub ${options} < $1
696  status=$?
697  if [ ${status} -gt 0 ] ; then
698    IGCM_debug_Print 2 "IGCM_sys_Qsub ${options} $1 : error code ${status}"
699    IGCM_debug_Exit "IGCM_sys_Qsub"
700  fi
701  IGCM_debug_PopStack "IGCM_sys_Qsub"
702}
703
704#D-#==================================================
705#D-function IGCM_sys_QsubPost
706#D-* Purpose: Qsub new job on scalaire
707#D-* Examples:
708#D-
709function IGCM_sys_QsubPost {
710  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
711  if ( $DEBUG_sys ) ; then
712    echo "IGCM_sys_QsubPost :" $@
713  fi
714  typeset status
715  MY_PROJECT=$(echo ${BRIDGE_MSUB_PROJECT:=${DEFAULT_PROJECT}} | cut -d@ -f1 )
716  /usr/bin/ccc_msub -Q normal -A ${MY_PROJECT} -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out ${libIGCM_POST}/$1.job
717  status=$?
718  if [ ${status} -gt 0 ] ; then
719    IGCM_debug_Print 2 "IGCM_sys_QsubPost $1 : error code ${status}"
720    IGCM_debug_Exit "IGCM_sys_QsubPost"
721  fi
722  IGCM_debug_PopStack "IGCM_sys_QsubPost"
723}
724
725#D-*************************
726#D- File transfer functions
727#D-*************************
728#D-
729
730#D-#==================================================
731#D-function IGCM_sys_Rsync_out
732#D-* Purpose: treat return val of rsync
733#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
734#D-  Error values and explanations can depend on your system version.
735function IGCM_sys_Rsync_out {
736  status=$1
737  if [ ! $status ] ; then
738    echo "rsync error !"
739  fi
740
741  if [ $MYLANG = "fr" ]; then
742    case $status in
743    0)  return ;;
744    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
745      echo "Erreur de syntaxe ou d'utilisation."
746      return;;
747    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
748      echo "Incompatibilité de protocole."
749      return;;
750    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
751      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
752      echo "répertoires"
753      return;;
754    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
755      echo "Action demandée non supportée : une tentative de manipulation de"
756      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
757      echo "été faite ; ou une option qui est supportée par le  client  mais"
758      echo "pas par le serveur a été spécifiée."
759      return;;
760    10) echo "Erreur de rsync ; RERR_SOCKETIO"
761      echo "Erreur dans le socket d'entrée sortie"
762      return;;
763    11) echo "Erreur de rsync ; RERR_FILEIO"
764      echo "Erreur d'entrée sortie fichier"
765      return;;
766    12) echo "Erreur de rsync ; RERR_STREAMIO"
767      echo "Erreur dans flux de donnée du protocole rsync"
768      return;;
769    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
770      echo "Erreur avec les diagnostics du programme"
771      return;;
772    14) echo "Erreur de rsync ; RERR_IPC"
773      echo "Erreur dans le code IPC"
774      return;;
775    20) echo "Erreur de rsync ; RERR_SIGNAL"
776      echo "SIGUSR1 ou SIGINT reçu"
777      return;;
778    21) echo "Erreur de rsync ; RERR_WAITCHILD"
779      echo "Une erreur retournée par waitpid()"
780      return;;
781    22) echo "Erreur de rsync ; RERR_MALLOC"
782      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
783      return;;
784    23) echo ""
785      echo "Erreur fichier inexistant"
786      return;;
787    30) echo "Erreur de rsync ; RERR_TIMEOUT"
788      echo "Temps d'attente écoulé dans l'envoi/réception de données"
789      return;;
790    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
791      return;;
792    esac
793  elif [ $MYLANG = "en" ] ; then
794    case $status in
795    0)  return;;
796    1)  echo "rsync error : Syntax or usage error "
797      return;;
798    2)  echo "rsync error : Protocol incompatibility "
799      return;;
800    3)  echo "rsync error : Errors selecting input/output files, dirs"
801      return;;
802    4)  echo "rsync error : Requested action not supported: an attempt"
803      echo "was made to manipulate 64-bit files on a platform that cannot support"
804      echo "them; or an option was specified that is supported by the client and"
805      echo "not by the server."
806      return;;
807    5)  echo "rsync error : Error starting client-server protocol"
808      return;;
809    10) echo "rsync error : Error in socket I/O "
810      return;;
811    11) echo "rsync error : Error in file I/O "
812      return;;
813    12) echo "rsync error : Error in rsync protocol data stream "
814      return;;
815    13) echo "rsync error : Errors with program diagnostics "
816      return;;
817    14) echo "rsync error : Error in IPC code "
818      return;;
819    20) echo "rsync error : Received SIGUSR1 or SIGINT "
820      return;;
821    21) echo "rsync error : Some error returned by waitpid() "
822      return;;
823    22) echo "rsync error : Error allocating core memory buffers "
824      return;;
825    23) echo "rsync error : Partial transfer due to error"
826      return;;
827    24) echo "rsync error : Partial transfer due to vanished source files"
828      return;;
829    30) echo "rsync error : Timeout in data send/receive "
830      return;;
831    *)  echo "rsync error : return code of rsync unknown :" $status
832      return;;
833    esac
834  else
835    echo "unknown language $MYLANG."
836    return
837  fi
838}
839
840#D-#==================================================
841#D-function IGCM_sys_Miror_libIGCM
842#D-* Purpose: Mirror libIGCM PATH and lib to frontend
843#D-* Examples:
844#D-
845function IGCM_sys_Mirror_libIGCM {
846  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
847  if ( $DEBUG_sys ) ; then
848    echo "IGCM_sys_Mirror_libIGCM"
849  fi
850
851  typeset status
852
853  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
854
855  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
856  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
857  status=$?
858
859  if [ ${status} -gt 0 ] ; then
860    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on frontend."
861    cat out_rsync
862  fi
863  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
864}
865
866#D-#==================================================
867#D-function IGCM_sys_Cp
868#D-* Purpose: generic cp
869#D-* Examples:
870#D-
871function IGCM_sys_Cp {
872  IGCM_debug_PushStack "IGCM_sys_Cp" $@
873  if ( $DEBUG_sys ) ; then
874    echo "IGCM_sys_Cp :" $@
875  fi
876
877  typeset status
878
879  echo cp $@ > out_rsync 2>&1
880  \cp $@ >> out_rsync 2>&1
881  status=$?
882
883  if [ ${status} -gt 0 ] ; then
884    echo "IGCM_sys_Cp : error code ${status}"
885    cat out_rsync
886    IGCM_debug_Exit "IGCM_sys_Cp"
887  else
888    \rm out_rsync
889  fi
890  IGCM_debug_PopStack "IGCM_sys_Cp"
891}
892
893#D-#==================================================
894#D-function IGCM_sys_Rm
895#D-* Purpose: generic rm
896#D-* Examples:
897#D-
898function IGCM_sys_Rm {
899  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
900  if ( $DEBUG_sys ) ; then
901    echo "IGCM_sys_Rm :" $@
902  fi
903
904  typeset status
905
906  echo rm $@ > out_rsync 2>&1
907  \rm $@ >> out_rsync 2>&1
908  status=$?
909
910  if [ ${status} -gt 0 ] ; then
911    echo "IGCM_sys_Rm : error code ${status}"
912    cat out_rsync
913    IGCM_debug_Exit "IGCM_sys_Rm"
914  else
915    \rm out_rsync
916  fi
917  IGCM_debug_PopStack "IGCM_sys_Rm"
918}
919
920#D-#==================================================
921#D-function IGCM_sys_RmRunDir
922#D-* Purpose: rm tmpdir (dummy function most of the time batch
923#D-                      scheduler will do the job)
924#D-* Examples:
925#D-
926function IGCM_sys_RmRunDir {
927  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
928  if ( $DEBUG_sys ) ; then
929    echo "IGCM_sys_RmRunDir :" $@
930  fi
931
932  typeset status
933
934  echo rm $@ > out_rsync 2>&1
935  \rm $@ >> out_rsync 2>&1
936  status=$?
937
938  if [ ${status} -gt 0 ] ; then
939    echo "IGCM_sys_RmRunDir : rm error code is ${status}."
940    cat out_rsync
941    IGCM_debug_Exit "IGCM_sys_RmRunDir"
942  else
943    \rm out_rsync
944  fi
945  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
946}
947
948#D-#==================================================
949#D-function IGCM_sys_Mv
950#D-* Purpose: generic move
951#D-* Examples:
952#D-
953function IGCM_sys_Mv {
954  IGCM_debug_PushStack "IGCM_sys_Mv" $@
955  if ( $DEBUG_sys ) ; then
956    echo "IGCM_sys_Mv :" $@
957  fi
958
959  if [ $DRYRUN = 0 ]; then
960
961    typeset status
962
963    echo mv $@ > out_rsync 2>&1
964    \mv $@ >> out_rsync 2>&1
965    status=$?
966
967    if [ ${status} -gt 0 ] ; then
968      echo "IGCM_sys_Mv : error code ${status}"
969      cat out_rsync
970      IGCM_debug_Exit "IGCM_sys_Mv"
971    else
972      \rm out_rsync
973    fi
974  fi
975
976  IGCM_debug_PopStack "IGCM_sys_Mv"
977}
978
979#D-#==================================================
980#D-function IGCM_sys_Put_Dir
981#D-* Purpose: Copy a complete directory on $(ARCHIVE)
982#D-* Examples:
983#D-
984function IGCM_sys_Put_Dir {
985  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
986  if ( $DEBUG_sys ) ; then
987    echo "IGCM_sys_Put_Dir :" $@
988  fi
989  if [ $DRYRUN = 0 ]; then
990    if [ ! -d ${1} ] ; then
991      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
992      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
993      return
994    fi
995
996    typeset status
997
998    # Only if we use rsync
999    #IGCM_sys_TestDirArchive $( dirname $2 )
1000    #
1001    #USUAL WAY
1002    \cp -r $1 $2 > out_rsync 2>&1
1003    status=$?
1004
1005    if [ ${status} -gt 0 ] ; then
1006      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
1007      cat out_rsync
1008      IGCM_debug_Exit "IGCM_sys_Put_Dir"
1009    else
1010      \rm out_rsync
1011    fi
1012  fi
1013  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1014}
1015
1016#D-#==================================================
1017#D-function IGCM_sys_Get_Dir
1018#D-* Purpose: Copy a complete directory from ${ARCHIVE}
1019#D-* Examples:
1020#D-
1021function IGCM_sys_Get_Dir {
1022  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
1023  if ( $DEBUG_sys ) ; then
1024    echo "IGCM_sys_Get_Dir :" $@
1025  fi
1026  if [ $DRYRUN = 0 ]; then
1027#    if [ ! -d ${1} ] ; then
1028#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
1029#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1030#      return
1031#    fi
1032
1033    typeset NB_ESSAI DELAI status i
1034    # number of tentative
1035    NB_ESSAI=3
1036    # time delay between tentative
1037    DELAI=2
1038
1039    # Only if we use rsync
1040    #IGCM_sys_TestDirArchive $( dirname $2 )
1041    #
1042    # USUAL WAY
1043    # add 'ccc_hsm get' (to demigrate all offline files) to reduce time of this command :
1044    ccc_hsm get -r $1
1045
1046    i=0
1047    while [ $i -lt $NB_ESSAI ] ; do
1048      \cp -ur $1 $2 >> out_rsync 2>&1
1049      status=$?
1050      if [ ${status} -gt 0 ] ; then
1051        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}"
1052        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
1053        sleep $DELAI
1054      else
1055        break
1056      fi
1057      (( i = i + 1 ))
1058    done
1059
1060    if [ ${status} -gt 0 ] ; then
1061      echo "IGCM_sys_Get_Dir : error."
1062      cat out_rsync
1063      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1064    else
1065      \rm out_rsync
1066    fi
1067  fi
1068  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1069}
1070
1071#D-#==================================================
1072#D-function IGCM_sys_Get_Master
1073#D-* Purpose: Copy a complete directory from MASTER filesystem
1074#D-* Examples:
1075#D-
1076function IGCM_sys_Get_Master {
1077  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1078  if ( $DEBUG_sys ) ; then
1079    echo "IGCM_sys_Get_Master :" $@
1080  fi
1081  if [ $DRYRUN = 0 ]; then
1082    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
1083      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1084      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1085      return
1086    fi
1087
1088    typeset NB_ESSAI DELAI status i
1089    # number of tentative
1090    NB_ESSAI=3
1091    # time delay between tentative
1092    DELAI=2
1093
1094    i=0
1095    while [ $i -lt $NB_ESSAI ] ; do
1096      \cp -urL $1 $2 > out_rsync 2>&1
1097      status=$?
1098      if [ ${status} -gt 0 ]; then
1099        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
1100        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
1101        sleep $DELAI
1102      else
1103        break
1104      fi
1105      (( i = i + 1 ))
1106    done
1107
1108    if [ ${status} -gt 0 ] ; then
1109      echo "IGCM_sys_Get_Master : error."
1110      cat out_rsync
1111      IGCM_debug_Exit "IGCM_sys_Get_Master"
1112    else
1113      \rm out_rsync
1114    fi
1115  fi
1116  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1117}
1118
1119#====================================================
1120#- Call IGCM_sys_Mirror_libIGCM now !
1121if ( $MirrorlibIGCM ) ; then
1122  IGCM_sys_Mirror_libIGCM
1123fi
1124
1125#D-#==================================================
1126#D-function IGCM_sys_Put_Rest
1127#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1128#D-           File and target directory must exist.
1129#D-* Examples:
1130#D-
1131function IGCM_sys_Put_Rest {
1132  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1133  if ( $DEBUG_sys ) ; then
1134    echo "IGCM_sys_Put_Rest :" $@
1135  fi
1136  if [ $DRYRUN = 0 ]; then
1137    if [ ! -f ${1} ] ; then
1138      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1139      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1140    fi
1141
1142    typeset status
1143    #
1144    # USUAL WAY
1145    \cp $1 $2 > out_rsync 2>&1
1146    status=$?
1147
1148#       #RSYNC WITH NETWORK SSH CALL
1149#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1150#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1151
1152#       #RSYNC WITH NFS USE
1153#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1154#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1155
1156#       status=$?
1157#       IGCM_sys_Rsync_out $status
1158
1159#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1160#       (( status=status+$? ))
1161
1162    if [ ${status} -gt 0 ] ; then
1163      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
1164      [ -f ${1} ] && ls -l ${1}
1165      [ -f ${2} ] && ls -l ${2}
1166      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1167      cat out_rsync
1168      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1169    else
1170
1171      if [ X${JobType} = XRUN ] ; then
1172        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1173        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1174      fi
1175
1176      \rm out_rsync
1177    fi
1178  fi
1179  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1180}
1181
1182#D-#==================================================
1183#D-function IGCM_sys_PutBuffer_Rest
1184#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1185#D-           File and target directory must exist.
1186#D-* Examples:
1187#D-
1188function IGCM_sys_PutBuffer_Rest {
1189  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1190  if ( $DEBUG_sys ) ; then
1191    echo "IGCM_sys_PutBuffer_Rest :" $@
1192  fi
1193  if [ $DRYRUN = 0 ]; then
1194    if [ ! -f ${1} ] ; then
1195      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1196      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1197    fi
1198
1199    typeset status
1200    #
1201    # USUAL WAY
1202    \cp $1 $2 > out_rsync 2>&1
1203    status=$?
1204
1205    if [ ${status} -gt 0 ] ; then
1206      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1207      [ -f ${2} ] && ls -l ${2}
1208      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1209      cat out_rsync
1210      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1211    else
1212
1213      if [ X${JobType} = XRUN ] ; then
1214        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1215        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1216      fi
1217
1218      \rm out_rsync
1219    fi
1220  fi
1221  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1222}
1223
1224#D-#==================================================
1225#D-function IGCM_sys_PrepareTaredRestart
1226#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1227#D-* Examples:
1228#D-
1229function IGCM_sys_PrepareTaredRestart {
1230  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1231  if [ $DRYRUN = 0 ]; then
1232    [ ! -f $( basename $1 ) ] && DEBUG_sys=false IGCM_sys_Get $1 .
1233  fi
1234  echo $( basename $1 )
1235  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1236}
1237
1238#D-#==================================================
1239#D-function IGCM_sys_Put_Out
1240#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1241#D-* Examples:
1242#D-
1243function IGCM_sys_Put_Out {
1244  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1245  if ( $DEBUG_sys ) ; then
1246    echo "IGCM_sys_Put_Out :" $@
1247  fi
1248
1249  typeset NB_ESSAI DELAI status i exist skip
1250
1251  # number of tentative
1252  NB_ESSAI=3
1253  # time delay between tentative
1254  DELAI=2
1255
1256  if [ $DRYRUN = 0 ]; then
1257    if [ ! -f ${1} ] ; then
1258      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1259      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1260      return 1
1261    fi
1262    #
1263    IGCM_sys_MkdirArchive $( dirname $2 )
1264    #
1265
1266    #=====================================================
1267    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1268    #=====================================================
1269
1270    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1271    #if [ $? -eq 0 ] ; then
1272    #    typeset WORKPATH FILEPATH
1273    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1274    #    IGCM_sys_MkdirWork ${WORKPATH}
1275    #    FILEPATH=${WORKPATH}/$( basename $2 )
1276    #    #
1277    #    IGCM_sys_Cp ${1} ${FILEPATH}
1278    #fi
1279
1280    exist=false
1281    skip=false
1282    if [ -f $2 ] ; then
1283      IGCM_debug_Print 1 "$2 already exist"
1284      #dmget $2
1285      ccc_hsm get $2
1286      exist=true
1287      if [ "X$( diff $1 $2 )" = X ] ; then
1288        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1289        skip=true
1290      else
1291        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1292        skip=false
1293      fi
1294    fi
1295    #
1296    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1297      IGCM_sys_Chmod u+w $2
1298    fi
1299
1300    if [ X${skip} = Xfalse ] ; then
1301      i=0
1302      while [ $i -lt $NB_ESSAI ] ; do
1303        # USUAL WAY
1304        \cp $1 $2 > out_rsync 2>&1
1305        status=$?
1306        if [ ${status} -gt 0 ]; then
1307          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1308          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1309          [ -f ${1} ] && ls -l ${1}
1310          [ -f ${2} ] && ls -l ${2}
1311          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1312          sleep $DELAI
1313        else
1314          break
1315        fi
1316        (( i = i + 1 ))
1317      done
1318    fi
1319
1320#       #RSYNC WITH NETWORK SSH CALL
1321#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1322#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1323
1324#       #RSYNC WITH NFS USE
1325#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1326#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1327
1328#       status=$?
1329#       IGCM_sys_Rsync_out $status
1330
1331#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1332#       (( status=status+$? ))
1333
1334    if [ ${status} -gt 0 ] ; then
1335      echo "IGCM_sys_Put_Out : error."
1336      [ -f ${1} ] && ls -l ${1}
1337      [ -f ${2} ] && ls -l ${2}
1338      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1339      cat out_rsync
1340      IGCM_debug_Exit "IGCM_sys_Put_Out"
1341    else
1342
1343      if [ X${JobType} = XRUN ] ; then
1344        if [ X${3} = X ] ; then
1345          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1346          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1347        fi
1348      fi
1349
1350      \rm out_rsync
1351    fi
1352  fi
1353  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1354  return 0
1355}
1356
1357#D-#==================================================
1358#D-function IGCM_sys_PutBuffer_Out
1359#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1360#D-* Examples:
1361#D-
1362function IGCM_sys_PutBuffer_Out {
1363  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1364  if ( $DEBUG_sys ) ; then
1365    echo "IGCM_sys_PutBuffer_Out :" $@
1366  fi
1367
1368  typeset NB_ESSAI DELAI status i exist skip
1369
1370  # number of tentative
1371  NB_ESSAI=3
1372  # time delay between tentative
1373  DELAI=2
1374
1375  if [ $DRYRUN = 0 ]; then
1376    if [ ! -f ${1} ] ; then
1377      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1378      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1379      return 1
1380    fi
1381    #
1382    IGCM_sys_Mkdir $( dirname $2 )
1383    #
1384
1385    exist=false
1386    skip=false
1387    if [ -f $2 ] ; then
1388      IGCM_debug_Print 1 "$2 already exist"
1389      exist=true
1390      if [ "X$( diff $1 $2 )" = X ] ; then
1391        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1392        status=0
1393        skip=true
1394      else
1395        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1396        skip=false
1397      fi
1398    fi
1399    #
1400    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1401      IGCM_sys_Chmod u+w $2
1402    fi
1403
1404    if [ X${skip} = Xfalse ] ; then
1405      i=0
1406      while [ $i -lt $NB_ESSAI ] ; do
1407        # USUAL WAY
1408        \cp $1 $2 > out_rsync 2>&1
1409        status=$?
1410        if [ ${status} -gt 0 ]; then
1411          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1412          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1413          [ -f ${2} ] && ls -l ${2}
1414          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1415          sleep $DELAI
1416        else
1417          break
1418        fi
1419        (( i = i + 1 ))
1420      done
1421    fi
1422
1423    if [ ${status} -gt 0 ] ; then
1424      echo "IGCM_sys_PutBuffer_Out : error."
1425      [ -f ${2} ] && ls -l ${2}
1426      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1427      cat out_rsync
1428      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1429    else
1430
1431      if [ X${JobType} = XRUN ] ; then
1432        if [ X${3} = X ] ; then
1433          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1434          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1435        fi
1436      fi
1437
1438      \rm out_rsync
1439    fi
1440  fi
1441  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1442  return 0
1443}
1444
1445#D-#==================================================
1446#D-function IGCM_sys_Get
1447#D-* Purpose: Get a file from ${ARCHIVE}
1448#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1449#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1450function IGCM_sys_Get {
1451  IGCM_debug_PushStack "IGCM_sys_Get" $@
1452
1453  typeset DEST dm_liste target file_work
1454  typeset NB_ESSAI DELAI status i
1455
1456  if ( $DEBUG_sys ) ; then
1457    echo "IGCM_sys_Get :" $@
1458  fi
1459
1460  # number of tentative
1461  NB_ESSAI=3
1462  # time delay between tentative
1463  DELAI=2
1464
1465  if [ $DRYRUN -le 2 ]; then
1466    if [ X${1} = X'/l' ] ; then
1467      # test if the first file is present in the old computation :
1468      eval set +A dm_liste \${${2}}
1469    else
1470      eval set +A dm_liste ${1}
1471    fi
1472    eval DEST=\${${#}}
1473
1474    #=====================================================
1475    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1476    #=====================================================
1477
1478    # Is it an R_OUT file (not R_IN) ?
1479    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1480    #if [ $? -eq 0 ] ; then
1481    #  # Yes  ? then we try to get it in SCRATCHDIR
1482    #  set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1483    #  if [ -f ${file_work[0]} ] ; then
1484    #    IGCM_sys_Cp ${file_work[*]} ${DEST}
1485    #    IGCM_debug_PopStack "IGCM_sys_Get"
1486    #    return
1487    #  fi
1488    #fi
1489
1490    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1491    status=$?
1492    if [ ${status} -gt 0 ] ; then
1493      echo "WARNING IGCM_sys_Get : error code ${status}"
1494      cat out_rsync
1495      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1496    fi
1497
1498    #if [ ${status} -gt 0 ] ; then
1499    #  if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1500    #    cat out_rsync
1501    #    echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1502    #    sleep 30
1503    #    echo "We try another time"
1504    ##    dmget ${dm_liste[*]} > out_rsync 2>&1
1505    #    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1506    #    status=$?
1507    #    if [ ${status} -gt 0 ] ; then
1508    #      echo "ERROR IGCM_sys_Get : again demigration error :"
1509    #      cat out_rsync
1510    #      IGCM_debug_Exit "IGCM_sys_Get"
1511    #    fi
1512    #  else
1513    #    echo "ERROR IGCM_sys_Get : demigration error :"
1514    #    cat out_rsync
1515    #    IGCM_debug_Exit "IGCM_sys_Get"
1516    #  fi
1517    #fi
1518
1519    #   #RSYNC WITH NETWORK SSH CALL
1520    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1521    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1522
1523    #   #RSYNC WITH NFS USE
1524    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1525    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1526
1527    #   status=$?
1528    #   IGCM_sys_Rsync_out $status
1529
1530    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1531    #   (( status=status+$? ))
1532
1533    #USUAL WAY
1534    if [ X${1} = X'/l' ] ; then
1535      for target in ${dm_liste[*]} ; do
1536        local_file=$( basename ${target} )
1537        # test if the target file is present before the loop
1538        IGCM_sys_TestFileArchive ${target}
1539        status=$?
1540        if [ ${status} -gt 0 ] ; then
1541          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1542          IGCM_debug_Exit "IGCM_sys_Get"
1543        else
1544          i=0
1545          while [ $i -lt $NB_ESSAI ] ; do
1546            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1547            status=$?
1548            if [ ${status} -gt 0 ]; then
1549              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1550              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1551              sleep $DELAI
1552            else
1553              break
1554            fi
1555            (( i = i + 1 ))
1556          done
1557          if [ ${status} -gt 0 ] ; then
1558            echo "IGCM_sys_Get : error"
1559            cat out_rsync
1560            \rm out_rsync
1561            IGCM_debug_Exit "IGCM_sys_Get"
1562          else
1563            \rm out_rsync
1564          fi
1565        fi
1566      done
1567    else
1568      i=0
1569      while [ $i -lt $NB_ESSAI ] ; do
1570        \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1571        status=$?
1572        if [ ${status} -gt 0 ]; then
1573          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1574          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1575          sleep $DELAI
1576        else
1577          break
1578        fi
1579        (( i = i + 1 ))
1580      done
1581      if [ ${status} -gt 0 ] ; then
1582        echo "IGCM_sys_Get : error"
1583        cat out_rsync
1584        \rm out_rsync
1585        IGCM_debug_Exit "IGCM_sys_Get"
1586      else
1587        \rm out_rsync
1588      fi
1589    fi
1590  fi
1591  IGCM_debug_PopStack "IGCM_sys_Get"
1592}
1593
1594#D-#==================================================
1595#D-function IGCM_sys_GetBuffer
1596#D-* Purpose: Get a file from ${SCRATCHDIR}
1597#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1598#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1599function IGCM_sys_GetBuffer {
1600  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1601
1602  typeset DEST buf_liste target file_work
1603  typeset NB_ESSAI DELAI status i
1604
1605  if ( $DEBUG_sys ) ; then
1606    echo "IGCM_sys_GetBuffer :" $@
1607  fi
1608
1609  # number of tentative
1610  NB_ESSAI=3
1611  # time delay between tentative
1612  DELAI=2
1613
1614  if [ $DRYRUN -le 2 ]; then
1615    if [ X${1} = X'/l' ] ; then
1616      # test if the first file is present in the old computation :
1617      eval set +A buf_liste \${${2}}
1618    else
1619      eval set +A buf_liste ${1}
1620    fi
1621    eval DEST=\${${#}}
1622
1623    #USUAL WAY
1624    if [ X${1} = X'/l' ] ; then
1625      for target in ${buf_liste[*]} ; do
1626        local_file=$( basename ${target} )
1627        i=0
1628        while [ $i -lt $NB_ESSAI ] ; do
1629          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1630          status=$?
1631          if [ ${status} -gt 0 ]; then
1632            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1633            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1634            sleep $DELAI
1635          else
1636            break
1637          fi
1638          (( i = i + 1 ))
1639        done
1640        if [ ${status} -gt 0 ] ; then
1641          echo "IGCM_sys_Get : error"
1642          cat out_rsync
1643          \rm out_rsync
1644          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1645        else
1646          \rm out_rsync
1647        fi
1648      done
1649    else
1650      i=0
1651      while [ $i -lt $NB_ESSAI ] ; do
1652        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1653        status=$?
1654        if [ ${status} -gt 0 ]; then
1655          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1656          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1657          sleep $DELAI
1658        else
1659          break
1660        fi
1661        (( i = i + 1 ))
1662      done
1663      if [ ${status} -gt 0 ] ; then
1664        echo "IGCM_sys_Get : error"
1665        cat out_rsync
1666        \rm out_rsync
1667        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1668      else
1669        \rm out_rsync
1670      fi
1671    fi
1672  fi
1673  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1674}
1675
1676#D-#==================================================
1677#D-function IGCM_sys_GetDate_FichWork
1678#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1679#D-* Examples:
1680#D-
1681function IGCM_sys_GetDate_FichWork {
1682  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1683  if ( $DEBUG_sys ) ; then
1684    echo "IGCM_sys_GetDate_FichWork :" $@
1685  fi
1686  typeset dateF
1687  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1688  eval ${2}=${dateF[5]}
1689
1690  # donne la date filesys d'un fichier sur la machine work
1691  IGCM_debug_PopStack "IGCM_sys_FichWork"
1692}
1693
1694#D-#==================================================
1695#D-function IGCM_sys_GetDate_FichArchive
1696#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1697#D-* Examples:
1698#D-
1699function IGCM_sys_GetDate_FichArchive {
1700  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1701  if ( $DEBUG_sys ) ; then
1702    echo "IGCM_sys_GetDate_FichArchive :" $@
1703  fi
1704  typeset dateF
1705  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1706  eval ${2}=${dateF[5]}
1707
1708  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1709}
1710
1711#D-#==================================================
1712#D-function IGCM_sys_GetDate_Monitoring
1713#D-* Purpose: get the last year for which the monitoring has been computed
1714#D-* Examples:
1715#D-
1716function IGCM_sys_GetDate_Monitoring {
1717  IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@
1718  if ( $DEBUG_sys ) ; then
1719    echo "IGCM_sys_GetDate_Monitoring :" $@
1720  fi
1721
1722  eval ${2}=$( cdo showyear ${1} 2> /dev/null | gawk '{ print $NF }' )
1723
1724  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
1725}
1726
1727#D-#==================================================
1728#D-function IGCM_sys_Dods_Rm
1729#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1730#D-* Examples:
1731#D-
1732function IGCM_sys_Dods_Rm {
1733  if ( $DEBUG_sys ) ; then
1734    echo "IGCM_sys_Dods_Rm :" $@
1735  fi
1736  typeset status
1737  if [ $DRYRUN = 0 ]; then
1738
1739#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1740#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1741#      echo "Nothing has been done."
1742#      return
1743#    fi
1744
1745    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1746    status=$?
1747
1748#    if [ ${status} -gt 0 ] ; then
1749#      echo "IGCM_sys_Dods_Rm : error."
1750#      cat out_dods_rm
1751#      IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1752#    else
1753#      rm out_dods_rm
1754#    fi
1755
1756  fi
1757  return $status
1758}
1759
1760#D-#==================================================
1761#D-function IGCM_sys_Dods_Cp
1762#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1763#D-* Examples:
1764#D-
1765function IGCM_sys_Dods_Cp {
1766  if ( $DEBUG_sys ) ; then
1767    echo "IGCM_sys_Dods_Cp :" $@
1768  fi
1769  typeset status
1770  if [ $DRYRUN = 0 ]; then
1771
1772#    if [ ! -d ${R_SAVE}/${1} ] ; then
1773#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1774#      echo "Nothing has been done."
1775#      return
1776#    fi
1777
1778    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1779    status=$?
1780
1781#       if [ ${status} -gt 0 ] ; then
1782#           echo "IGCM_sys_Dods_Cp : error."
1783#           cat out_dods_cp
1784#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1785#       else
1786#           rm out_dods_cp
1787#       fi
1788
1789  fi
1790  return $status
1791}
1792
1793#D-#==================================================
1794#D-function IGCM_sys_Put_Dods
1795#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1796#D-* Examples:
1797#D-
1798function IGCM_sys_Put_Dods {
1799  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1800  if ( $DEBUG_sys ) ; then
1801    echo "IGCM_sys_Put_Dods :" $@
1802  fi
1803  #set -vx
1804  typeset status
1805  if [ $DRYRUN = 0 ]; then
1806    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1807      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1808      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1809      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1810      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1811      return
1812    fi
1813
1814    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1815      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1816      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1817      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1818      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1819      return
1820    fi
1821    #
1822    if [ -d ${R_SAVE}/${1} ] ; then
1823      cd ${R_SAVE}
1824    elif [ -d ${R_FIGR}/${1} ] ; then
1825      cd ${R_FIGR}
1826    fi
1827
1828    IGCM_sys_Dods_Rm ${1}
1829    IGCM_sys_Dods_Cp ${1}
1830    status=0
1831
1832    if [ ${status} -gt 0 ] ; then
1833      echo "IGCM_sys_Put_Dods : error."
1834      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1835    fi
1836  fi
1837  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1838}
1839
1840##############################################################
1841# REBUILD OPERATOR
1842
1843#D-#==================================================
1844#D-function IGCM_sys_rebuild
1845#D-* Purpose: rebuild parallel files
1846#D-* Examples:
1847#D-
1848function IGCM_sys_rebuild {
1849  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1850  if ( $DEBUG_sys ) ; then
1851    echo "IGCM_sys_rebuild :" $@
1852  fi
1853
1854  typeset NB_ESSAI DELAI status i firstArg
1855  # number of tentative
1856  NB_ESSAI=3
1857  # time delay between tentative
1858  DELAI=2
1859
1860  i=0
1861  while [ $i -lt $NB_ESSAI ] ; do
1862    ~p86ipsl/X64_CURIE/bin/rebuild -f -o $@ > out_rsync 2>&1
1863    status=$?
1864    if [ ${status} -gt 0 ] ; then
1865      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1866      cat out_rsync
1867      \rm out_rsync
1868      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1869      firstArg=${1}
1870      \rm ${firstArg}
1871      sleep $DELAI
1872    else
1873      \rm out_rsync
1874      break
1875    fi
1876    (( i = i + 1 ))
1877  done
1878
1879  if [ ${status} -gt 0 ] ; then
1880    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1881    IGCM_debug_Exit "rebuild"
1882  fi
1883
1884  IGCM_debug_PopStack "IGCM_sys_rebuild"
1885}
1886
1887#D-#==================================================
1888#D-function IGCM_sys_rebuild_station
1889#D-* Purpose: rebuild parallel files describing station
1890#D-* Examples:
1891#D-
1892function IGCM_sys_rebuild_station {
1893  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1894  typeset i list_opt file_in file_out prefix_invert list_invert
1895  if ( $DEBUG_sys ) ; then
1896    echo "IGCM_sys_rebuild_station :" $@
1897  fi
1898  list_opt=$@
1899
1900  # Invert Axis : t,x -> x,t
1901  #               t,pres,x -> x,t,pres
1902  # So that we can concatenate along x
1903  i=0
1904  for file_in in ${list_opt} ; do
1905    (( i = i + 1))
1906    [ ${i} = 1 ] && file_out=${file_in} && continue
1907    prefix_invert=$( basename ${file_in} .nc )
1908    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1909    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1910  done
1911
1912  # Concatenate
1913  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1914
1915  # Re-ivert file
1916  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1917
1918  # Station re-ordering is too expansive to be run within libICGM
1919  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1920  # This re-ordering must be done "in memory" by the cmorization process
1921  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1922  # BEGIN reordering
1923
1924  # Only LMDZ text output contains the exact ordering of the station.
1925  # We isolate this in the code below:
1926  #  0  38  -157.5000000000000  70.98591549295774
1927  #  0  54  27.49999999999999   67.18309859154928
1928  #  0  56  -62.50000000000001  82.39436619718309
1929  #  0  79  12.49999999999999   78.59154929577466
1930  #  0  116 -165.0000000000000  76.05633802816901
1931  #  0  117 130.0000000000000   70.98591549295774
1932  #  0  118 110.0000000000000   87.46478873239437
1933  #  1  40  4.999999999999995   51.97183098591550
1934#  typeset iStation iProc list_opt file_in file_out prefix_invert
1935#  typeset -Z4 j4
1936#  typeset -Z3 j3
1937
1938#  unset list_opt
1939#  set +A list_opt $@
1940
1941  # Filename after rebuild
1942#  file_out=${list_opt[0]}
1943  # Prefix of output files
1944#  prefix_invert=$( basename ${file_out} .nc )
1945  # Number of procs
1946#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1947
1948#  iProc=0
1949#  while [ ${iProc} -lt ${num_proc} ] ; do
1950    # Array containing Station as a number
1951#    unset proc_stn
1952#    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}' )
1953    # Number of stations produced by processor proc
1954#    stationLast=${#proc_stn[*]}
1955    # Proc number on 4 digits
1956#    j4=${iProc}
1957    # Init
1958#    iStation=0
1959#    while [ ${iStation} -lt ${stationLast} ] ; do
1960      # Station number on 3 digits
1961#      j3=${proc_stn[${iStation}]}
1962      # Extract station
1963      # Invert Axis : t,x -> x,t
1964      #               t,pres,x -> x,t,pres
1965      # So that we can concatenate along x
1966#      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
1967#      (( iStation = iStation + 1 ))
1968#    done
1969#    (( iProc = iProc + 1 ))
1970#  done
1971
1972  # Concatenate all station along x
1973#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1974
1975  # Re-invert file
1976#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1977
1978  # END reordering
1979
1980  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1981}
1982
1983############################################################
1984# Activate Running Environnment Variables
1985
1986#D-#==================================================
1987#D-function IGCM_sys_desactiv_variables
1988#D-* Purpose: set environement variables prior to execution
1989#D-* Examples:
1990#D-
1991function IGCM_sys_activ_variables {
1992  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1993  if ( $DEBUG_sys ) ; then
1994    echo "IGCM_sys_activ_variables"
1995  fi
1996
1997# --------------------------------------------------------------------
1998#D- MPI specifications
1999# --------------------------------------------------------------------
2000
2001# --------------------------------------------------------------------
2002#D- Other specifications
2003# --------------------------------------------------------------------
2004
2005  ulimit -s unlimited
2006
2007  IGCM_debug_PopStack "IGCM_sys_activ_variables"
2008}
2009
2010############################################################
2011# Desactivate Running Environnment Variables
2012
2013#D-#==================================================
2014#D-function IGCM_sys_desactiv_variables
2015#D-* Purpose: unset environement variables after execution
2016#D-* Examples:
2017#D-
2018function IGCM_sys_desactiv_variables {
2019  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
2020  if ( $DEBUG_sys ) ; then
2021    echo "IGCM_sys_desactiv_variables"
2022  fi
2023# --------------------------------------------------------------------
2024#D- MPI specifications
2025# --------------------------------------------------------------------
2026
2027# --------------------------------------------------------------------
2028#D- Other specifications
2029# --------------------------------------------------------------------
2030
2031  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
2032}
2033
2034############################################################
2035# Build MPI/OMP scripts run file (dummy function)
2036
2037#D-#==================================================
2038#D-function IGCM_sys_build_run_file
2039#D-* Purpose: build run file (deprecated)
2040#D-* Examples:
2041#D-
2042function IGCM_sys_build_run_file {
2043
2044  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
2045
2046}
2047
2048############################################################
2049# Build MPI/OMP scripts
2050
2051#D-#==================================================
2052#D-function IGCM_sys_build_execution_scripts
2053#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
2054#D-* Examples:
2055#D-
2056function IGCM_sys_build_execution_scripts
2057{
2058  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
2059  if ( $DEBUG_sys ) ; then
2060    echo "IGCM_sys_build_execution_scripts " $@
2061  fi
2062
2063  EXECUTION=${HOST_MPIRUN_COMMAND}
2064
2065  if ( ${OK_PARA_MPMD} ) ; then
2066
2067    if [ -f run_file ] ; then
2068      IGCM_sys_Rm -f run_file
2069    fi
2070    touch run_file
2071
2072# run_file construction
2073
2074# Then first loop on the components for the coupler ie oasis
2075
2076## the coupler ie oasis must be the first one
2077    for comp in ${config_ListOfComponents[*]} ; do
2078
2079      eval ExeNameIn=\${config_Executable_${comp}[0]}
2080      eval ExeNameOut=\${config_Executable_${comp}[1]}
2081
2082      # for CPL component only
2083      if [ "X${comp}" = "XCPL" ] ; then
2084
2085        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2086        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2087        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2088      fi
2089    done
2090
2091# Then second loop on the components
2092
2093    for comp in ${config_ListOfComponents[*]} ; do
2094
2095      eval ExeNameIn=\${config_Executable_${comp}[0]}
2096      eval ExeNameOut=\${config_Executable_${comp}[1]}
2097
2098      # Only if we really have an executable for the component and not the coupler ie oasis:
2099      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
2100
2101        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2102        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2103        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2104      fi
2105    done
2106
2107    EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
2108
2109    IGCM_sys_Chmod u+x run_file
2110    if ( $DEBUG_sys ) ; then
2111      echo "run_file contains : "
2112      cat run_file
2113    fi
2114
2115  else # Only one executable. launch it.
2116
2117    for comp in ${config_ListOfComponents[*]} ; do
2118
2119      # Only if we really have an executable for the component :
2120      eval ExeNameOut=\${config_Executable_${comp}[1]}
2121      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2122
2123        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2124        echo ""  >> script_${ExeNameOut}.ksh
2125        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2126
2127        if ( ${OK_PARA_OMP} ) ; then
2128          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2129          echo ""  >> script_${ExeNameOut}.ksh
2130          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2131          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2132          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2133          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
2134        fi
2135
2136        if  ( ${OK_PARA_MPI} ) ; then
2137          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2138          # Default : ccc_mprun used if nb_proc gt 1
2139          # to have out/err per process on different files
2140          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
2141          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2142          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
2143        else
2144          # Default : ccc_mprun is NOT used if nb_proc eq 1
2145          # to have out/err per process on different files
2146          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
2147          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2148          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
2149        fi
2150
2151        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
2152        cat script_${ExeNameOut}.ksh
2153
2154      fi
2155
2156    done
2157
2158  fi
2159
2160  IGCM_debug_Print 1 "sys Curie : execution command is "
2161  IGCM_debug_Print 1 "$EXECUTION"
2162
2163  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2164}
2165
2166############################################################
2167# Check of space available on temporary filesytems.
2168
2169#D-#==================================================
2170#D-function IGCM_sys_check_quota
2171#D-* Purpose: check user quota. Stop the simulation if quota above 90%
2172#D-* Examples:
2173#D-
2174function IGCM_sys_check_quota {
2175  IGCM_debug_PushStack "IGCM_sys_check_quota"
2176  if ( $DEBUG_sys ) ; then
2177    echo "IGCM_sys_check_quota"
2178  fi
2179  # Limit of quota (in %)
2180  limit_quota=90
2181
2182  # Check of the volume
2183  volume_quota=$(ccc_quota | grep ' scratch' | awk '{print $2}')
2184  volume_avail=$(ccc_quota | grep ' scratch' | awk '{print $3}')
2185
2186  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
2187
2188    unit_avail=${volume_avail: -1}
2189    unit_quota=${volume_quota: -1}
2190
2191    if [ "${unit_quota}" = "*" ] ; then
2192      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2193      IGCM_debug_Print 1 "More than 100% of your quota is used"
2194      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2195      IGCM_debug_Print 1 "You must have more than 10% available to run"
2196      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2197      IGCM_debug_Verif_Exit
2198    fi
2199
2200    temp_avail=${volume_avail%%${volume_avail: -1}*}
2201    temp_quota=${volume_quota%%${volume_quota: -1}*}
2202
2203    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2204
2205    # Convertion
2206      if [ ${volume_avail: -1} = "T" ] ; then
2207        (( temp_avail = temp_avail * 1000000000000 ))
2208      elif [ ${volume_avail: -1} = "G" ] ; then
2209        (( temp_avail = temp_avail * 1000000000 ))
2210      elif [ ${volume_avail: -1} = "M" ] ; then
2211        (( temp_avail = temp_avail * 1000000 ))
2212      elif [ ${volume_avail: -1} = "k" ] ; then
2213        (( temp_avail = temp_avail * 1000 ))
2214      else
2215        (( temp_avail = volume_avail ))
2216      fi
2217      if [ ${volume_quota: -1} = "T" ] ; then
2218        (( temp_quota = temp_quota * 1000000000000 ))
2219      elif [ ${volume_quota: -1} = "G" ] ; then
2220        (( temp_quota = temp_quota * 1000000000 ))
2221      elif [ ${volume_quota: -1} = "M" ] ; then
2222        (( temp_quota = temp_quota * 1000000 ))
2223      elif [ ${volume_quota: -1} = "k" ] ; then
2224        (( temp_quota = temp_quota * 1000 ))
2225      else
2226        (( temp_quota = volume_quota ))
2227      fi
2228    fi
2229
2230    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2231#    echo "volume ratio is " $quota_volume
2232
2233    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2234      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2235      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2236      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2237      IGCM_debug_Print 1 "You must have more than 10% available to run"
2238      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2239      IGCM_debug_Verif_Exit
2240    fi
2241
2242  fi
2243
2244# Check of the number of inodes
2245
2246  inode_quota=$(ccc_quota | grep ' scratch' | awk '{print $6}')
2247  inode_avail=$(ccc_quota | grep ' scratch' | awk '{print $7}')
2248
2249  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
2250
2251    unit_avail=${inode_avail: -1}
2252    unit_quota=${inode_quota: -1}
2253
2254    if [ "${unit_quota}" = "*" ] ; then
2255      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2256      IGCM_debug_Print 1 "More than 100% of your quota is used"
2257      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2258      IGCM_debug_Print 1 "You must have more than 10% available to run"
2259      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2260      IGCM_debug_Verif_Exit
2261    fi
2262
2263    temp_avail=${inode_avail%%${inode_avail: -1}*}
2264    temp_quota=${inode_quota%%${inode_quota: -1}*}
2265
2266    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2267
2268    # Convertion
2269      if [ ${inode_avail: -1} = "T" ] ; then
2270        (( temp_avail = temp_avail * 1000000000000 ))
2271      elif [ ${inode_avail: -1} = "G" ] ; then
2272        (( temp_avail = temp_avail * 1000000000 ))
2273      elif [ ${inode_avail: -1} = "M" ] ; then
2274        (( temp_avail = temp_avail * 1000000 ))
2275      elif [ ${inode_avail: -1} = "k" ] ; then
2276        (( temp_avail = temp_avail * 1000 ))
2277      else
2278        (( temp_avail = inode_avail ))
2279      fi
2280
2281      if [ ${inode_quota: -1} = "T" ] ; then
2282        (( temp_quota = temp_quota * 1000000000000 ))
2283      elif [ ${inode_quota: -1} = "G" ] ; then
2284        (( temp_quota = temp_quota * 1000000000 ))
2285      elif [ ${inode_quota: -1} = "M" ] ; then
2286        (( temp_quota = temp_quota * 1000000 ))
2287      elif [ ${inode_quota: -1} = "k" ] ; then
2288        (( temp_quota = temp_quota * 1000 ))
2289      else
2290        (( temp_quota = inode_quota ))
2291      fi
2292    fi
2293    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2294#    echo "inode ratio is " $quota_inode
2295
2296    if [ ${quota_inode} -ge ${limit_quota} ] ; then
2297      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2298      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
2299      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2300      IGCM_debug_Print 1 "You must have more than 10% available to run"
2301      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2302      IGCM_debug_Verif_Exit
2303    fi
2304  fi
2305  IGCM_debug_PopStack "IGCM_sys_check_quota"
2306}
2307
2308#D-#==================================================
2309#D-function IGCM_sys_CountJobInQueue
2310#D-* Purpose: Check if job_name is currently
2311#D-  running or in queue
2312#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
2313#D-
2314function IGCM_sys_CountJobInQueue {
2315  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
2316  if ( $DEBUG_sys ) ; then
2317    echo "IGCM_sys_CountJobInQueue"
2318  fi
2319
2320  #NbRun=$( ccc_mstat -f | grep -c ${JobName} )
2321
2322  # With -f option, the full job name is given in the last column
2323  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ( $NF ~ JobName ) { x=x+1 } END { print x }' )
2324
2325  eval ${2}=${NbRun}
2326
2327  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
2328}
2329
2330##############################################################
2331# NCO OPERATOR
2332
2333#D-#==================================================
2334#D-function IGCM_sys_ncap2
2335#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2336#D-* Examples:
2337#D-
2338function IGCM_sys_ncap2 {
2339  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2340  if ( $DEBUG_sys ) ; then
2341    echo "IGCM_sys_ncap2 :" $@
2342  fi
2343
2344  typeset NB_ESSAI DELAI status i
2345  # number of tentative
2346  NB_ESSAI=3
2347  # time delay between tentative
2348  DELAI=2
2349
2350  i=0
2351  while [ $i -lt $NB_ESSAI ] ; do
2352    ncap2 "$@" > out_rsync 2>&1
2353    status=$?
2354    if [ ${status} -gt 0 ] ; then
2355      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2356      cat out_rsync
2357      \rm out_rsync
2358      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2359      sleep $DELAI
2360    else
2361      \rm out_rsync
2362      break
2363    fi
2364    (( i = i + 1 ))
2365  done
2366
2367  if [ ${status} -gt 0 ] ; then
2368    echo "IGCM_sys_ncap2 : ncap2 error"
2369    IGCM_debug_Exit "ncap2"
2370  fi
2371
2372  IGCM_debug_PopStack "IGCM_sys_ncap2"
2373}
2374
2375#D-#==================================================
2376#D-function IGCM_sys_ncatted
2377#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2378#D-* Examples:
2379#D-
2380function IGCM_sys_ncatted {
2381  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2382  if ( $DEBUG_sys ) ; then
2383    echo "IGCM_sys_ncatted :" $@
2384  fi
2385
2386  typeset NB_ESSAI DELAI status i
2387  # number of tentative
2388  NB_ESSAI=3
2389  # time delay between tentative
2390  DELAI=2
2391
2392  i=0
2393  while [ $i -lt $NB_ESSAI ] ; do
2394    ncatted "$@" > out_rsync 2>&1
2395    status=$?
2396    if [ ${status} -gt 0 ] ; then
2397      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2398      cat out_rsync
2399      \rm out_rsync
2400      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2401      sleep $DELAI
2402    else
2403      \rm out_rsync
2404      break
2405    fi
2406    (( i = i + 1 ))
2407  done
2408
2409  if [ ${status} -gt 0 ] ; then
2410    echo "IGCM_sys_ncatted : ncatted error"
2411    IGCM_debug_Exit "ncatted"
2412  fi
2413
2414  IGCM_debug_PopStack "IGCM_sys_ncatted"
2415}
2416
2417#D-#==================================================
2418#D-function IGCM_sys_ncbo
2419#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2420#D-* Examples:
2421#D-
2422function IGCM_sys_ncbo {
2423  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2424  if ( $DEBUG_sys ) ; then
2425    echo "IGCM_sys_ncbo :" $@
2426  fi
2427
2428  typeset NB_ESSAI DELAI status i
2429  # number of tentative
2430  NB_ESSAI=3
2431  # time delay between tentative
2432  DELAI=2
2433
2434  i=0
2435  while [ $i -lt $NB_ESSAI ] ; do
2436    ncbo $@ > out_rsync 2>&1
2437    status=$?
2438    if [ ${status} -gt 0 ] ; then
2439      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2440      cat out_rsync
2441      \rm out_rsync
2442      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2443      sleep $DELAI
2444    else
2445      \rm out_rsync
2446      break
2447    fi
2448    (( i = i + 1 ))
2449  done
2450
2451  if [ ${status} -gt 0 ] ; then
2452    echo "IGCM_sys_ncbo : ncbo error"
2453    IGCM_debug_Exit "ncbo"
2454  fi
2455
2456  IGCM_debug_PopStack "IGCM_sys_ncbo"
2457}
2458
2459#D-#==================================================
2460#D-function IGCM_sys_ncdif
2461#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2462#D-* Examples:
2463#D-
2464function IGCM_sys_ncdiff {
2465  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2466  if ( $DEBUG_sys ) ; then
2467    echo "IGCM_sys_ncdiff :" $@
2468  fi
2469
2470  typeset NB_ESSAI DELAI status i
2471  # number of tentative
2472  NB_ESSAI=3
2473  # time delay between tentative
2474  DELAI=2
2475
2476  i=0
2477  while [ $i -lt $NB_ESSAI ] ; do
2478    ncdiff $@ > out_rsync 2>&1
2479    status=$?
2480    if [ ${status} -gt 0 ] ; then
2481      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2482      cat out_rsync
2483      \rm out_rsync
2484      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2485      sleep $DELAI
2486    else
2487      \rm out_rsync
2488      break
2489    fi
2490    (( i = i + 1 ))
2491  done
2492
2493  if [ ${status} -gt 0 ] ; then
2494    echo "IGCM_sys_ncdiff : ncdiff error"
2495    IGCM_debug_Exit "ncdiff"
2496  fi
2497
2498  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2499}
2500
2501#D-#==================================================
2502#D-function IGCM_sys_ncea
2503#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2504#D-* Examples:
2505#D-
2506function IGCM_sys_ncea {
2507  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2508  if ( $DEBUG_sys ) ; then
2509    echo "IGCM_sys_ncea :" $@
2510  fi
2511
2512  typeset NB_ESSAI DELAI status i
2513  # number of tentative
2514  NB_ESSAI=3
2515  # time delay between tentative
2516  DELAI=2
2517
2518  i=0
2519  while [ $i -lt $NB_ESSAI ] ; do
2520    ncea $@ > out_rsync 2>&1
2521    status=$?
2522    if [ ${status} -gt 0 ] ; then
2523      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2524      cat out_rsync
2525      \rm out_rsync
2526      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2527      sleep $DELAI
2528    else
2529      \rm out_rsync
2530      break
2531    fi
2532    (( i = i + 1 ))
2533  done
2534
2535  if [ ${status} -gt 0 ] ; then
2536    echo "IGCM_sys_ncea : ncea error"
2537    IGCM_debug_Exit "ncea"
2538  fi
2539
2540  IGCM_debug_PopStack "IGCM_sys_ncea"
2541}
2542
2543#D-#==================================================
2544#D-function IGCM_sys_ncecat
2545#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2546#D-* Examples:
2547#D-
2548function IGCM_sys_ncecat {
2549  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2550  if ( $DEBUG_sys ) ; then
2551    echo "IGCM_sys_ncecat :" $@
2552  fi
2553
2554  typeset NB_ESSAI DELAI status i
2555  # number of tentative
2556  NB_ESSAI=3
2557  # time delay between tentative
2558  DELAI=2
2559
2560  i=0
2561  while [ $i -lt $NB_ESSAI ] ; do
2562    ncecat $@ > out_rsync 2>&1
2563    status=$?
2564    if [ ${status} -gt 0 ] ; then
2565      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2566      cat out_rsync
2567      \rm out_rsync
2568      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2569      sleep $DELAI
2570    else
2571      \rm out_rsync
2572      break
2573    fi
2574    (( i = i + 1 ))
2575  done
2576
2577  if [ ${status} -gt 0 ] ; then
2578    echo "IGCM_sys_ncecat : ncecat error"
2579    IGCM_debug_Exit "ncecat"
2580  fi
2581
2582  IGCM_debug_PopStack "IGCM_sys_ncecat"
2583}
2584
2585#D-#==================================================
2586#D-function IGCM_sys_ncflint
2587#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2588#D-* Examples:
2589#D-
2590function IGCM_sys_ncflint {
2591  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2592  if ( $DEBUG_sys ) ; then
2593    echo "IGCM_sys_ncflint :" $@
2594  fi
2595
2596  typeset NB_ESSAI DELAI status i
2597  # number of tentative
2598  NB_ESSAI=3
2599  # time delay between tentative
2600  DELAI=2
2601
2602  i=0
2603  while [ $i -lt $NB_ESSAI ] ; do
2604    ncflint $@ > out_rsync 2>&1
2605    status=$?
2606    if [ ${status} -gt 0 ] ; then
2607      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2608      cat out_rsync
2609      \rm out_rsync
2610      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2611      sleep $DELAI
2612    else
2613      \rm out_rsync
2614      break
2615    fi
2616    (( i = i + 1 ))
2617  done
2618
2619  if [ ${status} -gt 0 ] ; then
2620    echo "IGCM_sys_ncflint : ncflint error"
2621    IGCM_debug_Exit "ncflint"
2622  fi
2623
2624  IGCM_debug_PopStack "IGCM_sys_ncflint"
2625}
2626
2627#D-#==================================================
2628#D-function IGCM_sys_ncks
2629#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2630#D-* Examples:
2631#D-
2632function IGCM_sys_ncks {
2633  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2634  if ( $DEBUG_sys ) ; then
2635    echo "IGCM_sys_ncks :" $@
2636  fi
2637
2638  typeset NB_ESSAI DELAI status i
2639  # number of tentative
2640  NB_ESSAI=3
2641  # time delay between tentative
2642  DELAI=2
2643
2644  i=0
2645  while [ $i -lt $NB_ESSAI ] ; do
2646    ncks $@ > out_rsync 2>&1
2647    status=$?
2648    if [ ${status} -gt 0 ] ; then
2649      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2650      cat out_rsync
2651      \rm out_rsync
2652      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2653      sleep $DELAI
2654    else
2655      \rm out_rsync
2656      break
2657    fi
2658    (( i = i + 1 ))
2659  done
2660
2661  if [ ${status} -gt 0 ] ; then
2662    echo "IGCM_sys_ncks : ncks error"
2663    IGCM_debug_Exit "ncks"
2664  fi
2665
2666  IGCM_debug_PopStack "IGCM_sys_ncks"
2667}
2668
2669#D-#==================================================
2670#D-function IGCM_sys_ncpdq
2671#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2672#D-* Examples:
2673#D-
2674function IGCM_sys_ncpdq {
2675  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2676  if ( $DEBUG_sys ) ; then
2677    echo "IGCM_sys_ncpdq :" $@
2678  fi
2679
2680  typeset NB_ESSAI DELAI status i
2681  # number of tentative
2682  NB_ESSAI=3
2683  # time delay between tentative
2684  DELAI=2
2685
2686  i=0
2687  while [ $i -lt $NB_ESSAI ] ; do
2688    ncpdq $@ > out_rsync 2>&1
2689    status=$?
2690    if [ ${status} -gt 0 ] ; then
2691      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2692      cat out_rsync
2693      \rm out_rsync
2694      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2695      sleep $DELAI
2696    else
2697      \rm out_rsync
2698      break
2699    fi
2700    (( i = i + 1 ))
2701  done
2702
2703  if [ ${status} -gt 0 ] ; then
2704    echo "IGCM_sys_ncpdq : ncpdq error"
2705    IGCM_debug_Exit "ncpdq"
2706  fi
2707
2708  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2709}
2710
2711#D-#==================================================
2712#D-function IGCM_sys_ncra
2713#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2714#D-* Examples:
2715#D-
2716function IGCM_sys_ncra {
2717  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2718  if ( $DEBUG_sys ) ; then
2719    echo "IGCM_sys_ncra :" $@
2720  fi
2721
2722  typeset NB_ESSAI DELAI status i
2723  # number of tentative
2724  NB_ESSAI=3
2725  # time delay between tentative
2726  DELAI=2
2727
2728  i=0
2729  while [ $i -lt $NB_ESSAI ] ; do
2730    ncra $@ > out_rsync 2>&1
2731    status=$?
2732    if [ ${status} -gt 0 ] ; then
2733      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2734      cat out_rsync
2735      \rm out_rsync
2736      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2737      sleep $DELAI
2738    else
2739      \rm out_rsync
2740      break
2741    fi
2742    (( i = i + 1 ))
2743  done
2744
2745  if [ ${status} -gt 0 ] ; then
2746    echo "IGCM_sys_ncra : ncra error"
2747    IGCM_debug_Exit "ncra"
2748  fi
2749
2750  IGCM_debug_PopStack "IGCM_sys_ncra"
2751}
2752
2753#D-#==================================================
2754#D-function IGCM_sys_ncrcat
2755#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2756#D-* Examples:
2757#D-
2758function IGCM_sys_ncrcat {
2759  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2760  if ( $DEBUG_sys ) ; then
2761    echo "IGCM_sys_ncrcat :" $@
2762  fi
2763
2764  typeset NB_ESSAI DELAI status i lastArg
2765  # number of tentative
2766  NB_ESSAI=3
2767  # time delay between tentative
2768  DELAI=2
2769
2770  i=0
2771  while [ $i -lt $NB_ESSAI ] ; do
2772    ncrcat $@ > out_rsync 2>&1
2773    status=$?
2774    if [ ${status} -gt 0 ] ; then
2775      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2776      cat out_rsync
2777      \rm out_rsync
2778      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2779      sleep $DELAI
2780    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2781      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2782      cat out_rsync
2783      # remove files having corrupted time axis
2784      eval lastArg=\${$#}
2785      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2786      \rm ${lastArg}
2787      \rm out_rsync
2788      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2789      sleep $DELAI
2790    else
2791      \rm out_rsync
2792      break
2793    fi
2794    (( i = i + 1 ))
2795  done
2796
2797  if [ ${status} -gt 0 ] ; then
2798    echo "IGCM_sys_ncrcat : ncrcat error"
2799    #IGCM_debug_Exit "ncrcat"
2800  fi
2801
2802  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2803}
2804
2805#D-#==================================================
2806#D-function IGCM_sys_ncrename
2807#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2808#D-* Examples:
2809#D-
2810function IGCM_sys_ncrename {
2811  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2812  if ( $DEBUG_sys ) ; then
2813    echo "IGCM_sys_ncrename :" $@
2814  fi
2815
2816  typeset NB_ESSAI DELAI status i
2817  # number of tentative
2818  NB_ESSAI=3
2819  # time delay between tentative
2820  DELAI=2
2821
2822  i=0
2823  while [ $i -lt $NB_ESSAI ] ; do
2824    ncrename $@ > out_rsync 2>&1
2825    status=$?
2826    if [ ${status} -gt 0 ] ; then
2827      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2828      cat out_rsync
2829      \rm out_rsync
2830      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2831      sleep $DELAI
2832    else
2833      \rm out_rsync
2834      break
2835    fi
2836    (( i = i + 1 ))
2837  done
2838
2839  if [ ${status} -gt 0 ] ; then
2840    echo "IGCM_sys_ncrename : ncrename error"
2841    IGCM_debug_Exit "ncrename"
2842  fi
2843
2844  IGCM_debug_PopStack "IGCM_sys_ncrename"
2845}
2846
2847#D-#==================================================
2848#D-function IGCM_sys_ncwa
2849#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2850#D-* Examples:
2851#D-
2852function IGCM_sys_ncwa {
2853  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2854  if ( $DEBUG_sys ) ; then
2855    echo "IGCM_sys_ncwa :" $@
2856  fi
2857
2858  typeset NB_ESSAI DELAI status i
2859  # number of tentative
2860  NB_ESSAI=3
2861  # time delay between tentative
2862  DELAI=2
2863
2864  i=0
2865  while [ $i -lt $NB_ESSAI ] ; do
2866    ncwa $@ > out_rsync 2>&1
2867    status=$?
2868    if [ ${status} -gt 0 ] ; then
2869      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2870      cat out_rsync
2871      \rm out_rsync
2872      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2873      sleep $DELAI
2874    else
2875      \rm out_rsync
2876      break
2877    fi
2878    (( i = i + 1 ))
2879  done
2880
2881  if [ ${status} -gt 0 ] ; then
2882    echo "IGCM_sys_ncwa : ncwa error"
2883    IGCM_debug_Exit "ncwa"
2884  fi
2885
2886  IGCM_debug_PopStack "IGCM_sys_ncwa"
2887}
2888
2889##############################################################
2890# CDO OPERATOR
2891
2892#D-#==================================================
2893#D-function IGCM_sys_cdo
2894#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2895#D-* Examples:
2896#D-
2897function IGCM_sys_cdo {
2898  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2899  if ( $DEBUG_sys ) ; then
2900    echo "IGCM_sys_cdo :" $@
2901  fi
2902
2903  typeset status
2904
2905  \cdo $@ > out_rsync 2>&1
2906  status=$?
2907  if [ ${status} -gt 0 ] ; then
2908    echo "IGCM_sys_cdo : error code ${status}"
2909    cat out_rsync
2910    \rm out_rsync
2911    IGCM_debug_PopStack "IGCM_sys_cdo"
2912    return 1
2913  else
2914    IGCM_debug_PopStack "IGCM_sys_cdo"
2915    return 0
2916  fi
2917
2918  IGCM_debug_PopStack "IGCM_sys_cdo"
2919}
Note: See TracBrowser for help on using the repository browser.