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

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

RunChecker? : add JobID to output (#169).

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