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

Last change on this file since 807 was 807, checked in by mafoipsl, 11 years ago

On curie, adapt EXECUTION command to stop immediately instead of waiting 600s. tested in single executable and in coupled mode.

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