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

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

Some data movement optimization. See #202

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