source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh @ 657

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