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

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