source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_default.ksh @ 1179

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

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