source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_mercurex9.ksh @ 782

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