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

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