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

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