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

Last change on this file since 828 was 828, checked in by sdipsl, 11 years ago
  • Stack file management must be kept in libIGCM_debug
  • Property svn:keywords set to Revision Author Date
File size: 81.7 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_Dods_Rm
1697#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1698#D-* Examples:
1699#D-
1700function IGCM_sys_Dods_Rm {
1701  if ( $DEBUG_sys ) ; then
1702    echo "IGCM_sys_Dods_Rm :" $@
1703  fi
1704  typeset status
1705  if [ $DRYRUN = 0 ]; then
1706
1707#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1708#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1709#      echo "Nothing has been done."
1710#      return
1711#    fi
1712
1713    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1714    status=$?
1715
1716#    if [ ${status} -gt 0 ] ; then
1717#      echo "IGCM_sys_Dods_Rm : error."
1718#      cat out_dods_rm
1719#      IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1720#    else
1721#      rm out_dods_rm
1722#    fi
1723
1724  fi
1725  return $status
1726}
1727
1728#D-#==================================================
1729#D-function IGCM_sys_Dods_Cp
1730#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1731#D-* Examples:
1732#D-
1733function IGCM_sys_Dods_Cp {
1734  if ( $DEBUG_sys ) ; then
1735    echo "IGCM_sys_Dods_Cp :" $@
1736  fi
1737  typeset status
1738  if [ $DRYRUN = 0 ]; then
1739
1740#    if [ ! -d ${R_SAVE}/${1} ] ; then
1741#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1742#      echo "Nothing has been done."
1743#      return
1744#    fi
1745
1746    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1747    status=$?
1748
1749#       if [ ${status} -gt 0 ] ; then
1750#           echo "IGCM_sys_Dods_Cp : error."
1751#           cat out_dods_cp
1752#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1753#       else
1754#           rm out_dods_cp
1755#       fi
1756
1757  fi
1758  return $status
1759}
1760
1761#D-#==================================================
1762#D-function IGCM_sys_Put_Dods
1763#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1764#D-* Examples:
1765#D-
1766function IGCM_sys_Put_Dods {
1767  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1768  if ( $DEBUG_sys ) ; then
1769    echo "IGCM_sys_Put_Dods :" $@
1770  fi
1771  #set -vx
1772  typeset status
1773  if [ $DRYRUN = 0 ]; then
1774    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1775      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1776      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1777      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1778      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1779      return
1780    fi
1781
1782    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1783      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1784      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1785      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1786      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1787      return
1788    fi
1789    #
1790    if [ -d ${R_SAVE}/${1} ] ; then
1791      cd ${R_SAVE}
1792    elif [ -d ${R_FIGR}/${1} ] ; then
1793      cd ${R_FIGR}
1794    fi
1795
1796    IGCM_sys_Dods_Rm ${1}
1797    IGCM_sys_Dods_Cp ${1}
1798    status=0
1799
1800    if [ ${status} -gt 0 ] ; then
1801      echo "IGCM_sys_Put_Dods : error."
1802      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1803    fi
1804  fi
1805  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1806}
1807
1808##############################################################
1809# REBUILD OPERATOR
1810
1811#D-#==================================================
1812#D-function IGCM_sys_rebuild
1813#D-* Purpose: rebuild parallel files
1814#D-* Examples:
1815#D-
1816function IGCM_sys_rebuild {
1817  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1818  if ( $DEBUG_sys ) ; then
1819    echo "IGCM_sys_rebuild :" $@
1820  fi
1821
1822  typeset NB_ESSAI DELAI status i firstArg
1823  # number of tentative
1824  NB_ESSAI=3
1825  # time delay between tentative
1826  DELAI=2
1827
1828  i=0
1829  while [ $i -lt $NB_ESSAI ] ; do
1830    ~p86ipsl/CESIUM/bin/rebuild -f -o $@ > out_rsync 2>&1
1831    status=$?
1832    if [ ${status} -gt 0 ] ; then
1833      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1834      cat out_rsync
1835      \rm out_rsync
1836      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1837      firstArg=${1}
1838      \rm ${firstArg}
1839      sleep $DELAI
1840    else
1841      \rm out_rsync
1842      break
1843    fi
1844    (( i = i + 1 ))
1845  done
1846
1847  if [ ${status} -gt 0 ] ; then
1848    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1849    IGCM_debug_Exit "rebuild"
1850  fi
1851
1852  IGCM_debug_PopStack "IGCM_sys_rebuild"
1853}
1854
1855#D-#==================================================
1856#D-function IGCM_sys_rebuild_station
1857#D-* Purpose: rebuild parallel files describing station
1858#D-* Examples:
1859#D-
1860function IGCM_sys_rebuild_station {
1861  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1862  typeset i list_opt file_in file_out prefix_invert list_invert
1863  if ( $DEBUG_sys ) ; then
1864    echo "IGCM_sys_rebuild_station :" $@
1865  fi
1866  list_opt=$@
1867
1868  # Invert Axis : t,x -> x,t
1869  #               t,pres,x -> x,t,pres
1870  # So that we can concatenate along x
1871  i=0
1872  for file_in in ${list_opt} ; do
1873    (( i = i + 1))
1874    [ ${i} = 1 ] && file_out=${file_in} && continue
1875    prefix_invert=$( basename ${file_in} .nc )
1876    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1877    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1878  done
1879
1880  # Concatenate
1881  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1882
1883  # Re-ivert file
1884  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1885
1886  # Station re-ordering is too expansive to be run within libICGM
1887  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1888  # This re-ordering must be done "in memory" by the cmorization process
1889  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1890  # BEGIN reordering
1891
1892  # Only LMDZ text output contains the exact ordering of the station.
1893  # We isolate this in the code below:
1894  #  0  38  -157.5000000000000  70.98591549295774
1895  #  0  54  27.49999999999999   67.18309859154928
1896  #  0  56  -62.50000000000001  82.39436619718309
1897  #  0  79  12.49999999999999   78.59154929577466
1898  #  0  116 -165.0000000000000  76.05633802816901
1899  #  0  117 130.0000000000000   70.98591549295774
1900  #  0  118 110.0000000000000   87.46478873239437
1901  #  1  40  4.999999999999995   51.97183098591550
1902#  typeset iStation iProc list_opt file_in file_out prefix_invert
1903#  typeset -Z4 j4
1904#  typeset -Z3 j3
1905
1906#  unset list_opt
1907#  set +A list_opt $@
1908
1909  # Filename after rebuild
1910#  file_out=${list_opt[0]}
1911  # Prefix of output files
1912#  prefix_invert=$( basename ${file_out} .nc )
1913  # Number of procs
1914#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1915
1916#  iProc=0
1917#  while [ ${iProc} -lt ${num_proc} ] ; do
1918    # Array containing Station as a number
1919#    unset proc_stn
1920#    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}' )
1921    # Number of stations produced by processor proc
1922#    stationLast=${#proc_stn[*]}
1923    # Proc number on 4 digits
1924#    j4=${iProc}
1925    # Init
1926#    iStation=0
1927#    while [ ${iStation} -lt ${stationLast} ] ; do
1928      # Station number on 3 digits
1929#      j3=${proc_stn[${iStation}]}
1930      # Extract station
1931      # Invert Axis : t,x -> x,t
1932      #               t,pres,x -> x,t,pres
1933      # So that we can concatenate along x
1934#      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
1935#      (( iStation = iStation + 1 ))
1936#    done
1937#    (( iProc = iProc + 1 ))
1938#  done
1939
1940  # Concatenate all station along x
1941#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1942
1943  # Re-invert file
1944#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1945
1946  # END reordering
1947
1948  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1949}
1950
1951############################################################
1952# Activate Running Environnment Variables
1953
1954#D-#==================================================
1955#D-function IGCM_sys_desactiv_variables
1956#D-* Purpose: set environement variables prior to execution
1957#D-* Examples:
1958#D-
1959function IGCM_sys_activ_variables {
1960  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1961  if ( $DEBUG_sys ) ; then
1962    echo "IGCM_sys_activ_variables"
1963  fi
1964
1965# --------------------------------------------------------------------
1966#D- MPI specifications
1967# --------------------------------------------------------------------
1968
1969# --------------------------------------------------------------------
1970#D- Other specifications
1971# --------------------------------------------------------------------
1972
1973  ulimit -s unlimited
1974
1975  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1976}
1977
1978############################################################
1979# Desactivate Running Environnment Variables
1980
1981#D-#==================================================
1982#D-function IGCM_sys_desactiv_variables
1983#D-* Purpose: unset environement variables after execution
1984#D-* Examples:
1985#D-
1986function IGCM_sys_desactiv_variables {
1987  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1988  if ( $DEBUG_sys ) ; then
1989    echo "IGCM_sys_desactiv_variables"
1990  fi
1991# --------------------------------------------------------------------
1992#D- MPI specifications
1993# --------------------------------------------------------------------
1994
1995# --------------------------------------------------------------------
1996#D- Other specifications
1997# --------------------------------------------------------------------
1998
1999  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
2000}
2001
2002############################################################
2003# Build MPI/OMP scripts run file (dummy function)
2004
2005#D-#==================================================
2006#D-function IGCM_sys_build_run_file
2007#D-* Purpose: build run file (deprecated)
2008#D-* Examples:
2009#D-
2010function IGCM_sys_build_run_file {
2011
2012  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
2013
2014}
2015
2016############################################################
2017# Build MPI/OMP scripts
2018
2019#D-#==================================================
2020#D-function IGCM_sys_build_execution_scripts
2021#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
2022#D-* Examples:
2023#D-
2024function IGCM_sys_build_execution_scripts
2025{
2026  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
2027  if ( $DEBUG_sys ) ; then
2028    echo "IGCM_sys_build_execution_scripts " $@
2029  fi
2030
2031  EXECUTION=${HOST_MPIRUN_COMMAND}
2032
2033  if ( ${OK_PARA_MPMD} ) ; then
2034
2035    if [ -f run_file ] ; then
2036      IGCM_sys_Rm -f run_file
2037    fi
2038    touch run_file
2039
2040# run_file construction
2041
2042# Then first loop on the components for the coupler ie oasis
2043
2044## the coupler ie oasis must be the first one
2045    for comp in ${config_ListOfComponents[*]} ; do
2046
2047      eval ExeNameIn=\${config_Executable_${comp}[0]}
2048      eval ExeNameOut=\${config_Executable_${comp}[1]}
2049
2050      # for CPL component only
2051      if [ "X${comp}" = "XCPL" ] ; then
2052
2053        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2054        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2055        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2056      fi
2057    done
2058
2059# Then second loop on the components
2060
2061    for comp in ${config_ListOfComponents[*]} ; do
2062
2063      eval ExeNameIn=\${config_Executable_${comp}[0]}
2064      eval ExeNameOut=\${config_Executable_${comp}[1]}
2065
2066      # Only if we really have an executable for the component and not the coupler ie oasis:
2067      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "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    EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
2076
2077    IGCM_sys_Chmod u+x run_file
2078    if ( $DEBUG_sys ) ; then
2079      echo "run_file contains : "
2080      cat run_file
2081    fi
2082
2083  else # Only one executable. launch it.
2084
2085    for comp in ${config_ListOfComponents[*]} ; do
2086
2087      # Only if we really have an executable for the component :
2088      eval ExeNameOut=\${config_Executable_${comp}[1]}
2089      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2090
2091        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2092        echo ""  >> script_${ExeNameOut}.ksh
2093        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2094
2095        if ( ${OK_PARA_OMP} ) ; then
2096          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2097          echo ""  >> script_${ExeNameOut}.ksh
2098          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2099          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2100          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2101          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
2102        fi
2103
2104        if  ( ${OK_PARA_MPI} ) ; then
2105          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2106          # Default : ccc_mprun used if nb_proc gt 1
2107          # to have out/err per process on different files
2108          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
2109          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2110          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
2111        else
2112          # Default : ccc_mprun is NOT used if nb_proc eq 1
2113          # to have out/err per process on different files
2114          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
2115          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2116          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
2117        fi
2118
2119        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
2120        cat script_${ExeNameOut}.ksh
2121
2122      fi
2123
2124    done
2125
2126  fi
2127
2128  IGCM_debug_Print 1 "sys Curie : execution command is "
2129  IGCM_debug_Print 1 "$EXECUTION"
2130
2131  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2132}
2133
2134############################################################
2135# Check of space available on temporary filesytems.
2136
2137#D-#==================================================
2138#D-function IGCM_sys_check_quota
2139#D-* Purpose: check user quota. Stop the simulation if quota above 90%
2140#D-* Examples:
2141#D-
2142function IGCM_sys_check_quota {
2143  IGCM_debug_PushStack "IGCM_sys_check_quota"
2144  if ( $DEBUG_sys ) ; then
2145    echo "IGCM_sys_check_quota"
2146  fi
2147  # Limit of quota (in %)
2148  limit_quota=90
2149
2150  # Check of the volume
2151  volume_quota=$(ccc_quota | grep ' scratch' | awk '{print $2}')
2152  volume_avail=$(ccc_quota | grep ' scratch' | awk '{print $3}')
2153
2154  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
2155
2156    unit_avail=${volume_avail: -1}
2157    unit_quota=${volume_quota: -1}
2158
2159    if [ "${unit_quota}" = "*" ] ; then
2160      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2161      IGCM_debug_Print 1 "More than 100% of your quota is used"
2162      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2163      IGCM_debug_Print 1 "You must have more than 10% available to run"
2164      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2165      IGCM_debug_Verif_Exit
2166    fi
2167
2168    temp_avail=${volume_avail%%${volume_avail: -1}*}
2169    temp_quota=${volume_quota%%${volume_quota: -1}*}
2170
2171    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2172
2173    # Convertion
2174      if [ ${volume_avail: -1} = "T" ] ; then
2175        (( temp_avail = temp_avail * 1000000000000 ))
2176      elif [ ${volume_avail: -1} = "G" ] ; then
2177        (( temp_avail = temp_avail * 1000000000 ))
2178      elif [ ${volume_avail: -1} = "M" ] ; then
2179        (( temp_avail = temp_avail * 1000000 ))
2180      elif [ ${volume_avail: -1} = "k" ] ; then
2181        (( temp_avail = temp_avail * 1000 ))
2182      else
2183        (( temp_avail = volume_avail ))
2184      fi
2185      if [ ${volume_quota: -1} = "T" ] ; then
2186        (( temp_quota = temp_quota * 1000000000000 ))
2187      elif [ ${volume_quota: -1} = "G" ] ; then
2188        (( temp_quota = temp_quota * 1000000000 ))
2189      elif [ ${volume_quota: -1} = "M" ] ; then
2190        (( temp_quota = temp_quota * 1000000 ))
2191      elif [ ${volume_quota: -1} = "k" ] ; then
2192        (( temp_quota = temp_quota * 1000 ))
2193      else
2194        (( temp_quota = volume_quota ))
2195      fi
2196    fi
2197
2198    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2199#    echo "volume ratio is " $quota_volume
2200
2201    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2202      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2203      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2204      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2205      IGCM_debug_Print 1 "You must have more than 10% available to run"
2206      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2207      IGCM_debug_Verif_Exit
2208    fi
2209
2210  fi
2211
2212# Check of the number of inodes
2213
2214  inode_quota=$(ccc_quota | grep ' scratch' | awk '{print $6}')
2215  inode_avail=$(ccc_quota | grep ' scratch' | awk '{print $7}')
2216
2217  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
2218
2219    unit_avail=${inode_avail: -1}
2220    unit_quota=${inode_quota: -1}
2221
2222    if [ "${unit_quota}" = "*" ] ; then
2223      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2224      IGCM_debug_Print 1 "More than 100% of your quota is used"
2225      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2226      IGCM_debug_Print 1 "You must have more than 10% available to run"
2227      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2228      IGCM_debug_Verif_Exit
2229    fi
2230
2231    temp_avail=${inode_avail%%${inode_avail: -1}*}
2232    temp_quota=${inode_quota%%${inode_quota: -1}*}
2233
2234    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2235
2236    # Convertion
2237      if [ ${inode_avail: -1} = "T" ] ; then
2238        (( temp_avail = temp_avail * 1000000000000 ))
2239      elif [ ${inode_avail: -1} = "G" ] ; then
2240        (( temp_avail = temp_avail * 1000000000 ))
2241      elif [ ${inode_avail: -1} = "M" ] ; then
2242        (( temp_avail = temp_avail * 1000000 ))
2243      elif [ ${inode_avail: -1} = "k" ] ; then
2244        (( temp_avail = temp_avail * 1000 ))
2245      else
2246        (( temp_avail = inode_avail ))
2247      fi
2248
2249      if [ ${inode_quota: -1} = "T" ] ; then
2250        (( temp_quota = temp_quota * 1000000000000 ))
2251      elif [ ${inode_quota: -1} = "G" ] ; then
2252        (( temp_quota = temp_quota * 1000000000 ))
2253      elif [ ${inode_quota: -1} = "M" ] ; then
2254        (( temp_quota = temp_quota * 1000000 ))
2255      elif [ ${inode_quota: -1} = "k" ] ; then
2256        (( temp_quota = temp_quota * 1000 ))
2257      else
2258        (( temp_quota = inode_quota ))
2259      fi
2260    fi
2261    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2262#    echo "inode ratio is " $quota_inode
2263
2264    if [ ${quota_inode} -ge ${limit_quota} ] ; then
2265      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2266      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
2267      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2268      IGCM_debug_Print 1 "You must have more than 10% available to run"
2269      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2270      IGCM_debug_Verif_Exit
2271    fi
2272  fi
2273  IGCM_debug_PopStack "IGCM_sys_check_quota"
2274}
2275
2276#D-#==================================================
2277#D-function IGCM_sys_CountJobInQueue
2278#D-* Purpose: Check if job_name is currently
2279#D-  running or in queue
2280#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
2281#D-
2282function IGCM_sys_CountJobInQueue {
2283  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
2284  if ( $DEBUG_sys ) ; then
2285    echo "IGCM_sys_CountJobInQueue"
2286  fi
2287
2288  #NbRun=$( ccc_mstat -f | grep -c ${JobName} )
2289
2290  # With -f option, the full job name is given in the last column
2291  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ($NF~String) { x=x+1 } END { print x }' )
2292
2293  eval ${2}=${NbRun}
2294
2295  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
2296}
2297
2298##############################################################
2299# NCO OPERATOR
2300
2301#D-#==================================================
2302#D-function IGCM_sys_ncap2
2303#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2304#D-* Examples:
2305#D-
2306function IGCM_sys_ncap2 {
2307  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2308  if ( $DEBUG_sys ) ; then
2309    echo "IGCM_sys_ncap2 :" $@
2310  fi
2311
2312  typeset NB_ESSAI DELAI status i
2313  # number of tentative
2314  NB_ESSAI=3
2315  # time delay between tentative
2316  DELAI=2
2317
2318  i=0
2319  while [ $i -lt $NB_ESSAI ] ; do
2320    ncap2 "$@" > out_rsync 2>&1
2321    status=$?
2322    if [ ${status} -gt 0 ] ; then
2323      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2324      cat out_rsync
2325      \rm out_rsync
2326      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2327      sleep $DELAI
2328    else
2329      \rm out_rsync
2330      break
2331    fi
2332    (( i = i + 1 ))
2333  done
2334
2335  if [ ${status} -gt 0 ] ; then
2336    echo "IGCM_sys_ncap2 : ncap2 error"
2337    IGCM_debug_Exit "ncap2"
2338  fi
2339
2340  IGCM_debug_PopStack "IGCM_sys_ncap2"
2341}
2342
2343#D-#==================================================
2344#D-function IGCM_sys_ncatted
2345#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2346#D-* Examples:
2347#D-
2348function IGCM_sys_ncatted {
2349  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2350  if ( $DEBUG_sys ) ; then
2351    echo "IGCM_sys_ncatted :" $@
2352  fi
2353
2354  typeset NB_ESSAI DELAI status i
2355  # number of tentative
2356  NB_ESSAI=3
2357  # time delay between tentative
2358  DELAI=2
2359
2360  i=0
2361  while [ $i -lt $NB_ESSAI ] ; do
2362    ncatted "$@" > out_rsync 2>&1
2363    status=$?
2364    if [ ${status} -gt 0 ] ; then
2365      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2366      cat out_rsync
2367      \rm out_rsync
2368      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2369      sleep $DELAI
2370    else
2371      \rm out_rsync
2372      break
2373    fi
2374    (( i = i + 1 ))
2375  done
2376
2377  if [ ${status} -gt 0 ] ; then
2378    echo "IGCM_sys_ncatted : ncatted error"
2379    IGCM_debug_Exit "ncatted"
2380  fi
2381
2382  IGCM_debug_PopStack "IGCM_sys_ncatted"
2383}
2384
2385#D-#==================================================
2386#D-function IGCM_sys_ncbo
2387#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2388#D-* Examples:
2389#D-
2390function IGCM_sys_ncbo {
2391  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2392  if ( $DEBUG_sys ) ; then
2393    echo "IGCM_sys_ncbo :" $@
2394  fi
2395
2396  typeset NB_ESSAI DELAI status i
2397  # number of tentative
2398  NB_ESSAI=3
2399  # time delay between tentative
2400  DELAI=2
2401
2402  i=0
2403  while [ $i -lt $NB_ESSAI ] ; do
2404    ncbo $@ > out_rsync 2>&1
2405    status=$?
2406    if [ ${status} -gt 0 ] ; then
2407      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2408      cat out_rsync
2409      \rm out_rsync
2410      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2411      sleep $DELAI
2412    else
2413      \rm out_rsync
2414      break
2415    fi
2416    (( i = i + 1 ))
2417  done
2418
2419  if [ ${status} -gt 0 ] ; then
2420    echo "IGCM_sys_ncbo : ncbo error"
2421    IGCM_debug_Exit "ncbo"
2422  fi
2423
2424  IGCM_debug_PopStack "IGCM_sys_ncbo"
2425}
2426
2427#D-#==================================================
2428#D-function IGCM_sys_ncdif
2429#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2430#D-* Examples:
2431#D-
2432function IGCM_sys_ncdiff {
2433  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2434  if ( $DEBUG_sys ) ; then
2435    echo "IGCM_sys_ncdiff :" $@
2436  fi
2437
2438  typeset NB_ESSAI DELAI status i
2439  # number of tentative
2440  NB_ESSAI=3
2441  # time delay between tentative
2442  DELAI=2
2443
2444  i=0
2445  while [ $i -lt $NB_ESSAI ] ; do
2446    ncdiff $@ > out_rsync 2>&1
2447    status=$?
2448    if [ ${status} -gt 0 ] ; then
2449      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2450      cat out_rsync
2451      \rm out_rsync
2452      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2453      sleep $DELAI
2454    else
2455      \rm out_rsync
2456      break
2457    fi
2458    (( i = i + 1 ))
2459  done
2460
2461  if [ ${status} -gt 0 ] ; then
2462    echo "IGCM_sys_ncdiff : ncdiff error"
2463    IGCM_debug_Exit "ncdiff"
2464  fi
2465
2466  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2467}
2468
2469#D-#==================================================
2470#D-function IGCM_sys_ncea
2471#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2472#D-* Examples:
2473#D-
2474function IGCM_sys_ncea {
2475  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2476  if ( $DEBUG_sys ) ; then
2477    echo "IGCM_sys_ncea :" $@
2478  fi
2479
2480  typeset NB_ESSAI DELAI status i
2481  # number of tentative
2482  NB_ESSAI=3
2483  # time delay between tentative
2484  DELAI=2
2485
2486  i=0
2487  while [ $i -lt $NB_ESSAI ] ; do
2488    ncea $@ > out_rsync 2>&1
2489    status=$?
2490    if [ ${status} -gt 0 ] ; then
2491      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2492      cat out_rsync
2493      \rm out_rsync
2494      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2495      sleep $DELAI
2496    else
2497      \rm out_rsync
2498      break
2499    fi
2500    (( i = i + 1 ))
2501  done
2502
2503  if [ ${status} -gt 0 ] ; then
2504    echo "IGCM_sys_ncea : ncea error"
2505    IGCM_debug_Exit "ncea"
2506  fi
2507
2508  IGCM_debug_PopStack "IGCM_sys_ncea"
2509}
2510
2511#D-#==================================================
2512#D-function IGCM_sys_ncecat
2513#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2514#D-* Examples:
2515#D-
2516function IGCM_sys_ncecat {
2517  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2518  if ( $DEBUG_sys ) ; then
2519    echo "IGCM_sys_ncecat :" $@
2520  fi
2521
2522  typeset NB_ESSAI DELAI status i
2523  # number of tentative
2524  NB_ESSAI=3
2525  # time delay between tentative
2526  DELAI=2
2527
2528  i=0
2529  while [ $i -lt $NB_ESSAI ] ; do
2530    ncecat $@ > out_rsync 2>&1
2531    status=$?
2532    if [ ${status} -gt 0 ] ; then
2533      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2534      cat out_rsync
2535      \rm out_rsync
2536      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2537      sleep $DELAI
2538    else
2539      \rm out_rsync
2540      break
2541    fi
2542    (( i = i + 1 ))
2543  done
2544
2545  if [ ${status} -gt 0 ] ; then
2546    echo "IGCM_sys_ncecat : ncecat error"
2547    IGCM_debug_Exit "ncecat"
2548  fi
2549
2550  IGCM_debug_PopStack "IGCM_sys_ncecat"
2551}
2552
2553#D-#==================================================
2554#D-function IGCM_sys_ncflint
2555#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2556#D-* Examples:
2557#D-
2558function IGCM_sys_ncflint {
2559  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2560  if ( $DEBUG_sys ) ; then
2561    echo "IGCM_sys_ncflint :" $@
2562  fi
2563
2564  typeset NB_ESSAI DELAI status i
2565  # number of tentative
2566  NB_ESSAI=3
2567  # time delay between tentative
2568  DELAI=2
2569
2570  i=0
2571  while [ $i -lt $NB_ESSAI ] ; do
2572    ncflint $@ > out_rsync 2>&1
2573    status=$?
2574    if [ ${status} -gt 0 ] ; then
2575      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2576      cat out_rsync
2577      \rm out_rsync
2578      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2579      sleep $DELAI
2580    else
2581      \rm out_rsync
2582      break
2583    fi
2584    (( i = i + 1 ))
2585  done
2586
2587  if [ ${status} -gt 0 ] ; then
2588    echo "IGCM_sys_ncflint : ncflint error"
2589    IGCM_debug_Exit "ncflint"
2590  fi
2591
2592  IGCM_debug_PopStack "IGCM_sys_ncflint"
2593}
2594
2595#D-#==================================================
2596#D-function IGCM_sys_ncks
2597#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2598#D-* Examples:
2599#D-
2600function IGCM_sys_ncks {
2601  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2602  if ( $DEBUG_sys ) ; then
2603    echo "IGCM_sys_ncks :" $@
2604  fi
2605
2606  typeset NB_ESSAI DELAI status i
2607  # number of tentative
2608  NB_ESSAI=3
2609  # time delay between tentative
2610  DELAI=2
2611
2612  i=0
2613  while [ $i -lt $NB_ESSAI ] ; do
2614    ncks $@ > out_rsync 2>&1
2615    status=$?
2616    if [ ${status} -gt 0 ] ; then
2617      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2618      cat out_rsync
2619      \rm out_rsync
2620      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2621      sleep $DELAI
2622    else
2623      \rm out_rsync
2624      break
2625    fi
2626    (( i = i + 1 ))
2627  done
2628
2629  if [ ${status} -gt 0 ] ; then
2630    echo "IGCM_sys_ncks : ncks error"
2631    IGCM_debug_Exit "ncks"
2632  fi
2633
2634  IGCM_debug_PopStack "IGCM_sys_ncks"
2635}
2636
2637#D-#==================================================
2638#D-function IGCM_sys_ncpdq
2639#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2640#D-* Examples:
2641#D-
2642function IGCM_sys_ncpdq {
2643  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2644  if ( $DEBUG_sys ) ; then
2645    echo "IGCM_sys_ncpdq :" $@
2646  fi
2647
2648  typeset NB_ESSAI DELAI status i
2649  # number of tentative
2650  NB_ESSAI=3
2651  # time delay between tentative
2652  DELAI=2
2653
2654  i=0
2655  while [ $i -lt $NB_ESSAI ] ; do
2656    ncpdq $@ > out_rsync 2>&1
2657    status=$?
2658    if [ ${status} -gt 0 ] ; then
2659      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2660      cat out_rsync
2661      \rm out_rsync
2662      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2663      sleep $DELAI
2664    else
2665      \rm out_rsync
2666      break
2667    fi
2668    (( i = i + 1 ))
2669  done
2670
2671  if [ ${status} -gt 0 ] ; then
2672    echo "IGCM_sys_ncpdq : ncpdq error"
2673    IGCM_debug_Exit "ncpdq"
2674  fi
2675
2676  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2677}
2678
2679#D-#==================================================
2680#D-function IGCM_sys_ncra
2681#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2682#D-* Examples:
2683#D-
2684function IGCM_sys_ncra {
2685  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2686  if ( $DEBUG_sys ) ; then
2687    echo "IGCM_sys_ncra :" $@
2688  fi
2689
2690  typeset NB_ESSAI DELAI status i
2691  # number of tentative
2692  NB_ESSAI=3
2693  # time delay between tentative
2694  DELAI=2
2695
2696  i=0
2697  while [ $i -lt $NB_ESSAI ] ; do
2698    ncra $@ > out_rsync 2>&1
2699    status=$?
2700    if [ ${status} -gt 0 ] ; then
2701      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2702      cat out_rsync
2703      \rm out_rsync
2704      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2705      sleep $DELAI
2706    else
2707      \rm out_rsync
2708      break
2709    fi
2710    (( i = i + 1 ))
2711  done
2712
2713  if [ ${status} -gt 0 ] ; then
2714    echo "IGCM_sys_ncra : ncra error"
2715    IGCM_debug_Exit "ncra"
2716  fi
2717
2718  IGCM_debug_PopStack "IGCM_sys_ncra"
2719}
2720
2721#D-#==================================================
2722#D-function IGCM_sys_ncrcat
2723#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2724#D-* Examples:
2725#D-
2726function IGCM_sys_ncrcat {
2727  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2728  if ( $DEBUG_sys ) ; then
2729    echo "IGCM_sys_ncrcat :" $@
2730  fi
2731
2732  typeset NB_ESSAI DELAI status i lastArg
2733  # number of tentative
2734  NB_ESSAI=3
2735  # time delay between tentative
2736  DELAI=2
2737
2738  i=0
2739  while [ $i -lt $NB_ESSAI ] ; do
2740    ncrcat $@ > out_rsync 2>&1
2741    status=$?
2742    if [ ${status} -gt 0 ] ; then
2743      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2744      cat out_rsync
2745      \rm out_rsync
2746      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2747      sleep $DELAI
2748    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2749      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2750      cat out_rsync
2751      # remove files having corrupted time axis
2752      eval lastArg=\${$#}
2753      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2754      \rm ${lastArg}
2755      \rm out_rsync
2756      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2757      sleep $DELAI
2758    else
2759      \rm out_rsync
2760      break
2761    fi
2762    (( i = i + 1 ))
2763  done
2764
2765  if [ ${status} -gt 0 ] ; then
2766    echo "IGCM_sys_ncrcat : ncrcat error"
2767    #IGCM_debug_Exit "ncrcat"
2768  fi
2769
2770  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2771}
2772
2773#D-#==================================================
2774#D-function IGCM_sys_ncrename
2775#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2776#D-* Examples:
2777#D-
2778function IGCM_sys_ncrename {
2779  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2780  if ( $DEBUG_sys ) ; then
2781    echo "IGCM_sys_ncrename :" $@
2782  fi
2783
2784  typeset NB_ESSAI DELAI status i
2785  # number of tentative
2786  NB_ESSAI=3
2787  # time delay between tentative
2788  DELAI=2
2789
2790  i=0
2791  while [ $i -lt $NB_ESSAI ] ; do
2792    ncrename $@ > out_rsync 2>&1
2793    status=$?
2794    if [ ${status} -gt 0 ] ; then
2795      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2796      cat out_rsync
2797      \rm out_rsync
2798      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2799      sleep $DELAI
2800    else
2801      \rm out_rsync
2802      break
2803    fi
2804    (( i = i + 1 ))
2805  done
2806
2807  if [ ${status} -gt 0 ] ; then
2808    echo "IGCM_sys_ncrename : ncrename error"
2809    IGCM_debug_Exit "ncrename"
2810  fi
2811
2812  IGCM_debug_PopStack "IGCM_sys_ncrename"
2813}
2814
2815#D-#==================================================
2816#D-function IGCM_sys_ncwa
2817#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2818#D-* Examples:
2819#D-
2820function IGCM_sys_ncwa {
2821  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2822  if ( $DEBUG_sys ) ; then
2823    echo "IGCM_sys_ncwa :" $@
2824  fi
2825
2826  typeset NB_ESSAI DELAI status i
2827  # number of tentative
2828  NB_ESSAI=3
2829  # time delay between tentative
2830  DELAI=2
2831
2832  i=0
2833  while [ $i -lt $NB_ESSAI ] ; do
2834    ncwa $@ > out_rsync 2>&1
2835    status=$?
2836    if [ ${status} -gt 0 ] ; then
2837      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2838      cat out_rsync
2839      \rm out_rsync
2840      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2841      sleep $DELAI
2842    else
2843      \rm out_rsync
2844      break
2845    fi
2846    (( i = i + 1 ))
2847  done
2848
2849  if [ ${status} -gt 0 ] ; then
2850    echo "IGCM_sys_ncwa : ncwa error"
2851    IGCM_debug_Exit "ncwa"
2852  fi
2853
2854  IGCM_debug_PopStack "IGCM_sys_ncwa"
2855}
2856
2857##############################################################
2858# CDO OPERATOR
2859
2860#D-#==================================================
2861#D-function IGCM_sys_cdo
2862#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2863#D-* Examples:
2864#D-
2865function IGCM_sys_cdo {
2866  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2867  if ( $DEBUG_sys ) ; then
2868    echo "IGCM_sys_cdo :" $@
2869  fi
2870
2871  typeset status
2872
2873  \cdo $@ > out_rsync 2>&1
2874  status=$?
2875  if [ ${status} -gt 0 ] ; then
2876    echo "IGCM_sys_cdo : error code ${status}"
2877    cat out_rsync
2878    \rm out_rsync
2879    IGCM_debug_PopStack "IGCM_sys_cdo"
2880    return 1
2881  else
2882    IGCM_debug_PopStack "IGCM_sys_cdo"
2883    return 0
2884  fi
2885
2886  IGCM_debug_PopStack "IGCM_sys_cdo"
2887}
Note: See TracBrowser for help on using the repository browser.