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

Last change on this file since 1046 was 1046, checked in by sdipsl, 10 years ago

Fix rebuild_station in the case empty files has been produced. see #212

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