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

Last change on this file since 759 was 759, checked in by mafoipsl, 12 years ago

On curie first consolidation for 444 file transfer.

  • Property svn:keywords set to Revision Author Date
File size: 73.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# 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 ${2} ] && ls -l ${2}
1171      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1172      cat out_rsync
1173      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1174    else
1175
1176      if [ X${JobType} = XRUN ] ; then
1177        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1178        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1179      fi
1180
1181      \rm out_rsync
1182    fi
1183  else
1184    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1185  fi
1186  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1187}
1188
1189#D-#==================================================
1190#D-function IGCM_sys_PutBuffer_Rest
1191#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1192#D-           File and target directory must exist.
1193#D-* Examples:
1194#D-
1195function IGCM_sys_PutBuffer_Rest {
1196  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1197  if ( $DEBUG_sys ) ; then
1198    echo "IGCM_sys_PutBuffer_Rest :" $@
1199  fi
1200  if [ $DRYRUN = 0 ]; then
1201    if [ ! -f ${1} ] ; then
1202      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1203      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1204    fi
1205
1206    typeset status
1207    #
1208    # USUAL WAY
1209    \cp $1 $2 > out_rsync 2>&1
1210    status=$?
1211
1212    if [ ${status} -gt 0 ] ; then
1213      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1214      [ -f ${2} ] && ls -l ${2}
1215      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1216      cat out_rsync
1217      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1218    else
1219
1220      if [ X${JobType} = XRUN ] ; then
1221        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1222        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1223      fi
1224
1225      \rm out_rsync
1226    fi
1227  else
1228    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1229  fi
1230  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1231}
1232
1233#D-#==================================================
1234#D-function IGCM_sys_Put_Out
1235#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1236#D-* Examples:
1237#D-
1238function IGCM_sys_Put_Out {
1239  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1240  if ( $DEBUG_sys ) ; then
1241    echo "IGCM_sys_Put_Out :" $@
1242  fi
1243
1244  typeset NB_ESSAI DELAI status i exist skip
1245
1246  # number of tentative
1247  NB_ESSAI=3
1248  # time delay between tentative
1249  DELAI=2
1250
1251  if [ $DRYRUN = 0 ]; then
1252    if [ ! -f ${1} ] ; then
1253      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1254      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1255      return 1
1256    fi
1257    #
1258    IGCM_sys_MkdirArchive $( dirname $2 )
1259    #
1260
1261    #=====================================================
1262    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1263    #=====================================================
1264
1265    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1266    #if [ $? -eq 0 ] ; then
1267    #    typeset WORKPATH FILEPATH
1268    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1269    #    IGCM_sys_MkdirWork ${WORKPATH}
1270    #    FILEPATH=${WORKPATH}/$( basename $2 )
1271    #    #
1272    #    IGCM_sys_Cp ${1} ${FILEPATH}
1273    #fi
1274
1275    exist=false
1276    skip=false
1277    if [ -f $2 ] ; then
1278      IGCM_debug_Print 1 "$2 already exist"
1279      #dmget $2
1280      ccc_hsm get $2
1281      exist=true
1282      if [ "X$( diff $1 $2 )" = X ] ; then
1283        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1284        skip=true
1285      else
1286        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1287        skip=false
1288      fi
1289    fi
1290    #
1291    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1292      IGCM_sys_Chmod u+w $2
1293    fi
1294
1295    if [ X${skip} = Xfalse ] ; then
1296      i=0
1297      while [ $i -lt $NB_ESSAI ] ; do
1298        # USUAL WAY
1299        \cp $1 $2 > out_rsync 2>&1
1300        status=$?
1301        if [ ${status} -gt 0 ]; then
1302          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1303          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1304          [ -f ${2} ] && ls -l ${2}
1305          [ -f ${2}/${1} ] && ls -l ${2}/${1}
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      [ -f ${2} ] && ls -l ${2}
1331      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1332      cat out_rsync
1333      IGCM_debug_Exit "IGCM_sys_Put_Out"
1334    else
1335
1336      if [ X${JobType} = XRUN ] ; then
1337        if [ X${3} = X ] ; then
1338          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1339          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1340        fi
1341      fi
1342
1343      \rm out_rsync
1344    fi
1345  else
1346    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1347  fi
1348  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1349  return 0
1350}
1351
1352#D-#==================================================
1353#D-function IGCM_sys_PutBuffer_Out
1354#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1355#D-* Examples:
1356#D-
1357function IGCM_sys_PutBuffer_Out {
1358  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1359  if ( $DEBUG_sys ) ; then
1360    echo "IGCM_sys_PutBuffer_Out :" $@
1361  fi
1362
1363  typeset NB_ESSAI DELAI status i exist skip
1364
1365  # number of tentative
1366  NB_ESSAI=3
1367  # time delay between tentative
1368  DELAI=2
1369
1370  if [ $DRYRUN = 0 ]; then
1371    if [ ! -f ${1} ] ; then
1372      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1373      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1374      return 1
1375    fi
1376    #
1377    IGCM_sys_Mkdir $( dirname $2 )
1378    #
1379
1380    exist=false
1381    skip=false
1382    if [ -f $2 ] ; then
1383      IGCM_debug_Print 1 "$2 already exist"
1384      exist=true
1385      if [ "X$( diff $1 $2 )" = X ] ; then
1386        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1387        skip=true
1388      else
1389        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1390        skip=false
1391      fi
1392    fi
1393    #
1394    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1395      IGCM_sys_Chmod u+w $2
1396    fi
1397
1398    if [ X${skip} = Xfalse ] ; then
1399      i=0
1400      while [ $i -lt $NB_ESSAI ] ; do
1401        # USUAL WAY
1402        \cp $1 $2 > out_rsync 2>&1
1403        status=$?
1404        if [ ${status} -gt 0 ]; then
1405          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1406          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1407          [ -f ${2} ] && ls -l ${2}
1408          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1409          sleep $DELAI
1410        else
1411          break
1412        fi
1413        (( i = i + 1 ))
1414      done
1415    fi
1416
1417    if [ ${status} -gt 0 ] ; then
1418      echo "IGCM_sys_PutBuffer_Out : error."
1419      [ -f ${2} ] && ls -l ${2}
1420      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1421      cat out_rsync
1422      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1423    else
1424
1425      if [ X${JobType} = XRUN ] ; then
1426        if [ X${3} = X ] ; then
1427          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1428          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1429        fi
1430      fi
1431
1432      \rm out_rsync
1433    fi
1434  else
1435    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1436  fi
1437  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1438  return 0
1439}
1440
1441#D-#==================================================
1442#D-function IGCM_sys_Get
1443#D-* Purpose: Get a file from ${ARCHIVE}
1444#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1445#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1446function IGCM_sys_Get {
1447  IGCM_debug_PushStack "IGCM_sys_Get" $@
1448
1449  typeset DEST dm_liste ifile target file_work
1450  typeset NB_ESSAI DELAI status i
1451
1452  if ( $DEBUG_sys ) ; then
1453    echo "IGCM_sys_Get :" $@
1454  fi
1455
1456  # number of tentative
1457  NB_ESSAI=3
1458  # time delay between tentative
1459  DELAI=2
1460
1461  if [ $DRYRUN -le 2 ]; then
1462    if [ X${1} = X'/l' ] ; then
1463      # test if the first file is present in the old computation :
1464      eval set +A dm_liste \${${2}}
1465    else
1466      eval set +A dm_liste ${1}
1467    fi
1468    eval DEST=\${${#}}
1469
1470    #=====================================================
1471    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1472    #=====================================================
1473
1474    # Is it an R_OUT file (not R_IN) ?
1475    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1476    #if [ $? -eq 0 ] ; then
1477    #    # Yes  ? then we try to get it in SCRATCHDIR
1478    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1479    #    if [ -f ${file_work[0]} ] ; then
1480    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1481    #   IGCM_debug_PopStack "IGCM_sys_Get"
1482    #   return
1483    #    fi
1484    #fi
1485
1486    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1487    status=$?
1488    if [ ${status} -gt 0 ] ; then
1489      echo "WARNING IGCM_sys_Get : error code ${status}"
1490      cat out_rsync
1491      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1492    fi
1493
1494    #if [ ${status} -gt 0 ] ; then
1495    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1496    #   cat out_rsync
1497    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1498    #   sleep 30
1499    #   echo "We try another time"
1500    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1501    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1502    #   status=$?
1503    #   if [ ${status} -gt 0 ] ; then
1504    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1505    #       cat out_rsync
1506    #       IGCM_debug_Exit "IGCM_sys_Get"
1507    #   fi
1508    #    else
1509    #   echo "ERROR IGCM_sys_Get : demigration error :"
1510    #   cat out_rsync
1511    #   IGCM_debug_Exit "IGCM_sys_Get"
1512    #    fi
1513    #fi
1514
1515    #   #RSYNC WITH NETWORK SSH CALL
1516    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1517    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1518
1519    #   #RSYNC WITH NFS USE
1520    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1521    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1522
1523    #   status=$?
1524    #   IGCM_sys_Rsync_out $status
1525
1526    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1527    #   (( status=status+$? ))
1528
1529    #USUAL WAY
1530    if [ X${1} = X'/l' ] ; then
1531      for target in ${dm_liste[*]} ; do
1532        local_file=$( basename ${target} )
1533        # test if the target file is present before the loop
1534        IGCM_sys_TestFileArchive ${target}
1535        status=$?
1536        if [ ${status} -gt 0 ] ; then
1537          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1538          IGCM_debug_Exit "IGCM_sys_Get"
1539        else
1540          i=0
1541          while [ $i -lt $NB_ESSAI ] ; do
1542            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1543            status=$?
1544            if [ ${status} -gt 0 ]; then
1545              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1546              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1547              sleep $DELAI
1548            else
1549              break
1550            fi
1551            (( i = i + 1 ))
1552          done
1553          if [ ${status} -gt 0 ] ; then
1554            echo "IGCM_sys_Get : error"
1555            cat out_rsync
1556            \rm out_rsync
1557            IGCM_debug_Exit "IGCM_sys_Get"
1558          else
1559            \rm out_rsync
1560          fi
1561        fi
1562      done
1563    else
1564      i=0
1565      while [ $i -lt $NB_ESSAI ] ; do
1566        \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1567        status=$?
1568        if [ ${status} -gt 0 ]; then
1569          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1570          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1571          sleep $DELAI
1572        else
1573          break
1574        fi
1575        (( i = i + 1 ))
1576      done
1577      if [ ${status} -gt 0 ] ; then
1578        echo "IGCM_sys_Get : error"
1579        cat out_rsync
1580        \rm out_rsync
1581        IGCM_debug_Exit "IGCM_sys_Get"
1582      else
1583        \rm out_rsync
1584      fi
1585    fi
1586  else
1587    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1588  fi
1589  IGCM_debug_PopStack "IGCM_sys_Get"
1590}
1591
1592#D-#==================================================
1593#D-function IGCM_sys_GetBuffer
1594#D-* Purpose: Get a file from ${SCRATCHDIR}
1595#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1596#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1597function IGCM_sys_GetBuffer {
1598  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1599
1600  typeset DEST buf_liste ifile target file_work
1601  typeset NB_ESSAI DELAI status i
1602
1603  if ( $DEBUG_sys ) ; then
1604    echo "IGCM_sys_GetBuffer :" $@
1605  fi
1606
1607  # number of tentative
1608  NB_ESSAI=3
1609  # time delay between tentative
1610  DELAI=2
1611
1612  if [ $DRYRUN -le 2 ]; then
1613    if [ X${1} = X'/l' ] ; then
1614      # test if the first file is present in the old computation :
1615      eval set +A buf_liste \${${2}}
1616    else
1617      eval set +A buf_liste ${1}
1618    fi
1619    eval DEST=\${${#}}
1620
1621    #USUAL WAY
1622    if [ X${1} = X'/l' ] ; then
1623      for target in ${buf_liste[*]} ; do
1624        local_file=$( basename ${target} )
1625        i=0
1626        while [ $i -lt $NB_ESSAI ] ; do
1627          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1628          status=$?
1629          if [ ${status} -gt 0 ]; then
1630            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1631            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1632            sleep $DELAI
1633          else
1634            break
1635          fi
1636          (( i = i + 1 ))
1637        done
1638        if [ ${status} -gt 0 ] ; then
1639          echo "IGCM_sys_Get : error"
1640          cat out_rsync
1641          \rm out_rsync
1642          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1643        else
1644          \rm out_rsync
1645        fi
1646      done
1647    else
1648      i=0
1649      while [ $i -lt $NB_ESSAI ] ; do
1650        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1651        status=$?
1652        if [ ${status} -gt 0 ]; then
1653          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1654          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1655          sleep $DELAI
1656        else
1657          break
1658        fi
1659        (( i = i + 1 ))
1660      done
1661      if [ ${status} -gt 0 ] ; then
1662        echo "IGCM_sys_Get : error"
1663        cat out_rsync
1664        \rm out_rsync
1665        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1666      else
1667        \rm out_rsync
1668      fi
1669    fi
1670  else
1671    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1672  fi
1673  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1674}
1675
1676#D-#==================================================
1677#D-function IGCM_sys_GetDate_FichWork
1678#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1679#D-* Examples:
1680#D-
1681function IGCM_sys_GetDate_FichWork {
1682  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1683  if ( $DEBUG_sys ) ; then
1684    echo "IGCM_sys_GetDate_FichWork :" $@
1685  fi
1686  typeset dateF
1687  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1688  eval ${2}=${dateF[5]}
1689
1690    # donne la date filesys d'un fichier sur la machine work
1691  IGCM_debug_PopStack "IGCM_sys_FichWork"
1692}
1693
1694#D-#==================================================
1695#D-function IGCM_sys_GetDate_FichArchive
1696#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1697#D-* Examples:
1698#D-
1699function IGCM_sys_GetDate_FichArchive {
1700  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1701  if ( $DEBUG_sys ) ; then
1702    echo "IGCM_sys_GetDate_FichArchive :" $@
1703  fi
1704  typeset dateF
1705  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1706  eval ${2}=${dateF[5]}
1707
1708  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1709}
1710
1711#D-#==================================================
1712#D-function IGCM_sys_Dods_Rm
1713#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1714#D-* Examples:
1715#D-
1716function IGCM_sys_Dods_Rm {
1717  if ( $DEBUG_sys ) ; then
1718    echo "IGCM_sys_Dods_Rm :" $@
1719  fi
1720  typeset status
1721  if [ $DRYRUN = 0 ]; then
1722
1723#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1724#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1725#      echo "Nothing has been done."
1726#      return
1727#    fi
1728
1729    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1730    status=$?
1731
1732#       if [ ${status} -gt 0 ] ; then
1733#           echo "IGCM_sys_Dods_Rm : error."
1734#           cat out_dods_rm
1735#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1736#       else
1737#           rm out_dods_rm
1738#       fi
1739
1740  else
1741    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1742  fi
1743  return $status
1744}
1745
1746#D-#==================================================
1747#D-function IGCM_sys_Dods_Cp
1748#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1749#D-* Examples:
1750#D-
1751function IGCM_sys_Dods_Cp {
1752  if ( $DEBUG_sys ) ; then
1753    echo "IGCM_sys_Dods_Cp :" $@
1754  fi
1755  typeset status
1756  if [ $DRYRUN = 0 ]; then
1757
1758#    if [ ! -d ${R_SAVE}/${1} ] ; then
1759#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1760#      echo "Nothing has been done."
1761#      return
1762#    fi
1763
1764    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1765    status=$?
1766
1767#       if [ ${status} -gt 0 ] ; then
1768#           echo "IGCM_sys_Dods_Cp : error."
1769#           cat out_dods_cp
1770#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1771#       else
1772#           rm out_dods_cp
1773#       fi
1774
1775  else
1776    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1777  fi
1778  return $status
1779}
1780
1781#D-#==================================================
1782#D-function IGCM_sys_Put_Dods
1783#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1784#D-* Examples:
1785#D-
1786function IGCM_sys_Put_Dods {
1787  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1788  if ( $DEBUG_sys ) ; then
1789    echo "IGCM_sys_Put_Dods :" $@
1790  fi
1791  #set -vx
1792  typeset status
1793  if [ $DRYRUN = 0 ]; then
1794    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1795      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1796      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1797      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1798      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1799      return
1800    fi
1801
1802    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1803      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1804      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1805      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1806      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1807      return
1808    fi
1809    #
1810    if [ -d ${R_SAVE}/${1} ] ; then
1811      cd ${R_SAVE}
1812    elif [ -d ${R_FIGR}/${1} ] ; then
1813      cd ${R_FIGR}
1814    fi
1815
1816    IGCM_sys_Dods_Rm ${1}
1817    IGCM_sys_Dods_Cp ${1}
1818    status=0
1819
1820    if [ ${status} -gt 0 ] ; then
1821      echo "IGCM_sys_Put_Dods : error."
1822      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1823    fi
1824  else
1825    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1826  fi
1827  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1828}
1829
1830##############################################################
1831# REBUILD OPERATOR
1832
1833function IGCM_sys_rebuild {
1834  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1835  if ( $DEBUG_sys ) ; then
1836    echo "IGCM_sys_rebuild :" $@
1837  fi
1838
1839  typeset NB_ESSAI DELAI status i firstArg
1840  # number of tentative
1841  NB_ESSAI=3
1842  # time delay between tentative
1843  DELAI=2
1844
1845  i=0
1846  while [ $i -lt $NB_ESSAI ] ; do
1847    ~p86ipsl/CESIUM/bin/rebuild -f -o $@ > out_rsync 2>&1
1848    status=$?
1849    if [ ${status} -gt 0 ] ; then
1850      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1851      cat out_rsync
1852      \rm out_rsync
1853      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1854      firstArg=${1}
1855      \rm ${firstArg}
1856      sleep $DELAI
1857    else
1858      \rm out_rsync
1859      break
1860    fi
1861    (( i = i + 1 ))
1862  done
1863
1864  if [ ${status} -gt 0 ] ; then
1865    echo "IGCM_sys_rebuild : rebuild error"
1866    IGCM_debug_Exit "rebuild"
1867  fi
1868
1869  IGCM_debug_PopStack "IGCM_sys_rebuild"
1870}
1871
1872function IGCM_sys_rebuild_station {
1873  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1874  typeset i list_opt file_in file_out prefix_invert list_invert
1875  if ( $DEBUG_sys ) ; then
1876    echo "IGCM_sys_rebuild_station :" $@
1877  fi
1878  list_opt=$@
1879
1880  # Invert Axis : t,x -> x,t
1881  #               t,pres,x -> x,t,pres
1882  # So that we can concatenate along x
1883  i=0
1884  for file_in in ${list_opt} ; do
1885    (( i = i + 1))
1886    [ ${i} = 1 ] && file_out=${file_in} && continue
1887    prefix_invert=$( basename ${file_in} .nc )
1888    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1889    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1890  done
1891
1892  # Concatenate
1893  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1894
1895  # Re-ivert file
1896  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1897
1898  # Station re-ordering is too expansive to be run within libICGM
1899  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1900  # This re-ordering must be done "in memory" by the cmorization process
1901  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1902  # BEGIN reordering
1903
1904  # Only LMDZ text output contains the exact ordering of the station.
1905  # We isolate this in the code below:
1906  #  0  38  -157.5000000000000  70.98591549295774
1907  #  0  54  27.49999999999999   67.18309859154928
1908  #  0  56  -62.50000000000001  82.39436619718309
1909  #  0  79  12.49999999999999   78.59154929577466
1910  #  0  116 -165.0000000000000  76.05633802816901
1911  #  0  117 130.0000000000000   70.98591549295774
1912  #  0  118 110.0000000000000   87.46478873239437
1913  #  1  40  4.999999999999995   51.97183098591550
1914#  typeset iStation iProc list_opt file_in file_out prefix_invert
1915#  typeset -Z4 j4
1916#  typeset -Z3 j3
1917
1918#  unset list_opt
1919#  set +A list_opt $@
1920
1921  # Filename after rebuild
1922#  file_out=${list_opt[0]}
1923  # Prefix of output files
1924#  prefix_invert=$( basename ${file_out} .nc )
1925  # Number of procs
1926#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1927
1928#  iProc=0
1929#  while [ ${iProc} -lt ${num_proc} ] ; do
1930    # Array containing Station as a number
1931#    unset proc_stn
1932#    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}' )
1933    # Number of stations produced by processor proc
1934#    stationLast=${#proc_stn[*]}
1935    # Proc number on 4 digits
1936#    j4=${iProc}
1937    # Init
1938#    iStation=0
1939#    while [ ${iStation} -lt ${stationLast} ] ; do
1940      # Station number on 3 digits
1941#      j3=${proc_stn[${iStation}]}
1942      # Extract station
1943      # Invert Axis : t,x -> x,t
1944      #               t,pres,x -> x,t,pres
1945      # So that we can concatenate along x
1946#      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
1947#      (( iStation = iStation + 1 ))
1948#    done
1949#    (( iProc = iProc + 1 ))
1950#  done
1951
1952  # Concatenate all station along x
1953#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1954
1955  # Re-invert file
1956#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1957
1958  # END reordering
1959
1960  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1961}
1962
1963############################################################
1964# Activate Running Environnment Variables
1965
1966function IGCM_sys_activ_variables {
1967  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1968  if ( $DEBUG_sys ) ; then
1969    echo "IGCM_sys_activ_variables"
1970  fi
1971
1972  ulimit -s unlimited
1973
1974  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1975}
1976
1977############################################################
1978# Desactivate Running Environnment Variables
1979
1980function IGCM_sys_desactiv_variables {
1981  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1982  if ( $DEBUG_sys ) ; then
1983    echo "IGCM_sys_desactiv_variables"
1984  fi
1985  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1986}
1987
1988############################################################
1989# Build MPI/OMP scripts run file (dummy function)
1990
1991function IGCM_sys_build_run_file {
1992
1993IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1994
1995}
1996
1997############################################################
1998# Build MPI/OMP scripts
1999function IGCM_sys_build_execution_scripts
2000{
2001  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
2002  if ( $DEBUG_sys ) ; then
2003    echo "IGCM_sys_build_execution_scripts " $@
2004  fi
2005
2006    # Verification with MSUB parameter
2007  EXECUTION=${HOST_MPIRUN_COMMAND}
2008
2009  if ( ${OK_PARA_MPMD} ) ; then
2010
2011    if [ -f run_file ] ; then
2012      IGCM_sys_Rm -f run_file
2013    fi
2014    touch run_file
2015
2016# run_file construction
2017
2018# Then first loop on the components for the coupler ie oasis
2019
2020### the coupler ie oasis must be the first one
2021    for comp in ${config_ListOfComponents[*]} ; do
2022
2023      eval ExeNameIn=\${config_Executable_${comp}[0]}
2024      eval ExeNameOut=\${config_Executable_${comp}[1]}
2025
2026        # for CPL component only
2027      if [ "X${comp}" = "XCPL" ] ; then
2028
2029        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2030        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2031        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2032      fi
2033    done
2034
2035# Then second loop on the components
2036
2037    for comp in ${config_ListOfComponents[*]} ; do
2038
2039      eval ExeNameIn=\${config_Executable_${comp}[0]}
2040      eval ExeNameOut=\${config_Executable_${comp}[1]}
2041
2042        # Only if we really have an executable for the component and not the coupler ie oasis:
2043      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
2044
2045        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2046        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2047        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2048      fi
2049    done
2050
2051    EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
2052
2053    IGCM_sys_Chmod u+x run_file
2054    if ( $DEBUG_sys ) ; then
2055      echo "run_file contains : "
2056      cat run_file
2057    fi
2058
2059  else # Only one executable. launch it.
2060
2061    #
2062    for comp in ${config_ListOfComponents[*]} ; do
2063
2064      # Only if we really have an executable for the component :
2065      eval ExeNameOut=\${config_Executable_${comp}[1]}
2066      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2067
2068        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2069        echo ""  >> script_${ExeNameOut}.ksh
2070        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2071
2072        if ( ${OK_PARA_OMP} ) ; then
2073          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2074          echo ""  >> script_${ExeNameOut}.ksh
2075          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2076          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2077          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2078          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
2079        fi
2080
2081        if  ( ${OK_PARA_MPI} ) ; then
2082          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2083          # Default : ccc_mprun used if nb_proc gt 1
2084          # to have out/err per process on different files
2085          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
2086          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2087          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
2088        else
2089          # Default : ccc_mprun is NOT used if nb_proc eq 1
2090          # to have out/err per process on different files
2091          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
2092          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
2093          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
2094        fi
2095
2096        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
2097        cat script_${ExeNameOut}.ksh
2098
2099      fi
2100
2101    done
2102
2103  fi
2104
2105  IGCM_debug_Print 1 "sys Curie : execution command is "
2106  IGCM_debug_Print 1 "$EXECUTION"
2107
2108  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2109}
2110
2111############################################################
2112# Check of space available on temporary filesytems
2113function IGCM_sys_check_quota {
2114    IGCM_debug_PushStack "IGCM_sys_check_quota"
2115    if ( $DEBUG_sys ) ; then
2116        echo "IGCM_sys_check_quota"
2117    fi
2118    IGCM_debug_PopStack "IGCM_sys_check_quota"
2119}
2120
2121##############################################################
2122# NCO OPERATOR
2123
2124function IGCM_sys_ncap2 {
2125  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2126  if ( $DEBUG_sys ) ; then
2127    echo "IGCM_sys_ncap2 :" $@
2128  fi
2129
2130  typeset NB_ESSAI DELAI status i
2131  # number of tentative
2132  NB_ESSAI=3
2133  # time delay between tentative
2134  DELAI=2
2135
2136  i=0
2137  while [ $i -lt $NB_ESSAI ] ; do
2138    ncap2 "$@" > out_rsync 2>&1
2139    status=$?
2140    if [ ${status} -gt 0 ] ; then
2141      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2142      cat out_rsync
2143      \rm out_rsync
2144      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2145      sleep $DELAI
2146    else
2147      \rm out_rsync
2148      break
2149    fi
2150    (( i = i + 1 ))
2151  done
2152
2153  if [ ${status} -gt 0 ] ; then
2154      echo "IGCM_sys_ncap2 : ncap2 error"
2155      IGCM_debug_Exit "ncap2"
2156  fi
2157
2158  IGCM_debug_PopStack "IGCM_sys_ncap2"
2159}
2160
2161function IGCM_sys_ncatted {
2162  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2163  if ( $DEBUG_sys ) ; then
2164    echo "IGCM_sys_ncatted :" $@
2165  fi
2166
2167  typeset NB_ESSAI DELAI status i
2168  # number of tentative
2169  NB_ESSAI=3
2170  # time delay between tentative
2171  DELAI=2
2172
2173  i=0
2174  while [ $i -lt $NB_ESSAI ] ; do
2175    ncatted "$@" > out_rsync 2>&1
2176    status=$?
2177    if [ ${status} -gt 0 ] ; then
2178      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2179      cat out_rsync
2180      \rm out_rsync
2181      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2182      sleep $DELAI
2183    else
2184      \rm out_rsync
2185      break
2186    fi
2187    (( i = i + 1 ))
2188  done
2189
2190  if [ ${status} -gt 0 ] ; then
2191      echo "IGCM_sys_ncatted : ncatted error"
2192      IGCM_debug_Exit "ncatted"
2193  fi
2194
2195  IGCM_debug_PopStack "IGCM_sys_ncatted"
2196}
2197
2198function IGCM_sys_ncbo {
2199  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2200  if ( $DEBUG_sys ) ; then
2201    echo "IGCM_sys_ncbo :" $@
2202  fi
2203
2204  typeset NB_ESSAI DELAI status i
2205  # number of tentative
2206  NB_ESSAI=3
2207  # time delay between tentative
2208  DELAI=2
2209
2210  i=0
2211  while [ $i -lt $NB_ESSAI ] ; do
2212    ncbo $@ > out_rsync 2>&1
2213    status=$?
2214    if [ ${status} -gt 0 ] ; then
2215      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2216      cat out_rsync
2217      \rm out_rsync
2218      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2219      sleep $DELAI
2220    else
2221      \rm out_rsync
2222      break
2223    fi
2224    (( i = i + 1 ))
2225  done
2226
2227  if [ ${status} -gt 0 ] ; then
2228      echo "IGCM_sys_ncbo : ncbo error"
2229      IGCM_debug_Exit "ncbo"
2230  fi
2231
2232  IGCM_debug_PopStack "IGCM_sys_ncbo"
2233}
2234
2235function IGCM_sys_ncdiff {
2236  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2237  if ( $DEBUG_sys ) ; then
2238    echo "IGCM_sys_ncdiff :" $@
2239  fi
2240
2241  typeset NB_ESSAI DELAI status i
2242  # number of tentative
2243  NB_ESSAI=3
2244  # time delay between tentative
2245  DELAI=2
2246
2247  i=0
2248  while [ $i -lt $NB_ESSAI ] ; do
2249    ncdiff $@ > out_rsync 2>&1
2250    status=$?
2251    if [ ${status} -gt 0 ] ; then
2252      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2253      cat out_rsync
2254      \rm out_rsync
2255      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2256      sleep $DELAI
2257    else
2258      \rm out_rsync
2259      break
2260    fi
2261    (( i = i + 1 ))
2262  done
2263
2264  if [ ${status} -gt 0 ] ; then
2265      echo "IGCM_sys_ncdiff : ncdiff error"
2266      IGCM_debug_Exit "ncdiff"
2267  fi
2268
2269  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2270}
2271
2272function IGCM_sys_ncea {
2273  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2274  if ( $DEBUG_sys ) ; then
2275    echo "IGCM_sys_ncea :" $@
2276  fi
2277
2278  typeset NB_ESSAI DELAI status i
2279  # number of tentative
2280  NB_ESSAI=3
2281  # time delay between tentative
2282  DELAI=2
2283
2284  i=0
2285  while [ $i -lt $NB_ESSAI ] ; do
2286    ncea $@ > out_rsync 2>&1
2287    status=$?
2288    if [ ${status} -gt 0 ] ; then
2289      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2290      cat out_rsync
2291      \rm out_rsync
2292      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2293      sleep $DELAI
2294    else
2295      \rm out_rsync
2296      break
2297    fi
2298    (( i = i + 1 ))
2299  done
2300
2301  if [ ${status} -gt 0 ] ; then
2302      echo "IGCM_sys_ncea : ncea error"
2303      IGCM_debug_Exit "ncea"
2304  fi
2305
2306  IGCM_debug_PopStack "IGCM_sys_ncea"
2307}
2308
2309function IGCM_sys_ncecat {
2310  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2311  if ( $DEBUG_sys ) ; then
2312    echo "IGCM_sys_ncecat :" $@
2313  fi
2314
2315  typeset NB_ESSAI DELAI status i
2316  # number of tentative
2317  NB_ESSAI=3
2318  # time delay between tentative
2319  DELAI=2
2320
2321  i=0
2322  while [ $i -lt $NB_ESSAI ] ; do
2323    ncecat $@ > out_rsync 2>&1
2324    status=$?
2325    if [ ${status} -gt 0 ] ; then
2326      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2327      cat out_rsync
2328      \rm out_rsync
2329      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2330      sleep $DELAI
2331    else
2332      \rm out_rsync
2333      break
2334    fi
2335    (( i = i + 1 ))
2336  done
2337
2338  if [ ${status} -gt 0 ] ; then
2339      echo "IGCM_sys_ncecat : ncecat error"
2340      IGCM_debug_Exit "ncecat"
2341  fi
2342
2343  IGCM_debug_PopStack "IGCM_sys_ncecat"
2344}
2345
2346function IGCM_sys_ncflint {
2347  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2348  if ( $DEBUG_sys ) ; then
2349    echo "IGCM_sys_ncflint :" $@
2350  fi
2351
2352  typeset NB_ESSAI DELAI status i
2353  # number of tentative
2354  NB_ESSAI=3
2355  # time delay between tentative
2356  DELAI=2
2357
2358  i=0
2359  while [ $i -lt $NB_ESSAI ] ; do
2360    ncflint $@ > out_rsync 2>&1
2361    status=$?
2362    if [ ${status} -gt 0 ] ; then
2363      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2364      cat out_rsync
2365      \rm out_rsync
2366      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2367      sleep $DELAI
2368    else
2369      \rm out_rsync
2370      break
2371    fi
2372    (( i = i + 1 ))
2373  done
2374
2375  if [ ${status} -gt 0 ] ; then
2376      echo "IGCM_sys_ncflint : ncflint error"
2377      IGCM_debug_Exit "ncflint"
2378  fi
2379
2380  IGCM_debug_PopStack "IGCM_sys_ncflint"
2381}
2382
2383function IGCM_sys_ncks {
2384  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2385  if ( $DEBUG_sys ) ; then
2386    echo "IGCM_sys_ncks :" $@
2387  fi
2388
2389  typeset NB_ESSAI DELAI status i
2390  # number of tentative
2391  NB_ESSAI=3
2392  # time delay between tentative
2393  DELAI=2
2394
2395  i=0
2396  while [ $i -lt $NB_ESSAI ] ; do
2397    ncks $@ > out_rsync 2>&1
2398    status=$?
2399    if [ ${status} -gt 0 ] ; then
2400      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2401      cat out_rsync
2402      \rm out_rsync
2403      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2404      sleep $DELAI
2405    else
2406      \rm out_rsync
2407      break
2408    fi
2409    (( i = i + 1 ))
2410  done
2411
2412  if [ ${status} -gt 0 ] ; then
2413      echo "IGCM_sys_ncks : ncks error"
2414      IGCM_debug_Exit "ncks"
2415  fi
2416
2417  IGCM_debug_PopStack "IGCM_sys_ncks"
2418}
2419
2420function IGCM_sys_ncpdq {
2421  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2422  if ( $DEBUG_sys ) ; then
2423    echo "IGCM_sys_ncpdq :" $@
2424  fi
2425
2426  typeset NB_ESSAI DELAI status i
2427  # number of tentative
2428  NB_ESSAI=3
2429  # time delay between tentative
2430  DELAI=2
2431
2432  i=0
2433  while [ $i -lt $NB_ESSAI ] ; do
2434    ncpdq $@ > out_rsync 2>&1
2435    status=$?
2436    if [ ${status} -gt 0 ] ; then
2437      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2438      cat out_rsync
2439      \rm out_rsync
2440      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2441      sleep $DELAI
2442    else
2443      \rm out_rsync
2444      break
2445    fi
2446    (( i = i + 1 ))
2447  done
2448
2449  if [ ${status} -gt 0 ] ; then
2450      echo "IGCM_sys_ncpdq : ncpdq error"
2451      IGCM_debug_Exit "ncpdq"
2452  fi
2453
2454  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2455}
2456
2457function IGCM_sys_ncra {
2458  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2459  if ( $DEBUG_sys ) ; then
2460    echo "IGCM_sys_ncra :" $@
2461  fi
2462
2463  typeset NB_ESSAI DELAI status i
2464  # number of tentative
2465  NB_ESSAI=3
2466  # time delay between tentative
2467  DELAI=2
2468
2469  i=0
2470  while [ $i -lt $NB_ESSAI ] ; do
2471    ncra $@ > out_rsync 2>&1
2472    status=$?
2473    if [ ${status} -gt 0 ] ; then
2474      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2475      cat out_rsync
2476      \rm out_rsync
2477      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2478      sleep $DELAI
2479    else
2480      \rm out_rsync
2481      break
2482    fi
2483    (( i = i + 1 ))
2484  done
2485
2486  if [ ${status} -gt 0 ] ; then
2487      echo "IGCM_sys_ncra : ncra error"
2488      IGCM_debug_Exit "ncra"
2489  fi
2490
2491  IGCM_debug_PopStack "IGCM_sys_ncra"
2492}
2493
2494function IGCM_sys_ncrcat {
2495  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2496  if ( $DEBUG_sys ) ; then
2497    echo "IGCM_sys_ncrcat :" $@
2498  fi
2499
2500  typeset NB_ESSAI DELAI status i lastArg
2501  # number of tentative
2502  NB_ESSAI=3
2503  # time delay between tentative
2504  DELAI=2
2505
2506  i=0
2507  while [ $i -lt $NB_ESSAI ] ; do
2508    ncrcat $@ > out_rsync 2>&1
2509    status=$?
2510    if [ ${status} -gt 0 ] ; then
2511      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2512      cat out_rsync
2513      \rm out_rsync
2514      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2515      sleep $DELAI
2516    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2517      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2518      cat out_rsync
2519      # remove files having corrupted time axis
2520      eval lastArg=\${$#}
2521      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2522      \rm ${lastArg}
2523      \rm out_rsync
2524      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2525      sleep $DELAI
2526    else
2527      \rm out_rsync
2528      break
2529    fi
2530    (( i = i + 1 ))
2531  done
2532
2533  if [ ${status} -gt 0 ] ; then
2534      echo "IGCM_sys_ncrcat : ncrcat error"
2535      #IGCM_debug_Exit "ncrcat"
2536  fi
2537
2538  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2539}
2540
2541function IGCM_sys_ncrename {
2542  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2543  if ( $DEBUG_sys ) ; then
2544    echo "IGCM_sys_ncrename :" $@
2545  fi
2546
2547  typeset NB_ESSAI DELAI status i
2548  # number of tentative
2549  NB_ESSAI=3
2550  # time delay between tentative
2551  DELAI=2
2552
2553  i=0
2554  while [ $i -lt $NB_ESSAI ] ; do
2555    ncrename $@ > out_rsync 2>&1
2556    status=$?
2557    if [ ${status} -gt 0 ] ; then
2558      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2559      cat out_rsync
2560      \rm out_rsync
2561      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2562      sleep $DELAI
2563    else
2564      \rm out_rsync
2565      break
2566    fi
2567    (( i = i + 1 ))
2568  done
2569
2570  if [ ${status} -gt 0 ] ; then
2571      echo "IGCM_sys_ncrename : ncrename error"
2572      IGCM_debug_Exit "ncrename"
2573  fi
2574
2575  IGCM_debug_PopStack "IGCM_sys_ncrename"
2576}
2577
2578function IGCM_sys_ncwa {
2579  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2580  if ( $DEBUG_sys ) ; then
2581    echo "IGCM_sys_ncwa :" $@
2582  fi
2583
2584  typeset NB_ESSAI DELAI status i
2585  # number of tentative
2586  NB_ESSAI=3
2587  # time delay between tentative
2588  DELAI=2
2589
2590  i=0
2591  while [ $i -lt $NB_ESSAI ] ; do
2592    ncwa $@ > out_rsync 2>&1
2593    status=$?
2594    if [ ${status} -gt 0 ] ; then
2595      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2596      cat out_rsync
2597      \rm out_rsync
2598      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2599      sleep $DELAI
2600    else
2601      \rm out_rsync
2602      break
2603    fi
2604    (( i = i + 1 ))
2605  done
2606
2607  if [ ${status} -gt 0 ] ; then
2608      echo "IGCM_sys_ncwa : ncwa error"
2609      IGCM_debug_Exit "ncwa"
2610  fi
2611
2612  IGCM_debug_PopStack "IGCM_sys_ncwa"
2613}
2614
2615##############################################################
2616# CDO OPERATOR
2617
2618function IGCM_sys_cdo {
2619  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2620  if ( $DEBUG_sys ) ; then
2621    echo "IGCM_sys_cdo :" $@
2622  fi
2623
2624  typeset status
2625
2626  \cdo $@ > out_rsync 2>&1
2627  status=$?
2628  if [ ${status} -gt 0 ] ; then
2629    echo "IGCM_sys_cdo : error code ${status}"
2630    cat out_rsync
2631    \rm out_rsync
2632    IGCM_debug_PopStack "IGCM_sys_cdo"
2633    return 1
2634  else
2635    IGCM_debug_PopStack "IGCM_sys_cdo"
2636    return 0
2637  fi
2638
2639  IGCM_debug_PopStack "IGCM_sys_cdo"
2640}
Note: See TracBrowser for help on using the repository browser.