source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh @ 765

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