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

Last change on this file since 1180 was 1180, checked in by sdipsl, 9 years ago

house keeping in libIGCM_sys (third pass). Will ease #248 and #251

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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