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

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

Add function IGCM_sys_RshArchive_NoError to be used in monitoring.job.
See #129.

  • Property svn:keywords set to Revision Author Date
File size: 71.4 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/smphome/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 ) ] && 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 status
1234
1235  if [ $DRYRUN = 0 ]; then
1236    if [ ! -f ${1} ] ; then
1237      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1238      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1239      return 1
1240    fi
1241
1242    #
1243    if [ X${JobType} = XRUN ] ; then
1244      if [ X${3} = X ] ; then
1245        IGCM_sys_Chmod 444 ${1}
1246      fi
1247    fi
1248    #
1249    #
1250    #Command depends on targeted file system
1251    DEBUG_sys=false IGCM_sys_IsFileArchived $2
1252    if [ $? = 0 ] ; then
1253      mfput $1 $2 > out_rsync 2>&1
1254      status=$?
1255    else
1256      IGCM_sys_MkdirArchive $( dirname $2 )
1257      \cp $1 $2 > out_rsync 2>&1
1258      status=$?
1259    fi
1260
1261#       #RSYNC WITH NETWORK RSH CALL
1262#       IGCM_sys_MkdirArchive $( dirname $2 )
1263#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1264#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1265
1266#       #RSYNC WITH NFS USE
1267#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1268#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1269
1270#       status=$?
1271#       IGCM_sys_Rsync_out $status
1272
1273#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1274#       (( status=status+$? ))
1275
1276    if [ ${status} -gt 0 ] ; then
1277      IGCM_debug_Print 2 "IGCM_sys_Put_Out : mfput or cp failed error code ${status}"
1278      cat out_rsync
1279      IGCM_debug_Exit "IGCM_sys_Put_Out"
1280    else
1281      \rm out_rsync
1282    fi
1283  fi
1284  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1285  return 0
1286}
1287
1288#D-#==================================================
1289#D-function IGCM_sys_PutBuffer_Out
1290#D-* Purpose: Copy a file on ${WORKDIR} after having chmod it in readonly
1291#D-* Examples:
1292#D-
1293function IGCM_sys_PutBuffer_Out {
1294  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1295  if ( $DEBUG_sys ) ; then
1296    echo "IGCM_sys_PutBuffer_Out :" $@
1297  fi
1298
1299  typeset NB_ESSAI DELAI status i exist skip
1300
1301  # number of tentative
1302  NB_ESSAI=3
1303  # time delay between tentative
1304  DELAI=2
1305
1306  if [ $DRYRUN = 0 ]; then
1307    if [ ! -f ${1} ] ; then
1308      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1309      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1310      return 1
1311    fi
1312    #
1313    IGCM_sys_Mkdir $( dirname $2 )
1314    #
1315
1316    exist=false
1317    skip=false
1318    if [ -f $2 ] ; then
1319      IGCM_debug_Print 1 "$2 already exist"
1320      exist=true
1321      if [ "X$( diff $1 $2 )" = X ] ; then
1322        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1323        status=0
1324        skip=true
1325      else
1326        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1327        skip=false
1328      fi
1329    fi
1330    #
1331    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1332      IGCM_sys_Chmod u+w $2
1333    fi
1334
1335    if [ X${skip} = Xfalse ] ; then
1336      i=0
1337      while [ $i -lt $NB_ESSAI ] ; do
1338        # USUAL WAY
1339        \cp $1 $2 > out_rsync 2>&1
1340        status=$?
1341        if [ ${status} -gt 0 ]; then
1342          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1343          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1344          [ -f ${2} ] && ls -l ${2}
1345          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1346          sleep $DELAI
1347        else
1348          break
1349        fi
1350        (( i = i + 1 ))
1351      done
1352    fi
1353
1354    if [ ${status} -gt 0 ] ; then
1355      echo "IGCM_sys_PutBuffer_Out : error."
1356      [ -f ${2} ] && ls -l ${2}
1357      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1358      cat out_rsync
1359      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1360    else
1361
1362      if [ X${JobType} = XRUN ] ; then
1363        if [ X${3} = X ] ; then
1364          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1365          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1366        fi
1367      fi
1368
1369      \rm out_rsync
1370    fi
1371  fi
1372  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1373  return 0
1374}
1375
1376#D-#==================================================
1377#D-function IGCM_sys_Get
1378#D-* Purpose: Get a file from ${ARCHIVE}
1379#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1380#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1381function IGCM_sys_Get {
1382  IGCM_debug_PushStack "IGCM_sys_Get" $@
1383
1384  typeset DEST status dm_liste
1385
1386  if ( $DEBUG_sys ) ; then
1387    echo "IGCM_sys_Get :" $@
1388  fi
1389  if [ $DRYRUN -le 2 ]; then
1390    if [ X${1} = X'/l' ] ; then
1391      # test if the first file is present in the old computation :
1392      eval set +A dm_liste \${${2}}
1393    else
1394      dm_liste=${1}
1395    fi
1396    eval DEST=\${${#}}
1397
1398    # test if the (first) file is present in the old computation :
1399    DEBUG_sys=false IGCM_sys_IsFileArchived ${dm_liste[0]}
1400    if [ $? = 0 ] ; then
1401      IGCM_sys_TestFileArchive ${dm_liste[0]}
1402      status=$?
1403    else
1404      IGCM_sys_TestFileBuffer ${dm_liste[0]}
1405      status=$?
1406    fi
1407
1408    if [ ${status} -gt 0 ] ; then
1409      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1410      IGCM_debug_Exit "IGCM_sys_Get"
1411      return
1412    fi
1413
1414    #Command depends on targeted file system
1415    DEBUG_sys=false IGCM_sys_IsFileArchived ${dm_liste[0]}
1416    if [ $? = 0 ] ; then
1417      mfget ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1418      status=$?
1419    else
1420      \cp ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1421      status=$?
1422    fi
1423
1424#       #RSYNC WITH NETWORK RSH CALL
1425#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1426#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1427
1428#       #RSYNC WITH NFS USE
1429#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1430#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1431
1432#       status=$?
1433#       IGCM_sys_Rsync_out $status
1434
1435#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1436#       (( status=status+$? ))
1437
1438    if [ ${status} -gt 0 ] ; then
1439      IGCM_debug_Print 2 "IGCM_sys_Get : mfget or cp failed error code ${status}"
1440      cat out_rsync
1441      IGCM_debug_Exit "IGCM_sys_Get"
1442    else
1443      \rm out_rsync
1444    fi
1445  fi
1446  IGCM_debug_PopStack "IGCM_sys_Get"
1447}
1448
1449#D-#==================================================
1450#D-function IGCM_sys_GetBuffer
1451#D-* Purpose: Get a file from ${SCRATCHDIR}
1452#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1453#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1454function IGCM_sys_GetBuffer {
1455  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1456
1457  typeset DEST buf_liste target file_work
1458  typeset NB_ESSAI DELAI status i
1459
1460  if ( $DEBUG_sys ) ; then
1461    echo "IGCM_sys_GetBuffer :" $@
1462  fi
1463
1464  # number of tentative
1465  NB_ESSAI=3
1466  # time delay between tentative
1467  DELAI=2
1468
1469  if [ $DRYRUN -le 2 ]; then
1470    if [ X${1} = X'/l' ] ; then
1471      # test if the first file is present in the old computation :
1472      eval set +A buf_liste \${${2}}
1473    else
1474      eval set +A buf_liste ${1}
1475    fi
1476    eval DEST=\${${#}}
1477
1478    #USUAL WAY
1479    if [ X${1} = X'/l' ] ; then
1480      for target in ${buf_liste[*]} ; do
1481        local_file=$( basename ${target} )
1482        i=0
1483        while [ $i -lt $NB_ESSAI ] ; do
1484          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1485          status=$?
1486          if [ ${status} -gt 0 ]; then
1487            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1488            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1489            sleep $DELAI
1490          else
1491            break
1492          fi
1493          (( i = i + 1 ))
1494        done
1495        if [ ${status} -gt 0 ] ; then
1496          echo "IGCM_sys_Get : error"
1497          cat out_rsync
1498          \rm out_rsync
1499          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1500        else
1501          \rm out_rsync
1502        fi
1503      done
1504    else
1505      i=0
1506      while [ $i -lt $NB_ESSAI ] ; do
1507        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1508        status=$?
1509        if [ ${status} -gt 0 ]; then
1510          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1511          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1512          sleep $DELAI
1513        else
1514          break
1515        fi
1516        (( i = i + 1 ))
1517      done
1518      if [ ${status} -gt 0 ] ; then
1519        echo "IGCM_sys_Get : error"
1520        cat out_rsync
1521        \rm out_rsync
1522        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1523      else
1524        \rm out_rsync
1525      fi
1526    fi
1527  fi
1528  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1529}
1530
1531#D-#==================================================
1532#D-function IGCM_sys_GetDate_FichWork
1533#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1534#D-* Examples:
1535#D-
1536function IGCM_sys_GetDate_FichWork {
1537  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1538  if ( $DEBUG_sys ) ; then
1539    echo "IGCM_sys_GetDate_FichWork :" $@
1540  fi
1541  typeset dateF
1542  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1543  eval ${2}=${dateF[5]}
1544
1545  # donne la date filesys d'un fichier sur la machine work
1546  IGCM_debug_PopStack "IGCM_sys_FichWork"
1547}
1548
1549#D-#==================================================
1550#D-function IGCM_sys_GetDate_FichArchive
1551#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1552#D-* Examples:
1553#D-
1554function IGCM_sys_GetDate_FichArchive {
1555  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1556  if ( $DEBUG_sys ) ; then
1557    echo "IGCM_sys_GetDate_FichArchive :" $@
1558  fi
1559  typeset dateF
1560  set +A dateF -- $( rsh ${STOREHOST} -n ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1561  eval ${2}=${dateF[5]}
1562
1563  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1564}
1565
1566#D-#==================================================
1567#D-function IGCM_sys_GetDate_Monitoring
1568#D-* Purpose: get the last year for which the monitoring has been computed
1569#D-* Examples:
1570#D-
1571function IGCM_sys_GetDate_Monitoring {
1572#set -vx
1573  IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@
1574  if ( $DEBUG_sys ) ; then
1575    echo "IGCM_sys_GetDate_Monitoring :" $@
1576  fi
1577
1578  IGCM_sys_Cd /tmp
1579  IGCM_sys_Get ${1} .
1580  eval ${2}=$( cdo showyear $( basename ${1} ) 2> /dev/null | gawk '{ print $NF }' )
1581  IGCM_sys_Cd -
1582
1583#set +vx
1584  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
1585}
1586
1587#D-#==================================================
1588#D-function IGCM_sys_Put_Dods
1589#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1590#D-* Examples:
1591#D-
1592function IGCM_sys_Put_Dods {
1593  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1594  if ( $DEBUG_sys ) ; then
1595    echo "IGCM_sys_Put_Dods :" $@
1596  fi
1597  if [ $DRYRUN = 0 ]; then
1598    # We take our time on that
1599    sleep 10
1600    IGCM_sys_TestDirArchive ${R_SAVE}/${1}
1601    if [ $? != 0 ] ; then
1602      echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
1603      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1604      return
1605    fi
1606
1607    typeset status
1608    #
1609    rsh gaya exec /bin/ksh <<EOF
1610          cd ${R_SAVE}
1611          /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${R_DODS}/${1} > /dev/null 2>&1
1612          /bin/chmod -R u+w ${R_SAVE}/${1}
1613          /usr/local/bin/dods_cp ${1} DODS/pub/${LOGIN}/${R_DODS} > /dev/null 2>&1
1614          /bin/chmod -R +rX ${R_SAVE}/${1}
1615          /bin/chmod -R u+w ${R_SAVE}/${1}
1616EOF
1617    status=$?
1618
1619    if [ ${status} -gt 0 ] ; then
1620      echo "IGCM_sys_Put_Dods : error."
1621      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1622    fi
1623  fi
1624  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1625}
1626
1627##############################################################
1628# REBUILD OPERATOR
1629
1630#D-#==================================================
1631#D-function IGCM_sys_rebuild
1632#D-* Purpose: rebuild parallel files
1633#D-* Examples:
1634#D-
1635function IGCM_sys_rebuild {
1636  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1637  if ( $DEBUG_sys ) ; then
1638    echo "IGCM_sys_rebuild :" $@
1639  fi
1640
1641  typeset NB_ESSAI DELAI status i firstArg
1642  # number of tentative
1643  NB_ESSAI=3
1644  # time delay between tentative
1645  DELAI=2
1646
1647  i=0
1648  while [ $i -lt $NB_ESSAI ] ; do
1649    /smphome/rech/psl/rpsl035/bin/rebuild -f -o $@ > out_rsync 2>&1
1650    status=$?
1651    if [ ${status} -gt 0 ] ; then
1652      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1653      cat out_rsync
1654      \rm out_rsync
1655      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1656      firstArg=${1}
1657      \rm ${firstArg}
1658      sleep $DELAI
1659    else
1660      \rm out_rsync
1661      break
1662    fi
1663    (( i = i + 1 ))
1664  done
1665
1666  if [ ${status} -gt 0 ] ; then
1667    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1668    IGCM_debug_Exit "rebuild"
1669  fi
1670
1671  IGCM_debug_PopStack "IGCM_sys_rebuild"
1672}
1673
1674#D-#==================================================
1675#D-function IGCM_sys_rebuild_station
1676#D-* Purpose: rebuild parallel files describing station
1677#D-* Examples:
1678#D-
1679function IGCM_sys_rebuild_station {
1680  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1681  typeset i list_opt file_in file_out prefix_invert list_invert
1682  if ( $DEBUG_sys ) ; then
1683    echo "IGCM_sys_rebuild_station :" $@
1684  fi
1685  list_opt=$@
1686
1687  # Invert Axis : t,x -> x,t
1688  #               t,pres,x -> x,t,pres
1689  # So that we can concatenate along x
1690  i=0
1691  for file_in in ${list_opt} ; do
1692    (( i = i + 1))
1693    [ ${i} = 1 ] && file_out=${file_in} && continue
1694    prefix_invert=$( basename ${file_in} .nc )
1695    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1696    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1697  done
1698
1699  # Concatenate
1700  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1701
1702  # Re-ivert file
1703  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1704
1705  # Station re-ordering is too expansive to be run within libICGM
1706  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1707  # This re-ordering must be done "in memory" by the cmorization process
1708  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1709  # BEGIN reordering
1710
1711  # Only LMDZ text output contains the exact ordering of the station.
1712  # We isolate this in the code below:
1713  #  0  38  -157.5000000000000  70.98591549295774
1714  #  0  54  27.49999999999999   67.18309859154928
1715  #  0  56  -62.50000000000001  82.39436619718309
1716  #  0  79  12.49999999999999   78.59154929577466
1717  #  0  116 -165.0000000000000  76.05633802816901
1718  #  0  117 130.0000000000000   70.98591549295774
1719  #  0  118 110.0000000000000   87.46478873239437
1720  #  1  40  4.999999999999995   51.97183098591550
1721#  typeset iStation iProc list_opt file_in file_out prefix_invert
1722#  typeset -Z4 j4
1723#  typeset -Z3 j3
1724
1725#  unset list_opt
1726#  set +A list_opt $@
1727
1728  # Filename after rebuild
1729#  file_out=${list_opt[0]}
1730  # Prefix of output files
1731#  prefix_invert=$( basename ${file_out} .nc )
1732  # Number of procs
1733#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1734
1735#  iProc=0
1736#  while [ ${iProc} -lt ${num_proc} ] ; do
1737    # Array containing Station as a number
1738#    unset proc_stn
1739#    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}' )
1740    # Number of stations produced by processor proc
1741#    stationLast=${#proc_stn[*]}
1742    # Proc number on 4 digits
1743#    j4=${iProc}
1744    # Init
1745#    iStation=0
1746#    while [ ${iStation} -lt ${stationLast} ] ; do
1747      # Station number on 3 digits
1748#      j3=${proc_stn[${iStation}]}
1749      # Extract station
1750      # Invert Axis : t,x -> x,t
1751      #               t,pres,x -> x,t,pres
1752      # So that we can concatenate along x
1753#      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
1754#      (( iStation = iStation + 1 ))
1755#    done
1756#    (( iProc = iProc + 1 ))
1757#  done
1758
1759  # Concatenate all station along x
1760#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1761
1762  # Re-invert file
1763#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1764
1765  # END reordering
1766
1767  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1768}
1769
1770############################################################
1771# Activate Running Environnment Variables
1772
1773#D-#==================================================
1774#D-function IGCM_sys_desactiv_variables
1775#D-* Purpose: set environement variables prior to execution
1776#D-* Examples:
1777#D-
1778function IGCM_sys_activ_variables {
1779  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1780  if ( $DEBUG_sys ) ; then
1781    echo "IGCM_sys_activ_variables"
1782  fi
1783
1784# --------------------------------------------------------------------
1785#D- MPI specifications
1786# --------------------------------------------------------------------
1787
1788# --------------------------------------------------------------------
1789#D- Other specifications
1790# --------------------------------------------------------------------
1791
1792  ulimit -s unlimited
1793
1794## to be done only one time
1795## export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/smplocal/pub/NetCDF/4.1.3/lib:/smplocal/pub/HDF5/1.8.9/seq/lib
1796  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
1797  echo LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
1798
1799  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1800}
1801
1802############################################################
1803# Desactivate Running Environnment Variables
1804
1805#D-#==================================================
1806#D-function IGCM_sys_desactiv_variables
1807#D-* Purpose: unset environement variables after execution
1808#D-* Examples:
1809#D-
1810function IGCM_sys_desactiv_variables {
1811  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1812  if ( $DEBUG_sys ) ; then
1813    echo "IGCM_sys_desactiv_variables"
1814  fi
1815# --------------------------------------------------------------------
1816#D- MPI specifications
1817# --------------------------------------------------------------------
1818
1819# --------------------------------------------------------------------
1820#D- Other specifications
1821# --------------------------------------------------------------------
1822
1823  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1824}
1825
1826############################################################
1827# Build MPI/OMP scripts run file (dummy function)
1828
1829#D-#==================================================
1830#D-function IGCM_sys_build_run_file
1831#D-* Purpose: build run file (deprecated)
1832#D-* Examples:
1833#D-
1834function IGCM_sys_build_run_file {
1835
1836  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1837
1838}
1839
1840############################################################
1841# Build MPI/OMP scripts
1842
1843#D-#==================================================
1844#D-function IGCM_sys_build_execution_scripts
1845#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1846#D-* Examples:
1847#D-
1848function IGCM_sys_build_execution_scripts
1849{
1850  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1851  if ( $DEBUG_sys ) ; then
1852    echo "IGCM_sys_build_execution_scripts " $@
1853  fi
1854
1855  EXECUTION=${HOST_MPIRUN_COMMAND}
1856
1857  if ( ${OK_PARA_MPMD} ) ; then
1858
1859    if [ -f run_file ] ; then
1860      IGCM_sys_Rm -f run_file
1861    fi
1862    touch run_file
1863
1864# run_file construction
1865
1866# Then first loop on the components for the coupler ie oasis
1867
1868### the coupler ie oasis must be the first one
1869    for comp in ${config_ListOfComponents[*]} ; do
1870
1871      eval ExeNameIn=\${config_Executable_${comp}[0]}
1872      eval ExeNameOut=\${config_Executable_${comp}[1]}
1873
1874      # for CPL component only
1875      if [ "X${comp}" = "XCPL" ] ; then
1876
1877        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1878        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1879
1880        if ( ${OK_PARA_MPI} ) ; then
1881          (( mpi_count = 1 ))
1882          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1883            echo "./${ExeNameOut}" >> run_file
1884            (( mpi_count = mpi_count + 1 ))
1885          done
1886        else
1887          echo "./${ExeNameOut} " >> run_file
1888        fi
1889      fi
1890    done
1891
1892# Then second loop on the components
1893
1894    for comp in ${config_ListOfComponents[*]} ; do
1895
1896      eval ExeNameIn=\${config_Executable_${comp}[0]}
1897      eval ExeNameOut=\${config_Executable_${comp}[1]}
1898
1899      # Only if we really have an executable for the component and not the coupler ie oasis:
1900      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1901
1902        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1903        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1904
1905        if ( ${OK_PARA_MPI} ) ; then
1906          (( mpi_count = 1 ))
1907          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1908            echo "./${ExeNameOut}" >> run_file
1909            (( mpi_count = mpi_count + 1 ))
1910          done
1911        else
1912            echo "./${ExeNameOut} " >> run_file
1913        fi
1914      fi
1915    done
1916
1917    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
1918
1919    IGCM_sys_Chmod u+x run_file
1920    if ( $DEBUG_sys ) ; then
1921      echo "run_file contains : "
1922      cat run_file
1923    fi
1924
1925  else # Only one executable. launch it.
1926
1927    for comp in ${config_ListOfComponents[*]} ; do
1928
1929      # Only if we really have an executable for the component :
1930      eval ExeNameOut=\${config_Executable_${comp}[1]}
1931      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1932        EXECUTION="${HOST_MPIRUN_COMMAND} ./${ExeNameOut}"
1933      fi
1934
1935    done
1936
1937  fi
1938
1939  IGCM_debug_Print 1 "sys ada : execution command is "
1940  IGCM_debug_Print 1 "$EXECUTION"
1941
1942  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1943}
1944
1945############################################################
1946# Check of space available on temporary filesytems.
1947
1948#D-#==================================================
1949#D-function IGCM_sys_check_quota
1950#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1951#D-* Examples:
1952#D-
1953function IGCM_sys_check_quota {
1954  IGCM_debug_PushStack "IGCM_sys_check_quota"
1955  if ( $DEBUG_sys ) ; then
1956    echo "IGCM_sys_check_quota"
1957  fi
1958  # Limit of quota (in %)
1959  limit_quota=90
1960
1961  # Check of the volume
1962  volume_quota=$(quota_u -w | grep 'Quota soft' | awk '{print $5}')
1963  if [ ! X${volume_quota} = X ] ; then
1964    quota_volume=${volume_quota%%\%}
1965#    echo $quota_volume
1966    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1967      IGCM_debug_Print 1 "Please, check your quota of volume on workgpfs"
1968      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1969      IGCM_debug_Print 1 "Use the quota_u -w command to check"
1970      IGCM_debug_Print 1 "You must have more than 10% available to run"
1971      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1972      IGCM_debug_Verif_Exit
1973    fi
1974
1975  fi
1976  IGCM_debug_PopStack "IGCM_sys_check_quota"
1977}
1978
1979#D-#==================================================
1980#D-function IGCM_sys_CountJobInQueue
1981#D-* Purpose: Check if job_name is currently
1982#D-  running or in queue
1983#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1984#D-
1985function IGCM_sys_CountJobInQueue {
1986  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1987  if ( $DEBUG_sys ) ; then
1988    echo "IGCM_sys_CountJobInQueue"
1989  fi
1990
1991  # Print only the full (-W) JobName (%jn)
1992  NbRun=$( llq -W -f %jn | grep -c "$1" )
1993
1994  eval ${2}=${NbRun}
1995
1996  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1997}
1998
1999##############################################################
2000# NCO OPERATOR
2001
2002#D-#==================================================
2003#D-function IGCM_sys_ncap2
2004#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2005#D-* Examples:
2006#D-
2007function IGCM_sys_ncap2 {
2008  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2009  if ( $DEBUG_sys ) ; then
2010    echo "IGCM_sys_ncap2 :" $@
2011  fi
2012
2013  typeset NB_ESSAI DELAI status i
2014  # number of tentative
2015  NB_ESSAI=3
2016  # time delay between tentative
2017  DELAI=2
2018
2019  i=0
2020  while [ $i -lt $NB_ESSAI ] ; do
2021    ncap2 "$@" > out_rsync 2>&1
2022    status=$?
2023    if [ ${status} -gt 0 ] ; then
2024      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2025      cat out_rsync
2026      \rm out_rsync
2027      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2028      sleep $DELAI
2029    else
2030      \rm out_rsync
2031      break
2032    fi
2033    (( i = i + 1 ))
2034  done
2035
2036  if [ ${status} -gt 0 ] ; then
2037    echo "IGCM_sys_ncap2 : ncap2 error"
2038    IGCM_debug_Exit "ncap2"
2039  fi
2040
2041  IGCM_debug_PopStack "IGCM_sys_ncap2"
2042}
2043
2044#D-#==================================================
2045#D-function IGCM_sys_ncatted
2046#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2047#D-* Examples:
2048#D-
2049function IGCM_sys_ncatted {
2050  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2051  if ( $DEBUG_sys ) ; then
2052    echo "IGCM_sys_ncatted :" $@
2053  fi
2054
2055  typeset NB_ESSAI DELAI status i
2056  # number of tentative
2057  NB_ESSAI=3
2058  # time delay between tentative
2059  DELAI=2
2060
2061  i=0
2062  while [ $i -lt $NB_ESSAI ] ; do
2063    ncatted "$@" > out_rsync 2>&1
2064    status=$?
2065    if [ ${status} -gt 0 ] ; then
2066      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2067      cat out_rsync
2068      \rm out_rsync
2069      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2070      sleep $DELAI
2071    else
2072      \rm out_rsync
2073      break
2074    fi
2075    (( i = i + 1 ))
2076  done
2077
2078  if [ ${status} -gt 0 ] ; then
2079    echo "IGCM_sys_ncatted : ncatted error"
2080    IGCM_debug_Exit "ncatted"
2081  fi
2082
2083  IGCM_debug_PopStack "IGCM_sys_ncatted"
2084}
2085
2086#D-#==================================================
2087#D-function IGCM_sys_ncbo
2088#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2089#D-* Examples:
2090#D-
2091function IGCM_sys_ncbo {
2092  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2093  if ( $DEBUG_sys ) ; then
2094    echo "IGCM_sys_ncbo :" $@
2095  fi
2096
2097  typeset NB_ESSAI DELAI status i
2098  # number of tentative
2099  NB_ESSAI=3
2100  # time delay between tentative
2101  DELAI=2
2102
2103  i=0
2104  while [ $i -lt $NB_ESSAI ] ; do
2105    ncbo $@ > out_rsync 2>&1
2106    status=$?
2107    if [ ${status} -gt 0 ] ; then
2108      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2109      cat out_rsync
2110      \rm out_rsync
2111      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2112      sleep $DELAI
2113    else
2114      \rm out_rsync
2115      break
2116    fi
2117    (( i = i + 1 ))
2118  done
2119
2120  if [ ${status} -gt 0 ] ; then
2121    echo "IGCM_sys_ncbo : ncbo error"
2122    IGCM_debug_Exit "ncbo"
2123  fi
2124
2125  IGCM_debug_PopStack "IGCM_sys_ncbo"
2126}
2127
2128#D-#==================================================
2129#D-function IGCM_sys_ncdif
2130#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2131#D-* Examples:
2132#D-
2133function IGCM_sys_ncdiff {
2134  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2135  if ( $DEBUG_sys ) ; then
2136    echo "IGCM_sys_ncdiff :" $@
2137  fi
2138
2139  typeset NB_ESSAI DELAI status i
2140  # number of tentative
2141  NB_ESSAI=3
2142  # time delay between tentative
2143  DELAI=2
2144
2145  i=0
2146  while [ $i -lt $NB_ESSAI ] ; do
2147    ncdiff $@ > out_rsync 2>&1
2148    status=$?
2149    if [ ${status} -gt 0 ] ; then
2150      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2151      cat out_rsync
2152      \rm out_rsync
2153      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2154      sleep $DELAI
2155    else
2156      \rm out_rsync
2157      break
2158    fi
2159    (( i = i + 1 ))
2160  done
2161
2162  if [ ${status} -gt 0 ] ; then
2163    echo "IGCM_sys_ncdiff : ncdiff error"
2164    IGCM_debug_Exit "ncdiff"
2165  fi
2166
2167  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2168}
2169
2170#D-#==================================================
2171#D-function IGCM_sys_ncea
2172#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2173#D-* Examples:
2174#D-
2175function IGCM_sys_ncea {
2176  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2177  if ( $DEBUG_sys ) ; then
2178    echo "IGCM_sys_ncea :" $@
2179  fi
2180
2181  typeset NB_ESSAI DELAI status i
2182  # number of tentative
2183  NB_ESSAI=3
2184  # time delay between tentative
2185  DELAI=2
2186
2187  i=0
2188  while [ $i -lt $NB_ESSAI ] ; do
2189    ncea $@ > out_rsync 2>&1
2190    status=$?
2191    if [ ${status} -gt 0 ] ; then
2192      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2193      cat out_rsync
2194      \rm out_rsync
2195      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2196      sleep $DELAI
2197    else
2198      \rm out_rsync
2199      break
2200    fi
2201    (( i = i + 1 ))
2202  done
2203
2204  if [ ${status} -gt 0 ] ; then
2205    echo "IGCM_sys_ncea : ncea error"
2206    IGCM_debug_Exit "ncea"
2207  fi
2208
2209  IGCM_debug_PopStack "IGCM_sys_ncea"
2210}
2211
2212#D-#==================================================
2213#D-function IGCM_sys_ncecat
2214#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2215#D-* Examples:
2216#D-
2217function IGCM_sys_ncecat {
2218  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2219  if ( $DEBUG_sys ) ; then
2220    echo "IGCM_sys_ncecat :" $@
2221  fi
2222
2223  typeset NB_ESSAI DELAI status i
2224  # number of tentative
2225  NB_ESSAI=3
2226  # time delay between tentative
2227  DELAI=2
2228
2229  i=0
2230  while [ $i -lt $NB_ESSAI ] ; do
2231    ncecat $@ > out_rsync 2>&1
2232    status=$?
2233    if [ ${status} -gt 0 ] ; then
2234      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2235      cat out_rsync
2236      \rm out_rsync
2237      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2238      sleep $DELAI
2239    else
2240      \rm out_rsync
2241      break
2242    fi
2243    (( i = i + 1 ))
2244  done
2245
2246  if [ ${status} -gt 0 ] ; then
2247    echo "IGCM_sys_ncecat : ncecat error"
2248    IGCM_debug_Exit "ncecat"
2249  fi
2250
2251  IGCM_debug_PopStack "IGCM_sys_ncecat"
2252}
2253
2254#D-#==================================================
2255#D-function IGCM_sys_ncflint
2256#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2257#D-* Examples:
2258#D-
2259function IGCM_sys_ncflint {
2260  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2261  if ( $DEBUG_sys ) ; then
2262    echo "IGCM_sys_ncflint :" $@
2263  fi
2264
2265  typeset NB_ESSAI DELAI status i
2266  # number of tentative
2267  NB_ESSAI=3
2268  # time delay between tentative
2269  DELAI=2
2270
2271  i=0
2272  while [ $i -lt $NB_ESSAI ] ; do
2273    ncflint $@ > out_rsync 2>&1
2274    status=$?
2275    if [ ${status} -gt 0 ] ; then
2276      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2277      cat out_rsync
2278      \rm out_rsync
2279      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2280      sleep $DELAI
2281    else
2282      \rm out_rsync
2283      break
2284    fi
2285    (( i = i + 1 ))
2286  done
2287
2288  if [ ${status} -gt 0 ] ; then
2289    echo "IGCM_sys_ncflint : ncflint error"
2290    IGCM_debug_Exit "ncflint"
2291  fi
2292
2293  IGCM_debug_PopStack "IGCM_sys_ncflint"
2294}
2295
2296#D-#==================================================
2297#D-function IGCM_sys_ncks
2298#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2299#D-* Examples:
2300#D-
2301function IGCM_sys_ncks {
2302  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2303  if ( $DEBUG_sys ) ; then
2304    echo "IGCM_sys_ncks :" $@
2305  fi
2306
2307  typeset NB_ESSAI DELAI status i
2308  # number of tentative
2309  NB_ESSAI=3
2310  # time delay between tentative
2311  DELAI=2
2312
2313  i=0
2314  while [ $i -lt $NB_ESSAI ] ; do
2315    ncks $@ > out_rsync 2>&1
2316    status=$?
2317    if [ ${status} -gt 0 ] ; then
2318      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2319      cat out_rsync
2320      \rm out_rsync
2321      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2322      sleep $DELAI
2323    else
2324      \rm out_rsync
2325      break
2326    fi
2327    (( i = i + 1 ))
2328  done
2329
2330  if [ ${status} -gt 0 ] ; then
2331    echo "IGCM_sys_ncks : ncks error"
2332    IGCM_debug_Exit "ncks"
2333  fi
2334
2335  IGCM_debug_PopStack "IGCM_sys_ncks"
2336}
2337
2338#D-#==================================================
2339#D-function IGCM_sys_ncpdq
2340#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2341#D-* Examples:
2342#D-
2343function IGCM_sys_ncpdq {
2344  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2345  if ( $DEBUG_sys ) ; then
2346    echo "IGCM_sys_ncpdq :" $@
2347  fi
2348
2349  typeset NB_ESSAI DELAI status i
2350  # number of tentative
2351  NB_ESSAI=3
2352  # time delay between tentative
2353  DELAI=2
2354
2355  i=0
2356  while [ $i -lt $NB_ESSAI ] ; do
2357    ncpdq $@ > out_rsync 2>&1
2358    status=$?
2359    if [ ${status} -gt 0 ] ; then
2360      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2361      cat out_rsync
2362      \rm out_rsync
2363      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2364      sleep $DELAI
2365    else
2366      \rm out_rsync
2367      break
2368    fi
2369    (( i = i + 1 ))
2370  done
2371
2372  if [ ${status} -gt 0 ] ; then
2373    echo "IGCM_sys_ncpdq : ncpdq error"
2374    IGCM_debug_Exit "ncpdq"
2375  fi
2376
2377  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2378}
2379
2380#D-#==================================================
2381#D-function IGCM_sys_ncra
2382#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2383#D-* Examples:
2384#D-
2385function IGCM_sys_ncra {
2386  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2387  if ( $DEBUG_sys ) ; then
2388    echo "IGCM_sys_ncra :" $@
2389  fi
2390
2391  typeset NB_ESSAI DELAI status i
2392  # number of tentative
2393  NB_ESSAI=3
2394  # time delay between tentative
2395  DELAI=2
2396
2397  i=0
2398  while [ $i -lt $NB_ESSAI ] ; do
2399    ncra $@ > out_rsync 2>&1
2400    status=$?
2401    if [ ${status} -gt 0 ] ; then
2402      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2403      cat out_rsync
2404      \rm out_rsync
2405      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2406      sleep $DELAI
2407    else
2408      \rm out_rsync
2409      break
2410    fi
2411    (( i = i + 1 ))
2412  done
2413
2414  if [ ${status} -gt 0 ] ; then
2415    echo "IGCM_sys_ncra : ncra error"
2416    IGCM_debug_Exit "ncra"
2417  fi
2418
2419  IGCM_debug_PopStack "IGCM_sys_ncra"
2420}
2421
2422#D-#==================================================
2423#D-function IGCM_sys_ncrcat
2424#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2425#D-* Examples:
2426#D-
2427function IGCM_sys_ncrcat {
2428  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2429  if ( $DEBUG_sys ) ; then
2430    echo "IGCM_sys_ncrcat :" $@
2431  fi
2432
2433  typeset NB_ESSAI DELAI status i lastArg
2434  # number of tentative
2435  NB_ESSAI=3
2436  # time delay between tentative
2437  DELAI=2
2438
2439  i=0
2440  while [ $i -lt $NB_ESSAI ] ; do
2441    ncrcat $@ > out_rsync 2>&1
2442    status=$?
2443    if [ ${status} -gt 0 ] ; then
2444      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2445      cat out_rsync
2446      \rm out_rsync
2447      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2448      sleep $DELAI
2449    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2450      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2451      cat out_rsync
2452      # remove files having corrupted time axis
2453      eval lastArg=\${$#}
2454      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2455      \rm ${lastArg}
2456      \rm out_rsync
2457      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2458      sleep $DELAI
2459    else
2460      \rm out_rsync
2461      break
2462    fi
2463    (( i = i + 1 ))
2464  done
2465
2466  if [ ${status} -gt 0 ] ; then
2467    echo "IGCM_sys_ncrcat : ncrcat error"
2468    #IGCM_debug_Exit "ncrcat"
2469  fi
2470
2471  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2472}
2473
2474#D-#==================================================
2475#D-function IGCM_sys_ncrename
2476#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2477#D-* Examples:
2478#D-
2479function IGCM_sys_ncrename {
2480  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2481  if ( $DEBUG_sys ) ; then
2482    echo "IGCM_sys_ncrename :" $@
2483  fi
2484
2485  typeset NB_ESSAI DELAI status i
2486  # number of tentative
2487  NB_ESSAI=3
2488  # time delay between tentative
2489  DELAI=2
2490
2491  i=0
2492  while [ $i -lt $NB_ESSAI ] ; do
2493    ncrename $@ > out_rsync 2>&1
2494    status=$?
2495    if [ ${status} -gt 0 ] ; then
2496      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2497      cat out_rsync
2498      \rm out_rsync
2499      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2500      sleep $DELAI
2501    else
2502      \rm out_rsync
2503      break
2504    fi
2505    (( i = i + 1 ))
2506  done
2507
2508  if [ ${status} -gt 0 ] ; then
2509    echo "IGCM_sys_ncrename : ncrename error"
2510    IGCM_debug_Exit "ncrename"
2511  fi
2512
2513  IGCM_debug_PopStack "IGCM_sys_ncrename"
2514}
2515
2516#D-#==================================================
2517#D-function IGCM_sys_ncwa
2518#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2519#D-* Examples:
2520#D-
2521function IGCM_sys_ncwa {
2522  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2523  if ( $DEBUG_sys ) ; then
2524    echo "IGCM_sys_ncwa :" $@
2525  fi
2526
2527  typeset NB_ESSAI DELAI status i
2528  # number of tentative
2529  NB_ESSAI=3
2530  # time delay between tentative
2531  DELAI=2
2532
2533  i=0
2534  while [ $i -lt $NB_ESSAI ] ; do
2535    ncwa $@ > out_rsync 2>&1
2536    status=$?
2537    if [ ${status} -gt 0 ] ; then
2538      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2539      cat out_rsync
2540      \rm out_rsync
2541      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2542      sleep $DELAI
2543    else
2544      \rm out_rsync
2545      break
2546    fi
2547    (( i = i + 1 ))
2548  done
2549
2550  if [ ${status} -gt 0 ] ; then
2551    echo "IGCM_sys_ncwa : ncwa error"
2552    IGCM_debug_Exit "ncwa"
2553  fi
2554
2555  IGCM_debug_PopStack "IGCM_sys_ncwa"
2556}
2557
2558##############################################################
2559# CDO OPERATOR
2560
2561#D-#==================================================
2562#D-function IGCM_sys_cdo
2563#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2564#D-* Examples:
2565#D-
2566function IGCM_sys_cdo {
2567  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2568  if ( $DEBUG_sys ) ; then
2569    echo "IGCM_sys_cdo :" $@
2570  fi
2571
2572  typeset status
2573
2574  \cdo $@ > out_rsync 2>&1
2575  status=$?
2576  if [ ${status} -gt 0 ] ; then
2577    echo "IGCM_sys_cdo : error code ${status}"
2578    cat out_rsync
2579    \rm out_rsync
2580    IGCM_debug_PopStack "IGCM_sys_cdo"
2581    return 1
2582  else
2583    IGCM_debug_PopStack "IGCM_sys_cdo"
2584    return 0
2585  fi
2586
2587  IGCM_debug_PopStack "IGCM_sys_cdo"
2588}
Note: See TracBrowser for help on using the repository browser.