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

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

Addon for 3D perturbation mechanism. see #197
Cosmetics
SN

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