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

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