source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh @ 920

Last change on this file since 920 was 918, checked in by sdipsl, 11 years ago

Active instrumentation #140 disturbs this kind of call
TarFileLocation?=$( IGCM_sys_PrepareTaredRestart ${TarFileFound?} )

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