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

Last change on this file since 1272 was 1272, checked in by mafoipsl, 8 years ago

Add a system function IGCM_sys_atlas specially adapted on curie (bug ksh) and allowing error discovery for all systems.
Use IGCM_sys_atlas funcion in AA_atlas jobs.

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