source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_titane.ksh @ 804

Last change on this file since 804 was 804, checked in by sdipsl, 11 years ago
  • Files waiting for rebuild are stored within the relevant simulation tree. see #87

--> /IGCM_OUT/TagName/SpaceName/ExperiementName/JobName/REBUILD

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