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