source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh @ 1032

Last change on this file since 1032 was 1032, checked in by sdipsl, 10 years ago

Fix #201

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