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

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