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

Last change on this file since 727 was 725, checked in by sdipsl, 12 years ago
  • prepare sys lib to be able to run/store on scratchdir when running TEST simulation
  • bugfix : rebuild can't overwrite existing files neither write things in a tmp file before moving it to a final file. So we need to clean things up for him
  • cosmetics
  • Property svn:keywords set to Revision Author Date
File size: 83.5 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          sleep $DELAI
1334        else
1335          break
1336        fi
1337        (( i = i + 1 ))
1338      done
1339    fi
1340
1341#       #RSYNC WITH NETWORK SSH CALL
1342#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1343#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1344
1345#       #RSYNC WITH NFS USE
1346#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1347#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1348
1349#       status=$?
1350#       IGCM_sys_Rsync_out $status
1351
1352#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1353#       (( status=status+$? ))
1354
1355    if [ ${status} -gt 0 ] ; then
1356      echo "IGCM_sys_Put_Out : error."
1357      cat out_rsync
1358      IGCM_debug_Exit "IGCM_sys_Put_Out"
1359    else
1360      \rm out_rsync
1361    fi
1362  else
1363    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1364  fi
1365  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1366  return 0
1367}
1368
1369#D-#==================================================
1370#D-function IGCM_sys_PutBuffer_Out
1371#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1372#D-* Examples:
1373#D-
1374function IGCM_sys_PutBuffer_Out {
1375  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1376  if ( $DEBUG_sys ) ; then
1377    echo "IGCM_sys_PutBuffer_Out :" $@
1378  fi
1379
1380  typeset NB_ESSAI DELAI status i exist skip
1381
1382  # number of tentative
1383  NB_ESSAI=3
1384  # time delay between tentative
1385  DELAI=2
1386
1387  if [ $DRYRUN = 0 ]; then
1388    if [ ! -f ${1} ] ; then
1389      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1390      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1391      return 1
1392    fi
1393    #
1394    IGCM_sys_Mkdir $( dirname $2 )
1395    #
1396
1397    if [ X${JobType} = XRUN ] ; then
1398      if [ X${3} = X ] ; then
1399        IGCM_sys_Chmod 444 ${1}
1400      fi
1401    fi
1402
1403    exist=false
1404    skip=false
1405    if [ -f $2 ] ; then
1406      IGCM_debug_Print 1 "$2 already exist"
1407      exist=true
1408      if [ "X$( diff $1 $2 )" = X ] ; then
1409        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1410        skip=true
1411      else
1412        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1413        skip=false
1414      fi
1415    fi
1416    #
1417    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1418      IGCM_sys_Chmod u+w $2
1419    fi
1420
1421    if [ X${skip} = Xfalse ] ; then
1422      i=0
1423      while [ $i -lt $NB_ESSAI ] ; do
1424        # USUAL WAY
1425        \cp $1 $2 > out_rsync 2>&1
1426        status=$?
1427        if [ ${status} -gt 0 ]; then
1428          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1429          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1430          sleep $DELAI
1431        else
1432          break
1433        fi
1434        (( i = i + 1 ))
1435      done
1436    fi
1437
1438    if [ ${status} -gt 0 ] ; then
1439      echo "IGCM_sys_PutBuffer_Out : error."
1440      cat out_rsync
1441      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1442    else
1443      \rm out_rsync
1444    fi
1445  else
1446    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1447  fi
1448  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1449  return 0
1450}
1451
1452#D-#==================================================
1453#D-function IGCM_sys_Get
1454#D-* Purpose: Get a file from ${ARCHIVE}
1455#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1456#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1457function IGCM_sys_Get {
1458  IGCM_debug_PushStack "IGCM_sys_Get" $@
1459
1460  typeset DEST dm_liste ifile target file_work
1461  typeset NB_ESSAI DELAI status i
1462
1463  if ( $DEBUG_sys ) ; then
1464    echo "IGCM_sys_Get :" $@
1465  fi
1466
1467  # number of tentative
1468  NB_ESSAI=3
1469  # time delay between tentative
1470  DELAI=2
1471
1472  if [ $DRYRUN -le 2 ]; then
1473    if [ X${1} = X'/l' ] ; then
1474      # test if the first file is present in the old computation :
1475      eval set +A dm_liste \${${2}}
1476    else
1477      eval set +A dm_liste ${1}
1478    fi
1479    eval DEST=\${${#}}
1480
1481    #=====================================================
1482    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1483    #=====================================================
1484
1485    # Is it an R_OUT file (not R_IN) ?
1486    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1487    #if [ $? -eq 0 ] ; then
1488    #    # Yes  ? then we try to get it in SCRATCHDIR
1489    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1490    #    if [ -f ${file_work[0]} ] ; then
1491    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1492    #   IGCM_debug_PopStack "IGCM_sys_Get"
1493    #   return
1494    #    fi
1495    #fi
1496
1497    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1498    status=$?
1499    if [ ${status} -gt 0 ] ; then
1500      echo "WARNING IGCM_sys_Get : error code ${status}"
1501      cat out_rsync
1502      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1503    fi
1504
1505    #if [ ${status} -gt 0 ] ; then
1506    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1507    #   cat out_rsync
1508    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1509    #   sleep 30
1510    #   echo "We try another time"
1511    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1512    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1513    #   status=$?
1514    #   if [ ${status} -gt 0 ] ; then
1515    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1516    #       cat out_rsync
1517    #       IGCM_debug_Exit "IGCM_sys_Get"
1518    #   fi
1519    #    else
1520    #   echo "ERROR IGCM_sys_Get : demigration error :"
1521    #   cat out_rsync
1522    #   IGCM_debug_Exit "IGCM_sys_Get"
1523    #    fi
1524    #fi
1525
1526    #   #RSYNC WITH NETWORK SSH CALL
1527    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1528    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1529
1530    #   #RSYNC WITH NFS USE
1531    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1532    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1533
1534    #   status=$?
1535    #   IGCM_sys_Rsync_out $status
1536
1537    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1538    #   (( status=status+$? ))
1539
1540    #USUAL WAY
1541    if [ X${1} = X'/l' ] ; then
1542      for target in ${dm_liste[*]} ; do
1543        local_file=$( basename ${target} )
1544        # test if the target file is present before the loop
1545        IGCM_sys_TestFileArchive ${target}
1546        status=$?
1547        if [ ${status} -gt 0 ] ; then
1548          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1549          IGCM_debug_Exit "IGCM_sys_Get"
1550        else
1551          i=0
1552          while [ $i -lt $NB_ESSAI ] ; do
1553            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1554            status=$?
1555            if [ ${status} -gt 0 ]; then
1556              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1557              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1558              sleep $DELAI
1559            else
1560              break
1561            fi
1562            (( i = i + 1 ))
1563          done
1564          if [ ${status} -gt 0 ] ; then
1565            echo "IGCM_sys_Get : error"
1566            cat out_rsync
1567            \rm out_rsync
1568            IGCM_debug_Exit "IGCM_sys_Get"
1569          else
1570            \rm out_rsync
1571          fi
1572        fi
1573      done
1574    else
1575      i=0
1576      while [ $i -lt $NB_ESSAI ] ; do
1577        \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1578        status=$?
1579        if [ ${status} -gt 0 ]; then
1580          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1581          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1582          sleep $DELAI
1583        else
1584          break
1585        fi
1586        (( i = i + 1 ))
1587      done
1588      if [ ${status} -gt 0 ] ; then
1589        echo "IGCM_sys_Get : error"
1590        cat out_rsync
1591        \rm out_rsync
1592        IGCM_debug_Exit "IGCM_sys_Get"
1593      else
1594        \rm out_rsync
1595      fi
1596    fi
1597  else
1598    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1599  fi
1600  IGCM_debug_PopStack "IGCM_sys_Get"
1601}
1602
1603#D-#==================================================
1604#D-function IGCM_sys_GetBuffer
1605#D-* Purpose: Get a file from ${SCRATCHDIR}
1606#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1607#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1608function IGCM_sys_GetBuffer {
1609  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1610
1611  typeset DEST buf_liste ifile target file_work
1612  typeset NB_ESSAI DELAI status i
1613
1614  if ( $DEBUG_sys ) ; then
1615    echo "IGCM_sys_GetBuffer :" $@
1616  fi
1617
1618  # number of tentative
1619  NB_ESSAI=3
1620  # time delay between tentative
1621  DELAI=2
1622
1623  if [ $DRYRUN -le 2 ]; then
1624    if [ X${1} = X'/l' ] ; then
1625      # test if the first file is present in the old computation :
1626      eval set +A buf_liste \${${2}}
1627    else
1628      eval set +A buf_liste ${1}
1629    fi
1630    eval DEST=\${${#}}
1631
1632    #USUAL WAY
1633    if [ X${1} = X'/l' ] ; then
1634      for target in ${buf_liste[*]} ; do
1635        local_file=$( basename ${target} )
1636        i=0
1637        while [ $i -lt $NB_ESSAI ] ; do
1638          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1639          status=$?
1640          if [ ${status} -gt 0 ]; then
1641            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1642            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1643            sleep $DELAI
1644          else
1645            break
1646          fi
1647          (( i = i + 1 ))
1648        done
1649        if [ ${status} -gt 0 ] ; then
1650          echo "IGCM_sys_Get : error"
1651          cat out_rsync
1652          \rm out_rsync
1653          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1654        else
1655          \rm out_rsync
1656        fi
1657      done
1658    else
1659      i=0
1660      while [ $i -lt $NB_ESSAI ] ; do
1661        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1662        status=$?
1663        if [ ${status} -gt 0 ]; then
1664          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1665          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1666          sleep $DELAI
1667        else
1668          break
1669        fi
1670        (( i = i + 1 ))
1671      done
1672      if [ ${status} -gt 0 ] ; then
1673        echo "IGCM_sys_Get : error"
1674        cat out_rsync
1675        \rm out_rsync
1676        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1677      else
1678        \rm out_rsync
1679      fi
1680    fi
1681  else
1682    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1683  fi
1684  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1685}
1686
1687#D-#==================================================
1688#D-function IGCM_sys_GetDate_FichWork
1689#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1690#D-* Examples:
1691#D-
1692function IGCM_sys_GetDate_FichWork {
1693  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1694  if ( $DEBUG_sys ) ; then
1695    echo "IGCM_sys_GetDate_FichWork :" $@
1696  fi
1697  typeset dateF
1698  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1699  eval ${2}=${dateF[5]}
1700
1701    # donne la date filesys d'un fichier sur la machine work
1702  IGCM_debug_PopStack "IGCM_sys_FichWork"
1703}
1704
1705#D-#==================================================
1706#D-function IGCM_sys_GetDate_FichArchive
1707#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1708#D-* Examples:
1709#D-
1710function IGCM_sys_GetDate_FichArchive {
1711  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1712  if ( $DEBUG_sys ) ; then
1713    echo "IGCM_sys_GetDate_FichArchive :" $@
1714  fi
1715  typeset dateF
1716  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1717  eval ${2}=${dateF[5]}
1718
1719  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1720}
1721
1722#D-#==================================================
1723#D-function IGCM_sys_Dods_Rm
1724#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1725#D-* Examples:
1726#D-
1727function IGCM_sys_Dods_Rm {
1728  if ( $DEBUG_sys ) ; then
1729    echo "IGCM_sys_Dods_Rm :" $@
1730  fi
1731  typeset status
1732  if [ $DRYRUN = 0 ]; then
1733
1734#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1735#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1736#      echo "Nothing has been done."
1737#      return
1738#    fi
1739
1740    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1741    status=$?
1742
1743#       if [ ${status} -gt 0 ] ; then
1744#           echo "IGCM_sys_Dods_Rm : error."
1745#           cat out_dods_rm
1746#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1747#       else
1748#           rm out_dods_rm
1749#       fi
1750
1751  else
1752    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1753  fi
1754  return $status
1755}
1756
1757#D-#==================================================
1758#D-function IGCM_sys_Dods_Cp
1759#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1760#D-* Examples:
1761#D-
1762function IGCM_sys_Dods_Cp {
1763  if ( $DEBUG_sys ) ; then
1764    echo "IGCM_sys_Dods_Cp :" $@
1765  fi
1766  typeset status
1767  if [ $DRYRUN = 0 ]; then
1768
1769#    if [ ! -d ${R_SAVE}/${1} ] ; then
1770#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1771#      echo "Nothing has been done."
1772#      return
1773#    fi
1774
1775    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1776    status=$?
1777
1778#       if [ ${status} -gt 0 ] ; then
1779#           echo "IGCM_sys_Dods_Cp : error."
1780#           cat out_dods_cp
1781#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1782#       else
1783#           rm out_dods_cp
1784#       fi
1785
1786  else
1787    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1788  fi
1789  return $status
1790}
1791
1792#D-#==================================================
1793#D-function IGCM_sys_Put_Dods
1794#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1795#D-* Examples:
1796#D-
1797function IGCM_sys_Put_Dods {
1798  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1799  if ( $DEBUG_sys ) ; then
1800    echo "IGCM_sys_Put_Dods :" $@
1801  fi
1802  #set -vx
1803  typeset status
1804  if [ $DRYRUN = 0 ]; then
1805    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1806      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1807      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1808      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1809      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1810      return
1811    fi
1812
1813    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1814      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1815      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1816      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1817      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1818      return
1819    fi
1820    #
1821    if [ -d ${R_SAVE}/${1} ] ; then
1822      cd ${R_SAVE}
1823    elif [ -d ${R_FIGR}/${1} ] ; then
1824      cd ${R_FIGR}
1825    fi
1826
1827    IGCM_sys_Dods_Rm ${1}
1828    IGCM_sys_Dods_Cp ${1}
1829    status=0
1830
1831    if [ ${status} -gt 0 ] ; then
1832      echo "IGCM_sys_Put_Dods : error."
1833      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1834    fi
1835  else
1836    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1837  fi
1838  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1839}
1840
1841##############################################################
1842# REBUILD OPERATOR
1843
1844function IGCM_sys_rebuild {
1845  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1846  if ( $DEBUG_sys ) ; then
1847    echo "IGCM_sys_rebuild :" $@
1848  fi
1849
1850  typeset NB_ESSAI DELAI status i lastArg
1851  # number of tentative
1852  NB_ESSAI=3
1853  # time delay between tentative
1854  DELAI=2
1855
1856  i=0
1857  while [ $i -lt $NB_ESSAI ] ; do
1858      /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@ > out_rsync 2>&1
1859    status=$?
1860    if [ ${status} -gt 0 ] ; then
1861      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1862      cat out_rsync
1863      \rm out_rsync
1864      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1865      eval lastArg=\$$#
1866      \rm ${lastArg}
1867    else
1868      \rm out_rsync
1869      break
1870    fi
1871    (( i = i + 1 ))
1872  done
1873
1874  if [ ${status} -gt 0 ] ; then
1875    echo "IGCM_sys_rebuild : rebuild error"
1876    IGCM_debug_Exit "rebuild"
1877  fi
1878
1879  IGCM_debug_PopStack "IGCM_sys_rebuild"
1880}
1881
1882function IGCM_sys_rebuild_station {
1883  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1884  typeset i list_opt file_in file_out prefix_invert list_invert
1885  if ( $DEBUG_sys ) ; then
1886    echo "IGCM_sys_rebuild_station :" $@
1887  fi
1888  list_opt=$@
1889
1890  # Invert Axis : t,x -> x,t
1891  #               t,pres,x -> x,t,pres
1892  # So that we can concatenate along x
1893  i=0
1894  for file_in in ${list_opt} ; do
1895    (( i = i + 1))
1896    [ ${i} = 1 ] && file_out=${file_in} && continue
1897    prefix_invert=$( basename ${file_in} .nc )
1898    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1899    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1900  done
1901
1902  # Concatenate
1903  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1904
1905  # Re-ivert file
1906  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1907
1908  # Station re-ordering is too expansive to be run within libICGM
1909  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1910  # This re-ordering must be done "in memory" by the cmorization process
1911  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1912  # BEGIN reordering
1913
1914  # Only LMDZ text output contains the exact ordering of the station.
1915  # We isolate this in the code below:
1916  #  0  38  -157.5000000000000  70.98591549295774
1917  #  0  54  27.49999999999999   67.18309859154928
1918  #  0  56  -62.50000000000001  82.39436619718309
1919  #  0  79  12.49999999999999   78.59154929577466
1920  #  0  116 -165.0000000000000  76.05633802816901
1921  #  0  117 130.0000000000000   70.98591549295774
1922  #  0  118 110.0000000000000   87.46478873239437
1923  #  1  40  4.999999999999995   51.97183098591550
1924#  typeset iStation iProc list_opt file_in file_out prefix_invert
1925#  typeset -Z4 j4
1926#  typeset -Z3 j3
1927
1928#  unset list_opt
1929#  set +A list_opt $@
1930
1931  # Filename after rebuild
1932#  file_out=${list_opt[0]}
1933  # Prefix of output files
1934#  prefix_invert=$( basename ${file_out} .nc )
1935  # Number of procs
1936#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1937
1938#  iProc=0
1939#  while [ ${iProc} -lt ${num_proc} ] ; do
1940    # Array containing Station as a number
1941#    unset proc_stn
1942#    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}' )
1943    # Number of stations produced by processor proc
1944#    stationLast=${#proc_stn[*]}
1945    # Proc number on 4 digits
1946#    j4=${iProc}
1947    # Init
1948#    iStation=0
1949#    while [ ${iStation} -lt ${stationLast} ] ; do
1950      # Station number on 3 digits
1951#      j3=${proc_stn[${iStation}]}
1952      # Extract station
1953      # Invert Axis : t,x -> x,t
1954      #               t,pres,x -> x,t,pres
1955      # So that we can concatenate along x
1956#      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
1957#      (( iStation = iStation + 1 ))
1958#    done
1959#    (( iProc = iProc + 1 ))
1960#  done
1961
1962  # Concatenate all station along x
1963#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1964
1965  # Re-invert file
1966#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1967
1968  # END reordering
1969
1970  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1971}
1972
1973############################################################
1974# Activate Running Environnment Variables
1975
1976function IGCM_sys_activ_variables {
1977  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1978  if ( $DEBUG_sys ) ; then
1979    echo "IGCM_sys_activ_variables"
1980  fi
1981
1982  ulimit -s unlimited
1983
1984  export KMP_STACKSIZE=3g
1985  export KMP_LIBRARY=turnaround
1986  export MKL_SERIAL=YES
1987  unset MPI_PLACING_MODE
1988
1989  # add module load nb of threads for core placement
1990  (( max_omp = 0 ))
1991
1992  for comp in ${config_ListOfComponents[*]} ; do
1993    eval ExeNameIn=\${config_Executable_${comp}[0]}
1994    eval ExeNameOut=\${config_Executable_${comp}[1]}
1995
1996    # Only if we really have an executable for the component :
1997    if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1998      eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1999      if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
2000        (( max_omp = comp_proc_omp_loc ))
2001      fi
2002    fi
2003  done
2004
2005  ( [ X${max_omp} = X4 ] || [ X${max_omp} = X8 ] ) &&  { module load openmp/${max_omp}thds ; IGCM_debug_Print 1 "module load openmp/${max_omp}thds" ; }
2006
2007  IGCM_debug_PopStack "IGCM_sys_activ_variables"
2008}
2009
2010############################################################
2011# Desactivate Running Environnment Variables
2012
2013function IGCM_sys_desactiv_variables {
2014  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
2015  if ( $DEBUG_sys ) ; then
2016    echo "IGCM_sys_desactiv_variables"
2017  fi
2018  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
2019}
2020
2021############################################################
2022# Build MPI/OMP scripts run file (dummy function)
2023
2024function IGCM_sys_build_run_file {
2025
2026IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
2027
2028}
2029
2030############################################################
2031# Build MPI/OMP scripts
2032function IGCM_sys_build_execution_scripts
2033{
2034  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
2035  if ( $DEBUG_sys ) ; then
2036    echo "IGCM_sys_build_execution_scripts " $@
2037  fi
2038  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
2039  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
2040  typeset num_corempi nombre_restant_node nombre_restant_comp
2041  typeset IGCM_OMP
2042
2043  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
2044    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
2045  fi
2046
2047  if ( ${OK_PARA_MPMD} ) ; then
2048
2049    if [ -f run_file ] ; then
2050      IGCM_sys_Rm -f run_file
2051    fi
2052    touch run_file
2053
2054    if ( ${OK_PARA_OMP} ) ; then
2055
2056      #  Hosts treatment
2057
2058      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
2059
2060      i=0
2061      rm -f hosts
2062      IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
2063      for nodes in `cat hosts.tmp` ; do
2064        host[$i]=$nodes
2065        echo "${host[$i]} slots=8 max_slots=8" >> hosts
2066        IGCM_debug_Print 1 ${host[$i]}
2067        i=$((i+1))
2068      done
2069      rm -f hosts.tmp
2070
2071      listnodes=${host[*]}
2072
2073      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
2074
2075      # Initialisation
2076
2077      init_node=y
2078      node_num_current=0
2079      start_num=0
2080      init_exec=n
2081
2082      # Test : if oasis is there, we put it at the first position
2083
2084      for comp in ${config_ListOfComponents[*]} ; do
2085
2086        if [ "X${comp}" = "XCPL" ]  ; then
2087
2088          eval ExeNameIn=\${config_Executable_${comp}[0]}
2089          eval ExeNameOut=\${config_Executable_${comp}[1]}
2090
2091          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2092          echo ""  >> script_${ExeNameOut}.ksh
2093          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2094          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2095          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2096          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
2097          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2098
2099          init_node=n
2100
2101          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
2102          node_num_current=0
2103          node_current=${host[${node_num_current}]}
2104
2105          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
2106
2107          init_exec=y
2108          start_num=1
2109
2110        fi
2111
2112      done
2113
2114      # Then loop on the components (except for oasis)
2115
2116      for comp in ${config_ListOfComponents[*]} ; do
2117
2118        eval ExeNameIn=\${config_Executable_${comp}[0]}
2119        eval ExeNameOut=\${config_Executable_${comp}[1]}
2120
2121        # Only if we really have an executable for the component :
2122        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
2123
2124          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2125          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2126
2127          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2128          # echo "set -vx" >> script_${ExeNameOut}.ksh
2129          echo ""  >> script_${ExeNameOut}.ksh
2130          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2131          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2132          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2133          echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
2134          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
2135          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
2136          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2137
2138          node_num=0
2139
2140          # We define the number of MPI process to be assigned for the component
2141
2142          nombre_restant_comp=${comp_proc_mpi_loc}
2143
2144          # Loop on the allocated nodes
2145
2146          for node in ${listnodes} ; do
2147
2148            # We go to the current node
2149            if [ ${node_num} = ${node_num_current} ] ; then
2150
2151              node_current=${host[${node_num_current}]}
2152
2153              # If first time on the node : initialisation
2154
2155              if [ ${init_node} = y ] ; then
2156                nombre_restant_node=${NUM_COREPERNODE}
2157              fi
2158
2159              # Test on the number of OMP threads
2160
2161              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
2162                (( node_num = node_num + 1 ))
2163                node_num_current=${node_num}
2164                init_node=y
2165                continue
2166              fi
2167
2168              # Number of MPI process to assign
2169
2170              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
2171
2172              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
2173                num_corempi=${nombre_restant_comp}
2174              fi
2175
2176              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
2177              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
2178
2179              if [ ${init_exec} = y ] ; then
2180                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
2181              else
2182                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
2183                init_exec=y
2184              fi
2185
2186              ((  start_num = num_corempi + start_num ))
2187
2188            else
2189
2190              (( node_num = node_num + 1 ))
2191              continue
2192            fi
2193
2194            # Test on the number of core/process remaining on the node/component
2195
2196            if [ ${nombre_restant_node} = 0 ] ; then
2197              (( node_num = node_num + 1 ))
2198              node_num_current=${node_num}
2199              init_node=y
2200
2201              if [ ${nombre_restant_comp} = 0 ] ; then
2202                break 1
2203              fi
2204            else
2205
2206              node_num_current=${node_num}
2207              init_node=n
2208
2209              if [ ${nombre_restant_comp} = 0 ] ; then
2210                break 1
2211              fi
2212            fi
2213          done
2214        fi
2215      done
2216
2217    else
2218
2219        # Then first loop on the components for the coupler ie oasis
2220
2221        ## the coupler ie oasis must be the first one
2222        for comp in ${config_ListOfComponents[*]} ; do
2223
2224            eval ExeNameOut=\${config_Executable_${comp}[1]}
2225
2226        # for CPL component only
2227            if [ "X${comp}" = "XCPL" ] ; then
2228                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2229                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
2230            fi
2231        done
2232
2233        # Then second loop on the components
2234
2235        for comp in ${config_ListOfComponents[*]} ; do
2236
2237            eval ExeNameOut=\${config_Executable_${comp}[1]}
2238
2239            # Only if we really have an executable for the component and not the coupler ie oasis:
2240            if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
2241                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2242                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2243            fi
2244        done
2245        IGCM_sys_Chmod u+x run_file
2246
2247        EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
2248
2249    fi
2250
2251  else # Only one executable.
2252      # Check has to be added with :
2253      # Job :
2254      # #MSUB -n 8 # reservation des processeurs pour le job
2255      # #MSUB -N 4 # reservation des nodes pour le job
2256      # BATCH_NUM_PROC_TOT=32
2257      #
2258      # config.card :
2259      # ATM= (gcm.e, lmdz.x, 8MPI, 4OMP)
2260      #
2261      # tested with :
2262      # Job :
2263      # #MSUB -n 32
2264      # BATCH_NUM_PROC_TOT=32
2265      #
2266      # config.card :
2267      # ATM= (gcm.e, lmdz.x)
2268
2269
2270      for comp in ${config_ListOfComponents[*]} ; do
2271
2272          # Only if we really have an executable for the component :
2273          eval ExeNameOut=\${config_Executable_${comp}[1]}
2274###       if ( [ "X${ExeNameOut}" != X\"\" ] ) ; then
2275          if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2276
2277              IGCM_OMP=1
2278
2279              if ( ${OK_PARA_OMP} ) ; then
2280                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2281                  export OMP_NUM_THREADS=${comp_proc_omp_loc}
2282                  IGCMG_OMP=${comp_proc_omp_loc}
2283              fi
2284              if  ( ${OK_PARA_MPI} ) ; then
2285                  eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2286                  # Default : mpirun used if nb_proc gt 1
2287                  # pour sortie out/err par process ? more test required
2288                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
2289                  EXECUTION="${HOST_MPIRUN_COMMAND} -np ${comp_proc_mpi_loc} ./${ExeNameOut}"
2290              else
2291                  # Check if BATCH_NUM_PROC_TOT = IGCMG_OMP
2292                  if ( [  ${IGCM_OMP} -ne ${BATCH_NUM_PROC_TOT} ] ) ; then
2293                      IGCM_debug_Print 1 "sys Titane : BATCH_NUM_PROC_TOT <> ${comp}_PROC_OMP : ${BATCH_NUM_PROC_TOT} <> ${BRIDGE_MSUB_NPROC} "
2294                      IGCM_debug_Print 1 "sys Titane : Check #MSUB -n xx into Job"
2295                      IGCM_debug_Exit "IGCM_sys_build_execution_scripts"
2296                  fi
2297                  # Default : mpirun is NOT used if nb_proc eq 1
2298                  # pour sortie out/err par process ? more test required
2299                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
2300                  EXECUTION="/usr/bin/time ./${ExeNameOut}"
2301              fi
2302          fi
2303      done
2304
2305  fi
2306
2307  IGCM_debug_Print 1 "sys Titane : La commande d execution est "
2308  IGCM_debug_Print 1 "$EXECUTION"
2309
2310  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2311}
2312
2313############################################################
2314# Check of space available on temporary filesytems
2315function IGCM_sys_check_quota {
2316  IGCM_debug_PushStack "IGCM_sys_check_quota"
2317  if ( $DEBUG_sys ) ; then
2318    echo "IGCM_sys_check_quota "
2319  fi
2320  # Limit of quota (in %)
2321  limit_quota=90
2322
2323  # Check of the volume
2324  volume_quota=$(ccc_quota | grep ' scratch' | awk '{print $2}')
2325  volume_avail=$(ccc_quota | grep ' scratch' | awk '{print $3}')
2326
2327  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
2328
2329    unit_avail=${volume_avail: -1}
2330    unit_quota=${volume_quota: -1}
2331
2332    if [ "${unit_quota}" = "*" ] ; then
2333        IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2334        IGCM_debug_Print 1 "More than 100% of your quota is used"
2335        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2336        IGCM_debug_Print 1 "You must have more than 10% available to run"
2337        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2338        IGCM_debug_Verif_Exit
2339    fi
2340
2341    temp_avail=${volume_avail%%${volume_avail: -1}*}
2342    temp_quota=${volume_quota%%${volume_quota: -1}*}
2343
2344    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2345
2346    # Convertion
2347      if [ ${volume_avail: -1} = "T" ] ; then
2348        (( temp_avail = temp_avail * 1000000000000 ))
2349      elif [ ${volume_avail: -1} = "G" ] ; then
2350        (( temp_avail = temp_avail * 1000000000 ))
2351      elif [ ${volume_avail: -1} = "M" ] ; then
2352        (( temp_avail = temp_avail * 1000000 ))
2353      elif [ ${volume_avail: -1} = "k" ] ; then
2354        (( temp_avail = temp_avail * 1000 ))
2355      else
2356        (( temp_avail = volume_avail ))
2357      fi
2358      if [ ${volume_quota: -1} = "T" ] ; then
2359        (( temp_quota = temp_quota * 1000000000000 ))
2360      elif [ ${volume_quota: -1} = "G" ] ; then
2361        (( temp_quota = temp_quota * 1000000000 ))
2362      elif [ ${volume_quota: -1} = "M" ] ; then
2363        (( temp_quota = temp_quota * 1000000 ))
2364      elif [ ${volume_quota: -1} = "k" ] ; then
2365        (( temp_quota = temp_quota * 1000 ))
2366      else
2367        (( temp_quota = volume_quota ))
2368      fi
2369    fi
2370
2371    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2372#    echo "volume ratio is " $quota_volume
2373
2374    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2375      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2376      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2377      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2378      IGCM_debug_Print 1 "You must have more than 10% available to run"
2379      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2380      IGCM_debug_Verif_Exit
2381    fi
2382
2383  fi
2384
2385# Check of the number of inodes
2386
2387  inode_quota=$(ccc_quota | grep ' scratch' | awk '{print $6}')
2388  inode_avail=$(ccc_quota | grep ' scratch' | awk '{print $7}')
2389
2390  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
2391
2392    unit_avail=${inode_avail: -1}
2393    unit_quota=${inode_quota: -1}
2394
2395    if [ "${unit_quota}" = "*" ] ; then
2396        IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2397        IGCM_debug_Print 1 "More than 100% of your quota is used"
2398        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2399        IGCM_debug_Print 1 "You must have more than 10% available to run"
2400        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2401        IGCM_debug_Verif_Exit
2402    fi
2403
2404    temp_avail=${inode_avail%%${inode_avail: -1}*}
2405    temp_quota=${inode_quota%%${inode_quota: -1}*}
2406
2407    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2408
2409    # Convertion
2410      if [ ${inode_avail: -1} = "T" ] ; then
2411        (( temp_avail = temp_avail * 1000000000000 ))
2412      elif [ ${inode_avail: -1} = "G" ] ; then
2413        (( temp_avail = temp_avail * 1000000000 ))
2414      elif [ ${inode_avail: -1} = "M" ] ; then
2415        (( temp_avail = temp_avail * 1000000 ))
2416      elif [ ${inode_avail: -1} = "k" ] ; then
2417        (( temp_avail = temp_avail * 1000 ))
2418      else
2419        (( temp_avail = inode_avail ))
2420      fi
2421
2422      if [ ${inode_quota: -1} = "T" ] ; then
2423        (( temp_quota = temp_quota * 1000000000000 ))
2424      elif [ ${inode_quota: -1} = "G" ] ; then
2425        (( temp_quota = temp_quota * 1000000000 ))
2426      elif [ ${inode_quota: -1} = "M" ] ; then
2427        (( temp_quota = temp_quota * 1000000 ))
2428      elif [ ${inode_quota: -1} = "k" ] ; then
2429        (( temp_quota = temp_quota * 1000 ))
2430      else
2431        (( temp_quota = inode_quota ))
2432      fi
2433    fi
2434    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2435#    echo "inode ratio is " $quota_inode
2436
2437    if [ ${quota_inode} -ge ${limit_quota} ] ; then
2438      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2439      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
2440      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2441      IGCM_debug_Print 1 "You must have more than 10% available to run"
2442      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2443      IGCM_debug_Verif_Exit
2444    fi
2445
2446  fi
2447  IGCM_debug_PopStack "IGCM_sys_check_quota"
2448}
2449
2450##############################################################
2451# NCO OPERATOR
2452
2453function IGCM_sys_ncap2 {
2454  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2455  if ( $DEBUG_sys ) ; then
2456    echo "IGCM_sys_ncap2 :" $@
2457  fi
2458
2459  typeset NB_ESSAI DELAI status i
2460  # number of tentative
2461  NB_ESSAI=3
2462  # time delay between tentative
2463  DELAI=2
2464
2465  i=0
2466  while [ $i -lt $NB_ESSAI ] ; do
2467    ncap2 "$@" > out_rsync 2>&1
2468    status=$?
2469    if [ ${status} -gt 0 ] ; then
2470      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2471      cat out_rsync
2472      \rm out_rsync
2473      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2474    else
2475      \rm out_rsync
2476      break
2477    fi
2478    (( i = i + 1 ))
2479  done
2480
2481  if [ ${status} -gt 0 ] ; then
2482      echo "IGCM_sys_ncap2 : ncap2 error"
2483      IGCM_debug_Exit "ncap2"
2484  fi
2485
2486  IGCM_debug_PopStack "IGCM_sys_ncap2"
2487}
2488
2489function IGCM_sys_ncatted {
2490  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2491  if ( $DEBUG_sys ) ; then
2492    echo "IGCM_sys_ncatted :" $@
2493  fi
2494
2495  typeset NB_ESSAI DELAI status i
2496  # number of tentative
2497  NB_ESSAI=3
2498  # time delay between tentative
2499  DELAI=2
2500
2501  i=0
2502  while [ $i -lt $NB_ESSAI ] ; do
2503    ncatted "$@" > out_rsync 2>&1
2504    status=$?
2505    if [ ${status} -gt 0 ] ; then
2506      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2507      cat out_rsync
2508      \rm out_rsync
2509      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2510    else
2511      \rm out_rsync
2512      break
2513    fi
2514    (( i = i + 1 ))
2515  done
2516
2517  if [ ${status} -gt 0 ] ; then
2518      echo "IGCM_sys_ncatted : ncatted error"
2519      IGCM_debug_Exit "ncatted"
2520  fi
2521
2522  IGCM_debug_PopStack "IGCM_sys_ncatted"
2523}
2524
2525function IGCM_sys_ncbo {
2526  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2527  if ( $DEBUG_sys ) ; then
2528    echo "IGCM_sys_ncbo :" $@
2529  fi
2530
2531  typeset NB_ESSAI DELAI status i
2532  # number of tentative
2533  NB_ESSAI=3
2534  # time delay between tentative
2535  DELAI=2
2536
2537  i=0
2538  while [ $i -lt $NB_ESSAI ] ; do
2539    ncbo $@ > out_rsync 2>&1
2540    status=$?
2541    if [ ${status} -gt 0 ] ; then
2542      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2543      cat out_rsync
2544      \rm out_rsync
2545      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2546    else
2547      \rm out_rsync
2548      break
2549    fi
2550    (( i = i + 1 ))
2551  done
2552
2553  if [ ${status} -gt 0 ] ; then
2554      echo "IGCM_sys_ncbo : ncbo error"
2555      IGCM_debug_Exit "ncbo"
2556  fi
2557
2558  IGCM_debug_PopStack "IGCM_sys_ncbo"
2559}
2560
2561function IGCM_sys_ncdiff {
2562  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2563  if ( $DEBUG_sys ) ; then
2564    echo "IGCM_sys_ncdiff :" $@
2565  fi
2566
2567  typeset NB_ESSAI DELAI status i
2568  # number of tentative
2569  NB_ESSAI=3
2570  # time delay between tentative
2571  DELAI=2
2572
2573  i=0
2574  while [ $i -lt $NB_ESSAI ] ; do
2575    ncdiff $@ > out_rsync 2>&1
2576    status=$?
2577    if [ ${status} -gt 0 ] ; then
2578      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2579      cat out_rsync
2580      \rm out_rsync
2581      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2582    else
2583      \rm out_rsync
2584      break
2585    fi
2586    (( i = i + 1 ))
2587  done
2588
2589  if [ ${status} -gt 0 ] ; then
2590      echo "IGCM_sys_ncdiff : ncdiff error"
2591      IGCM_debug_Exit "ncdiff"
2592  fi
2593
2594  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2595}
2596
2597function IGCM_sys_ncea {
2598  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2599  if ( $DEBUG_sys ) ; then
2600    echo "IGCM_sys_ncea :" $@
2601  fi
2602
2603  typeset NB_ESSAI DELAI status i
2604  # number of tentative
2605  NB_ESSAI=3
2606  # time delay between tentative
2607  DELAI=2
2608
2609  i=0
2610  while [ $i -lt $NB_ESSAI ] ; do
2611    ncea $@ > out_rsync 2>&1
2612    status=$?
2613    if [ ${status} -gt 0 ] ; then
2614      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2615      cat out_rsync
2616      \rm out_rsync
2617      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2618    else
2619      \rm out_rsync
2620      break
2621    fi
2622    (( i = i + 1 ))
2623  done
2624
2625  if [ ${status} -gt 0 ] ; then
2626      echo "IGCM_sys_ncea : ncea error"
2627      IGCM_debug_Exit "ncea"
2628  fi
2629
2630  IGCM_debug_PopStack "IGCM_sys_ncea"
2631}
2632
2633function IGCM_sys_ncecat {
2634  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2635  if ( $DEBUG_sys ) ; then
2636    echo "IGCM_sys_ncecat :" $@
2637  fi
2638
2639  typeset NB_ESSAI DELAI status i
2640  # number of tentative
2641  NB_ESSAI=3
2642  # time delay between tentative
2643  DELAI=2
2644
2645  i=0
2646  while [ $i -lt $NB_ESSAI ] ; do
2647    ncecat $@ > out_rsync 2>&1
2648    status=$?
2649    if [ ${status} -gt 0 ] ; then
2650      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2651      cat out_rsync
2652      \rm out_rsync
2653      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2654    else
2655      \rm out_rsync
2656      break
2657    fi
2658    (( i = i + 1 ))
2659  done
2660
2661  if [ ${status} -gt 0 ] ; then
2662      echo "IGCM_sys_ncecat : ncecat error"
2663      IGCM_debug_Exit "ncecat"
2664  fi
2665
2666  IGCM_debug_PopStack "IGCM_sys_ncecat"
2667}
2668
2669function IGCM_sys_ncflint {
2670  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2671  if ( $DEBUG_sys ) ; then
2672    echo "IGCM_sys_ncflint :" $@
2673  fi
2674
2675  typeset NB_ESSAI DELAI status i
2676  # number of tentative
2677  NB_ESSAI=3
2678  # time delay between tentative
2679  DELAI=2
2680
2681  i=0
2682  while [ $i -lt $NB_ESSAI ] ; do
2683    ncflint $@ > out_rsync 2>&1
2684    status=$?
2685    if [ ${status} -gt 0 ] ; then
2686      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2687      cat out_rsync
2688      \rm out_rsync
2689      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2690    else
2691      \rm out_rsync
2692      break
2693    fi
2694    (( i = i + 1 ))
2695  done
2696
2697  if [ ${status} -gt 0 ] ; then
2698      echo "IGCM_sys_ncflint : ncflint error"
2699      IGCM_debug_Exit "ncflint"
2700  fi
2701
2702  IGCM_debug_PopStack "IGCM_sys_ncflint"
2703}
2704
2705function IGCM_sys_ncks {
2706  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2707  if ( $DEBUG_sys ) ; then
2708    echo "IGCM_sys_ncks :" $@
2709  fi
2710
2711  typeset NB_ESSAI DELAI status i
2712  # number of tentative
2713  NB_ESSAI=3
2714  # time delay between tentative
2715  DELAI=2
2716
2717  i=0
2718  while [ $i -lt $NB_ESSAI ] ; do
2719    ncks $@ > out_rsync 2>&1
2720    status=$?
2721    if [ ${status} -gt 0 ] ; then
2722      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2723      cat out_rsync
2724      \rm out_rsync
2725      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2726    else
2727      \rm out_rsync
2728      break
2729    fi
2730    (( i = i + 1 ))
2731  done
2732
2733  if [ ${status} -gt 0 ] ; then
2734      echo "IGCM_sys_ncks : ncks error"
2735      IGCM_debug_Exit "ncks"
2736  fi
2737
2738  IGCM_debug_PopStack "IGCM_sys_ncks"
2739}
2740
2741function IGCM_sys_ncpdq {
2742  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2743  if ( $DEBUG_sys ) ; then
2744    echo "IGCM_sys_ncpdq :" $@
2745  fi
2746
2747  typeset NB_ESSAI DELAI status i
2748  # number of tentative
2749  NB_ESSAI=3
2750  # time delay between tentative
2751  DELAI=2
2752
2753  i=0
2754  while [ $i -lt $NB_ESSAI ] ; do
2755    ncpdq $@ > out_rsync 2>&1
2756    status=$?
2757    if [ ${status} -gt 0 ] ; then
2758      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2759      cat out_rsync
2760      \rm out_rsync
2761      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2762    else
2763      \rm out_rsync
2764      break
2765    fi
2766    (( i = i + 1 ))
2767  done
2768
2769  if [ ${status} -gt 0 ] ; then
2770      echo "IGCM_sys_ncpdq : ncpdq error"
2771      IGCM_debug_Exit "ncpdq"
2772  fi
2773
2774  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2775}
2776
2777function IGCM_sys_ncra {
2778  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2779  if ( $DEBUG_sys ) ; then
2780    echo "IGCM_sys_ncra :" $@
2781  fi
2782
2783  typeset NB_ESSAI DELAI status i
2784  # number of tentative
2785  NB_ESSAI=3
2786  # time delay between tentative
2787  DELAI=2
2788
2789  i=0
2790  while [ $i -lt $NB_ESSAI ] ; do
2791    ncra $@ > out_rsync 2>&1
2792    status=$?
2793    if [ ${status} -gt 0 ] ; then
2794      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2795      cat out_rsync
2796      \rm out_rsync
2797      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2798    else
2799      \rm out_rsync
2800      break
2801    fi
2802    (( i = i + 1 ))
2803  done
2804
2805  if [ ${status} -gt 0 ] ; then
2806      echo "IGCM_sys_ncra : ncra error"
2807      IGCM_debug_Exit "ncra"
2808  fi
2809
2810  IGCM_debug_PopStack "IGCM_sys_ncra"
2811}
2812
2813function IGCM_sys_ncrcat {
2814  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2815  if ( $DEBUG_sys ) ; then
2816    echo "IGCM_sys_ncrcat :" $@
2817  fi
2818
2819  typeset NB_ESSAI DELAI status i
2820  # number of tentative
2821  NB_ESSAI=3
2822  # time delay between tentative
2823  DELAI=2
2824
2825  i=0
2826  while [ $i -lt $NB_ESSAI ] ; do
2827    ncrcat $@ > out_rsync 2>&1
2828    status=$?
2829    if [ ${status} -gt 0 ] ; then
2830      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2831      cat out_rsync
2832      \rm out_rsync
2833      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2834    else
2835      \rm out_rsync
2836      break
2837    fi
2838    (( i = i + 1 ))
2839  done
2840
2841  if [ ${status} -gt 0 ] ; then
2842      echo "IGCM_sys_ncrcat : ncrcat error"
2843      #IGCM_debug_Exit "ncrcat"
2844  fi
2845
2846  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2847}
2848
2849function IGCM_sys_ncrename {
2850  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2851  if ( $DEBUG_sys ) ; then
2852    echo "IGCM_sys_ncrename :" $@
2853  fi
2854
2855  typeset NB_ESSAI DELAI status i
2856  # number of tentative
2857  NB_ESSAI=3
2858  # time delay between tentative
2859  DELAI=2
2860
2861  i=0
2862  while [ $i -lt $NB_ESSAI ] ; do
2863    ncrename $@ > out_rsync 2>&1
2864    status=$?
2865    if [ ${status} -gt 0 ] ; then
2866      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2867      cat out_rsync
2868      \rm out_rsync
2869      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2870    else
2871      \rm out_rsync
2872      break
2873    fi
2874    (( i = i + 1 ))
2875  done
2876
2877  if [ ${status} -gt 0 ] ; then
2878      echo "IGCM_sys_ncrename : ncrename error"
2879      IGCM_debug_Exit "ncrename"
2880  fi
2881
2882  IGCM_debug_PopStack "IGCM_sys_ncrename"
2883}
2884
2885function IGCM_sys_ncwa {
2886  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2887  if ( $DEBUG_sys ) ; then
2888    echo "IGCM_sys_ncwa :" $@
2889  fi
2890
2891  typeset NB_ESSAI DELAI status i
2892  # number of tentative
2893  NB_ESSAI=3
2894  # time delay between tentative
2895  DELAI=2
2896
2897  i=0
2898  while [ $i -lt $NB_ESSAI ] ; do
2899    ncwa $@ > out_rsync 2>&1
2900    status=$?
2901    if [ ${status} -gt 0 ] ; then
2902      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2903      cat out_rsync
2904      \rm out_rsync
2905      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2906    else
2907      \rm out_rsync
2908      break
2909    fi
2910    (( i = i + 1 ))
2911  done
2912
2913  if [ ${status} -gt 0 ] ; then
2914      echo "IGCM_sys_ncwa : ncwa error"
2915      IGCM_debug_Exit "ncwa"
2916  fi
2917
2918  IGCM_debug_PopStack "IGCM_sys_ncwa"
2919}
2920
2921##############################################################
2922# CDO OPERATOR
2923
2924function IGCM_sys_cdo {
2925  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2926  if ( $DEBUG_sys ) ; then
2927    echo "IGCM_sys_cdo :" $@
2928  fi
2929
2930  typeset status
2931
2932  \cdo $@ > out_rsync 2>&1
2933  status=$?
2934  if [ ${status} -gt 0 ] ; then
2935    echo "IGCM_sys_cdo : error code ${status}"
2936    cat out_rsync
2937    \rm out_rsync
2938    IGCM_debug_PopStack "IGCM_sys_cdo"
2939    return 1
2940  else
2941    IGCM_debug_PopStack "IGCM_sys_cdo"
2942    return 0
2943  fi
2944
2945  IGCM_debug_PopStack "IGCM_sys_cdo"
2946}
Note: See TracBrowser for help on using the repository browser.