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

Last change on this file since 713 was 713, checked in by sdipsl, 12 years ago
  • curie : multiple tries over nco command
  • curie : print error code from mv, cp, nco, ...
  • curie, titane, mercure : use recursive demigration when applicable ccc_hsm get -r
  • Property svn:keywords set to Revision Author Date
File size: 68.5 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for Curie
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=curie
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# 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 RET 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  RET=$?
836
837  if [ ${RET} -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 RET
856
857  echo cp $@ > out_rsync 2>&1
858  \cp $@ >> out_rsync 2>&1
859  RET=$?
860
861  if [ ${RET} -gt 0 ] ; then
862    echo "IGCM_sys_Cp : error code ${RET}"
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 RET
883
884  echo rm $@ > out_rsync 2>&1
885  \rm $@ >> out_rsync 2>&1
886  RET=$?
887
888  if [ ${RET} -gt 0 ] ; then
889    echo "IGCM_sys_Rm : error code ${RET}"
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 RET
911
912  echo rm $@ > out_rsync 2>&1
913  \rm $@ >> out_rsync 2>&1
914  RET=$?
915
916  if [ ${RET} -gt 0 ] ; then
917    echo "IGCM_sys_RmRunDir : error code ${RET}"
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 RET
940
941    echo mv $@ > out_rsync 2>&1
942    \mv $@ >> out_rsync 2>&1
943    RET=$?
944
945    if [ ${RET} -gt 0 ] ; then
946      echo "IGCM_sys_Mv : error code ${RET}"
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 RET
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    RET=$?
984
985    if [ ${RET} -gt 0 ] ; then
986      echo "IGCM_sys_Put_Dir : error code ${RET}"
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 RET
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    RET=$?
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#       RET=$?
1148#       IGCM_sys_Rsync_out $RET
1149
1150#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1151#       (( RET=RET+$? ))
1152
1153    if [ ${RET} -gt 0 ] ; then
1154      echo "IGCM_sys_Put_Rest : cp failed error code ${RET}"
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 RET
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    RET=$?
1193
1194    if [ ${RET} -gt 0 ] ; then
1195      echo "IGCM_sys_PutBuffer_Rest : error code ${RET}"
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    RET=$?
1451    if [ ${RET} -gt 0 ] ; then
1452      echo "WARNING IGCM_sys_Get : error code ${RET}"
1453      cat out_rsync
1454      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1455    fi
1456
1457    #if [ ${RET} -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    #   RET=$?
1466    #   if [ ${RET} -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        RET=$?
1487        if [ ${RET} -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      RET=$?
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#       RET=$?
1520#       IGCM_sys_Rsync_out $RET
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 code ${RET}"
1527      cat out_rsync
1528      IGCM_debug_Exit "IGCM_sys_Get"
1529    else
1530      \rm out_rsync
1531    fi
1532  else
1533    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1534  fi
1535  IGCM_debug_PopStack "IGCM_sys_Get"
1536}
1537
1538#D-#==================================================
1539#D-function IGCM_sys_GetBuffer
1540#D-* Purpose: Get a file from ${SCRATCHDIR}
1541#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1542#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1543function IGCM_sys_GetBuffer {
1544  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1545
1546  typeset DEST RET buf_liste ifile target file_work
1547
1548  if ( $DEBUG_sys ) ; then
1549    echo "IGCM_sys_GetBuffer :" $@
1550  fi
1551  if [ $DRYRUN -le 2 ]; then
1552    if [ X${1} = X'/l' ] ; then
1553      # test if the first file is present in the old computation :
1554      eval set +A buf_liste \${${2}}
1555    else
1556      eval set +A buf_liste ${1}
1557    fi
1558    eval DEST=\${${#}}
1559
1560    #USUAL WAY
1561    if [ X${1} = X'/l' ] ; then
1562      (( RET=0 ))
1563      for target in ${buf_liste[*]} ; do
1564        local_file=$( basename ${target} )
1565        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1566        (( RET = RET + $? ))
1567      done
1568    else
1569      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1570      RET=$?
1571    fi
1572
1573    if [ ${RET} -gt 0 ] ; then
1574      echo "IGCM_sys_GetBuffer : error code ${RET}"
1575      cat out_rsync
1576      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1577    else
1578      \rm out_rsync
1579    fi
1580  else
1581    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1582  fi
1583  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1584}
1585
1586#D-#==================================================
1587#D-function IGCM_sys_GetDate_FichWork
1588#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1589#D-* Examples:
1590#D-
1591function IGCM_sys_GetDate_FichWork {
1592  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1593  if ( $DEBUG_sys ) ; then
1594    echo "IGCM_sys_GetDate_FichWork :" $@
1595  fi
1596  typeset dateF
1597  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1598  eval ${2}=${dateF[5]}
1599
1600    # donne la date filesys d'un fichier sur la machine work
1601  IGCM_debug_PopStack "IGCM_sys_FichWork"
1602}
1603
1604#D-#==================================================
1605#D-function IGCM_sys_GetDate_FichArchive
1606#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1607#D-* Examples:
1608#D-
1609function IGCM_sys_GetDate_FichArchive {
1610  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1611  if ( $DEBUG_sys ) ; then
1612    echo "IGCM_sys_GetDate_FichArchive :" $@
1613  fi
1614  typeset dateF
1615  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1616  eval ${2}=${dateF[5]}
1617
1618  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1619}
1620
1621#D-#==================================================
1622#D-function IGCM_sys_Dods_Rm
1623#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1624#D-* Examples:
1625#D-
1626function IGCM_sys_Dods_Rm {
1627  if ( $DEBUG_sys ) ; then
1628    echo "IGCM_sys_Dods_Rm :" $@
1629  fi
1630  typeset RET
1631  RET=0
1632  if [ $DRYRUN = 0 ]; then
1633
1634#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1635#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1636#      echo "Nothing has been done."
1637#      return
1638#    fi
1639
1640    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1641    RET=$?
1642
1643#       if [ ${RET} -gt 0 ] ; then
1644#           echo "IGCM_sys_Dods_Rm : error."
1645#           cat out_dods_rm
1646#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1647#       else
1648#           rm out_dods_rm
1649#       fi
1650
1651  else
1652    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1653  fi
1654  return $RET
1655}
1656
1657#D-#==================================================
1658#D-function IGCM_sys_Dods_Cp
1659#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1660#D-* Examples:
1661#D-
1662function IGCM_sys_Dods_Cp {
1663  if ( $DEBUG_sys ) ; then
1664    echo "IGCM_sys_Dods_Cp :" $@
1665  fi
1666  typeset RET
1667  RET=0
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    RET=$?
1678
1679#       if [ ${RET} -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 $RET
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 RET
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    RET=0
1731
1732    if [ ${RET} -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  ~p86ipsl/CESIUM/bin/rebuild -f -o $@
1751  if [ $? -gt 0 ] ; then
1752    echo "IGCM_sys_rebuild : erreur ${@}."
1753    IGCM_debug_Exit "rebuild"
1754  fi
1755
1756  IGCM_debug_PopStack "IGCM_sys_rebuild"
1757}
1758
1759function IGCM_sys_rebuild_station {
1760  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1761  typeset i list_opt file_in file_out prefix_invert list_invert
1762  if ( $DEBUG_sys ) ; then
1763    echo "IGCM_sys_rebuild_station :" $@
1764  fi
1765  list_opt=$@
1766
1767  # Invert Axis : t,x -> x,t
1768  #               t,pres,x -> x,t,pres
1769  # So that we can concatenate along x
1770  i=0
1771  for file_in in ${list_opt} ; do
1772    (( i = i + 1))
1773    [ ${i} = 1 ] && file_out=${file_in} && continue
1774    prefix_invert=$( basename ${file_in} .nc )
1775    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1776    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1777  done
1778
1779  # Concatenate
1780  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1781
1782  # Re-ivert file
1783  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1784
1785  # Station re-ordering is too expansive to be run within libICGM
1786  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1787  # This re-ordering must be done "in memory" by the cmorization process
1788  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1789  # BEGIN reordering
1790
1791  # Only LMDZ text output contains the exact ordering of the station.
1792  # We isolate this in the code below:
1793  #  0  38  -157.5000000000000  70.98591549295774
1794  #  0  54  27.49999999999999   67.18309859154928
1795  #  0  56  -62.50000000000001  82.39436619718309
1796  #  0  79  12.49999999999999   78.59154929577466
1797  #  0  116 -165.0000000000000  76.05633802816901
1798  #  0  117 130.0000000000000   70.98591549295774
1799  #  0  118 110.0000000000000   87.46478873239437
1800  #  1  40  4.999999999999995   51.97183098591550
1801#  typeset iStation iProc list_opt file_in file_out prefix_invert
1802#  typeset -Z4 j4
1803#  typeset -Z3 j3
1804
1805#  unset list_opt
1806#  set +A list_opt $@
1807
1808  # Filename after rebuild
1809#  file_out=${list_opt[0]}
1810  # Prefix of output files
1811#  prefix_invert=$( basename ${file_out} .nc )
1812  # Number of procs
1813#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1814
1815#  iProc=0
1816#  while [ ${iProc} -lt ${num_proc} ] ; do
1817    # Array containing Station as a number
1818#    unset proc_stn
1819#    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}' )
1820    # Number of stations produced by processor proc
1821#    stationLast=${#proc_stn[*]}
1822    # Proc number on 4 digits
1823#    j4=${iProc}
1824    # Init
1825#    iStation=0
1826#    while [ ${iStation} -lt ${stationLast} ] ; do
1827      # Station number on 3 digits
1828#      j3=${proc_stn[${iStation}]}
1829      # Extract station
1830      # Invert Axis : t,x -> x,t
1831      #               t,pres,x -> x,t,pres
1832      # So that we can concatenate along x
1833#      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
1834#      (( iStation = iStation + 1 ))
1835#    done
1836#    (( iProc = iProc + 1 ))
1837#  done
1838
1839  # Concatenate all station along x
1840#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1841
1842  # Re-invert file
1843#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1844
1845  # END reordering
1846
1847  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1848}
1849
1850############################################################
1851# Activate Running Environnment Variables
1852
1853function IGCM_sys_activ_variables {
1854  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1855  if ( $DEBUG_sys ) ; then
1856    echo "IGCM_sys_activ_variables"
1857  fi
1858
1859  ulimit -s unlimited
1860
1861  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1862}
1863
1864############################################################
1865# Desactivate Running Environnment Variables
1866
1867function IGCM_sys_desactiv_variables {
1868  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1869  if ( $DEBUG_sys ) ; then
1870    echo "IGCM_sys_desactiv_variables"
1871  fi
1872  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1873}
1874
1875############################################################
1876# Build MPI/OMP scripts run file (dummy function)
1877
1878function IGCM_sys_build_run_file {
1879
1880IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1881
1882}
1883
1884############################################################
1885# Build MPI/OMP scripts
1886function IGCM_sys_build_execution_scripts
1887{
1888  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1889  if ( $DEBUG_sys ) ; then
1890    echo "IGCM_sys_build_execution_scripts " $@
1891  fi
1892
1893    # Verification with MSUB parameter
1894  EXECUTION=${HOST_MPIRUN_COMMAND}
1895
1896  if ( ${OK_PARA_MPMD} ) ; then
1897
1898    if [ -f run_file ] ; then
1899      IGCM_sys_Rm -f run_file
1900    fi
1901    touch run_file
1902
1903# run_file construction
1904
1905# Then first loop on the components for the coupler ie oasis
1906
1907### the coupler ie oasis must be the first one
1908    for comp in ${config_ListOfComponents[*]} ; do
1909
1910      eval ExeNameIn=\${config_Executable_${comp}[0]}
1911      eval ExeNameOut=\${config_Executable_${comp}[1]}
1912
1913        # for CPL component only
1914      if [ "X${comp}" = "XCPL" ] ; then
1915
1916        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1917        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1918        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1919      fi
1920    done
1921
1922# Then second loop on the components
1923
1924    for comp in ${config_ListOfComponents[*]} ; do
1925
1926      eval ExeNameIn=\${config_Executable_${comp}[0]}
1927      eval ExeNameOut=\${config_Executable_${comp}[1]}
1928
1929        # Only if we really have an executable for the component and not the coupler ie oasis:
1930      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1931
1932        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1933        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1934        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1935      fi
1936    done
1937
1938    EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1939
1940    IGCM_sys_Chmod u+x run_file
1941    if ( $DEBUG_sys ) ; then
1942      echo "run_file contains : "
1943      cat run_file
1944    fi
1945
1946  else # Only one executable. launch it.
1947
1948    #
1949    for comp in ${config_ListOfComponents[*]} ; do
1950
1951      # Only if we really have an executable for the component :
1952      eval ExeNameOut=\${config_Executable_${comp}[1]}
1953      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1954
1955        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1956        echo ""  >> script_${ExeNameOut}.ksh
1957        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1958
1959        if ( ${OK_PARA_OMP} ) ; then
1960          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1961          echo ""  >> script_${ExeNameOut}.ksh
1962          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1963          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1964          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1965          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1966        fi
1967
1968        if  ( ${OK_PARA_MPI} ) ; then
1969          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1970          # Default : ccc_mprun used if nb_proc gt 1
1971          # to have out/err per process on different files
1972          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
1973          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1974          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1975        else
1976          # Default : ccc_mprun is NOT used if nb_proc eq 1
1977          # to have out/err per process on different files
1978          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1979          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1980          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
1981        fi
1982
1983        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
1984        cat script_${ExeNameOut}.ksh
1985
1986      fi
1987
1988    done
1989
1990  fi
1991
1992  IGCM_debug_Print 1 "sys Curie : execution command is "
1993  IGCM_debug_Print 1 "$EXECUTION"
1994
1995  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1996}
1997
1998##############################################################
1999# NCO OPERATOR
2000
2001function IGCM_sys_ncap2 {
2002  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2003  if ( $DEBUG_sys ) ; then
2004    echo "IGCM_sys_ncap2 :" $@
2005  fi
2006
2007  typeset NB_ESSAI DELAI status i
2008  # number of tentative
2009  NB_ESSAI=3
2010  # time delay between tentative
2011  DELAI=2
2012
2013  i=0
2014  while [ $i -lt $NB_ESSAI ] ; do
2015    ncap2 "$@" > out_rsync 2>&1
2016    status=$?
2017    if [ ${status} -gt 0 ] ; then
2018      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2019      cat out_rsync
2020      \rm out_rsync
2021      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2022    else
2023      \rm out_rsync
2024      break
2025    fi
2026    (( i = i + 1 ))
2027  done
2028
2029  if [ ${status} -gt 0 ] ; then
2030      echo "IGCM_sys_ncap2 : ncap2 error"
2031      IGCM_debug_Exit "ncap2"
2032  fi
2033
2034  IGCM_debug_PopStack "IGCM_sys_ncap2"
2035}
2036
2037function IGCM_sys_ncatted {
2038  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2039  if ( $DEBUG_sys ) ; then
2040    echo "IGCM_sys_ncatted :" $@
2041  fi
2042
2043  typeset NB_ESSAI DELAI status i
2044  # number of tentative
2045  NB_ESSAI=3
2046  # time delay between tentative
2047  DELAI=2
2048
2049  i=0
2050  while [ $i -lt $NB_ESSAI ] ; do
2051    ncatted "$@" > out_rsync 2>&1
2052    status=$?
2053    if [ ${status} -gt 0 ] ; then
2054      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2055      cat out_rsync
2056      \rm out_rsync
2057      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2058    else
2059      \rm out_rsync
2060      break
2061    fi
2062    (( i = i + 1 ))
2063  done
2064
2065  if [ ${status} -gt 0 ] ; then
2066      echo "IGCM_sys_ncatted : ncatted error"
2067      IGCM_debug_Exit "ncatted"
2068  fi
2069
2070  IGCM_debug_PopStack "IGCM_sys_ncatted"
2071}
2072
2073function IGCM_sys_ncbo {
2074  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2075  if ( $DEBUG_sys ) ; then
2076    echo "IGCM_sys_ncbo :" $@
2077  fi
2078
2079  typeset NB_ESSAI DELAI status i
2080  # number of tentative
2081  NB_ESSAI=3
2082  # time delay between tentative
2083  DELAI=2
2084
2085  i=0
2086  while [ $i -lt $NB_ESSAI ] ; do
2087    ncbo $@ > out_rsync 2>&1
2088    status=$?
2089    if [ ${status} -gt 0 ] ; then
2090      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2091      cat out_rsync
2092      \rm out_rsync
2093      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2094    else
2095      \rm out_rsync
2096      break
2097    fi
2098    (( i = i + 1 ))
2099  done
2100
2101  if [ ${status} -gt 0 ] ; then
2102      echo "IGCM_sys_ncbo : ncbo error"
2103      IGCM_debug_Exit "ncbo"
2104  fi
2105
2106  IGCM_debug_PopStack "IGCM_sys_ncbo"
2107}
2108
2109function IGCM_sys_ncdiff {
2110  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2111  if ( $DEBUG_sys ) ; then
2112    echo "IGCM_sys_ncdiff :" $@
2113  fi
2114
2115  typeset NB_ESSAI DELAI status i
2116  # number of tentative
2117  NB_ESSAI=3
2118  # time delay between tentative
2119  DELAI=2
2120
2121  i=0
2122  while [ $i -lt $NB_ESSAI ] ; do
2123    ncdiff $@ > out_rsync 2>&1
2124    status=$?
2125    if [ ${status} -gt 0 ] ; then
2126      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2127      cat out_rsync
2128      \rm out_rsync
2129      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2130    else
2131      \rm out_rsync
2132      break
2133    fi
2134    (( i = i + 1 ))
2135  done
2136
2137  if [ ${status} -gt 0 ] ; then
2138      echo "IGCM_sys_ncdiff : ncdiff error"
2139      IGCM_debug_Exit "ncdiff"
2140  fi
2141
2142  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2143}
2144
2145function IGCM_sys_ncea {
2146  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2147  if ( $DEBUG_sys ) ; then
2148    echo "IGCM_sys_ncea :" $@
2149  fi
2150
2151  typeset NB_ESSAI DELAI status i
2152  # number of tentative
2153  NB_ESSAI=3
2154  # time delay between tentative
2155  DELAI=2
2156
2157  i=0
2158  while [ $i -lt $NB_ESSAI ] ; do
2159    ncea $@ > out_rsync 2>&1
2160    status=$?
2161    if [ ${status} -gt 0 ] ; then
2162      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2163      cat out_rsync
2164      \rm out_rsync
2165      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2166    else
2167      \rm out_rsync
2168      break
2169    fi
2170    (( i = i + 1 ))
2171  done
2172
2173  if [ ${status} -gt 0 ] ; then
2174      echo "IGCM_sys_ncea : ncea error"
2175      IGCM_debug_Exit "ncea"
2176  fi
2177
2178  IGCM_debug_PopStack "IGCM_sys_ncea"
2179}
2180
2181function IGCM_sys_ncecat {
2182  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2183  if ( $DEBUG_sys ) ; then
2184    echo "IGCM_sys_ncecat :" $@
2185  fi
2186
2187  typeset NB_ESSAI DELAI status i
2188  # number of tentative
2189  NB_ESSAI=3
2190  # time delay between tentative
2191  DELAI=2
2192
2193  i=0
2194  while [ $i -lt $NB_ESSAI ] ; do
2195    ncecat $@ > out_rsync 2>&1
2196    status=$?
2197    if [ ${status} -gt 0 ] ; then
2198      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2199      cat out_rsync
2200      \rm out_rsync
2201      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2202    else
2203      \rm out_rsync
2204      break
2205    fi
2206    (( i = i + 1 ))
2207  done
2208
2209  if [ ${status} -gt 0 ] ; then
2210      echo "IGCM_sys_ncecat : ncecat error"
2211      IGCM_debug_Exit "ncecat"
2212  fi
2213
2214  IGCM_debug_PopStack "IGCM_sys_ncecat"
2215}
2216
2217function IGCM_sys_ncflint {
2218  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2219  if ( $DEBUG_sys ) ; then
2220    echo "IGCM_sys_ncflint :" $@
2221  fi
2222
2223  typeset NB_ESSAI DELAI status i
2224  # number of tentative
2225  NB_ESSAI=3
2226  # time delay between tentative
2227  DELAI=2
2228
2229  i=0
2230  while [ $i -lt $NB_ESSAI ] ; do
2231    ncflint $@ > out_rsync 2>&1
2232    status=$?
2233    if [ ${status} -gt 0 ] ; then
2234      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2235      cat out_rsync
2236      \rm out_rsync
2237      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2238    else
2239      \rm out_rsync
2240      break
2241    fi
2242    (( i = i + 1 ))
2243  done
2244
2245  if [ ${status} -gt 0 ] ; then
2246      echo "IGCM_sys_ncflint : ncflint error"
2247      IGCM_debug_Exit "ncflint"
2248  fi
2249
2250  IGCM_debug_PopStack "IGCM_sys_ncflint"
2251}
2252
2253function IGCM_sys_ncks {
2254  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2255  if ( $DEBUG_sys ) ; then
2256    echo "IGCM_sys_ncks :" $@
2257  fi
2258
2259  typeset NB_ESSAI DELAI status i
2260  # number of tentative
2261  NB_ESSAI=3
2262  # time delay between tentative
2263  DELAI=2
2264
2265  i=0
2266  while [ $i -lt $NB_ESSAI ] ; do
2267    ncks $@ > out_rsync 2>&1
2268    status=$?
2269    if [ ${status} -gt 0 ] ; then
2270      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2271      cat out_rsync
2272      \rm out_rsync
2273      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2274    else
2275      \rm out_rsync
2276      break
2277    fi
2278    (( i = i + 1 ))
2279  done
2280
2281  if [ ${status} -gt 0 ] ; then
2282      echo "IGCM_sys_ncks : ncks error"
2283      IGCM_debug_Exit "ncks"
2284  fi
2285
2286  IGCM_debug_PopStack "IGCM_sys_ncks"
2287}
2288
2289function IGCM_sys_ncpdq {
2290  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2291  if ( $DEBUG_sys ) ; then
2292    echo "IGCM_sys_ncpdq :" $@
2293  fi
2294
2295  typeset NB_ESSAI DELAI status i
2296  # number of tentative
2297  NB_ESSAI=3
2298  # time delay between tentative
2299  DELAI=2
2300
2301  i=0
2302  while [ $i -lt $NB_ESSAI ] ; do
2303    ncpdq $@ > out_rsync 2>&1
2304    status=$?
2305    if [ ${status} -gt 0 ] ; then
2306      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2307      cat out_rsync
2308      \rm out_rsync
2309      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2310    else
2311      \rm out_rsync
2312      break
2313    fi
2314    (( i = i + 1 ))
2315  done
2316
2317  if [ ${status} -gt 0 ] ; then
2318      echo "IGCM_sys_ncpdq : ncpdq error"
2319      IGCM_debug_Exit "ncpdq"
2320  fi
2321
2322  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2323}
2324
2325function IGCM_sys_ncra {
2326  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2327  if ( $DEBUG_sys ) ; then
2328    echo "IGCM_sys_ncra :" $@
2329  fi
2330
2331  typeset NB_ESSAI DELAI status i
2332  # number of tentative
2333  NB_ESSAI=3
2334  # time delay between tentative
2335  DELAI=2
2336
2337  i=0
2338  while [ $i -lt $NB_ESSAI ] ; do
2339    ncra $@ > out_rsync 2>&1
2340    status=$?
2341    if [ ${status} -gt 0 ] ; then
2342      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2343      cat out_rsync
2344      \rm out_rsync
2345      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2346    else
2347      \rm out_rsync
2348      break
2349    fi
2350    (( i = i + 1 ))
2351  done
2352
2353  if [ ${status} -gt 0 ] ; then
2354      echo "IGCM_sys_ncra : ncra error"
2355      IGCM_debug_Exit "ncra"
2356  fi
2357
2358  IGCM_debug_PopStack "IGCM_sys_ncra"
2359}
2360
2361function IGCM_sys_ncrcat {
2362  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2363  if ( $DEBUG_sys ) ; then
2364    echo "IGCM_sys_ncrcat :" $@
2365  fi
2366
2367  typeset NB_ESSAI DELAI status i
2368  # number of tentative
2369  NB_ESSAI=3
2370  # time delay between tentative
2371  DELAI=2
2372
2373  i=0
2374  while [ $i -lt $NB_ESSAI ] ; do
2375    ncrcat $@ > out_rsync 2>&1
2376    status=$?
2377    if [ ${status} -gt 0 ] ; then
2378      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2379      cat out_rsync
2380      \rm out_rsync
2381      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2382    else
2383      \rm out_rsync
2384      break
2385    fi
2386    (( i = i + 1 ))
2387  done
2388
2389  if [ ${status} -gt 0 ] ; then
2390      echo "IGCM_sys_ncrcat : ncrcat error"
2391      #IGCM_debug_Exit "ncrcat"
2392  fi
2393
2394  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2395}
2396
2397function IGCM_sys_ncrename {
2398  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2399  if ( $DEBUG_sys ) ; then
2400    echo "IGCM_sys_ncrename :" $@
2401  fi
2402
2403  typeset NB_ESSAI DELAI status i
2404  # number of tentative
2405  NB_ESSAI=3
2406  # time delay between tentative
2407  DELAI=2
2408
2409  i=0
2410  while [ $i -lt $NB_ESSAI ] ; do
2411    ncrename $@ > out_rsync 2>&1
2412    status=$?
2413    if [ ${status} -gt 0 ] ; then
2414      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2415      cat out_rsync
2416      \rm out_rsync
2417      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2418    else
2419      \rm out_rsync
2420      break
2421    fi
2422    (( i = i + 1 ))
2423  done
2424
2425  if [ ${status} -gt 0 ] ; then
2426      echo "IGCM_sys_ncrename : ncrename error"
2427      IGCM_debug_Exit "ncrename"
2428  fi
2429
2430  IGCM_debug_PopStack "IGCM_sys_ncrename"
2431}
2432
2433function IGCM_sys_ncwa {
2434  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2435  if ( $DEBUG_sys ) ; then
2436    echo "IGCM_sys_ncwa :" $@
2437  fi
2438
2439  typeset NB_ESSAI DELAI status i
2440  # number of tentative
2441  NB_ESSAI=3
2442  # time delay between tentative
2443  DELAI=2
2444
2445  i=0
2446  while [ $i -lt $NB_ESSAI ] ; do
2447    ncwa $@ > out_rsync 2>&1
2448    status=$?
2449    if [ ${status} -gt 0 ] ; then
2450      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2451      cat out_rsync
2452      \rm out_rsync
2453      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2454    else
2455      \rm out_rsync
2456      break
2457    fi
2458    (( i = i + 1 ))
2459  done
2460
2461  if [ ${status} -gt 0 ] ; then
2462      echo "IGCM_sys_ncwa : ncwa error"
2463      IGCM_debug_Exit "ncwa"
2464  fi
2465
2466  IGCM_debug_PopStack "IGCM_sys_ncwa"
2467}
2468
2469##############################################################
2470# CDO OPERATOR
2471
2472function IGCM_sys_cdo {
2473  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2474  if ( $DEBUG_sys ) ; then
2475    echo "IGCM_sys_cdo :" $@
2476  fi
2477
2478  typeset status
2479
2480  \cdo $@ > out_rsync 2>&1
2481  status=$?
2482  if [ ${status} -gt 0 ] ; then
2483    echo "IGCM_sys_cdo : error code ${status}"
2484    cat out_rsync
2485    \rm out_rsync
2486    IGCM_debug_PopStack "IGCM_sys_cdo"
2487    return 1
2488  else
2489    IGCM_debug_PopStack "IGCM_sys_cdo"
2490    return 0
2491  fi
2492
2493  IGCM_debug_PopStack "IGCM_sys_cdo"
2494}
2495
2496############################################################
2497# Check of space available on temporary filesytems
2498function IGCM_sys_check_quota {
2499    IGCM_debug_PushStack "IGCM_sys_check_quota"
2500    if ( $DEBUG_sys ) ; then
2501        echo "IGCM_sys_check_quota"
2502    fi
2503    IGCM_debug_PopStack "IGCM_sys_check_quota"
2504}
Note: See TracBrowser for help on using the repository browser.