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

Last change on this file since 1150 was 1150, checked in by sdipsl, 9 years ago

adressing #242
message 2000 and 3000 (pushstack and popstack) has been turned off for the moment to ease downstream processing

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Revision Author Date
File size: 82.5 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    ARCHIVE=${config_UserChoices_ARCHIVE}
173  else
174    #====================================================
175    #- ARCHIVE (dedicated to large files)
176    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    STORAGE=${config_UserChoices_STORAGE}
183  else
184    #====================================================
185    #- STORAGE (dedicated to small/medium files)
186    STORAGE=${WORKDIR}
187  fi
188
189  if [ X${config_UserChoices_SpaceName} = XTEST ]; then
190    #====================================================
191    #- R_OUT
192    R_OUT=${WORKDIR}/IGCM_OUT
193
194    #====================================================
195    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
196    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    R_OUT=${ARCHIVE}/IGCM_OUT
204
205    #====================================================
206    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
207    R_FIG=${ARCHIVE}/IGCM_OUT
208  fi
209
210  #====================================================
211  #- R_BUF (ONLY FOR double copy an scratch)
212  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  RUN_DIR_PATH=${RUN_DIR_PATH} /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 >${RUN_DIR_PATH}/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
324
325  RUN_DIR_PATH=${RUN_DIR_PATH} /bin/ksh <${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/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-
565function 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-
587#function 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-
623function 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-
645#function 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 > ${RUN_DIR_PATH}/out_command.$$ 2>&1 ; status=$? ; cd - ;
764
765  cat ${RUN_DIR_PATH}/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'} ${RUN_DIR_PATH}/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} > ${RUN_DIR_PATH}/out_command.$$ 2>&1
941  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/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 $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
965  \cp $@ >> ${RUN_DIR_PATH}/out_command.$$ 2>&1
966  status=$?
967
968  if [ ${status} -gt 0 ] ; then
969    echo "IGCM_sys_Cp : error code ${status}"
970    cat ${RUN_DIR_PATH}/out_command.$$
971    IGCM_debug_Exit "IGCM_sys_Cp"
972  else
973    \rm ${RUN_DIR_PATH}/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 $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1036    \mv $@ >> ${RUN_DIR_PATH}/out_command.$$ 2>&1
1037    status=$?
1038
1039    if [ ${status} -gt 0 ] ; then
1040      echo "IGCM_sys_Mv : error code ${status}"
1041      cat ${RUN_DIR_PATH}/out_command.$$
1042      IGCM_debug_Exit "IGCM_sys_Mv"
1043    else
1044      \rm ${RUN_DIR_PATH}/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 > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1077      status=$?
1078    else
1079      \cp -r $1 $2 > ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/out_command.$$
1086      IGCM_debug_Exit "IGCM_sys_Put_Dir"
1087    else
1088      \rm ${RUN_DIR_PATH}/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 > ${RUN_DIR_PATH}/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 > ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/out_command.$$
1144        IGCM_debug_Exit "IGCM_sys_Get_Dir"
1145      else
1146        \rm ${RUN_DIR_PATH}/out_command.$$
1147      fi
1148    fi
1149    if [ ${status} -gt 0 ] ; then
1150      echo "IGCM_sys_Get_Dir : error."
1151      cat ${RUN_DIR_PATH}/out_command.$$
1152      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1153    else
1154      \rm ${RUN_DIR_PATH}/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 > ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/out_command.$$
1200      IGCM_debug_Exit "IGCM_sys_Get_Master"
1201    else
1202      \rm ${RUN_DIR_PATH}/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 > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1242      status=$?
1243    else
1244      IGCM_sys_MkdirArchive $( dirname $2 )
1245      \cp $1 $2 > ${RUN_DIR_PATH}/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} > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1252#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${RUN_DIR_PATH}/out_command.$$ 2>&1
1253
1254#       #RSYNC WITH NFS USE
1255#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1256#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${RUN_DIR_PATH}/out_command.$$ 2>&1
1257
1258#       status=$?
1259#       IGCM_sys_Rsync_out $status
1260
1261#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/out_command.$$
1267      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1268    else
1269      \rm ${RUN_DIR_PATH}/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 > ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/out_command.$$
1308      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1309    else
1310      \rm ${RUN_DIR_PATH}/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 > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1361      status=$?
1362    else
1363      IGCM_sys_MkdirArchive $( dirname $2 )
1364      \cp $1 $2 > ${RUN_DIR_PATH}/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} > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1371#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${RUN_DIR_PATH}/out_command.$$ 2>&1
1372
1373#       #RSYNC WITH NFS USE
1374#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1375#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${RUN_DIR_PATH}/out_command.$$ 2>&1
1376
1377#       status=$?
1378#       IGCM_sys_Rsync_out $status
1379
1380#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/out_command.$$
1386      IGCM_debug_Exit "IGCM_sys_Put_Out"
1387    else
1388      \rm ${RUN_DIR_PATH}/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 > ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/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} > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1524      status=$?
1525    else
1526      \cp ${dm_liste[*]} ${DEST} > ${RUN_DIR_PATH}/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} > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1532#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> ${RUN_DIR_PATH}/out_command.$$ 2>&1
1533
1534#       #RSYNC WITH NFS USE
1535#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1536#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> ${RUN_DIR_PATH}/out_command.$$ 2>&1
1537
1538#       status=$?
1539#       IGCM_sys_Rsync_out $status
1540
1541#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/out_command.$$
1547      IGCM_debug_Exit "IGCM_sys_Get"
1548    else
1549      \rm ${RUN_DIR_PATH}/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} >> ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/out_command.$$
1603          \rm ${RUN_DIR_PATH}/out_command.$$
1604          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1605        else
1606          \rm ${RUN_DIR_PATH}/out_command.$$
1607        fi
1608      done
1609    else
1610      i=0
1611      while [ $i -lt $NB_ESSAI ] ; do
1612        \cp ${buf_liste} ${DEST} >> ${RUN_DIR_PATH}/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 ${RUN_DIR_PATH}/out_command.$$
1626        \rm ${RUN_DIR_PATH}/out_command.$$
1627        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1628      else
1629        \rm ${RUN_DIR_PATH}/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  # NASTY HACK. We force /tmp here. This function is called only from the front-end and interactively.
1702  RUN_DIR_PATH=/tmp IGCM_sys_Get ${1} .
1703  eval ${2}=$( cdo showyear $( basename ${1} ) 2> /dev/null | gawk '{ print $NF }' )
1704  # Need to erase this file to avoid collision (permission denied getting file) between users on the front-end
1705  IGCM_sys_Rm -f $( basename ${1} )
1706  IGCM_sys_Cd -
1707
1708  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
1709}
1710
1711#D-#==================================================
1712#D-function IGCM_sys_Put_Dods
1713#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1714#D-* Examples:
1715#D-
1716function IGCM_sys_Put_Dods {
1717  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1718  if ( $DEBUG_sys ) ; then
1719    echo "IGCM_sys_Put_Dods :" $@
1720  fi
1721  if [ $DRYRUN = 0 ]; then
1722    # We take our time on that
1723    sleep 10
1724    IGCM_sys_TestDirArchive ${R_SAVE}/${1}
1725    if [ $? != 0 ] ; then
1726      echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
1727      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1728      return
1729    fi
1730
1731    typeset status
1732    #
1733    rsh ${STOREHOST} exec /bin/ksh <<EOF
1734          cd ${R_SAVE}
1735          /arch/local/bin/dods_rm DODS/pub/${LOGIN}/${R_DODS}/${1} > /dev/null 2>&1
1736          /bin/chmod -R u+w ${R_SAVE}/${1}
1737          /arch/local/bin/dods_cp ${1} DODS/pub/${LOGIN}/${R_DODS} > /dev/null 2>&1
1738          /bin/chmod -R +rX ${R_SAVE}/${1}
1739          /bin/chmod -R u+w ${R_SAVE}/${1}
1740EOF
1741    status=$?
1742
1743    if [ ${status} -gt 0 ] ; then
1744      echo "IGCM_sys_Put_Dods : error."
1745      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1746    fi
1747  fi
1748  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1749}
1750
1751##############################################################
1752# REBUILD OPERATOR
1753
1754#D-#==================================================
1755#D-function IGCM_sys_rebuild
1756#D-* Purpose: rebuild parallel files
1757#D-* Examples:
1758#D-
1759function IGCM_sys_rebuild {
1760  IGCM_debug_PushStack "IGCM_sys_rebuild" $@
1761  if ( $DEBUG_sys ) ; then
1762    echo "IGCM_sys_rebuild :" $@
1763  fi
1764
1765  typeset NB_ESSAI DELAI status i firstArg
1766  # number of tentative
1767  NB_ESSAI=3
1768  # time delay between tentative
1769  DELAI=2
1770
1771  i=0
1772  while [ $i -lt $NB_ESSAI ] ; do
1773    /smphome/rech/psl/rpsl035/bin/rebuild -f -o $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
1774    status=$?
1775    if [ ${status} -gt 0 ] ; then
1776      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1777      cat ${RUN_DIR_PATH}/out_command.$$
1778      \rm ${RUN_DIR_PATH}/out_command.$$
1779      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1780      firstArg=${1}
1781      \rm ${firstArg}
1782      sleep $DELAI
1783    else
1784      \rm ${RUN_DIR_PATH}/out_command.$$
1785      break
1786    fi
1787    (( i = i + 1 ))
1788  done
1789
1790  if [ ${status} -gt 0 ] ; then
1791    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1792    IGCM_debug_Exit "rebuild"
1793  fi
1794
1795  IGCM_debug_PopStack "IGCM_sys_rebuild"
1796}
1797
1798#D-#==================================================
1799#D-function IGCM_sys_rebuild_station
1800#D-* Purpose: rebuild parallel files describing station
1801#D-* Examples:
1802#D-
1803function IGCM_sys_rebuild_station {
1804  IGCM_debug_PushStack "IGCM_sys_rebuild_station" $@
1805  typeset i list_opt file_in file_out prefix_invert list_invert
1806  if ( $DEBUG_sys ) ; then
1807    echo "IGCM_sys_rebuild_station :" $@
1808  fi
1809  list_opt=$@
1810
1811  # Invert Axis : t,x -> x,t
1812  #               t,pres,x -> x,t,pres
1813  # So that we can concatenate along x
1814  i=0
1815  for file_in in ${list_opt} ; do
1816    (( i = i + 1))
1817    [ ${i} = 1 ] && file_out=${file_in} && continue
1818    # detect time counter and do the job only if present
1819    var_unlim=$(ncdump -h ${file_in} | grep UNLIMITED | cut -d ' ' -f 1 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
1820    if [ X${var_unlim} = Xtime_counter ] ; then
1821      prefix_invert=$( basename ${file_in} .nc )
1822      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1823      list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1824    fi
1825  done
1826
1827  # Concatenate
1828  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1829
1830  # Re-ivert file
1831  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1832
1833  # Station re-ordering is too expansive to be run within libIGCM
1834  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1835  # This re-ordering must be done "in memory" by the cmorization process
1836  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1837  # BEGIN reordering
1838
1839  # Only LMDZ text output contains the exact ordering of the station.
1840  # We isolate this in the code below:
1841  #  0  38  -157.5000000000000  70.98591549295774
1842  #  0  54  27.49999999999999   67.18309859154928
1843  #  0  56  -62.50000000000001  82.39436619718309
1844  #  0  79  12.49999999999999   78.59154929577466
1845  #  0  116 -165.0000000000000  76.05633802816901
1846  #  0  117 130.0000000000000   70.98591549295774
1847  #  0  118 110.0000000000000   87.46478873239437
1848  #  1  40  4.999999999999995   51.97183098591550
1849#  typeset iStation iProc list_opt file_in file_out prefix_invert
1850#  typeset -Z4 j4
1851#  typeset -Z3 j3
1852
1853#  unset list_opt
1854#  set +A list_opt $@
1855
1856  # Filename after rebuild
1857#  file_out=${list_opt[0]}
1858  # Prefix of output files
1859#  prefix_invert=$( basename ${file_out} .nc )
1860  # Number of procs
1861#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1862
1863#  iProc=0
1864#  while [ ${iProc} -lt ${num_proc} ] ; do
1865    # Array containing Station as a number
1866#    unset proc_stn
1867#    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}' )
1868    # Number of stations produced by processor proc
1869#    stationLast=${#proc_stn[*]}
1870    # Proc number on 4 digits
1871#    j4=${iProc}
1872    # Init
1873#    iStation=0
1874#    while [ ${iStation} -lt ${stationLast} ] ; do
1875      # Station number on 3 digits
1876#      j3=${proc_stn[${iStation}]}
1877      # Extract station
1878      # Invert Axis : t,x -> x,t
1879      #               t,pres,x -> x,t,pres
1880      # So that we can concatenate along x
1881#      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
1882#      (( iStation = iStation + 1 ))
1883#    done
1884#    (( iProc = iProc + 1 ))
1885#  done
1886
1887  # Concatenate all station along x
1888#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1889
1890  # Re-invert file
1891#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1892
1893  # END reordering
1894
1895  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1896}
1897
1898############################################################
1899# Activate Running Environnment Variables
1900
1901#D-#==================================================
1902#D-function IGCM_sys_desactiv_variables
1903#D-* Purpose: set environement variables prior to execution
1904#D-* Examples:
1905#D-
1906function IGCM_sys_activ_variables {
1907  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1908  if ( $DEBUG_sys ) ; then
1909    echo "IGCM_sys_activ_variables"
1910  fi
1911
1912# --------------------------------------------------------------------
1913#D- MPI specifications
1914# --------------------------------------------------------------------
1915
1916# --------------------------------------------------------------------
1917#D- Other specifications
1918# --------------------------------------------------------------------
1919
1920  ulimit -s unlimited
1921## to be done only one time
1922## export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/smplocal/pub/NetCDF/4.1.3/lib:/smplocal/pub/HDF5/1.8.9/seq/lib
1923##  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
1924  IGCM_debug_Print 1 "set LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
1925
1926  export MP_STDOUTMODE=combined
1927  IGCM_debug_Print 1 "set MP_STDOUTMODE=${MP_STDOUTMODE}"
1928
1929## fix to reduce memory usage. Required since 2014/22/04. On ada IDRIS.
1930  export MP_EUILIBPATH=/smplocal/lib/ibmhpc/pe12012/ppe.pami/gnu/lib64/pami64
1931  IGCM_debug_Print 1 "set MP_EUILIBPATH=${MP_EUILIBPATH}"
1932
1933  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1934}
1935
1936############################################################
1937# Desactivate Running Environnment Variables
1938
1939#D-#==================================================
1940#D-function IGCM_sys_desactiv_variables
1941#D-* Purpose: unset environement variables after execution
1942#D-* Examples:
1943#D-
1944function IGCM_sys_desactiv_variables {
1945  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1946  if ( $DEBUG_sys ) ; then
1947    echo "IGCM_sys_desactiv_variables"
1948  fi
1949# --------------------------------------------------------------------
1950#D- MPI specifications
1951# --------------------------------------------------------------------
1952
1953# --------------------------------------------------------------------
1954#D- Other specifications
1955# --------------------------------------------------------------------
1956
1957  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1958}
1959
1960############################################################
1961# Build MPI/OMP scripts run file (dummy function)
1962
1963#D-#==================================================
1964#D-function IGCM_sys_build_run_file
1965#D-* Purpose: build run file (deprecated)
1966#D-* Examples:
1967#D-
1968function IGCM_sys_build_run_file {
1969
1970  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1971
1972}
1973
1974############################################################
1975# Build MPI/OMP scripts
1976
1977#D-#==================================================
1978#D-function IGCM_sys_build_execution_scripts
1979#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1980#D-* Examples:
1981#D-
1982function IGCM_sys_build_execution_scripts
1983{
1984  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1985  if ( $DEBUG_sys ) ; then
1986    echo "IGCM_sys_build_execution_scripts " $@
1987  fi
1988
1989  EXECUTION=${HOST_MPIRUN_COMMAND}
1990
1991  if ( ${OK_PARA_MPMD} ) ; then
1992
1993    if [ -f run_file ] ; then
1994      IGCM_sys_Rm -f run_file
1995    fi
1996    touch run_file
1997
1998# run_file construction
1999
2000# Then first loop on the components for the coupler ie oasis
2001
2002### the coupler ie oasis must be the first one
2003    for comp in ${config_ListOfComponents[*]} ; do
2004
2005      eval ExeNameIn=\${config_Executable_${comp}[0]}
2006      eval ExeNameOut=\${config_Executable_${comp}[1]}
2007
2008      # for CPL component only
2009      if [ "X${comp}" = "XCPL" ] ; then
2010
2011        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2012        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2013
2014        if ( ${OK_PARA_MPI} ) ; then
2015          (( mpi_count = 1 ))
2016          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
2017            echo "./${ExeNameOut}" >> run_file
2018            (( mpi_count = mpi_count + 1 ))
2019          done
2020        else
2021          echo "./${ExeNameOut} " >> run_file
2022        fi
2023      fi
2024    done
2025
2026# Then second loop on the components
2027
2028    for comp in ${config_ListOfComponents[*]} ; do
2029
2030      eval ExeNameIn=\${config_Executable_${comp}[0]}
2031      eval ExeNameOut=\${config_Executable_${comp}[1]}
2032
2033      # Only if we really have an executable for the component and not the coupler ie oasis:
2034      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
2035
2036        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2037        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2038
2039        if ( ${OK_PARA_MPI} ) ; then
2040          (( mpi_count = 1 ))
2041          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
2042            if ( ${OK_PARA_OMP} ) ; then
2043              # Check if the number of threads is correct
2044              case ${comp_proc_omp_loc} in
2045              1|2)
2046                IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
2047                ;;
2048              4|8|16)
2049                IGCM_debug_Exit "ERROR with OMP parameters !"
2050                IGCM_debug_Print 2 "Beware : ${comp_proc_omp_loc} is too much for MPMD mode"
2051                IGCM_debug_Print 2 "You will use more CPU than needed"
2052                IGCM_debug_Verif_Exit
2053                ;;
2054              *)
2055                IGCM_debug_Exit "ERROR with OMP parameters !"
2056                IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
2057                IGCM_debug_Print 2 "Only 2,4,8,16 as number of OMP threads are possible "
2058                IGCM_debug_Verif_Exit
2059                ;;
2060              esac
2061              echo "env OMP_NUM_THREADS=$comp_proc_omp_loc ./${ExeNameOut}" >> run_file
2062            else
2063              echo "./${ExeNameOut}" >> run_file
2064            fi
2065            (( mpi_count = mpi_count + 1 ))
2066          done
2067        else
2068          echo "./${ExeNameOut} " >> run_file
2069        fi
2070        if ( ${OK_PARA_OMP} ) ; then
2071          export KMP_STACKSIZE=200m
2072        fi
2073      fi
2074    done
2075
2076    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
2077
2078    IGCM_sys_Chmod u+x run_file
2079    if ( $DEBUG_sys ) ; then
2080      echo "run_file contains : "
2081      cat run_file
2082    fi
2083
2084  else # Only one executable. launch it.
2085
2086    for comp in ${config_ListOfComponents[*]} ; do
2087
2088      # Only if we really have an executable for the component :
2089      eval ExeNameOut=\${config_Executable_${comp}[1]}
2090      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2091
2092        if ( ${OK_PARA_OMP} ) ; then
2093          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2094          export KMP_STACKSIZE=200m
2095          #export KMP_LIBRARY=turnaround
2096          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2097          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2098          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2099        fi
2100
2101        EXECUTION="${HOST_MPIRUN_COMMAND} ./${ExeNameOut}"
2102      fi
2103
2104    done
2105
2106  fi
2107
2108  IGCM_debug_Print 1 "sys ada : execution command is "
2109  IGCM_debug_Print 1 "$EXECUTION"
2110
2111  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2112}
2113
2114#D-#==================================================
2115#D-function IGCM_sys_check_path
2116#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
2117#D-* do not point to an important use directory. Stop immediately in that case.
2118#D-* Examples:
2119#D-
2120function IGCM_sys_check_path {
2121  IGCM_debug_PushStack "IGCM_sys_check_path"
2122  if ( $DEBUG_sys ) ; then
2123    echo "IGCM_sys_check_path"
2124  fi
2125
2126  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${WORKDIR} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
2127    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
2128    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
2129    IGCM_debug_Exit "This will stop the job"
2130  fi
2131  IGCM_debug_PopStack "IGCM_sys_check_path"
2132}
2133
2134#D-#==================================================
2135#D-function IGCM_sys_check_quota
2136#D-* Purpose: check user quota. Stop the simulation if quota above 90%
2137#D-* Examples:
2138#D-
2139function IGCM_sys_check_quota {
2140  IGCM_debug_PushStack "IGCM_sys_check_quota"
2141  if ( $DEBUG_sys ) ; then
2142    echo "IGCM_sys_check_quota"
2143  fi
2144  # Limit of quota (in %)
2145  limit_quota=90
2146
2147  # Check of the volume
2148  volume_quota=$(quota_u -w 2>/dev/null| grep 'Quota soft' | gawk '{print $5}')
2149  if [ ! X${volume_quota} = X ] ; then
2150    quota_volume=${volume_quota%%\%}
2151#    echo $quota_volume
2152    if [ $(echo "${quota_volume} > ${limit_quota}" | bc) -eq 1 ] ; then
2153      IGCM_debug_Print 1 "Please, check your quota of volume on workgpfs"
2154      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2155      IGCM_debug_Print 1 "Use the quota_u -w command to check"
2156      IGCM_debug_Print 1 "You must have more than 10% available to run"
2157      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2158      IGCM_debug_Verif_Exit
2159    fi
2160
2161  fi
2162  IGCM_debug_PopStack "IGCM_sys_check_quota"
2163}
2164
2165#D-#==================================================
2166#D-function IGCM_sys_GetJobID
2167#D-* Purpose: Check if job_name is currently
2168#D-  running or in queue
2169#D-* Examples: IGCM_sys_GetJobID ${JobName} NbRun
2170#D-
2171function IGCM_sys_GetJobID {
2172  IGCM_debug_PushStack "IGCM_sys_GetJobID"
2173  if ( $DEBUG_sys ) ; then
2174    echo "IGCM_sys_GetJobID"
2175  fi
2176
2177  # Print only the full (-W) JobID (%id) and JobName (%jn)
2178  ID=$( llq -u $2 -W -f %id %jn | \
2179        gawk -v JobName=$1 '( $NF ~ JobName ) { print $1 }' )
2180
2181  eval ${3}=${ID}
2182
2183  IGCM_debug_PopStack "IGCM_sys_GetJobID"
2184}
2185
2186#D-#==================================================
2187#D-function IGCM_sys_CountJobInQueue
2188#D-* Purpose: Check if job_name is currently
2189#D-  running or in queue
2190#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
2191#D-
2192function IGCM_sys_CountJobInQueue {
2193  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
2194  if ( $DEBUG_sys ) ; then
2195    echo "IGCM_sys_CountJobInQueue"
2196  fi
2197
2198  # Print only the full (-W) JobName (%jn)
2199  NbRun=$( llq -W -f %jn | grep -c "$1" )
2200
2201  eval ${2}=${NbRun}
2202
2203  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
2204}
2205
2206#D-#==================================================
2207#D-function IGCM_sys_ListJobInQueue
2208#D-* Purpose: Check if job_name is currently
2209#D-  running or in queue
2210#D-* Examples: IGCM_sys_ListJobInQueue ${User} JobNameList
2211#D-
2212function IGCM_sys_ListJobInQueue {
2213  IGCM_debug_PushStack "IGCM_sys_ListJobInQueue"
2214  if ( $DEBUG_sys ) ; then
2215    echo "IGCM_sys_ListJobInQueue"
2216  fi
2217
2218  # With -W option, column width is as large as necessary
2219  set -A JobList $( llq -u $1 -W -f %jn | head -n -2 | tail -n +3 | \
2220                    gawk '( $1 != /TS/      && \
2221                            $1 !~ /PACK/    && \
2222                            $1 !~ /REBUILD/ && \
2223                            $1 !~ /pack/ )     \
2224                          { print $1 }' | sed -e "s/\(.*\)\.[0-9]*/\1/" )
2225
2226  eval set -A ${2} ${JobList[*]}
2227
2228  IGCM_debug_PopStack "IGCM_sys_ListJobInQueue"
2229}
2230
2231##############################################################
2232# NCO OPERATOR
2233
2234#D-#==================================================
2235#D-function IGCM_sys_ncap2
2236#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2237#D-* Examples:
2238#D-
2239function IGCM_sys_ncap2 {
2240  IGCM_debug_PushStack "IGCM_sys_ncap2" $@
2241  if ( $DEBUG_sys ) ; then
2242    echo "IGCM_sys_ncap2 :" $@
2243  fi
2244
2245  typeset NB_ESSAI DELAI status i
2246  # number of tentative
2247  NB_ESSAI=3
2248  # time delay between tentative
2249  DELAI=2
2250
2251  i=0
2252  while [ $i -lt $NB_ESSAI ] ; do
2253    ncap2 -C "$@" > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2254    status=$?
2255    if [ ${status} -gt 0 ] ; then
2256      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2257      cat ${RUN_DIR_PATH}/out_command.$$
2258      \rm ${RUN_DIR_PATH}/out_command.$$
2259      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2260      sleep $DELAI
2261    else
2262      \rm ${RUN_DIR_PATH}/out_command.$$
2263      break
2264    fi
2265    (( i = i + 1 ))
2266  done
2267
2268  if [ ${status} -gt 0 ] ; then
2269    echo "IGCM_sys_ncap2 : ncap2 error"
2270    IGCM_debug_Exit "ncap2"
2271  fi
2272
2273  IGCM_debug_PopStack "IGCM_sys_ncap2"
2274}
2275
2276#D-#==================================================
2277#D-function IGCM_sys_ncatted
2278#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2279#D-* Examples:
2280#D-
2281function IGCM_sys_ncatted {
2282  IGCM_debug_PushStack "IGCM_sys_ncatted" $@
2283  if ( $DEBUG_sys ) ; then
2284    echo "IGCM_sys_ncatted :" $@
2285  fi
2286
2287  typeset NB_ESSAI DELAI status i
2288  # number of tentative
2289  NB_ESSAI=3
2290  # time delay between tentative
2291  DELAI=2
2292
2293  i=0
2294  while [ $i -lt $NB_ESSAI ] ; do
2295    ncatted "$@" > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2296    status=$?
2297    if [ ${status} -gt 0 ] ; then
2298      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2299      cat ${RUN_DIR_PATH}/out_command.$$
2300      \rm ${RUN_DIR_PATH}/out_command.$$
2301      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2302      sleep $DELAI
2303    else
2304      \rm ${RUN_DIR_PATH}/out_command.$$
2305      break
2306    fi
2307    (( i = i + 1 ))
2308  done
2309
2310  if [ ${status} -gt 0 ] ; then
2311    echo "IGCM_sys_ncatted : ncatted error"
2312    IGCM_debug_Exit "ncatted"
2313  fi
2314
2315  IGCM_debug_PopStack "IGCM_sys_ncatted"
2316}
2317
2318#D-#==================================================
2319#D-function IGCM_sys_ncbo
2320#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2321#D-* Examples:
2322#D-
2323function IGCM_sys_ncbo {
2324  IGCM_debug_PushStack "IGCM_sys_ncbo" $@
2325  if ( $DEBUG_sys ) ; then
2326    echo "IGCM_sys_ncbo :" $@
2327  fi
2328
2329  typeset NB_ESSAI DELAI status i
2330  # number of tentative
2331  NB_ESSAI=3
2332  # time delay between tentative
2333  DELAI=2
2334
2335  i=0
2336  while [ $i -lt $NB_ESSAI ] ; do
2337    ncbo -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2338    status=$?
2339    if [ ${status} -gt 0 ] ; then
2340      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2341      cat ${RUN_DIR_PATH}/out_command.$$
2342      \rm ${RUN_DIR_PATH}/out_command.$$
2343      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2344      sleep $DELAI
2345    else
2346      \rm ${RUN_DIR_PATH}/out_command.$$
2347      break
2348    fi
2349    (( i = i + 1 ))
2350  done
2351
2352  if [ ${status} -gt 0 ] ; then
2353    echo "IGCM_sys_ncbo : ncbo error"
2354    IGCM_debug_Exit "ncbo"
2355  fi
2356
2357  IGCM_debug_PopStack "IGCM_sys_ncbo"
2358}
2359
2360#D-#==================================================
2361#D-function IGCM_sys_ncdif
2362#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2363#D-* Examples:
2364#D-
2365function IGCM_sys_ncdiff {
2366  IGCM_debug_PushStack "IGCM_sys_ncdiff" $@
2367  if ( $DEBUG_sys ) ; then
2368    echo "IGCM_sys_ncdiff :" $@
2369  fi
2370
2371  typeset NB_ESSAI DELAI status i
2372  # number of tentative
2373  NB_ESSAI=3
2374  # time delay between tentative
2375  DELAI=2
2376
2377  i=0
2378  while [ $i -lt $NB_ESSAI ] ; do
2379    ncdiff -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2380    status=$?
2381    if [ ${status} -gt 0 ] ; then
2382      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2383      cat ${RUN_DIR_PATH}/out_command.$$
2384      \rm ${RUN_DIR_PATH}/out_command.$$
2385      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2386      sleep $DELAI
2387    else
2388      \rm ${RUN_DIR_PATH}/out_command.$$
2389      break
2390    fi
2391    (( i = i + 1 ))
2392  done
2393
2394  if [ ${status} -gt 0 ] ; then
2395    echo "IGCM_sys_ncdiff : ncdiff error"
2396    IGCM_debug_Exit "ncdiff"
2397  fi
2398
2399  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2400}
2401
2402#D-#==================================================
2403#D-function IGCM_sys_ncea
2404#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2405#D-* Examples:
2406#D-
2407function IGCM_sys_ncea {
2408  IGCM_debug_PushStack "IGCM_sys_ncea" $@
2409  if ( $DEBUG_sys ) ; then
2410    echo "IGCM_sys_ncea :" $@
2411  fi
2412
2413  typeset NB_ESSAI DELAI status i
2414  # number of tentative
2415  NB_ESSAI=3
2416  # time delay between tentative
2417  DELAI=2
2418
2419  i=0
2420  while [ $i -lt $NB_ESSAI ] ; do
2421    ncea -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2422    status=$?
2423    if [ ${status} -gt 0 ] ; then
2424      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2425      cat ${RUN_DIR_PATH}/out_command.$$
2426      \rm ${RUN_DIR_PATH}/out_command.$$
2427      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2428      sleep $DELAI
2429    else
2430      \rm ${RUN_DIR_PATH}/out_command.$$
2431      break
2432    fi
2433    (( i = i + 1 ))
2434  done
2435
2436  if [ ${status} -gt 0 ] ; then
2437    echo "IGCM_sys_ncea : ncea error"
2438    IGCM_debug_Exit "ncea"
2439  fi
2440
2441  IGCM_debug_PopStack "IGCM_sys_ncea"
2442}
2443
2444#D-#==================================================
2445#D-function IGCM_sys_ncecat
2446#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2447#D-* Examples:
2448#D-
2449function IGCM_sys_ncecat {
2450  IGCM_debug_PushStack "IGCM_sys_ncecat" $@
2451  if ( $DEBUG_sys ) ; then
2452    echo "IGCM_sys_ncecat :" $@
2453  fi
2454
2455  typeset NB_ESSAI DELAI status i
2456  # number of tentative
2457  NB_ESSAI=3
2458  # time delay between tentative
2459  DELAI=2
2460
2461  i=0
2462  while [ $i -lt $NB_ESSAI ] ; do
2463    ncecat -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2464    status=$?
2465    if [ ${status} -gt 0 ] ; then
2466      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2467      cat ${RUN_DIR_PATH}/out_command.$$
2468      \rm ${RUN_DIR_PATH}/out_command.$$
2469      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2470      sleep $DELAI
2471    else
2472      \rm ${RUN_DIR_PATH}/out_command.$$
2473      break
2474    fi
2475    (( i = i + 1 ))
2476  done
2477
2478  if [ ${status} -gt 0 ] ; then
2479    echo "IGCM_sys_ncecat : ncecat error"
2480    IGCM_debug_Exit "ncecat"
2481  fi
2482
2483  IGCM_debug_PopStack "IGCM_sys_ncecat"
2484}
2485
2486#D-#==================================================
2487#D-function IGCM_sys_ncflint
2488#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2489#D-* Examples:
2490#D-
2491function IGCM_sys_ncflint {
2492  IGCM_debug_PushStack "IGCM_sys_ncflint" $@
2493  if ( $DEBUG_sys ) ; then
2494    echo "IGCM_sys_ncflint :" $@
2495  fi
2496
2497  typeset NB_ESSAI DELAI status i
2498  # number of tentative
2499  NB_ESSAI=3
2500  # time delay between tentative
2501  DELAI=2
2502
2503  i=0
2504  while [ $i -lt $NB_ESSAI ] ; do
2505    ncflint -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2506    status=$?
2507    if [ ${status} -gt 0 ] ; then
2508      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2509      cat ${RUN_DIR_PATH}/out_command.$$
2510      \rm ${RUN_DIR_PATH}/out_command.$$
2511      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2512      sleep $DELAI
2513    else
2514      \rm ${RUN_DIR_PATH}/out_command.$$
2515      break
2516    fi
2517    (( i = i + 1 ))
2518  done
2519
2520  if [ ${status} -gt 0 ] ; then
2521    echo "IGCM_sys_ncflint : ncflint error"
2522    IGCM_debug_Exit "ncflint"
2523  fi
2524
2525  IGCM_debug_PopStack "IGCM_sys_ncflint"
2526}
2527
2528#D-#==================================================
2529#D-function IGCM_sys_ncks
2530#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2531#D-* Examples:
2532#D-
2533function IGCM_sys_ncks {
2534  IGCM_debug_PushStack "IGCM_sys_ncks" $@
2535  if ( $DEBUG_sys ) ; then
2536    echo "IGCM_sys_ncks :" $@
2537  fi
2538
2539  typeset NB_ESSAI DELAI status i
2540  # number of tentative
2541  NB_ESSAI=3
2542  # time delay between tentative
2543  DELAI=2
2544
2545  i=0
2546  while [ $i -lt $NB_ESSAI ] ; do
2547    ncks -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2548    status=$?
2549    if [ ${status} -gt 0 ] ; then
2550      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2551      cat ${RUN_DIR_PATH}/out_command.$$
2552      \rm ${RUN_DIR_PATH}/out_command.$$
2553      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2554      sleep $DELAI
2555    else
2556      \rm ${RUN_DIR_PATH}/out_command.$$
2557      break
2558    fi
2559    (( i = i + 1 ))
2560  done
2561
2562  if [ ${status} -gt 0 ] ; then
2563    echo "IGCM_sys_ncks : ncks error"
2564    IGCM_debug_Exit "ncks"
2565  fi
2566
2567  IGCM_debug_PopStack "IGCM_sys_ncks"
2568}
2569
2570#D-#==================================================
2571#D-function IGCM_sys_ncpdq
2572#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2573#D-* Examples:
2574#D-
2575function IGCM_sys_ncpdq {
2576  IGCM_debug_PushStack "IGCM_sys_ncpdq" $@
2577  if ( $DEBUG_sys ) ; then
2578    echo "IGCM_sys_ncpdq :" $@
2579  fi
2580
2581  typeset NB_ESSAI DELAI status i
2582  # number of tentative
2583  NB_ESSAI=3
2584  # time delay between tentative
2585  DELAI=2
2586
2587  i=0
2588  while [ $i -lt $NB_ESSAI ] ; do
2589    ncpdq -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2590    status=$?
2591    if [ ${status} -gt 0 ] ; then
2592      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2593      cat ${RUN_DIR_PATH}/out_command.$$
2594      \rm ${RUN_DIR_PATH}/out_command.$$
2595      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2596      sleep $DELAI
2597    else
2598      \rm ${RUN_DIR_PATH}/out_command.$$
2599      break
2600    fi
2601    (( i = i + 1 ))
2602  done
2603
2604  if [ ${status} -gt 0 ] ; then
2605    echo "IGCM_sys_ncpdq : ncpdq error"
2606    IGCM_debug_Exit "ncpdq"
2607  fi
2608
2609  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2610}
2611
2612#D-#==================================================
2613#D-function IGCM_sys_ncra
2614#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2615#D-* Examples:
2616#D-
2617function IGCM_sys_ncra {
2618  IGCM_debug_PushStack "IGCM_sys_ncra" $@
2619  if ( $DEBUG_sys ) ; then
2620    echo "IGCM_sys_ncra :" $@
2621  fi
2622
2623  typeset NB_ESSAI DELAI status i
2624  # number of tentative
2625  NB_ESSAI=3
2626  # time delay between tentative
2627  DELAI=2
2628
2629  i=0
2630  while [ $i -lt $NB_ESSAI ] ; do
2631    ncra -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2632    status=$?
2633    if [ ${status} -gt 0 ] ; then
2634      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2635      cat ${RUN_DIR_PATH}/out_command.$$
2636      \rm ${RUN_DIR_PATH}/out_command.$$
2637      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2638      sleep $DELAI
2639    else
2640      \rm ${RUN_DIR_PATH}/out_command.$$
2641      break
2642    fi
2643    (( i = i + 1 ))
2644  done
2645
2646  if [ ${status} -gt 0 ] ; then
2647    echo "IGCM_sys_ncra : ncra error"
2648    IGCM_debug_Exit "ncra"
2649  fi
2650
2651  IGCM_debug_PopStack "IGCM_sys_ncra"
2652}
2653
2654#D-#==================================================
2655#D-function IGCM_sys_ncrcat
2656#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2657#D-* Examples:
2658#D-
2659function IGCM_sys_ncrcat {
2660  IGCM_debug_PushStack "IGCM_sys_ncrcat" $@
2661  if ( $DEBUG_sys ) ; then
2662    echo "IGCM_sys_ncrcat :" $@
2663  fi
2664
2665  typeset NB_ESSAI DELAI status i lastArg
2666  # number of tentative
2667  NB_ESSAI=3
2668  # time delay between tentative
2669  DELAI=2
2670
2671  i=0
2672  while [ $i -lt $NB_ESSAI ] ; do
2673    ncrcat -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2674    status=$?
2675    if [ ${status} -gt 0 ] ; then
2676      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2677      cat ${RUN_DIR_PATH}/out_command.$$
2678      \rm ${RUN_DIR_PATH}/out_command.$$
2679      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2680      sleep $DELAI
2681    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" ${RUN_DIR_PATH}/out_command.$$ )" = "X" ] ; then
2682      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2683      cat ${RUN_DIR_PATH}/out_command.$$
2684      # remove files having corrupted time axis
2685      eval lastArg=\${$#}
2686      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2687      \rm ${lastArg}
2688      \rm ${RUN_DIR_PATH}/out_command.$$
2689      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2690      sleep $DELAI
2691    else
2692      \rm ${RUN_DIR_PATH}/out_command.$$
2693      break
2694    fi
2695    (( i = i + 1 ))
2696  done
2697
2698  if [ ${status} -gt 0 ] ; then
2699    echo "IGCM_sys_ncrcat : ncrcat error"
2700    #IGCM_debug_Exit "ncrcat"
2701  fi
2702
2703  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2704}
2705
2706#D-#==================================================
2707#D-function IGCM_sys_ncrename
2708#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2709#D-* Examples:
2710#D-
2711function IGCM_sys_ncrename {
2712  IGCM_debug_PushStack "IGCM_sys_ncrename" $@
2713  if ( $DEBUG_sys ) ; then
2714    echo "IGCM_sys_ncrename :" $@
2715  fi
2716
2717  typeset NB_ESSAI DELAI status i
2718  # number of tentative
2719  NB_ESSAI=3
2720  # time delay between tentative
2721  DELAI=2
2722
2723  i=0
2724  while [ $i -lt $NB_ESSAI ] ; do
2725    ncrename $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2726    status=$?
2727    if [ ${status} -gt 0 ] ; then
2728      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2729      cat ${RUN_DIR_PATH}/out_command.$$
2730      \rm ${RUN_DIR_PATH}/out_command.$$
2731      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2732      sleep $DELAI
2733    else
2734      \rm ${RUN_DIR_PATH}/out_command.$$
2735      break
2736    fi
2737    (( i = i + 1 ))
2738  done
2739
2740  if [ ${status} -gt 0 ] ; then
2741    echo "IGCM_sys_ncrename : ncrename error"
2742    IGCM_debug_Exit "ncrename"
2743  fi
2744
2745  IGCM_debug_PopStack "IGCM_sys_ncrename"
2746}
2747
2748#D-#==================================================
2749#D-function IGCM_sys_ncwa
2750#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2751#D-* Examples:
2752#D-
2753function IGCM_sys_ncwa {
2754  IGCM_debug_PushStack "IGCM_sys_ncwa" $@
2755  if ( $DEBUG_sys ) ; then
2756    echo "IGCM_sys_ncwa :" $@
2757  fi
2758
2759  typeset NB_ESSAI DELAI status i
2760  # number of tentative
2761  NB_ESSAI=3
2762  # time delay between tentative
2763  DELAI=2
2764
2765  i=0
2766  while [ $i -lt $NB_ESSAI ] ; do
2767    ncwa -C $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2768    status=$?
2769    if [ ${status} -gt 0 ] ; then
2770      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2771      cat ${RUN_DIR_PATH}/out_command.$$
2772      \rm ${RUN_DIR_PATH}/out_command.$$
2773      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2774      sleep $DELAI
2775    else
2776      \rm ${RUN_DIR_PATH}/out_command.$$
2777      break
2778    fi
2779    (( i = i + 1 ))
2780  done
2781
2782  if [ ${status} -gt 0 ] ; then
2783    echo "IGCM_sys_ncwa : ncwa error"
2784    IGCM_debug_Exit "ncwa"
2785  fi
2786
2787  IGCM_debug_PopStack "IGCM_sys_ncwa"
2788}
2789
2790##############################################################
2791# CDO OPERATOR
2792
2793#D-#==================================================
2794#D-function IGCM_sys_cdo
2795#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2796#D-* Examples:
2797#D-
2798function IGCM_sys_cdo {
2799  IGCM_debug_PushStack "IGCM_sys_cdo" $@
2800  if ( $DEBUG_sys ) ; then
2801    echo "IGCM_sys_cdo :" $@
2802  fi
2803
2804  typeset status
2805
2806  \cdo $@ > ${RUN_DIR_PATH}/out_command.$$ 2>&1
2807  status=$?
2808  if [ ${status} -gt 0 ] ; then
2809    echo "IGCM_sys_cdo : error code ${status}"
2810    cat ${RUN_DIR_PATH}/out_command.$$
2811    \rm ${RUN_DIR_PATH}/out_command.$$
2812    IGCM_debug_PopStack "IGCM_sys_cdo"
2813    return 1
2814  else
2815    IGCM_debug_PopStack "IGCM_sys_cdo"
2816    return 0
2817  fi
2818
2819  IGCM_debug_PopStack "IGCM_sys_cdo"
2820}
Note: See TracBrowser for help on using the repository browser.