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

Last change on this file since 676 was 676, checked in by sdipsl, 12 years ago
  • Prevent the fact that cp command is not reliable on ccrt/tgcc filesystems
  • Cosmetics
  • Property svn:keywords set to Revision Author Date
File size: 66.2 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
1214  typeset NB_ESSAI DELAI RET i
1215
1216  # number of tentative
1217  NB_ESSAI=3
1218  # time delay between tentative
1219  DELAI=2
1220
1221  if [ $DRYRUN = 0 ]; then
1222    if [ ! -f ${1} ] ; then
1223      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1224      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1225      return 1
1226    fi
1227    #
1228    IGCM_sys_MkdirArchive $( dirname $2 )
1229    #
1230
1231    #=====================================================
1232    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1233    #=====================================================
1234
1235    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1236    #if [ $? -eq 0 ] ; then
1237    #    typeset WORKPATH FILEPATH
1238    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1239    #    IGCM_sys_MkdirWork ${WORKPATH}
1240    #    FILEPATH=${WORKPATH}/$( basename $2 )
1241    #    #
1242    #    IGCM_sys_Cp ${1} ${FILEPATH}
1243    #fi
1244
1245    if [ X${JobType} = XRUN ] ; then
1246      if [ X${3} = X ] ; then
1247        IGCM_sys_Chmod 444 ${1}
1248      fi
1249    fi
1250    #
1251
1252    (( i = 0 ))
1253    while [ $i -lt $NB_ESSAI ] ; do
1254    # USUAL WAY
1255      \cp $1 $2 > out_rsync 2>&1
1256      RET=$?
1257      if [ ${RET} -gt 0 ]; then
1258        IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed ${i}/${NB_ESSAI}"
1259        IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1260        sleep $DELAI
1261      else
1262        break
1263      fi
1264      (( i = i + 1 ))
1265    done
1266
1267#       #RSYNC WITH NETWORK SSH CALL
1268#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1269#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1270
1271#       #RSYNC WITH NFS USE
1272#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1273#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1274
1275#       RET=$?
1276#       IGCM_sys_Rsync_out $RET
1277
1278#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1279#       (( RET=RET+$? ))
1280
1281    if [ ${RET} -gt 0 ] ; then
1282      echo "IGCM_sys_Put_Out : error."
1283      cat out_rsync
1284      IGCM_debug_Exit "IGCM_sys_Put_Out"
1285    else
1286      \rm out_rsync
1287    fi
1288  else
1289    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1290  fi
1291  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1292  return 0
1293}
1294
1295#D-#==================================================
1296#D-function IGCM_sys_PutBuffer_Out
1297#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1298#D-* Examples:
1299#D-
1300function IGCM_sys_PutBuffer_Out {
1301  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1302  if ( $DEBUG_sys ) ; then
1303    echo "IGCM_sys_PutBuffer_Out :" $@
1304  fi
1305  if [ $DRYRUN = 0 ]; then
1306    if [ ! -f ${1} ] ; then
1307      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1308      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1309      return 1
1310    fi
1311    #
1312    IGCM_sys_Mkdir $( dirname $2 )
1313    #
1314    typeset RET
1315
1316    if [ X${JobType} = XRUN ] ; then
1317      if [ X${3} = X ] ; then
1318        IGCM_sys_Chmod 444 ${1}
1319      fi
1320    fi
1321    #
1322    # USUAL WAY
1323    \cp $1 $2 > out_rsync 2>&1
1324    RET=$?
1325
1326    if [ ${RET} -gt 0 ] ; then
1327      echo "IGCM_sys_PutBuffer_Out : error."
1328      cat out_rsync
1329      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1330    else
1331      \rm out_rsync
1332    fi
1333  else
1334    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1335  fi
1336  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1337  return 0
1338}
1339
1340#D-#==================================================
1341#D-function IGCM_sys_Get
1342#D-* Purpose: Get a file from ${ARCHIVE}
1343#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1344#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1345function IGCM_sys_Get {
1346  IGCM_debug_PushStack "IGCM_sys_Get" $@
1347
1348  typeset DEST RET dm_liste ifile target file_work
1349  typeset NB_ESSAI DELAI status i
1350
1351  if ( $DEBUG_sys ) ; then
1352    echo "IGCM_sys_Get :" $@
1353  fi
1354
1355  # number of tentative
1356  NB_ESSAI=3
1357  # time delay between tentative
1358  DELAI=2
1359
1360  if [ $DRYRUN -le 2 ]; then
1361    if [ X${1} = X'/l' ] ; then
1362      # test if the first file is present in the old computation :
1363      eval set +A dm_liste \${${2}}
1364    else
1365      eval set +A dm_liste ${1}
1366    fi
1367    eval DEST=\${${#}}
1368
1369    #=====================================================
1370    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1371    #=====================================================
1372
1373    # Is it an R_OUT file (not R_IN) ?
1374    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1375    #if [ $? -eq 0 ] ; then
1376    #    # Yes  ? then we try to get it in SCRATCHDIR
1377    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1378    #    if [ -f ${file_work[0]} ] ; then
1379    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1380    #   IGCM_debug_PopStack "IGCM_sys_Get"
1381    #   return
1382    #    fi
1383    #fi
1384
1385    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1386    RET=$?
1387    if [ ${RET} -gt 0 ] ; then
1388      echo "WARNING IGCM_sys_Get : demigration error."
1389      cat out_rsync
1390      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1391    fi
1392
1393    #if [ ${RET} -gt 0 ] ; then
1394    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1395    #   cat out_rsync
1396    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1397    #   sleep 30
1398    #   echo "We try another time"
1399    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1400    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1401    #   RET=$?
1402    #   if [ ${RET} -gt 0 ] ; then
1403    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1404    #       cat out_rsync
1405    #       IGCM_debug_Exit "IGCM_sys_Get"
1406    #   fi
1407    #    else
1408    #   echo "ERROR IGCM_sys_Get : demigration error :"
1409    #   cat out_rsync
1410    #   IGCM_debug_Exit "IGCM_sys_Get"
1411    #    fi
1412    #fi
1413
1414    #USUAL WAY
1415    if [ X${1} = X'/l' ] ; then
1416      (( RET=0 ))
1417      for target in ${dm_liste[*]} ; do
1418        local_file=$( basename ${target} )
1419        (( i = 0 ))
1420        # test if the target file is present before the loop
1421        IGCM_sys_TestFileArchive ${target}
1422        RET=$?
1423        if [ ${RET} -gt 0 ] ; then
1424          echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1425          IGCM_debug_Exit "IGCM_sys_Get"
1426        else
1427          while [ $i -lt $NB_ESSAI ] ; do
1428            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1429            status=$?
1430            if [ ${status} -gt 0 ]; then
1431              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed ${i}/${NB_ESSAI}"
1432              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1433              sleep $DELAI
1434            else
1435              break
1436            fi
1437            (( i = i + 1 ))
1438          done
1439          (( RET = RET + status ))
1440        fi
1441      done
1442    else
1443      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1444      RET=$?
1445    fi
1446
1447#       #RSYNC WITH NETWORK SSH CALL
1448#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1449#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1450
1451#       #RSYNC WITH NFS USE
1452#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1453#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1454
1455#       RET=$?
1456#       IGCM_sys_Rsync_out $RET
1457
1458#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1459#       (( RET=RET+$? ))
1460
1461    if [ ${RET} -gt 0 ] ; then
1462      echo "IGCM_sys_Get : copy error."
1463      cat out_rsync
1464      IGCM_debug_Exit "IGCM_sys_Get"
1465    else
1466      \rm out_rsync
1467    fi
1468  else
1469    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1470  fi
1471  IGCM_debug_PopStack "IGCM_sys_Get"
1472}
1473
1474#D-#==================================================
1475#D-function IGCM_sys_GetBuffer
1476#D-* Purpose: Get a file from ${SCRATCHDIR}
1477#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1478#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1479function IGCM_sys_GetBuffer {
1480  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1481
1482  typeset DEST RET buf_liste ifile target file_work
1483
1484  if ( $DEBUG_sys ) ; then
1485    echo "IGCM_sys_GetBuffer :" $@
1486  fi
1487  if [ $DRYRUN -le 2 ]; then
1488    if [ X${1} = X'/l' ] ; then
1489      # test if the first file is present in the old computation :
1490      eval set +A buf_liste \${${2}}
1491    else
1492      eval set +A buf_liste ${1}
1493    fi
1494    eval DEST=\${${#}}
1495
1496    #USUAL WAY
1497    if [ X${1} = X'/l' ] ; then
1498      (( RET=0 ))
1499      for target in ${buf_liste[*]} ; do
1500        local_file=$( basename ${target} )
1501        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1502        (( RET = RET + $? ))
1503      done
1504    else
1505      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1506      RET=$?
1507    fi
1508
1509    if [ ${RET} -gt 0 ] ; then
1510      echo "IGCM_sys_GetBuffer : copy error."
1511      cat out_rsync
1512      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1513    else
1514      \rm out_rsync
1515    fi
1516  else
1517    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1518  fi
1519  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1520}
1521
1522#D-#==================================================
1523#D-function IGCM_sys_GetDate_FichWork
1524#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1525#D-* Examples:
1526#D-
1527function IGCM_sys_GetDate_FichWork {
1528  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1529  if ( $DEBUG_sys ) ; then
1530    echo "IGCM_sys_GetDate_FichWork :" $@
1531  fi
1532  typeset dateF
1533  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1534  eval ${2}=${dateF[5]}
1535
1536    # donne la date filesys d'un fichier sur la machine work
1537  IGCM_debug_PopStack "IGCM_sys_FichWork"
1538}
1539
1540#D-#==================================================
1541#D-function IGCM_sys_GetDate_FichArchive
1542#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1543#D-* Examples:
1544#D-
1545function IGCM_sys_GetDate_FichArchive {
1546  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1547  if ( $DEBUG_sys ) ; then
1548    echo "IGCM_sys_GetDate_FichArchive :" $@
1549  fi
1550  typeset dateF
1551  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1552  eval ${2}=${dateF[5]}
1553
1554  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1555}
1556
1557#D-#==================================================
1558#D-function IGCM_sys_Dods_Rm
1559#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1560#D-* Examples:
1561#D-
1562function IGCM_sys_Dods_Rm {
1563  if ( $DEBUG_sys ) ; then
1564    echo "IGCM_sys_Dods_Rm :" $@
1565  fi
1566  typeset RET
1567  RET=0
1568  if [ $DRYRUN = 0 ]; then
1569
1570#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1571#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1572#      echo "Nothing has been done."
1573#      return
1574#    fi
1575
1576    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1577    RET=$?
1578
1579#       if [ ${RET} -gt 0 ] ; then
1580#           echo "IGCM_sys_Dods_Rm : error."
1581#           cat out_dods_rm
1582#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1583#       else
1584#           rm out_dods_rm
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_Dods_Cp
1595#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1596#D-* Examples:
1597#D-
1598function IGCM_sys_Dods_Cp {
1599  if ( $DEBUG_sys ) ; then
1600    echo "IGCM_sys_Dods_Cp :" $@
1601  fi
1602  typeset RET
1603  RET=0
1604  if [ $DRYRUN = 0 ]; then
1605
1606#    if [ ! -d ${R_SAVE}/${1} ] ; then
1607#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1608#      echo "Nothing has been done."
1609#      return
1610#    fi
1611
1612    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1613    RET=$?
1614
1615#       if [ ${RET} -gt 0 ] ; then
1616#           echo "IGCM_sys_Dods_Cp : error."
1617#           cat out_dods_cp
1618#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1619#       else
1620#           rm out_dods_cp
1621#       fi
1622
1623  else
1624    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1625  fi
1626  return $RET
1627}
1628
1629#D-#==================================================
1630#D-function IGCM_sys_Put_Dods
1631#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1632#D-* Examples:
1633#D-
1634function IGCM_sys_Put_Dods {
1635  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1636  if ( $DEBUG_sys ) ; then
1637    echo "IGCM_sys_Put_Dods :" $@
1638  fi
1639  set -vx
1640  typeset RET
1641  if [ $DRYRUN = 0 ]; then
1642    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1643      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1644      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1645      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1646      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1647      return
1648    fi
1649
1650    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1651      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1652      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1653      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1654      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1655      return
1656    fi
1657    #
1658    if [ -d ${R_SAVE}/${1} ] ; then
1659      cd ${R_SAVE}
1660    elif [ -d ${R_FIGR}/${1} ] ; then
1661      cd ${R_FIGR}
1662    fi
1663
1664    IGCM_sys_Dods_Rm ${1}
1665    IGCM_sys_Dods_Cp ${1}
1666    RET=0
1667
1668    if [ ${RET} -gt 0 ] ; then
1669      echo "IGCM_sys_Put_Dods : error."
1670      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1671    fi
1672  else
1673    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1674  fi
1675  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1676}
1677
1678##############################################################
1679# REBUILD OPERATOR
1680
1681function IGCM_sys_rebuild {
1682  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1683  if ( $DEBUG_sys ) ; then
1684    echo "IGCM_sys_rebuild :" $@
1685  fi
1686  /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@
1687  if [ $? -gt 0 ] ; then
1688    echo "IGCM_sys_rebuild : erreur ${@}."
1689    IGCM_debug_Exit "rebuild"
1690  fi
1691
1692  IGCM_debug_PopStack "IGCM_sys_rebuild"
1693}
1694
1695############################################################
1696# Activate Running Environnment Variables
1697
1698function IGCM_sys_activ_variables {
1699  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1700  if ( $DEBUG_sys ) ; then
1701    echo "IGCM_sys_activ_variables"
1702  fi
1703
1704  typeset max_omp
1705
1706  ulimit -s unlimited
1707
1708  (( max_omp = 0 ))
1709  for comp in ${config_ListOfComponents[*]} ; do
1710
1711    eval ExeNameIn=\${config_Executable_${comp}[0]}
1712    eval ExeNameOut=\${config_Executable_${comp}[1]}
1713
1714    # Only if we really have an executable for the component :
1715    if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1716      eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1717      if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
1718        (( max_omp = comp_proc_omp_loc ))
1719      fi
1720    fi
1721  done
1722  if [ ${max_omp} -gt 1 ] ; then
1723    module load openmp/${max_omp}thds
1724  fi
1725
1726  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1727}
1728
1729############################################################
1730# Desactivate Running Environnment Variables
1731
1732function IGCM_sys_desactiv_variables {
1733  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1734  if ( $DEBUG_sys ) ; then
1735    echo "IGCM_sys_desactiv_variables"
1736  fi
1737  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1738}
1739
1740############################################################
1741# Build MPI/OMP scripts run file (dummy function)
1742
1743function IGCM_sys_build_run_file {
1744
1745IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1746
1747}
1748
1749############################################################
1750# Build MPI/OMP scripts
1751function IGCM_sys_build_execution_scripts
1752{
1753  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1754  if ( $DEBUG_sys ) ; then
1755    echo "IGCM_sys_build_execution_scripts " $@
1756  fi
1757  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1758  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1759  typeset num_corempi nombre_restant_node nombre_restant_comp
1760
1761  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1762    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1763  fi
1764
1765  if ( ${OK_PARA_MPMD} ) ; then
1766
1767    if [ -f run_file ] ; then
1768      IGCM_sys_Rm -f run_file
1769    fi
1770    touch run_file
1771
1772    if ( ${OK_PARA_OMP} ) ; then
1773
1774      #  Hosts treatment
1775
1776      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1777
1778      i=0
1779      rm -f hosts
1780      IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
1781      for nodes in `cat hosts.tmp` ; do
1782        host[$i]=$nodes
1783        echo "${host[$i]} slots=8 max_slots=8" >> hosts
1784        IGCM_debug_Print 1 ${host[$i]}
1785        i=$((i+1))
1786      done
1787      rm -f hosts.tmp
1788
1789      listnodes=${host[*]}
1790
1791      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1792
1793      # Initialisation
1794
1795      init_node=y
1796      node_num_current=0
1797      start_num=0
1798      init_exec=n
1799
1800      # Test : if oasis is there, we put it at the first position
1801
1802      for comp in ${config_ListOfComponents[*]} ; do
1803
1804        if [ "X${comp}" = "XCPL" ]  ; then
1805
1806          eval ExeNameIn=\${config_Executable_${comp}[0]}
1807          eval ExeNameOut=\${config_Executable_${comp}[1]}
1808
1809          echo "#!/bin/ksh" > 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 "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1815          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1816
1817          init_node=n
1818
1819          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1820          node_num_current=0
1821          node_current=${host[${node_num_current}]}
1822
1823          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1824
1825          init_exec=y
1826          start_num=1
1827
1828        fi
1829
1830      done
1831
1832      # Then loop on the components (except for oasis)
1833
1834      for comp in ${config_ListOfComponents[*]} ; do
1835
1836        eval ExeNameIn=\${config_Executable_${comp}[0]}
1837        eval ExeNameOut=\${config_Executable_${comp}[1]}
1838
1839        # Only if we really have an executable for the component :
1840        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1841
1842          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1843          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1844
1845          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1846          # echo "set -vx" >> script_${ExeNameOut}.ksh
1847          echo ""  >> script_${ExeNameOut}.ksh
1848          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1849          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1850          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1851          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1852          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1853          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1854          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1855
1856          node_num=0
1857
1858          # We define the number of MPI process to be assigned for the component
1859
1860          nombre_restant_comp=${comp_proc_mpi_loc}
1861
1862          # Loop on the allocated nodes
1863
1864          for node in ${listnodes} ; do
1865
1866            # We go to the current node
1867            if [ ${node_num} = ${node_num_current} ] ; then
1868
1869              node_current=${host[${node_num_current}]}
1870
1871              # If first time on the node : initialisation
1872
1873              if [ ${init_node} = y ] ; then
1874                nombre_restant_node=${NUM_COREPERNODE}
1875              fi
1876
1877              # Test on the number of OMP threads
1878
1879              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1880                (( node_num = node_num + 1 ))
1881                node_num_current=${node_num}
1882                init_node=y
1883                continue
1884              fi
1885
1886              # Number of MPI process to assign
1887
1888              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1889
1890              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1891                num_corempi=${nombre_restant_comp}
1892              fi
1893
1894              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1895              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1896
1897              if [ ${init_exec} = y ] ; then
1898                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1899              else
1900                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1901                init_exec=y
1902              fi
1903
1904              ((  start_num = num_corempi + start_num ))
1905
1906            else
1907
1908              (( node_num = node_num + 1 ))
1909              continue
1910            fi
1911
1912            # Test on the number of core/process remaining on the node/component
1913
1914            if [ ${nombre_restant_node} = 0 ] ; then
1915              (( node_num = node_num + 1 ))
1916              node_num_current=${node_num}
1917              init_node=y
1918
1919              if [ ${nombre_restant_comp} = 0 ] ; then
1920                break 1
1921              fi
1922            else
1923
1924              node_num_current=${node_num}
1925              init_node=n
1926
1927              if [ ${nombre_restant_comp} = 0 ] ; then
1928                break 1
1929              fi
1930            fi
1931          done
1932        fi
1933      done
1934
1935    else
1936
1937        # Then first loop on the components for the coupler ie oasis
1938
1939        ## the coupler ie oasis must be the first one
1940        for comp in ${config_ListOfComponents[*]} ; do
1941
1942            eval ExeNameOut=\${config_Executable_${comp}[1]}
1943
1944        # for CPL component only
1945            if [ "X${comp}" = "XCPL" ] ; then
1946                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1947                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1948            fi
1949        done
1950
1951        # Then second loop on the components
1952
1953        for comp in ${config_ListOfComponents[*]} ; do
1954
1955            eval ExeNameOut=\${config_Executable_${comp}[1]}
1956
1957            # Only if we really have an executable for the component and not the coupler ie oasis:
1958            if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1959                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1960                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1961            fi
1962        done
1963        IGCM_sys_Chmod u+x run_file
1964
1965        EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1966
1967    fi
1968
1969  else # Only one executable. launch it.
1970
1971      for comp in ${config_ListOfComponents[*]} ; do
1972
1973          # Only if we really have an executable for the component :
1974          eval ExeNameOut=\${config_Executable_${comp}[1]}
1975###       if ( [ "X${ExeNameOut}" != X\"\" ] ) ; then
1976          if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1977
1978              echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1979              echo ""  >> script_${ExeNameOut}.ksh
1980              if ( ${OK_PARA_OMP} ) ; then
1981                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1982                  echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1983              fi
1984              if  ( ${OK_PARA_MPI} ) ; then
1985                  # Default : mpirun used if nb_proc gt 1
1986                  # pour sortie out/err par process
1987                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1988                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1989                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1990                  EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1991              else
1992                  # Default : mpirun is NOT used if nb_proc eq 1
1993                  # pour sortie out/err par process
1994                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1995                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1996                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1997                  EXECUTION="time ./script_${ExeNameOut}.ksh"
1998              fi
1999          fi
2000      done
2001
2002  fi
2003
2004  IGCM_debug_Print 1 "sys Titane : La commande d execution est "
2005  IGCM_debug_Print 1 $EXECUTION
2006
2007  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2008}
2009
2010############################################################
2011# Check of space available on temporary filesytems
2012function IGCM_sys_check_quota {
2013  IGCM_debug_PushStack "IGCM_sys_check_quota"
2014  if ( $DEBUG_sys ) ; then
2015    echo "IGCM_sys_check_quota "
2016  fi
2017  # Limit of quota (in %)
2018  limit_quota=90
2019
2020  # Check of the volume
2021  volume_quota=$(ccc_quota | grep ' scratch' | awk '{print $2}')
2022  volume_avail=$(ccc_quota | grep ' scratch' | awk '{print $3}')
2023
2024  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
2025
2026    unit_avail=${volume_avail: -1}
2027    unit_quota=${volume_quota: -1}
2028
2029    temp_avail=${volume_avail%%${volume_avail: -1}*}
2030    temp_quota=${volume_quota%%${volume_quota: -1}*}
2031
2032    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2033
2034    # Convertion
2035      if [ ${volume_avail: -1} = "T" ] ; then
2036        (( temp_avail = temp_avail * 1000000000000 ))
2037      elif [ ${volume_avail: -1} = "G" ] ; then
2038        (( temp_avail = temp_avail * 1000000000 ))
2039      elif [ ${volume_avail: -1} = "M" ] ; then
2040        (( temp_avail = temp_avail * 1000000 ))
2041      elif [ ${volume_avail: -1} = "k" ] ; then
2042        (( temp_avail = temp_avail * 1000 ))
2043      else
2044        (( temp_avail = volume_avail ))
2045      fi
2046      if [ ${volume_quota: -1} = "T" ] ; then
2047        (( temp_quota = temp_quota * 1000000000000 ))
2048      elif [ ${volume_quota: -1} = "G" ] ; then
2049        (( temp_quota = temp_quota * 1000000000 ))
2050      elif [ ${volume_quota: -1} = "M" ] ; then
2051        (( temp_quota = temp_quota * 1000000 ))
2052      elif [ ${volume_quota: -1} = "k" ] ; then
2053        (( temp_quota = temp_quota * 1000 ))
2054      else
2055        (( temp_quota = volume_quota ))
2056      fi
2057    fi
2058
2059    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2060#    echo "volume ratio is " $quota_volume
2061
2062    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2063      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2064      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2065      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2066      IGCM_debug_Print 1 "You must have more than 10% available to run"
2067      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2068      IGCM_debug_Verif_Exit
2069    fi
2070
2071  fi
2072
2073# Check of the number of inodes
2074
2075  inode_quota=$(ccc_quota | grep ' scratch' | awk '{print $6}')
2076  inode_avail=$(ccc_quota | grep ' scratch' | awk '{print $7}')
2077
2078  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
2079
2080    unit_avail=${inode_avail: -1}
2081    unit_quota=${inode_quota: -1}
2082
2083    temp_avail=${inode_avail%%${inode_avail: -1}*}
2084    temp_quota=${inode_quota%%${inode_quota: -1}*}
2085
2086    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2087
2088    # Convertion
2089      if [ ${inode_avail: -1} = "T" ] ; then
2090        (( temp_avail = temp_avail * 1000000000000 ))
2091      elif [ ${inode_avail: -1} = "G" ] ; then
2092        (( temp_avail = temp_avail * 1000000000 ))
2093      elif [ ${inode_avail: -1} = "M" ] ; then
2094        (( temp_avail = temp_avail * 1000000 ))
2095      elif [ ${inode_avail: -1} = "k" ] ; then
2096        (( temp_avail = temp_avail * 1000 ))
2097      else
2098        (( temp_avail = inode_avail ))
2099      fi
2100
2101      if [ ${inode_quota: -1} = "T" ] ; then
2102        (( temp_quota = temp_quota * 1000000000000 ))
2103      elif [ ${inode_quota: -1} = "G" ] ; then
2104        (( temp_quota = temp_quota * 1000000000 ))
2105      elif [ ${inode_quota: -1} = "M" ] ; then
2106        (( temp_quota = temp_quota * 1000000 ))
2107      elif [ ${inode_quota: -1} = "k" ] ; then
2108        (( temp_quota = temp_quota * 1000 ))
2109      else
2110        (( temp_quota = inode_quota ))
2111      fi
2112    fi
2113    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2114#    echo "inode ratio is " $quota_inode
2115
2116    if [ ${quota_inode} -ge ${limit_quota} ] ; then
2117      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2118      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
2119      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2120      IGCM_debug_Print 1 "You must have more than 10% available to run"
2121      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2122      IGCM_debug_Verif_Exit
2123    fi
2124
2125  fi
2126  IGCM_debug_PopStack "IGCM_sys_check_quota"
2127}
2128
2129##############################################################
2130# NCO OPERATOR
2131
2132function IGCM_sys_ncap2 {
2133  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2134  if ( $DEBUG_sys ) ; then
2135    echo "IGCM_sys_ncap2 :" $@
2136  fi
2137  ncap2 "$@"
2138  if [ $? -gt 0 ] ; then
2139    echo "IGCM_sys_ncap2 : erreur ${@}."
2140    IGCM_debug_Exit "ncap2"
2141  fi
2142
2143  IGCM_debug_PopStack "IGCM_sys_ncap2"
2144}
2145
2146function IGCM_sys_ncatted {
2147  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2148  if ( $DEBUG_sys ) ; then
2149    echo "IGCM_sys_ncatted :" $@
2150  fi
2151  ncatted "$@"
2152  if [ $? -gt 0 ] ; then
2153    echo "IGCM_sys_ncatted : erreur ${@}."
2154    IGCM_debug_Exit "ncatted"
2155  fi
2156
2157  IGCM_debug_PopStack "IGCM_sys_ncatted"
2158}
2159
2160function IGCM_sys_ncbo {
2161  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2162  if ( $DEBUG_sys ) ; then
2163    echo "IGCM_sys_ncbo :" $@
2164  fi
2165  ncbo $@
2166  if [ $? -gt 0 ] ; then
2167    echo "IGCM_sys_ncbo : erreur ${@}."
2168    IGCM_debug_Exit "ncbo"
2169  fi
2170
2171  IGCM_debug_PopStack "IGCM_sys_ncbo"
2172}
2173
2174function IGCM_sys_ncdiff {
2175  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2176  if ( $DEBUG_sys ) ; then
2177    echo "IGCM_sys_ncdiff :" $@
2178  fi
2179  ncdiff $@
2180  if [ $? -gt 0 ] ; then
2181    echo "IGCM_sys_ncdiff : erreur ${@}."
2182    IGCM_debug_Exit "ncdiff"
2183  fi
2184
2185  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2186}
2187
2188function IGCM_sys_ncea {
2189  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2190  if ( $DEBUG_sys ) ; then
2191    echo "IGCM_sys_ncea :" $@
2192  fi
2193  ncea $@
2194  if [ $? -gt 0 ] ; then
2195    echo "IGCM_sys_ncea : erreur ${@}."
2196    IGCM_debug_Exit "ncea"
2197  fi
2198
2199  IGCM_debug_PopStack "IGCM_sys_ncea"
2200}
2201
2202function IGCM_sys_ncecat {
2203  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2204  if ( $DEBUG_sys ) ; then
2205    echo "IGCM_sys_ncecat :" $@
2206  fi
2207  ncecat $@
2208  if [ $? -gt 0 ] ; then
2209    echo "IGCM_sys_ncecat : erreur ${@}."
2210    IGCM_debug_Exit "ncecat"
2211  fi
2212
2213  IGCM_debug_PopStack "IGCM_sys_ncecat"
2214}
2215
2216function IGCM_sys_ncflint {
2217  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2218  if ( $DEBUG_sys ) ; then
2219    echo "IGCM_sys_ncflint :" $@
2220  fi
2221  ncflint $@
2222  if [ $? -gt 0 ] ; then
2223    echo "IGCM_sys_ncflint : erreur ${@}."
2224    IGCM_debug_Exit "ncflint"
2225  fi
2226
2227  IGCM_debug_PopStack "IGCM_sys_ncflint"
2228}
2229
2230function IGCM_sys_ncks {
2231  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2232  if ( $DEBUG_sys ) ; then
2233    echo "IGCM_sys_ncks :" $@
2234  fi
2235  ncks $@
2236  if [ $? -gt 0 ] ; then
2237    echo "IGCM_sys_ncks : erreur ${@}."
2238    IGCM_debug_Exit "ncks"
2239  fi
2240
2241  IGCM_debug_PopStack "IGCM_sys_ncks"
2242}
2243
2244function IGCM_sys_ncpdq {
2245  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2246  if ( $DEBUG_sys ) ; then
2247    echo "IGCM_sys_ncpdq :" $@
2248  fi
2249  ncpdq $@
2250  if [ $? -gt 0 ] ; then
2251    echo "IGCM_sys_ncpdq : erreur ${@}."
2252    IGCM_debug_Exit "ncpdq"
2253  fi
2254
2255  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2256}
2257
2258function IGCM_sys_ncra {
2259  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2260  if ( $DEBUG_sys ) ; then
2261    echo "IGCM_sys_ncra :" $@
2262  fi
2263  ncra $@
2264  if [ $? -gt 0 ] ; then
2265    echo "IGCM_sys_ncra : erreur ${@}."
2266    IGCM_debug_Exit "ncra"
2267  fi
2268
2269  IGCM_debug_PopStack "IGCM_sys_ncra"
2270}
2271
2272function IGCM_sys_ncrcat {
2273  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2274  if ( $DEBUG_sys ) ; then
2275    echo "IGCM_sys_ncrcat :" $@
2276  fi
2277  ncrcat --omp_num_threads 2 $@
2278  if [ $? -gt 0 ] ; then
2279    echo "IGCM_sys_ncrcat : erreur ${@}."
2280#       IGCM_debug_Exit "ncrcat"
2281  fi
2282
2283  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2284}
2285
2286function IGCM_sys_ncrename {
2287  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2288  if ( $DEBUG_sys ) ; then
2289    echo "IGCM_sys_ncrename :" $@
2290  fi
2291  ncrename $@
2292  if [ $? -gt 0 ] ; then
2293    echo "IGCM_sys_ncrename : erreur ${@}."
2294    IGCM_debug_Exit "ncrename"
2295  fi
2296
2297  IGCM_debug_PopStack "IGCM_sys_ncrename"
2298}
2299
2300function IGCM_sys_ncwa {
2301  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2302  if ( $DEBUG_sys ) ; then
2303    echo "IGCM_sys_ncwa :" $@
2304  fi
2305  ncwa $@
2306  if [ $? -gt 0 ] ; then
2307    echo "IGCM_sys_ncwa : erreur ${@}."
2308    IGCM_debug_Exit "ncwa"
2309  fi
2310
2311  IGCM_debug_PopStack "IGCM_sys_ncwa"
2312}
2313
2314##############################################################
2315# CDO OPERATOR
2316
2317function IGCM_sys_cdo {
2318  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2319  if ( $DEBUG_sys ) ; then
2320    echo "IGCM_sys_cdo :" $@
2321  fi
2322  \cdo $@
2323  if [ $? -gt 0 ] ; then
2324    echo "IGCM_sys_cdo : erreur ${@}."
2325    IGCM_debug_PopStack "IGCM_sys_cdo"
2326    return 1
2327  else
2328    IGCM_debug_PopStack "IGCM_sys_cdo"
2329    return 0
2330  fi
2331
2332  IGCM_debug_PopStack "IGCM_sys_cdo"
2333}
Note: See TracBrowser for help on using the repository browser.