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

Last change on this file since 912 was 912, checked in by sdipsl, 11 years ago

remove machines that are not available anymore
cleanup

  • Property svn:keywords set to Revision Author Date
File size: 82.6 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for Curie
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe/param/files |            |         |                           |
46# |          |  Chmod Qsub         |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=curie
71# add default project on curie
72typeset DEFAULT_PROJECT=gen0826
73
74#D-
75#D-#==================================================
76#D-Program used in libIGCM
77#D-#==================================================
78
79# Submit command
80typeset SUBMIT=${SUBMIT:=ccc_msub}
81# rsync with path
82typeset -r RSYNC=/usr/bin/rsync
83# RSYNC_opt args to rsync
84typeset -r RSYNC_opt="-va"
85# ie storage filesystem
86typeset -r STOREHOST=${MASTER}
87
88#====================================================
89# Source default environment
90#====================================================
91##. /etc/profile
92
93#====================================================
94# Set environment tools (ferret, nco, cdo)
95#====================================================
96if [ X${TaskType} = Xcomputing ] ; then
97  . /ccc/cont003/home/dsm/p86ipsl/.atlas_env_calcul_curie_ksh
98  export PATH=${PATH}:/ccc/cont003/home/dsm/p86ipsl/AddNoise/src_X64/bin
99else
100  . /ccc/cont003/home/dsm/p86ipsl/.atlas_env_post_curie_ksh
101fi
102
103#====================================================
104# Specific for ocean additionnal diagnostic
105export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
106export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
107
108#====================================================
109# Host specific DIRECTORIES
110#====================================================
111
112# ============ CESIUM START ============ #
113
114#====================================================
115#- Mirror libIGCM from titane to cesium if needed
116#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
117#if [ ! ${ROOTSYS} = "home" ] ; then
118#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
119#else
120#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
121#fi
122
123#====================================================
124#- libIGCM_POST
125#if ( ${MirrorlibIGCM} ) ; then
126#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
127#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
128#else
129#  typeset -r libIGCM_POST=${libIGCM}
130#fi
131
132# ============ CESIUM  END  ============ #
133
134#====================================================
135#- MirrorlibIGCM for frontend
136typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
137
138#====================================================
139#- libIGCM_POST for frontend
140typeset -r libIGCM_POST=${libIGCM}
141
142#====================================================
143#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
144typeset -r R_EXE="${MODIPSL}/bin"
145
146#====================================================
147#- SUBMIT_DIR : submission dir
148typeset SUBMIT_DIR=${SUBMIT_DIR:=${BRIDGE_MSUB_PWD}}
149
150#====================================================
151#- IN
152typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
153typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/ccc/work/cont003/dsm/p24data}
154
155#====================================================
156#- ARCHIVE (dedicated to large files)
157typeset ARCHIVE=${CCCSTOREDIR}
158
159#====================================================
160#- STORAGE (dedicated to small/medium files)
161typeset STORAGE=${CCCWORKDIR}
162
163#====================================================
164#- R_OUT
165typeset R_OUT=${ARCHIVE}/IGCM_OUT
166
167#====================================================
168#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
169typeset R_FIG=${STORAGE}/IGCM_OUT
170
171#====================================================
172#- R_BUF (ONLY FOR double copy an scratch)
173typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
174
175#====================================================
176#- RUN_DIR_PATH : Temporary working directory (=> TMP)
177typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${BRIDGE_MSUB_JOBID}_${$}}
178
179#====================================================
180#- HOST_MPIRUN_COMMAND
181typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="/usr/bin/time ccc_mprun -E-K1"}
182
183#====================================================
184#- Max number of arguments passed to nco operator or demigration command
185UNIX_MAX_LIMIT=360
186
187#====================================================
188#- set PackDefault true on curie
189PackDefault=true
190
191#====================================================
192#- Number of core per node (max number of OpenMP task)
193NUM_COREPERNODE=8
194
195#====================================================
196#- Default number of MPI task for IPSL coupled model
197#- required for backward compatibility
198#-
199DEFAULT_NUM_PROC_OCE=5
200DEFAULT_NUM_PROC_CPL=1
201(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
202DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
203
204#D-#==================================================
205#D-function IGCM_sys_ChangeArchive
206#D-* Purpose: if SpaceName=TEST everything is stored on SCRATCHDIR
207#D-* Examples:
208#D-
209function IGCM_sys_ChangeArchive {
210  IGCM_debug_PushStack "IGCM_sys_ChangeArchive"
211
212  R_OUT=${SCRATCHDIR}/IGCM_OUT
213  R_FIG=${SCRATCHDIR}/IGCM_OUT
214
215  IGCM_debug_Print 1 "R_OUT   has been redefined = ${R_OUT}"
216  IGCM_debug_Print 1 "R_FIG   has been redefined = ${R_FIG}"
217
218  IGCM_debug_PopStack "IGCM_sys_ChangeArchive"
219}
220
221#D-#==================================================
222#D-function IGCM_sys_RshMaster
223#D-* Purpose: Connection to frontend machine.
224#D-* Examples:
225#D-
226function IGCM_sys_RshMaster {
227  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
228  /bin/ksh <<-EOF
229    export libIGCM=${libIGCM}
230    export DEBUG_debug=${DEBUG_debug}
231    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
232    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
233    ${@}
234EOF
235  if [ $? -gt 0 ] ; then
236    echo "IGCM_sys_RshMaster : erreur."
237    IGCM_debug_Exit "IGCM_sys_RshMaster"
238  fi
239  IGCM_debug_PopStack "IGCM_sys_RshMaster"
240}
241
242#D-#==================================================
243#D-function IGCM_sys_RshArchive
244#D-* Purpose: Archive rsh command
245#D-* Examples:
246#D-
247function IGCM_sys_RshArchive {
248  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
249  /bin/ksh <<-EOF
250    ${@}
251EOF
252  status=$?
253  if [ ${status} -gt 0 ] ; then
254    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
255    IGCM_debug_Exit "IGCM_sys_RshArchive"
256  fi
257  IGCM_debug_PopStack "IGCM_sys_RshArchive"
258}
259
260#D-#==================================================
261#D-function IGCM_sys_RshArchive_NoError
262#D-* Purpose: Archive rsh command, without error
263#D-*          used only in monitoring.job
264#D-* Examples:
265#D-
266function IGCM_sys_RshArchive_NoError {
267  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
268  /bin/ksh <<-EOF
269    ${@} 2> \dev\null
270EOF
271  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
272}
273
274#D-#==================================================
275#D-function IGCM_sys_RshPost
276#D-* Purpose: Post-process rsh command
277#D-* Examples:
278#D-
279function IGCM_sys_RshPost {
280  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
281  if ( $DEBUG_sys ) ; then
282    echo "IGCM_sys_RshPost :" $@
283  fi
284  # keep standard input (stdin) for the loop onto temporary file
285  cat >/tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
286
287  /bin/ksh </tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
288  if [ $? -gt 0 ] ; then
289    echo "IGCM_sys_RshPost : erreur."
290    IGCM_debug_Exit "IGCM_sys_RshPost"
291  fi
292  # delete temporary file
293  \rm /tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
294
295# ============ FRONTEND  END  ============ #
296
297# ============ CESIUM START ============ #
298#  typeset NB_ESSAI DELAI status i
299#  if [ "X$( grep rebuild_from tmp_IGCM_sys_RshPost_$$ )" != "X" ] ; then
300#    #little hack so that rebuild submission is done on titane not an cesium
301#
302#    libIGCM_POST_sed=$( echo $libIGCM_POST | sed 's/\//\\\//g' )
303#    POST_DIR_sed=$( echo ${POST_DIR} | sed 's/\//\\\//g' )
304#    sed "s/IGCM_sys_QsubPost/IGCM_sys_Qsub/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
305#    sed "s/ rebuild_fromWorkdir/ ${libIGCM_POST_sed}\/rebuild_fromWorkdir.job/g" tmp.txt > tmp_IGCM_sys_RshPost_$$
306#    sed "s/ rebuild_fromArchive/ ${libIGCM_POST_sed}\/rebuild_fromArchive.job/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
307#    sed "s/Script_Post_Output=/Script_Output=${POST_DIR_sed}\//g" tmp.txt > tmp_IGCM_sys_RshPost_$$
308#    \mv tmp.txt tmp_IGCM_sys_RshPost_$$
309#
310#    echo cat tmp_IGCM_sys_RshPost_$$ AFTER
311#    cat tmp_IGCM_sys_RshPost_$$
312#
313#    /bin/ksh <tmp_IGCM_sys_RshPost_$$
314#    if [ $? -gt 0 ] ; then
315#      echo "IGCM_sys_RshPost : erreur."
316#      IGCM_debug_Exit "IGCM_sys_RshPost"
317#    fi
318#    # delete temporary file
319#    \rm tmp_IGCM_sys_RshPost_$$
320#
321#  else
322#    # number of tentative
323#    NB_ESSAI=10
324#    # time delay between tentative
325#    DELAI=10
326#    i=0
327#    while [ $i -ne $NB_ESSAI ] ; do
328#      ssh -t titane996 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
329#      status=$?
330#      if [ ${status} -ne 0 ];
331#      then
332#        sleep $DELAI
333#      else
334#        break
335#      fi
336#      let i=$i+1
337#    done
338#    # delete temporary file
339#    \rm tmp_IGCM_sys_RshPost_$$
340#
341#    if [ ${status} -gt 0 ] ; then
342#      echo "IGCM_sys_RshPost : erreur."
343#      IGCM_debug_Exit "IGCM_sys_RshPost"
344#    fi
345#  fi
346
347# ============ CESIUM  END  ============ #
348
349  IGCM_debug_PopStack "IGCM_sys_RshPost"
350}
351
352#D-#==================================================
353#D-function IGCM_sys_SendMail
354#D-* Purpose: Send mail when simulation is over
355#D-* Examples:
356#D-
357function IGCM_sys_SendMail {
358  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
359  if ( $DEBUG_sys ) ; then
360    echo "IGCM_sys_SendMail :" $@
361  fi
362
363  if ( ${ExitFlag} ) ; then
364    status=failed
365  else
366    status=completed
367  fi
368
369  cat  << END_MAIL > job_end.mail
370Dear ${LOGIN},
371
372  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
373  Job started : ${DateBegin}
374  Job ended   : ${DateEnd}
375  Output files are available in ${R_SAVE}
376  Files to be rebuild are temporarily available in ${REBUILD_DIR}
377  Pre-packed files are temporarily available in ${R_BUFR}
378  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
379END_MAIL
380
381  if [ ! -z ${config_UserChoices_MailName} ] ; then
382    mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < job_end.mail
383  elif [ -f ~/.forward ] ; then
384    mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
385  fi
386
387  sleep 10
388  rm -f job_end.mail
389
390  if [ $? -gt 0 ] ; then
391    echo "IGCM_sys_SendMail : erreur."
392    IGCM_debug_Exit "IGCM_sys_SendMail"
393  fi
394  IGCM_debug_PopStack "IGCM_sys_SendMail"
395}
396
397#D-#==================================================
398#D-function IGCM_sys_Mkdir
399#D-* Purpose: Master locale mkdir command
400#D-* Examples:
401#D-
402function IGCM_sys_Mkdir {
403  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
404  if ( $DEBUG_sys ) ; then
405    echo "IGCM_sys_Mkdir :" $@
406  fi
407  if [ ! -d ${1} ]; then
408    \mkdir -p $1
409    if [ $? -gt 0 ] ; then
410      echo "IGCM_sys_Mkdir : erreur."
411      IGCM_debug_Exit "IGCM_sys_Mkdir"
412    fi
413  fi
414  # vérification :
415  if [ ! -d ${1} ] ; then
416    echo "IGCM_sys_Mkdir : erreur."
417    IGCM_debug_Exit "IGCM_sys_Mkdir"
418  fi
419  IGCM_debug_PopStack "IGCM_sys_Mkdir"
420}
421
422#D-#==================================================
423#D-function IGCM_sys_MkdirArchive
424#D-* Purpose: Mkdir on Archive
425#D-* Examples:
426#D-
427function IGCM_sys_MkdirArchive {
428  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
429  if ( $DEBUG_sys ) ; then
430    echo "IGCM_sys_MkdirArchive :" $@
431  fi
432  #- creation de repertoire sur le serveur fichier
433  if [ ! -d ${1} ]; then
434    \mkdir -p $1
435    status=$?
436
437    if [ ${status} -gt 0 ] ; then
438      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
439      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
440    fi
441  fi
442  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
443}
444
445#D-#==================================================
446#D-function IGCM_sys_MkdirWork
447#D-* Purpose: Mkdir on Work
448#D-* Examples:
449#D-
450function IGCM_sys_MkdirWork {
451  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
452  if ( $DEBUG_sys ) ; then
453    echo "IGCM_sys_MkdirWork :" $@
454  fi
455  #- creation de repertoire sur le serveur fichier
456  if [ ! -d ${1} ]; then
457    \mkdir -p $1
458    if [ $? -gt 0 ] ; then
459      echo "IGCM_sys_MkdirWork : erreur."
460      IGCM_debug_Exit "IGCM_sys_MkdirWork"
461    fi
462  fi
463  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
464}
465
466#D-#==================================================
467#D-function IGCM_sys_Cd
468#D-* Purpose: master cd command
469#D-* Examples:
470#D-
471function IGCM_sys_Cd {
472  IGCM_debug_PushStack "IGCM_sys_Cd" $@
473  if ( $DEBUG_sys ) ; then
474    echo "IGCM_sys_Cd :" $@
475  fi
476  \cd $1
477  if [ $? -gt 0 ] ; then
478    echo "IGCM_sys_Cd : erreur."
479    IGCM_debug_Exit "IGCM_sys_Cd"
480  fi
481  IGCM_debug_PopStack "IGCM_sys_Cd"
482}
483
484#D-#==================================================
485#D-function IGCM_sys_Chmod
486#D-* Purpose: Chmod
487#D-* Examples:
488#D-
489function IGCM_sys_Chmod {
490  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
491  if ( $DEBUG_sys ) ; then
492    echo "IGCM_sys_Chmod :" $@
493  fi
494  \chmod $@
495  if [ $? -gt 0 ] ; then
496    echo "IGCM_sys_Chmod : erreur."
497    IGCM_debug_Exit "IGCM_sys_Chmod"
498  fi
499  IGCM_debug_PopStack "IGCM_sys_Chmod"
500}
501
502#D-#==================================================
503#D-function IGCM_sys_FileSize
504#D-* Purpose: Filesize
505#D-* Examples:
506#D-
507function IGCM_sys_FileSize {
508  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
509
510  typeset sizeF
511  set +A sizeF -- $( ls -la ${1} )
512  if [ $? -gt 0 ] ; then
513    IGCM_debug_Exit "IGCM_sys_FileSize"
514  fi
515  eval ${2}=${sizeF[4]}
516
517  IGCM_debug_PopStack "IGCM_sys_FileSize"
518}
519
520#D-#==================================================
521#D-function IGCM_sys_TestDir
522#D-* Purpose: Test Directory that must exists
523#D-* Examples:
524#D-
525function IGCM_sys_TestDir {
526  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
527  if ( $DEBUG_sys ) ; then
528    echo "IGCM_sys_TestDir :" $@
529  fi
530  typeset ExistFlag
531  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
532  IGCM_debug_PopStack "IGCM_sys_TestDir"
533
534  return ${ExistFlag}
535}
536
537#D-#==================================================
538#D-function IGCM_sys_TestDirArchive
539#D-* Purpose: Test Directory that must exists on Archive
540#D-* Examples:
541#D-
542function IGCM_sys_TestDirArchive {
543  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
544  if ( $DEBUG_sys ) ; then
545    echo "IGCM_sys_TestDirArchive :" $@
546  fi
547  typeset ExistFlag
548  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
549  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
550  return ${ExistFlag}
551}
552
553#D-#==================================================
554#D-function IGCM_sys_IsFileArchived
555#D-* Purpose: Test file that must NOT EXISTS on Archive
556#D-* Examples:
557#D-
558function IGCM_sys_IsFileArchived {
559  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
560  if ( $DEBUG_sys ) ; then
561    echo "IGCM_sys_IsFileArchived :" $@
562  fi
563  typeset IsArchivedFlag
564  IsArchivedFlag=$( [ X$( echo $@ | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
565  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
566
567  return ${IsArchivedFlag}
568}
569
570#D-#==================================================
571#D-function IGCM_sys_TestFileArchive
572#D-* Purpose: Test file that must NOT EXISTS on Archive
573#D-* Examples:
574#D-
575function IGCM_sys_TestFileArchive {
576  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
577  typeset ExistFlag
578  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
579  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
580
581  return ${ExistFlag}
582}
583
584#D-#==================================================
585#D-function IGCM_sys_TestFileBuffer
586#D-* Purpose: Test file that must NOT EXISTS on Buffer
587#D-* Examples:
588#D-
589function IGCM_sys_TestFileBuffer {
590  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
591  typeset ExistFlag
592  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
593  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
594
595  return ${ExistFlag}
596}
597
598#D-#==================================================
599#D-function IGCM_sys_CountFileArchive
600#D-* Purpose: Count files on Archive filesystem
601#D-* Examples:
602#D-
603function IGCM_sys_CountFileArchive {
604  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
605  ls ${@} 2>/dev/null | wc -l
606  if [ $? -gt 0 ] ; then
607    echo "IGCM_sys_CountFileArchive : erreur."
608  fi
609  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
610}
611
612#D-#==================================================
613#D-function IGCM_sys_CountFileBuffer
614#D-* Purpose: Count files on Scratch filesystem
615#D-* Examples:
616#D-
617function IGCM_sys_CountFileBuffer {
618  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
619  ls ${@} 2>/dev/null | wc -l
620  if [ $? -gt 0 ] ; then
621    echo "IGCM_sys_CountFileBuffer : erreur."
622  fi
623  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
624}
625
626#D-#==================================================
627#D-function IGCM_sys_Tree
628#D-* Purpose: Tree directories with files on ${ARCHIVE}
629#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
630#D-
631function IGCM_sys_Tree {
632  IGCM_debug_PushStack "IGCM_sys_Tree" $@
633  if ( $DEBUG_sys ) ; then
634    echo "IGCM_sys_Tree :" $@
635  fi
636
637  \ls -lR ${@}
638
639  IGCM_debug_PopStack "IGCM_sys_Tree"
640}
641
642#D-#==================================================
643#D-function IGCM_sys_Tar
644#D-* Purpose: master tar command
645#D-* Examples:
646#D-
647function IGCM_sys_Tar {
648  IGCM_debug_PushStack "IGCM_sys_Tar" $@
649  if ( $DEBUG_sys ) ; then
650    echo "IGCM_sys_Tar :" $@
651  fi
652  \tar cf $@
653  if [ $? -gt 0 ] ; then
654    echo "IGCM_sys_Tar : erreur."
655    IGCM_debug_Exit "IGCM_sys_Tar"
656  fi
657  IGCM_debug_PopStack "IGCM_sys_Tar"
658}
659
660#D-#==================================================
661#D-function IGCM_sys_UnTar
662#D-* Purpose: master un-tar command
663#D-* Examples:
664#D-
665function IGCM_sys_UnTar {
666  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
667  if ( $DEBUG_sys ) ; then
668    echo "IGCM_sys_UnTar :" $@
669  fi
670  \tar xvf $1
671  if [ $? -gt 0 ] ; then
672    echo "IGCM_sys_UnTar : erreur."
673    IGCM_debug_Exit "IGCM_sys_UnTar"
674  fi
675  IGCM_debug_PopStack "IGCM_sys_UnTar"
676}
677
678#D-#==================================================
679#D-function IGCM_sys_Qsub
680#D-* Purpose: Qsub new job
681#D-* Examples:
682#D-
683function IGCM_sys_Qsub {
684  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
685  if ( $DEBUG_sys ) ; then
686    echo "IGCM_sys_Qsub :" $@
687  fi
688  typeset options status
689#  if [ ${config_UserChoices_JobName}.${CumulPeriod} = "." ] ; then
690    options=" -o ${SUBMIT_DIR}/${Script_Output} -e ${SUBMIT_DIR}/${Script_Output}"
691#  else
692#    options=" -o ${SUBMIT_DIR}/${Script_Output} -e ${SUBMIT_DIR}/${Script_Output} -r ${config_UserChoices_JobName}.${CumulPeriod}"
693#  fi
694
695  /usr/bin/ccc_msub ${options} < $1
696  status=$?
697  if [ ${status} -gt 0 ] ; then
698    IGCM_debug_Print 2 "IGCM_sys_Qsub ${options} $1 : error code ${status}"
699    IGCM_debug_Exit "IGCM_sys_Qsub"
700  fi
701  IGCM_debug_PopStack "IGCM_sys_Qsub"
702}
703
704#D-#==================================================
705#D-function IGCM_sys_QsubPost
706#D-* Purpose: Qsub new job on scalaire
707#D-* Examples:
708#D-
709function IGCM_sys_QsubPost {
710  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
711  if ( $DEBUG_sys ) ; then
712    echo "IGCM_sys_QsubPost :" $@
713  fi
714  typeset status
715  MY_PROJECT=$(echo ${BRIDGE_MSUB_PROJECT:=${DEFAULT_PROJECT}} | cut -d@ -f1 )
716  /usr/bin/ccc_msub -Q normal -A ${MY_PROJECT} -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out ${libIGCM_POST}/$1.job
717  status=$?
718  if [ ${status} -gt 0 ] ; then
719    IGCM_debug_Print 2 "IGCM_sys_QsubPost $1 : error code ${status}"
720    IGCM_debug_Exit "IGCM_sys_QsubPost"
721  fi
722  IGCM_debug_PopStack "IGCM_sys_QsubPost"
723}
724
725#D-*************************
726#D- File transfer functions
727#D-*************************
728#D-
729
730#D-#==================================================
731#D-function IGCM_sys_Rsync_out
732#D-* Purpose: treat return val of rsync
733#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
734#D-  Error values and explanations can depend on your system version.
735function IGCM_sys_Rsync_out {
736  status=$1
737  if [ ! $status ] ; then
738    echo "rsync error !"
739  fi
740
741  if [ $MYLANG = "fr" ]; then
742    case $status in
743    0)  return ;;
744    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
745      echo "Erreur de syntaxe ou d'utilisation."
746      return;;
747    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
748      echo "Incompatibilité de protocole."
749      return;;
750    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
751      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
752      echo "répertoires"
753      return;;
754    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
755      echo "Action demandée non supportée : une tentative de manipulation de"
756      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
757      echo "été faite ; ou une option qui est supportée par le  client  mais"
758      echo "pas par le serveur a été spécifiée."
759      return;;
760    10) echo "Erreur de rsync ; RERR_SOCKETIO"
761      echo "Erreur dans le socket d'entrée sortie"
762      return;;
763    11) echo "Erreur de rsync ; RERR_FILEIO"
764      echo "Erreur d'entrée sortie fichier"
765      return;;
766    12) echo "Erreur de rsync ; RERR_STREAMIO"
767      echo "Erreur dans flux de donnée du protocole rsync"
768      return;;
769    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
770      echo "Erreur avec les diagnostics du programme"
771      return;;
772    14) echo "Erreur de rsync ; RERR_IPC"
773      echo "Erreur dans le code IPC"
774      return;;
775    20) echo "Erreur de rsync ; RERR_SIGNAL"
776      echo "SIGUSR1 ou SIGINT reçu"
777      return;;
778    21) echo "Erreur de rsync ; RERR_WAITCHILD"
779      echo "Une erreur retournée par waitpid()"
780      return;;
781    22) echo "Erreur de rsync ; RERR_MALLOC"
782      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
783      return;;
784    23) echo ""
785      echo "Erreur fichier inexistant"
786      return;;
787    30) echo "Erreur de rsync ; RERR_TIMEOUT"
788      echo "Temps d'attente écoulé dans l'envoi/réception de données"
789      return;;
790    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
791      return;;
792    esac
793  elif [ $MYLANG = "en" ] ; then
794    case $status in
795    0)  return;;
796    1)  echo "rsync error : Syntax or usage error "
797      return;;
798    2)  echo "rsync error : Protocol incompatibility "
799      return;;
800    3)  echo "rsync error : Errors selecting input/output files, dirs"
801      return;;
802    4)  echo "rsync error : Requested action not supported: an attempt"
803      echo "was made to manipulate 64-bit files on a platform that cannot support"
804      echo "them; or an option was specified that is supported by the client and"
805      echo "not by the server."
806      return;;
807    5)  echo "rsync error : Error starting client-server protocol"
808      return;;
809    10) echo "rsync error : Error in socket I/O "
810      return;;
811    11) echo "rsync error : Error in file I/O "
812      return;;
813    12) echo "rsync error : Error in rsync protocol data stream "
814      return;;
815    13) echo "rsync error : Errors with program diagnostics "
816      return;;
817    14) echo "rsync error : Error in IPC code "
818      return;;
819    20) echo "rsync error : Received SIGUSR1 or SIGINT "
820      return;;
821    21) echo "rsync error : Some error returned by waitpid() "
822      return;;
823    22) echo "rsync error : Error allocating core memory buffers "
824      return;;
825    23) echo "rsync error : Partial transfer due to error"
826      return;;
827    24) echo "rsync error : Partial transfer due to vanished source files"
828      return;;
829    30) echo "rsync error : Timeout in data send/receive "
830      return;;
831    *)  echo "rsync error : return code of rsync unknown :" $status
832      return;;
833    esac
834  else
835    echo "unknown language $MYLANG."
836    return
837  fi
838}
839
840#D-#==================================================
841#D-function IGCM_sys_Miror_libIGCM
842#D-* Purpose: Mirror libIGCM PATH and lib to frontend
843#D-* Examples:
844#D-
845function IGCM_sys_Mirror_libIGCM {
846  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
847  if ( $DEBUG_sys ) ; then
848    echo "IGCM_sys_Mirror_libIGCM"
849  fi
850
851  typeset status
852
853  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
854
855  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
856  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
857  status=$?
858
859  if [ ${status} -gt 0 ] ; then
860    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on frontend."
861    cat out_rsync
862  fi
863  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
864}
865
866#D-#==================================================
867#D-function IGCM_sys_Cp
868#D-* Purpose: generic cp
869#D-* Examples:
870#D-
871function IGCM_sys_Cp {
872  IGCM_debug_PushStack "IGCM_sys_Cp" $@
873  if ( $DEBUG_sys ) ; then
874    echo "IGCM_sys_Cp :" $@
875  fi
876
877  typeset status
878
879  echo cp $@ > out_rsync 2>&1
880  \cp $@ >> out_rsync 2>&1
881  status=$?
882
883  if [ ${status} -gt 0 ] ; then
884    echo "IGCM_sys_Cp : error code ${status}"
885    cat out_rsync
886    IGCM_debug_Exit "IGCM_sys_Cp"
887  else
888    \rm out_rsync
889  fi
890  IGCM_debug_PopStack "IGCM_sys_Cp"
891}
892
893#D-#==================================================
894#D-function IGCM_sys_Rm
895#D-* Purpose: generic rm
896#D-* Examples:
897#D-
898function IGCM_sys_Rm {
899  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
900  if ( $DEBUG_sys ) ; then
901    echo "IGCM_sys_Rm :" $@
902  fi
903
904  typeset status
905
906  echo rm $@ > out_rsync 2>&1
907  \rm $@ >> out_rsync 2>&1
908  status=$?
909
910  if [ ${status} -gt 0 ] ; then
911    echo "IGCM_sys_Rm : error code ${status}"
912    cat out_rsync
913    IGCM_debug_Exit "IGCM_sys_Rm"
914  else
915    \rm out_rsync
916  fi
917  IGCM_debug_PopStack "IGCM_sys_Rm"
918}
919
920#D-#==================================================
921#D-function IGCM_sys_RmRunDir
922#D-* Purpose: rm tmpdir (dummy function most of the time batch
923#D-                      scheduler will do the job)
924#D-* Examples:
925#D-
926function IGCM_sys_RmRunDir {
927  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
928  if ( $DEBUG_sys ) ; then
929    echo "IGCM_sys_RmRunDir :" $@
930  fi
931
932  typeset status
933
934  echo rm $@ > out_rsync 2>&1
935  \rm $@ >> out_rsync 2>&1
936  status=$?
937
938  if [ ${status} -gt 0 ] ; then
939    echo "IGCM_sys_RmRunDir : rm error code is ${status}."
940    cat out_rsync
941    IGCM_debug_Exit "IGCM_sys_RmRunDir"
942  else
943    \rm out_rsync
944  fi
945  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
946}
947
948#D-#==================================================
949#D-function IGCM_sys_Mv
950#D-* Purpose: generic move
951#D-* Examples:
952#D-
953function IGCM_sys_Mv {
954  IGCM_debug_PushStack "IGCM_sys_Mv" $@
955  if ( $DEBUG_sys ) ; then
956    echo "IGCM_sys_Mv :" $@
957  fi
958
959  if [ $DRYRUN = 0 ]; then
960
961    typeset status
962
963    echo mv $@ > out_rsync 2>&1
964    \mv $@ >> out_rsync 2>&1
965    status=$?
966
967    if [ ${status} -gt 0 ] ; then
968      echo "IGCM_sys_Mv : error code ${status}"
969      cat out_rsync
970      IGCM_debug_Exit "IGCM_sys_Mv"
971    else
972      \rm out_rsync
973    fi
974  fi
975
976  IGCM_debug_PopStack "IGCM_sys_Mv"
977}
978
979#D-#==================================================
980#D-function IGCM_sys_Put_Dir
981#D-* Purpose: Copy a complete directory on $(ARCHIVE)
982#D-* Examples:
983#D-
984function IGCM_sys_Put_Dir {
985  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
986  if ( $DEBUG_sys ) ; then
987    echo "IGCM_sys_Put_Dir :" $@
988  fi
989  if [ $DRYRUN = 0 ]; then
990    if [ ! -d ${1} ] ; then
991      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
992      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
993      return
994    fi
995
996    typeset status
997
998    # Only if we use rsync
999    #IGCM_sys_TestDirArchive $( dirname $2 )
1000    #
1001    #USUAL WAY
1002    \cp -r $1 $2 > out_rsync 2>&1
1003    status=$?
1004
1005    if [ ${status} -gt 0 ] ; then
1006      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
1007      cat out_rsync
1008      IGCM_debug_Exit "IGCM_sys_Put_Dir"
1009    else
1010      \rm out_rsync
1011    fi
1012  fi
1013  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1014}
1015
1016#D-#==================================================
1017#D-function IGCM_sys_Get_Dir
1018#D-* Purpose: Copy a complete directory from ${ARCHIVE}
1019#D-* Examples:
1020#D-
1021function IGCM_sys_Get_Dir {
1022  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
1023  if ( $DEBUG_sys ) ; then
1024    echo "IGCM_sys_Get_Dir :" $@
1025  fi
1026  if [ $DRYRUN = 0 ]; then
1027#    if [ ! -d ${1} ] ; then
1028#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
1029#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1030#      return
1031#    fi
1032
1033    typeset NB_ESSAI DELAI status i
1034    # number of tentative
1035    NB_ESSAI=3
1036    # time delay between tentative
1037    DELAI=2
1038
1039    # Only if we use rsync
1040    #IGCM_sys_TestDirArchive $( dirname $2 )
1041    #
1042    # USUAL WAY
1043    # add 'ccc_hsm get' (to demigrate all offline files) to reduce time of this command :
1044    ccc_hsm get -r $1
1045
1046    i=0
1047    while [ $i -lt $NB_ESSAI ] ; do
1048      \cp -ur $1 $2 >> out_rsync 2>&1
1049      status=$?
1050      if [ ${status} -gt 0 ] ; then
1051        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}"
1052        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
1053        sleep $DELAI
1054      else
1055        break
1056      fi
1057      (( i = i + 1 ))
1058    done
1059
1060    if [ ${status} -gt 0 ] ; then
1061      echo "IGCM_sys_Get_Dir : error."
1062      cat out_rsync
1063      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1064    else
1065      \rm out_rsync
1066    fi
1067  fi
1068  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1069}
1070
1071#D-#==================================================
1072#D-function IGCM_sys_Get_Master
1073#D-* Purpose: Copy a complete directory from MASTER filesystem
1074#D-* Examples:
1075#D-
1076function IGCM_sys_Get_Master {
1077  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1078  if ( $DEBUG_sys ) ; then
1079    echo "IGCM_sys_Get_Master :" $@
1080  fi
1081  if [ $DRYRUN = 0 ]; then
1082    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
1083      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1084      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1085      return
1086    fi
1087
1088    typeset NB_ESSAI DELAI status i
1089    # number of tentative
1090    NB_ESSAI=3
1091    # time delay between tentative
1092    DELAI=2
1093
1094    i=0
1095    while [ $i -lt $NB_ESSAI ] ; do
1096      \cp -urL $1 $2 > out_rsync 2>&1
1097      status=$?
1098      if [ ${status} -gt 0 ]; then
1099        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
1100        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
1101        sleep $DELAI
1102      else
1103        break
1104      fi
1105      (( i = i + 1 ))
1106    done
1107
1108    if [ ${status} -gt 0 ] ; then
1109      echo "IGCM_sys_Get_Master : error."
1110      cat out_rsync
1111      IGCM_debug_Exit "IGCM_sys_Get_Master"
1112    else
1113      \rm out_rsync
1114    fi
1115  fi
1116  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1117}
1118
1119#====================================================
1120#- Call IGCM_sys_Mirror_libIGCM now !
1121if ( $MirrorlibIGCM ) ; then
1122  IGCM_sys_Mirror_libIGCM
1123fi
1124
1125#D-#==================================================
1126#D-function IGCM_sys_Put_Rest
1127#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1128#D-           File and target directory must exist.
1129#D-* Examples:
1130#D-
1131function IGCM_sys_Put_Rest {
1132  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1133  if ( $DEBUG_sys ) ; then
1134    echo "IGCM_sys_Put_Rest :" $@
1135  fi
1136  if [ $DRYRUN = 0 ]; then
1137    if [ ! -f ${1} ] ; then
1138      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1139      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1140    fi
1141
1142    typeset status
1143    #
1144    # USUAL WAY
1145    \cp $1 $2 > out_rsync 2>&1
1146    status=$?
1147
1148#       #RSYNC WITH NETWORK SSH CALL
1149#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1150#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1151
1152#       #RSYNC WITH NFS USE
1153#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1154#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1155
1156#       status=$?
1157#       IGCM_sys_Rsync_out $status
1158
1159#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1160#       (( status=status+$? ))
1161
1162    if [ ${status} -gt 0 ] ; then
1163      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
1164      [ -f ${1} ] && ls -l ${1}
1165      [ -f ${2} ] && ls -l ${2}
1166      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1167      cat out_rsync
1168      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1169    else
1170
1171      if [ X${JobType} = XRUN ] ; then
1172        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1173        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1174      fi
1175
1176      \rm out_rsync
1177    fi
1178  fi
1179  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1180}
1181
1182#D-#==================================================
1183#D-function IGCM_sys_PutBuffer_Rest
1184#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1185#D-           File and target directory must exist.
1186#D-* Examples:
1187#D-
1188function IGCM_sys_PutBuffer_Rest {
1189  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1190  if ( $DEBUG_sys ) ; then
1191    echo "IGCM_sys_PutBuffer_Rest :" $@
1192  fi
1193  if [ $DRYRUN = 0 ]; then
1194    if [ ! -f ${1} ] ; then
1195      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1196      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1197    fi
1198
1199    typeset status
1200    #
1201    # USUAL WAY
1202    \cp $1 $2 > out_rsync 2>&1
1203    status=$?
1204
1205    if [ ${status} -gt 0 ] ; then
1206      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1207      [ -f ${2} ] && ls -l ${2}
1208      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1209      cat out_rsync
1210      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1211    else
1212
1213      if [ X${JobType} = XRUN ] ; then
1214        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1215        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1216      fi
1217
1218      \rm out_rsync
1219    fi
1220  fi
1221  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1222}
1223
1224#D-#==================================================
1225#D-function IGCM_sys_PrepareTaredRestart
1226#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1227#D-* Examples:
1228#D-
1229function IGCM_sys_PrepareTaredRestart {
1230  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1231  if [ $DRYRUN = 0 ]; then
1232    [ ! -f $( basename $1 ) ] && DEBUG_sys=false IGCM_sys_Get $1 .
1233  fi
1234  echo $( basename $1 )
1235  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1236}
1237
1238#D-#==================================================
1239#D-function IGCM_sys_Put_Out
1240#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1241#D-* Examples:
1242#D-
1243function IGCM_sys_Put_Out {
1244  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1245  if ( $DEBUG_sys ) ; then
1246    echo "IGCM_sys_Put_Out :" $@
1247  fi
1248
1249  typeset NB_ESSAI DELAI status i exist skip
1250
1251  # number of tentative
1252  NB_ESSAI=3
1253  # time delay between tentative
1254  DELAI=2
1255
1256  if [ $DRYRUN = 0 ]; then
1257    if [ ! -f ${1} ] ; then
1258      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1259      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1260      return 1
1261    fi
1262    #
1263    IGCM_sys_MkdirArchive $( dirname $2 )
1264    #
1265
1266    #=====================================================
1267    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1268    #=====================================================
1269
1270    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1271    #if [ $? -eq 0 ] ; then
1272    #    typeset WORKPATH FILEPATH
1273    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1274    #    IGCM_sys_MkdirWork ${WORKPATH}
1275    #    FILEPATH=${WORKPATH}/$( basename $2 )
1276    #    #
1277    #    IGCM_sys_Cp ${1} ${FILEPATH}
1278    #fi
1279
1280    exist=false
1281    skip=false
1282    if [ -f $2 ] ; then
1283      IGCM_debug_Print 1 "$2 already exist"
1284      #dmget $2
1285      ccc_hsm get $2
1286      exist=true
1287      if [ "X$( diff $1 $2 )" = X ] ; then
1288        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1289        skip=true
1290      else
1291        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1292        skip=false
1293      fi
1294    fi
1295    #
1296    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1297      IGCM_sys_Chmod u+w $2
1298    fi
1299
1300    if [ X${skip} = Xfalse ] ; then
1301      i=0
1302      while [ $i -lt $NB_ESSAI ] ; do
1303        # USUAL WAY
1304        \cp $1 $2 > out_rsync 2>&1
1305        status=$?
1306        if [ ${status} -gt 0 ]; then
1307          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1308          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1309          [ -f ${1} ] && ls -l ${1}
1310          [ -f ${2} ] && ls -l ${2}
1311          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1312          sleep $DELAI
1313        else
1314          break
1315        fi
1316        (( i = i + 1 ))
1317      done
1318    fi
1319
1320#       #RSYNC WITH NETWORK SSH CALL
1321#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1322#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1323
1324#       #RSYNC WITH NFS USE
1325#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1326#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1327
1328#       status=$?
1329#       IGCM_sys_Rsync_out $status
1330
1331#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1332#       (( status=status+$? ))
1333
1334    if [ ${status} -gt 0 ] ; then
1335      echo "IGCM_sys_Put_Out : error."
1336      [ -f ${1} ] && ls -l ${1}
1337      [ -f ${2} ] && ls -l ${2}
1338      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1339      cat out_rsync
1340      IGCM_debug_Exit "IGCM_sys_Put_Out"
1341    else
1342
1343      if [ X${JobType} = XRUN ] ; then
1344        if [ X${3} = X ] ; then
1345          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1346          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1347        fi
1348      fi
1349
1350      \rm out_rsync
1351    fi
1352  fi
1353  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1354  return 0
1355}
1356
1357#D-#==================================================
1358#D-function IGCM_sys_PutBuffer_Out
1359#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1360#D-* Examples:
1361#D-
1362function IGCM_sys_PutBuffer_Out {
1363  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1364  if ( $DEBUG_sys ) ; then
1365    echo "IGCM_sys_PutBuffer_Out :" $@
1366  fi
1367
1368  typeset NB_ESSAI DELAI status i exist skip
1369
1370  # number of tentative
1371  NB_ESSAI=3
1372  # time delay between tentative
1373  DELAI=2
1374
1375  if [ $DRYRUN = 0 ]; then
1376    if [ ! -f ${1} ] ; then
1377      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1378      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1379      return 1
1380    fi
1381    #
1382    IGCM_sys_Mkdir $( dirname $2 )
1383    #
1384
1385    exist=false
1386    skip=false
1387    if [ -f $2 ] ; then
1388      IGCM_debug_Print 1 "$2 already exist"
1389      exist=true
1390      if [ "X$( diff $1 $2 )" = X ] ; then
1391        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1392        status=0
1393        skip=true
1394      else
1395        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1396        skip=false
1397      fi
1398    fi
1399    #
1400    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1401      IGCM_sys_Chmod u+w $2
1402    fi
1403
1404    if [ X${skip} = Xfalse ] ; then
1405      i=0
1406      while [ $i -lt $NB_ESSAI ] ; do
1407        # USUAL WAY
1408        \cp $1 $2 > out_rsync 2>&1
1409        status=$?
1410        if [ ${status} -gt 0 ]; then
1411          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1412          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1413          [ -f ${2} ] && ls -l ${2}
1414          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1415          sleep $DELAI
1416        else
1417          break
1418        fi
1419        (( i = i + 1 ))
1420      done
1421    fi
1422
1423    if [ ${status} -gt 0 ] ; then
1424      echo "IGCM_sys_PutBuffer_Out : error."
1425      [ -f ${2} ] && ls -l ${2}
1426      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1427      cat out_rsync
1428      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1429    else
1430
1431      if [ X${JobType} = XRUN ] ; then
1432        if [ X${3} = X ] ; then
1433          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1434          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1435        fi
1436      fi
1437
1438      \rm out_rsync
1439    fi
1440  fi
1441  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1442  return 0
1443}
1444
1445#D-#==================================================
1446#D-function IGCM_sys_Get
1447#D-* Purpose: Get a file from ${ARCHIVE}
1448#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1449#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1450function IGCM_sys_Get {
1451  IGCM_debug_PushStack "IGCM_sys_Get" $@
1452
1453  typeset DEST dm_liste target file_work
1454  typeset NB_ESSAI DELAI status i
1455
1456  if ( $DEBUG_sys ) ; then
1457    echo "IGCM_sys_Get :" $@
1458  fi
1459
1460  # number of tentative
1461  NB_ESSAI=3
1462  # time delay between tentative
1463  DELAI=2
1464
1465  if [ $DRYRUN -le 2 ]; then
1466    if [ X${1} = X'/l' ] ; then
1467      eval set +A dm_liste \${${2}}
1468    else
1469      eval set +A dm_liste ${1}
1470    fi
1471    eval DEST=\${${#}}
1472
1473    #=====================================================
1474    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1475    #=====================================================
1476
1477    # Is it an R_OUT file (not R_IN) ?
1478    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1479    #if [ $? -eq 0 ] ; then
1480    #  # Yes  ? then we try to get it in SCRATCHDIR
1481    #  set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1482    #  if [ -f ${file_work[0]} ] ; then
1483    #    IGCM_sys_Cp ${file_work[*]} ${DEST}
1484    #    IGCM_debug_PopStack "IGCM_sys_Get"
1485    #    return
1486    #  fi
1487    #fi
1488
1489    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1490    status=$?
1491    if [ ${status} -gt 0 ] ; then
1492      echo "WARNING IGCM_sys_Get : error code ${status}"
1493      cat out_rsync
1494      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1495    fi
1496
1497    #if [ ${status} -gt 0 ] ; then
1498    #  if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1499    #    cat out_rsync
1500    #    echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1501    #    sleep 30
1502    #    echo "We try another time"
1503    ##    dmget ${dm_liste[*]} > out_rsync 2>&1
1504    #    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1505    #    status=$?
1506    #    if [ ${status} -gt 0 ] ; then
1507    #      echo "ERROR IGCM_sys_Get : again demigration error :"
1508    #      cat out_rsync
1509    #      IGCM_debug_Exit "IGCM_sys_Get"
1510    #    fi
1511    #  else
1512    #    echo "ERROR IGCM_sys_Get : demigration error :"
1513    #    cat out_rsync
1514    #    IGCM_debug_Exit "IGCM_sys_Get"
1515    #  fi
1516    #fi
1517
1518    #   #RSYNC WITH NETWORK SSH CALL
1519    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1520    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1521
1522    #   #RSYNC WITH NFS USE
1523    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1524    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1525
1526    #   status=$?
1527    #   IGCM_sys_Rsync_out $status
1528
1529    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1530    #   (( status=status+$? ))
1531
1532    #USUAL WAY
1533    if [ X${1} = X'/l' ] ; then
1534      for target in ${dm_liste[*]} ; do
1535        local_file=$( basename ${target} )
1536        # test if the target file is present before the loop
1537        IGCM_sys_TestFileArchive ${target}
1538        status=$?
1539        if [ ${status} -gt 0 ] ; then
1540          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1541          IGCM_debug_Exit "IGCM_sys_Get"
1542        else
1543          i=0
1544          while [ $i -lt $NB_ESSAI ] ; do
1545            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1546            status=$?
1547            if [ ${status} -gt 0 ]; then
1548              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1549              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1550              sleep $DELAI
1551            else
1552              break
1553            fi
1554            (( i = i + 1 ))
1555          done
1556          if [ ${status} -gt 0 ] ; then
1557            echo "IGCM_sys_Get : error"
1558            cat out_rsync
1559            \rm out_rsync
1560            IGCM_debug_Exit "IGCM_sys_Get"
1561          else
1562            \rm out_rsync
1563          fi
1564        fi
1565      done
1566    else
1567      i=0
1568      while [ $i -lt $NB_ESSAI ] ; do
1569        \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1570        status=$?
1571        if [ ${status} -gt 0 ]; then
1572          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1573          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1574          sleep $DELAI
1575        else
1576          break
1577        fi
1578        (( i = i + 1 ))
1579      done
1580      if [ ${status} -gt 0 ] ; then
1581        echo "IGCM_sys_Get : error"
1582        cat out_rsync
1583        \rm out_rsync
1584        IGCM_debug_Exit "IGCM_sys_Get"
1585      else
1586        \rm out_rsync
1587      fi
1588    fi
1589  fi
1590  IGCM_debug_PopStack "IGCM_sys_Get"
1591}
1592
1593#D-#==================================================
1594#D-function IGCM_sys_GetBuffer
1595#D-* Purpose: Get a file from ${SCRATCHDIR}
1596#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1597#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1598function IGCM_sys_GetBuffer {
1599  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1600
1601  typeset DEST buf_liste target file_work
1602  typeset NB_ESSAI DELAI status i
1603
1604  if ( $DEBUG_sys ) ; then
1605    echo "IGCM_sys_GetBuffer :" $@
1606  fi
1607
1608  # number of tentative
1609  NB_ESSAI=3
1610  # time delay between tentative
1611  DELAI=2
1612
1613  if [ $DRYRUN -le 2 ]; then
1614    if [ X${1} = X'/l' ] ; then
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" | gawk ' {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' | gawk '{print $2}')
2182  volume_avail=$(ccc_quota | grep ' scratch' | gawk '{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' | gawk '{print $6}')
2245  inode_avail=$(ccc_quota | grep ' scratch' | gawk '{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.