source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh @ 1273

Last change on this file since 1273 was 1273, checked in by sdipsl, 9 years ago
  • Bugfix for metrics_*
  • 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: 55.2 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.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 Curie
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 user names project maxCpuTime
65# $hostname ou hostname
66typeset HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=curie
71# add default project on curie
72typeset PROJECT=$(echo ${BRIDGE_MSUB_PROJECT:=gen0826} | cut -d@ -f1 )
73# jobWarningDelay in seconds
74typeset jobWarningDelay=${BRIDGE_MSUB_MAXTIME}
75
76#D-
77#D-#==================================================
78#D-Program used in libIGCM
79#D-#==================================================
80
81# Submit command
82typeset SUBMIT=${SUBMIT:=ccc_msub}
83# rsync with path
84typeset -r RSYNC=/usr/bin/rsync
85# RSYNC_opt args to rsync
86typeset -r RSYNC_opt="-va"
87# ie storage filesystem
88typeset -r STOREHOST=${MASTER}
89typeset -r REMOTE_RSYNC=/usr/bin/rsync
90
91#====================================================
92# Set environment tools (ferret, nco, cdo, rebuild, ...)
93#====================================================
94if [ X${TaskType} = Xcomputing ] ; then
95  . /ccc/cont003/home/dsm/p86ipsl/.atlas_env_netcdf4.3.3.1_hdf5_parallel_curie_ksh > /dev/null 2>&1
96# to run with netcdf 3.6.3 ie compilation done before 17/2/2014
97# uncomment 2 lines :
98#  module unload netcdf
99#  module load netcdf/3.6.3
100else
101  . /ccc/cont003/home/dsm/p86ipsl/.atlas_env_netcdf4.3.3.1_hdf5_parallel_curie_ksh > /dev/null 2>&1
102  PCMDI_MP=/ccc/work/cont003/dsm/p86ipsl/PCMDI-MP
103  export UVCDAT_ANONYMOUS_LOG=no
104fi
105[ ! X${TaskType} = Xchecking ] && IGCM_debug_Print 1 "List of loaded modules:"
106[ ! X${TaskType} = Xchecking ] && module list
107
108export PATH=${PATH}:/ccc/cont003/home/dsm/p86ipsl/AddNoise/src_X64_CURIE/bin
109export PATH=${PATH}:/ccc/cont003/home/dsm/p86ipsl/AddPerturbation/src_X64_CURIE/bin
110export PATH=${PATH}:$( ccc_home -u p86ipsl )/rebuild/src_X64_CURIE/modipsl_v2_2_2_netcdf4.2/bin/
111
112#====================================================
113# Specific for ocean additionnal diagnostic
114export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
115export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
116
117#====================================================
118# Host specific DIRECTORIES
119#====================================================
120
121# ============ CESIUM START ============ #
122
123#====================================================
124#- Mirror libIGCM from titane to cesium if needed
125#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
126#if [ ! ${ROOTSYS} = "home" ] ; then
127#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
128#else
129#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
130#fi
131
132#====================================================
133#- libIGCM_POST
134#if ( ${MirrorlibIGCM} ) ; then
135#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
136#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
137#else
138#  typeset -r libIGCM_POST=${libIGCM}
139#fi
140
141# ============ CESIUM  END  ============ #
142
143#====================================================
144#- MirrorlibIGCM for frontend
145typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
146
147#====================================================
148#- libIGCM_POST for frontend
149typeset -r libIGCM_POST=${libIGCM}
150
151#====================================================
152#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
153typeset -r R_EXE="${MODIPSL}/bin"
154
155#====================================================
156#- SUBMIT_DIR : submission dir
157typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${BRIDGE_MSUB_PWD}}
158
159#====================================================
160#- IN
161typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
162typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/ccc/work/cont003/dsm/p24data}
163
164#====================================================
165#- RUN_DIR_PATH : Temporary working directory (=> TMP)
166typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${BRIDGE_MSUB_JOBID}_${$}}
167
168#====================================================
169#- OUTCOMMAND_PATH : tmp place to store command lines standard error and outputs
170typeset -r OUTCOMMAND_PATH=/tmp
171
172#====================================================
173#- HOST_MPIRUN_COMMAND
174typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="/usr/bin/time ccc_mprun -E-K1"}
175
176#====================================================
177#- Max number of arguments passed to nco operator or demigration command
178UNIX_MAX_LIMIT=360
179
180#====================================================
181#- set PackDefault to true on curie
182PackDefault=true
183
184#====================================================
185#- Number of core per node (max number of OpenMP task)
186NUM_COREPERNODE=8
187
188#====================================================
189#- Default number of MPI task for IPSL coupled model
190#- required for backward compatibility
191#-
192DEFAULT_NUM_PROC_OCE=5
193DEFAULT_NUM_PROC_CPL=1
194(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
195
196#D-#==================================================
197#D-function IGCM_sys_defineArchives
198#D-* Purpose:
199#D-* Define ARCHIVE : Dedicated to large files
200#D-* Define STORAGE : Dedicated to small/medium files
201#D-* Define R_OUT   : Output tree located on ARCHIVE
202#D-* Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
203#D-* Define R_BUF   : Output tree located on SCRATCHDIR hosting files waiting for rebuild or pack processes
204#D-* if SpaceName=TEST everything is stored on SCRATCHDIR
205#D-* Examples:
206#D-
207function IGCM_sys_defineArchives {
208  IGCM_debug_PushStack "IGCM_sys_defineArchives"
209
210  if [ ! X${config_UserChoices_ARCHIVE} = X ]; then
211    #====================================================
212    #- ARCHIVE (dedicated to large files)
213    ARCHIVE=${config_UserChoices_ARCHIVE}
214  else
215    #====================================================
216    #- ARCHIVE (dedicated to large files)
217    ARCHIVE=${CCCSTOREDIR}
218  fi
219
220  if [ ! X${config_UserChoices_STORAGE} = X ]; then
221    #====================================================
222    #- STORAGE (dedicated to small/medium files)
223    STORAGE=${config_UserChoices_STORAGE}
224  else
225    #====================================================
226    #- STORAGE (dedicated to small/medium files)
227    STORAGE=${CCCWORKDIR}
228  fi
229
230  if [ X${config_UserChoices_SpaceName} = XTEST ]; then
231    #====================================================
232    #- R_OUT
233    R_OUT=${SCRATCHDIR}/IGCM_OUT
234
235    #====================================================
236    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
237    R_FIG=${SCRATCHDIR}/IGCM_OUT
238
239    IGCM_debug_Print 1 "SpaceName=TEST ==> OVERRULE destination path directories"
240
241  else
242    #====================================================
243    #- R_OUT
244    R_OUT=${ARCHIVE}/IGCM_OUT
245
246    #====================================================
247    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
248    R_FIG=${STORAGE}/IGCM_OUT
249  fi
250
251  #====================================================
252  #- R_BUF (ONLY FOR double copy an scratch)
253  R_BUF=${SCRATCHDIR}/IGCM_OUT
254
255  IGCM_debug_Print 1 "R_OUT has been defined = ${R_OUT}"
256  IGCM_debug_Print 1 "R_BUF has been defined = ${R_BUF}"
257  IGCM_debug_Print 1 "R_FIG has been defined = ${R_FIG}"
258
259  IGCM_debug_PopStack "IGCM_sys_defineArchives"
260}
261
262#D-#==================================================
263#D-function IGCM_sys_RshArchive
264#D-* Purpose: Archive rsh command
265#D-* Examples:
266#D-
267function IGCM_sys_RshArchive {
268  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
269  /bin/ksh <<-EOF
270    ${@}
271EOF
272  status=$?
273  if [ ${status} -gt 0 ] ; then
274    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
275    IGCM_debug_Exit "IGCM_sys_RshArchive"
276  fi
277  IGCM_debug_PopStack "IGCM_sys_RshArchive"
278}
279
280#D-#==================================================
281#D-function IGCM_sys_RshArchive_NoError
282#D-* Purpose: Archive rsh command, without error
283#D-*          used only in monitoring.job
284#D-* Examples:
285#D-
286function IGCM_sys_RshArchive_NoError {
287  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
288  /bin/ksh <<-EOF
289    ${@} 2> /dev/null
290EOF
291  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
292}
293
294#D-#==================================================
295#D-function IGCM_sys_MkdirArchive
296#D-* Purpose: Mkdir on Archive
297#D-* Examples:
298#D-
299function IGCM_sys_MkdirArchive {
300  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
301  if ( $DEBUG_sys ) ; then
302    echo "IGCM_sys_MkdirArchive :" $@
303  fi
304  #- creation de repertoire sur le serveur fichier
305  if [ ! -d ${1} ]; then
306    \mkdir -p $1
307    status=$?
308
309    if [ ${status} -gt 0 ] ; then
310      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
311      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
312    fi
313  fi
314  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
315}
316
317#D-#==================================================
318#D-function IGCM_sys_TestDirArchive
319#D-* Purpose: Test Directory that must exists on Archive
320#D-* Examples:
321#D-
322function IGCM_sys_TestDirArchive {
323  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
324  if ( $DEBUG_sys ) ; then
325    echo "IGCM_sys_TestDirArchive :" $@
326  fi
327  typeset ExistFlag
328  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
329  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
330  return ${ExistFlag}
331}
332
333#D-#==================================================
334#D-function IGCM_sys_IsFileArchived
335#D-* Purpose: Test file that must NOT EXISTS on Archive based on filename only
336#D-* Examples:
337#D-
338function IGCM_sys_IsFileArchived {
339  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
340  if ( $DEBUG_sys ) ; then
341    echo "IGCM_sys_IsFileArchived :" $@
342  fi
343  typeset IsArchivedFlag
344  IsArchivedFlag=$( [ X$( echo $@ | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
345  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
346
347  return ${IsArchivedFlag}
348}
349
350#D-#==================================================
351#D-function IGCM_sys_TestFileArchive
352#D-* Purpose: Test file that must NOT EXISTS on Archive
353#D-* Examples:
354#D-
355function IGCM_sys_TestFileArchive {
356  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
357  typeset ExistFlag
358  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
359  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
360
361  return ${ExistFlag}
362}
363
364#D-#==================================================
365#D-function IGCM_sys_CountFileArchive
366#D-* Purpose: Count files on Archive filesystem
367#D-* Examples:
368#D-
369function IGCM_sys_CountFileArchive {
370  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
371  ls ${@} 2>/dev/null | wc -l
372  if [ $? -gt 0 ] ; then
373    echo "IGCM_sys_CountFileArchive : erreur."
374  fi
375  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
376}
377
378#D-#==================================================
379#D-function IGCM_sys_Tree
380#D-* Purpose: Tree directories with files on ${ARCHIVE}
381#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
382#D-
383function IGCM_sys_Tree {
384  IGCM_debug_PushStack "IGCM_sys_Tree" $@
385  if ( $DEBUG_sys ) ; then
386    echo "IGCM_sys_Tree :" $@
387  fi
388
389  \ls -lR ${@}
390
391  IGCM_debug_PopStack "IGCM_sys_Tree"
392}
393
394#D-#==================================================
395#D-function IGCM_sys_Qsub
396#D-* Purpose: Qsub new job
397#D-* Examples:
398#D-
399function IGCM_sys_Qsub {
400  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
401  if ( $DEBUG_sys ) ; then
402    echo "IGCM_sys_Qsub :" $@
403  fi
404  typeset options status
405  options="-o ${SUBMIT_DIR}/${Script_Output} -e ${SUBMIT_DIR}/${Script_Output}"
406
407  /usr/bin/ccc_msub ${options} $1 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
408  status=$?
409
410  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
411  if [ ${status} -gt 0 ] ; then
412    IGCM_debug_Print 2 "IGCM_sys_Qsub ${options} $1 : error code ${status}"
413    IGCM_debug_Exit "IGCM_sys_Qsub"
414  else
415    JobID=$( gawk {'print $4'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
416  fi
417  IGCM_debug_PopStack "IGCM_sys_Qsub"
418}
419
420#D-#==================================================
421#D-function IGCM_sys_QsubPost
422#D-* Purpose: Qsub new job on scalaire
423#D-* Examples:
424#D-
425function IGCM_sys_QsubPost {
426  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
427  if ( $DEBUG_sys ) ; then
428    echo "IGCM_sys_QsubPost :" $@
429  fi
430  typeset options status
431
432  # EASIER TO DO THIS INSTEAD OF DUPLICATING libIGCM_sys_curie.ksh
433  case $( hostname -s ) in
434  curie*)
435    options="-Q normal -A ${PROJECT} -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out";;
436  airain*)
437    options="-q ivybridge -A dsm -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out"
438  esac
439
440  /usr/bin/ccc_msub ${options} ${libIGCM_POST}/$1.job > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
441  status=$?
442
443  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
444  if [ ${status} -gt 0 ] ; then
445    IGCM_debug_Print 2 "IGCM_sys_QsubPost ${options} ${libIGCM_POST}/$1.job : error code ${status}"
446    IGCM_debug_Exit "IGCM_sys_QsubPost"
447  else
448    JobID=$( gawk {'print $4'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
449  fi
450  IGCM_debug_PopStack "IGCM_sys_QsubPost"
451}
452
453#D-*************************
454#D- File transfer functions
455#D-*************************
456#D-
457
458#D-#==================================================
459#D-function IGCM_sys_RmRunDir
460#D-* Purpose: rm tmpdir (dummy function most of the time batch
461#D-                      scheduler will do the job)
462#D-* Examples:
463#D-
464function IGCM_sys_RmRunDir {
465  IGCM_debug_PushStack "IGCM_sys_RmRunDir" $@
466  if ( $DEBUG_sys ) ; then
467    echo "IGCM_sys_RmRunDir :" $@
468  fi
469
470  typeset status
471
472  echo rm $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
473  \rm $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
474  status=$?
475
476  if [ ${status} -gt 0 ] ; then
477    IGCM_debug_Print 1 "IGCM_sys_RmRunDir : rm error code is ${status}."
478    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
479    IGCM_debug_Exit "IGCM_sys_RmRunDir"
480  else
481    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
482  fi
483  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
484}
485
486#D-#==================================================
487#D-function IGCM_sys_Put_Dir
488#D-* Purpose: Copy a complete directory on $(ARCHIVE)
489#D-* Examples:
490#D-
491function IGCM_sys_Put_Dir {
492  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
493  if ( $DEBUG_sys ) ; then
494    echo "IGCM_sys_Put_Dir :" $@
495  fi
496  if [ $DRYRUN = 0 ]; then
497    if [ ! -d ${1} ] ; then
498      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
499      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
500      return
501    fi
502
503    typeset status
504
505    # Only if we use rsync
506    #IGCM_sys_TestDirArchive $( dirname $2 )
507    #
508    #USUAL WAY
509    \cp -r $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
510    status=$?
511
512    if [ ${status} -gt 0 ] ; then
513      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
514      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
515      IGCM_debug_Exit "IGCM_sys_Put_Dir"
516    else
517      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
518    fi
519  fi
520  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
521}
522
523#D-#==================================================
524#D-function IGCM_sys_Get_Dir
525#D-* Purpose: Copy a complete directory from ${ARCHIVE}
526#D-* Examples:
527#D-
528function IGCM_sys_Get_Dir {
529  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
530  if ( $DEBUG_sys ) ; then
531    echo "IGCM_sys_Get_Dir :" $@
532  fi
533  if [ $DRYRUN = 0 ]; then
534    typeset NB_ESSAI DELAI status i
535    # number of tentative
536    NB_ESSAI=3
537    # time delay between tentative
538    DELAI=2
539
540    #
541    # USUAL WAY
542    # add 'ccc_hsm get' (to demigrate all offline files) to reduce time of this command :
543    ccc_hsm get -r $1
544
545    i=0
546    while [ $i -lt $NB_ESSAI ] ; do
547      \cp -ur $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
548      status=$?
549      if [ ${status} -gt 0 ] ; then
550        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}"
551        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
552        sleep $DELAI
553      else
554        break
555      fi
556      (( i = i + 1 ))
557    done
558
559    if [ ${status} -gt 0 ] ; then
560      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
561      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
562      IGCM_debug_Exit "IGCM_sys_Get_Dir"
563    else
564      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
565    fi
566  fi
567  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
568}
569
570#D-#==================================================
571#D-function IGCM_sys_Put_Rest
572#D-* Purpose: Put computied restarts on ${ARCHIVE}.
573#D-           File and target directory must exist.
574#D-* Examples:
575#D-
576function IGCM_sys_Put_Rest {
577  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
578  if ( $DEBUG_sys ) ; then
579    echo "IGCM_sys_Put_Rest :" $@
580  fi
581  if [ $DRYRUN = 0 ]; then
582    if [ ! -f ${1} ] ; then
583      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
584      IGCM_debug_Exit "IGCM_sys_Put_Rest"
585    fi
586
587    typeset status
588    #
589    # USUAL WAY
590    \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
591    status=$?
592
593#       #RSYNC WITH NETWORK SSH CALL
594#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
595#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
596
597#       #RSYNC WITH NFS USE
598#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
599#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
600
601#       status=$?
602#       IGCM_sys_Rsync_out $status
603
604#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
605#       (( status=status+$? ))
606
607    if [ ${status} -gt 0 ] ; then
608      IGCM_debug_Print 2 "IGCM_sys_Put_Rest : cp failed error code ${status}"
609      [ -f ${1} ] && ls -l ${1}
610      [ -f ${2} ] && ls -l ${2}
611      [ -f ${2}/${1} ] && ls -l ${2}/${1}
612      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
613      IGCM_debug_Exit "IGCM_sys_Put_Rest"
614    else
615
616      if [ X${JobType} = XRUN ] ; then
617        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
618        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
619      fi
620
621      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
622    fi
623  fi
624  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
625}
626
627#D-#==================================================
628#D-function IGCM_sys_Put_Out
629#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
630#D-* Examples:
631#D-
632function IGCM_sys_Put_Out {
633  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
634  if ( $DEBUG_sys ) ; then
635    echo "IGCM_sys_Put_Out :" $@
636  fi
637
638  typeset NB_ESSAI DELAI status i exist skip
639  typeset fileDeviceNumberInHex directoryDeviceNumberInHex
640
641  # number of tentative
642  NB_ESSAI=3
643  # time delay between tentative
644  DELAI=2
645
646  if [ $DRYRUN = 0 ]; then
647    if [ ! -f ${1} ] ; then
648      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
649      IGCM_debug_PopStack "IGCM_sys_Put_Out"
650      return 1
651    fi
652    #
653    IGCM_sys_MkdirArchive $( dirname $2 )
654    #
655    exist=false
656    skip=false
657    if [ -f $2 ] ; then
658      IGCM_debug_Print 1 "$2 already exist"
659      ccc_hsm get $2
660      exist=true
661      if [ "X$( diff $1 $2 )" = X ] ; then
662        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
663        skip=true
664      else
665        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
666        skip=false
667      fi
668    fi
669    #
670    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
671      IGCM_sys_Chmod u+w $2
672    fi
673
674    if [ X${skip} = Xfalse ] ; then
675      i=0
676      while [ $i -lt $NB_ESSAI ] ; do
677        # Identify file system
678        fileDeviceNumberInHex=$( stat -c %d $1 )
679        status=$?
680        if [ ${status} -gt 0 ] ; then
681          IGCM_debug_Exit "IGCM_sys_Put_Out"
682        fi
683        # Identify file system
684        directoryDeviceNumberInHex=$( stat -c %d $( dirname $2 ) )
685        status=$?
686        if [ ${status} -gt 0 ] ; then
687          IGCM_debug_Exit "IGCM_sys_Put_Out"
688        fi
689
690        if [ ${fileDeviceNumberInHex} -ne ${directoryDeviceNumberInHex} ] ; then
691          # They are not on the same device. USUAL WAY
692          \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
693          status=$?
694        else
695          # They are on the same device. NOT SO USUAL WAY
696          \mv $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
697          status=$?
698        fi
699        if [ ${status} -gt 0 ]; then
700          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
701          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
702          [ -f ${1} ] && ls -l ${1}
703          [ -f ${2} ] && ls -l ${2}
704          [ -f ${2}/${1} ] && ls -l ${2}/${1}
705          sleep $DELAI
706        else
707          break
708        fi
709        (( i = i + 1 ))
710      done
711    fi
712
713#       #RSYNC WITH NETWORK SSH CALL
714#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
715#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
716
717#       #RSYNC WITH NFS USE
718#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
719#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
720
721#       status=$?
722#       IGCM_sys_Rsync_out $status
723
724#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
725#       (( status=status+$? ))
726
727    if [ ${status} -gt 0 ] ; then
728      IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status}"
729      [ -f ${1} ] && ls -l ${1}
730      [ -f ${2} ] && ls -l ${2}
731      [ -f ${2}/${1} ] && ls -l ${2}/${1}
732      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
733      IGCM_debug_Exit "IGCM_sys_Put_Out"
734    else
735
736      if [ X${JobType} = XRUN ] ; then
737        if [ X${3} = X ] ; then
738          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
739          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
740        fi
741      fi
742
743      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
744    fi
745  fi
746  IGCM_debug_PopStack "IGCM_sys_Put_Out"
747  return 0
748}
749
750#D-#==================================================
751#D-function IGCM_sys_Get
752#D-* Purpose: Get a file from ${ARCHIVE}
753#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
754#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
755function IGCM_sys_Get {
756  IGCM_debug_PushStack "IGCM_sys_Get" $@
757
758  typeset DEST dm_liste target file_work
759  typeset NB_ESSAI DELAI status i
760
761  if ( $DEBUG_sys ) ; then
762    echo "IGCM_sys_Get :" $@
763  fi
764
765  # number of tentative
766  NB_ESSAI=3
767  # time delay between tentative
768  DELAI=2
769
770  if [ $DRYRUN -le 2 ]; then
771    if [ X${1} = X'/l' ] ; then
772      eval set +A dm_liste \${${2}}
773    else
774      eval set +A dm_liste ${1}
775    fi
776    eval DEST=\${${#}}
777    ccc_hsm get ${dm_liste[*]} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
778    status=$?
779    if [ ${status} -gt 0 ] ; then
780      echo "WARNING IGCM_sys_Get : error code ${status}"
781      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
782      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
783    fi
784
785    #if [ ${status} -gt 0 ] ; then
786    #  if [ ! "X$( grep "Lost dmusrcmd connection" ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )" = "X" ] ; then
787    #    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
788    #    echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
789    #    sleep 30
790    #    echo "We try another time"
791    ##    dmget ${dm_liste[*]} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
792    #    ccc_hsm get ${dm_liste[*]} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
793    #    status=$?
794    #    if [ ${status} -gt 0 ] ; then
795    #      echo "ERROR IGCM_sys_Get : again demigration error :"
796    #      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
797    #      IGCM_debug_Exit "IGCM_sys_Get"
798    #    fi
799    #  else
800    #    echo "ERROR IGCM_sys_Get : demigration error :"
801    #    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
802    #    IGCM_debug_Exit "IGCM_sys_Get"
803    #  fi
804    #fi
805
806    #   #RSYNC WITH NETWORK SSH CALL
807    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
808    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
809
810    #   #RSYNC WITH NFS USE
811    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
812    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
813
814    #   status=$?
815    #   IGCM_sys_Rsync_out $status
816
817    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
818    #   (( status=status+$? ))
819
820    #USUAL WAY
821    if [ X${1} = X'/l' ] ; then
822      for target in ${dm_liste[*]} ; do
823        local_file=$( basename ${target} )
824        # test if the target file is present before the loop
825        IGCM_sys_TestFileArchive ${target}
826        status=$?
827        if [ ${status} -gt 0 ] ; then
828          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
829          IGCM_debug_Exit "IGCM_sys_Get"
830        else
831          i=0
832          while [ $i -lt $NB_ESSAI ] ; do
833            #if [ X${DoLink} = Xtrue ] ; then
834            #  \ln -s ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
835            #  status=$?
836            #  else
837            #  \cp ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
838            #  status=$?
839            #fi
840            \ln -s ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
841            status=$?
842            if [ ${status} -gt 0 ]; then
843              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
844              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
845              sleep $DELAI
846            else
847              break
848            fi
849            (( i = i + 1 ))
850          done
851          if [ ${status} -gt 0 ] ; then
852            echo "IGCM_sys_Get : error"
853            cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
854            \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
855            IGCM_debug_Exit "IGCM_sys_Get"
856          else
857            \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
858          fi
859        fi
860      done
861    else
862      i=0
863      while [ $i -lt $NB_ESSAI ] ; do
864        \cp ${dm_liste} ${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
865        status=$?
866        if [ ${status} -gt 0 ]; then
867          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
868          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
869          sleep $DELAI
870        else
871          break
872        fi
873        (( i = i + 1 ))
874      done
875      if [ ${status} -gt 0 ] ; then
876        echo "IGCM_sys_Get : error"
877        cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
878        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
879        IGCM_debug_Exit "IGCM_sys_Get"
880      else
881        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
882      fi
883    fi
884  fi
885  IGCM_debug_PopStack "IGCM_sys_Get"
886}
887
888#D-#==================================================
889#D-function IGCM_sys_GetDate_Monitoring
890#D-* Purpose: get the last year for which the monitoring has been computed
891#D-* Examples:
892#D-
893function IGCM_sys_GetDate_Monitoring {
894  IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@
895  if ( $DEBUG_sys ) ; then
896    echo "IGCM_sys_GetDate_Monitoring :" $@
897  fi
898
899  eval ${2}=$( cdo showyear ${1} 2> /dev/null | gawk '{ print $NF }' )
900
901  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
902}
903
904#D-#==================================================
905#D-function IGCM_sys_Dods_Rm
906#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
907#D-* Examples:
908#D-
909function IGCM_sys_Dods_Rm {
910  if ( $DEBUG_sys ) ; then
911    echo "IGCM_sys_Dods_Rm :" $@
912  fi
913  typeset status
914  if [ $DRYRUN = 0 ]; then
915
916#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
917#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
918#      echo "Nothing has been done."
919#      return
920#    fi
921
922    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
923    status=$?
924
925#    if [ ${status} -gt 0 ] ; then
926#      echo "IGCM_sys_Dods_Rm : error."
927#      cat out_dods_rm
928#      IGCM_debug_Exit "IGCM_sys_Dods_Rm"
929#    else
930#      rm out_dods_rm
931#    fi
932
933  fi
934  return $status
935}
936
937#D-#==================================================
938#D-function IGCM_sys_Dods_Cp
939#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
940#D-* Examples:
941#D-
942function IGCM_sys_Dods_Cp {
943  if ( $DEBUG_sys ) ; then
944    echo "IGCM_sys_Dods_Cp :" $@
945  fi
946  typeset status
947  if [ $DRYRUN = 0 ]; then
948
949#    if [ ! -d ${R_SAVE}/${1} ] ; then
950#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
951#      echo "Nothing has been done."
952#      return
953#    fi
954
955    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
956    status=$?
957
958#       if [ ${status} -gt 0 ] ; then
959#           echo "IGCM_sys_Dods_Cp : error."
960#           cat out_dods_cp
961#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
962#       else
963#           rm out_dods_cp
964#       fi
965
966  fi
967  return $status
968}
969
970#D-#==================================================
971#D-function IGCM_sys_Put_Dods
972#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole.
973#D-* Examples:
974#D-
975function IGCM_sys_Put_Dods {
976  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
977  if ( $DEBUG_sys ) ; then
978    echo "IGCM_sys_Put_Dods :" $@
979  fi
980  typeset status
981  if [ $DRYRUN = 0 ]; then
982    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
983      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
984      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
985      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
986      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
987      return
988    fi
989
990    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
991      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
992      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
993      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
994      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
995      return
996    fi
997    #
998    if [ -d ${R_SAVE}/${1} ] ; then
999      cd ${R_SAVE}
1000    elif [ -d ${R_FIGR}/${1} ] ; then
1001      cd ${R_FIGR}
1002    fi
1003
1004    IGCM_sys_Dods_Rm ${1}
1005    IGCM_sys_Dods_Cp ${1}
1006    status=0
1007
1008    if [ ${status} -gt 0 ] ; then
1009      echo "IGCM_sys_Put_Dods : error."
1010      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1011    fi
1012  fi
1013  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1014}
1015
1016##############################################################
1017# REBUILD OPERATOR
1018
1019#D-#==================================================
1020#D-function IGCM_sys_sync
1021#D-* Purpose: flush buffer on disk
1022#D-* Examples:
1023#D-
1024function IGCM_sys_sync {
1025  IGCM_debug_PushStack "IGCM_sys_sync" $@
1026  if ( $DEBUG_sys ) ; then
1027    echo "IGCM_sys_sync :" $@
1028  fi
1029
1030  /bin/sync
1031
1032  IGCM_debug_PopStack "IGCM_sys_sync"
1033}
1034
1035############################################################
1036# Activate Running Environnment Variables
1037
1038#D-#==================================================
1039#D-function IGCM_sys_activ_variables
1040#D-* Purpose: set environement variables prior to execution
1041#D-* Examples:
1042#D-
1043function IGCM_sys_activ_variables {
1044  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1045  if ( $DEBUG_sys ) ; then
1046    echo "IGCM_sys_activ_variables"
1047  fi
1048
1049# --------------------------------------------------------------------
1050#D- MPI specifications
1051# --------------------------------------------------------------------
1052
1053# --------------------------------------------------------------------
1054#D- Other specifications
1055# --------------------------------------------------------------------
1056
1057  ulimit -s unlimited
1058
1059  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1060}
1061
1062############################################################
1063# Desactivate Running Environnment Variables
1064
1065#D-#==================================================
1066#D-function IGCM_sys_desactiv_variables
1067#D-* Purpose: unset environement variables after execution
1068#D-* Examples:
1069#D-
1070function IGCM_sys_desactiv_variables {
1071  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1072  if ( $DEBUG_sys ) ; then
1073    echo "IGCM_sys_desactiv_variables"
1074  fi
1075# --------------------------------------------------------------------
1076#D- MPI specifications
1077# --------------------------------------------------------------------
1078
1079# --------------------------------------------------------------------
1080#D- Other specifications
1081# --------------------------------------------------------------------
1082
1083  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1084}
1085
1086############################################################
1087# Update job headers to be used by the scheduler
1088
1089#D-#==================================================
1090#D-function IGCM_sys_updateHeaders
1091#D-* Purpose: Update job headers to be used by the scheduler
1092#D-* Examples: IGCM_sys_updateHeaders /path/to/Job_MYEXP
1093#D-
1094function IGCM_sys_updateHeaders {
1095  IGCM_debug_PushStack "IGCM_sys_updateHeaders"
1096  if ( $DEBUG_sys ) ; then
1097    echo "IGCM_sys_updateHeaders"
1098  fi
1099  typeset file
1100  file=$1
1101
1102  if [ ${executionType} -eq 1 ] ; then
1103    # MPMD + MPI
1104    sed -e "/::openMPthreads::/d"                  \
1105        -e "s/::JobNumProcTot::/${coreNumber}/"    \
1106        -e "/#MSUB -x/d"                           \
1107        -e "/--cpu_bind=none/d"                    \
1108      ${file} > ${file}.tmp
1109
1110  elif [ ${executionType} -eq 2 ] ; then
1111    # MPMD + MPI + OMP
1112    sed -e "/::openMPthreads::/d"                  \
1113        -e "s/::JobNumProcTot::/${coreNumber}/"    \
1114      ${file} > ${file}.tmp
1115
1116  elif [ ${executionType} -eq 3 ] ; then
1117    # SPMD + MPI/OMP
1118    sed -e "s/::openMPthreads::/${openMPthreads}/" \
1119        -e "s/::JobNumProcTot::/${mpiTasks}/"      \
1120        -e "/#MSUB -x/d"                           \
1121        -e "/--cpu_bind=none/d"                    \
1122      ${file} > ${file}.tmp
1123
1124  elif [ ${executionType} -eq 4 ] ; then
1125    # SPMD + MPI only
1126    sed -e "s/::JobNumProcTot::/${mpiTasks}/"      \
1127        -e "/::openMPthreads::/d"                  \
1128        -e "/#MSUB -x/d"                           \
1129        -e "/--cpu_bind=none/d"                    \
1130      ${file} > ${file}.tmp
1131
1132  elif [ ${executionType} -eq 5 ] ; then
1133    # SPMD + OMP only
1134    sed -e "s/::openMPthreads::/${openMPthreads}/" \
1135        -e "/::JobNumProcTot::/d"                  \
1136        -e "/#MSUB -x/d"                           \
1137        -e "/--cpu_bind=none/d"                    \
1138      ${file} > ${file}.tmp
1139
1140  elif [ ${executionType} -eq 6 ] ; then
1141    # SEQUENTIAL THEN
1142    sed -e "s/::JobNumProcTot::/1/"                \
1143        -e "/::openMPthreads::/d"                  \
1144        -e "/#MSUB -x/d"                           \
1145        -e "/--cpu_bind=none/d"                    \
1146      ${file} > ${file}.tmp
1147
1148  fi
1149
1150  IGCM_sys_Mv ${file}.tmp ${file}
1151
1152  IGCM_debug_PopStack "IGCM_sys_updateHeaders"
1153}
1154
1155############################################################
1156# Build MPI/OMP scripts run file (dummy function)
1157
1158#D-#==================================================
1159#D-function IGCM_sys_build_run_file
1160#D-* Purpose: build run file (deprecated)
1161#D-* Examples:
1162#D-
1163function IGCM_sys_build_run_file {
1164  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1165}
1166
1167############################################################
1168# Build MPI/OMP scripts
1169
1170#D-#==================================================
1171#D-function IGCM_sys_build_execution_scripts
1172#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1173#D-* Examples:
1174#D-
1175function IGCM_sys_build_execution_scripts
1176{
1177  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1178  if ( $DEBUG_sys ) ; then
1179    echo "IGCM_sys_build_execution_scripts " $@
1180  fi
1181
1182  EXECUTION=${HOST_MPIRUN_COMMAND}
1183
1184  # MPMD mode
1185  if ( ${OK_PARA_MPMD} ) ; then
1186
1187    # Only MPI (MPMD)
1188    if  ( ! ${OK_PARA_OMP} ) ; then
1189
1190      if [ -f run_file ] ; then
1191        IGCM_sys_Rm -f run_file
1192      fi
1193      touch run_file
1194
1195      # Build run_file
1196
1197      # First loop on the components for the coupler ie oasis (only if oasis3)
1198      # the coupler ie oasis3 must be the first one
1199      for comp in ${config_ListOfComponents[*]} ; do
1200
1201        eval ExeNameIn=\${config_Executable_${comp}[0]}
1202        eval ExeNameOut=\${config_Executable_${comp}[1]}
1203
1204        # for CPL component only
1205        if [ "X${comp}" = "XCPL" ] && [ "X${ExeNameOut}" != X\"\" ] ; then
1206
1207          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1208          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1209          echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1210        fi
1211      done
1212
1213      # Then second loop on the components
1214      for comp in ${config_ListOfComponents[*]} ; do
1215
1216        eval ExeNameIn=\${config_Executable_${comp}[0]}
1217        eval ExeNameOut=\${config_Executable_${comp}[1]}
1218
1219        # Only if we really have an executable for the component and not the coupler ie oasis:
1220        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1221
1222          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1223          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1224          echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1225        fi
1226      done
1227
1228      EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1229
1230      IGCM_sys_Chmod u+x run_file
1231      if ( $DEBUG_sys ) ; then
1232        echo "run_file contains : "
1233        cat run_file
1234      fi
1235
1236    # MPI-OpenMP (MPMD)
1237    else
1238
1239      # Use of mpirun instead of ccc_mprun
1240      EXECUTION="time mpirun"
1241
1242      #  Hosts treatment
1243      ${EXECUTION} hostname | sort | uniq > hosts.tmp
1244
1245      i=0
1246      rm -f hosts rankfile
1247      IGCM_debug_Print 1 "sys Curie, Hosts available :"
1248      for nodes in `cat hosts.tmp`
1249      do
1250        host[$i]=$nodes
1251        echo "${host[$i]}" >> hosts
1252        IGCM_debug_Print 1 ${host[$i]}
1253        i=$((i+1))
1254      done
1255      rm -f hosts.tmp
1256
1257      listnodes=${host[*]}
1258
1259      EXECUTION="${EXECUTION} -hostfile hosts -rankfile rankfile"
1260
1261      # Initialisation
1262      rank=0
1263      current_core=0
1264      core_per_node=16
1265      init_exec=n
1266
1267      # Loop on the components
1268      for comp in ${config_ListOfComponents[*]} ; do
1269
1270        eval ExeNameIn=\${config_Executable_${comp}[0]}
1271        eval ExeNameOut=\${config_Executable_${comp}[1]}
1272
1273        # Not possible if oasis has an executable (i.e old version of oasis3)
1274        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" = "XCPL" ] ) ; then
1275          IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version"
1276          IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler"
1277          IGCM_debug_Verif_Exit
1278        fi
1279
1280        # Only if we really have an executable for the component :
1281        if [ "X${ExeNameOut}" != X\"\" ] ; then
1282
1283          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1284          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1285
1286          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1287          echo ""  >> script_${ExeNameOut}.ksh
1288          if [ ${comp_proc_omp_loc} -gt 1 ] ; then
1289
1290            # Check if the number of threads is correct
1291            case ${comp_proc_omp_loc} in
1292            2|4|8|16)
1293              IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
1294              ;;
1295            *)
1296              IGCM_debug_Exit "ERROR with OMP parameters !"
1297              IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
1298              IGCM_debug_Print 2 "Only 2,4,8,16 as number of OMP threads are possible "
1299              IGCM_debug_Verif_Exit
1300              ;;
1301            esac
1302            echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1303            echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1304            echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1305            echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1306          fi
1307          #echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1308          #echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1309          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1310          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1311
1312          if [ ${init_exec} = y ] ; then
1313            EXECUTION="${EXECUTION} : -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1314          else
1315            EXECUTION="${EXECUTION} -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1316            init_exec=y
1317          fi
1318
1319# Build rankfile : method used to assign cores and nodes for the MPI process
1320# Ex :
1321#rank 0=curie5296 slot=0,1,2,3
1322#rank 1=curie5296 slot=4,5,6,7
1323# Example of final command :
1324# mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh
1325# with script_lmdz.x.ksh :
1326# #!/bin/ksh
1327#export KMP_STACKSIZE=3g
1328#export KMP_LIBRARY=turnaround
1329#export MKL_SERIAL=YES
1330#OMP_NUM_THREADS=4
1331#./lmdz.x
1332#
1333
1334          for nb_proc_mpi in `seq 0 $(($comp_proc_mpi_loc-1))`; do
1335            (( index_host = current_core / core_per_node ))
1336            host_value=${host[${index_host}]}
1337            (( slot =  current_core % core_per_node ))
1338            virg=","
1339            string_final=""
1340            for index in `seq $slot $(($slot+$comp_proc_omp_loc-1))`; do
1341              string=$index$virg
1342              string_final=$string_final$string
1343            done
1344            string_final=$( echo $string_final | sed "s/.$//" )
1345            echo "rank $rank=$host_value slot=$string_final" >> rankfile
1346            (( rank = rank + 1 ))
1347            (( current_core = current_core + comp_proc_omp_loc ))
1348          done
1349        fi
1350
1351      done
1352    fi
1353
1354  # Only one executable (SPMD mode).
1355  else
1356
1357    for comp in ${config_ListOfComponents[*]} ; do
1358
1359      # Only if we really have an executable for the component :
1360      eval ExeNameOut=\${config_Executable_${comp}[1]}
1361      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1362
1363        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1364        echo ""  >> script_${ExeNameOut}.ksh
1365        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1366
1367        if ( ${OK_PARA_OMP} ) ; then
1368          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1369          echo ""  >> script_${ExeNameOut}.ksh
1370          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1371          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1372          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1373          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1374        fi
1375
1376        if  ( ${OK_PARA_MPI} ) ; then
1377          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1378          # Default : ccc_mprun used if nb_proc gt 1
1379          # to have out/err per process on different files
1380          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
1381          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1382          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1383        else
1384          # Default : ccc_mprun is NOT used if nb_proc eq 1
1385          # to have out/err per process on different files
1386          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1387          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1388          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
1389        fi
1390
1391        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
1392        cat script_${ExeNameOut}.ksh
1393
1394      fi
1395
1396    done
1397
1398  fi
1399
1400  IGCM_debug_Print 1 "sys Curie : execution command is "
1401  IGCM_debug_Print 1 "$EXECUTION"
1402
1403  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1404}
1405
1406#D-#==================================================
1407#D-function IGCM_sys_check_path
1408#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1409#D-* do not point to an important use directory. Stop immediately in that case.
1410#D-* Examples:
1411#D-
1412function IGCM_sys_check_path {
1413  IGCM_debug_PushStack "IGCM_sys_check_path"
1414  if ( $DEBUG_sys ) ; then
1415    echo "IGCM_sys_check_path"
1416  fi
1417
1418  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${WORKDIR} ] || [ X${RUN_DIR_PATH} = X${SCRATCHDIR} ] || [ X${RUN_DIR_PATH} = X${CCCWORKDIR} ] || [ X${RUN_DIR_PATH} = X${CCCSTOREDIR} ] ) ; then
1419    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1420    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1421    IGCM_debug_Exit "This will stop the job"
1422  fi
1423  IGCM_debug_PopStack "IGCM_sys_check_path"
1424}
1425
1426#D-#==================================================
1427#D-function IGCM_sys_check_quota
1428#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1429#D-* Examples:
1430#D-
1431function IGCM_sys_check_quota {
1432  IGCM_debug_PushStack "IGCM_sys_check_quota"
1433  if ( $DEBUG_sys ) ; then
1434    echo "IGCM_sys_check_quota"
1435  fi
1436  # Limit of quota (in %)
1437  limit_quota=90
1438
1439  # Check of the volume
1440  volume_quota=$(ccc_quota | grep ' scratch' | gawk '{print $2}')
1441  volume_avail=$(ccc_quota | grep ' scratch' | gawk '{print $3}')
1442
1443  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
1444
1445    unit_avail=${volume_avail: -1}
1446    unit_quota=${volume_quota: -1}
1447
1448    if [ "${unit_quota}" = "*" ] ; then
1449      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1450      IGCM_debug_Print 1 "More than 100% of your quota is used"
1451      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1452      IGCM_debug_Print 1 "You must have more than 10% available to run"
1453      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1454      IGCM_debug_Verif_Exit
1455    fi
1456
1457    temp_avail=${volume_avail%%${volume_avail: -1}*}
1458    temp_quota=${volume_quota%%${volume_quota: -1}*}
1459
1460    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1461
1462    # Convertion
1463      if [ ${volume_avail: -1} = "T" ] ; then
1464        (( temp_avail = temp_avail * 1000000000000 ))
1465      elif [ ${volume_avail: -1} = "G" ] ; then
1466        (( temp_avail = temp_avail * 1000000000 ))
1467      elif [ ${volume_avail: -1} = "M" ] ; then
1468        (( temp_avail = temp_avail * 1000000 ))
1469      elif [ ${volume_avail: -1} = "k" ] ; then
1470        (( temp_avail = temp_avail * 1000 ))
1471      else
1472        (( temp_avail = volume_avail ))
1473      fi
1474      if [ ${volume_quota: -1} = "T" ] ; then
1475        (( temp_quota = temp_quota * 1000000000000 ))
1476      elif [ ${volume_quota: -1} = "G" ] ; then
1477        (( temp_quota = temp_quota * 1000000000 ))
1478      elif [ ${volume_quota: -1} = "M" ] ; then
1479        (( temp_quota = temp_quota * 1000000 ))
1480      elif [ ${volume_quota: -1} = "k" ] ; then
1481        (( temp_quota = temp_quota * 1000 ))
1482      else
1483        (( temp_quota = volume_quota ))
1484      fi
1485    fi
1486
1487    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1488#    echo "volume ratio is " $quota_volume
1489
1490    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1491      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1492      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1493      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1494      IGCM_debug_Print 1 "You must have more than 10% available to run"
1495      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1496      IGCM_debug_Verif_Exit
1497    fi
1498
1499  fi
1500
1501# Check of the number of inodes
1502
1503  inode_quota=$(ccc_quota | grep ' scratch' | gawk '{print $6}')
1504  inode_avail=$(ccc_quota | grep ' scratch' | gawk '{print $7}')
1505
1506  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
1507
1508    unit_avail=${inode_avail: -1}
1509    unit_quota=${inode_quota: -1}
1510
1511    if [ "${unit_quota}" = "*" ] ; then
1512      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
1513      IGCM_debug_Print 1 "More than 100% of your quota is used"
1514      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1515      IGCM_debug_Print 1 "You must have more than 10% available to run"
1516      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1517      IGCM_debug_Verif_Exit
1518    fi
1519
1520    temp_avail=${inode_avail%%${inode_avail: -1}*}
1521    temp_quota=${inode_quota%%${inode_quota: -1}*}
1522
1523    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1524
1525    # Convertion
1526      if [ ${inode_avail: -1} = "T" ] ; then
1527        (( temp_avail = temp_avail * 1000000000000 ))
1528      elif [ ${inode_avail: -1} = "G" ] ; then
1529        (( temp_avail = temp_avail * 1000000000 ))
1530      elif [ ${inode_avail: -1} = "M" ] ; then
1531        (( temp_avail = temp_avail * 1000000 ))
1532      elif [ ${inode_avail: -1} = "k" ] ; then
1533        (( temp_avail = temp_avail * 1000 ))
1534      else
1535        (( temp_avail = inode_avail ))
1536      fi
1537
1538      if [ ${inode_quota: -1} = "T" ] ; then
1539        (( temp_quota = temp_quota * 1000000000000 ))
1540      elif [ ${inode_quota: -1} = "G" ] ; then
1541        (( temp_quota = temp_quota * 1000000000 ))
1542      elif [ ${inode_quota: -1} = "M" ] ; then
1543        (( temp_quota = temp_quota * 1000000 ))
1544      elif [ ${inode_quota: -1} = "k" ] ; then
1545        (( temp_quota = temp_quota * 1000 ))
1546      else
1547        (( temp_quota = inode_quota ))
1548      fi
1549    fi
1550    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1551#    echo "inode ratio is " $quota_inode
1552
1553    if [ ${quota_inode} -ge ${limit_quota} ] ; then
1554      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
1555      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
1556      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1557      IGCM_debug_Print 1 "You must have more than 10% available to run"
1558      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1559      IGCM_debug_Verif_Exit
1560    fi
1561  fi
1562  IGCM_debug_PopStack "IGCM_sys_check_quota"
1563}
1564
1565#D-#==================================================
1566#D-function IGCM_sys_getJobSchedulerID
1567#D-* Purpose: Get the job ID during execution
1568#D-* Examples: IGCM_sys_getJobSchedulerID jobSchedulerID
1569#D-
1570function IGCM_sys_getJobSchedulerID {
1571  IGCM_debug_PushStack "IGCM_sys_getJobSchedulerID"
1572  if ( $DEBUG_sys ) ; then
1573    echo "IGCM_sys_getJobSchedulerID"
1574  fi
1575
1576  eval ${1}=${BRIDGE_MSUB_JOBID}
1577
1578  IGCM_debug_PopStack "IGCM_sys_getJobSchedulerID"
1579}
1580
1581#D-#==================================================
1582#D-function IGCM_sys_GetJobID
1583#D-* Purpose: Get the job ID from the JobName
1584#D-* Examples: IGCM_sys_GetJobID ${JobName} ${TargetUsr} JobID
1585#D-
1586function IGCM_sys_GetJobID {
1587  IGCM_debug_PushStack "IGCM_sys_GetJobID"
1588  if ( $DEBUG_sys ) ; then
1589    echo "IGCM_sys_GetJobID"
1590  fi
1591
1592  # With -f option, the full job name is given in the last column
1593  ID=$( ccc_mstat -f -u $2 | \
1594        gawk -v JobName=$1 '( $NF ~ JobName ) { print $1 }' )
1595
1596  eval ${3}=${ID}
1597  IGCM_debug_PopStack "IGCM_sys_GetJobID"
1598}
1599
1600#D-#==================================================
1601#D-function IGCM_sys_CountJobInQueue
1602#D-* Purpose: Count number of users job
1603#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1604#D-
1605function IGCM_sys_CountJobInQueue {
1606  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1607  if ( $DEBUG_sys ) ; then
1608    echo "IGCM_sys_CountJobInQueue"
1609  fi
1610
1611  # With -f option, the full job name is given in the last column
1612  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ( $NF ~ JobName ) { x=x+1 } END { print x }' )
1613
1614  eval ${2}=${NbRun}
1615
1616  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1617}
1618
1619#D-#==================================================
1620#D-function IGCM_sys_ListJobInQueue
1621#D-* Purpose: Produce a list of users computing jobs (excluding post-processing)
1622#D-* Examples: IGCM_sys_ListJobInQueue ${User} JobNameList
1623#D-
1624function IGCM_sys_ListJobInQueue {
1625  IGCM_debug_PushStack "IGCM_sys_ListJobInQueue"
1626  if ( $DEBUG_sys ) ; then
1627    echo "IGCM_sys_ListJobInQueue"
1628  fi
1629
1630  # With -f option, the full job name is given in the last column
1631  set -A JobList $( ccc_mstat -f | gawk -v User=$1             \
1632                                        '( $2  == User      && \
1633                                           $NF != /TS/      && \
1634                                           $NF !~ /PACK/    && \
1635                                           $NF !~ /REBUILD/ && \
1636                                           $NF !~ /pack/ )     \
1637                                         { print $NF }' | sed -e "s/\(.*\)\.[0-9]*/\1/" )
1638
1639  eval set -A ${2} ${JobList[*]}
1640
1641  IGCM_debug_PopStack "IGCM_sys_ListJobInQueue"
1642}
1643
1644#D-#==================================================
1645#D-function IGCM_sys_atlas
1646#D-* Purpose: encapsulate atlas call so as to manage error code and curie specificity
1647#D-* Examples:
1648#D-
1649function IGCM_sys_atlas {
1650  IGCM_debug_PushStack "IGCM_sys_atlas" $@
1651  if ( $DEBUG_sys ) ; then
1652    echo "IGCM_sys_atlas :" $@
1653  fi
1654
1655  typeset status
1656
1657  \ccc_mprun atlas $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1658  status=$?
1659  if [ ${status} -gt 0 ] ; then
1660    echo "IGCM_sys_atlas : error code ${status}"
1661    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1662    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1663    IGCM_debug_PopStack "IGCM_sys_atlas"
1664    return 1
1665  else
1666    IGCM_debug_PopStack "IGCM_sys_atlas"
1667    return 0
1668  fi
1669
1670  IGCM_debug_PopStack "IGCM_sys_atlas"
1671}
1672
Note: See TracBrowser for help on using the repository browser.