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

Last change on this file since 669 was 669, checked in by mafoipsl, 12 years ago

Add -L to copy files instead of links to avoid broken links in Post jobs.

  • 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: 50.0 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 |            |  Chmod  |                           |
46# |          |      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 -r MASTER=${HOST}
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# rsync with path
78typeset -r RSYNC=/usr/bin/rsync
79#RSYNC_opt args to rsync
80typeset -r RSYNC_opt="-va"
81#"-Lt -v"
82# ie storage filesystem
83typeset -r STOREHOST=${MASTER}
84
85#====================================================
86# Set environment tools (ferret, nco, cdo)
87#====================================================
88#. /home/${LOGIN}/.atlas_env_${HOST}_ksh
89
90#====================================================
91# Host specific DIRECTORIES
92#====================================================
93
94#====================================================
95#- MirrorlibIGCM for frontend
96typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
97
98#====================================================
99#- libIGCM_POST
100typeset -r libIGCM_POST=${libIGCM}
101
102#====================================================
103#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
104typeset -r R_EXE="${MODIPSL}/bin"
105
106#====================================================
107#- SCRATCHDIR (=> ${R_DONNEES})
108typeset -r SCRATCHDIR=/tmp
109
110#====================================================
111#- SUBMIT_DIR : submission dir
112typeset SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
113
114#====================================================
115#- ARCHIVE (dedicated to large files)
116typeset -r ARCHIVE=/home/${LOGIN}
117
118#- ARCHIVE (dedicated to small/medium files)
119typeset -r STORAGE=${ARCHIVE}
120
121#====================================================
122#- IN
123typeset -r R_IN=${R_IN:=${ARCHIVE}/IGCM}
124
125#====================================================
126#- OUT
127IGCM_OUT=${IGCM_OUT:=IGCM_OUT}
128typeset -r R_OUT=${ARCHIVE}/${IGCM_OUT}
129
130#====================================================
131#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
132typeset -r R_FIG=${STORAGE}/IGCM_OUT
133
134#====================================================
135#- R_BUF (ONLY FOR double copy an scratch)
136typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
137
138#====================================================
139#- BIG_DIR : BIG_DIR to store files waiting for rebuild
140typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
141
142#====================================================
143#- OUT_POST
144typeset -r R_OUT_POST=${R_OUT}
145
146#====================================================
147#- RUN_DIR_PATH : Temporary working directory (=> TMP)
148typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/tmp$$}
149
150#====================================================
151#- HOST_MPIRUN_COMMAND
152typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
153
154#=========================================================
155#- Add "time" before mpirun command
156MPIRUN_COMMAND="time "${MPIRUN_COMMAND}
157echo ${MPIRUN_COMMAND}
158
159#====================================================
160#- Max number of arguments passed to nco operator or demigration command
161UNIX_MAX_LIMIT=360
162
163#====================================================
164#- Number of core per node (max number of OpenMP task)
165NUM_COREPERNODE=1
166
167#====================================================
168#- Default number of MPI task for IPSL coupled model
169#- required for backward compatibility
170#-
171DEFAULT_NUM_PROC_OCE=1
172DEFAULT_NUM_PROC_CPL=1
173(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
174DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
175
176#D-#==================================================
177#D-function IGCM_sys_RshMaster
178#D-* Purpose: Just a fake command to wrapp
179#D-           IGCM_card call in post-treatment
180#D-           Ulam do not see brodie filesystem
181#D-           Cesium do not see all mercure filesystem
182#D-           That's why we need this hack.
183#D-* Examples:
184#D-
185function IGCM_sys_RshMaster {
186  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
187  ssh ${HOST} /bin/ksh  <<-EOF
188    export libIGCM=${libIGCM}
189    export DEBUG_debug=${DEBUG_debug}
190    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
191    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
192    ${@}
193EOF
194  if [ $? -gt 0 ] ; then
195    echo "IGCM_sys_RshMaster : erreur."
196    IGCM_debug_Exit "IGCM_sys_RshMaster"
197  fi
198  IGCM_debug_PopStack "IGCM_sys_RshMaster"
199}
200
201#D-#==================================================
202#D-function IGCM_sys_RshArchive
203#D-* Purpose: Archive rsh command
204#D-* Examples:
205#D-
206function IGCM_sys_RshArchive {
207  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
208  /bin/ksh  <<-EOF
209    ${@}
210EOF
211  if [ $? -gt 0 ] ; then
212    echo "IGCM_sys_RshArchive : erreur."
213    IGCM_debug_Exit "IGCM_sys_RshArchive"
214  fi
215  IGCM_debug_PopStack "IGCM_sys_RshArchive"
216}
217
218#D-#==================================================
219#D-function IGCM_sys_RshPost
220#D-* Purpose: Post-process rsh command
221#D-* Examples:
222#D-
223(( RshPNum = 0 ))
224function IGCM_sys_RshPost {
225  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
226  if ( $DEBUG_sys ) ; then
227    echo "IGCM_sys_RshPost :" $@
228  fi
229  #/bin/ksh -vx $@ > out_RshPost.${RshPNum}
230  ssh ${HOST} /bin/ksh $@ > out_RshPost.${RshPNum}
231  if [ $? -gt 0 ] ; then
232    echo "IGCM_sys_RshPost : erreur."
233    IGCM_debug_Exit "IGCM_sys_RshPost"
234  fi
235  (( RshPNum = RshPNum + 1 ))
236  IGCM_debug_PopStack "IGCM_sys_RshPost"
237}
238
239#D-#==================================================
240#D-function IGCM_sys_SendMail
241#D-* Purpose: Send mail when simulation is over
242#D-* Examples:
243#D-
244function IGCM_sys_SendMail {
245  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
246  if ( $DEBUG_sys ) ; then
247    echo "IGCM_sys_SendMail :" $@
248  fi
249
250  if ( ${ExitFlag} ) ; then
251    status=failed
252  else
253    status=completed
254  fi
255  cat  << END_MAIL > job_end.mail
256Dear ${LOGIN},
257
258  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
259  Job started : ${DateBegin}
260  Job ended   : ${DateEnd}
261  Output files are available in ${R_SAVE}
262  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
263END_MAIL
264
265  if [ ! -z ${config_UserChoices_MailName} ] ; then
266    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
267  elif [ -f ~/.forward ] ; then
268    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
269  fi
270
271  if [ $? -gt 0 ] ; then
272    echo "IGCM_sys_SendMail : erreur."
273    IGCM_debug_Exit "IGCM_sys_SendMail"
274  fi
275  IGCM_debug_PopStack "IGCM_sys_SendMail"
276}
277
278#D-#==================================================
279#D-function IGCM_sys_Mkdir
280#D-* Purpose: Master locale mkdir command
281#D-* Examples:
282#D-
283function IGCM_sys_Mkdir {
284  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
285  if ( $DEBUG_sys ) ; then
286    echo "IGCM_sys_Mkdir :" $@
287  fi
288  if [ ! -d ${1} ]; then
289    \mkdir -p $1
290    if [ $? -gt 0 ] ; then
291      echo "IGCM_sys_Mkdir : erreur."
292      IGCM_debug_Exit "IGCM_sys_Mkdir"
293    fi
294  fi
295    # vérification :
296  if [ ! -d ${1} ] ; then
297    echo "IGCM_sys_Mkdir : erreur."
298    IGCM_debug_Exit "IGCM_sys_Mkdir"
299  fi
300  IGCM_debug_PopStack "IGCM_sys_Mkdir"
301}
302
303#D-#==================================================
304#D-function IGCM_sys_MkdirArchive
305#D-* Purpose: Mkdir on Archive
306#D-* Examples:
307#D-
308function IGCM_sys_MkdirArchive {
309  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
310  if ( $DEBUG_sys ) ; then
311    echo "IGCM_sys_MkdirArchive :" $@
312  fi
313    #- creation de repertoire sur le serveur fichier
314  if [ ! -d ${1} ]; then
315    \mkdir -p $1
316    if [ $? -gt 0 ] ; then
317      echo "IGCM_sys_MkdirArchive : erreur."
318      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
319    fi
320  fi
321  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
322}
323
324#D-#==================================================
325#D-function IGCM_sys_MkdirWork
326#D-* Purpose: Mkdir on Work
327#D-* Examples:
328#D-
329function IGCM_sys_MkdirWork {
330  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
331  if ( $DEBUG_sys ) ; then
332    echo "IGCM_sys_MkdirWork :" $@
333  fi
334    #- creation de repertoire sur le serveur fichier
335  if [ ! -d ${1} ]; then
336    \mkdir -p $1
337    if [ $? -gt 0 ] ; then
338      echo "IGCM_sys_MkdirWork : erreur."
339      IGCM_debug_Exit "IGCM_sys_MkdirWork"
340    fi
341  fi
342  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
343}
344
345#D-#==================================================
346#D-function IGCM_sys_Cd
347#D-* Purpose: master cd command
348#D-* Examples:
349#D-
350function IGCM_sys_Cd {
351  IGCM_debug_PushStack "IGCM_sys_Cd" $@
352  if ( $DEBUG_sys ) ; then
353    echo "IGCM_sys_Cd :" $@
354  fi
355  \cd $1
356  if [ $? -gt 0 ] ; then
357    echo "IGCM_sys_Cd : erreur."
358    IGCM_debug_Exit "IGCM_sys_Cd"
359  fi
360  IGCM_debug_PopStack "IGCM_sys_Cd"
361}
362
363#D-#==================================================
364#D-function IGCM_sys_Chmod
365#D-* Purpose: Chmod
366#D-* Examples:
367#D-
368function IGCM_sys_Chmod {
369  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
370  if ( $DEBUG_sys ) ; then
371    echo "IGCM_sys_Chmod :" $@
372  fi
373  if [ $DRYRUN -le 1 ]; then
374    \chmod $@
375    if [ $? -gt 0 ] ; then
376      echo "IGCM_sys_Chmod : erreur."
377      IGCM_debug_Exit "IGCM_sys_Chmod"
378    fi
379  else
380    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
381  fi
382  IGCM_debug_PopStack "IGCM_sys_Chmod"
383}
384
385#D-#==================================================
386#D-function IGCM_sys_FileSize
387#D-* Purpose: Filesize
388#D-* Examples:
389#D-
390function IGCM_sys_FileSize {
391  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
392
393  typeset sizeF
394  set +A sizeF -- $( ls -la ${1} )
395  if [ $? -gt 0 ] ; then
396    IGCM_debug_Exit "IGCM_sys_FileSize"
397  fi
398  eval ${2}=${sizeF[4]}
399
400  IGCM_debug_PopStack "IGCM_sys_FileSize"
401}
402
403#D-#==================================================
404#D-function IGCM_sys_TestDir
405#D-* Purpose: Test Directory that must exists
406#D-* Examples:
407#D-
408function IGCM_sys_TestDir {
409  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
410  if ( $DEBUG_sys ) ; then
411    echo "IGCM_sys_TestDir :" $@
412  fi
413  typeset ExistFlag
414  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
415  IGCM_debug_PopStack "IGCM_sys_TestDir"
416
417  return ${ExistFlag}
418}
419
420#D-#==================================================
421#D-function IGCM_sys_TestDirArchive
422#D-* Purpose: Test Directory that must exists on Archive
423#D-* Examples:
424#D-
425function IGCM_sys_TestDirArchive {
426  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
427  if ( $DEBUG_sys ) ; then
428    echo "IGCM_sys_TestDirArchive :" $@
429  fi
430  typeset ExistFlag
431  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
432  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
433
434  return ${ExistFlag}
435}
436
437#D-#==================================================
438#D-function IGCM_sys_TestFileArchive
439#D-* Purpose: Test file that must NOT EXISTS on Archive
440#D-* Examples:
441#D-
442function IGCM_sys_TestFileArchive {
443  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
444  typeset ExistFlag
445  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
446  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
447
448  return ${ExistFlag}
449}
450
451#D-#==================================================
452#D-function IGCM_sys_TestFileBuffer
453#D-* Purpose: Test file that must NOT EXISTS on Buffer
454#D-* Examples:
455#D-
456function IGCM_sys_TestFileBuffer {
457  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
458  typeset ExistFlag
459  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
460  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
461
462  return ${ExistFlag}
463}
464
465#D-#==================================================
466#D-function IGCM_sys_CountFileArchive
467#D-* Purpose: Count files on Archive filesystem
468#D-* Examples:
469#D-
470function IGCM_sys_CountFileArchive {
471  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
472  ls ${@} 2>/dev/null | wc -l
473  if [ $? -gt 0 ] ; then
474    echo "IGCM_sys_CountFileArchive : erreur."
475  fi
476  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
477}
478
479#D-#==================================================
480#D-function IGCM_sys_CountFileBuffer
481#D-* Purpose: Count files on Scratch filesystem
482#D-* Examples:
483#D-
484function IGCM_sys_CountFileBuffer {
485  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
486  ls ${@} 2>/dev/null | wc -l
487  if [ $? -gt 0 ] ; then
488    echo "IGCM_sys_CountFileBuffer : erreur."
489  fi
490  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
491}
492
493#D-#==================================================
494#D-function IGCM_sys_Tree
495#D-* Purpose: Tree directories with files on ${ARCHIVE}
496#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
497#D-
498function IGCM_sys_Tree {
499  IGCM_debug_PushStack "IGCM_sys_Tree" $@
500  if ( $DEBUG_sys ) ; then
501    echo "IGCM_sys_Tree :" $@
502  fi
503
504  \tree -f $@
505
506  IGCM_debug_PopStack "IGCM_sys_Tree"
507}
508
509#D-#==================================================
510#D-function IGCM_sys_Tar
511#D-* Purpose: master tar command
512#D-* Examples:
513#D-
514function IGCM_sys_Tar {
515  IGCM_debug_PushStack "IGCM_sys_Tar" $@
516  if ( $DEBUG_sys ) ; then
517    echo "IGCM_sys_Tar :" $@
518  fi
519  \tar cf $@
520  if [ $? -gt 0 ] ; then
521    echo "IGCM_sys_Tar : erreur."
522    IGCM_debug_Exit "IGCM_sys_Tar"
523  fi
524
525  IGCM_debug_PopStack "IGCM_sys_Tar"
526}
527
528#D-#==================================================
529#D-function IGCM_sys_UnTar
530#D-* Purpose: master un-tar command
531#D-* Examples:
532#D-
533function IGCM_sys_UnTar {
534  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
535  if ( $DEBUG_sys ) ; then
536    echo "IGCM_sys_UnTar :" $@
537  fi
538  \tar xvf $1
539  if [ $? -gt 0 ] ; then
540    echo "IGCM_sys_UnTar : erreur."
541    IGCM_debug_Exit "IGCM_sys_UnTar"
542  fi
543  IGCM_debug_PopStack "IGCM_sys_UnTar"
544}
545
546#D-#==================================================
547#D-function IGCM_sys_Qsub
548#D-* Purpose: Qsub new job
549#D-* Examples:
550#D-
551function IGCM_sys_Qsub {
552  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
553  if ( $DEBUG_sys ) ; then
554    echo "IGCM_sys_Qsub :" $@
555  fi
556  echo "ssh -l ${LOGIN} ${HOST} ""cd ${SUBMIT_DIR} ; ${@}"" > ${Script_Output} 2>&1 &"
557  ssh -l ${LOGIN} ${HOST} "cd ${SUBMIT_DIR} ; ${@}" > ${Script_Output} 2>&1 &
558  if [ $? -gt 0 ] ; then
559    echo "IGCM_sys_Qsub : erreur."
560    IGCM_debug_Exit "IGCM_sys_Qsub"
561  fi
562  IGCM_debug_PopStack "IGCM_sys_Qsub"
563}
564
565#D-#==================================================
566#D-function IGCM_sys_QsubPost
567#D-* Purpose: Qsub new job on scalaire
568#D-* Examples:
569#D-
570function IGCM_sys_QsubPost {
571  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
572  if ( $DEBUG_sys ) ; then
573    echo "IGCM_sys_QsubPost :" $@
574  fi
575    #echo "ssh -x -l ${LOGIN} ${HOST} ${3} > ${2} 2>&1 &"
576    #    ssh -x -l ${LOGIN} ${HOST}
577  echo "${libIGCM_POST}/$1.job > ${POST_DIR}/$1.${PeriodDateEnd}.out 2>&1 &"
578  ${libIGCM_POST}/$1.job > ${POST_DIR}/${Script_Post_Output}.out 2>&1 &
579    #    ${3} > ${2} 2>&1 &
580  if [ $? -gt 0 ] ; then
581    echo "IGCM_sys_QsubPost : erreur " $@
582    IGCM_debug_Exit "IGCM_sys_QsubPost"
583  fi
584  IGCM_debug_PopStack "IGCM_sys_QsubPost"
585}
586
587#D-*************************
588#D- File transfer functions
589#D-*************************
590#D-
591
592#D-#==================================================
593#D-function IGCM_sys_Rsync_out
594#D-* Purpose: treat return val of rsync
595#D-* Examples:  IGCM_sys_Rsync_out out_RET_rsync
596#D-  Error values and explanations can depend on your system version.
597function IGCM_sys_Rsync_out {
598  RET=$1
599  if [ ! $RET ] ; then
600    echo "rsync error !"
601  fi
602
603  if [ $MYLANG = "fr" ]; then
604    case $RET in
605    0)  return ;;
606    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
607      echo "Erreur de syntaxe ou d'utilisation."
608      return;;
609    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
610      echo "Incompatibilité de protocole."
611      return;;
612    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
613      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
614      echo "répertoires"
615      return;;
616    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
617      echo "Action demandée non supportée : une tentative de manipulation de"
618      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
619      echo "été faite ; ou une option qui est supportée par le  client  mais"
620      echo "pas par le serveur a été spécifiée."
621      return;;
622    10) echo "Erreur de rsync ; RERR_SOCKETIO"
623      echo "Erreur dans le socket d'entrée sortie"
624      return;;
625    11) echo "Erreur de rsync ; RERR_FILEIO"
626      echo "Erreur d'entrée sortie fichier"
627      return;;
628    12) echo "Erreur de rsync ; RERR_STREAMIO"
629      echo "Erreur dans flux de donnée du protocole rsync"
630      return;;
631    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
632      echo "Erreur avec les diagnostics du programme"
633      return;;
634    14) echo "Erreur de rsync ; RERR_IPC"
635      echo "Erreur dans le code IPC"
636      return;;
637    20) echo "Erreur de rsync ; RERR_SIGNAL"
638      echo "SIGUSR1 ou SIGINT reçu"
639      return;;
640    21) echo "Erreur de rsync ; RERR_WAITCHILD"
641      echo "Une erreur retournée par waitpid()"
642      return;;
643    22) echo "Erreur de rsync ; RERR_MALLOC"
644      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
645      return;;
646    23) echo ""
647      echo "Erreur fichier inexistant"
648      return;;
649    30) echo "Erreur de rsync ; RERR_TIMEOUT"
650      echo "Temps d'attente écoulé dans l'envoi/réception de données"
651      return;;
652    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
653      return;;
654    esac
655  elif [ $MYLANG = "en" ] ; then
656    case $RET in
657    0)  return;;
658    1)  echo "rsync error : Syntax or usage error "
659      return;;
660    2)  echo "rsync error : Protocol incompatibility "
661      return;;
662    3)  echo "rsync error : Errors selecting input/output files, dirs"
663      return;;
664    4)  echo "rsync error : Requested action not supported: an attempt"
665      echo "was made to manipulate 64-bit files on a platform that cannot support"
666      echo "them; or an option was specified that is supported by the client and"
667      echo "not by the server."
668      return;;
669    5)  echo "rsync error : Error starting client-server protocol"
670      return;;
671    10) echo "rsync error : Error in socket I/O "
672      return;;
673    11) echo "rsync error : Error in file I/O "
674      return;;
675    12) echo "rsync error : Error in rsync protocol data stream "
676      return;;
677    13) echo "rsync error : Errors with program diagnostics "
678      return;;
679    14) echo "rsync error : Error in IPC code "
680      return;;
681    20) echo "rsync error : Received SIGUSR1 or SIGINT "
682      return;;
683    21) echo "rsync error : Some error returned by waitpid() "
684      return;;
685    22) echo "rsync error : Error allocating core memory buffers "
686      return;;
687    23) echo "rsync error : Partial transfer due to error"
688      return;;
689    24) echo "rsync error : Partial transfer due to vanished source files"
690      return;;
691    30) echo "rsync error : Timeout in data send/receive "
692      return;;
693    *)  echo "rsync error : return code of rsync unknown :" $RET
694      return;;
695    esac
696  else
697    echo "unknown language $MYLANG."
698    return
699  fi
700}
701
702#D-#==================================================
703#D-function IGCM_sys_Cp
704#D-* Purpose: generic cp
705#D-* Examples:
706#D-
707function IGCM_sys_Cp {
708  IGCM_debug_PushStack "IGCM_sys_Cp" $@
709  if ( $DEBUG_sys ) ; then
710    echo "IGCM_sys_Cp :" $@
711  fi
712
713  typeset RET
714
715  echo cp --preserve=timestamps $@ > out_rsync 2>&1
716  \cp --preserve=timestamps $@ >> out_rsync 2>&1
717  RET=$?
718
719  if [ ${RET} -gt 0 ] ; then
720    echo ""
721#       echo "IGCM_sys_Cp : error."
722#       cat out_rsync
723#       IGCM_debug_Exit "IGCM_sys_Cp"
724  else
725    \rm out_rsync
726  fi
727  IGCM_debug_PopStack "IGCM_sys_Cp"
728}
729
730#D-#==================================================
731#D-function IGCM_sys_Rm
732#D-* Purpose: generic rm
733#D-* Examples:
734#D-
735function IGCM_sys_Rm {
736  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
737  if ( $DEBUG_sys ) ; then
738    echo "IGCM_sys_Rm :" $@
739  fi
740
741  typeset RET
742
743  echo rm $@ > out_rsync 2>&1
744  \rm $@ >> out_rsync 2>&1
745  RET=$?
746
747  if [ ${RET} -gt 0 ] ; then
748    echo "IGCM_sys_Rm : error."
749    cat out_rsync
750    IGCM_debug_Exit "IGCM_sys_Rm"
751  else
752    \rm out_rsync
753  fi
754  IGCM_debug_PopStack "IGCM_sys_Rm"
755}
756
757#D-#==================================================
758#D-function IGCM_sys_RmRunDir
759#D-* Purpose: rm tmpdir (dummy function most of the time batch
760#D-                      scheduler will do the job)
761#D-* Examples:
762#D-
763function IGCM_sys_RmRunDir {
764  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
765  if ( $DEBUG_sys ) ; then
766    echo "IGCM_sys_RmRunDir :" $@
767    echo "Dummy call, let the scheduler do that."
768#       IGCM_sys_Rm -rf ${RUN_DIR}
769  fi
770  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
771}
772
773#D-#==================================================
774#D-function IGCM_sys_Mv
775#D-* Purpose: generic move
776#D-* Examples:
777#D-
778function IGCM_sys_Mv {
779  IGCM_debug_PushStack "IGCM_sys_Mv" $@
780  if ( $DEBUG_sys ) ; then
781    echo "IGCM_sys_Mv :" $@
782  fi
783
784  if [ $DRYRUN = 0 ]; then
785
786    typeset RET
787
788    echo mv $@ > out_rsync 2>&1
789    \mv $@ >> out_rsync 2>&1
790    RET=$?
791
792    if [ ${RET} -gt 0 ] ; then
793      echo "IGCM_sys_Mv : error in mv."
794      cat out_rsync
795      IGCM_debug_Exit "IGCM_sys_Mv"
796    else
797      \rm out_rsync
798    fi
799  else
800    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
801  fi
802
803  IGCM_debug_PopStack "IGCM_sys_Mv"
804}
805
806#D-#==================================================
807#D-function IGCM_sys_Put_Dir
808#D-* Purpose: Copy a complete directory on $(ARCHIVE)
809#D-* Examples:
810#D-
811function IGCM_sys_Put_Dir {
812  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
813  if ( $DEBUG_sys ) ; then
814    echo "IGCM_sys_Put_Dir :" $@
815  fi
816  if [ $DRYRUN = 0 ]; then
817    if [ ! -d ${1} ] ; then
818      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
819      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
820      return
821    fi
822
823    typeset RET
824
825        # Only if we use rsync
826        #IGCM_sys_TestDirArchive $( dirname $2 )
827        #
828        #USUAL WAY
829    \cp -R $1 $2 > out_rsync 2>&1
830    RET=$?
831
832    if [ ${RET} -gt 0 ] ; then
833      echo "IGCM_sys_Put_Dir : error."
834      cat out_rsync
835      IGCM_debug_Exit "IGCM_sys_Put_Dir"
836    else
837      \rm out_rsync
838    fi
839  else
840    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
841  fi
842  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
843}
844
845#D-#==================================================
846#D-function IGCM_sys_Get_Dir
847#D-* Purpose: Copy a complete directory from $(ARCHIVE)
848#D-* Examples:
849#D-
850function IGCM_sys_Get_Dir {
851  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
852  if ( $DEBUG_sys ) ; then
853    echo "IGCM_sys_Get_Dir :" $@
854  fi
855  if [ $DRYRUN = 0 ]; then
856    if [ ! -d ${1} ] ; then
857      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
858      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
859      return
860    fi
861
862    typeset RET
863
864        #USUAL WAY
865    \cp -R $1 $2 > out_rsync 2>&1
866    RET=$?
867
868    if [ ${RET} -gt 0 ] ; then
869      echo "IGCM_sys_Get_Dir : error."
870      cat out_rsync
871      IGCM_debug_Exit "IGCM_sys_Get_Dir"
872    else
873      \rm out_rsync
874    fi
875  else
876    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
877  fi
878  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
879}
880
881#D-#==================================================
882#D-function IGCM_sys_Get_Master
883#D-* Purpose: Copy a complete directory from MASTER filesystem
884#D-* Examples:
885#D-
886function IGCM_sys_Get_Master {
887  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
888  if ( $DEBUG_sys ) ; then
889    echo "IGCM_sys_Get_Master :" $@
890  fi
891  if [ $DRYRUN = 0 ]; then
892    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
893      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
894      IGCM_debug_PopStack "IGCM_sys_Get_Master"
895      return
896    fi
897
898    typeset RET
899
900        #USUAL WAY
901    cp -RL $1 $2 > out_rsync 2>&1
902    RET=$?
903
904    if [ ${RET} -gt 0 ] ; then
905      echo "IGCM_sys_Get_Master : error."
906      cat out_rsync
907      IGCM_debug_Exit "IGCM_sys_Get_Master"
908    else
909      \rm out_rsync
910    fi
911  else
912    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
913  fi
914  IGCM_debug_PopStack "IGCM_sys_Get_Master"
915}
916
917#D-#==================================================
918#D-function IGCM_sys_Put_Rest
919#D-* Purpose: Put computied restarts on $(ARCHIVE).
920#D-           File and target directory must exist.
921#D-* Examples:
922#D-
923function IGCM_sys_Put_Rest {
924  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
925  if ( $DEBUG_sys ) ; then
926    echo "IGCM_sys_Put_Rest :" $@
927  fi
928  if [ $DRYRUN = 0 ]; then
929
930    IGCM_sys_TestDirArchive $( dirname $2 )
931
932    if [ ! -f ${1} ] ; then
933      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
934      IGCM_debug_Exit "IGCM_sys_Put_Rest"
935    fi
936    if [ X${JobType} = XRUN ] ; then
937      IGCM_sys_Chmod 444 ${1}
938    fi
939
940    typeset RET
941
942    echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
943    ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
944    RET=$?
945    IGCM_sys_Rsync_out $RET
946
947    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
948    (( RET=RET+$? ))
949
950    if [ ${RET} -gt 0 ] ; then
951      echo "IGCM_sys_Put_Rest : error."
952      cat out_rsync
953      IGCM_debug_Exit "IGCM_sys_Put_Rest"
954    else
955      \rm out_rsync
956    fi
957  else
958    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
959  fi
960  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
961}
962
963#D-#==================================================
964#D-function IGCM_sys_PutBuffer_Rest
965#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
966#D-           File and target directory must exist.
967#D-* Examples:
968#D-
969function IGCM_sys_PutBuffer_Rest {
970  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
971  if ( $DEBUG_sys ) ; then
972    echo "IGCM_sys_PutBuffer_Rest :" $@
973  fi
974  if [ $DRYRUN = 0 ]; then
975    if [ ! -f ${1} ] ; then
976      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
977      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
978    fi
979
980    typeset RET
981    #
982    if [ X${JobType} = XRUN ] ; then
983      IGCM_sys_Chmod 444 ${1}
984    fi
985
986    #
987    # USUAL WAY
988    \cp $1 $2 > out_rsync 2>&1
989    RET=$?
990
991    if [ ${RET} -gt 0 ] ; then
992      echo "IGCM_sys_PutBuffer_Rest : error."
993      cat out_rsync
994      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
995    else
996      \rm out_rsync
997    fi
998  else
999    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1000  fi
1001  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1002}
1003
1004#D-#==================================================
1005#D-function IGCM_sys_Put_Out
1006#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
1007#D-* Examples:
1008#D-
1009function IGCM_sys_Put_Out {
1010  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1011  if ( $DEBUG_sys ) ; then
1012    echo "IGCM_sys_Put_Out :" $@
1013  fi
1014  if [ $DRYRUN = 0 ]; then
1015    if [ -f ${1} ] ; then
1016      if [ ! -d $( dirname $2 ) ] ; then
1017        IGCM_sys_MkdirArchive $( dirname $2 )
1018      fi
1019    else
1020      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1021      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1022      return 1
1023    fi
1024
1025    typeset RET
1026        #
1027    if [ X${JobType} = XRUN ] ; then
1028      if [ X${3} = X ] ; then
1029        IGCM_sys_Chmod 444 ${1}
1030      fi
1031    fi
1032        #
1033
1034    echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
1035    ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
1036    RET=$?
1037    IGCM_sys_Rsync_out $RET
1038
1039    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1040    (( RET=RET+$? ))
1041
1042    if [ ${RET} -gt 0 ] ; then
1043      echo "IGCM_sys_Put_Out : error."
1044      cat out_rsync
1045      IGCM_debug_Exit "IGCM_sys_Put_Out"
1046    else
1047      \rm out_rsync
1048    fi
1049  else
1050    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1051  fi
1052  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1053  return 0
1054}
1055
1056#D-#==================================================
1057#D-function IGCM_sys_PutBuffer_Out
1058#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1059#D-* Examples:
1060#D-
1061function IGCM_sys_PutBuffer_Out {
1062  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1063  if ( $DEBUG_sys ) ; then
1064    echo "IGCM_sys_PutBuffer_Out :" $@
1065  fi
1066  if [ $DRYRUN = 0 ]; then
1067    if [ ! -f ${1} ] ; then
1068      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1069      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1070      return 1
1071    fi
1072    #
1073    IGCM_sys_Mkdir $( dirname $2 )
1074    #
1075    typeset RET
1076
1077    if [ X${JobType} = XRUN ] ; then
1078      if [ X${3} = X ] ; then
1079        IGCM_sys_Chmod 444 ${1}
1080      fi
1081    fi
1082    #
1083    # USUAL WAY
1084    \cp $1 $2 > out_rsync 2>&1
1085    RET=$?
1086
1087    if [ ${RET} -gt 0 ] ; then
1088      echo "IGCM_sys_PutBuffer_Out : error."
1089      cat out_rsync
1090      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1091    else
1092      \rm out_rsync
1093    fi
1094  else
1095    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1096  fi
1097  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1098  return 0
1099}
1100
1101#D-#==================================================
1102#D-function IGCM_sys_Get
1103#D-* Purpose: Get a file from ${ARCHIVE}
1104#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1105#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1106function IGCM_sys_Get {
1107  IGCM_debug_PushStack "IGCM_sys_Get" $@
1108
1109  typeset DEST RET dm_liste ifile target
1110
1111  if ( $DEBUG_sys ) ; then
1112    echo "IGCM_sys_Get :" $@
1113  fi
1114  if [ $DRYRUN -le 2 ]; then
1115    if [ X${1} = X'/l' ] ; then
1116            # test if the first file is present in the old computation :
1117      eval set +A dm_liste \${${2}}
1118    else
1119      dm_liste=${1}
1120    fi
1121    eval DEST=\${${#}}
1122
1123        # test if the (first) file is present in the old computation :
1124    IGCM_sys_TestFileArchive ${dm_liste[0]}
1125    RET=$?
1126    if [ ${RET} -gt 0 ] ; then
1127      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1128      IGCM_debug_Exit "IGCM_sys_Get"
1129            #return
1130    fi
1131
1132    (( RET=0 ))
1133    for target in ${dm_liste[*]} ; do
1134      \cp ${target} ${DEST} >> out_rsync 2>&1
1135      (( RET=RET+$? ))
1136    done
1137
1138#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
1139#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
1140#       RET=$?
1141#       IGCM_sys_Rsync_out $RET
1142
1143#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1144#       (( RET=RET+$? ))
1145
1146    if [ ${RET} -gt 0 ] ; then
1147      echo "IGCM_sys_Get : copy error."
1148      cat out_rsync
1149      IGCM_debug_Exit "IGCM_sys_Get"
1150    else
1151      \rm out_rsync
1152    fi
1153  else
1154    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1155  fi
1156  IGCM_debug_PopStack "IGCM_sys_Get"
1157}
1158
1159#D-#==================================================
1160#D-function IGCM_sys_GetBuffer
1161#D-* Purpose: Get a file from ${SCRATCHDIR}
1162#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1163#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1164function IGCM_sys_GetBuffer {
1165  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1166
1167  typeset DEST RET buf_liste ifile target file_work
1168
1169  if ( $DEBUG_sys ) ; then
1170    echo "IGCM_sys_GetBuffer :" $@
1171  fi
1172  if [ $DRYRUN -le 2 ]; then
1173    if [ X${1} = X'/l' ] ; then
1174      # test if the first file is present in the old computation :
1175      eval set +A buf_liste \${${2}}
1176    else
1177      eval set +A buf_liste ${1}
1178    fi
1179    eval DEST=\${${#}}
1180
1181    #USUAL WAY
1182    if [ X${1} = X'/l' ] ; then
1183      (( RET=0 ))
1184      for target in ${buf_liste[*]} ; do
1185        local_file=$( basename ${target} )
1186        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1187        (( RET = RET + $? ))
1188      done
1189    else
1190      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1191      RET=$?
1192    fi
1193
1194    if [ ${RET} -gt 0 ] ; then
1195      echo "IGCM_sys_GetBuffer : copy error."
1196      cat out_rsync
1197      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1198    else
1199      \rm out_rsync
1200    fi
1201  else
1202    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1203  fi
1204  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1205}
1206
1207#D-#==================================================
1208#D-function IGCM_sys_GetDate_FichWork
1209#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1210#D-* Examples:
1211#D-
1212function IGCM_sys_GetDate_FichWork {
1213  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1214  if ( $DEBUG_sys ) ; then
1215    echo "IGCM_sys_GetDate_FichWork :" $@
1216  fi
1217  typeset dateF
1218  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1219  eval ${2}=${dateF[5]}
1220
1221    # donne la date filesys d'un fichier sur la machine work
1222  IGCM_debug_PopStack "IGCM_sys_FichWork"
1223}
1224
1225#D-#==================================================
1226#D-function IGCM_sys_GetDate_FichArchive
1227#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1228#D-* Examples:
1229#D-
1230function IGCM_sys_GetDate_FichArchive {
1231  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1232  if ( $DEBUG_sys ) ; then
1233    echo "IGCM_sys_GetDate_FichArchive :" $@
1234  fi
1235  typeset dateF
1236  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1237  eval ${2}=${dateF[5]}
1238
1239  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1240}
1241
1242#D-#==================================================
1243#D-function IGCM_sys_Dods_Rm
1244#D-* Purpose: Suppress files in /tmp/DODS for simulation of internet protocole.
1245#D-* Examples:
1246#D-
1247function IGCM_sys_Dods_Rm {
1248  if ( $DEBUG_sys ) ; then
1249    echo "IGCM_sys_Dods_Rm :" $@
1250  fi
1251  return 0
1252}
1253
1254
1255#D-#==================================================
1256#D-function IGCM_sys_Dods_Cp
1257#D-* Purpose: Copy from $(ARCHIVE) files to /tmp/DODS for simulation of internet protocole.
1258#D-* Examples:
1259#D-
1260function IGCM_sys_Dods_Cp {
1261  if ( $DEBUG_sys ) ; then
1262    echo "IGCM_sys_Dods_Cp :" $@
1263  fi
1264  return 0
1265}
1266
1267#D-#==================================================
1268#D-function IGCM_sys_Put_Dods
1269#D-* Purpose: Put $(ARCHIVE) files on /tmp/DODS for simulation of internet protocole.
1270#D-* Examples:
1271#D-
1272function IGCM_sys_Put_Dods {
1273  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1274  if ( $DEBUG_sys ) ; then
1275    echo "IGCM_sys_Put_Dods :" $@
1276  fi
1277  if [ $DRYRUN = 0 ]; then
1278    RET=0
1279
1280    if [ ${RET} -gt 0 ] ; then
1281      echo "IGCM_sys_Put_Dods : error."
1282      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1283    fi
1284  else
1285    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1286  fi
1287  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1288}
1289
1290##############################################################
1291# REBUILD OPERATOR
1292
1293function IGCM_sys_rebuild {
1294  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1295  if ( $DEBUG_sys ) ; then
1296    echo "IGCM_sys_rebuild :" $@
1297  fi
1298  rebuild -f -o $@
1299  if [ $? -gt 0 ] ; then
1300    echo "IGCM_sys_rebuild : erreur ${@}."
1301    IGCM_debug_Exit "rebuild"
1302  fi
1303
1304  IGCM_debug_PopStack "IGCM_sys_rebuild"
1305}
1306
1307############################################################
1308# Activate Running Environnment Variables
1309
1310function IGCM_sys_activ_variables {
1311  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1312  if ( $DEBUG_sys ) ; then
1313    echo "IGCM_sys_activ_variables"
1314  fi
1315  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1316}
1317
1318############################################################
1319# Desactivate Running Environnment Variables
1320
1321function IGCM_sys_desactiv_variables {
1322  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1323  if ( $DEBUG_sys ) ; then
1324    echo "IGCM_sys_desactiv_variables"
1325  fi
1326  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1327}
1328
1329############################################################
1330# Build run file
1331
1332function IGCM_sys_build_run_file {
1333
1334  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1335
1336}
1337
1338############################################################
1339# Build MPI/OMP scripts
1340function IGCM_sys_build_execution_scripts
1341{
1342  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1343  if ( $DEBUG_sys ) ; then
1344    echo "IGCM_sys_build_execution_scripts " $@
1345  fi
1346  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1347  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1348  typeset num_corempi nombre_restant_node nombre_restant_comp
1349
1350  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1351    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1352  fi
1353
1354  if ( ${OK_PARA_MPMD} ) ; then
1355
1356    if [ -f run_file ] ; then
1357      IGCM_sys_Rm -f run_file
1358    fi
1359    touch run_file
1360
1361    if ( ${OK_PARA_OMP} ) ; then
1362
1363      #  Hosts treatment
1364
1365      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1366
1367      i=0
1368      rm -f hosts
1369      IGCM_debug_Print 1 "sys $( hostname ), Hosts avaible :"
1370      for nodes in `cat hosts.tmp` ; do
1371        host[$i]=$nodes
1372        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1373        IGCM_debug_Print 1 ${host[$i]}
1374        i=$((i+1))
1375      done
1376      rm -f hosts.tmp
1377
1378      listnodes=${host[*]}
1379
1380      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1381
1382      # Initialisation
1383
1384      init_node=y
1385      node_num_current=0
1386      start_num=0
1387      init_exec=n
1388
1389      # Test : if oasis is there, we put it at the first position
1390
1391      for comp in ${config_ListOfComponents[*]} ; do
1392
1393        if [ "X${comp}" = "XCPL" ]  ; then
1394
1395          eval ExeNameIn=\${config_Executable_${comp}[0]}
1396          eval ExeNameOut=\${config_Executable_${comp}[1]}
1397
1398          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1399          echo ""  >> script_${ExeNameOut}.ksh
1400          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1401          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1402          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1403          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1404          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1405
1406          init_node=n
1407
1408          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1409          node_num_current=0
1410          node_current=${host[${node_num_current}]}
1411
1412          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1413
1414          init_exec=y
1415          start_num=1
1416
1417        fi
1418
1419      done
1420
1421      # Then loop on the components (except for oasis)
1422
1423      for comp in ${config_ListOfComponents[*]} ; do
1424
1425        eval ExeNameIn=\${config_Executable_${comp}[0]}
1426        eval ExeNameOut=\${config_Executable_${comp}[1]}
1427
1428        # Only if we really have an executable for the component :
1429        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1430
1431          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1432          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1433
1434          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1435          # echo "set -vx" >> script_${ExeNameOut}.ksh
1436          echo ""  >> script_${ExeNameOut}.ksh
1437          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1438          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1439          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1440          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1441          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1442          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1443          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1444
1445          node_num=0
1446
1447          # We define the number of MPI process to be assigned for the component
1448
1449          nombre_restant_comp=${comp_proc_mpi_loc}
1450
1451          # Loop on the allocated nodes
1452
1453          for node in ${listnodes} ; do
1454
1455            # We go to the current node
1456            if [ ${node_num} = ${node_num_current} ] ; then
1457
1458              node_current=${host[${node_num_current}]}
1459
1460              # If first time on the node : initialisation
1461
1462              if [ ${init_node} = y ] ; then
1463                nombre_restant_node=${NUM_COREPERNODE}
1464              fi
1465
1466              # Test on the number of OMP threads
1467
1468              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1469                (( node_num = node_num + 1 ))
1470                node_num_current=${node_num}
1471                init_node=y
1472                continue
1473              fi
1474
1475              # Number of MPI process to assign
1476
1477              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1478
1479              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1480                num_corempi=${nombre_restant_comp}
1481              fi
1482
1483              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1484              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1485
1486              if [ ${init_exec} = y ] ; then
1487                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1488              else
1489                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1490                init_exec=y
1491              fi
1492
1493              ((  start_num = num_corempi + start_num ))
1494
1495            else
1496
1497              (( node_num = node_num + 1 ))
1498              continue
1499            fi
1500
1501            # Test on the number of core/process remaining on the node/component
1502
1503            if [ ${nombre_restant_node} = 0 ] ; then
1504              (( node_num = node_num + 1 ))
1505              node_num_current=${node_num}
1506              init_node=y
1507
1508              if [ ${nombre_restant_comp} = 0 ] ; then
1509                break 1
1510              fi
1511            else
1512
1513              node_num_current=${node_num}
1514              init_node=n
1515
1516              if [ ${nombre_restant_comp} = 0 ] ; then
1517                break 1
1518              fi
1519            fi
1520          done
1521        fi
1522      done
1523
1524    else
1525
1526      # Then first loop on the components for the coupler ie oasis
1527
1528      ## the coupler ie oasis must be the first one
1529      for comp in ${config_ListOfComponents[*]} ; do
1530
1531        eval ExeNameOut=\${config_Executable_${comp}[1]}
1532
1533        # for CPL component only
1534        if [ "X${comp}" = "XCPL" ] ; then
1535          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1536          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1537        fi
1538      done
1539
1540      # Then second loop on the components
1541
1542      for comp in ${config_ListOfComponents[*]} ; do
1543
1544        eval ExeNameOut=\${config_Executable_${comp}[1]}
1545
1546        # Only if we really have an executable for the component and not the coupler ie oasis:
1547        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1548          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1549          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1550        fi
1551      done
1552      IGCM_sys_Chmod u+x run_file
1553
1554      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1555
1556    fi
1557
1558  else # Only one executable. launch it.
1559
1560    for comp in ${config_ListOfComponents[*]} ; do
1561
1562      # Only if we really have an executable for the component :
1563      eval ExeNameOut=\${config_Executable_${comp}[1]}
1564      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1565
1566        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1567        echo ""  >> script_${ExeNameOut}.ksh
1568        if ( ${OK_PARA_OMP} ) ; then
1569          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1570          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1571        fi
1572        if  ( ${OK_PARA_MPI} ) ; then
1573          # Default : mpirun used if nb_proc gt 1
1574          # pour sortie out/err par process
1575          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1576          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1577          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1578          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1579        else
1580          # Default : mpirun is NOT used if nb_proc eq 1
1581          # pour sortie out/err par process
1582          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1583          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1584          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1585          EXECUTION="time ./script_${ExeNameOut}.ksh"
1586        fi
1587      fi
1588    done
1589
1590  fi
1591
1592  IGCM_debug_Print 1 "sys $( hostname ) : La commande d execution est "
1593  IGCM_debug_Print 1 $EXECUTION
1594
1595  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1596}
1597
1598############################################################
1599# Check of space available on temporary filesytems
1600function IGCM_sys_check_quota {
1601  IGCM_debug_PushStack "IGCM_sys_check_quota"
1602  if ( $DEBUG_sys ) ; then
1603    echo "IGCM_sys_check_quota"
1604  fi
1605  IGCM_debug_PopStack "IGCM_sys_check_quota"
1606}
1607
1608##############################################################
1609# NCO OPERATOR
1610
1611function IGCM_sys_ncap2 {
1612  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1613  if ( $DEBUG_sys ) ; then
1614    echo "IGCM_sys_ncap2 :" $@
1615  fi
1616  /usr/local/bin/ncap2 "$@"
1617  if [ $? -gt 0 ] ; then
1618    echo "IGCM_sys_ncap2 : erreur ${@}."
1619    IGCM_debug_Exit "ncap2"
1620  fi
1621
1622  IGCM_debug_PopStack "IGCM_sys_ncap2"
1623}
1624
1625function IGCM_sys_ncatted {
1626  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1627  if ( $DEBUG_sys ) ; then
1628    echo "IGCM_sys_ncatted :" $@
1629  fi
1630  /usr/local/bin/ncatted "$@"
1631  if [ $? -gt 0 ] ; then
1632    echo "IGCM_sys_ncatted : erreur ${@}."
1633    IGCM_debug_Exit "ncatted"
1634  fi
1635
1636  IGCM_debug_PopStack "IGCM_sys_ncatted"
1637}
1638
1639function IGCM_sys_ncbo {
1640  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1641  if ( $DEBUG_sys ) ; then
1642    echo "IGCM_sys_ncbo :" $@
1643  fi
1644  /usr/local/bin/ncbo $@
1645  if [ $? -gt 0 ] ; then
1646    echo "IGCM_sys_ncbo : erreur ${@}."
1647    IGCM_debug_Exit "ncbo"
1648  fi
1649
1650  IGCM_debug_PopStack "IGCM_sys_ncbo"
1651}
1652
1653function IGCM_sys_ncdiff {
1654  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1655  if ( $DEBUG_sys ) ; then
1656    echo "IGCM_sys_ncdiff :" $@
1657  fi
1658  /usr/local/bin/ncdiff $@
1659  if [ $? -gt 0 ] ; then
1660    echo "IGCM_sys_ncdiff : erreur ${@}."
1661    IGCM_debug_Exit "ncdiff"
1662  fi
1663
1664  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1665}
1666
1667function IGCM_sys_ncea {
1668  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1669  if ( $DEBUG_sys ) ; then
1670    echo "IGCM_sys_ncea :" $@
1671  fi
1672  /usr/local/bin/ncea $@
1673  if [ $? -gt 0 ] ; then
1674    echo "IGCM_sys_ncea : erreur ${@}."
1675    IGCM_debug_Exit "ncea"
1676  fi
1677
1678  IGCM_debug_PopStack "IGCM_sys_ncea"
1679}
1680
1681function IGCM_sys_ncecat {
1682  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1683  if ( $DEBUG_sys ) ; then
1684    echo "IGCM_sys_ncecat :" $@
1685  fi
1686  /usr/local/bin/ncecat $@
1687  if [ $? -gt 0 ] ; then
1688    echo "IGCM_sys_ncecat : erreur ${@}."
1689    IGCM_debug_Exit "ncecat"
1690  fi
1691
1692  IGCM_debug_PopStack "IGCM_sys_ncecat"
1693}
1694
1695function IGCM_sys_ncflint {
1696  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1697  if ( $DEBUG_sys ) ; then
1698    echo "IGCM_sys_ncflint :" $@
1699  fi
1700  /usr/local/bin/ncflint $@
1701  if [ $? -gt 0 ] ; then
1702    echo "IGCM_sys_ncflint : erreur ${@}."
1703    IGCM_debug_Exit "ncflint"
1704  fi
1705
1706  IGCM_debug_PopStack "IGCM_sys_ncflint"
1707}
1708
1709function IGCM_sys_ncks {
1710  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1711  if ( $DEBUG_sys ) ; then
1712    echo "IGCM_sys_ncks :" $@
1713  fi
1714  /usr/local/bin/ncks $@
1715  if [ $? -gt 0 ] ; then
1716    echo "IGCM_sys_ncks : erreur ${@}."
1717    IGCM_debug_Exit "ncks"
1718  fi
1719
1720  IGCM_debug_PopStack "IGCM_sys_ncks"
1721}
1722
1723function IGCM_sys_ncpdq {
1724  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1725  if ( $DEBUG_sys ) ; then
1726    echo "IGCM_sys_ncpdq :" $@
1727  fi
1728  /usr/local/bin/ncpdq $@
1729  if [ $? -gt 0 ] ; then
1730    echo "IGCM_sys_ncpdq : erreur ${@}."
1731    IGCM_debug_Exit "ncpdq"
1732  fi
1733
1734  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1735}
1736
1737function IGCM_sys_ncra {
1738  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1739  if ( $DEBUG_sys ) ; then
1740    echo "IGCM_sys_ncra :" $@
1741  fi
1742  /usr/local/bin/ncra $@
1743  if [ $? -gt 0 ] ; then
1744    echo "IGCM_sys_ncra : erreur ${@}."
1745    IGCM_debug_Exit "ncra"
1746  fi
1747
1748  IGCM_debug_PopStack "IGCM_sys_ncra"
1749}
1750
1751function IGCM_sys_ncrcat {
1752  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1753  if ( $DEBUG_sys ) ; then
1754    echo "IGCM_sys_ncrcat :" $@
1755  fi
1756  /usr/local/bin/ncrcat $@
1757  if [ $? -gt 0 ] ; then
1758    echo "IGCM_sys_ncrcat : erreur ${@}."
1759#       IGCM_debug_Exit "ncrcat"
1760  fi
1761
1762  IGCM_debug_PopStack "IGCM_sys_ncrcat"
1763}
1764
1765function IGCM_sys_ncrename {
1766  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1767  if ( $DEBUG_sys ) ; then
1768    echo "IGCM_sys_ncrename :" $@
1769  fi
1770  /usr/local/bin/ncrename $@
1771  if [ $? -gt 0 ] ; then
1772    echo "IGCM_sys_ncrename : erreur ${@}."
1773    IGCM_debug_Exit "ncrename"
1774  fi
1775
1776  IGCM_debug_PopStack "IGCM_sys_ncrename"
1777}
1778
1779function IGCM_sys_ncwa {
1780  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1781  if ( $DEBUG_sys ) ; then
1782    echo "IGCM_sys_ncwa :" $@
1783  fi
1784  /usr/local/bin/ncwa $@
1785  if [ $? -gt 0 ] ; then
1786    echo "IGCM_sys_ncwa : erreur ${@}."
1787    IGCM_debug_Exit "ncwa"
1788  fi
1789
1790  IGCM_debug_PopStack "IGCM_sys_ncwa"
1791}
1792
1793##############################################################
1794# CDO OPERATOR
1795
1796function IGCM_sys_cdo {
1797  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
1798
1799  \cdo $@
1800  if [ $? -gt 0 ] ; then
1801    echo "IGCM_sys_cdo : erreur ${@}."
1802    IGCM_debug_PopStack "IGCM_sys_cdo"
1803    return 1
1804  else
1805    IGCM_debug_PopStack "IGCM_sys_cdo"
1806    return 0
1807  fi
1808
1809  IGCM_debug_PopStack "IGCM_sys_cdo"
1810}
Note: See TracBrowser for help on using the repository browser.