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

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