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

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