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

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