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

Last change on this file since 714 was 714, checked in by sdipsl, 12 years ago

all machine : multiple tries over nco commands.

  • Property svn:keywords set to Revision Author Date
File size: 77.6 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:=/dmnfs/cont003/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 RET 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  RET=$?
862
863  if [ ${RET} -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 RET
882
883  echo cp $@ > out_rsync 2>&1
884  \cp $@ >> out_rsync 2>&1
885  RET=$?
886
887  if [ ${RET} -gt 0 ] ; then
888    echo "IGCM_sys_Cp : error."
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 RET
909
910  echo rm $@ > out_rsync 2>&1
911  \rm $@ >> out_rsync 2>&1
912  RET=$?
913
914  if [ ${RET} -gt 0 ] ; then
915    echo "IGCM_sys_Rm : error."
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 RET
937
938  echo rm $@ > out_rsync 2>&1
939  \rm $@ >> out_rsync 2>&1
940  RET=$?
941
942  if [ ${RET} -gt 0 ] ; then
943    echo "IGCM_sys_RmRunDir : error."
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 RET
966
967    echo mv $@ > out_rsync 2>&1
968    \mv $@ >> out_rsync 2>&1
969    RET=$?
970
971    if [ ${RET} -gt 0 ] ; then
972      echo "IGCM_sys_Mv : error in mv."
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 RET
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    RET=$?
1010
1011    if [ ${RET} -gt 0 ] ; then
1012      echo "IGCM_sys_Put_Dir : error."
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 RET
1042
1043    # Only if we use rsync
1044    #IGCM_sys_TestDirArchive $( dirname $2 )
1045    #
1046    # USUAL WAY
1047    # add dmfind/dmget (to demigrate all offline files) :
1048    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
1049    ccc_hsm get -r $1
1050    \cp -r $1 $2 > out_rsync 2>&1
1051    RET=$?
1052
1053    if [ ${RET} -gt 0 ] ; then
1054      echo "IGCM_sys_Get_Dir : error."
1055      cat out_rsync
1056      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1057    else
1058      \rm out_rsync
1059    fi
1060  else
1061    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1062  fi
1063  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1064}
1065
1066#D-#==================================================
1067#D-function IGCM_sys_Get_Master
1068#D-* Purpose: Copy a complete directory from MASTER filesystem
1069#D-* Examples:
1070#D-
1071function IGCM_sys_Get_Master {
1072  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1073  if ( $DEBUG_sys ) ; then
1074    echo "IGCM_sys_Get_Master :" $@
1075  fi
1076  if [ $DRYRUN = 0 ]; then
1077    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
1078      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1079      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1080      return
1081    fi
1082
1083    typeset RET
1084
1085    #USUAL WAY
1086    \cp -rL $1 $2 > out_rsync 2>&1
1087    RET=$?
1088
1089    if [ ${RET} -gt 0 ] ; then
1090      echo "IGCM_sys_Get_Master : error."
1091      cat out_rsync
1092      IGCM_debug_Exit "IGCM_sys_Get_Master"
1093    else
1094      \rm out_rsync
1095    fi
1096  else
1097    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1098  fi
1099  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1100}
1101
1102#====================================================
1103#- Call IGCM_sys_Mirror_libIGCM now !
1104if ( $MirrorlibIGCM ) ; then
1105  IGCM_sys_Mirror_libIGCM
1106fi
1107
1108#D-#==================================================
1109#D-function IGCM_sys_Put_Rest
1110#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1111#D-           File and target directory must exist.
1112#D-* Examples:
1113#D-
1114function IGCM_sys_Put_Rest {
1115  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1116  if ( $DEBUG_sys ) ; then
1117    echo "IGCM_sys_Put_Rest :" $@
1118  fi
1119  if [ $DRYRUN = 0 ]; then
1120    if [ ! -f ${1} ] ; then
1121      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1122      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1123    fi
1124
1125    typeset RET
1126    #
1127    if [ X${JobType} = XRUN ] ; then
1128      IGCM_sys_Chmod 444 ${1}
1129    fi
1130
1131    #
1132    # USUAL WAY
1133    \cp $1 $2 > out_rsync 2>&1
1134    RET=$?
1135
1136#       #RSYNC WITH NETWORK SSH CALL
1137#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1138#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1139
1140#       #RSYNC WITH NFS USE
1141#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1142#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1143
1144#       RET=$?
1145#       IGCM_sys_Rsync_out $RET
1146
1147#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1148#       (( RET=RET+$? ))
1149
1150    if [ ${RET} -gt 0 ] ; then
1151      echo "IGCM_sys_Put_Rest : error."
1152      cat out_rsync
1153      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1154    else
1155      \rm out_rsync
1156    fi
1157  else
1158    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1159  fi
1160  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1161}
1162
1163#D-#==================================================
1164#D-function IGCM_sys_PutBuffer_Rest
1165#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1166#D-           File and target directory must exist.
1167#D-* Examples:
1168#D-
1169function IGCM_sys_PutBuffer_Rest {
1170  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1171  if ( $DEBUG_sys ) ; then
1172    echo "IGCM_sys_PutBuffer_Rest :" $@
1173  fi
1174  if [ $DRYRUN = 0 ]; then
1175    if [ ! -f ${1} ] ; then
1176      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1177      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1178    fi
1179
1180    typeset RET
1181    #
1182    if [ X${JobType} = XRUN ] ; then
1183      IGCM_sys_Chmod 444 ${1}
1184    fi
1185
1186    #
1187    # USUAL WAY
1188    \cp $1 $2 > out_rsync 2>&1
1189    RET=$?
1190
1191    if [ ${RET} -gt 0 ] ; then
1192      echo "IGCM_sys_PutBuffer_Rest : error."
1193      cat out_rsync
1194      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1195    else
1196      \rm out_rsync
1197    fi
1198  else
1199    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1200  fi
1201  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1202}
1203
1204#D-#==================================================
1205#D-function IGCM_sys_Put_Out
1206#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1207#D-* Examples:
1208#D-
1209function IGCM_sys_Put_Out {
1210  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1211  if ( $DEBUG_sys ) ; then
1212    echo "IGCM_sys_Put_Out :" $@
1213  fi
1214
1215  typeset NB_ESSAI DELAI RET i
1216
1217  # number of tentative
1218  NB_ESSAI=3
1219  # time delay between tentative
1220  DELAI=2
1221
1222  if [ $DRYRUN = 0 ]; then
1223    if [ ! -f ${1} ] ; then
1224      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1225      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1226      return 1
1227    fi
1228    #
1229    IGCM_sys_MkdirArchive $( dirname $2 )
1230    #
1231
1232    #=====================================================
1233    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1234    #=====================================================
1235
1236    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1237    #if [ $? -eq 0 ] ; then
1238    #    typeset WORKPATH FILEPATH
1239    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1240    #    IGCM_sys_MkdirWork ${WORKPATH}
1241    #    FILEPATH=${WORKPATH}/$( basename $2 )
1242    #    #
1243    #    IGCM_sys_Cp ${1} ${FILEPATH}
1244    #fi
1245
1246    if [ X${JobType} = XRUN ] ; then
1247      if [ X${3} = X ] ; then
1248        IGCM_sys_Chmod 444 ${1}
1249      fi
1250    fi
1251    #
1252
1253    (( i = 0 ))
1254    while [ $i -lt $NB_ESSAI ] ; do
1255    # USUAL WAY
1256      \cp $1 $2 > out_rsync 2>&1
1257      RET=$?
1258      if [ ${RET} -gt 0 ]; then
1259        IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed ${i}/${NB_ESSAI}"
1260        IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1261        sleep $DELAI
1262      else
1263        break
1264      fi
1265      (( i = i + 1 ))
1266    done
1267
1268#       #RSYNC WITH NETWORK SSH CALL
1269#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1270#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1271
1272#       #RSYNC WITH NFS USE
1273#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1274#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1275
1276#       RET=$?
1277#       IGCM_sys_Rsync_out $RET
1278
1279#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1280#       (( RET=RET+$? ))
1281
1282    if [ ${RET} -gt 0 ] ; then
1283      echo "IGCM_sys_Put_Out : error."
1284      cat out_rsync
1285      IGCM_debug_Exit "IGCM_sys_Put_Out"
1286    else
1287      \rm out_rsync
1288    fi
1289  else
1290    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1291  fi
1292  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1293  return 0
1294}
1295
1296#D-#==================================================
1297#D-function IGCM_sys_PutBuffer_Out
1298#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1299#D-* Examples:
1300#D-
1301function IGCM_sys_PutBuffer_Out {
1302  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1303  if ( $DEBUG_sys ) ; then
1304    echo "IGCM_sys_PutBuffer_Out :" $@
1305  fi
1306  if [ $DRYRUN = 0 ]; then
1307    if [ ! -f ${1} ] ; then
1308      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1309      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1310      return 1
1311    fi
1312    #
1313    IGCM_sys_Mkdir $( dirname $2 )
1314    #
1315    typeset RET
1316
1317    if [ X${JobType} = XRUN ] ; then
1318      if [ X${3} = X ] ; then
1319        IGCM_sys_Chmod 444 ${1}
1320      fi
1321    fi
1322    #
1323    # USUAL WAY
1324    \cp $1 $2 > out_rsync 2>&1
1325    RET=$?
1326
1327    if [ ${RET} -gt 0 ] ; then
1328      echo "IGCM_sys_PutBuffer_Out : error."
1329      cat out_rsync
1330      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1331    else
1332      \rm out_rsync
1333    fi
1334  else
1335    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1336  fi
1337  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1338  return 0
1339}
1340
1341#D-#==================================================
1342#D-function IGCM_sys_Get
1343#D-* Purpose: Get a file from ${ARCHIVE}
1344#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1345#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1346function IGCM_sys_Get {
1347  IGCM_debug_PushStack "IGCM_sys_Get" $@
1348
1349  typeset DEST RET dm_liste ifile target file_work
1350  typeset NB_ESSAI DELAI status i
1351
1352  if ( $DEBUG_sys ) ; then
1353    echo "IGCM_sys_Get :" $@
1354  fi
1355
1356  # number of tentative
1357  NB_ESSAI=3
1358  # time delay between tentative
1359  DELAI=2
1360
1361  if [ $DRYRUN -le 2 ]; then
1362    if [ X${1} = X'/l' ] ; then
1363      # test if the first file is present in the old computation :
1364      eval set +A dm_liste \${${2}}
1365    else
1366      eval set +A dm_liste ${1}
1367    fi
1368    eval DEST=\${${#}}
1369
1370    #=====================================================
1371    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1372    #=====================================================
1373
1374    # Is it an R_OUT file (not R_IN) ?
1375    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1376    #if [ $? -eq 0 ] ; then
1377    #    # Yes  ? then we try to get it in SCRATCHDIR
1378    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1379    #    if [ -f ${file_work[0]} ] ; then
1380    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1381    #   IGCM_debug_PopStack "IGCM_sys_Get"
1382    #   return
1383    #    fi
1384    #fi
1385
1386    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1387    RET=$?
1388    if [ ${RET} -gt 0 ] ; then
1389      echo "WARNING IGCM_sys_Get : demigration error."
1390      cat out_rsync
1391      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1392    fi
1393
1394    #if [ ${RET} -gt 0 ] ; then
1395    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1396    #   cat out_rsync
1397    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1398    #   sleep 30
1399    #   echo "We try another time"
1400    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1401    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1402    #   RET=$?
1403    #   if [ ${RET} -gt 0 ] ; then
1404    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1405    #       cat out_rsync
1406    #       IGCM_debug_Exit "IGCM_sys_Get"
1407    #   fi
1408    #    else
1409    #   echo "ERROR IGCM_sys_Get : demigration error :"
1410    #   cat out_rsync
1411    #   IGCM_debug_Exit "IGCM_sys_Get"
1412    #    fi
1413    #fi
1414
1415    #USUAL WAY
1416    if [ X${1} = X'/l' ] ; then
1417      (( RET=0 ))
1418      for target in ${dm_liste[*]} ; do
1419        local_file=$( basename ${target} )
1420        (( i = 0 ))
1421        # test if the target file is present before the loop
1422        IGCM_sys_TestFileArchive ${target}
1423        RET=$?
1424        if [ ${RET} -gt 0 ] ; then
1425          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1426          IGCM_debug_Exit "IGCM_sys_Get"
1427        else
1428          while [ $i -lt $NB_ESSAI ] ; do
1429            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1430            status=$?
1431            if [ ${status} -gt 0 ]; then
1432              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed ${i}/${NB_ESSAI}"
1433              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1434              sleep $DELAI
1435            else
1436              break
1437            fi
1438            (( i = i + 1 ))
1439          done
1440          (( RET = RET + status ))
1441        fi
1442      done
1443    else
1444      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1445      RET=$?
1446    fi
1447
1448#       #RSYNC WITH NETWORK SSH CALL
1449#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1450#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1451
1452#       #RSYNC WITH NFS USE
1453#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1454#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1455
1456#       RET=$?
1457#       IGCM_sys_Rsync_out $RET
1458
1459#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1460#       (( RET=RET+$? ))
1461
1462    if [ ${RET} -gt 0 ] ; then
1463      echo "IGCM_sys_Get : copy error."
1464      cat out_rsync
1465      IGCM_debug_Exit "IGCM_sys_Get"
1466    else
1467      \rm out_rsync
1468    fi
1469  else
1470    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1471  fi
1472  IGCM_debug_PopStack "IGCM_sys_Get"
1473}
1474
1475#D-#==================================================
1476#D-function IGCM_sys_GetBuffer
1477#D-* Purpose: Get a file from ${SCRATCHDIR}
1478#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1479#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1480function IGCM_sys_GetBuffer {
1481  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1482
1483  typeset DEST RET buf_liste ifile target file_work
1484
1485  if ( $DEBUG_sys ) ; then
1486    echo "IGCM_sys_GetBuffer :" $@
1487  fi
1488  if [ $DRYRUN -le 2 ]; then
1489    if [ X${1} = X'/l' ] ; then
1490      # test if the first file is present in the old computation :
1491      eval set +A buf_liste \${${2}}
1492    else
1493      eval set +A buf_liste ${1}
1494    fi
1495    eval DEST=\${${#}}
1496
1497    #USUAL WAY
1498    if [ X${1} = X'/l' ] ; then
1499      (( RET=0 ))
1500      for target in ${buf_liste[*]} ; do
1501        local_file=$( basename ${target} )
1502        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1503        (( RET = RET + $? ))
1504      done
1505    else
1506      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1507      RET=$?
1508    fi
1509
1510    if [ ${RET} -gt 0 ] ; then
1511      echo "IGCM_sys_GetBuffer : copy error."
1512      cat out_rsync
1513      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1514    else
1515      \rm out_rsync
1516    fi
1517  else
1518    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1519  fi
1520  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1521}
1522
1523#D-#==================================================
1524#D-function IGCM_sys_GetDate_FichWork
1525#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1526#D-* Examples:
1527#D-
1528function IGCM_sys_GetDate_FichWork {
1529  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1530  if ( $DEBUG_sys ) ; then
1531    echo "IGCM_sys_GetDate_FichWork :" $@
1532  fi
1533  typeset dateF
1534  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1535  eval ${2}=${dateF[5]}
1536
1537    # donne la date filesys d'un fichier sur la machine work
1538  IGCM_debug_PopStack "IGCM_sys_FichWork"
1539}
1540
1541#D-#==================================================
1542#D-function IGCM_sys_GetDate_FichArchive
1543#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1544#D-* Examples:
1545#D-
1546function IGCM_sys_GetDate_FichArchive {
1547  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1548  if ( $DEBUG_sys ) ; then
1549    echo "IGCM_sys_GetDate_FichArchive :" $@
1550  fi
1551  typeset dateF
1552  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1553  eval ${2}=${dateF[5]}
1554
1555  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1556}
1557
1558#D-#==================================================
1559#D-function IGCM_sys_Dods_Rm
1560#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1561#D-* Examples:
1562#D-
1563function IGCM_sys_Dods_Rm {
1564  if ( $DEBUG_sys ) ; then
1565    echo "IGCM_sys_Dods_Rm :" $@
1566  fi
1567  typeset RET
1568  RET=0
1569  if [ $DRYRUN = 0 ]; then
1570
1571#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1572#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1573#      echo "Nothing has been done."
1574#      return
1575#    fi
1576
1577    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1578    RET=$?
1579
1580#       if [ ${RET} -gt 0 ] ; then
1581#           echo "IGCM_sys_Dods_Rm : error."
1582#           cat out_dods_rm
1583#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1584#       else
1585#           rm out_dods_rm
1586#       fi
1587
1588  else
1589    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1590  fi
1591  return $RET
1592}
1593
1594#D-#==================================================
1595#D-function IGCM_sys_Dods_Cp
1596#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1597#D-* Examples:
1598#D-
1599function IGCM_sys_Dods_Cp {
1600  if ( $DEBUG_sys ) ; then
1601    echo "IGCM_sys_Dods_Cp :" $@
1602  fi
1603  typeset RET
1604  RET=0
1605  if [ $DRYRUN = 0 ]; then
1606
1607#    if [ ! -d ${R_SAVE}/${1} ] ; then
1608#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1609#      echo "Nothing has been done."
1610#      return
1611#    fi
1612
1613    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1614    RET=$?
1615
1616#       if [ ${RET} -gt 0 ] ; then
1617#           echo "IGCM_sys_Dods_Cp : error."
1618#           cat out_dods_cp
1619#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1620#       else
1621#           rm out_dods_cp
1622#       fi
1623
1624  else
1625    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1626  fi
1627  return $RET
1628}
1629
1630#D-#==================================================
1631#D-function IGCM_sys_Put_Dods
1632#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1633#D-* Examples:
1634#D-
1635function IGCM_sys_Put_Dods {
1636  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1637  if ( $DEBUG_sys ) ; then
1638    echo "IGCM_sys_Put_Dods :" $@
1639  fi
1640  set -vx
1641  typeset RET
1642  if [ $DRYRUN = 0 ]; then
1643    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1644      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1645      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1646      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1647      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1648      return
1649    fi
1650
1651    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1652      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1653      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1654      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1655      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1656      return
1657    fi
1658    #
1659    if [ -d ${R_SAVE}/${1} ] ; then
1660      cd ${R_SAVE}
1661    elif [ -d ${R_FIGR}/${1} ] ; then
1662      cd ${R_FIGR}
1663    fi
1664
1665    IGCM_sys_Dods_Rm ${1}
1666    IGCM_sys_Dods_Cp ${1}
1667    RET=0
1668
1669    if [ ${RET} -gt 0 ] ; then
1670      echo "IGCM_sys_Put_Dods : error."
1671      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1672    fi
1673  else
1674    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1675  fi
1676  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1677}
1678
1679##############################################################
1680# REBUILD OPERATOR
1681
1682function IGCM_sys_rebuild {
1683  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1684  if ( $DEBUG_sys ) ; then
1685    echo "IGCM_sys_rebuild :" $@
1686  fi
1687  /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@
1688  if [ $? -gt 0 ] ; then
1689    echo "IGCM_sys_rebuild : erreur ${@}."
1690    IGCM_debug_Exit "rebuild"
1691  fi
1692
1693  IGCM_debug_PopStack "IGCM_sys_rebuild"
1694}
1695
1696function IGCM_sys_rebuild_station {
1697  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1698  typeset i list_opt file_in file_out prefix_invert list_invert
1699  if ( $DEBUG_sys ) ; then
1700    echo "IGCM_sys_rebuild_station :" $@
1701  fi
1702  list_opt=$@
1703
1704  # Invert Axis : t,x -> x,t
1705  #               t,pres,x -> x,t,pres
1706  # So that we can concatenate along x
1707  i=0
1708  for file_in in ${list_opt} ; do
1709    (( i = i + 1))
1710    [ ${i} = 1 ] && file_out=${file_in} && continue
1711    prefix_invert=$( basename ${file_in} .nc )
1712    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1713    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1714  done
1715
1716  # Concatenate
1717  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1718
1719  # Re-ivert file
1720  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1721
1722  # Station re-ordering is too expansive to be run within libICGM
1723  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1724  # This re-ordering must be done "in memory" by the cmorization process
1725  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1726  # BEGIN reordering
1727
1728  # Only LMDZ text output contains the exact ordering of the station.
1729  # We isolate this in the code below:
1730  #  0  38  -157.5000000000000  70.98591549295774
1731  #  0  54  27.49999999999999   67.18309859154928
1732  #  0  56  -62.50000000000001  82.39436619718309
1733  #  0  79  12.49999999999999   78.59154929577466
1734  #  0  116 -165.0000000000000  76.05633802816901
1735  #  0  117 130.0000000000000   70.98591549295774
1736  #  0  118 110.0000000000000   87.46478873239437
1737  #  1  40  4.999999999999995   51.97183098591550
1738#  typeset iStation iProc list_opt file_in file_out prefix_invert
1739#  typeset -Z4 j4
1740#  typeset -Z3 j3
1741
1742#  unset list_opt
1743#  set +A list_opt $@
1744
1745  # Filename after rebuild
1746#  file_out=${list_opt[0]}
1747  # Prefix of output files
1748#  prefix_invert=$( basename ${file_out} .nc )
1749  # Number of procs
1750#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1751
1752#  iProc=0
1753#  while [ ${iProc} -lt ${num_proc} ] ; do
1754    # Array containing Station as a number
1755#    unset proc_stn
1756#    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}' )
1757    # Number of stations produced by processor proc
1758#    stationLast=${#proc_stn[*]}
1759    # Proc number on 4 digits
1760#    j4=${iProc}
1761    # Init
1762#    iStation=0
1763#    while [ ${iStation} -lt ${stationLast} ] ; do
1764      # Station number on 3 digits
1765#      j3=${proc_stn[${iStation}]}
1766      # Extract station
1767      # Invert Axis : t,x -> x,t
1768      #               t,pres,x -> x,t,pres
1769      # So that we can concatenate along x
1770#      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
1771#      (( iStation = iStation + 1 ))
1772#    done
1773#    (( iProc = iProc + 1 ))
1774#  done
1775
1776  # Concatenate all station along x
1777#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1778
1779  # Re-invert file
1780#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1781
1782  # END reordering
1783
1784  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1785}
1786
1787############################################################
1788# Activate Running Environnment Variables
1789
1790function IGCM_sys_activ_variables {
1791  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1792  if ( $DEBUG_sys ) ; then
1793    echo "IGCM_sys_activ_variables"
1794  fi
1795
1796  ulimit -s unlimited
1797
1798  export KMP_STACKSIZE=3g
1799  export KMP_LIBRARY=turnaround
1800  export MKL_SERIAL=YES
1801  unset MPI_PLACING_MODE
1802
1803  # add module load nb of threads for core placement
1804  (( max_omp = 0 ))
1805
1806  for comp in ${config_ListOfComponents[*]} ; do
1807    eval ExeNameIn=\${config_Executable_${comp}[0]}
1808    eval ExeNameOut=\${config_Executable_${comp}[1]}
1809
1810    # Only if we really have an executable for the component :
1811    if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1812      eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1813      if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
1814        (( max_omp = comp_proc_omp_loc ))
1815      fi
1816    fi
1817  done
1818
1819  ( [ X${max_omp} = X4 ] || [ X${max_omp} = X8 ] ) &&  { module load openmp/${max_omp}thds ; IGCM_debug_Print 1 "module load openmp/${max_omp}thds" ; }
1820
1821  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1822}
1823
1824############################################################
1825# Desactivate Running Environnment Variables
1826
1827function IGCM_sys_desactiv_variables {
1828  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1829  if ( $DEBUG_sys ) ; then
1830    echo "IGCM_sys_desactiv_variables"
1831  fi
1832  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1833}
1834
1835############################################################
1836# Build MPI/OMP scripts run file (dummy function)
1837
1838function IGCM_sys_build_run_file {
1839
1840IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1841
1842}
1843
1844############################################################
1845# Build MPI/OMP scripts
1846function IGCM_sys_build_execution_scripts
1847{
1848  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1849  if ( $DEBUG_sys ) ; then
1850    echo "IGCM_sys_build_execution_scripts " $@
1851  fi
1852  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1853  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1854  typeset num_corempi nombre_restant_node nombre_restant_comp
1855  typeset IGCM_OMP
1856
1857  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1858    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1859  fi
1860
1861  if ( ${OK_PARA_MPMD} ) ; then
1862
1863    if [ -f run_file ] ; then
1864      IGCM_sys_Rm -f run_file
1865    fi
1866    touch run_file
1867
1868    if ( ${OK_PARA_OMP} ) ; then
1869
1870      #  Hosts treatment
1871
1872      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1873
1874      i=0
1875      rm -f hosts
1876      IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
1877      for nodes in `cat hosts.tmp` ; do
1878        host[$i]=$nodes
1879        echo "${host[$i]} slots=8 max_slots=8" >> hosts
1880        IGCM_debug_Print 1 ${host[$i]}
1881        i=$((i+1))
1882      done
1883      rm -f hosts.tmp
1884
1885      listnodes=${host[*]}
1886
1887      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1888
1889      # Initialisation
1890
1891      init_node=y
1892      node_num_current=0
1893      start_num=0
1894      init_exec=n
1895
1896      # Test : if oasis is there, we put it at the first position
1897
1898      for comp in ${config_ListOfComponents[*]} ; do
1899
1900        if [ "X${comp}" = "XCPL" ]  ; then
1901
1902          eval ExeNameIn=\${config_Executable_${comp}[0]}
1903          eval ExeNameOut=\${config_Executable_${comp}[1]}
1904
1905          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1906          echo ""  >> script_${ExeNameOut}.ksh
1907          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1908          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1909          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1910          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1911          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1912
1913          init_node=n
1914
1915          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1916          node_num_current=0
1917          node_current=${host[${node_num_current}]}
1918
1919          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1920
1921          init_exec=y
1922          start_num=1
1923
1924        fi
1925
1926      done
1927
1928      # Then loop on the components (except for oasis)
1929
1930      for comp in ${config_ListOfComponents[*]} ; do
1931
1932        eval ExeNameIn=\${config_Executable_${comp}[0]}
1933        eval ExeNameOut=\${config_Executable_${comp}[1]}
1934
1935        # Only if we really have an executable for the component :
1936        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1937
1938          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1939          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1940
1941          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1942          # echo "set -vx" >> script_${ExeNameOut}.ksh
1943          echo ""  >> script_${ExeNameOut}.ksh
1944          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1945          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1946          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1947          echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1948          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1949          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1950          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1951
1952          node_num=0
1953
1954          # We define the number of MPI process to be assigned for the component
1955
1956          nombre_restant_comp=${comp_proc_mpi_loc}
1957
1958          # Loop on the allocated nodes
1959
1960          for node in ${listnodes} ; do
1961
1962            # We go to the current node
1963            if [ ${node_num} = ${node_num_current} ] ; then
1964
1965              node_current=${host[${node_num_current}]}
1966
1967              # If first time on the node : initialisation
1968
1969              if [ ${init_node} = y ] ; then
1970                nombre_restant_node=${NUM_COREPERNODE}
1971              fi
1972
1973              # Test on the number of OMP threads
1974
1975              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1976                (( node_num = node_num + 1 ))
1977                node_num_current=${node_num}
1978                init_node=y
1979                continue
1980              fi
1981
1982              # Number of MPI process to assign
1983
1984              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1985
1986              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1987                num_corempi=${nombre_restant_comp}
1988              fi
1989
1990              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1991              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1992
1993              if [ ${init_exec} = y ] ; then
1994                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1995              else
1996                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1997                init_exec=y
1998              fi
1999
2000              ((  start_num = num_corempi + start_num ))
2001
2002            else
2003
2004              (( node_num = node_num + 1 ))
2005              continue
2006            fi
2007
2008            # Test on the number of core/process remaining on the node/component
2009
2010            if [ ${nombre_restant_node} = 0 ] ; then
2011              (( node_num = node_num + 1 ))
2012              node_num_current=${node_num}
2013              init_node=y
2014
2015              if [ ${nombre_restant_comp} = 0 ] ; then
2016                break 1
2017              fi
2018            else
2019
2020              node_num_current=${node_num}
2021              init_node=n
2022
2023              if [ ${nombre_restant_comp} = 0 ] ; then
2024                break 1
2025              fi
2026            fi
2027          done
2028        fi
2029      done
2030
2031    else
2032
2033        # Then first loop on the components for the coupler ie oasis
2034
2035        ## the coupler ie oasis must be the first one
2036        for comp in ${config_ListOfComponents[*]} ; do
2037
2038            eval ExeNameOut=\${config_Executable_${comp}[1]}
2039
2040        # for CPL component only
2041            if [ "X${comp}" = "XCPL" ] ; then
2042                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2043                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
2044            fi
2045        done
2046
2047        # Then second loop on the components
2048
2049        for comp in ${config_ListOfComponents[*]} ; do
2050
2051            eval ExeNameOut=\${config_Executable_${comp}[1]}
2052
2053            # Only if we really have an executable for the component and not the coupler ie oasis:
2054            if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
2055                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2056                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2057            fi
2058        done
2059        IGCM_sys_Chmod u+x run_file
2060
2061        EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
2062
2063    fi
2064
2065  else # Only one executable.
2066      # Check has to be added with :
2067      # Job :
2068      # #MSUB -n 8 # reservation des processeurs pour le job
2069      # #MSUB -N 4 # reservation des nodes pour le job
2070      # BATCH_NUM_PROC_TOT=32
2071      #
2072      # config.card :
2073      # ATM= (gcm.e, lmdz.x, 8MPI, 4OMP)
2074      #
2075      # tested with :
2076      # Job :
2077      # #MSUB -n 32
2078      # BATCH_NUM_PROC_TOT=32
2079      #
2080      # config.card :
2081      # ATM= (gcm.e, lmdz.x)
2082
2083
2084      for comp in ${config_ListOfComponents[*]} ; do
2085
2086          # Only if we really have an executable for the component :
2087          eval ExeNameOut=\${config_Executable_${comp}[1]}
2088###       if ( [ "X${ExeNameOut}" != X\"\" ] ) ; then
2089          if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2090
2091              IGCM_OMP=1
2092
2093              if ( ${OK_PARA_OMP} ) ; then
2094                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2095                  export OMP_NUM_THREADS=${comp_proc_omp_loc}
2096                  IGCMG_OMP=${comp_proc_omp_loc}
2097              fi
2098              if  ( ${OK_PARA_MPI} ) ; then
2099                  eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2100                  # Default : mpirun used if nb_proc gt 1
2101                  # pour sortie out/err par process ? more test required
2102                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
2103                  EXECUTION="${HOST_MPIRUN_COMMAND} -np ${comp_proc_mpi_loc} ./${ExeNameOut}"
2104              else
2105                  # Check if BATCH_NUM_PROC_TOT = IGCMG_OMP
2106                  if ( [  ${IGCM_OMP} -ne ${BATCH_NUM_PROC_TOT} ] ) ; then
2107                      IGCM_debug_Print 1 "sys Titane : BATCH_NUM_PROC_TOT <> ${comp}_PROC_OMP : ${BATCH_NUM_PROC_TOT} <> ${BRIDGE_MSUB_NPROC} "
2108                      IGCM_debug_Print 1 "sys Titane : Check #MSUB -n xx into Job"
2109                      IGCM_debug_Exit "IGCM_sys_build_execution_scripts"
2110                  fi
2111                  # Default : mpirun is NOT used if nb_proc eq 1
2112                  # pour sortie out/err par process ? more test required
2113                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
2114                  EXECUTION="/usr/bin/time ./${ExeNameOut}"
2115              fi
2116          fi
2117      done
2118
2119  fi
2120
2121  IGCM_debug_Print 1 "sys Titane : La commande d execution est "
2122  IGCM_debug_Print 1 "$EXECUTION"
2123
2124  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2125}
2126
2127############################################################
2128# Check of space available on temporary filesytems
2129function IGCM_sys_check_quota {
2130  IGCM_debug_PushStack "IGCM_sys_check_quota"
2131  if ( $DEBUG_sys ) ; then
2132    echo "IGCM_sys_check_quota "
2133  fi
2134  # Limit of quota (in %)
2135  limit_quota=90
2136
2137  # Check of the volume
2138  volume_quota=$(ccc_quota | grep ' scratch' | awk '{print $2}')
2139  volume_avail=$(ccc_quota | grep ' scratch' | awk '{print $3}')
2140
2141  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
2142
2143    unit_avail=${volume_avail: -1}
2144    unit_quota=${volume_quota: -1}
2145
2146    if [ "${unit_quota}" = "*" ] ; then
2147        IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2148        IGCM_debug_Print 1 "More than 100% of your quota is used"
2149        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2150        IGCM_debug_Print 1 "You must have more than 10% available to run"
2151        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2152        IGCM_debug_Verif_Exit
2153    fi
2154
2155    temp_avail=${volume_avail%%${volume_avail: -1}*}
2156    temp_quota=${volume_quota%%${volume_quota: -1}*}
2157
2158    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2159
2160    # Convertion
2161      if [ ${volume_avail: -1} = "T" ] ; then
2162        (( temp_avail = temp_avail * 1000000000000 ))
2163      elif [ ${volume_avail: -1} = "G" ] ; then
2164        (( temp_avail = temp_avail * 1000000000 ))
2165      elif [ ${volume_avail: -1} = "M" ] ; then
2166        (( temp_avail = temp_avail * 1000000 ))
2167      elif [ ${volume_avail: -1} = "k" ] ; then
2168        (( temp_avail = temp_avail * 1000 ))
2169      else
2170        (( temp_avail = volume_avail ))
2171      fi
2172      if [ ${volume_quota: -1} = "T" ] ; then
2173        (( temp_quota = temp_quota * 1000000000000 ))
2174      elif [ ${volume_quota: -1} = "G" ] ; then
2175        (( temp_quota = temp_quota * 1000000000 ))
2176      elif [ ${volume_quota: -1} = "M" ] ; then
2177        (( temp_quota = temp_quota * 1000000 ))
2178      elif [ ${volume_quota: -1} = "k" ] ; then
2179        (( temp_quota = temp_quota * 1000 ))
2180      else
2181        (( temp_quota = volume_quota ))
2182      fi
2183    fi
2184
2185    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2186#    echo "volume ratio is " $quota_volume
2187
2188    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2189      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2190      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2191      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2192      IGCM_debug_Print 1 "You must have more than 10% available to run"
2193      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2194      IGCM_debug_Verif_Exit
2195    fi
2196
2197  fi
2198
2199# Check of the number of inodes
2200
2201  inode_quota=$(ccc_quota | grep ' scratch' | awk '{print $6}')
2202  inode_avail=$(ccc_quota | grep ' scratch' | awk '{print $7}')
2203
2204  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
2205
2206    unit_avail=${inode_avail: -1}
2207    unit_quota=${inode_quota: -1}
2208
2209    if [ "${unit_quota}" = "*" ] ; then
2210        IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2211        IGCM_debug_Print 1 "More than 100% of your quota is used"
2212        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2213        IGCM_debug_Print 1 "You must have more than 10% available to run"
2214        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2215        IGCM_debug_Verif_Exit
2216    fi
2217
2218    temp_avail=${inode_avail%%${inode_avail: -1}*}
2219    temp_quota=${inode_quota%%${inode_quota: -1}*}
2220
2221    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2222
2223    # Convertion
2224      if [ ${inode_avail: -1} = "T" ] ; then
2225        (( temp_avail = temp_avail * 1000000000000 ))
2226      elif [ ${inode_avail: -1} = "G" ] ; then
2227        (( temp_avail = temp_avail * 1000000000 ))
2228      elif [ ${inode_avail: -1} = "M" ] ; then
2229        (( temp_avail = temp_avail * 1000000 ))
2230      elif [ ${inode_avail: -1} = "k" ] ; then
2231        (( temp_avail = temp_avail * 1000 ))
2232      else
2233        (( temp_avail = inode_avail ))
2234      fi
2235
2236      if [ ${inode_quota: -1} = "T" ] ; then
2237        (( temp_quota = temp_quota * 1000000000000 ))
2238      elif [ ${inode_quota: -1} = "G" ] ; then
2239        (( temp_quota = temp_quota * 1000000000 ))
2240      elif [ ${inode_quota: -1} = "M" ] ; then
2241        (( temp_quota = temp_quota * 1000000 ))
2242      elif [ ${inode_quota: -1} = "k" ] ; then
2243        (( temp_quota = temp_quota * 1000 ))
2244      else
2245        (( temp_quota = inode_quota ))
2246      fi
2247    fi
2248    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2249#    echo "inode ratio is " $quota_inode
2250
2251    if [ ${quota_inode} -ge ${limit_quota} ] ; then
2252      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2253      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
2254      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2255      IGCM_debug_Print 1 "You must have more than 10% available to run"
2256      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2257      IGCM_debug_Verif_Exit
2258    fi
2259
2260  fi
2261  IGCM_debug_PopStack "IGCM_sys_check_quota"
2262}
2263
2264##############################################################
2265# NCO OPERATOR
2266
2267function IGCM_sys_ncap2 {
2268  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2269  if ( $DEBUG_sys ) ; then
2270    echo "IGCM_sys_ncap2 :" $@
2271  fi
2272
2273  typeset NB_ESSAI DELAI status i
2274  # number of tentative
2275  NB_ESSAI=3
2276  # time delay between tentative
2277  DELAI=2
2278
2279  i=0
2280  while [ $i -lt $NB_ESSAI ] ; do
2281    ncap2 "$@" > out_rsync 2>&1
2282    status=$?
2283    if [ ${status} -gt 0 ] ; then
2284      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2285      cat out_rsync
2286      \rm out_rsync
2287      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2288    else
2289      \rm out_rsync
2290      break
2291    fi
2292    (( i = i + 1 ))
2293  done
2294
2295  if [ ${status} -gt 0 ] ; then
2296      echo "IGCM_sys_ncap2 : ncap2 error"
2297      IGCM_debug_Exit "ncap2"
2298  fi
2299
2300  IGCM_debug_PopStack "IGCM_sys_ncap2"
2301}
2302
2303function IGCM_sys_ncatted {
2304  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2305  if ( $DEBUG_sys ) ; then
2306    echo "IGCM_sys_ncatted :" $@
2307  fi
2308
2309  typeset NB_ESSAI DELAI status i
2310  # number of tentative
2311  NB_ESSAI=3
2312  # time delay between tentative
2313  DELAI=2
2314
2315  i=0
2316  while [ $i -lt $NB_ESSAI ] ; do
2317    ncatted "$@" > out_rsync 2>&1
2318    status=$?
2319    if [ ${status} -gt 0 ] ; then
2320      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2321      cat out_rsync
2322      \rm out_rsync
2323      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2324    else
2325      \rm out_rsync
2326      break
2327    fi
2328    (( i = i + 1 ))
2329  done
2330
2331  if [ ${status} -gt 0 ] ; then
2332      echo "IGCM_sys_ncatted : ncatted error"
2333      IGCM_debug_Exit "ncatted"
2334  fi
2335
2336  IGCM_debug_PopStack "IGCM_sys_ncatted"
2337}
2338
2339function IGCM_sys_ncbo {
2340  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2341  if ( $DEBUG_sys ) ; then
2342    echo "IGCM_sys_ncbo :" $@
2343  fi
2344
2345  typeset NB_ESSAI DELAI status i
2346  # number of tentative
2347  NB_ESSAI=3
2348  # time delay between tentative
2349  DELAI=2
2350
2351  i=0
2352  while [ $i -lt $NB_ESSAI ] ; do
2353    ncbo $@ > out_rsync 2>&1
2354    status=$?
2355    if [ ${status} -gt 0 ] ; then
2356      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2357      cat out_rsync
2358      \rm out_rsync
2359      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2360    else
2361      \rm out_rsync
2362      break
2363    fi
2364    (( i = i + 1 ))
2365  done
2366
2367  if [ ${status} -gt 0 ] ; then
2368      echo "IGCM_sys_ncbo : ncbo error"
2369      IGCM_debug_Exit "ncbo"
2370  fi
2371
2372  IGCM_debug_PopStack "IGCM_sys_ncbo"
2373}
2374
2375function IGCM_sys_ncdiff {
2376  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2377  if ( $DEBUG_sys ) ; then
2378    echo "IGCM_sys_ncdiff :" $@
2379  fi
2380
2381  typeset NB_ESSAI DELAI status i
2382  # number of tentative
2383  NB_ESSAI=3
2384  # time delay between tentative
2385  DELAI=2
2386
2387  i=0
2388  while [ $i -lt $NB_ESSAI ] ; do
2389    ncdiff $@ > out_rsync 2>&1
2390    status=$?
2391    if [ ${status} -gt 0 ] ; then
2392      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2393      cat out_rsync
2394      \rm out_rsync
2395      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2396    else
2397      \rm out_rsync
2398      break
2399    fi
2400    (( i = i + 1 ))
2401  done
2402
2403  if [ ${status} -gt 0 ] ; then
2404      echo "IGCM_sys_ncdiff : ncdiff error"
2405      IGCM_debug_Exit "ncdiff"
2406  fi
2407
2408  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2409}
2410
2411function IGCM_sys_ncea {
2412  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2413  if ( $DEBUG_sys ) ; then
2414    echo "IGCM_sys_ncea :" $@
2415  fi
2416
2417  typeset NB_ESSAI DELAI status i
2418  # number of tentative
2419  NB_ESSAI=3
2420  # time delay between tentative
2421  DELAI=2
2422
2423  i=0
2424  while [ $i -lt $NB_ESSAI ] ; do
2425    ncea $@ > out_rsync 2>&1
2426    status=$?
2427    if [ ${status} -gt 0 ] ; then
2428      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2429      cat out_rsync
2430      \rm out_rsync
2431      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2432    else
2433      \rm out_rsync
2434      break
2435    fi
2436    (( i = i + 1 ))
2437  done
2438
2439  if [ ${status} -gt 0 ] ; then
2440      echo "IGCM_sys_ncea : ncea error"
2441      IGCM_debug_Exit "ncea"
2442  fi
2443
2444  IGCM_debug_PopStack "IGCM_sys_ncea"
2445}
2446
2447function IGCM_sys_ncecat {
2448  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2449  if ( $DEBUG_sys ) ; then
2450    echo "IGCM_sys_ncecat :" $@
2451  fi
2452
2453  typeset NB_ESSAI DELAI status i
2454  # number of tentative
2455  NB_ESSAI=3
2456  # time delay between tentative
2457  DELAI=2
2458
2459  i=0
2460  while [ $i -lt $NB_ESSAI ] ; do
2461    ncecat $@ > out_rsync 2>&1
2462    status=$?
2463    if [ ${status} -gt 0 ] ; then
2464      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2465      cat out_rsync
2466      \rm out_rsync
2467      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2468    else
2469      \rm out_rsync
2470      break
2471    fi
2472    (( i = i + 1 ))
2473  done
2474
2475  if [ ${status} -gt 0 ] ; then
2476      echo "IGCM_sys_ncecat : ncecat error"
2477      IGCM_debug_Exit "ncecat"
2478  fi
2479
2480  IGCM_debug_PopStack "IGCM_sys_ncecat"
2481}
2482
2483function IGCM_sys_ncflint {
2484  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2485  if ( $DEBUG_sys ) ; then
2486    echo "IGCM_sys_ncflint :" $@
2487  fi
2488
2489  typeset NB_ESSAI DELAI status i
2490  # number of tentative
2491  NB_ESSAI=3
2492  # time delay between tentative
2493  DELAI=2
2494
2495  i=0
2496  while [ $i -lt $NB_ESSAI ] ; do
2497    ncflint $@ > out_rsync 2>&1
2498    status=$?
2499    if [ ${status} -gt 0 ] ; then
2500      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2501      cat out_rsync
2502      \rm out_rsync
2503      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2504    else
2505      \rm out_rsync
2506      break
2507    fi
2508    (( i = i + 1 ))
2509  done
2510
2511  if [ ${status} -gt 0 ] ; then
2512      echo "IGCM_sys_ncflint : ncflint error"
2513      IGCM_debug_Exit "ncflint"
2514  fi
2515
2516  IGCM_debug_PopStack "IGCM_sys_ncflint"
2517}
2518
2519function IGCM_sys_ncks {
2520  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2521  if ( $DEBUG_sys ) ; then
2522    echo "IGCM_sys_ncks :" $@
2523  fi
2524
2525  typeset NB_ESSAI DELAI status i
2526  # number of tentative
2527  NB_ESSAI=3
2528  # time delay between tentative
2529  DELAI=2
2530
2531  i=0
2532  while [ $i -lt $NB_ESSAI ] ; do
2533    ncks $@ > out_rsync 2>&1
2534    status=$?
2535    if [ ${status} -gt 0 ] ; then
2536      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2537      cat out_rsync
2538      \rm out_rsync
2539      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2540    else
2541      \rm out_rsync
2542      break
2543    fi
2544    (( i = i + 1 ))
2545  done
2546
2547  if [ ${status} -gt 0 ] ; then
2548      echo "IGCM_sys_ncks : ncks error"
2549      IGCM_debug_Exit "ncks"
2550  fi
2551
2552  IGCM_debug_PopStack "IGCM_sys_ncks"
2553}
2554
2555function IGCM_sys_ncpdq {
2556  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2557  if ( $DEBUG_sys ) ; then
2558    echo "IGCM_sys_ncpdq :" $@
2559  fi
2560
2561  typeset NB_ESSAI DELAI status i
2562  # number of tentative
2563  NB_ESSAI=3
2564  # time delay between tentative
2565  DELAI=2
2566
2567  i=0
2568  while [ $i -lt $NB_ESSAI ] ; do
2569    ncpdq $@ > out_rsync 2>&1
2570    status=$?
2571    if [ ${status} -gt 0 ] ; then
2572      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2573      cat out_rsync
2574      \rm out_rsync
2575      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2576    else
2577      \rm out_rsync
2578      break
2579    fi
2580    (( i = i + 1 ))
2581  done
2582
2583  if [ ${status} -gt 0 ] ; then
2584      echo "IGCM_sys_ncpdq : ncpdq error"
2585      IGCM_debug_Exit "ncpdq"
2586  fi
2587
2588  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2589}
2590
2591function IGCM_sys_ncra {
2592  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2593  if ( $DEBUG_sys ) ; then
2594    echo "IGCM_sys_ncra :" $@
2595  fi
2596
2597  typeset NB_ESSAI DELAI status i
2598  # number of tentative
2599  NB_ESSAI=3
2600  # time delay between tentative
2601  DELAI=2
2602
2603  i=0
2604  while [ $i -lt $NB_ESSAI ] ; do
2605    ncra $@ > out_rsync 2>&1
2606    status=$?
2607    if [ ${status} -gt 0 ] ; then
2608      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2609      cat out_rsync
2610      \rm out_rsync
2611      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2612    else
2613      \rm out_rsync
2614      break
2615    fi
2616    (( i = i + 1 ))
2617  done
2618
2619  if [ ${status} -gt 0 ] ; then
2620      echo "IGCM_sys_ncra : ncra error"
2621      IGCM_debug_Exit "ncra"
2622  fi
2623
2624  IGCM_debug_PopStack "IGCM_sys_ncra"
2625}
2626
2627function IGCM_sys_ncrcat {
2628  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2629  if ( $DEBUG_sys ) ; then
2630    echo "IGCM_sys_ncrcat :" $@
2631  fi
2632
2633  typeset NB_ESSAI DELAI status i
2634  # number of tentative
2635  NB_ESSAI=3
2636  # time delay between tentative
2637  DELAI=2
2638
2639  i=0
2640  while [ $i -lt $NB_ESSAI ] ; do
2641    ncrcat $@ > out_rsync 2>&1
2642    status=$?
2643    if [ ${status} -gt 0 ] ; then
2644      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2645      cat out_rsync
2646      \rm out_rsync
2647      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2648    else
2649      \rm out_rsync
2650      break
2651    fi
2652    (( i = i + 1 ))
2653  done
2654
2655  if [ ${status} -gt 0 ] ; then
2656      echo "IGCM_sys_ncrcat : ncrcat error"
2657      #IGCM_debug_Exit "ncrcat"
2658  fi
2659
2660  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2661}
2662
2663function IGCM_sys_ncrename {
2664  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2665  if ( $DEBUG_sys ) ; then
2666    echo "IGCM_sys_ncrename :" $@
2667  fi
2668
2669  typeset NB_ESSAI DELAI status i
2670  # number of tentative
2671  NB_ESSAI=3
2672  # time delay between tentative
2673  DELAI=2
2674
2675  i=0
2676  while [ $i -lt $NB_ESSAI ] ; do
2677    ncrename $@ > out_rsync 2>&1
2678    status=$?
2679    if [ ${status} -gt 0 ] ; then
2680      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2681      cat out_rsync
2682      \rm out_rsync
2683      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2684    else
2685      \rm out_rsync
2686      break
2687    fi
2688    (( i = i + 1 ))
2689  done
2690
2691  if [ ${status} -gt 0 ] ; then
2692      echo "IGCM_sys_ncrename : ncrename error"
2693      IGCM_debug_Exit "ncrename"
2694  fi
2695
2696  IGCM_debug_PopStack "IGCM_sys_ncrename"
2697}
2698
2699function IGCM_sys_ncwa {
2700  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2701  if ( $DEBUG_sys ) ; then
2702    echo "IGCM_sys_ncwa :" $@
2703  fi
2704
2705  typeset NB_ESSAI DELAI status i
2706  # number of tentative
2707  NB_ESSAI=3
2708  # time delay between tentative
2709  DELAI=2
2710
2711  i=0
2712  while [ $i -lt $NB_ESSAI ] ; do
2713    ncwa $@ > out_rsync 2>&1
2714    status=$?
2715    if [ ${status} -gt 0 ] ; then
2716      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2717      cat out_rsync
2718      \rm out_rsync
2719      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2720    else
2721      \rm out_rsync
2722      break
2723    fi
2724    (( i = i + 1 ))
2725  done
2726
2727  if [ ${status} -gt 0 ] ; then
2728      echo "IGCM_sys_ncwa : ncwa error"
2729      IGCM_debug_Exit "ncwa"
2730  fi
2731
2732  IGCM_debug_PopStack "IGCM_sys_ncwa"
2733}
2734
2735##############################################################
2736# CDO OPERATOR
2737
2738function IGCM_sys_cdo {
2739  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2740  if ( $DEBUG_sys ) ; then
2741    echo "IGCM_sys_cdo :" $@
2742  fi
2743
2744  typeset status
2745
2746  \cdo $@ > out_rsync 2>&1
2747  status=$?
2748  if [ ${status} -gt 0 ] ; then
2749    echo "IGCM_sys_cdo : error code ${status}"
2750    cat out_rsync
2751    \rm out_rsync
2752    IGCM_debug_PopStack "IGCM_sys_cdo"
2753    return 1
2754  else
2755    IGCM_debug_PopStack "IGCM_sys_cdo"
2756    return 0
2757  fi
2758
2759  IGCM_debug_PopStack "IGCM_sys_cdo"
2760}
Note: See TracBrowser for help on using the repository browser.