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

Last change on this file since 716 was 716, checked in by sdipsl, 12 years ago

curie : multiple tries over rebuild command as well

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