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

Last change on this file since 773 was 773, checked in by sdipsl, 11 years ago

Cosmetics

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