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

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