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

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

catch JobID to be able to connect computing trees and post-processing trees. See #125
Obelix not yet done.

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