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

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