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

Last change on this file since 740 was 734, checked in by sdipsl, 12 years ago
  • bugfix : looping over rebuild command we must delete the first arguments not the last one.
  • bugfix : catching the last arg we must use this eval lastArg=\${$#} otherwise we won't catch the latest arguments if there are more than 9.
  • add date to debug print
  • Property svn:keywords set to Revision Author Date
File size: 84.2 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 firstArg
1861  # number of tentative
1862  NB_ESSAI=3
1863  # time delay between tentative
1864  DELAI=2
1865
1866  i=0
1867  while [ $i -lt $NB_ESSAI ] ; do
1868      /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@ > out_rsync 2>&1
1869    status=$?
1870    if [ ${status} -gt 0 ] ; then
1871      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1872      cat out_rsync
1873      \rm out_rsync
1874      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1875      firstArg=${1}
1876      \rm ${firstArg}
1877      sleep $DELAI
1878    else
1879      \rm out_rsync
1880      break
1881    fi
1882    (( i = i + 1 ))
1883  done
1884
1885  if [ ${status} -gt 0 ] ; then
1886    echo "IGCM_sys_rebuild : rebuild error"
1887    IGCM_debug_Exit "rebuild"
1888  fi
1889
1890  IGCM_debug_PopStack "IGCM_sys_rebuild"
1891}
1892
1893function IGCM_sys_rebuild_station {
1894  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1895  typeset i list_opt file_in file_out prefix_invert list_invert
1896  if ( $DEBUG_sys ) ; then
1897    echo "IGCM_sys_rebuild_station :" $@
1898  fi
1899  list_opt=$@
1900
1901  # Invert Axis : t,x -> x,t
1902  #               t,pres,x -> x,t,pres
1903  # So that we can concatenate along x
1904  i=0
1905  for file_in in ${list_opt} ; do
1906    (( i = i + 1))
1907    [ ${i} = 1 ] && file_out=${file_in} && continue
1908    prefix_invert=$( basename ${file_in} .nc )
1909    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1910    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1911  done
1912
1913  # Concatenate
1914  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1915
1916  # Re-ivert file
1917  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1918
1919  # Station re-ordering is too expansive to be run within libICGM
1920  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1921  # This re-ordering must be done "in memory" by the cmorization process
1922  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1923  # BEGIN reordering
1924
1925  # Only LMDZ text output contains the exact ordering of the station.
1926  # We isolate this in the code below:
1927  #  0  38  -157.5000000000000  70.98591549295774
1928  #  0  54  27.49999999999999   67.18309859154928
1929  #  0  56  -62.50000000000001  82.39436619718309
1930  #  0  79  12.49999999999999   78.59154929577466
1931  #  0  116 -165.0000000000000  76.05633802816901
1932  #  0  117 130.0000000000000   70.98591549295774
1933  #  0  118 110.0000000000000   87.46478873239437
1934  #  1  40  4.999999999999995   51.97183098591550
1935#  typeset iStation iProc list_opt file_in file_out prefix_invert
1936#  typeset -Z4 j4
1937#  typeset -Z3 j3
1938
1939#  unset list_opt
1940#  set +A list_opt $@
1941
1942  # Filename after rebuild
1943#  file_out=${list_opt[0]}
1944  # Prefix of output files
1945#  prefix_invert=$( basename ${file_out} .nc )
1946  # Number of procs
1947#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1948
1949#  iProc=0
1950#  while [ ${iProc} -lt ${num_proc} ] ; do
1951    # Array containing Station as a number
1952#    unset proc_stn
1953#    set +A proc_stn $( grep "iophy_mpi rank ip lon lat  $iProc" ${PREFIX}_${Exe_Output} | sed -e "s/iophy_mpi rank ip lon lat //g" | awk ' {print $2}' )
1954    # Number of stations produced by processor proc
1955#    stationLast=${#proc_stn[*]}
1956    # Proc number on 4 digits
1957#    j4=${iProc}
1958    # Init
1959#    iStation=0
1960#    while [ ${iStation} -lt ${stationLast} ] ; do
1961      # Station number on 3 digits
1962#      j3=${proc_stn[${iStation}]}
1963      # Extract station
1964      # Invert Axis : t,x -> x,t
1965      #               t,pres,x -> x,t,pres
1966      # So that we can concatenate along x
1967#      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs -d x,$iStation,$iStation ${prefix_invert}_${j4}.nc ${prefix_invert}_stn_${j3}.nc
1968#      (( iStation = iStation + 1 ))
1969#    done
1970#    (( iProc = iProc + 1 ))
1971#  done
1972
1973  # Concatenate all station along x
1974#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1975
1976  # Re-invert file
1977#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1978
1979  # END reordering
1980
1981  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1982}
1983
1984############################################################
1985# Activate Running Environnment Variables
1986
1987function IGCM_sys_activ_variables {
1988  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1989  if ( $DEBUG_sys ) ; then
1990    echo "IGCM_sys_activ_variables"
1991  fi
1992
1993  ulimit -s unlimited
1994
1995  export KMP_STACKSIZE=3g
1996  export KMP_LIBRARY=turnaround
1997  export MKL_SERIAL=YES
1998  unset MPI_PLACING_MODE
1999
2000  # add module load nb of threads for core placement
2001  (( max_omp = 0 ))
2002
2003  for comp in ${config_ListOfComponents[*]} ; do
2004    eval ExeNameIn=\${config_Executable_${comp}[0]}
2005    eval ExeNameOut=\${config_Executable_${comp}[1]}
2006
2007    # Only if we really have an executable for the component :
2008    if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2009      eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2010      if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
2011        (( max_omp = comp_proc_omp_loc ))
2012      fi
2013    fi
2014  done
2015
2016  ( [ X${max_omp} = X4 ] || [ X${max_omp} = X8 ] ) &&  { module load openmp/${max_omp}thds ; IGCM_debug_Print 1 "module load openmp/${max_omp}thds" ; }
2017
2018  IGCM_debug_PopStack "IGCM_sys_activ_variables"
2019}
2020
2021############################################################
2022# Desactivate Running Environnment Variables
2023
2024function IGCM_sys_desactiv_variables {
2025  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
2026  if ( $DEBUG_sys ) ; then
2027    echo "IGCM_sys_desactiv_variables"
2028  fi
2029  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
2030}
2031
2032############################################################
2033# Build MPI/OMP scripts run file (dummy function)
2034
2035function IGCM_sys_build_run_file {
2036
2037IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
2038
2039}
2040
2041############################################################
2042# Build MPI/OMP scripts
2043function IGCM_sys_build_execution_scripts
2044{
2045  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
2046  if ( $DEBUG_sys ) ; then
2047    echo "IGCM_sys_build_execution_scripts " $@
2048  fi
2049  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
2050  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
2051  typeset num_corempi nombre_restant_node nombre_restant_comp
2052  typeset IGCM_OMP
2053
2054  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
2055    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
2056  fi
2057
2058  if ( ${OK_PARA_MPMD} ) ; then
2059
2060    if [ -f run_file ] ; then
2061      IGCM_sys_Rm -f run_file
2062    fi
2063    touch run_file
2064
2065    if ( ${OK_PARA_OMP} ) ; then
2066
2067      #  Hosts treatment
2068
2069      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
2070
2071      i=0
2072      rm -f hosts
2073      IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
2074      for nodes in `cat hosts.tmp` ; do
2075        host[$i]=$nodes
2076        echo "${host[$i]} slots=8 max_slots=8" >> hosts
2077        IGCM_debug_Print 1 ${host[$i]}
2078        i=$((i+1))
2079      done
2080      rm -f hosts.tmp
2081
2082      listnodes=${host[*]}
2083
2084      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
2085
2086      # Initialisation
2087
2088      init_node=y
2089      node_num_current=0
2090      start_num=0
2091      init_exec=n
2092
2093      # Test : if oasis is there, we put it at the first position
2094
2095      for comp in ${config_ListOfComponents[*]} ; do
2096
2097        if [ "X${comp}" = "XCPL" ]  ; then
2098
2099          eval ExeNameIn=\${config_Executable_${comp}[0]}
2100          eval ExeNameOut=\${config_Executable_${comp}[1]}
2101
2102          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2103          echo ""  >> script_${ExeNameOut}.ksh
2104          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2105          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2106          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2107          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
2108          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2109
2110          init_node=n
2111
2112          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
2113          node_num_current=0
2114          node_current=${host[${node_num_current}]}
2115
2116          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
2117
2118          init_exec=y
2119          start_num=1
2120
2121        fi
2122
2123      done
2124
2125      # Then loop on the components (except for oasis)
2126
2127      for comp in ${config_ListOfComponents[*]} ; do
2128
2129        eval ExeNameIn=\${config_Executable_${comp}[0]}
2130        eval ExeNameOut=\${config_Executable_${comp}[1]}
2131
2132        # Only if we really have an executable for the component :
2133        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
2134
2135          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2136          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2137
2138          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2139          # echo "set -vx" >> script_${ExeNameOut}.ksh
2140          echo ""  >> script_${ExeNameOut}.ksh
2141          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2142          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2143          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2144          echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
2145          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
2146          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
2147          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2148
2149          node_num=0
2150
2151          # We define the number of MPI process to be assigned for the component
2152
2153          nombre_restant_comp=${comp_proc_mpi_loc}
2154
2155          # Loop on the allocated nodes
2156
2157          for node in ${listnodes} ; do
2158
2159            # We go to the current node
2160            if [ ${node_num} = ${node_num_current} ] ; then
2161
2162              node_current=${host[${node_num_current}]}
2163
2164              # If first time on the node : initialisation
2165
2166              if [ ${init_node} = y ] ; then
2167                nombre_restant_node=${NUM_COREPERNODE}
2168              fi
2169
2170              # Test on the number of OMP threads
2171
2172              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
2173                (( node_num = node_num + 1 ))
2174                node_num_current=${node_num}
2175                init_node=y
2176                continue
2177              fi
2178
2179              # Number of MPI process to assign
2180
2181              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
2182
2183              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
2184                num_corempi=${nombre_restant_comp}
2185              fi
2186
2187              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
2188              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
2189
2190              if [ ${init_exec} = y ] ; then
2191                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
2192              else
2193                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
2194                init_exec=y
2195              fi
2196
2197              ((  start_num = num_corempi + start_num ))
2198
2199            else
2200
2201              (( node_num = node_num + 1 ))
2202              continue
2203            fi
2204
2205            # Test on the number of core/process remaining on the node/component
2206
2207            if [ ${nombre_restant_node} = 0 ] ; then
2208              (( node_num = node_num + 1 ))
2209              node_num_current=${node_num}
2210              init_node=y
2211
2212              if [ ${nombre_restant_comp} = 0 ] ; then
2213                break 1
2214              fi
2215            else
2216
2217              node_num_current=${node_num}
2218              init_node=n
2219
2220              if [ ${nombre_restant_comp} = 0 ] ; then
2221                break 1
2222              fi
2223            fi
2224          done
2225        fi
2226      done
2227
2228    else
2229
2230        # Then first loop on the components for the coupler ie oasis
2231
2232        ## the coupler ie oasis must be the first one
2233        for comp in ${config_ListOfComponents[*]} ; do
2234
2235            eval ExeNameOut=\${config_Executable_${comp}[1]}
2236
2237        # for CPL component only
2238            if [ "X${comp}" = "XCPL" ] ; then
2239                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2240                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
2241            fi
2242        done
2243
2244        # Then second loop on the components
2245
2246        for comp in ${config_ListOfComponents[*]} ; do
2247
2248            eval ExeNameOut=\${config_Executable_${comp}[1]}
2249
2250            # Only if we really have an executable for the component and not the coupler ie oasis:
2251            if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
2252                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2253                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2254            fi
2255        done
2256        IGCM_sys_Chmod u+x run_file
2257
2258        EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
2259
2260    fi
2261
2262  else # Only one executable.
2263      # Check has to be added with :
2264      # Job :
2265      # #MSUB -n 8 # reservation des processeurs pour le job
2266      # #MSUB -N 4 # reservation des nodes pour le job
2267      # BATCH_NUM_PROC_TOT=32
2268      #
2269      # config.card :
2270      # ATM= (gcm.e, lmdz.x, 8MPI, 4OMP)
2271      #
2272      # tested with :
2273      # Job :
2274      # #MSUB -n 32
2275      # BATCH_NUM_PROC_TOT=32
2276      #
2277      # config.card :
2278      # ATM= (gcm.e, lmdz.x)
2279
2280
2281      for comp in ${config_ListOfComponents[*]} ; do
2282
2283          # Only if we really have an executable for the component :
2284          eval ExeNameOut=\${config_Executable_${comp}[1]}
2285###       if ( [ "X${ExeNameOut}" != X\"\" ] ) ; then
2286          if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2287
2288              IGCM_OMP=1
2289
2290              if ( ${OK_PARA_OMP} ) ; then
2291                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2292                  export OMP_NUM_THREADS=${comp_proc_omp_loc}
2293                  IGCMG_OMP=${comp_proc_omp_loc}
2294              fi
2295              if  ( ${OK_PARA_MPI} ) ; then
2296                  eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2297                  # Default : mpirun used if nb_proc gt 1
2298                  # pour sortie out/err par process ? more test required
2299                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
2300                  EXECUTION="${HOST_MPIRUN_COMMAND} -np ${comp_proc_mpi_loc} ./${ExeNameOut}"
2301              else
2302                  # Check if BATCH_NUM_PROC_TOT = IGCMG_OMP
2303                  if ( [  ${IGCM_OMP} -ne ${BATCH_NUM_PROC_TOT} ] ) ; then
2304                      IGCM_debug_Print 1 "sys Titane : BATCH_NUM_PROC_TOT <> ${comp}_PROC_OMP : ${BATCH_NUM_PROC_TOT} <> ${BRIDGE_MSUB_NPROC} "
2305                      IGCM_debug_Print 1 "sys Titane : Check #MSUB -n xx into Job"
2306                      IGCM_debug_Exit "IGCM_sys_build_execution_scripts"
2307                  fi
2308                  # Default : mpirun is NOT used if nb_proc eq 1
2309                  # pour sortie out/err par process ? more test required
2310                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
2311                  EXECUTION="/usr/bin/time ./${ExeNameOut}"
2312              fi
2313          fi
2314      done
2315
2316  fi
2317
2318  IGCM_debug_Print 1 "sys Titane : La commande d execution est "
2319  IGCM_debug_Print 1 "$EXECUTION"
2320
2321  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2322}
2323
2324############################################################
2325# Check of space available on temporary filesytems
2326function IGCM_sys_check_quota {
2327  IGCM_debug_PushStack "IGCM_sys_check_quota"
2328  if ( $DEBUG_sys ) ; then
2329    echo "IGCM_sys_check_quota "
2330  fi
2331  # Limit of quota (in %)
2332  limit_quota=90
2333
2334  # Check of the volume
2335  volume_quota=$(ccc_quota | grep ' scratch' | awk '{print $2}')
2336  volume_avail=$(ccc_quota | grep ' scratch' | awk '{print $3}')
2337
2338  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
2339
2340    unit_avail=${volume_avail: -1}
2341    unit_quota=${volume_quota: -1}
2342
2343    if [ "${unit_quota}" = "*" ] ; then
2344        IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2345        IGCM_debug_Print 1 "More than 100% of your quota is used"
2346        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2347        IGCM_debug_Print 1 "You must have more than 10% available to run"
2348        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2349        IGCM_debug_Verif_Exit
2350    fi
2351
2352    temp_avail=${volume_avail%%${volume_avail: -1}*}
2353    temp_quota=${volume_quota%%${volume_quota: -1}*}
2354
2355    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2356
2357    # Convertion
2358      if [ ${volume_avail: -1} = "T" ] ; then
2359        (( temp_avail = temp_avail * 1000000000000 ))
2360      elif [ ${volume_avail: -1} = "G" ] ; then
2361        (( temp_avail = temp_avail * 1000000000 ))
2362      elif [ ${volume_avail: -1} = "M" ] ; then
2363        (( temp_avail = temp_avail * 1000000 ))
2364      elif [ ${volume_avail: -1} = "k" ] ; then
2365        (( temp_avail = temp_avail * 1000 ))
2366      else
2367        (( temp_avail = volume_avail ))
2368      fi
2369      if [ ${volume_quota: -1} = "T" ] ; then
2370        (( temp_quota = temp_quota * 1000000000000 ))
2371      elif [ ${volume_quota: -1} = "G" ] ; then
2372        (( temp_quota = temp_quota * 1000000000 ))
2373      elif [ ${volume_quota: -1} = "M" ] ; then
2374        (( temp_quota = temp_quota * 1000000 ))
2375      elif [ ${volume_quota: -1} = "k" ] ; then
2376        (( temp_quota = temp_quota * 1000 ))
2377      else
2378        (( temp_quota = volume_quota ))
2379      fi
2380    fi
2381
2382    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2383#    echo "volume ratio is " $quota_volume
2384
2385    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2386      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2387      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2388      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2389      IGCM_debug_Print 1 "You must have more than 10% available to run"
2390      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2391      IGCM_debug_Verif_Exit
2392    fi
2393
2394  fi
2395
2396# Check of the number of inodes
2397
2398  inode_quota=$(ccc_quota | grep ' scratch' | awk '{print $6}')
2399  inode_avail=$(ccc_quota | grep ' scratch' | awk '{print $7}')
2400
2401  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
2402
2403    unit_avail=${inode_avail: -1}
2404    unit_quota=${inode_quota: -1}
2405
2406    if [ "${unit_quota}" = "*" ] ; then
2407        IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2408        IGCM_debug_Print 1 "More than 100% of your quota is used"
2409        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2410        IGCM_debug_Print 1 "You must have more than 10% available to run"
2411        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2412        IGCM_debug_Verif_Exit
2413    fi
2414
2415    temp_avail=${inode_avail%%${inode_avail: -1}*}
2416    temp_quota=${inode_quota%%${inode_quota: -1}*}
2417
2418    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2419
2420    # Convertion
2421      if [ ${inode_avail: -1} = "T" ] ; then
2422        (( temp_avail = temp_avail * 1000000000000 ))
2423      elif [ ${inode_avail: -1} = "G" ] ; then
2424        (( temp_avail = temp_avail * 1000000000 ))
2425      elif [ ${inode_avail: -1} = "M" ] ; then
2426        (( temp_avail = temp_avail * 1000000 ))
2427      elif [ ${inode_avail: -1} = "k" ] ; then
2428        (( temp_avail = temp_avail * 1000 ))
2429      else
2430        (( temp_avail = inode_avail ))
2431      fi
2432
2433      if [ ${inode_quota: -1} = "T" ] ; then
2434        (( temp_quota = temp_quota * 1000000000000 ))
2435      elif [ ${inode_quota: -1} = "G" ] ; then
2436        (( temp_quota = temp_quota * 1000000000 ))
2437      elif [ ${inode_quota: -1} = "M" ] ; then
2438        (( temp_quota = temp_quota * 1000000 ))
2439      elif [ ${inode_quota: -1} = "k" ] ; then
2440        (( temp_quota = temp_quota * 1000 ))
2441      else
2442        (( temp_quota = inode_quota ))
2443      fi
2444    fi
2445    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2446#    echo "inode ratio is " $quota_inode
2447
2448    if [ ${quota_inode} -ge ${limit_quota} ] ; then
2449      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2450      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
2451      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2452      IGCM_debug_Print 1 "You must have more than 10% available to run"
2453      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2454      IGCM_debug_Verif_Exit
2455    fi
2456
2457  fi
2458  IGCM_debug_PopStack "IGCM_sys_check_quota"
2459}
2460
2461##############################################################
2462# NCO OPERATOR
2463
2464function IGCM_sys_ncap2 {
2465  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2466  if ( $DEBUG_sys ) ; then
2467    echo "IGCM_sys_ncap2 :" $@
2468  fi
2469
2470  typeset NB_ESSAI DELAI status i
2471  # number of tentative
2472  NB_ESSAI=3
2473  # time delay between tentative
2474  DELAI=2
2475
2476  i=0
2477  while [ $i -lt $NB_ESSAI ] ; do
2478    ncap2 "$@" > out_rsync 2>&1
2479    status=$?
2480    if [ ${status} -gt 0 ] ; then
2481      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2482      cat out_rsync
2483      \rm out_rsync
2484      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2485      sleep $DELAI
2486    else
2487      \rm out_rsync
2488      break
2489    fi
2490    (( i = i + 1 ))
2491  done
2492
2493  if [ ${status} -gt 0 ] ; then
2494      echo "IGCM_sys_ncap2 : ncap2 error"
2495      IGCM_debug_Exit "ncap2"
2496  fi
2497
2498  IGCM_debug_PopStack "IGCM_sys_ncap2"
2499}
2500
2501function IGCM_sys_ncatted {
2502  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2503  if ( $DEBUG_sys ) ; then
2504    echo "IGCM_sys_ncatted :" $@
2505  fi
2506
2507  typeset NB_ESSAI DELAI status i
2508  # number of tentative
2509  NB_ESSAI=3
2510  # time delay between tentative
2511  DELAI=2
2512
2513  i=0
2514  while [ $i -lt $NB_ESSAI ] ; do
2515    ncatted "$@" > out_rsync 2>&1
2516    status=$?
2517    if [ ${status} -gt 0 ] ; then
2518      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2519      cat out_rsync
2520      \rm out_rsync
2521      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2522      sleep $DELAI
2523    else
2524      \rm out_rsync
2525      break
2526    fi
2527    (( i = i + 1 ))
2528  done
2529
2530  if [ ${status} -gt 0 ] ; then
2531      echo "IGCM_sys_ncatted : ncatted error"
2532      IGCM_debug_Exit "ncatted"
2533  fi
2534
2535  IGCM_debug_PopStack "IGCM_sys_ncatted"
2536}
2537
2538function IGCM_sys_ncbo {
2539  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2540  if ( $DEBUG_sys ) ; then
2541    echo "IGCM_sys_ncbo :" $@
2542  fi
2543
2544  typeset NB_ESSAI DELAI status i
2545  # number of tentative
2546  NB_ESSAI=3
2547  # time delay between tentative
2548  DELAI=2
2549
2550  i=0
2551  while [ $i -lt $NB_ESSAI ] ; do
2552    ncbo $@ > out_rsync 2>&1
2553    status=$?
2554    if [ ${status} -gt 0 ] ; then
2555      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2556      cat out_rsync
2557      \rm out_rsync
2558      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2559      sleep $DELAI
2560    else
2561      \rm out_rsync
2562      break
2563    fi
2564    (( i = i + 1 ))
2565  done
2566
2567  if [ ${status} -gt 0 ] ; then
2568      echo "IGCM_sys_ncbo : ncbo error"
2569      IGCM_debug_Exit "ncbo"
2570  fi
2571
2572  IGCM_debug_PopStack "IGCM_sys_ncbo"
2573}
2574
2575function IGCM_sys_ncdiff {
2576  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2577  if ( $DEBUG_sys ) ; then
2578    echo "IGCM_sys_ncdiff :" $@
2579  fi
2580
2581  typeset NB_ESSAI DELAI status i
2582  # number of tentative
2583  NB_ESSAI=3
2584  # time delay between tentative
2585  DELAI=2
2586
2587  i=0
2588  while [ $i -lt $NB_ESSAI ] ; do
2589    ncdiff $@ > out_rsync 2>&1
2590    status=$?
2591    if [ ${status} -gt 0 ] ; then
2592      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2593      cat out_rsync
2594      \rm out_rsync
2595      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2596      sleep $DELAI
2597    else
2598      \rm out_rsync
2599      break
2600    fi
2601    (( i = i + 1 ))
2602  done
2603
2604  if [ ${status} -gt 0 ] ; then
2605      echo "IGCM_sys_ncdiff : ncdiff error"
2606      IGCM_debug_Exit "ncdiff"
2607  fi
2608
2609  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2610}
2611
2612function IGCM_sys_ncea {
2613  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2614  if ( $DEBUG_sys ) ; then
2615    echo "IGCM_sys_ncea :" $@
2616  fi
2617
2618  typeset NB_ESSAI DELAI status i
2619  # number of tentative
2620  NB_ESSAI=3
2621  # time delay between tentative
2622  DELAI=2
2623
2624  i=0
2625  while [ $i -lt $NB_ESSAI ] ; do
2626    ncea $@ > out_rsync 2>&1
2627    status=$?
2628    if [ ${status} -gt 0 ] ; then
2629      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2630      cat out_rsync
2631      \rm out_rsync
2632      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2633      sleep $DELAI
2634    else
2635      \rm out_rsync
2636      break
2637    fi
2638    (( i = i + 1 ))
2639  done
2640
2641  if [ ${status} -gt 0 ] ; then
2642      echo "IGCM_sys_ncea : ncea error"
2643      IGCM_debug_Exit "ncea"
2644  fi
2645
2646  IGCM_debug_PopStack "IGCM_sys_ncea"
2647}
2648
2649function IGCM_sys_ncecat {
2650  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2651  if ( $DEBUG_sys ) ; then
2652    echo "IGCM_sys_ncecat :" $@
2653  fi
2654
2655  typeset NB_ESSAI DELAI status i
2656  # number of tentative
2657  NB_ESSAI=3
2658  # time delay between tentative
2659  DELAI=2
2660
2661  i=0
2662  while [ $i -lt $NB_ESSAI ] ; do
2663    ncecat $@ > out_rsync 2>&1
2664    status=$?
2665    if [ ${status} -gt 0 ] ; then
2666      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2667      cat out_rsync
2668      \rm out_rsync
2669      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2670      sleep $DELAI
2671    else
2672      \rm out_rsync
2673      break
2674    fi
2675    (( i = i + 1 ))
2676  done
2677
2678  if [ ${status} -gt 0 ] ; then
2679      echo "IGCM_sys_ncecat : ncecat error"
2680      IGCM_debug_Exit "ncecat"
2681  fi
2682
2683  IGCM_debug_PopStack "IGCM_sys_ncecat"
2684}
2685
2686function IGCM_sys_ncflint {
2687  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2688  if ( $DEBUG_sys ) ; then
2689    echo "IGCM_sys_ncflint :" $@
2690  fi
2691
2692  typeset NB_ESSAI DELAI status i
2693  # number of tentative
2694  NB_ESSAI=3
2695  # time delay between tentative
2696  DELAI=2
2697
2698  i=0
2699  while [ $i -lt $NB_ESSAI ] ; do
2700    ncflint $@ > out_rsync 2>&1
2701    status=$?
2702    if [ ${status} -gt 0 ] ; then
2703      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2704      cat out_rsync
2705      \rm out_rsync
2706      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2707      sleep $DELAI
2708    else
2709      \rm out_rsync
2710      break
2711    fi
2712    (( i = i + 1 ))
2713  done
2714
2715  if [ ${status} -gt 0 ] ; then
2716      echo "IGCM_sys_ncflint : ncflint error"
2717      IGCM_debug_Exit "ncflint"
2718  fi
2719
2720  IGCM_debug_PopStack "IGCM_sys_ncflint"
2721}
2722
2723function IGCM_sys_ncks {
2724  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2725  if ( $DEBUG_sys ) ; then
2726    echo "IGCM_sys_ncks :" $@
2727  fi
2728
2729  typeset NB_ESSAI DELAI status i
2730  # number of tentative
2731  NB_ESSAI=3
2732  # time delay between tentative
2733  DELAI=2
2734
2735  i=0
2736  while [ $i -lt $NB_ESSAI ] ; do
2737    ncks $@ > out_rsync 2>&1
2738    status=$?
2739    if [ ${status} -gt 0 ] ; then
2740      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2741      cat out_rsync
2742      \rm out_rsync
2743      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2744      sleep $DELAI
2745    else
2746      \rm out_rsync
2747      break
2748    fi
2749    (( i = i + 1 ))
2750  done
2751
2752  if [ ${status} -gt 0 ] ; then
2753      echo "IGCM_sys_ncks : ncks error"
2754      IGCM_debug_Exit "ncks"
2755  fi
2756
2757  IGCM_debug_PopStack "IGCM_sys_ncks"
2758}
2759
2760function IGCM_sys_ncpdq {
2761  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2762  if ( $DEBUG_sys ) ; then
2763    echo "IGCM_sys_ncpdq :" $@
2764  fi
2765
2766  typeset NB_ESSAI DELAI status i
2767  # number of tentative
2768  NB_ESSAI=3
2769  # time delay between tentative
2770  DELAI=2
2771
2772  i=0
2773  while [ $i -lt $NB_ESSAI ] ; do
2774    ncpdq $@ > out_rsync 2>&1
2775    status=$?
2776    if [ ${status} -gt 0 ] ; then
2777      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2778      cat out_rsync
2779      \rm out_rsync
2780      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2781      sleep $DELAI
2782    else
2783      \rm out_rsync
2784      break
2785    fi
2786    (( i = i + 1 ))
2787  done
2788
2789  if [ ${status} -gt 0 ] ; then
2790      echo "IGCM_sys_ncpdq : ncpdq error"
2791      IGCM_debug_Exit "ncpdq"
2792  fi
2793
2794  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2795}
2796
2797function IGCM_sys_ncra {
2798  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2799  if ( $DEBUG_sys ) ; then
2800    echo "IGCM_sys_ncra :" $@
2801  fi
2802
2803  typeset NB_ESSAI DELAI status i
2804  # number of tentative
2805  NB_ESSAI=3
2806  # time delay between tentative
2807  DELAI=2
2808
2809  i=0
2810  while [ $i -lt $NB_ESSAI ] ; do
2811    ncra $@ > out_rsync 2>&1
2812    status=$?
2813    if [ ${status} -gt 0 ] ; then
2814      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2815      cat out_rsync
2816      \rm out_rsync
2817      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2818      sleep $DELAI
2819    else
2820      \rm out_rsync
2821      break
2822    fi
2823    (( i = i + 1 ))
2824  done
2825
2826  if [ ${status} -gt 0 ] ; then
2827      echo "IGCM_sys_ncra : ncra error"
2828      IGCM_debug_Exit "ncra"
2829  fi
2830
2831  IGCM_debug_PopStack "IGCM_sys_ncra"
2832}
2833
2834function IGCM_sys_ncrcat {
2835  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2836  if ( $DEBUG_sys ) ; then
2837    echo "IGCM_sys_ncrcat :" $@
2838  fi
2839
2840  typeset NB_ESSAI DELAI status i
2841  # number of tentative
2842  NB_ESSAI=3
2843  # time delay between tentative
2844  DELAI=2
2845
2846  i=0
2847  while [ $i -lt $NB_ESSAI ] ; do
2848    ncrcat $@ > out_rsync 2>&1
2849    status=$?
2850    if [ ${status} -gt 0 ] ; then
2851      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2852      cat out_rsync
2853      \rm out_rsync
2854      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2855      sleep $DELAI
2856    else
2857      \rm out_rsync
2858      break
2859    fi
2860    (( i = i + 1 ))
2861  done
2862
2863  if [ ${status} -gt 0 ] ; then
2864      echo "IGCM_sys_ncrcat : ncrcat error"
2865      #IGCM_debug_Exit "ncrcat"
2866  fi
2867
2868  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2869}
2870
2871function IGCM_sys_ncrename {
2872  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2873  if ( $DEBUG_sys ) ; then
2874    echo "IGCM_sys_ncrename :" $@
2875  fi
2876
2877  typeset NB_ESSAI DELAI status i
2878  # number of tentative
2879  NB_ESSAI=3
2880  # time delay between tentative
2881  DELAI=2
2882
2883  i=0
2884  while [ $i -lt $NB_ESSAI ] ; do
2885    ncrename $@ > out_rsync 2>&1
2886    status=$?
2887    if [ ${status} -gt 0 ] ; then
2888      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2889      cat out_rsync
2890      \rm out_rsync
2891      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2892      sleep $DELAI
2893    else
2894      \rm out_rsync
2895      break
2896    fi
2897    (( i = i + 1 ))
2898  done
2899
2900  if [ ${status} -gt 0 ] ; then
2901      echo "IGCM_sys_ncrename : ncrename error"
2902      IGCM_debug_Exit "ncrename"
2903  fi
2904
2905  IGCM_debug_PopStack "IGCM_sys_ncrename"
2906}
2907
2908function IGCM_sys_ncwa {
2909  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2910  if ( $DEBUG_sys ) ; then
2911    echo "IGCM_sys_ncwa :" $@
2912  fi
2913
2914  typeset NB_ESSAI DELAI status i
2915  # number of tentative
2916  NB_ESSAI=3
2917  # time delay between tentative
2918  DELAI=2
2919
2920  i=0
2921  while [ $i -lt $NB_ESSAI ] ; do
2922    ncwa $@ > out_rsync 2>&1
2923    status=$?
2924    if [ ${status} -gt 0 ] ; then
2925      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2926      cat out_rsync
2927      \rm out_rsync
2928      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2929      sleep $DELAI
2930    else
2931      \rm out_rsync
2932      break
2933    fi
2934    (( i = i + 1 ))
2935  done
2936
2937  if [ ${status} -gt 0 ] ; then
2938      echo "IGCM_sys_ncwa : ncwa error"
2939      IGCM_debug_Exit "ncwa"
2940  fi
2941
2942  IGCM_debug_PopStack "IGCM_sys_ncwa"
2943}
2944
2945##############################################################
2946# CDO OPERATOR
2947
2948function IGCM_sys_cdo {
2949  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2950  if ( $DEBUG_sys ) ; then
2951    echo "IGCM_sys_cdo :" $@
2952  fi
2953
2954  typeset status
2955
2956  \cdo $@ > out_rsync 2>&1
2957  status=$?
2958  if [ ${status} -gt 0 ] ; then
2959    echo "IGCM_sys_cdo : error code ${status}"
2960    cat out_rsync
2961    \rm out_rsync
2962    IGCM_debug_PopStack "IGCM_sys_cdo"
2963    return 1
2964  else
2965    IGCM_debug_PopStack "IGCM_sys_cdo"
2966    return 0
2967  fi
2968
2969  IGCM_debug_PopStack "IGCM_sys_cdo"
2970}
Note: See TracBrowser for help on using the repository browser.