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

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

remove machines that are not available anymore
cleanup

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