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

Last change on this file since 863 was 863, checked in by jgipsl, 11 years ago

Changed to have rebuild in a directory with apropriate name for curie. The old directory will continue to exist containg a link to the new one.

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