source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_titane.ksh @ 640

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

Add norerun option on SX front-end. Transfer specific files ie config.card COMP ... with IGCM_sys_Get_Master and modify IGCM_sys_Get_Master to allow file transfer. tested on ulam and SX front-end.

  • Property svn:keywords set to Revision Author Date
File size: 61.0 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.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 Titane
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=titane
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# rsync with path
78typeset -r RSYNC=/usr/bin/rsync
79# RSYNC_opt args to rsync
80typeset -r RSYNC_opt="-va"
81# ie storage filesystem
82typeset -r STOREHOST=${MASTER}
83
84#====================================================
85# Source default environment
86#====================================================
87. /etc/profile
88
89#====================================================
90# Set environment tools (ferret, nco, cdo)
91#====================================================
92. /home/cont003/p86ipsl/.atlas_env_titane_ksh
93if [ X${LSB_QUEUE} = Xmono ] ; then
94  module switch nco/3.9.4 nco/3.9.4_netcdf4
95fi
96
97#====================================================
98# Specific for ocean additionnal diagnostic
99export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
100export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
101
102#====================================================
103# Host specific DIRECTORIES
104#====================================================
105
106# ============ CESIUM START ============ #
107
108#====================================================
109#- Mirror libIGCM from titane to cesium if needed
110#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
111#if [ ! ${ROOTSYS} = "home" ] ; then
112#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
113#else
114#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
115#fi
116
117#====================================================
118#- libIGCM_POST
119#if ( ${MirrorlibIGCM} ) ; then
120#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
121#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
122#else
123#  typeset -r libIGCM_POST=${libIGCM}
124#fi
125
126# ============ CESIUM  END  ============ #
127
128#====================================================
129#- MirrorlibIGCM for frontend
130typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
131
132#====================================================
133#- libIGCM_POST for frontend
134typeset -r libIGCM_POST=${libIGCM}
135
136#====================================================
137#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
138typeset -r R_EXE="${MODIPSL}/bin"
139
140#====================================================
141#- SUBMIT_DIR : submission dir
142typeset SUBMIT_DIR=${SUBMIT_DIR:=${LS_SUBCWD}}
143
144#====================================================
145#- ARCHIVE (dedicated to large files)
146typeset -r ARCHIVE=${CCCSTOREDIR}
147
148#- ARCHIVE (dedicated to small/medium files)
149typeset -r STORAGE=${CCCWORKDIR}
150
151#====================================================
152#- IN
153typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
154typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
155
156#====================================================
157#- R_OUT
158typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
159
160#====================================================
161#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
162typeset -r R_FIG=${STORAGE}/IGCM_OUT
163
164#====================================================
165#- R_BUF (ONLY FOR double copy an scratch)
166typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
167
168#====================================================
169#- BIG_DIR : BIG_DIR to store files waiting for rebuild
170typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
171
172#====================================================
173#- OUT_POST
174typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
175
176#====================================================
177#- RUN_DIR_PATH : Temporary working directory (=> TMP)
178if [ ! X${LSB_QUEUE} = Xmono ] ; then
179  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${LSB_JOBID}}
180else
181  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/TMPDIR_IGCM/${LSB_JOBID}}
182fi
183
184#====================================================
185#- HOST_MPIRUN_COMMAND
186typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
187
188#====================================================
189#- Max number of arguments passed to nco operator or demigration command
190UNIX_MAX_LIMIT=360
191
192#====================================================
193#- set PackDefault true on titane
194PackDefault=true
195
196NUM_COREPERNODE=8
197
198#====================================================
199#- Default number of MPI task for IPSL coupled model
200#- required for backward compatibility
201#-
202DEFAULT_NUM_PROC_OCE=5
203DEFAULT_NUM_PROC_CPL=1
204(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
205DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
206
207
208#D-#==================================================
209#D-function IGCM_sys_RshMaster
210#D-* Purpose: Connection to frontend machine.
211#D-* Examples:
212#D-
213function IGCM_sys_RshMaster {
214  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
215  /bin/ksh <<-EOF
216    export libIGCM=${libIGCM}
217    export DEBUG_debug=${DEBUG_debug}
218    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
219    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
220    ${@}
221EOF
222  if [ $? -gt 0 ] ; then
223    echo "IGCM_sys_RshMaster : erreur."
224    IGCM_debug_Exit "IGCM_sys_RshMaster"
225  fi
226  IGCM_debug_PopStack "IGCM_sys_RshMaster"
227}
228
229#D-#==================================================
230#D-function IGCM_sys_RshArchive
231#D-* Purpose: Archive rsh command
232#D-* Examples:
233#D-
234function IGCM_sys_RshArchive {
235  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
236  /bin/ksh <<-EOF
237    ${@}
238EOF
239  if [ $? -gt 0 ] ; then
240    echo "IGCM_sys_RshArchive : erreur."
241    IGCM_debug_Exit "IGCM_sys_RshArchive"
242  fi
243  IGCM_debug_PopStack "IGCM_sys_RshArchive"
244}
245
246#D-#==================================================
247#D-function IGCM_sys_RshPost
248#D-* Purpose: Post-process rsh command
249#D-* Examples:
250#D-
251function IGCM_sys_RshPost {
252  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
253  if ( $DEBUG_sys ) ; then
254    echo "IGCM_sys_RshPost :" $@
255  fi
256
257  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
258  #cat tmp_IGCM_sys_RshPost_$$
259  # keep standard input (stdin) for the loop onto temporary file
260  cat >tmp_IGCM_sys_RshPost_$$
261
262# ============ FRONTEND START ============ #
263
264  /bin/ksh <tmp_IGCM_sys_RshPost_$$
265  if [ $? -gt 0 ] ; then
266    echo "IGCM_sys_RshPost : erreur."
267    IGCM_debug_Exit "IGCM_sys_RshPost"
268  fi
269  # delete temporary file
270  \rm tmp_IGCM_sys_RshPost_$$
271
272# ============ FRONTEND  END  ============ #
273
274# ============ CESIUM START ============ #
275#  typeset NB_ESSAI DELAI status i
276#  if [ "X$( grep rebuild_from tmp_IGCM_sys_RshPost_$$ )" != "X" ] ; then
277#    #little hack so that rebuild submission is done on titane not an cesium
278#
279#    libIGCM_POST_sed=$( echo $libIGCM_POST | sed 's/\//\\\//g' )
280#    POST_DIR_sed=$( echo ${POST_DIR} | sed 's/\//\\\//g' )
281#    sed "s/IGCM_sys_QsubPost/IGCM_sys_Qsub/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
282#    sed "s/ rebuild_fromWorkdir/ ${libIGCM_POST_sed}\/rebuild_fromWorkdir.job/g" tmp.txt > tmp_IGCM_sys_RshPost_$$
283#    sed "s/ rebuild_fromArchive/ ${libIGCM_POST_sed}\/rebuild_fromArchive.job/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
284#    sed "s/Script_Post_Output=/Script_Output=${POST_DIR_sed}\//g" tmp.txt > tmp_IGCM_sys_RshPost_$$
285#    \mv tmp.txt tmp_IGCM_sys_RshPost_$$
286#
287#    echo cat tmp_IGCM_sys_RshPost_$$ AFTER
288#    cat tmp_IGCM_sys_RshPost_$$
289#
290#    /bin/ksh <tmp_IGCM_sys_RshPost_$$
291#    if [ $? -gt 0 ] ; then
292#      echo "IGCM_sys_RshPost : erreur."
293#      IGCM_debug_Exit "IGCM_sys_RshPost"
294#    fi
295#    # delete temporary file
296#    \rm tmp_IGCM_sys_RshPost_$$
297#
298#  else
299#    # number of tentative
300#    NB_ESSAI=10
301#    # time delay between tentative
302#    DELAI=10
303#    i=0
304#    while [ $i -ne $NB_ESSAI ] ; do
305#      ssh -t titane996 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
306#      status=$?
307#      if [ ${status} -ne 0 ];
308#      then
309#       sleep $DELAI
310#      else
311#       break
312#      fi
313#      let i=$i+1
314#    done
315#    # delete temporary file
316#    \rm tmp_IGCM_sys_RshPost_$$
317#
318#    if [ ${status} -gt 0 ] ; then
319#      echo "IGCM_sys_RshPost : erreur."
320#      IGCM_debug_Exit "IGCM_sys_RshPost"
321#    fi
322#  fi
323
324# ============ CESIUM  END  ============ #
325
326  IGCM_debug_PopStack "IGCM_sys_RshPost"
327}
328
329#D-#==================================================
330#D-function IGCM_sys_SendMail
331#D-* Purpose: Send mail when simulation is over
332#D-* Examples:
333#D-
334function IGCM_sys_SendMail {
335  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
336  if ( $DEBUG_sys ) ; then
337    echo "IGCM_sys_SendMail :" $@
338  fi
339
340  if ( ${ExitFlag} ) ; then
341    status=failed
342  else
343    status=completed
344  fi
345
346    cat  << END_MAIL > job_end.mail
347Dear ${LOGIN},
348
349  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
350  Job started : ${DateBegin}
351  Job ended   : ${DateEnd}
352  Output files are available in ${R_SAVE}
353  Files to be rebuild are temporarily available in ${REBUILD_DIR}
354  Pre-packed files are temporarily available in ${R_BUFR}
355  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
356END_MAIL
357
358    if [ ! -z ${config_UserChoices_MailName} ] ; then
359        mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < job_end.mail
360    elif [ -f ~/.forward ] ; then
361        mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
362    fi
363    sleep 10
364    rm -f job_end.mail
365
366  if [ $? -gt 0 ] ; then
367    echo "IGCM_sys_SendMail : erreur."
368    IGCM_debug_Exit "IGCM_sys_SendMail"
369  fi
370  IGCM_debug_PopStack "IGCM_sys_SendMail"
371}
372
373#D-#==================================================
374#D-function IGCM_sys_Mkdir
375#D-* Purpose: Master locale mkdir command
376#D-* Examples:
377#D-
378function IGCM_sys_Mkdir {
379  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
380  if ( $DEBUG_sys ) ; then
381    echo "IGCM_sys_Mkdir :" $@
382  fi
383  if [ ! -d ${1} ]; then
384    \mkdir -p $1
385    if [ $? -gt 0 ] ; then
386      echo "IGCM_sys_Mkdir : erreur."
387      IGCM_debug_Exit "IGCM_sys_Mkdir"
388    fi
389  fi
390  # vérification :
391  if [ ! -d ${1} ] ; then
392    echo "IGCM_sys_Mkdir : erreur."
393    IGCM_debug_Exit "IGCM_sys_Mkdir"
394  fi
395  IGCM_debug_PopStack "IGCM_sys_Mkdir"
396}
397
398#D-#==================================================
399#D-function IGCM_sys_MkdirArchive
400#D-* Purpose: Mkdir on Archive
401#D-* Examples:
402#D-
403function IGCM_sys_MkdirArchive {
404  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
405  if ( $DEBUG_sys ) ; then
406    echo "IGCM_sys_MkdirArchive :" $@
407  fi
408  #- creation de repertoire sur le serveur fichier
409  if [ ! -d ${1} ]; then
410    \mkdir -p $1
411    if [ $? -gt 0 ] ; then
412      echo "IGCM_sys_MkdirArchive : erreur."
413      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
414    fi
415  fi
416  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
417}
418
419#D-#==================================================
420#D-function IGCM_sys_MkdirWork
421#D-* Purpose: Mkdir on Work
422#D-* Examples:
423#D-
424function IGCM_sys_MkdirWork {
425  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
426  if ( $DEBUG_sys ) ; then
427    echo "IGCM_sys_MkdirWork :" $@
428  fi
429  #- creation de repertoire sur le serveur fichier
430  if [ ! -d ${1} ]; then
431    \mkdir -p $1
432    if [ $? -gt 0 ] ; then
433      echo "IGCM_sys_MkdirWork : erreur."
434      IGCM_debug_Exit "IGCM_sys_MkdirWork"
435    fi
436  fi
437  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
438}
439
440#D-#==================================================
441#D-function IGCM_sys_Cd
442#D-* Purpose: master cd command
443#D-* Examples:
444#D-
445function IGCM_sys_Cd {
446  IGCM_debug_PushStack "IGCM_sys_Cd" $@
447  if ( $DEBUG_sys ) ; then
448    echo "IGCM_sys_Cd :" $@
449  fi
450  \cd $1
451  if [ $? -gt 0 ] ; then
452    echo "IGCM_sys_Cd : erreur."
453    IGCM_debug_Exit "IGCM_sys_Cd"
454  fi
455  IGCM_debug_PopStack "IGCM_sys_Cd"
456}
457
458#D-#==================================================
459#D-function IGCM_sys_Chmod
460#D-* Purpose: Chmod
461#D-* Examples:
462#D-
463function IGCM_sys_Chmod {
464  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
465  if ( $DEBUG_sys ) ; then
466    echo "IGCM_sys_Chmod :" $@
467  fi
468  if [ $DRYRUN -le 1 ]; then
469    \chmod $@
470    if [ $? -gt 0 ] ; then
471      echo "IGCM_sys_Chmod : erreur."
472      IGCM_debug_Exit "IGCM_sys_Chmod"
473    fi
474  else
475    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
476  fi
477  IGCM_debug_PopStack "IGCM_sys_Chmod"
478}
479
480#D-#==================================================
481#D-function IGCM_sys_FileSize
482#D-* Purpose: Filesize
483#D-* Examples:
484#D-
485function IGCM_sys_FileSize {
486  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
487
488  typeset sizeF
489  set +A sizeF -- $( ls -la ${1} )
490  if [ $? -gt 0 ] ; then
491    IGCM_debug_Exit "IGCM_sys_FileSize"
492  fi
493  eval ${2}=${sizeF[4]}
494
495  IGCM_debug_PopStack "IGCM_sys_FileSize"
496}
497
498#D-#==================================================
499#D-function IGCM_sys_TestDir
500#D-* Purpose: Test Directory that must exists
501#D-* Examples:
502#D-
503function IGCM_sys_TestDir {
504  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
505  if ( $DEBUG_sys ) ; then
506    echo "IGCM_sys_TestDir :" $@
507  fi
508  typeset ExistFlag
509  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
510  IGCM_debug_PopStack "IGCM_sys_TestDir"
511
512  return ${ExistFlag}
513}
514
515#D-#==================================================
516#D-function IGCM_sys_TestDirArchive
517#D-* Purpose: Test Directory that must exists on Archive
518#D-* Examples:
519#D-
520function IGCM_sys_TestDirArchive {
521  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
522  if ( $DEBUG_sys ) ; then
523    echo "IGCM_sys_TestDirArchive :" $@
524  fi
525  typeset ExistFlag
526  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
527  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
528
529  return ${ExistFlag}
530}
531
532#D-#==================================================
533#D-function IGCM_sys_IsFileArchived
534#D-* Purpose: Test file that must NOT EXISTS on Archive
535#D-* Examples:
536#D-
537function IGCM_sys_IsFileArchived {
538  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
539  if ( $DEBUG_sys ) ; then
540    echo "IGCM_sys_IsFileArchived :" $@
541  fi
542  typeset IsArchivedFlag
543  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
544  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
545
546  return ${IsArchivedFlag}
547}
548
549#D-#==================================================
550#D-function IGCM_sys_TestFileArchive
551#D-* Purpose: Test file that must NOT EXISTS on Archive
552#D-* Examples:
553#D-
554function IGCM_sys_TestFileArchive {
555  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
556  if ( $DEBUG_sys ) ; then
557    echo "IGCM_sys_TestFileArchive :" $@
558  fi
559  typeset ExistFlag
560  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
561  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
562
563  return ${ExistFlag}
564}
565
566#D-#==================================================
567#D-function IGCM_sys_TestFileBuffer
568#D-* Purpose: Test file that must NOT EXISTS on Buffer
569#D-* Examples:
570#D-
571function IGCM_sys_TestFileBuffer {
572  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
573  typeset ExistFlag
574  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
575  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
576
577  return ${ExistFlag}
578}
579
580#D-#==================================================
581#D-function IGCM_sys_CountFileArchive
582#D-* Purpose: Count files on Archive filesystem
583#D-* Examples:
584#D-
585function IGCM_sys_CountFileArchive {
586  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
587  ls ${@} 2>/dev/null | wc -l
588  if [ $? -gt 0 ] ; then
589    echo "IGCM_sys_CountFileArchive : erreur."
590  fi
591  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
592}
593
594#D-#==================================================
595#D-function IGCM_sys_CountFileBuffer
596#D-* Purpose: Count files on Scratch filesystem
597#D-* Examples:
598#D-
599function IGCM_sys_CountFileBuffer {
600  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
601  ls ${@} 2>/dev/null | wc -l
602  if [ $? -gt 0 ] ; then
603    echo "IGCM_sys_CountFileBuffer : erreur."
604  fi
605  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
606}
607
608#D-#==================================================
609#D-function IGCM_sys_Tree
610#D-* Purpose: Tree directories with files on ${ARCHIVE}
611#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
612#D-
613function IGCM_sys_Tree {
614  IGCM_debug_PushStack "IGCM_sys_Tree" $@
615  if ( $DEBUG_sys ) ; then
616    echo "IGCM_sys_Tree :" $@
617  fi
618
619  \ls -lR ${@}
620
621  IGCM_debug_PopStack "IGCM_sys_Tree"
622}
623
624#D-#==================================================
625#D-function IGCM_sys_Tar
626#D-* Purpose: master tar command
627#D-* Examples:
628#D-
629function IGCM_sys_Tar {
630  IGCM_debug_PushStack "IGCM_sys_Tar" $@
631  if ( $DEBUG_sys ) ; then
632    echo "IGCM_sys_Tar :" $@
633  fi
634  \tar cf $@
635  if [ $? -gt 0 ] ; then
636    echo "IGCM_sys_Tar : erreur."
637    IGCM_debug_Exit "IGCM_sys_Tar"
638  fi
639  IGCM_debug_PopStack "IGCM_sys_Tar"
640}
641
642#D-#==================================================
643#D-function IGCM_sys_UnTar
644#D-* Purpose: master un-tar command
645#D-* Examples:
646#D-
647function IGCM_sys_UnTar {
648  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
649  if ( $DEBUG_sys ) ; then
650    echo "IGCM_sys_UnTar :" $@
651  fi
652  \tar xvf $1
653  if [ $? -gt 0 ] ; then
654    echo "IGCM_sys_UnTar : erreur."
655    IGCM_debug_Exit "IGCM_sys_UnTar"
656  fi
657  IGCM_debug_PopStack "IGCM_sys_UnTar"
658}
659
660#D-#==================================================
661#D-function IGCM_sys_Qsub
662#D-* Purpose: Qsub new job
663#D-* Examples:
664#D-
665function IGCM_sys_Qsub {
666  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
667  if ( $DEBUG_sys ) ; then
668    echo "IGCM_sys_Qsub :" $@
669  fi
670  typeset options
671  if [ ${config_UserChoices_JobName}.${CumulPeriod} = "." ] ; then
672    options=" -o ${Script_Output} -e ${Script_Output}"
673  else
674    options=" -o ${Script_Output} -e ${Script_Output} -r ${config_UserChoices_JobName}.${CumulPeriod}"
675  fi
676
677  /usr/local/bin/ccc_msub ${options} < $1
678  if [ $? -gt 0 ] ; then
679    echo "IGCM_sys_Qsub : erreur ${options} $1"
680    IGCM_debug_Exit "IGCM_sys_Qsub"
681  fi
682  IGCM_debug_PopStack "IGCM_sys_Qsub"
683}
684
685#D-#==================================================
686#D-function IGCM_sys_QsubPost
687#D-* Purpose: Qsub new job on scalaire
688#D-* Examples:
689#D-
690function IGCM_sys_QsubPost {
691  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
692  if ( $DEBUG_sys ) ; then
693    echo "IGCM_sys_QsubPost :" $@
694  fi
695
696  # Need to export listVarEnv for cesium
697  # NO Need to export listVarEnv for titane
698# ============ FRONTEND START ============ #
699
700  /usr/local/bin/ccc_msub -p ${BRIDGE_MSUB_PROJECT} -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out ${libIGCM_POST}/$1.job
701
702# ============ FRONTEND  END  ============ #
703
704# ============ CESIUM START ============ #
705#  typeset NB_ESSAI DELAI status i
706#  # number of tentative
707#  NB_ESSAI=10
708#  # time delay between tentative
709#  DELAI=10
710#  (( i = 0 ))
711#  while [ $i -lt $NB_ESSAI ] ; do
712#    /usr/local/bin/ccc_msub -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.e.out -E "-v ${listVarEnv}" ${libIGCM_POST}/$1.job
713#    status=$?
714#    if [ ${status} -gt 0 ]; then
715#      sleep $DELAI
716#    else
717#      break
718#    fi
719#    (( i = i + 1 ))
720#  done
721# ============ CESIUM  END  ============ #
722
723  if [ $? -gt 0 ] ; then
724    echo "IGCM_sys_QsubPost : erreur " $@
725    IGCM_debug_Exit "IGCM_sys_QsubPost"
726  fi
727  IGCM_debug_PopStack "IGCM_sys_QsubPost"
728}
729
730#D-*************************
731#D- File transfer functions
732#D-*************************
733#D-
734
735#D-#==================================================
736#D-function IGCM_sys_Rsync_out
737#D-* Purpose: treat return val of rsync
738#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
739#D-  Error values and explanations can depend on your system version.
740function IGCM_sys_Rsync_out {
741  RET=$1
742  if [ ! $RET ] ; then
743    echo "rsync error !"
744  fi
745
746  if [ $MYLANG = "fr" ]; then
747    case $RET in
748    0)  return ;;
749    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
750      echo "Erreur de syntaxe ou d'utilisation."
751      return;;
752    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
753      echo "Incompatibilité de protocole."
754      return;;
755    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
756      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
757      echo "répertoires"
758      return;;
759    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
760      echo "Action demandée non supportée : une tentative de manipulation de"
761      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
762      echo "été faite ; ou une option qui est supportée par le  client  mais"
763      echo "pas par le serveur a été spécifiée."
764      return;;
765    10) echo "Erreur de rsync ; RERR_SOCKETIO"
766      echo "Erreur dans le socket d'entrée sortie"
767      return;;
768    11) echo "Erreur de rsync ; RERR_FILEIO"
769      echo "Erreur d'entrée sortie fichier"
770      return;;
771    12) echo "Erreur de rsync ; RERR_STREAMIO"
772      echo "Erreur dans flux de donnée du protocole rsync"
773      return;;
774    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
775      echo "Erreur avec les diagnostics du programme"
776      return;;
777    14) echo "Erreur de rsync ; RERR_IPC"
778      echo "Erreur dans le code IPC"
779      return;;
780    20) echo "Erreur de rsync ; RERR_SIGNAL"
781      echo "SIGUSR1 ou SIGINT reçu"
782      return;;
783    21) echo "Erreur de rsync ; RERR_WAITCHILD"
784      echo "Une erreur retournée par waitpid()"
785      return;;
786    22) echo "Erreur de rsync ; RERR_MALLOC"
787      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
788      return;;
789    23) echo ""
790      echo "Erreur fichier inexistant"
791      return;;
792    30) echo "Erreur de rsync ; RERR_TIMEOUT"
793      echo "Temps d'attente écoulé dans l'envoi/réception de données"
794      return;;
795    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
796      return;;
797    esac
798  elif [ $MYLANG = "en" ] ; then
799    case $RET in
800    0)  return;;
801    1)  echo "rsync error : Syntax or usage error "
802      return;;
803    2)  echo "rsync error : Protocol incompatibility "
804      return;;
805    3)  echo "rsync error : Errors selecting input/output files, dirs"
806      return;;
807    4)  echo "rsync error : Requested action not supported: an attempt"
808      echo "was made to manipulate 64-bit files on a platform that cannot support"
809      echo "them; or an option was specified that is supported by the client and"
810      echo "not by the server."
811      return;;
812    5)  echo "rsync error : Error starting client-server protocol"
813      return;;
814    10) echo "rsync error : Error in socket I/O "
815      return;;
816    11) echo "rsync error : Error in file I/O "
817      return;;
818    12) echo "rsync error : Error in rsync protocol data stream "
819      return;;
820    13) echo "rsync error : Errors with program diagnostics "
821      return;;
822    14) echo "rsync error : Error in IPC code "
823      return;;
824    20) echo "rsync error : Received SIGUSR1 or SIGINT "
825      return;;
826    21) echo "rsync error : Some error returned by waitpid() "
827      return;;
828    22) echo "rsync error : Error allocating core memory buffers "
829      return;;
830    23) echo "rsync error : Partial transfer due to error"
831      return;;
832    24) echo "rsync error : Partial transfer due to vanished source files"
833      return;;
834    30) echo "rsync error : Timeout in data send/receive "
835      return;;
836    *)  echo "rsync error : return code of rsync unknown :" $RET
837      return;;
838    esac
839  else
840    echo "unknown language $MYLANG."
841    return
842  fi
843}
844
845#D-#==================================================
846#D-function IGCM_sys_Miror_libIGCM
847#D-* Purpose: Mirror libIGCM PATH and lib to cesium
848#D-* Examples:
849#D-
850function IGCM_sys_Mirror_libIGCM {
851  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
852  if ( $DEBUG_sys ) ; then
853    echo "IGCM_sys_Mirror_libIGCM"
854  fi
855
856  typeset RET DEST
857
858  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
859
860  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
861  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
862  RET=$?
863
864  if [ ${RET} -gt 0 ] ; then
865    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on cesium."
866    cat out_rsync
867  fi
868  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
869}
870
871#====================================================
872#- Call IGCM_sys_Mirror_libIGCM now !
873if ( $MirrorlibIGCM ) ; then
874  IGCM_sys_Mirror_libIGCM
875fi
876
877#D-#==================================================
878#D-function IGCM_sys_Cp
879#D-* Purpose: generic cp
880#D-* Examples:
881#D-
882function IGCM_sys_Cp {
883  IGCM_debug_PushStack "IGCM_sys_Cp" $@
884  if ( $DEBUG_sys ) ; then
885    echo "IGCM_sys_Cp :" $@
886  fi
887
888  typeset RET
889
890  echo cp $@ > out_rsync 2>&1
891  \cp $@ >> out_rsync 2>&1
892  RET=$?
893
894  if [ ${RET} -gt 0 ] ; then
895    echo "IGCM_sys_Cp : error."
896    cat out_rsync
897    IGCM_debug_Exit "IGCM_sys_Cp"
898  else
899    \rm out_rsync
900  fi
901  IGCM_debug_PopStack "IGCM_sys_Cp"
902}
903
904#D-#==================================================
905#D-function IGCM_sys_Rm
906#D-* Purpose: generic rm
907#D-* Examples:
908#D-
909function IGCM_sys_Rm {
910  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
911  if ( $DEBUG_sys ) ; then
912    echo "IGCM_sys_Rm :" $@
913  fi
914
915  typeset RET
916
917  echo rm $@ > out_rsync 2>&1
918  \rm $@ >> out_rsync 2>&1
919  RET=$?
920
921  if [ ${RET} -gt 0 ] ; then
922    echo "IGCM_sys_Rm : error."
923    cat out_rsync
924    IGCM_debug_Exit "IGCM_sys_Rm"
925  else
926    \rm out_rsync
927  fi
928  IGCM_debug_PopStack "IGCM_sys_Rm"
929}
930
931#D-#==================================================
932#D-function IGCM_sys_RmRunDir
933#D-* Purpose: rm tmpdir (dummy function most of the time batch
934#D-                      scheduler will do the job)
935#D-* Examples:
936#D-
937function IGCM_sys_RmRunDir {
938  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
939  if ( $DEBUG_sys ) ; then
940    echo "IGCM_sys_RmRunDir :" $@
941  fi
942
943  typeset RET
944
945  echo rm $@ > out_rsync 2>&1
946  \rm $@ >> out_rsync 2>&1
947  RET=$?
948
949  if [ ${RET} -gt 0 ] ; then
950    echo "IGCM_sys_RmRunDir : error."
951    cat out_rsync
952    IGCM_debug_Exit "IGCM_sys_RmRunDir"
953  else
954    \rm out_rsync
955  fi
956  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
957}
958
959#D-#==================================================
960#D-function IGCM_sys_Mv
961#D-* Purpose: generic move
962#D-* Examples:
963#D-
964function IGCM_sys_Mv {
965  IGCM_debug_PushStack "IGCM_sys_Mv" $@
966  if ( $DEBUG_sys ) ; then
967    echo "IGCM_sys_Mv :" $@
968  fi
969
970  if [ $DRYRUN = 0 ]; then
971
972    typeset RET
973
974    echo mv $@ > out_rsync 2>&1
975    \mv $@ >> out_rsync 2>&1
976    RET=$?
977
978    if [ ${RET} -gt 0 ] ; then
979      echo "IGCM_sys_Mv : error in mv."
980      cat out_rsync
981      IGCM_debug_Exit "IGCM_sys_Mv"
982    else
983      \rm out_rsync
984    fi
985  else
986    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
987  fi
988
989  IGCM_debug_PopStack "IGCM_sys_Mv"
990}
991
992#D-#==================================================
993#D-function IGCM_sys_Put_Dir
994#D-* Purpose: Copy a complete directory on $(ARCHIVE)
995#D-* Examples:
996#D-
997function IGCM_sys_Put_Dir {
998  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
999  if ( $DEBUG_sys ) ; then
1000    echo "IGCM_sys_Put_Dir :" $@
1001  fi
1002  if [ $DRYRUN = 0 ]; then
1003    if [ ! -d ${1} ] ; then
1004      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
1005      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1006      return
1007    fi
1008
1009    typeset RET
1010
1011    # Only if we use rsync
1012    #IGCM_sys_TestDirArchive $( dirname $2 )
1013    #
1014    #USUAL WAY
1015    \cp -r $1 $2 > out_rsync 2>&1
1016    RET=$?
1017
1018    if [ ${RET} -gt 0 ] ; then
1019      echo "IGCM_sys_Put_Dir : error."
1020      cat out_rsync
1021      IGCM_debug_Exit "IGCM_sys_Put_Dir"
1022    else
1023      \rm out_rsync
1024    fi
1025  else
1026    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1027  fi
1028  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1029}
1030
1031#D-#==================================================
1032#D-function IGCM_sys_Get_Dir
1033#D-* Purpose: Copy a complete directory from ${ARCHIVE}
1034#D-* Examples:
1035#D-
1036function IGCM_sys_Get_Dir {
1037  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
1038  if ( $DEBUG_sys ) ; then
1039    echo "IGCM_sys_Get_Dir :" $@
1040  fi
1041  if [ $DRYRUN = 0 ]; then
1042#    if [ ! -d ${1} ] ; then
1043#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
1044#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1045#      return
1046#    fi
1047
1048    typeset RET
1049
1050    # Only if we use rsync
1051    #IGCM_sys_TestDirArchive $( dirname $2 )
1052    #
1053    # USUAL WAY
1054    # add dmfind/dmget (to demigrate all offline files) :
1055    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
1056    \cp -r $1 $2 > out_rsync 2>&1
1057    RET=$?
1058
1059    if [ ${RET} -gt 0 ] ; then
1060      echo "IGCM_sys_Get_Dir : error."
1061      cat out_rsync
1062      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1063    else
1064      \rm out_rsync
1065    fi
1066  else
1067    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1068  fi
1069  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1070}
1071
1072#D-#==================================================
1073#D-function IGCM_sys_Get_Master
1074#D-* Purpose: Copy a complete directory from MASTER filesystem
1075#D-* Examples:
1076#D-
1077function IGCM_sys_Get_Master {
1078  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1079  if ( $DEBUG_sys ) ; then
1080    echo "IGCM_sys_Get_Master :" $@
1081  fi
1082  if [ $DRYRUN = 0 ]; then
1083    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
1084      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1085      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1086      return
1087    fi
1088
1089    typeset RET
1090
1091    #USUAL WAY
1092    \cp -r $1 $2 > out_rsync 2>&1
1093    RET=$?
1094
1095    if [ ${RET} -gt 0 ] ; then
1096      echo "IGCM_sys_Get_Master : error."
1097      cat out_rsync
1098      IGCM_debug_Exit "IGCM_sys_Get_Master"
1099    else
1100      \rm out_rsync
1101    fi
1102  else
1103    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1104  fi
1105  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1106}
1107
1108#D-#==================================================
1109#D-function IGCM_sys_Put_Rest
1110#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1111#D-           File and target directory must exist.
1112#D-* Examples:
1113#D-
1114function IGCM_sys_Put_Rest {
1115  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1116  if ( $DEBUG_sys ) ; then
1117    echo "IGCM_sys_Put_Rest :" $@
1118  fi
1119  if [ $DRYRUN = 0 ]; then
1120    if [ ! -f ${1} ] ; then
1121      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1122      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1123    fi
1124
1125    typeset RET
1126    #
1127    if [ X${JobType} = XRUN ] ; then
1128      IGCM_sys_Chmod 444 ${1}
1129    fi
1130
1131    #
1132    # USUAL WAY
1133    \cp $1 $2 > out_rsync 2>&1
1134    RET=$?
1135
1136#       #RSYNC WITH NETWORK SSH CALL
1137#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1138#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1139
1140#       #RSYNC WITH NFS USE
1141#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1142#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1143
1144#       RET=$?
1145#       IGCM_sys_Rsync_out $RET
1146
1147#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1148#       (( RET=RET+$? ))
1149
1150    if [ ${RET} -gt 0 ] ; then
1151      echo "IGCM_sys_Put_Rest : error."
1152      cat out_rsync
1153      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1154    else
1155      \rm out_rsync
1156    fi
1157  else
1158    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1159  fi
1160  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1161}
1162
1163#D-#==================================================
1164#D-function IGCM_sys_PutBuffer_Rest
1165#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1166#D-           File and target directory must exist.
1167#D-* Examples:
1168#D-
1169function IGCM_sys_PutBuffer_Rest {
1170  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1171  if ( $DEBUG_sys ) ; then
1172    echo "IGCM_sys_PutBuffer_Rest :" $@
1173  fi
1174  if [ $DRYRUN = 0 ]; then
1175    if [ ! -f ${1} ] ; then
1176      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1177      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1178    fi
1179
1180    typeset RET
1181    #
1182    if [ X${JobType} = XRUN ] ; then
1183      IGCM_sys_Chmod 444 ${1}
1184    fi
1185
1186    #
1187    # USUAL WAY
1188    \cp $1 $2 > out_rsync 2>&1
1189    RET=$?
1190
1191    if [ ${RET} -gt 0 ] ; then
1192      echo "IGCM_sys_PutBuffer_Rest : error."
1193      cat out_rsync
1194      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1195    else
1196      \rm out_rsync
1197    fi
1198  else
1199    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1200  fi
1201  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1202}
1203
1204#D-#==================================================
1205#D-function IGCM_sys_Put_Out
1206#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1207#D-* Examples:
1208#D-
1209function IGCM_sys_Put_Out {
1210  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1211  if ( $DEBUG_sys ) ; then
1212    echo "IGCM_sys_Put_Out :" $@
1213  fi
1214  if [ $DRYRUN = 0 ]; then
1215    if [ ! -f ${1} ] ; then
1216      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1217      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1218      return 1
1219    fi
1220    #
1221    IGCM_sys_MkdirArchive $( dirname $2 )
1222    #
1223    typeset RET
1224
1225    #=====================================================
1226    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1227    #=====================================================
1228
1229    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1230    #if [ $? -eq 0 ] ; then
1231    #    typeset WORKPATH FILEPATH
1232    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1233    #    IGCM_sys_MkdirWork ${WORKPATH}
1234    #    FILEPATH=${WORKPATH}/$( basename $2 )
1235    #    #
1236    #    IGCM_sys_Cp ${1} ${FILEPATH}
1237    #fi
1238
1239    if [ X${JobType} = XRUN ] ; then
1240      if [ X${3} = X ] ; then
1241        IGCM_sys_Chmod 444 ${1}
1242      fi
1243    fi
1244    #
1245    # USUAL WAY
1246    \cp $1 $2 > out_rsync 2>&1
1247    RET=$?
1248
1249#       #RSYNC WITH NETWORK SSH CALL
1250#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1251#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1252
1253#       #RSYNC WITH NFS USE
1254#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1255#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1256
1257#       RET=$?
1258#       IGCM_sys_Rsync_out $RET
1259
1260#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1261#       (( RET=RET+$? ))
1262
1263    if [ ${RET} -gt 0 ] ; then
1264      echo "IGCM_sys_Put_Out : error."
1265      cat out_rsync
1266      IGCM_debug_Exit "IGCM_sys_Put_Out"
1267    else
1268      \rm out_rsync
1269    fi
1270  else
1271    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1272  fi
1273  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1274  return 0
1275}
1276
1277#D-#==================================================
1278#D-function IGCM_sys_PutBuffer_Out
1279#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1280#D-* Examples:
1281#D-
1282function IGCM_sys_PutBuffer_Out {
1283  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1284  if ( $DEBUG_sys ) ; then
1285    echo "IGCM_sys_PutBuffer_Out :" $@
1286  fi
1287  if [ $DRYRUN = 0 ]; then
1288    if [ ! -f ${1} ] ; then
1289      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1290      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1291      return 1
1292    fi
1293    #
1294    IGCM_sys_Mkdir $( dirname $2 )
1295    #
1296    typeset RET
1297
1298    if [ X${JobType} = XRUN ] ; then
1299      if [ X${3} = X ] ; then
1300        IGCM_sys_Chmod 444 ${1}
1301      fi
1302    fi
1303    #
1304    # USUAL WAY
1305    \cp $1 $2 > out_rsync 2>&1
1306    RET=$?
1307
1308    if [ ${RET} -gt 0 ] ; then
1309      echo "IGCM_sys_PutBuffer_Out : error."
1310      cat out_rsync
1311      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1312    else
1313      \rm out_rsync
1314    fi
1315  else
1316    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1317  fi
1318  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1319  return 0
1320}
1321
1322#D-#==================================================
1323#D-function IGCM_sys_Get
1324#D-* Purpose: Get a file from ${ARCHIVE}
1325#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1326#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1327function IGCM_sys_Get {
1328  IGCM_debug_PushStack "IGCM_sys_Get" $@
1329
1330  typeset DEST RET dm_liste ifile target file_work
1331
1332  if ( $DEBUG_sys ) ; then
1333    echo "IGCM_sys_Get :" $@
1334  fi
1335  if [ $DRYRUN -le 2 ]; then
1336    if [ X${1} = X'/l' ] ; then
1337      # test if the first file is present in the old computation :
1338      eval set +A dm_liste \${${2}}
1339    else
1340      eval set +A dm_liste ${1}
1341    fi
1342    eval DEST=\${${#}}
1343
1344    #=====================================================
1345    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1346    #=====================================================
1347
1348    # Is it an R_OUT file (not R_IN) ?
1349    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1350    #if [ $? -eq 0 ] ; then
1351    #    # Yes  ? then we try to get it in SCRATCHDIR
1352    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1353    #    if [ -f ${file_work[0]} ] ; then
1354    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1355    #   IGCM_debug_PopStack "IGCM_sys_Get"
1356    #   return
1357    #    fi
1358    #fi
1359
1360    # test if the (first) file is present in the old computation :
1361    IGCM_sys_TestFileArchive ${dm_liste[0]}
1362    RET=$?
1363    if [ ${RET} -gt 0 ] ; then
1364      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1365      IGCM_debug_Exit "IGCM_sys_Get"
1366    fi
1367
1368    #dmget ${dm_liste[*]} > out_rsync 2>&1
1369    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1370    RET=$?
1371    if [ ${RET} -gt 0 ] ; then
1372      echo "WARNING IGCM_sys_Get : demigration error."
1373      cat out_rsync
1374      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1375    fi
1376
1377    #if [ ${RET} -gt 0 ] ; then
1378    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1379    #   cat out_rsync
1380    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1381    #   sleep 30
1382    #   echo "We try another time"
1383    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1384    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1385    #   RET=$?
1386    #   if [ ${RET} -gt 0 ] ; then
1387    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1388    #       cat out_rsync
1389    #       IGCM_debug_Exit "IGCM_sys_Get"
1390    #   fi
1391    #    else
1392    #   echo "ERROR IGCM_sys_Get : demigration error :"
1393    #   cat out_rsync
1394    #   IGCM_debug_Exit "IGCM_sys_Get"
1395    #    fi
1396    #fi
1397
1398    #USUAL WAY
1399    if [ X${1} = X'/l' ] ; then
1400      (( RET=0 ))
1401      for target in ${dm_liste[*]} ; do
1402        local_file=$( basename ${target} )
1403        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1404        (( RET = RET + $? ))
1405      done
1406    else
1407      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1408      RET=$?
1409    fi
1410
1411#       #RSYNC WITH NETWORK SSH CALL
1412#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1413#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1414
1415#       #RSYNC WITH NFS USE
1416#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1417#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1418
1419#       RET=$?
1420#       IGCM_sys_Rsync_out $RET
1421
1422#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1423#       (( RET=RET+$? ))
1424
1425    if [ ${RET} -gt 0 ] ; then
1426      echo "IGCM_sys_Get : copy error."
1427      cat out_rsync
1428      IGCM_debug_Exit "IGCM_sys_Get"
1429    else
1430      \rm out_rsync
1431    fi
1432  else
1433    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1434  fi
1435  IGCM_debug_PopStack "IGCM_sys_Get"
1436}
1437
1438#D-#==================================================
1439#D-function IGCM_sys_GetBuffer
1440#D-* Purpose: Get a file from ${SCRATCHDIR}
1441#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1442#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1443function IGCM_sys_GetBuffer {
1444  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1445
1446  typeset DEST RET buf_liste ifile target file_work
1447
1448  if ( $DEBUG_sys ) ; then
1449    echo "IGCM_sys_GetBuffer :" $@
1450  fi
1451  if [ $DRYRUN -le 2 ]; then
1452    if [ X${1} = X'/l' ] ; then
1453      # test if the first file is present in the old computation :
1454      eval set +A buf_liste \${${2}}
1455    else
1456      eval set +A buf_liste ${1}
1457    fi
1458    eval DEST=\${${#}}
1459
1460    #USUAL WAY
1461    if [ X${1} = X'/l' ] ; then
1462      (( RET=0 ))
1463      for target in ${buf_liste[*]} ; do
1464        local_file=$( basename ${target} )
1465        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1466        (( RET = RET + $? ))
1467      done
1468    else
1469      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1470      RET=$?
1471    fi
1472
1473    if [ ${RET} -gt 0 ] ; then
1474      echo "IGCM_sys_GetBuffer : copy error."
1475      cat out_rsync
1476      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1477    else
1478      \rm out_rsync
1479    fi
1480  else
1481    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1482  fi
1483  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1484}
1485
1486#D-#==================================================
1487#D-function IGCM_sys_GetDate_FichWork
1488#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1489#D-* Examples:
1490#D-
1491function IGCM_sys_GetDate_FichWork {
1492  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1493  if ( $DEBUG_sys ) ; then
1494    echo "IGCM_sys_GetDate_FichWork :" $@
1495  fi
1496  typeset dateF
1497  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1498  eval ${2}=${dateF[5]}
1499
1500    # donne la date filesys d'un fichier sur la machine work
1501  IGCM_debug_PopStack "IGCM_sys_FichWork"
1502}
1503
1504#D-#==================================================
1505#D-function IGCM_sys_GetDate_FichArchive
1506#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1507#D-* Examples:
1508#D-
1509function IGCM_sys_GetDate_FichArchive {
1510  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1511  if ( $DEBUG_sys ) ; then
1512    echo "IGCM_sys_GetDate_FichArchive :" $@
1513  fi
1514  typeset dateF
1515  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1516  eval ${2}=${dateF[5]}
1517
1518  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1519}
1520
1521#D-#==================================================
1522#D-function IGCM_sys_Dods_Rm
1523#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1524#D-* Examples:
1525#D-
1526function IGCM_sys_Dods_Rm {
1527  if ( $DEBUG_sys ) ; then
1528    echo "IGCM_sys_Dods_Rm :" $@
1529  fi
1530  typeset RET
1531  RET=0
1532  if [ $DRYRUN = 0 ]; then
1533
1534#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1535#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1536#      echo "Nothing has been done."
1537#      return
1538#    fi
1539
1540    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1541    RET=$?
1542
1543#       if [ ${RET} -gt 0 ] ; then
1544#           echo "IGCM_sys_Dods_Rm : error."
1545#           cat out_dods_rm
1546#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1547#       else
1548#           rm out_dods_rm
1549#       fi
1550
1551  else
1552    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1553  fi
1554  return $RET
1555}
1556
1557#D-#==================================================
1558#D-function IGCM_sys_Dods_Cp
1559#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1560#D-* Examples:
1561#D-
1562function IGCM_sys_Dods_Cp {
1563  if ( $DEBUG_sys ) ; then
1564    echo "IGCM_sys_Dods_Cp :" $@
1565  fi
1566  typeset RET
1567  RET=0
1568  if [ $DRYRUN = 0 ]; then
1569
1570#    if [ ! -d ${R_SAVE}/${1} ] ; then
1571#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1572#      echo "Nothing has been done."
1573#      return
1574#    fi
1575
1576    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1577    RET=$?
1578
1579#       if [ ${RET} -gt 0 ] ; then
1580#           echo "IGCM_sys_Dods_Cp : error."
1581#           cat out_dods_cp
1582#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1583#       else
1584#           rm out_dods_cp
1585#       fi
1586
1587  else
1588    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1589  fi
1590  return $RET
1591}
1592
1593#D-#==================================================
1594#D-function IGCM_sys_Put_Dods
1595#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1596#D-* Examples:
1597#D-
1598function IGCM_sys_Put_Dods {
1599  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1600  if ( $DEBUG_sys ) ; then
1601    echo "IGCM_sys_Put_Dods :" $@
1602  fi
1603  set -vx
1604  typeset RET
1605  if [ $DRYRUN = 0 ]; then
1606    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1607      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1608      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1609      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1610      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1611      return
1612    fi
1613
1614    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1615      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1616      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1617      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1618      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1619      return
1620    fi
1621    #
1622    if [ -d ${R_SAVE}/${1} ] ; then
1623      cd ${R_SAVE}
1624    elif [ -d ${R_FIGR}/${1} ] ; then
1625      cd ${R_FIGR}
1626    fi
1627
1628    IGCM_sys_Dods_Rm ${1}
1629    IGCM_sys_Dods_Cp ${1}
1630    RET=0
1631
1632    if [ ${RET} -gt 0 ] ; then
1633      echo "IGCM_sys_Put_Dods : error."
1634      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1635    fi
1636  else
1637    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1638  fi
1639  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1640}
1641
1642##############################################################
1643# REBUILD OPERATOR
1644
1645function IGCM_sys_rebuild {
1646  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1647  if ( $DEBUG_sys ) ; then
1648    echo "IGCM_sys_rebuild :" $@
1649  fi
1650  /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@
1651  if [ $? -gt 0 ] ; then
1652    echo "IGCM_sys_rebuild : erreur ${@}."
1653    IGCM_debug_Exit "rebuild"
1654  fi
1655
1656  IGCM_debug_PopStack "IGCM_sys_rebuild"
1657}
1658
1659############################################################
1660# Activate Running Environnment Variables
1661
1662function IGCM_sys_activ_variables {
1663  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1664  if ( $DEBUG_sys ) ; then
1665    echo "IGCM_sys_activ_variables"
1666  fi
1667
1668  typeset max_omp
1669
1670  ulimit -s unlimited
1671
1672  (( max_omp = 0 ))
1673  for comp in ${config_ListOfComponents[*]} ; do
1674
1675    eval ExeNameIn=\${config_Executable_${comp}[0]}
1676    eval ExeNameOut=\${config_Executable_${comp}[1]}
1677
1678    # Only if we really have an executable for the component :
1679    if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1680      eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1681      if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
1682        (( max_omp = comp_proc_omp_loc ))
1683      fi
1684    fi
1685  done
1686  if [ ${max_omp} -gt 1 ] ; then
1687    module load openmp/${max_omp}thds
1688  fi
1689
1690  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1691}
1692
1693############################################################
1694# Desactivate Running Environnment Variables
1695
1696function IGCM_sys_desactiv_variables {
1697  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1698  if ( $DEBUG_sys ) ; then
1699    echo "IGCM_sys_desactiv_variables"
1700  fi
1701  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1702}
1703
1704############################################################
1705# Build MPI/OMP scripts run file (dummy function)
1706
1707function IGCM_sys_build_run_file {
1708
1709IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1710
1711}
1712
1713############################################################
1714# Build MPI/OMP scripts
1715function IGCM_sys_build_execution_scripts
1716{
1717  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1718  if ( $DEBUG_sys ) ; then
1719    echo "IGCM_sys_build_execution_scripts " $@
1720  fi
1721  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1722  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1723  typeset num_corempi nombre_restant_node nombre_restant_comp
1724
1725  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1726    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1727  fi
1728
1729  if ( ${OK_PARA_MPMD} ) ; then
1730
1731    if [ -f run_file ] ; then
1732      IGCM_sys_Rm -f run_file
1733    fi
1734    touch run_file
1735
1736    if ( ${OK_PARA_OMP} ) ; then
1737
1738      #  Hosts treatment
1739
1740      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1741
1742      i=0
1743      rm -f hosts
1744      IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
1745      for nodes in `cat hosts.tmp` ; do
1746        host[$i]=$nodes
1747        echo "${host[$i]} slots=8 max_slots=8" >> hosts
1748        IGCM_debug_Print 1 ${host[$i]}
1749        i=$((i+1))
1750      done
1751      rm -f hosts.tmp
1752
1753      listnodes=${host[*]}
1754
1755      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1756
1757      # Initialisation
1758
1759      init_node=y
1760      node_num_current=0
1761      start_num=0
1762      init_exec=n
1763
1764      # Test : if oasis is there, we put it at the first position
1765
1766      for comp in ${config_ListOfComponents[*]} ; do
1767
1768        if [ "X${comp}" = "XCPL" ]  ; then
1769
1770          eval ExeNameIn=\${config_Executable_${comp}[0]}
1771          eval ExeNameOut=\${config_Executable_${comp}[1]}
1772
1773          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1774          echo ""  >> script_${ExeNameOut}.ksh
1775          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1776          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1777          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1778          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1779          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1780
1781          init_node=n
1782
1783          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1784          node_num_current=0
1785          node_current=${host[${node_num_current}]}
1786
1787          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1788
1789          init_exec=y
1790          start_num=1
1791
1792        fi
1793
1794      done
1795
1796      # Then loop on the components (except for oasis)
1797
1798      for comp in ${config_ListOfComponents[*]} ; do
1799
1800        eval ExeNameIn=\${config_Executable_${comp}[0]}
1801        eval ExeNameOut=\${config_Executable_${comp}[1]}
1802
1803        # Only if we really have an executable for the component :
1804        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1805
1806          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1807          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1808
1809          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1810          # echo "set -vx" >> script_${ExeNameOut}.ksh
1811          echo ""  >> script_${ExeNameOut}.ksh
1812          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1813          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1814          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1815          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1816          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1817          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1818          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1819
1820          node_num=0
1821
1822          # We define the number of MPI process to be assigned for the component
1823
1824          nombre_restant_comp=${comp_proc_mpi_loc}
1825
1826          # Loop on the allocated nodes
1827
1828          for node in ${listnodes} ; do
1829
1830            # We go to the current node
1831            if [ ${node_num} = ${node_num_current} ] ; then
1832
1833              node_current=${host[${node_num_current}]}
1834
1835              # If first time on the node : initialisation
1836
1837              if [ ${init_node} = y ] ; then
1838                nombre_restant_node=${NUM_COREPERNODE}
1839              fi
1840
1841              # Test on the number of OMP threads
1842
1843              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1844                (( node_num = node_num + 1 ))
1845                node_num_current=${node_num}
1846                init_node=y
1847                continue
1848              fi
1849
1850              # Number of MPI process to assign
1851
1852              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1853
1854              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1855                num_corempi=${nombre_restant_comp}
1856              fi
1857
1858              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1859              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1860
1861              if [ ${init_exec} = y ] ; then
1862                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1863              else
1864                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1865                init_exec=y
1866              fi
1867
1868              ((  start_num = num_corempi + start_num ))
1869
1870            else
1871
1872              (( node_num = node_num + 1 ))
1873              continue
1874            fi
1875
1876            # Test on the number of core/process remaining on the node/component
1877
1878            if [ ${nombre_restant_node} = 0 ] ; then
1879              (( node_num = node_num + 1 ))
1880              node_num_current=${node_num}
1881              init_node=y
1882
1883              if [ ${nombre_restant_comp} = 0 ] ; then
1884                break 1
1885              fi
1886            else
1887
1888              node_num_current=${node_num}
1889              init_node=n
1890
1891              if [ ${nombre_restant_comp} = 0 ] ; then
1892                break 1
1893              fi
1894            fi
1895          done
1896        fi
1897      done
1898
1899    else
1900
1901        # Then first loop on the components for the coupler ie oasis
1902
1903        ## the coupler ie oasis must be the first one
1904        for comp in ${config_ListOfComponents[*]} ; do
1905
1906            eval ExeNameOut=\${config_Executable_${comp}[1]}
1907
1908        # for CPL component only
1909            if [ "X${comp}" = "XCPL" ] ; then
1910                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1911                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1912            fi
1913        done
1914
1915        # Then second loop on the components
1916
1917        for comp in ${config_ListOfComponents[*]} ; do
1918
1919            eval ExeNameOut=\${config_Executable_${comp}[1]}
1920
1921            # Only if we really have an executable for the component and not the coupler ie oasis:
1922            if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1923                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1924                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1925            fi
1926        done
1927        IGCM_sys_Chmod u+x run_file
1928
1929        EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1930
1931    fi
1932
1933  else # Only one executable. launch it.
1934
1935      for comp in ${config_ListOfComponents[*]} ; do
1936
1937          # Only if we really have an executable for the component :
1938          eval ExeNameOut=\${config_Executable_${comp}[1]}
1939          if ( [ "X${ExeNameOut}" != X\"\" ] ) ; then
1940
1941              echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1942              echo ""  >> script_${ExeNameOut}.ksh
1943              if ( ${OK_PARA_OMP} ) ; then
1944                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1945                  echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1946              fi
1947              if  ( ${OK_PARA_MPI} ) ; then
1948                  # Default : mpirun used if nb_proc gt 1
1949                  # pour sortie out/err par process
1950                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1951                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1952                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1953                  EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1954              else
1955                  # Default : mpirun is NOT used if nb_proc eq 1
1956                  # pour sortie out/err par process
1957                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1958                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1959                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1960                  EXECUTION="time ./script_${ExeNameOut}.ksh"
1961              fi
1962          fi
1963      done
1964
1965  fi
1966
1967  IGCM_debug_Print 1 "sys Titane : La commande d execution est "
1968  IGCM_debug_Print 1 $EXECUTION
1969
1970  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1971}
1972
1973##############################################################
1974# NCO OPERATOR
1975
1976function IGCM_sys_ncap2 {
1977  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1978  if ( $DEBUG_sys ) ; then
1979    echo "IGCM_sys_ncap2 :" $@
1980  fi
1981  ncap2 "$@"
1982  if [ $? -gt 0 ] ; then
1983    echo "IGCM_sys_ncap2 : erreur ${@}."
1984    IGCM_debug_Exit "ncap2"
1985  fi
1986
1987  IGCM_debug_PopStack "IGCM_sys_ncap2"
1988}
1989
1990function IGCM_sys_ncatted {
1991  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1992  if ( $DEBUG_sys ) ; then
1993    echo "IGCM_sys_ncatted :" $@
1994  fi
1995  ncatted "$@"
1996  if [ $? -gt 0 ] ; then
1997    echo "IGCM_sys_ncatted : erreur ${@}."
1998    IGCM_debug_Exit "ncatted"
1999  fi
2000
2001  IGCM_debug_PopStack "IGCM_sys_ncatted"
2002}
2003
2004function IGCM_sys_ncbo {
2005  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2006  if ( $DEBUG_sys ) ; then
2007    echo "IGCM_sys_ncbo :" $@
2008  fi
2009  ncbo $@
2010  if [ $? -gt 0 ] ; then
2011    echo "IGCM_sys_ncbo : erreur ${@}."
2012    IGCM_debug_Exit "ncbo"
2013  fi
2014
2015  IGCM_debug_PopStack "IGCM_sys_ncbo"
2016}
2017
2018function IGCM_sys_ncdiff {
2019  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2020  if ( $DEBUG_sys ) ; then
2021    echo "IGCM_sys_ncdiff :" $@
2022  fi
2023  ncdiff $@
2024  if [ $? -gt 0 ] ; then
2025    echo "IGCM_sys_ncdiff : erreur ${@}."
2026    IGCM_debug_Exit "ncdiff"
2027  fi
2028
2029  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2030}
2031
2032function IGCM_sys_ncea {
2033  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2034  if ( $DEBUG_sys ) ; then
2035    echo "IGCM_sys_ncea :" $@
2036  fi
2037  ncea $@
2038  if [ $? -gt 0 ] ; then
2039    echo "IGCM_sys_ncea : erreur ${@}."
2040    IGCM_debug_Exit "ncea"
2041  fi
2042
2043  IGCM_debug_PopStack "IGCM_sys_ncea"
2044}
2045
2046function IGCM_sys_ncecat {
2047  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2048  if ( $DEBUG_sys ) ; then
2049    echo "IGCM_sys_ncecat :" $@
2050  fi
2051  ncecat $@
2052  if [ $? -gt 0 ] ; then
2053    echo "IGCM_sys_ncecat : erreur ${@}."
2054    IGCM_debug_Exit "ncecat"
2055  fi
2056
2057  IGCM_debug_PopStack "IGCM_sys_ncecat"
2058}
2059
2060function IGCM_sys_ncflint {
2061  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2062  if ( $DEBUG_sys ) ; then
2063    echo "IGCM_sys_ncflint :" $@
2064  fi
2065  ncflint $@
2066  if [ $? -gt 0 ] ; then
2067    echo "IGCM_sys_ncflint : erreur ${@}."
2068    IGCM_debug_Exit "ncflint"
2069  fi
2070
2071  IGCM_debug_PopStack "IGCM_sys_ncflint"
2072}
2073
2074function IGCM_sys_ncks {
2075  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2076  if ( $DEBUG_sys ) ; then
2077    echo "IGCM_sys_ncks :" $@
2078  fi
2079  ncks $@
2080  if [ $? -gt 0 ] ; then
2081    echo "IGCM_sys_ncks : erreur ${@}."
2082    IGCM_debug_Exit "ncks"
2083  fi
2084
2085  IGCM_debug_PopStack "IGCM_sys_ncks"
2086}
2087
2088function IGCM_sys_ncpdq {
2089  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2090  if ( $DEBUG_sys ) ; then
2091    echo "IGCM_sys_ncpdq :" $@
2092  fi
2093  ncpdq $@
2094  if [ $? -gt 0 ] ; then
2095    echo "IGCM_sys_ncpdq : erreur ${@}."
2096    IGCM_debug_Exit "ncpdq"
2097  fi
2098
2099  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2100}
2101
2102function IGCM_sys_ncra {
2103  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2104  if ( $DEBUG_sys ) ; then
2105    echo "IGCM_sys_ncra :" $@
2106  fi
2107  ncra $@
2108  if [ $? -gt 0 ] ; then
2109    echo "IGCM_sys_ncra : erreur ${@}."
2110    IGCM_debug_Exit "ncra"
2111  fi
2112
2113  IGCM_debug_PopStack "IGCM_sys_ncra"
2114}
2115
2116function IGCM_sys_ncrcat {
2117  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2118  if ( $DEBUG_sys ) ; then
2119    echo "IGCM_sys_ncrcat :" $@
2120  fi
2121  ncrcat --omp_num_threads 2 $@
2122  if [ $? -gt 0 ] ; then
2123    echo "IGCM_sys_ncrcat : erreur ${@}."
2124#       IGCM_debug_Exit "ncrcat"
2125  fi
2126
2127  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2128}
2129
2130function IGCM_sys_ncrename {
2131  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2132  if ( $DEBUG_sys ) ; then
2133    echo "IGCM_sys_ncrename :" $@
2134  fi
2135  ncrename $@
2136  if [ $? -gt 0 ] ; then
2137    echo "IGCM_sys_ncrename : erreur ${@}."
2138    IGCM_debug_Exit "ncrename"
2139  fi
2140
2141  IGCM_debug_PopStack "IGCM_sys_ncrename"
2142}
2143
2144function IGCM_sys_ncwa {
2145  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2146  if ( $DEBUG_sys ) ; then
2147    echo "IGCM_sys_ncwa :" $@
2148  fi
2149  ncwa $@
2150  if [ $? -gt 0 ] ; then
2151    echo "IGCM_sys_ncwa : erreur ${@}."
2152    IGCM_debug_Exit "ncwa"
2153  fi
2154
2155  IGCM_debug_PopStack "IGCM_sys_ncwa"
2156}
2157
2158##############################################################
2159# CDO OPERATOR
2160
2161function IGCM_sys_cdo {
2162  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2163  if ( $DEBUG_sys ) ; then
2164    echo "IGCM_sys_cdo :" $@
2165  fi
2166  \cdo $@
2167  if [ $? -gt 0 ] ; then
2168    echo "IGCM_sys_cdo : erreur ${@}."
2169    IGCM_debug_PopStack "IGCM_sys_cdo"
2170    return 1
2171  else
2172    IGCM_debug_PopStack "IGCM_sys_cdo"
2173    return 0
2174  fi
2175
2176  IGCM_debug_PopStack "IGCM_sys_cdo"
2177}
Note: See TracBrowser for help on using the repository browser.