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

Last change on this file since 837 was 835, checked in by labetoulle, 11 years ago

Runchecker : add rsh access for monitoring files on Ada. See #128.

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