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

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