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