source: tags/libIGCM_v2.3/libIGCM_sys/libIGCM_sys_curie.ksh

Last change on this file was 1010, checked in by aclsce, 10 years ago

Use of "typeset -x" instead of "typeset" in order to keep the SUBMIT_DIR value in the calling Job.
(pb occured with new ksh version on Curie)

  • Property svn:keywords set to Revision Author Date
File size: 90.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 > /dev/null 2>&1
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 > /dev/null 2>&1
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 -x 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# MPMD mode
2086
2087  if ( ${OK_PARA_MPMD} ) ; then
2088
2089# Only MPI (MPMD)
2090      if  ( ! ${OK_PARA_OMP} ) ; then
2091
2092          if [ -f run_file ] ; then
2093              IGCM_sys_Rm -f run_file
2094          fi
2095          touch run_file
2096
2097# Build run_file
2098
2099# First loop on the components for the coupler ie oasis (only if oasis3)
2100
2101## the coupler ie oasis3 must be the first one
2102          for comp in ${config_ListOfComponents[*]} ; do
2103
2104              eval ExeNameIn=\${config_Executable_${comp}[0]}
2105              eval ExeNameOut=\${config_Executable_${comp}[1]}
2106
2107      # for CPL component only
2108              if [ "X${comp}" = "XCPL" ] && [ "X${ExeNameOut}" != X\"\" ] ; then
2109
2110                  eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2111                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2112                  echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2113              fi
2114          done
2115
2116# Then second loop on the components
2117
2118          for comp in ${config_ListOfComponents[*]} ; do
2119
2120              eval ExeNameIn=\${config_Executable_${comp}[0]}
2121              eval ExeNameOut=\${config_Executable_${comp}[1]}
2122
2123      # Only if we really have an executable for the component and not the coupler ie oasis:
2124              if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
2125
2126                  eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2127                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2128                  echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2129              fi
2130          done
2131
2132          EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
2133
2134          IGCM_sys_Chmod u+x run_file
2135          if ( $DEBUG_sys ) ; then
2136              echo "run_file contains : "
2137              cat run_file
2138          fi
2139
2140# MPI-OpenMP (MPMD)   
2141      else
2142
2143# Use of mpirun instead of ccc_mprun
2144          EXECUTION="time mpirun"
2145
2146#  Hosts treatment
2147          ${EXECUTION} hostname | sort | uniq > hosts.tmp
2148         
2149          i=0
2150          rm -f hosts rankfile
2151          IGCM_debug_Print 1 "sys Curie, Hosts available :"
2152          for nodes in `cat hosts.tmp`
2153          do
2154              host[$i]=$nodes
2155              echo "${host[$i]}" >> hosts
2156              IGCM_debug_Print 1 ${host[$i]}
2157              i=$((i+1))
2158          done
2159          rm -f hosts.tmp
2160
2161          listnodes=${host[*]}
2162         
2163          EXECUTION="${EXECUTION} -hostfile hosts -rankfile rankfile" 
2164
2165# Initialisation
2166          rank=0
2167          current_core=0
2168          core_per_node=16
2169          init_exec=n
2170
2171# Loop on the components
2172          for comp in ${config_ListOfComponents[*]} ; do
2173             
2174              eval ExeNameIn=\${config_Executable_${comp}[0]}
2175              eval ExeNameOut=\${config_Executable_${comp}[1]}
2176
2177# Not possible if oasis has an executable (i.e old version of oasis3)   
2178              if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" = "XCPL" ] ) ; then
2179                  IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version"
2180                  IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler"
2181                  IGCM_debug_Verif_Exit
2182              fi
2183
2184# Only if we really have an executable for the component :
2185              if [ "X${ExeNameOut}" != X\"\" ] ; then
2186                 
2187                  eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2188                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2189
2190                  echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2191                  echo ""  >> script_${ExeNameOut}.ksh
2192                  if [ ${comp_proc_omp_loc} -gt 1 ] ; then
2193
2194# Check if the number of threads is correct
2195                      case ${comp_proc_omp_loc} in
2196                          2|4|8|16)
2197                              IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
2198                              ;;
2199                          *) 
2200                              IGCM_debug_Exit "ERROR with OMP parameters !"
2201                              IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
2202                              IGCM_debug_Print 2 "Only 2,4,8,16 as number of OMP threads are possible "
2203                              IGCM_debug_Verif_Exit
2204                              ;;
2205                      esac
2206                      echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2207                      echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2208                      echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2209                      echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
2210                  fi
2211#               echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
2212#               echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
2213                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2214                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2215                 
2216                  if [ ${init_exec} = y ] ; then
2217                      EXECUTION="${EXECUTION} : -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
2218                  else 
2219                      EXECUTION="${EXECUTION} -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
2220                      init_exec=y
2221                  fi
2222
2223# Build rankfile : method used to assign cores and nodes for the MPI process
2224# Ex :
2225#rank 0=curie5296 slot=0,1,2,3
2226#rank 1=curie5296 slot=4,5,6,7
2227# Example of final command :
2228# mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh
2229# with script_lmdz.x.ksh :
2230# #!/bin/ksh
2231#export KMP_STACKSIZE=3g
2232#export KMP_LIBRARY=turnaround
2233#export MKL_SERIAL=YES
2234#OMP_NUM_THREADS=4
2235#./lmdz.x
2236#
2237
2238                  for nb_proc_mpi in `seq 0 $(($comp_proc_mpi_loc-1))`; do
2239                      (( index_host = current_core / core_per_node ))
2240                      host_value=${host[${index_host}]}
2241                      (( slot =  current_core % core_per_node ))
2242                      virg=","
2243                      string_final=""
2244                      for index in `seq $slot $(($slot+$comp_proc_omp_loc-1))`; do
2245                          string=$index$virg
2246                          string_final=$string_final$string
2247                      done
2248                      string_final=$( echo $string_final | sed "s/.$//" )
2249                      echo "rank $rank=$host_value slot=$string_final" >> rankfile
2250                      (( rank = rank + 1 ))
2251                      (( current_core = current_core + comp_proc_omp_loc ))
2252                  done
2253              fi
2254
2255          done
2256      fi
2257
2258# Only one executable (SPMD mode).
2259  else
2260
2261    for comp in ${config_ListOfComponents[*]} ; do
2262
2263      # Only if we really have an executable for the component :
2264      eval ExeNameOut=\${config_Executable_${comp}[1]}
2265      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2266
2267        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2268        echo ""  >> script_${ExeNameOut}.ksh
2269        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2270
2271        if ( ${OK_PARA_OMP} ) ; then
2272          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2273          echo ""  >> script_${ExeNameOut}.ksh
2274          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2275          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2276          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2277          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
2278        fi
2279
2280        if  ( ${OK_PARA_MPI} ) ; then
2281          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2282          # Default : ccc_mprun used if nb_proc gt 1
2283          # to have out/err per process on different files
2284          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
2285          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2286          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
2287        else
2288          # Default : ccc_mprun is NOT used if nb_proc eq 1
2289          # to have out/err per process on different files
2290          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
2291          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2292          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
2293        fi
2294
2295        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
2296        cat script_${ExeNameOut}.ksh
2297
2298      fi
2299
2300    done
2301
2302  fi
2303
2304  IGCM_debug_Print 1 "sys Curie : execution command is "
2305  IGCM_debug_Print 1 "$EXECUTION"
2306
2307  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2308}
2309
2310#D-#==================================================
2311#D-function IGCM_sys_check_path
2312#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
2313#D-* do not point to an important use directory. Stop immediately in that case.
2314#D-* Examples:
2315#D-
2316function IGCM_sys_check_path {
2317  IGCM_debug_PushStack "IGCM_sys_check_path"
2318  if ( $DEBUG_sys ) ; then
2319    echo "IGCM_sys_check_path"
2320  fi
2321
2322  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
2323    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
2324    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
2325    IGCM_debug_Exit "This will stop the job"
2326  fi
2327  IGCM_debug_PopStack "IGCM_sys_check_path"
2328}
2329
2330#D-#==================================================
2331#D-function IGCM_sys_check_quota
2332#D-* Purpose: check user quota. Stop the simulation if quota above 90%
2333#D-* Examples:
2334#D-
2335function IGCM_sys_check_quota {
2336  IGCM_debug_PushStack "IGCM_sys_check_quota"
2337  if ( $DEBUG_sys ) ; then
2338    echo "IGCM_sys_check_quota"
2339  fi
2340  # Limit of quota (in %)
2341  limit_quota=90
2342
2343  # Check of the volume
2344  volume_quota=$(ccc_quota | grep ' scratch' | gawk '{print $2}')
2345  volume_avail=$(ccc_quota | grep ' scratch' | gawk '{print $3}')
2346
2347  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
2348
2349    unit_avail=${volume_avail: -1}
2350    unit_quota=${volume_quota: -1}
2351
2352    if [ "${unit_quota}" = "*" ] ; then
2353      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2354      IGCM_debug_Print 1 "More than 100% of your quota is used"
2355      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2356      IGCM_debug_Print 1 "You must have more than 10% available to run"
2357      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2358      IGCM_debug_Verif_Exit
2359    fi
2360
2361    temp_avail=${volume_avail%%${volume_avail: -1}*}
2362    temp_quota=${volume_quota%%${volume_quota: -1}*}
2363
2364    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2365
2366    # Convertion
2367      if [ ${volume_avail: -1} = "T" ] ; then
2368        (( temp_avail = temp_avail * 1000000000000 ))
2369      elif [ ${volume_avail: -1} = "G" ] ; then
2370        (( temp_avail = temp_avail * 1000000000 ))
2371      elif [ ${volume_avail: -1} = "M" ] ; then
2372        (( temp_avail = temp_avail * 1000000 ))
2373      elif [ ${volume_avail: -1} = "k" ] ; then
2374        (( temp_avail = temp_avail * 1000 ))
2375      else
2376        (( temp_avail = volume_avail ))
2377      fi
2378      if [ ${volume_quota: -1} = "T" ] ; then
2379        (( temp_quota = temp_quota * 1000000000000 ))
2380      elif [ ${volume_quota: -1} = "G" ] ; then
2381        (( temp_quota = temp_quota * 1000000000 ))
2382      elif [ ${volume_quota: -1} = "M" ] ; then
2383        (( temp_quota = temp_quota * 1000000 ))
2384      elif [ ${volume_quota: -1} = "k" ] ; then
2385        (( temp_quota = temp_quota * 1000 ))
2386      else
2387        (( temp_quota = volume_quota ))
2388      fi
2389    fi
2390
2391    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2392#    echo "volume ratio is " $quota_volume
2393
2394    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2395      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2396      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2397      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2398      IGCM_debug_Print 1 "You must have more than 10% available to run"
2399      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2400      IGCM_debug_Verif_Exit
2401    fi
2402
2403  fi
2404
2405# Check of the number of inodes
2406
2407  inode_quota=$(ccc_quota | grep ' scratch' | gawk '{print $6}')
2408  inode_avail=$(ccc_quota | grep ' scratch' | gawk '{print $7}')
2409
2410  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
2411
2412    unit_avail=${inode_avail: -1}
2413    unit_quota=${inode_quota: -1}
2414
2415    if [ "${unit_quota}" = "*" ] ; then
2416      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2417      IGCM_debug_Print 1 "More than 100% of your quota is used"
2418      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2419      IGCM_debug_Print 1 "You must have more than 10% available to run"
2420      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2421      IGCM_debug_Verif_Exit
2422    fi
2423
2424    temp_avail=${inode_avail%%${inode_avail: -1}*}
2425    temp_quota=${inode_quota%%${inode_quota: -1}*}
2426
2427    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2428
2429    # Convertion
2430      if [ ${inode_avail: -1} = "T" ] ; then
2431        (( temp_avail = temp_avail * 1000000000000 ))
2432      elif [ ${inode_avail: -1} = "G" ] ; then
2433        (( temp_avail = temp_avail * 1000000000 ))
2434      elif [ ${inode_avail: -1} = "M" ] ; then
2435        (( temp_avail = temp_avail * 1000000 ))
2436      elif [ ${inode_avail: -1} = "k" ] ; then
2437        (( temp_avail = temp_avail * 1000 ))
2438      else
2439        (( temp_avail = inode_avail ))
2440      fi
2441
2442      if [ ${inode_quota: -1} = "T" ] ; then
2443        (( temp_quota = temp_quota * 1000000000000 ))
2444      elif [ ${inode_quota: -1} = "G" ] ; then
2445        (( temp_quota = temp_quota * 1000000000 ))
2446      elif [ ${inode_quota: -1} = "M" ] ; then
2447        (( temp_quota = temp_quota * 1000000 ))
2448      elif [ ${inode_quota: -1} = "k" ] ; then
2449        (( temp_quota = temp_quota * 1000 ))
2450      else
2451        (( temp_quota = inode_quota ))
2452      fi
2453    fi
2454    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2455#    echo "inode ratio is " $quota_inode
2456
2457    if [ ${quota_inode} -ge ${limit_quota} ] ; then
2458      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2459      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
2460      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2461      IGCM_debug_Print 1 "You must have more than 10% available to run"
2462      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2463      IGCM_debug_Verif_Exit
2464    fi
2465  fi
2466  IGCM_debug_PopStack "IGCM_sys_check_quota"
2467}
2468
2469#D-#==================================================
2470#D-function IGCM_sys_GetJobID
2471#D-* Purpose: Check if job_name is currently
2472#D-  running or in queue
2473#D-* Examples: IGCM_sys_GetJobID ${JobName} ${TargetUsr} JobID
2474#D-
2475function IGCM_sys_GetJobID {
2476  IGCM_debug_PushStack "IGCM_sys_GetJobID"
2477  if ( $DEBUG_sys ) ; then
2478    echo "IGCM_sys_GetJobID"
2479  fi
2480
2481  # With -f option, the full job name is given in the last column
2482  ID=$( ccc_mstat -f -u $2 | \
2483        gawk -v JobName=$1 '( $NF ~ JobName ) { print $1 }' )
2484
2485  eval ${3}=${ID}
2486
2487  IGCM_debug_PopStack "IGCM_sys_GetJobID"
2488}
2489
2490#D-#==================================================
2491#D-function IGCM_sys_CountJobInQueue
2492#D-* Purpose: Check if job_name is currently
2493#D-  running or in queue
2494#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
2495#D-
2496function IGCM_sys_CountJobInQueue {
2497  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
2498  if ( $DEBUG_sys ) ; then
2499    echo "IGCM_sys_CountJobInQueue"
2500  fi
2501
2502  #NbRun=$( ccc_mstat -f | grep -c ${JobName} )
2503
2504  # With -f option, the full job name is given in the last column
2505  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ( $NF ~ JobName ) { x=x+1 } END { print x }' )
2506
2507  eval ${2}=${NbRun}
2508
2509  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
2510}
2511
2512#D-#==================================================
2513#D-function IGCM_sys_ListJobInQueue
2514#D-* Purpose: Check if job_name is currently
2515#D-  running or in queue
2516#D-* Examples: IGCM_sys_ListJobInQueue ${User} JobNameList
2517#D-
2518function IGCM_sys_ListJobInQueue {
2519  IGCM_debug_PushStack "IGCM_sys_ListJobInQueue"
2520  if ( $DEBUG_sys ) ; then
2521    echo "IGCM_sys_ListJobInQueue"
2522  fi
2523
2524  # With -f option, the full job name is given in the last column
2525  set -A JobList $( ccc_mstat -f | gawk -v User=$1             \
2526                                        '( $2  == User      && \
2527                                           $NF != /TS/      && \
2528                                           $NF !~ /PACK/    && \
2529                                           $NF !~ /REBUILD/ && \
2530                                           $NF !~ /pack/ )     \
2531                                         { print $NF }' | sed -e "s/\(.*\)\.[0-9]*/\1/" )
2532
2533  eval set -A ${2} ${JobList[*]}
2534
2535  IGCM_debug_PopStack "IGCM_sys_ListJobInQueue"
2536}
2537
2538##############################################################
2539# NCO OPERATOR
2540
2541#D-#==================================================
2542#D-function IGCM_sys_ncap2
2543#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2544#D-* Examples:
2545#D-
2546function IGCM_sys_ncap2 {
2547  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2548  if ( $DEBUG_sys ) ; then
2549    echo "IGCM_sys_ncap2 :" $@
2550  fi
2551
2552  typeset NB_ESSAI DELAI status i
2553  # number of tentative
2554  NB_ESSAI=3
2555  # time delay between tentative
2556  DELAI=2
2557
2558  i=0
2559  while [ $i -lt $NB_ESSAI ] ; do
2560    ncap2 "$@" > /tmp/out_command.$$ 2>&1
2561    status=$?
2562    if [ ${status} -gt 0 ] ; then
2563      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2564      cat /tmp/out_command.$$
2565      \rm /tmp/out_command.$$
2566      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2567      sleep $DELAI
2568    else
2569      \rm /tmp/out_command.$$
2570      break
2571    fi
2572    (( i = i + 1 ))
2573  done
2574
2575  if [ ${status} -gt 0 ] ; then
2576    echo "IGCM_sys_ncap2 : ncap2 error"
2577    IGCM_debug_Exit "ncap2"
2578  fi
2579
2580  IGCM_debug_PopStack "IGCM_sys_ncap2"
2581}
2582
2583#D-#==================================================
2584#D-function IGCM_sys_ncatted
2585#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2586#D-* Examples:
2587#D-
2588function IGCM_sys_ncatted {
2589  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2590  if ( $DEBUG_sys ) ; then
2591    echo "IGCM_sys_ncatted :" $@
2592  fi
2593
2594  typeset NB_ESSAI DELAI status i
2595  # number of tentative
2596  NB_ESSAI=3
2597  # time delay between tentative
2598  DELAI=2
2599
2600  i=0
2601  while [ $i -lt $NB_ESSAI ] ; do
2602    ncatted "$@" > /tmp/out_command.$$ 2>&1
2603    status=$?
2604    if [ ${status} -gt 0 ] ; then
2605      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2606      cat /tmp/out_command.$$
2607      \rm /tmp/out_command.$$
2608      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2609      sleep $DELAI
2610    else
2611      \rm /tmp/out_command.$$
2612      break
2613    fi
2614    (( i = i + 1 ))
2615  done
2616
2617  if [ ${status} -gt 0 ] ; then
2618    echo "IGCM_sys_ncatted : ncatted error"
2619    IGCM_debug_Exit "ncatted"
2620  fi
2621
2622  IGCM_debug_PopStack "IGCM_sys_ncatted"
2623}
2624
2625#D-#==================================================
2626#D-function IGCM_sys_ncbo
2627#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2628#D-* Examples:
2629#D-
2630function IGCM_sys_ncbo {
2631  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2632  if ( $DEBUG_sys ) ; then
2633    echo "IGCM_sys_ncbo :" $@
2634  fi
2635
2636  typeset NB_ESSAI DELAI status i
2637  # number of tentative
2638  NB_ESSAI=3
2639  # time delay between tentative
2640  DELAI=2
2641
2642  i=0
2643  while [ $i -lt $NB_ESSAI ] ; do
2644    ncbo $@ > /tmp/out_command.$$ 2>&1
2645    status=$?
2646    if [ ${status} -gt 0 ] ; then
2647      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2648      cat /tmp/out_command.$$
2649      \rm /tmp/out_command.$$
2650      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2651      sleep $DELAI
2652    else
2653      \rm /tmp/out_command.$$
2654      break
2655    fi
2656    (( i = i + 1 ))
2657  done
2658
2659  if [ ${status} -gt 0 ] ; then
2660    echo "IGCM_sys_ncbo : ncbo error"
2661    IGCM_debug_Exit "ncbo"
2662  fi
2663
2664  IGCM_debug_PopStack "IGCM_sys_ncbo"
2665}
2666
2667#D-#==================================================
2668#D-function IGCM_sys_ncdif
2669#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2670#D-* Examples:
2671#D-
2672function IGCM_sys_ncdiff {
2673  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2674  if ( $DEBUG_sys ) ; then
2675    echo "IGCM_sys_ncdiff :" $@
2676  fi
2677
2678  typeset NB_ESSAI DELAI status i
2679  # number of tentative
2680  NB_ESSAI=3
2681  # time delay between tentative
2682  DELAI=2
2683
2684  i=0
2685  while [ $i -lt $NB_ESSAI ] ; do
2686    ncdiff $@ > /tmp/out_command.$$ 2>&1
2687    status=$?
2688    if [ ${status} -gt 0 ] ; then
2689      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2690      cat /tmp/out_command.$$
2691      \rm /tmp/out_command.$$
2692      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2693      sleep $DELAI
2694    else
2695      \rm /tmp/out_command.$$
2696      break
2697    fi
2698    (( i = i + 1 ))
2699  done
2700
2701  if [ ${status} -gt 0 ] ; then
2702    echo "IGCM_sys_ncdiff : ncdiff error"
2703    IGCM_debug_Exit "ncdiff"
2704  fi
2705
2706  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2707}
2708
2709#D-#==================================================
2710#D-function IGCM_sys_ncea
2711#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2712#D-* Examples:
2713#D-
2714function IGCM_sys_ncea {
2715  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2716  if ( $DEBUG_sys ) ; then
2717    echo "IGCM_sys_ncea :" $@
2718  fi
2719
2720  typeset NB_ESSAI DELAI status i
2721  # number of tentative
2722  NB_ESSAI=3
2723  # time delay between tentative
2724  DELAI=2
2725
2726  i=0
2727  while [ $i -lt $NB_ESSAI ] ; do
2728    ncea $@ > /tmp/out_command.$$ 2>&1
2729    status=$?
2730    if [ ${status} -gt 0 ] ; then
2731      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2732      cat /tmp/out_command.$$
2733      \rm /tmp/out_command.$$
2734      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2735      sleep $DELAI
2736    else
2737      \rm /tmp/out_command.$$
2738      break
2739    fi
2740    (( i = i + 1 ))
2741  done
2742
2743  if [ ${status} -gt 0 ] ; then
2744    echo "IGCM_sys_ncea : ncea error"
2745    IGCM_debug_Exit "ncea"
2746  fi
2747
2748  IGCM_debug_PopStack "IGCM_sys_ncea"
2749}
2750
2751#D-#==================================================
2752#D-function IGCM_sys_ncecat
2753#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2754#D-* Examples:
2755#D-
2756function IGCM_sys_ncecat {
2757  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2758  if ( $DEBUG_sys ) ; then
2759    echo "IGCM_sys_ncecat :" $@
2760  fi
2761
2762  typeset NB_ESSAI DELAI status i
2763  # number of tentative
2764  NB_ESSAI=3
2765  # time delay between tentative
2766  DELAI=2
2767
2768  i=0
2769  while [ $i -lt $NB_ESSAI ] ; do
2770    ncecat $@ > /tmp/out_command.$$ 2>&1
2771    status=$?
2772    if [ ${status} -gt 0 ] ; then
2773      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2774      cat /tmp/out_command.$$
2775      \rm /tmp/out_command.$$
2776      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2777      sleep $DELAI
2778    else
2779      \rm /tmp/out_command.$$
2780      break
2781    fi
2782    (( i = i + 1 ))
2783  done
2784
2785  if [ ${status} -gt 0 ] ; then
2786    echo "IGCM_sys_ncecat : ncecat error"
2787    IGCM_debug_Exit "ncecat"
2788  fi
2789
2790  IGCM_debug_PopStack "IGCM_sys_ncecat"
2791}
2792
2793#D-#==================================================
2794#D-function IGCM_sys_ncflint
2795#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2796#D-* Examples:
2797#D-
2798function IGCM_sys_ncflint {
2799  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2800  if ( $DEBUG_sys ) ; then
2801    echo "IGCM_sys_ncflint :" $@
2802  fi
2803
2804  typeset NB_ESSAI DELAI status i
2805  # number of tentative
2806  NB_ESSAI=3
2807  # time delay between tentative
2808  DELAI=2
2809
2810  i=0
2811  while [ $i -lt $NB_ESSAI ] ; do
2812    ncflint $@ > /tmp/out_command.$$ 2>&1
2813    status=$?
2814    if [ ${status} -gt 0 ] ; then
2815      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2816      cat /tmp/out_command.$$
2817      \rm /tmp/out_command.$$
2818      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2819      sleep $DELAI
2820    else
2821      \rm /tmp/out_command.$$
2822      break
2823    fi
2824    (( i = i + 1 ))
2825  done
2826
2827  if [ ${status} -gt 0 ] ; then
2828    echo "IGCM_sys_ncflint : ncflint error"
2829    IGCM_debug_Exit "ncflint"
2830  fi
2831
2832  IGCM_debug_PopStack "IGCM_sys_ncflint"
2833}
2834
2835#D-#==================================================
2836#D-function IGCM_sys_ncks
2837#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2838#D-* Examples:
2839#D-
2840function IGCM_sys_ncks {
2841  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2842  if ( $DEBUG_sys ) ; then
2843    echo "IGCM_sys_ncks :" $@
2844  fi
2845
2846  typeset NB_ESSAI DELAI status i
2847  # number of tentative
2848  NB_ESSAI=3
2849  # time delay between tentative
2850  DELAI=2
2851
2852  i=0
2853  while [ $i -lt $NB_ESSAI ] ; do
2854    ncks $@ > /tmp/out_command.$$ 2>&1
2855    status=$?
2856    if [ ${status} -gt 0 ] ; then
2857      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2858      cat /tmp/out_command.$$
2859      \rm /tmp/out_command.$$
2860      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2861      sleep $DELAI
2862    else
2863      \rm /tmp/out_command.$$
2864      break
2865    fi
2866    (( i = i + 1 ))
2867  done
2868
2869  if [ ${status} -gt 0 ] ; then
2870    echo "IGCM_sys_ncks : ncks error"
2871    IGCM_debug_Exit "ncks"
2872  fi
2873
2874  IGCM_debug_PopStack "IGCM_sys_ncks"
2875}
2876
2877#D-#==================================================
2878#D-function IGCM_sys_ncpdq
2879#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2880#D-* Examples:
2881#D-
2882function IGCM_sys_ncpdq {
2883  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2884  if ( $DEBUG_sys ) ; then
2885    echo "IGCM_sys_ncpdq :" $@
2886  fi
2887
2888  typeset NB_ESSAI DELAI status i
2889  # number of tentative
2890  NB_ESSAI=3
2891  # time delay between tentative
2892  DELAI=2
2893
2894  i=0
2895  while [ $i -lt $NB_ESSAI ] ; do
2896    ncpdq $@ > /tmp/out_command.$$ 2>&1
2897    status=$?
2898    if [ ${status} -gt 0 ] ; then
2899      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2900      cat /tmp/out_command.$$
2901      \rm /tmp/out_command.$$
2902      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2903      sleep $DELAI
2904    else
2905      \rm /tmp/out_command.$$
2906      break
2907    fi
2908    (( i = i + 1 ))
2909  done
2910
2911  if [ ${status} -gt 0 ] ; then
2912    echo "IGCM_sys_ncpdq : ncpdq error"
2913    IGCM_debug_Exit "ncpdq"
2914  fi
2915
2916  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2917}
2918
2919#D-#==================================================
2920#D-function IGCM_sys_ncra
2921#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2922#D-* Examples:
2923#D-
2924function IGCM_sys_ncra {
2925  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2926  if ( $DEBUG_sys ) ; then
2927    echo "IGCM_sys_ncra :" $@
2928  fi
2929
2930  typeset NB_ESSAI DELAI status i
2931  # number of tentative
2932  NB_ESSAI=3
2933  # time delay between tentative
2934  DELAI=2
2935
2936  i=0
2937  while [ $i -lt $NB_ESSAI ] ; do
2938    ncra $@ > /tmp/out_command.$$ 2>&1
2939    status=$?
2940    if [ ${status} -gt 0 ] ; then
2941      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2942      cat /tmp/out_command.$$
2943      \rm /tmp/out_command.$$
2944      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2945      sleep $DELAI
2946    else
2947      \rm /tmp/out_command.$$
2948      break
2949    fi
2950    (( i = i + 1 ))
2951  done
2952
2953  if [ ${status} -gt 0 ] ; then
2954    echo "IGCM_sys_ncra : ncra error"
2955    IGCM_debug_Exit "ncra"
2956  fi
2957
2958  IGCM_debug_PopStack "IGCM_sys_ncra"
2959}
2960
2961#D-#==================================================
2962#D-function IGCM_sys_ncrcat
2963#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2964#D-* Examples:
2965#D-
2966function IGCM_sys_ncrcat {
2967  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2968  if ( $DEBUG_sys ) ; then
2969    echo "IGCM_sys_ncrcat :" $@
2970  fi
2971
2972  typeset NB_ESSAI DELAI status i lastArg
2973  # number of tentative
2974  NB_ESSAI=3
2975  # time delay between tentative
2976  DELAI=2
2977
2978  i=0
2979  while [ $i -lt $NB_ESSAI ] ; do
2980    ncrcat $@ > /tmp/out_command.$$ 2>&1
2981    status=$?
2982    if [ ${status} -gt 0 ] ; then
2983      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2984      cat /tmp/out_command.$$
2985      \rm /tmp/out_command.$$
2986      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2987      sleep $DELAI
2988    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command.$$ )" = "X" ] ; then
2989      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2990      cat /tmp/out_command.$$
2991      # remove files having corrupted time axis
2992      eval lastArg=\${$#}
2993      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2994      \rm ${lastArg}
2995      \rm /tmp/out_command.$$
2996      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2997      sleep $DELAI
2998    else
2999      \rm /tmp/out_command.$$
3000      break
3001    fi
3002    (( i = i + 1 ))
3003  done
3004
3005  if [ ${status} -gt 0 ] ; then
3006    echo "IGCM_sys_ncrcat : ncrcat error"
3007    #IGCM_debug_Exit "ncrcat"
3008  fi
3009
3010  IGCM_debug_PopStack "IGCM_sys_ncrcat"
3011}
3012
3013#D-#==================================================
3014#D-function IGCM_sys_ncrename
3015#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
3016#D-* Examples:
3017#D-
3018function IGCM_sys_ncrename {
3019  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
3020  if ( $DEBUG_sys ) ; then
3021    echo "IGCM_sys_ncrename :" $@
3022  fi
3023
3024  typeset NB_ESSAI DELAI status i
3025  # number of tentative
3026  NB_ESSAI=3
3027  # time delay between tentative
3028  DELAI=2
3029
3030  i=0
3031  while [ $i -lt $NB_ESSAI ] ; do
3032    ncrename $@ > /tmp/out_command.$$ 2>&1
3033    status=$?
3034    if [ ${status} -gt 0 ] ; then
3035      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
3036      cat /tmp/out_command.$$
3037      \rm /tmp/out_command.$$
3038      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
3039      sleep $DELAI
3040    else
3041      \rm /tmp/out_command.$$
3042      break
3043    fi
3044    (( i = i + 1 ))
3045  done
3046
3047  if [ ${status} -gt 0 ] ; then
3048    echo "IGCM_sys_ncrename : ncrename error"
3049    IGCM_debug_Exit "ncrename"
3050  fi
3051
3052  IGCM_debug_PopStack "IGCM_sys_ncrename"
3053}
3054
3055#D-#==================================================
3056#D-function IGCM_sys_ncwa
3057#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
3058#D-* Examples:
3059#D-
3060function IGCM_sys_ncwa {
3061  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
3062  if ( $DEBUG_sys ) ; then
3063    echo "IGCM_sys_ncwa :" $@
3064  fi
3065
3066  typeset NB_ESSAI DELAI status i
3067  # number of tentative
3068  NB_ESSAI=3
3069  # time delay between tentative
3070  DELAI=2
3071
3072  i=0
3073  while [ $i -lt $NB_ESSAI ] ; do
3074    ncwa $@ > /tmp/out_command.$$ 2>&1
3075    status=$?
3076    if [ ${status} -gt 0 ] ; then
3077      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
3078      cat /tmp/out_command.$$
3079      \rm /tmp/out_command.$$
3080      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
3081      sleep $DELAI
3082    else
3083      \rm /tmp/out_command.$$
3084      break
3085    fi
3086    (( i = i + 1 ))
3087  done
3088
3089  if [ ${status} -gt 0 ] ; then
3090    echo "IGCM_sys_ncwa : ncwa error"
3091    IGCM_debug_Exit "ncwa"
3092  fi
3093
3094  IGCM_debug_PopStack "IGCM_sys_ncwa"
3095}
3096
3097##############################################################
3098# CDO OPERATOR
3099
3100#D-#==================================================
3101#D-function IGCM_sys_cdo
3102#D-* Purpose: encapsulate cdo call so as to manage error code and retry
3103#D-* Examples:
3104#D-
3105function IGCM_sys_cdo {
3106  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
3107  if ( $DEBUG_sys ) ; then
3108    echo "IGCM_sys_cdo :" $@
3109  fi
3110
3111  typeset status
3112
3113  \cdo $@ > /tmp/out_command.$$ 2>&1
3114  status=$?
3115  if [ ${status} -gt 0 ] ; then
3116    echo "IGCM_sys_cdo : error code ${status}"
3117    cat /tmp/out_command.$$
3118    \rm /tmp/out_command.$$
3119    IGCM_debug_PopStack "IGCM_sys_cdo"
3120    return 1
3121  else
3122    IGCM_debug_PopStack "IGCM_sys_cdo"
3123    return 0
3124  fi
3125
3126  IGCM_debug_PopStack "IGCM_sys_cdo"
3127}
Note: See TracBrowser for help on using the repository browser.