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

Last change on this file since 883 was 883, checked in by mafoipsl, 11 years ago

On ada , use STOREHOST variable instead of gaya directly.

  • Property svn:keywords set to Revision Author Date
File size: 71.8 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=$(rsh ${STOREHOST} 'echo $HOME') 
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
1933        if ( ${OK_PARA_OMP} ) ; then
1934          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1935          export KMP_STACKSIZE=200m
1936          #export KMP_LIBRARY=turnaround
1937          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1938          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1939          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1940        fi
1941
1942        EXECUTION="${HOST_MPIRUN_COMMAND} ./${ExeNameOut}"
1943      fi
1944
1945    done
1946
1947  fi
1948
1949  IGCM_debug_Print 1 "sys ada : execution command is "
1950  IGCM_debug_Print 1 "$EXECUTION"
1951
1952  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1953}
1954
1955############################################################
1956# Check of space available on temporary filesytems.
1957
1958#D-#==================================================
1959#D-function IGCM_sys_check_quota
1960#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1961#D-* Examples:
1962#D-
1963function IGCM_sys_check_quota {
1964  IGCM_debug_PushStack "IGCM_sys_check_quota"
1965  if ( $DEBUG_sys ) ; then
1966    echo "IGCM_sys_check_quota"
1967  fi
1968  # Limit of quota (in %)
1969  limit_quota=90
1970
1971  # Check of the volume
1972  volume_quota=$(quota_u -w | grep 'Quota soft' | awk '{print $5}')
1973  if [ ! X${volume_quota} = X ] ; then
1974    quota_volume=${volume_quota%%\%}
1975#    echo $quota_volume
1976    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1977      IGCM_debug_Print 1 "Please, check your quota of volume on workgpfs"
1978      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1979      IGCM_debug_Print 1 "Use the quota_u -w command to check"
1980      IGCM_debug_Print 1 "You must have more than 10% available to run"
1981      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1982      IGCM_debug_Verif_Exit
1983    fi
1984
1985  fi
1986  IGCM_debug_PopStack "IGCM_sys_check_quota"
1987}
1988
1989#D-#==================================================
1990#D-function IGCM_sys_CountJobInQueue
1991#D-* Purpose: Check if job_name is currently
1992#D-  running or in queue
1993#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1994#D-
1995function IGCM_sys_CountJobInQueue {
1996  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1997  if ( $DEBUG_sys ) ; then
1998    echo "IGCM_sys_CountJobInQueue"
1999  fi
2000
2001  # Print only the full (-W) JobName (%jn)
2002  NbRun=$( llq -W -f %jn | grep -c "$1" )
2003
2004  eval ${2}=${NbRun}
2005
2006  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
2007}
2008
2009##############################################################
2010# NCO OPERATOR
2011
2012#D-#==================================================
2013#D-function IGCM_sys_ncap2
2014#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2015#D-* Examples:
2016#D-
2017function IGCM_sys_ncap2 {
2018  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2019  if ( $DEBUG_sys ) ; then
2020    echo "IGCM_sys_ncap2 :" $@
2021  fi
2022
2023  typeset NB_ESSAI DELAI status i
2024  # number of tentative
2025  NB_ESSAI=3
2026  # time delay between tentative
2027  DELAI=2
2028
2029  i=0
2030  while [ $i -lt $NB_ESSAI ] ; do
2031    ncap2 "$@" > out_rsync 2>&1
2032    status=$?
2033    if [ ${status} -gt 0 ] ; then
2034      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2035      cat out_rsync
2036      \rm out_rsync
2037      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2038      sleep $DELAI
2039    else
2040      \rm out_rsync
2041      break
2042    fi
2043    (( i = i + 1 ))
2044  done
2045
2046  if [ ${status} -gt 0 ] ; then
2047    echo "IGCM_sys_ncap2 : ncap2 error"
2048    IGCM_debug_Exit "ncap2"
2049  fi
2050
2051  IGCM_debug_PopStack "IGCM_sys_ncap2"
2052}
2053
2054#D-#==================================================
2055#D-function IGCM_sys_ncatted
2056#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2057#D-* Examples:
2058#D-
2059function IGCM_sys_ncatted {
2060  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2061  if ( $DEBUG_sys ) ; then
2062    echo "IGCM_sys_ncatted :" $@
2063  fi
2064
2065  typeset NB_ESSAI DELAI status i
2066  # number of tentative
2067  NB_ESSAI=3
2068  # time delay between tentative
2069  DELAI=2
2070
2071  i=0
2072  while [ $i -lt $NB_ESSAI ] ; do
2073    ncatted "$@" > out_rsync 2>&1
2074    status=$?
2075    if [ ${status} -gt 0 ] ; then
2076      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2077      cat out_rsync
2078      \rm out_rsync
2079      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2080      sleep $DELAI
2081    else
2082      \rm out_rsync
2083      break
2084    fi
2085    (( i = i + 1 ))
2086  done
2087
2088  if [ ${status} -gt 0 ] ; then
2089    echo "IGCM_sys_ncatted : ncatted error"
2090    IGCM_debug_Exit "ncatted"
2091  fi
2092
2093  IGCM_debug_PopStack "IGCM_sys_ncatted"
2094}
2095
2096#D-#==================================================
2097#D-function IGCM_sys_ncbo
2098#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2099#D-* Examples:
2100#D-
2101function IGCM_sys_ncbo {
2102  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2103  if ( $DEBUG_sys ) ; then
2104    echo "IGCM_sys_ncbo :" $@
2105  fi
2106
2107  typeset NB_ESSAI DELAI status i
2108  # number of tentative
2109  NB_ESSAI=3
2110  # time delay between tentative
2111  DELAI=2
2112
2113  i=0
2114  while [ $i -lt $NB_ESSAI ] ; do
2115    ncbo $@ > out_rsync 2>&1
2116    status=$?
2117    if [ ${status} -gt 0 ] ; then
2118      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2119      cat out_rsync
2120      \rm out_rsync
2121      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2122      sleep $DELAI
2123    else
2124      \rm out_rsync
2125      break
2126    fi
2127    (( i = i + 1 ))
2128  done
2129
2130  if [ ${status} -gt 0 ] ; then
2131    echo "IGCM_sys_ncbo : ncbo error"
2132    IGCM_debug_Exit "ncbo"
2133  fi
2134
2135  IGCM_debug_PopStack "IGCM_sys_ncbo"
2136}
2137
2138#D-#==================================================
2139#D-function IGCM_sys_ncdif
2140#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2141#D-* Examples:
2142#D-
2143function IGCM_sys_ncdiff {
2144  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2145  if ( $DEBUG_sys ) ; then
2146    echo "IGCM_sys_ncdiff :" $@
2147  fi
2148
2149  typeset NB_ESSAI DELAI status i
2150  # number of tentative
2151  NB_ESSAI=3
2152  # time delay between tentative
2153  DELAI=2
2154
2155  i=0
2156  while [ $i -lt $NB_ESSAI ] ; do
2157    ncdiff $@ > out_rsync 2>&1
2158    status=$?
2159    if [ ${status} -gt 0 ] ; then
2160      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2161      cat out_rsync
2162      \rm out_rsync
2163      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2164      sleep $DELAI
2165    else
2166      \rm out_rsync
2167      break
2168    fi
2169    (( i = i + 1 ))
2170  done
2171
2172  if [ ${status} -gt 0 ] ; then
2173    echo "IGCM_sys_ncdiff : ncdiff error"
2174    IGCM_debug_Exit "ncdiff"
2175  fi
2176
2177  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2178}
2179
2180#D-#==================================================
2181#D-function IGCM_sys_ncea
2182#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2183#D-* Examples:
2184#D-
2185function IGCM_sys_ncea {
2186  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2187  if ( $DEBUG_sys ) ; then
2188    echo "IGCM_sys_ncea :" $@
2189  fi
2190
2191  typeset NB_ESSAI DELAI status i
2192  # number of tentative
2193  NB_ESSAI=3
2194  # time delay between tentative
2195  DELAI=2
2196
2197  i=0
2198  while [ $i -lt $NB_ESSAI ] ; do
2199    ncea $@ > out_rsync 2>&1
2200    status=$?
2201    if [ ${status} -gt 0 ] ; then
2202      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2203      cat out_rsync
2204      \rm out_rsync
2205      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2206      sleep $DELAI
2207    else
2208      \rm out_rsync
2209      break
2210    fi
2211    (( i = i + 1 ))
2212  done
2213
2214  if [ ${status} -gt 0 ] ; then
2215    echo "IGCM_sys_ncea : ncea error"
2216    IGCM_debug_Exit "ncea"
2217  fi
2218
2219  IGCM_debug_PopStack "IGCM_sys_ncea"
2220}
2221
2222#D-#==================================================
2223#D-function IGCM_sys_ncecat
2224#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2225#D-* Examples:
2226#D-
2227function IGCM_sys_ncecat {
2228  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2229  if ( $DEBUG_sys ) ; then
2230    echo "IGCM_sys_ncecat :" $@
2231  fi
2232
2233  typeset NB_ESSAI DELAI status i
2234  # number of tentative
2235  NB_ESSAI=3
2236  # time delay between tentative
2237  DELAI=2
2238
2239  i=0
2240  while [ $i -lt $NB_ESSAI ] ; do
2241    ncecat $@ > out_rsync 2>&1
2242    status=$?
2243    if [ ${status} -gt 0 ] ; then
2244      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2245      cat out_rsync
2246      \rm out_rsync
2247      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2248      sleep $DELAI
2249    else
2250      \rm out_rsync
2251      break
2252    fi
2253    (( i = i + 1 ))
2254  done
2255
2256  if [ ${status} -gt 0 ] ; then
2257    echo "IGCM_sys_ncecat : ncecat error"
2258    IGCM_debug_Exit "ncecat"
2259  fi
2260
2261  IGCM_debug_PopStack "IGCM_sys_ncecat"
2262}
2263
2264#D-#==================================================
2265#D-function IGCM_sys_ncflint
2266#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2267#D-* Examples:
2268#D-
2269function IGCM_sys_ncflint {
2270  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2271  if ( $DEBUG_sys ) ; then
2272    echo "IGCM_sys_ncflint :" $@
2273  fi
2274
2275  typeset NB_ESSAI DELAI status i
2276  # number of tentative
2277  NB_ESSAI=3
2278  # time delay between tentative
2279  DELAI=2
2280
2281  i=0
2282  while [ $i -lt $NB_ESSAI ] ; do
2283    ncflint $@ > out_rsync 2>&1
2284    status=$?
2285    if [ ${status} -gt 0 ] ; then
2286      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2287      cat out_rsync
2288      \rm out_rsync
2289      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2290      sleep $DELAI
2291    else
2292      \rm out_rsync
2293      break
2294    fi
2295    (( i = i + 1 ))
2296  done
2297
2298  if [ ${status} -gt 0 ] ; then
2299    echo "IGCM_sys_ncflint : ncflint error"
2300    IGCM_debug_Exit "ncflint"
2301  fi
2302
2303  IGCM_debug_PopStack "IGCM_sys_ncflint"
2304}
2305
2306#D-#==================================================
2307#D-function IGCM_sys_ncks
2308#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2309#D-* Examples:
2310#D-
2311function IGCM_sys_ncks {
2312  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2313  if ( $DEBUG_sys ) ; then
2314    echo "IGCM_sys_ncks :" $@
2315  fi
2316
2317  typeset NB_ESSAI DELAI status i
2318  # number of tentative
2319  NB_ESSAI=3
2320  # time delay between tentative
2321  DELAI=2
2322
2323  i=0
2324  while [ $i -lt $NB_ESSAI ] ; do
2325    ncks $@ > out_rsync 2>&1
2326    status=$?
2327    if [ ${status} -gt 0 ] ; then
2328      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2329      cat out_rsync
2330      \rm out_rsync
2331      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2332      sleep $DELAI
2333    else
2334      \rm out_rsync
2335      break
2336    fi
2337    (( i = i + 1 ))
2338  done
2339
2340  if [ ${status} -gt 0 ] ; then
2341    echo "IGCM_sys_ncks : ncks error"
2342    IGCM_debug_Exit "ncks"
2343  fi
2344
2345  IGCM_debug_PopStack "IGCM_sys_ncks"
2346}
2347
2348#D-#==================================================
2349#D-function IGCM_sys_ncpdq
2350#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2351#D-* Examples:
2352#D-
2353function IGCM_sys_ncpdq {
2354  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2355  if ( $DEBUG_sys ) ; then
2356    echo "IGCM_sys_ncpdq :" $@
2357  fi
2358
2359  typeset NB_ESSAI DELAI status i
2360  # number of tentative
2361  NB_ESSAI=3
2362  # time delay between tentative
2363  DELAI=2
2364
2365  i=0
2366  while [ $i -lt $NB_ESSAI ] ; do
2367    ncpdq $@ > out_rsync 2>&1
2368    status=$?
2369    if [ ${status} -gt 0 ] ; then
2370      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2371      cat out_rsync
2372      \rm out_rsync
2373      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2374      sleep $DELAI
2375    else
2376      \rm out_rsync
2377      break
2378    fi
2379    (( i = i + 1 ))
2380  done
2381
2382  if [ ${status} -gt 0 ] ; then
2383    echo "IGCM_sys_ncpdq : ncpdq error"
2384    IGCM_debug_Exit "ncpdq"
2385  fi
2386
2387  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2388}
2389
2390#D-#==================================================
2391#D-function IGCM_sys_ncra
2392#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2393#D-* Examples:
2394#D-
2395function IGCM_sys_ncra {
2396  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2397  if ( $DEBUG_sys ) ; then
2398    echo "IGCM_sys_ncra :" $@
2399  fi
2400
2401  typeset NB_ESSAI DELAI status i
2402  # number of tentative
2403  NB_ESSAI=3
2404  # time delay between tentative
2405  DELAI=2
2406
2407  i=0
2408  while [ $i -lt $NB_ESSAI ] ; do
2409    ncra $@ > out_rsync 2>&1
2410    status=$?
2411    if [ ${status} -gt 0 ] ; then
2412      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2413      cat out_rsync
2414      \rm out_rsync
2415      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2416      sleep $DELAI
2417    else
2418      \rm out_rsync
2419      break
2420    fi
2421    (( i = i + 1 ))
2422  done
2423
2424  if [ ${status} -gt 0 ] ; then
2425    echo "IGCM_sys_ncra : ncra error"
2426    IGCM_debug_Exit "ncra"
2427  fi
2428
2429  IGCM_debug_PopStack "IGCM_sys_ncra"
2430}
2431
2432#D-#==================================================
2433#D-function IGCM_sys_ncrcat
2434#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2435#D-* Examples:
2436#D-
2437function IGCM_sys_ncrcat {
2438  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2439  if ( $DEBUG_sys ) ; then
2440    echo "IGCM_sys_ncrcat :" $@
2441  fi
2442
2443  typeset NB_ESSAI DELAI status i lastArg
2444  # number of tentative
2445  NB_ESSAI=3
2446  # time delay between tentative
2447  DELAI=2
2448
2449  i=0
2450  while [ $i -lt $NB_ESSAI ] ; do
2451    ncrcat $@ > out_rsync 2>&1
2452    status=$?
2453    if [ ${status} -gt 0 ] ; then
2454      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2455      cat out_rsync
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    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2460      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2461      cat out_rsync
2462      # remove files having corrupted time axis
2463      eval lastArg=\${$#}
2464      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2465      \rm ${lastArg}
2466      \rm out_rsync
2467      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2468      sleep $DELAI
2469    else
2470      \rm out_rsync
2471      break
2472    fi
2473    (( i = i + 1 ))
2474  done
2475
2476  if [ ${status} -gt 0 ] ; then
2477    echo "IGCM_sys_ncrcat : ncrcat error"
2478    #IGCM_debug_Exit "ncrcat"
2479  fi
2480
2481  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2482}
2483
2484#D-#==================================================
2485#D-function IGCM_sys_ncrename
2486#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2487#D-* Examples:
2488#D-
2489function IGCM_sys_ncrename {
2490  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2491  if ( $DEBUG_sys ) ; then
2492    echo "IGCM_sys_ncrename :" $@
2493  fi
2494
2495  typeset NB_ESSAI DELAI status i
2496  # number of tentative
2497  NB_ESSAI=3
2498  # time delay between tentative
2499  DELAI=2
2500
2501  i=0
2502  while [ $i -lt $NB_ESSAI ] ; do
2503    ncrename $@ > out_rsync 2>&1
2504    status=$?
2505    if [ ${status} -gt 0 ] ; then
2506      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2507      cat out_rsync
2508      \rm out_rsync
2509      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2510      sleep $DELAI
2511    else
2512      \rm out_rsync
2513      break
2514    fi
2515    (( i = i + 1 ))
2516  done
2517
2518  if [ ${status} -gt 0 ] ; then
2519    echo "IGCM_sys_ncrename : ncrename error"
2520    IGCM_debug_Exit "ncrename"
2521  fi
2522
2523  IGCM_debug_PopStack "IGCM_sys_ncrename"
2524}
2525
2526#D-#==================================================
2527#D-function IGCM_sys_ncwa
2528#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2529#D-* Examples:
2530#D-
2531function IGCM_sys_ncwa {
2532  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2533  if ( $DEBUG_sys ) ; then
2534    echo "IGCM_sys_ncwa :" $@
2535  fi
2536
2537  typeset NB_ESSAI DELAI status i
2538  # number of tentative
2539  NB_ESSAI=3
2540  # time delay between tentative
2541  DELAI=2
2542
2543  i=0
2544  while [ $i -lt $NB_ESSAI ] ; do
2545    ncwa $@ > out_rsync 2>&1
2546    status=$?
2547    if [ ${status} -gt 0 ] ; then
2548      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2549      cat out_rsync
2550      \rm out_rsync
2551      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2552      sleep $DELAI
2553    else
2554      \rm out_rsync
2555      break
2556    fi
2557    (( i = i + 1 ))
2558  done
2559
2560  if [ ${status} -gt 0 ] ; then
2561    echo "IGCM_sys_ncwa : ncwa error"
2562    IGCM_debug_Exit "ncwa"
2563  fi
2564
2565  IGCM_debug_PopStack "IGCM_sys_ncwa"
2566}
2567
2568##############################################################
2569# CDO OPERATOR
2570
2571#D-#==================================================
2572#D-function IGCM_sys_cdo
2573#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2574#D-* Examples:
2575#D-
2576function IGCM_sys_cdo {
2577  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2578  if ( $DEBUG_sys ) ; then
2579    echo "IGCM_sys_cdo :" $@
2580  fi
2581
2582  typeset status
2583
2584  \cdo $@ > out_rsync 2>&1
2585  status=$?
2586  if [ ${status} -gt 0 ] ; then
2587    echo "IGCM_sys_cdo : error code ${status}"
2588    cat out_rsync
2589    \rm out_rsync
2590    IGCM_debug_PopStack "IGCM_sys_cdo"
2591    return 1
2592  else
2593    IGCM_debug_PopStack "IGCM_sys_cdo"
2594    return 0
2595  fi
2596
2597  IGCM_debug_PopStack "IGCM_sys_cdo"
2598}
Note: See TracBrowser for help on using the repository browser.