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

Last change on this file since 802 was 802, checked in by sdipsl, 11 years ago

Curie as well need adaptation due to STORE issue.

  • Property svn:keywords set to Revision Author Date
File size: 78.8 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_PrepareTaredRestart
1233#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1234#D-* Examples:
1235#D-
1236function IGCM_sys_PrepareTaredRestart {
1237  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1238  if [ $DRYRUN = 0 ]; then
1239    [ ! -f $( basename $1 ) ] && DEBUG_sys=false IGCM_sys_Get $1 .
1240  else
1241    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1242  fi
1243  echo $( basename $1 )
1244  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1245}
1246
1247#D-#==================================================
1248#D-function IGCM_sys_Put_Out
1249#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1250#D-* Examples:
1251#D-
1252function IGCM_sys_Put_Out {
1253  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1254  if ( $DEBUG_sys ) ; then
1255    echo "IGCM_sys_Put_Out :" $@
1256  fi
1257
1258  typeset NB_ESSAI DELAI status i exist skip
1259
1260  # number of tentative
1261  NB_ESSAI=3
1262  # time delay between tentative
1263  DELAI=2
1264
1265  if [ $DRYRUN = 0 ]; then
1266    if [ ! -f ${1} ] ; then
1267      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1268      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1269      return 1
1270    fi
1271    #
1272    IGCM_sys_MkdirArchive $( dirname $2 )
1273    #
1274
1275    #=====================================================
1276    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1277    #=====================================================
1278
1279    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1280    #if [ $? -eq 0 ] ; then
1281    #    typeset WORKPATH FILEPATH
1282    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1283    #    IGCM_sys_MkdirWork ${WORKPATH}
1284    #    FILEPATH=${WORKPATH}/$( basename $2 )
1285    #    #
1286    #    IGCM_sys_Cp ${1} ${FILEPATH}
1287    #fi
1288
1289    exist=false
1290    skip=false
1291    if [ -f $2 ] ; then
1292      IGCM_debug_Print 1 "$2 already exist"
1293      #dmget $2
1294      ccc_hsm get $2
1295      exist=true
1296      if [ "X$( diff $1 $2 )" = X ] ; then
1297        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1298        skip=true
1299      else
1300        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1301        skip=false
1302      fi
1303    fi
1304    #
1305    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1306      IGCM_sys_Chmod u+w $2
1307    fi
1308
1309    if [ X${skip} = Xfalse ] ; then
1310      i=0
1311      while [ $i -lt $NB_ESSAI ] ; do
1312        # USUAL WAY
1313        \cp $1 $2 > out_rsync 2>&1
1314        status=$?
1315        if [ ${status} -gt 0 ]; then
1316          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1317          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1318          [ -f ${1} ] && ls -l ${1}
1319          [ -f ${2} ] && ls -l ${2}
1320          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1321          sleep $DELAI
1322        else
1323          break
1324        fi
1325        (( i = i + 1 ))
1326      done
1327    fi
1328
1329#       #RSYNC WITH NETWORK SSH CALL
1330#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1331#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1332
1333#       #RSYNC WITH NFS USE
1334#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1335#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1336
1337#       status=$?
1338#       IGCM_sys_Rsync_out $status
1339
1340#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1341#       (( status=status+$? ))
1342
1343    if [ ${status} -gt 0 ] ; then
1344      echo "IGCM_sys_Put_Out : error."
1345      [ -f ${1} ] && ls -l ${1}
1346      [ -f ${2} ] && ls -l ${2}
1347      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1348      cat out_rsync
1349      IGCM_debug_Exit "IGCM_sys_Put_Out"
1350    else
1351
1352      if [ X${JobType} = XRUN ] ; then
1353        if [ X${3} = X ] ; then
1354          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1355          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1356        fi
1357      fi
1358
1359      \rm out_rsync
1360    fi
1361  else
1362    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1363  fi
1364  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1365  return 0
1366}
1367
1368#D-#==================================================
1369#D-function IGCM_sys_PutBuffer_Out
1370#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1371#D-* Examples:
1372#D-
1373function IGCM_sys_PutBuffer_Out {
1374  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1375  if ( $DEBUG_sys ) ; then
1376    echo "IGCM_sys_PutBuffer_Out :" $@
1377  fi
1378
1379  typeset NB_ESSAI DELAI status i exist skip
1380
1381  # number of tentative
1382  NB_ESSAI=3
1383  # time delay between tentative
1384  DELAI=2
1385
1386  if [ $DRYRUN = 0 ]; then
1387    if [ ! -f ${1} ] ; then
1388      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1389      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1390      return 1
1391    fi
1392    #
1393    IGCM_sys_Mkdir $( dirname $2 )
1394    #
1395
1396    exist=false
1397    skip=false
1398    if [ -f $2 ] ; then
1399      IGCM_debug_Print 1 "$2 already exist"
1400      exist=true
1401      if [ "X$( diff $1 $2 )" = X ] ; then
1402        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
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        # USUAL WAY
1418        \cp $1 $2 > out_rsync 2>&1
1419        status=$?
1420        if [ ${status} -gt 0 ]; then
1421          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1422          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1423          [ -f ${2} ] && ls -l ${2}
1424          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1425          sleep $DELAI
1426        else
1427          break
1428        fi
1429        (( i = i + 1 ))
1430      done
1431    fi
1432
1433    if [ ${status} -gt 0 ] ; then
1434      echo "IGCM_sys_PutBuffer_Out : error."
1435      [ -f ${2} ] && ls -l ${2}
1436      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1437      cat out_rsync
1438      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1439    else
1440
1441      if [ X${JobType} = XRUN ] ; then
1442        if [ X${3} = X ] ; then
1443          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1444          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1445        fi
1446      fi
1447
1448      \rm out_rsync
1449    fi
1450  else
1451    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1452  fi
1453  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1454  return 0
1455}
1456
1457#D-#==================================================
1458#D-function IGCM_sys_Get
1459#D-* Purpose: Get a file from ${ARCHIVE}
1460#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1461#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1462function IGCM_sys_Get {
1463  IGCM_debug_PushStack "IGCM_sys_Get" $@
1464
1465  typeset DEST dm_liste target file_work
1466  typeset NB_ESSAI DELAI status i
1467
1468  if ( $DEBUG_sys ) ; then
1469    echo "IGCM_sys_Get :" $@
1470  fi
1471
1472  # number of tentative
1473  NB_ESSAI=3
1474  # time delay between tentative
1475  DELAI=2
1476
1477  if [ $DRYRUN -le 2 ]; then
1478    if [ X${1} = X'/l' ] ; then
1479      # test if the first file is present in the old computation :
1480      eval set +A dm_liste \${${2}}
1481    else
1482      eval set +A dm_liste ${1}
1483    fi
1484    eval DEST=\${${#}}
1485
1486    #=====================================================
1487    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1488    #=====================================================
1489
1490    # Is it an R_OUT file (not R_IN) ?
1491    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1492    #if [ $? -eq 0 ] ; then
1493    #  # Yes  ? then we try to get it in SCRATCHDIR
1494    #  set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1495    #  if [ -f ${file_work[0]} ] ; then
1496    #    IGCM_sys_Cp ${file_work[*]} ${DEST}
1497    #    IGCM_debug_PopStack "IGCM_sys_Get"
1498    #    return
1499    #  fi
1500    #fi
1501
1502    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1503    status=$?
1504    if [ ${status} -gt 0 ] ; then
1505      echo "WARNING IGCM_sys_Get : error code ${status}"
1506      cat out_rsync
1507      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1508    fi
1509
1510    #if [ ${status} -gt 0 ] ; then
1511    #  if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1512    #    cat out_rsync
1513    #    echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1514    #    sleep 30
1515    #    echo "We try another time"
1516    ##    dmget ${dm_liste[*]} > out_rsync 2>&1
1517    #    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1518    #    status=$?
1519    #    if [ ${status} -gt 0 ] ; then
1520    #      echo "ERROR IGCM_sys_Get : again demigration error :"
1521    #      cat out_rsync
1522    #      IGCM_debug_Exit "IGCM_sys_Get"
1523    #    fi
1524    #  else
1525    #    echo "ERROR IGCM_sys_Get : demigration error :"
1526    #    cat out_rsync
1527    #    IGCM_debug_Exit "IGCM_sys_Get"
1528    #  fi
1529    #fi
1530
1531    #   #RSYNC WITH NETWORK SSH CALL
1532    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1533    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1534
1535    #   #RSYNC WITH NFS USE
1536    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1537    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1538
1539    #   status=$?
1540    #   IGCM_sys_Rsync_out $status
1541
1542    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1543    #   (( status=status+$? ))
1544
1545    #USUAL WAY
1546    if [ X${1} = X'/l' ] ; then
1547      for target in ${dm_liste[*]} ; do
1548        local_file=$( basename ${target} )
1549        # test if the target file is present before the loop
1550        IGCM_sys_TestFileArchive ${target}
1551        status=$?
1552        if [ ${status} -gt 0 ] ; then
1553          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1554          IGCM_debug_Exit "IGCM_sys_Get"
1555        else
1556          i=0
1557          while [ $i -lt $NB_ESSAI ] ; do
1558            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1559            status=$?
1560            if [ ${status} -gt 0 ]; then
1561              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1562              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1563              sleep $DELAI
1564            else
1565              break
1566            fi
1567            (( i = i + 1 ))
1568          done
1569          if [ ${status} -gt 0 ] ; then
1570            echo "IGCM_sys_Get : error"
1571            cat out_rsync
1572            \rm out_rsync
1573            IGCM_debug_Exit "IGCM_sys_Get"
1574          else
1575            \rm out_rsync
1576          fi
1577        fi
1578      done
1579    else
1580      i=0
1581      while [ $i -lt $NB_ESSAI ] ; do
1582        \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1583        status=$?
1584        if [ ${status} -gt 0 ]; then
1585          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1586          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1587          sleep $DELAI
1588        else
1589          break
1590        fi
1591        (( i = i + 1 ))
1592      done
1593      if [ ${status} -gt 0 ] ; then
1594        echo "IGCM_sys_Get : error"
1595        cat out_rsync
1596        \rm out_rsync
1597        IGCM_debug_Exit "IGCM_sys_Get"
1598      else
1599        \rm out_rsync
1600      fi
1601    fi
1602  else
1603    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1604  fi
1605  IGCM_debug_PopStack "IGCM_sys_Get"
1606}
1607
1608#D-#==================================================
1609#D-function IGCM_sys_GetBuffer
1610#D-* Purpose: Get a file from ${SCRATCHDIR}
1611#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1612#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1613function IGCM_sys_GetBuffer {
1614  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1615
1616  typeset DEST buf_liste target file_work
1617  typeset NB_ESSAI DELAI status i
1618
1619  if ( $DEBUG_sys ) ; then
1620    echo "IGCM_sys_GetBuffer :" $@
1621  fi
1622
1623  # number of tentative
1624  NB_ESSAI=3
1625  # time delay between tentative
1626  DELAI=2
1627
1628  if [ $DRYRUN -le 2 ]; then
1629    if [ X${1} = X'/l' ] ; then
1630      # test if the first file is present in the old computation :
1631      eval set +A buf_liste \${${2}}
1632    else
1633      eval set +A buf_liste ${1}
1634    fi
1635    eval DEST=\${${#}}
1636
1637    #USUAL WAY
1638    if [ X${1} = X'/l' ] ; then
1639      for target in ${buf_liste[*]} ; do
1640        local_file=$( basename ${target} )
1641        i=0
1642        while [ $i -lt $NB_ESSAI ] ; do
1643          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1644          status=$?
1645          if [ ${status} -gt 0 ]; then
1646            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1647            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1648            sleep $DELAI
1649          else
1650            break
1651          fi
1652          (( i = i + 1 ))
1653        done
1654        if [ ${status} -gt 0 ] ; then
1655          echo "IGCM_sys_Get : error"
1656          cat out_rsync
1657          \rm out_rsync
1658          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1659        else
1660          \rm out_rsync
1661        fi
1662      done
1663    else
1664      i=0
1665      while [ $i -lt $NB_ESSAI ] ; do
1666        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1667        status=$?
1668        if [ ${status} -gt 0 ]; then
1669          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1670          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1671          sleep $DELAI
1672        else
1673          break
1674        fi
1675        (( i = i + 1 ))
1676      done
1677      if [ ${status} -gt 0 ] ; then
1678        echo "IGCM_sys_Get : error"
1679        cat out_rsync
1680        \rm out_rsync
1681        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1682      else
1683        \rm out_rsync
1684      fi
1685    fi
1686  else
1687    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1688  fi
1689  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1690}
1691
1692#D-#==================================================
1693#D-function IGCM_sys_GetDate_FichWork
1694#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1695#D-* Examples:
1696#D-
1697function IGCM_sys_GetDate_FichWork {
1698  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1699  if ( $DEBUG_sys ) ; then
1700    echo "IGCM_sys_GetDate_FichWork :" $@
1701  fi
1702  typeset dateF
1703  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1704  eval ${2}=${dateF[5]}
1705
1706  # donne la date filesys d'un fichier sur la machine work
1707  IGCM_debug_PopStack "IGCM_sys_FichWork"
1708}
1709
1710#D-#==================================================
1711#D-function IGCM_sys_GetDate_FichArchive
1712#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1713#D-* Examples:
1714#D-
1715function IGCM_sys_GetDate_FichArchive {
1716  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1717  if ( $DEBUG_sys ) ; then
1718    echo "IGCM_sys_GetDate_FichArchive :" $@
1719  fi
1720  typeset dateF
1721  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1722  eval ${2}=${dateF[5]}
1723
1724  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1725}
1726
1727#D-#==================================================
1728#D-function IGCM_sys_Dods_Rm
1729#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1730#D-* Examples:
1731#D-
1732function IGCM_sys_Dods_Rm {
1733  if ( $DEBUG_sys ) ; then
1734    echo "IGCM_sys_Dods_Rm :" $@
1735  fi
1736  typeset status
1737  if [ $DRYRUN = 0 ]; then
1738
1739#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1740#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1741#      echo "Nothing has been done."
1742#      return
1743#    fi
1744
1745    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1746    status=$?
1747
1748#    if [ ${status} -gt 0 ] ; then
1749#      echo "IGCM_sys_Dods_Rm : error."
1750#      cat out_dods_rm
1751#      IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1752#    else
1753#      rm out_dods_rm
1754#    fi
1755
1756  else
1757    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1758  fi
1759  return $status
1760}
1761
1762#D-#==================================================
1763#D-function IGCM_sys_Dods_Cp
1764#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1765#D-* Examples:
1766#D-
1767function IGCM_sys_Dods_Cp {
1768  if ( $DEBUG_sys ) ; then
1769    echo "IGCM_sys_Dods_Cp :" $@
1770  fi
1771  typeset status
1772  if [ $DRYRUN = 0 ]; then
1773
1774#    if [ ! -d ${R_SAVE}/${1} ] ; then
1775#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1776#      echo "Nothing has been done."
1777#      return
1778#    fi
1779
1780    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1781    status=$?
1782
1783#       if [ ${status} -gt 0 ] ; then
1784#           echo "IGCM_sys_Dods_Cp : error."
1785#           cat out_dods_cp
1786#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1787#       else
1788#           rm out_dods_cp
1789#       fi
1790
1791  else
1792    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1793  fi
1794  return $status
1795}
1796
1797#D-#==================================================
1798#D-function IGCM_sys_Put_Dods
1799#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1800#D-* Examples:
1801#D-
1802function IGCM_sys_Put_Dods {
1803  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1804  if ( $DEBUG_sys ) ; then
1805    echo "IGCM_sys_Put_Dods :" $@
1806  fi
1807  #set -vx
1808  typeset status
1809  if [ $DRYRUN = 0 ]; then
1810    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1811      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1812      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1813      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1814      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1815      return
1816    fi
1817
1818    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1819      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1820      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1821      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1822      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1823      return
1824    fi
1825    #
1826    if [ -d ${R_SAVE}/${1} ] ; then
1827      cd ${R_SAVE}
1828    elif [ -d ${R_FIGR}/${1} ] ; then
1829      cd ${R_FIGR}
1830    fi
1831
1832    IGCM_sys_Dods_Rm ${1}
1833    IGCM_sys_Dods_Cp ${1}
1834    status=0
1835
1836    if [ ${status} -gt 0 ] ; then
1837      echo "IGCM_sys_Put_Dods : error."
1838      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1839    fi
1840  else
1841    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1842  fi
1843  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1844}
1845
1846##############################################################
1847# REBUILD OPERATOR
1848
1849function IGCM_sys_rebuild {
1850  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1851  if ( $DEBUG_sys ) ; then
1852    echo "IGCM_sys_rebuild :" $@
1853  fi
1854
1855  typeset NB_ESSAI DELAI status i firstArg
1856  # number of tentative
1857  NB_ESSAI=3
1858  # time delay between tentative
1859  DELAI=2
1860
1861  i=0
1862  while [ $i -lt $NB_ESSAI ] ; do
1863    ~p86ipsl/CESIUM/bin/rebuild -f -o $@ > out_rsync 2>&1
1864    status=$?
1865    if [ ${status} -gt 0 ] ; then
1866      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1867      cat out_rsync
1868      \rm out_rsync
1869      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1870      firstArg=${1}
1871      \rm ${firstArg}
1872      sleep $DELAI
1873    else
1874      \rm out_rsync
1875      break
1876    fi
1877    (( i = i + 1 ))
1878  done
1879
1880  if [ ${status} -gt 0 ] ; then
1881    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1882    IGCM_debug_Exit "rebuild"
1883  fi
1884
1885  IGCM_debug_PopStack "IGCM_sys_rebuild"
1886}
1887
1888function IGCM_sys_rebuild_station {
1889  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1890  typeset i list_opt file_in file_out prefix_invert list_invert
1891  if ( $DEBUG_sys ) ; then
1892    echo "IGCM_sys_rebuild_station :" $@
1893  fi
1894  list_opt=$@
1895
1896  # Invert Axis : t,x -> x,t
1897  #               t,pres,x -> x,t,pres
1898  # So that we can concatenate along x
1899  i=0
1900  for file_in in ${list_opt} ; do
1901    (( i = i + 1))
1902    [ ${i} = 1 ] && file_out=${file_in} && continue
1903    prefix_invert=$( basename ${file_in} .nc )
1904    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1905    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1906  done
1907
1908  # Concatenate
1909  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1910
1911  # Re-ivert file
1912  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1913
1914  # Station re-ordering is too expansive to be run within libICGM
1915  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1916  # This re-ordering must be done "in memory" by the cmorization process
1917  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1918  # BEGIN reordering
1919
1920  # Only LMDZ text output contains the exact ordering of the station.
1921  # We isolate this in the code below:
1922  #  0  38  -157.5000000000000  70.98591549295774
1923  #  0  54  27.49999999999999   67.18309859154928
1924  #  0  56  -62.50000000000001  82.39436619718309
1925  #  0  79  12.49999999999999   78.59154929577466
1926  #  0  116 -165.0000000000000  76.05633802816901
1927  #  0  117 130.0000000000000   70.98591549295774
1928  #  0  118 110.0000000000000   87.46478873239437
1929  #  1  40  4.999999999999995   51.97183098591550
1930#  typeset iStation iProc list_opt file_in file_out prefix_invert
1931#  typeset -Z4 j4
1932#  typeset -Z3 j3
1933
1934#  unset list_opt
1935#  set +A list_opt $@
1936
1937  # Filename after rebuild
1938#  file_out=${list_opt[0]}
1939  # Prefix of output files
1940#  prefix_invert=$( basename ${file_out} .nc )
1941  # Number of procs
1942#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1943
1944#  iProc=0
1945#  while [ ${iProc} -lt ${num_proc} ] ; do
1946    # Array containing Station as a number
1947#    unset proc_stn
1948#    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}' )
1949    # Number of stations produced by processor proc
1950#    stationLast=${#proc_stn[*]}
1951    # Proc number on 4 digits
1952#    j4=${iProc}
1953    # Init
1954#    iStation=0
1955#    while [ ${iStation} -lt ${stationLast} ] ; do
1956      # Station number on 3 digits
1957#      j3=${proc_stn[${iStation}]}
1958      # Extract station
1959      # Invert Axis : t,x -> x,t
1960      #               t,pres,x -> x,t,pres
1961      # So that we can concatenate along x
1962#      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
1963#      (( iStation = iStation + 1 ))
1964#    done
1965#    (( iProc = iProc + 1 ))
1966#  done
1967
1968  # Concatenate all station along x
1969#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1970
1971  # Re-invert file
1972#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1973
1974  # END reordering
1975
1976  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1977}
1978
1979############################################################
1980# Activate Running Environnment Variables
1981
1982function IGCM_sys_activ_variables {
1983  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1984  if ( $DEBUG_sys ) ; then
1985    echo "IGCM_sys_activ_variables"
1986  fi
1987
1988  ulimit -s unlimited
1989
1990  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1991}
1992
1993############################################################
1994# Desactivate Running Environnment Variables
1995
1996function IGCM_sys_desactiv_variables {
1997  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1998  if ( $DEBUG_sys ) ; then
1999    echo "IGCM_sys_desactiv_variables"
2000  fi
2001  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
2002}
2003
2004############################################################
2005# Build MPI/OMP scripts run file (dummy function)
2006
2007function IGCM_sys_build_run_file {
2008
2009IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
2010
2011}
2012
2013############################################################
2014# Build MPI/OMP scripts
2015function IGCM_sys_build_execution_scripts
2016{
2017  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
2018  if ( $DEBUG_sys ) ; then
2019    echo "IGCM_sys_build_execution_scripts " $@
2020  fi
2021
2022    # Verification with MSUB parameter
2023  EXECUTION=${HOST_MPIRUN_COMMAND}
2024
2025  if ( ${OK_PARA_MPMD} ) ; then
2026
2027    if [ -f run_file ] ; then
2028      IGCM_sys_Rm -f run_file
2029    fi
2030    touch run_file
2031
2032# run_file construction
2033
2034# Then first loop on the components for the coupler ie oasis
2035
2036### the coupler ie oasis must be the first one
2037    for comp in ${config_ListOfComponents[*]} ; do
2038
2039      eval ExeNameIn=\${config_Executable_${comp}[0]}
2040      eval ExeNameOut=\${config_Executable_${comp}[1]}
2041
2042      # for CPL component only
2043      if [ "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# Then second loop on the components
2052
2053    for comp in ${config_ListOfComponents[*]} ; do
2054
2055      eval ExeNameIn=\${config_Executable_${comp}[0]}
2056      eval ExeNameOut=\${config_Executable_${comp}[1]}
2057
2058      # Only if we really have an executable for the component and not the coupler ie oasis:
2059      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
2060
2061        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2062        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2063        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2064      fi
2065    done
2066
2067    EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
2068
2069    IGCM_sys_Chmod u+x run_file
2070    if ( $DEBUG_sys ) ; then
2071      echo "run_file contains : "
2072      cat run_file
2073    fi
2074
2075  else # Only one executable. launch it.
2076
2077    #
2078    for comp in ${config_ListOfComponents[*]} ; do
2079
2080      # Only if we really have an executable for the component :
2081      eval ExeNameOut=\${config_Executable_${comp}[1]}
2082      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2083
2084        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2085        echo ""  >> script_${ExeNameOut}.ksh
2086        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2087
2088        if ( ${OK_PARA_OMP} ) ; then
2089          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2090          echo ""  >> script_${ExeNameOut}.ksh
2091          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2092          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2093          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2094          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
2095        fi
2096
2097        if  ( ${OK_PARA_MPI} ) ; then
2098          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2099          # Default : ccc_mprun used if nb_proc gt 1
2100          # to have out/err per process on different files
2101          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
2102          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2103          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
2104        else
2105          # Default : ccc_mprun is NOT used if nb_proc eq 1
2106          # to have out/err per process on different files
2107          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
2108          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2109          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
2110        fi
2111
2112        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
2113        cat script_${ExeNameOut}.ksh
2114
2115      fi
2116
2117    done
2118
2119  fi
2120
2121  IGCM_debug_Print 1 "sys Curie : execution command is "
2122  IGCM_debug_Print 1 "$EXECUTION"
2123
2124  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2125}
2126
2127############################################################
2128# Check of space available on temporary filesytems
2129function IGCM_sys_check_quota {
2130  IGCM_debug_PushStack "IGCM_sys_check_quota"
2131  if ( $DEBUG_sys ) ; then
2132    echo "IGCM_sys_check_quota"
2133  fi
2134  # Limit of quota (in %)
2135  limit_quota=90
2136
2137  # Check of the volume
2138  volume_quota=$(ccc_quota | grep ' scratch' | awk '{print $2}')
2139  volume_avail=$(ccc_quota | grep ' scratch' | awk '{print $3}')
2140
2141  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
2142
2143    unit_avail=${volume_avail: -1}
2144    unit_quota=${volume_quota: -1}
2145
2146    if [ "${unit_quota}" = "*" ] ; then
2147        IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2148        IGCM_debug_Print 1 "More than 100% of your quota is used"
2149        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2150        IGCM_debug_Print 1 "You must have more than 10% available to run"
2151        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2152        IGCM_debug_Verif_Exit
2153    fi
2154
2155    temp_avail=${volume_avail%%${volume_avail: -1}*}
2156    temp_quota=${volume_quota%%${volume_quota: -1}*}
2157
2158    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2159
2160    # Convertion
2161      if [ ${volume_avail: -1} = "T" ] ; then
2162        (( temp_avail = temp_avail * 1000000000000 ))
2163      elif [ ${volume_avail: -1} = "G" ] ; then
2164        (( temp_avail = temp_avail * 1000000000 ))
2165      elif [ ${volume_avail: -1} = "M" ] ; then
2166        (( temp_avail = temp_avail * 1000000 ))
2167      elif [ ${volume_avail: -1} = "k" ] ; then
2168        (( temp_avail = temp_avail * 1000 ))
2169      else
2170        (( temp_avail = volume_avail ))
2171      fi
2172      if [ ${volume_quota: -1} = "T" ] ; then
2173        (( temp_quota = temp_quota * 1000000000000 ))
2174      elif [ ${volume_quota: -1} = "G" ] ; then
2175        (( temp_quota = temp_quota * 1000000000 ))
2176      elif [ ${volume_quota: -1} = "M" ] ; then
2177        (( temp_quota = temp_quota * 1000000 ))
2178      elif [ ${volume_quota: -1} = "k" ] ; then
2179        (( temp_quota = temp_quota * 1000 ))
2180      else
2181        (( temp_quota = volume_quota ))
2182      fi
2183    fi
2184
2185    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2186#    echo "volume ratio is " $quota_volume
2187
2188    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2189      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2190      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2191      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2192      IGCM_debug_Print 1 "You must have more than 10% available to run"
2193      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2194      IGCM_debug_Verif_Exit
2195    fi
2196
2197  fi
2198
2199# Check of the number of inodes
2200
2201  inode_quota=$(ccc_quota | grep ' scratch' | awk '{print $6}')
2202  inode_avail=$(ccc_quota | grep ' scratch' | awk '{print $7}')
2203
2204  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
2205
2206    unit_avail=${inode_avail: -1}
2207    unit_quota=${inode_quota: -1}
2208
2209    if [ "${unit_quota}" = "*" ] ; then
2210        IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2211        IGCM_debug_Print 1 "More than 100% of your quota is used"
2212        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2213        IGCM_debug_Print 1 "You must have more than 10% available to run"
2214        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2215        IGCM_debug_Verif_Exit
2216    fi
2217
2218    temp_avail=${inode_avail%%${inode_avail: -1}*}
2219    temp_quota=${inode_quota%%${inode_quota: -1}*}
2220
2221    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2222
2223    # Convertion
2224      if [ ${inode_avail: -1} = "T" ] ; then
2225        (( temp_avail = temp_avail * 1000000000000 ))
2226      elif [ ${inode_avail: -1} = "G" ] ; then
2227        (( temp_avail = temp_avail * 1000000000 ))
2228      elif [ ${inode_avail: -1} = "M" ] ; then
2229        (( temp_avail = temp_avail * 1000000 ))
2230      elif [ ${inode_avail: -1} = "k" ] ; then
2231        (( temp_avail = temp_avail * 1000 ))
2232      else
2233        (( temp_avail = inode_avail ))
2234      fi
2235
2236      if [ ${inode_quota: -1} = "T" ] ; then
2237        (( temp_quota = temp_quota * 1000000000000 ))
2238      elif [ ${inode_quota: -1} = "G" ] ; then
2239        (( temp_quota = temp_quota * 1000000000 ))
2240      elif [ ${inode_quota: -1} = "M" ] ; then
2241        (( temp_quota = temp_quota * 1000000 ))
2242      elif [ ${inode_quota: -1} = "k" ] ; then
2243        (( temp_quota = temp_quota * 1000 ))
2244      else
2245        (( temp_quota = inode_quota ))
2246      fi
2247    fi
2248    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2249#    echo "inode ratio is " $quota_inode
2250
2251    if [ ${quota_inode} -ge ${limit_quota} ] ; then
2252      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2253      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
2254      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2255      IGCM_debug_Print 1 "You must have more than 10% available to run"
2256      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2257      IGCM_debug_Verif_Exit
2258    fi
2259  fi
2260  IGCM_debug_PopStack "IGCM_sys_check_quota"
2261}
2262
2263#D-#==================================================
2264#D-function IGCM_sys_CountJobInQueue
2265#D-* Purpose: Check if job_name is currently
2266#D-  running or in queue
2267#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
2268#D-
2269
2270function IGCM_sys_CountJobInQueue {
2271  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
2272  if ( $DEBUG_sys ) ; then
2273    echo "IGCM_sys_CountJobInQueue"
2274  fi
2275
2276  #NbRun=$( ccc_mstat -f | grep -c ${JobName} )
2277
2278  # With -f option, the full job name is given in the last column
2279  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ($NF~String) { x=x+1 } END { print x }' )
2280
2281  eval ${2}=${NbRun}
2282
2283  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
2284}
2285
2286##############################################################
2287# NCO OPERATOR
2288
2289function IGCM_sys_ncap2 {
2290  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2291  if ( $DEBUG_sys ) ; then
2292    echo "IGCM_sys_ncap2 :" $@
2293  fi
2294
2295  typeset NB_ESSAI DELAI status i
2296  # number of tentative
2297  NB_ESSAI=3
2298  # time delay between tentative
2299  DELAI=2
2300
2301  i=0
2302  while [ $i -lt $NB_ESSAI ] ; do
2303    ncap2 "$@" > out_rsync 2>&1
2304    status=$?
2305    if [ ${status} -gt 0 ] ; then
2306      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2307      cat out_rsync
2308      \rm out_rsync
2309      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2310      sleep $DELAI
2311    else
2312      \rm out_rsync
2313      break
2314    fi
2315    (( i = i + 1 ))
2316  done
2317
2318  if [ ${status} -gt 0 ] ; then
2319      echo "IGCM_sys_ncap2 : ncap2 error"
2320      IGCM_debug_Exit "ncap2"
2321  fi
2322
2323  IGCM_debug_PopStack "IGCM_sys_ncap2"
2324}
2325
2326function IGCM_sys_ncatted {
2327  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2328  if ( $DEBUG_sys ) ; then
2329    echo "IGCM_sys_ncatted :" $@
2330  fi
2331
2332  typeset NB_ESSAI DELAI status i
2333  # number of tentative
2334  NB_ESSAI=3
2335  # time delay between tentative
2336  DELAI=2
2337
2338  i=0
2339  while [ $i -lt $NB_ESSAI ] ; do
2340    ncatted "$@" > out_rsync 2>&1
2341    status=$?
2342    if [ ${status} -gt 0 ] ; then
2343      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2344      cat out_rsync
2345      \rm out_rsync
2346      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2347      sleep $DELAI
2348    else
2349      \rm out_rsync
2350      break
2351    fi
2352    (( i = i + 1 ))
2353  done
2354
2355  if [ ${status} -gt 0 ] ; then
2356      echo "IGCM_sys_ncatted : ncatted error"
2357      IGCM_debug_Exit "ncatted"
2358  fi
2359
2360  IGCM_debug_PopStack "IGCM_sys_ncatted"
2361}
2362
2363function IGCM_sys_ncbo {
2364  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2365  if ( $DEBUG_sys ) ; then
2366    echo "IGCM_sys_ncbo :" $@
2367  fi
2368
2369  typeset NB_ESSAI DELAI status i
2370  # number of tentative
2371  NB_ESSAI=3
2372  # time delay between tentative
2373  DELAI=2
2374
2375  i=0
2376  while [ $i -lt $NB_ESSAI ] ; do
2377    ncbo $@ > out_rsync 2>&1
2378    status=$?
2379    if [ ${status} -gt 0 ] ; then
2380      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2381      cat out_rsync
2382      \rm out_rsync
2383      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2384      sleep $DELAI
2385    else
2386      \rm out_rsync
2387      break
2388    fi
2389    (( i = i + 1 ))
2390  done
2391
2392  if [ ${status} -gt 0 ] ; then
2393      echo "IGCM_sys_ncbo : ncbo error"
2394      IGCM_debug_Exit "ncbo"
2395  fi
2396
2397  IGCM_debug_PopStack "IGCM_sys_ncbo"
2398}
2399
2400function IGCM_sys_ncdiff {
2401  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2402  if ( $DEBUG_sys ) ; then
2403    echo "IGCM_sys_ncdiff :" $@
2404  fi
2405
2406  typeset NB_ESSAI DELAI status i
2407  # number of tentative
2408  NB_ESSAI=3
2409  # time delay between tentative
2410  DELAI=2
2411
2412  i=0
2413  while [ $i -lt $NB_ESSAI ] ; do
2414    ncdiff $@ > out_rsync 2>&1
2415    status=$?
2416    if [ ${status} -gt 0 ] ; then
2417      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2418      cat out_rsync
2419      \rm out_rsync
2420      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2421      sleep $DELAI
2422    else
2423      \rm out_rsync
2424      break
2425    fi
2426    (( i = i + 1 ))
2427  done
2428
2429  if [ ${status} -gt 0 ] ; then
2430      echo "IGCM_sys_ncdiff : ncdiff error"
2431      IGCM_debug_Exit "ncdiff"
2432  fi
2433
2434  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2435}
2436
2437function IGCM_sys_ncea {
2438  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2439  if ( $DEBUG_sys ) ; then
2440    echo "IGCM_sys_ncea :" $@
2441  fi
2442
2443  typeset NB_ESSAI DELAI status i
2444  # number of tentative
2445  NB_ESSAI=3
2446  # time delay between tentative
2447  DELAI=2
2448
2449  i=0
2450  while [ $i -lt $NB_ESSAI ] ; do
2451    ncea $@ > out_rsync 2>&1
2452    status=$?
2453    if [ ${status} -gt 0 ] ; then
2454      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2455      cat out_rsync
2456      \rm out_rsync
2457      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2458      sleep $DELAI
2459    else
2460      \rm out_rsync
2461      break
2462    fi
2463    (( i = i + 1 ))
2464  done
2465
2466  if [ ${status} -gt 0 ] ; then
2467      echo "IGCM_sys_ncea : ncea error"
2468      IGCM_debug_Exit "ncea"
2469  fi
2470
2471  IGCM_debug_PopStack "IGCM_sys_ncea"
2472}
2473
2474function IGCM_sys_ncecat {
2475  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2476  if ( $DEBUG_sys ) ; then
2477    echo "IGCM_sys_ncecat :" $@
2478  fi
2479
2480  typeset NB_ESSAI DELAI status i
2481  # number of tentative
2482  NB_ESSAI=3
2483  # time delay between tentative
2484  DELAI=2
2485
2486  i=0
2487  while [ $i -lt $NB_ESSAI ] ; do
2488    ncecat $@ > out_rsync 2>&1
2489    status=$?
2490    if [ ${status} -gt 0 ] ; then
2491      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2492      cat out_rsync
2493      \rm out_rsync
2494      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2495      sleep $DELAI
2496    else
2497      \rm out_rsync
2498      break
2499    fi
2500    (( i = i + 1 ))
2501  done
2502
2503  if [ ${status} -gt 0 ] ; then
2504      echo "IGCM_sys_ncecat : ncecat error"
2505      IGCM_debug_Exit "ncecat"
2506  fi
2507
2508  IGCM_debug_PopStack "IGCM_sys_ncecat"
2509}
2510
2511function IGCM_sys_ncflint {
2512  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2513  if ( $DEBUG_sys ) ; then
2514    echo "IGCM_sys_ncflint :" $@
2515  fi
2516
2517  typeset NB_ESSAI DELAI status i
2518  # number of tentative
2519  NB_ESSAI=3
2520  # time delay between tentative
2521  DELAI=2
2522
2523  i=0
2524  while [ $i -lt $NB_ESSAI ] ; do
2525    ncflint $@ > out_rsync 2>&1
2526    status=$?
2527    if [ ${status} -gt 0 ] ; then
2528      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2529      cat out_rsync
2530      \rm out_rsync
2531      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2532      sleep $DELAI
2533    else
2534      \rm out_rsync
2535      break
2536    fi
2537    (( i = i + 1 ))
2538  done
2539
2540  if [ ${status} -gt 0 ] ; then
2541      echo "IGCM_sys_ncflint : ncflint error"
2542      IGCM_debug_Exit "ncflint"
2543  fi
2544
2545  IGCM_debug_PopStack "IGCM_sys_ncflint"
2546}
2547
2548function IGCM_sys_ncks {
2549  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2550  if ( $DEBUG_sys ) ; then
2551    echo "IGCM_sys_ncks :" $@
2552  fi
2553
2554  typeset NB_ESSAI DELAI status i
2555  # number of tentative
2556  NB_ESSAI=3
2557  # time delay between tentative
2558  DELAI=2
2559
2560  i=0
2561  while [ $i -lt $NB_ESSAI ] ; do
2562    ncks $@ > out_rsync 2>&1
2563    status=$?
2564    if [ ${status} -gt 0 ] ; then
2565      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2566      cat out_rsync
2567      \rm out_rsync
2568      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2569      sleep $DELAI
2570    else
2571      \rm out_rsync
2572      break
2573    fi
2574    (( i = i + 1 ))
2575  done
2576
2577  if [ ${status} -gt 0 ] ; then
2578      echo "IGCM_sys_ncks : ncks error"
2579      IGCM_debug_Exit "ncks"
2580  fi
2581
2582  IGCM_debug_PopStack "IGCM_sys_ncks"
2583}
2584
2585function IGCM_sys_ncpdq {
2586  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2587  if ( $DEBUG_sys ) ; then
2588    echo "IGCM_sys_ncpdq :" $@
2589  fi
2590
2591  typeset NB_ESSAI DELAI status i
2592  # number of tentative
2593  NB_ESSAI=3
2594  # time delay between tentative
2595  DELAI=2
2596
2597  i=0
2598  while [ $i -lt $NB_ESSAI ] ; do
2599    ncpdq $@ > out_rsync 2>&1
2600    status=$?
2601    if [ ${status} -gt 0 ] ; then
2602      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2603      cat out_rsync
2604      \rm out_rsync
2605      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2606      sleep $DELAI
2607    else
2608      \rm out_rsync
2609      break
2610    fi
2611    (( i = i + 1 ))
2612  done
2613
2614  if [ ${status} -gt 0 ] ; then
2615      echo "IGCM_sys_ncpdq : ncpdq error"
2616      IGCM_debug_Exit "ncpdq"
2617  fi
2618
2619  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2620}
2621
2622function IGCM_sys_ncra {
2623  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2624  if ( $DEBUG_sys ) ; then
2625    echo "IGCM_sys_ncra :" $@
2626  fi
2627
2628  typeset NB_ESSAI DELAI status i
2629  # number of tentative
2630  NB_ESSAI=3
2631  # time delay between tentative
2632  DELAI=2
2633
2634  i=0
2635  while [ $i -lt $NB_ESSAI ] ; do
2636    ncra $@ > out_rsync 2>&1
2637    status=$?
2638    if [ ${status} -gt 0 ] ; then
2639      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2640      cat out_rsync
2641      \rm out_rsync
2642      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2643      sleep $DELAI
2644    else
2645      \rm out_rsync
2646      break
2647    fi
2648    (( i = i + 1 ))
2649  done
2650
2651  if [ ${status} -gt 0 ] ; then
2652      echo "IGCM_sys_ncra : ncra error"
2653      IGCM_debug_Exit "ncra"
2654  fi
2655
2656  IGCM_debug_PopStack "IGCM_sys_ncra"
2657}
2658
2659function IGCM_sys_ncrcat {
2660  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2661  if ( $DEBUG_sys ) ; then
2662    echo "IGCM_sys_ncrcat :" $@
2663  fi
2664
2665  typeset NB_ESSAI DELAI status i lastArg
2666  # number of tentative
2667  NB_ESSAI=3
2668  # time delay between tentative
2669  DELAI=2
2670
2671  i=0
2672  while [ $i -lt $NB_ESSAI ] ; do
2673    ncrcat $@ > out_rsync 2>&1
2674    status=$?
2675    if [ ${status} -gt 0 ] ; then
2676      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2677      cat out_rsync
2678      \rm out_rsync
2679      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2680      sleep $DELAI
2681    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2682      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2683      cat out_rsync
2684      # remove files having corrupted time axis
2685      eval lastArg=\${$#}
2686      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2687      \rm ${lastArg}
2688      \rm out_rsync
2689      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2690      sleep $DELAI
2691    else
2692      \rm out_rsync
2693      break
2694    fi
2695    (( i = i + 1 ))
2696  done
2697
2698  if [ ${status} -gt 0 ] ; then
2699      echo "IGCM_sys_ncrcat : ncrcat error"
2700      #IGCM_debug_Exit "ncrcat"
2701  fi
2702
2703  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2704}
2705
2706function IGCM_sys_ncrename {
2707  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2708  if ( $DEBUG_sys ) ; then
2709    echo "IGCM_sys_ncrename :" $@
2710  fi
2711
2712  typeset NB_ESSAI DELAI status i
2713  # number of tentative
2714  NB_ESSAI=3
2715  # time delay between tentative
2716  DELAI=2
2717
2718  i=0
2719  while [ $i -lt $NB_ESSAI ] ; do
2720    ncrename $@ > out_rsync 2>&1
2721    status=$?
2722    if [ ${status} -gt 0 ] ; then
2723      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2724      cat out_rsync
2725      \rm out_rsync
2726      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2727      sleep $DELAI
2728    else
2729      \rm out_rsync
2730      break
2731    fi
2732    (( i = i + 1 ))
2733  done
2734
2735  if [ ${status} -gt 0 ] ; then
2736      echo "IGCM_sys_ncrename : ncrename error"
2737      IGCM_debug_Exit "ncrename"
2738  fi
2739
2740  IGCM_debug_PopStack "IGCM_sys_ncrename"
2741}
2742
2743function IGCM_sys_ncwa {
2744  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2745  if ( $DEBUG_sys ) ; then
2746    echo "IGCM_sys_ncwa :" $@
2747  fi
2748
2749  typeset NB_ESSAI DELAI status i
2750  # number of tentative
2751  NB_ESSAI=3
2752  # time delay between tentative
2753  DELAI=2
2754
2755  i=0
2756  while [ $i -lt $NB_ESSAI ] ; do
2757    ncwa $@ > out_rsync 2>&1
2758    status=$?
2759    if [ ${status} -gt 0 ] ; then
2760      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2761      cat out_rsync
2762      \rm out_rsync
2763      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2764      sleep $DELAI
2765    else
2766      \rm out_rsync
2767      break
2768    fi
2769    (( i = i + 1 ))
2770  done
2771
2772  if [ ${status} -gt 0 ] ; then
2773      echo "IGCM_sys_ncwa : ncwa error"
2774      IGCM_debug_Exit "ncwa"
2775  fi
2776
2777  IGCM_debug_PopStack "IGCM_sys_ncwa"
2778}
2779
2780##############################################################
2781# CDO OPERATOR
2782
2783function IGCM_sys_cdo {
2784  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2785  if ( $DEBUG_sys ) ; then
2786    echo "IGCM_sys_cdo :" $@
2787  fi
2788
2789  typeset status
2790
2791  \cdo $@ > out_rsync 2>&1
2792  status=$?
2793  if [ ${status} -gt 0 ] ; then
2794    echo "IGCM_sys_cdo : error code ${status}"
2795    cat out_rsync
2796    \rm out_rsync
2797    IGCM_debug_PopStack "IGCM_sys_cdo"
2798    return 1
2799  else
2800    IGCM_debug_PopStack "IGCM_sys_cdo"
2801    return 0
2802  fi
2803
2804  IGCM_debug_PopStack "IGCM_sys_cdo"
2805}
Note: See TracBrowser for help on using the repository browser.