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

Last change on this file since 992 was 992, checked in by mafoipsl, 10 years ago

For curie, add AddNoise PATH to AddNoise compiled with predefined netcdf library PATH : -Wl,-rpath=/usr/local/netcdf-4.2/lib

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