source: tags/libIGCM_v2.0_rc1/libIGCM_sys/libIGCM_sys_titane.ksh @ 1137

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