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

Last change on this file since 801 was 801, checked in by sdipsl, 11 years ago
  • Some adaptation so as to find and prepare tared restart on Ada.
  • Property svn:keywords set to Revision Author Date
File size: 58.3 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_PrepareTaredRestart
1146#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1147#D-* Examples:
1148#D-
1149function IGCM_sys_PrepareTaredRestart {
1150  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1151  echo $1
1152  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1153}
1154
1155#D-#==================================================
1156#D-function IGCM_sys_Put_Out
1157#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1158#D-* Examples:
1159#D-
1160function IGCM_sys_Put_Out {
1161  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1162  if ( $DEBUG_sys ) ; then
1163    echo "IGCM_sys_Put_Out :" $@
1164  fi
1165
1166  typeset NB_ESSAI DELAI status i exist skip
1167
1168  # number of tentative
1169  NB_ESSAI=3
1170  # time delay between tentative
1171  DELAI=2
1172
1173  if [ $DRYRUN = 0 ]; then
1174    if [ ! -f ${1} ] ; then
1175      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1176      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1177      return 1
1178    fi
1179    #
1180    IGCM_sys_MkdirArchive $( dirname $2 )
1181    #
1182
1183    #=====================================================
1184    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1185    #=====================================================
1186
1187    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1188    #if [ $? -eq 0 ] ; then
1189    #    typeset WORKPATH FILEPATH
1190    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1191    #    IGCM_sys_MkdirWork ${WORKPATH}
1192    #    FILEPATH=${WORKPATH}/$( basename $2 )
1193    #    #
1194    #    IGCM_sys_Cp ${1} ${FILEPATH}
1195    #fi
1196
1197    if [ X${JobType} = XRUN ] ; then
1198      if [ X${3} = X ] ; then
1199        IGCM_sys_Chmod 444 ${1}
1200      fi
1201    fi
1202    #
1203
1204    exist=false
1205    skip=false
1206    if [ -f $2 ] ; then
1207      IGCM_debug_Print 1 "$2 already exist"
1208      #dmget $2
1209      ccc_hsm get $2
1210      exist=true
1211      if [ "X$( diff $1 $2 )" = X ] ; then
1212        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1213        skip=true
1214      else
1215        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1216        skip=false
1217      fi
1218    fi
1219    #
1220    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1221      IGCM_sys_Chmod u+w $2
1222    fi
1223
1224    if [ X${skip} = Xfalse ] ; then
1225      i=0
1226      while [ $i -lt $NB_ESSAI ] ; do
1227        # USUAL WAY
1228        \cp $1 $2 > out_rsync 2>&1
1229        status=$?
1230        if [ ${status} -gt 0 ]; then
1231          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1232          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1233          sleep $DELAI
1234        else
1235          break
1236        fi
1237        (( i = i + 1 ))
1238      done
1239    fi
1240
1241#       #RSYNC WITH NETWORK SSH CALL
1242#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1243#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1244
1245#       #RSYNC WITH NFS USE
1246#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1247#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1248
1249#       status=$?
1250#       IGCM_sys_Rsync_out $status
1251
1252#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1253#       (( status=status+$? ))
1254
1255    if [ ${status} -gt 0 ] ; then
1256      echo "IGCM_sys_Put_Out : error."
1257      cat out_rsync
1258      IGCM_debug_Exit "IGCM_sys_Put_Out"
1259    else
1260      \rm out_rsync
1261    fi
1262  else
1263    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1264  fi
1265  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1266  return 0
1267}
1268
1269#D-#==================================================
1270#D-function IGCM_sys_PutBuffer_Out
1271#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1272#D-* Examples:
1273#D-
1274function IGCM_sys_PutBuffer_Out {
1275  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1276  if ( $DEBUG_sys ) ; then
1277    echo "IGCM_sys_PutBuffer_Out :" $@
1278  fi
1279
1280  typeset NB_ESSAI DELAI status i exist skip
1281
1282  # number of tentative
1283  NB_ESSAI=3
1284  # time delay between tentative
1285  DELAI=2
1286
1287  if [ $DRYRUN = 0 ]; then
1288    if [ ! -f ${1} ] ; then
1289      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1290      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1291      return 1
1292    fi
1293    #
1294    IGCM_sys_Mkdir $( dirname $2 )
1295    #
1296
1297    if [ X${JobType} = XRUN ] ; then
1298      if [ X${3} = X ] ; then
1299        IGCM_sys_Chmod 444 ${1}
1300      fi
1301    fi
1302
1303    exist=false
1304    skip=false
1305    if [ -f $2 ] ; then
1306      IGCM_debug_Print 1 "$2 already exist"
1307      exist=true
1308      if [ "X$( diff $1 $2 )" = X ] ; then
1309        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1310        skip=true
1311      else
1312        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1313        skip=false
1314      fi
1315    fi
1316    #
1317    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1318      IGCM_sys_Chmod u+w $2
1319    fi
1320
1321    if [ X${skip} = Xfalse ] ; then
1322      i=0
1323      while [ $i -lt $NB_ESSAI ] ; do
1324        # USUAL WAY
1325        \cp $1 $2 > out_rsync 2>&1
1326        status=$?
1327        if [ ${status} -gt 0 ]; then
1328          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1329          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1330          sleep $DELAI
1331        else
1332          break
1333        fi
1334        (( i = i + 1 ))
1335      done
1336    fi
1337
1338    if [ ${status} -gt 0 ] ; then
1339      echo "IGCM_sys_PutBuffer_Out : error."
1340      cat out_rsync
1341      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1342    else
1343      \rm out_rsync
1344    fi
1345  else
1346    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1347  fi
1348  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1349  return 0
1350}
1351
1352#D-#==================================================
1353#D-function IGCM_sys_Get
1354#D-* Purpose: Get a file from ${ARCHIVE}
1355#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1356#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1357function IGCM_sys_Get {
1358  IGCM_debug_PushStack "IGCM_sys_Get" $@
1359
1360  typeset DEST dm_liste ifile target file_work
1361  typeset NB_ESSAI DELAI status i
1362
1363  if ( $DEBUG_sys ) ; then
1364    echo "IGCM_sys_Get :" $@
1365  fi
1366
1367  # number of tentative
1368  NB_ESSAI=3
1369  # time delay between tentative
1370  DELAI=2
1371
1372  if [ $DRYRUN -le 2 ]; then
1373    if [ X${1} = X'/l' ] ; then
1374      # test if the first file is present in the old computation :
1375      eval set +A dm_liste \${${2}}
1376    else
1377      eval set +A dm_liste ${1}
1378    fi
1379    eval DEST=\${${#}}
1380
1381    #=====================================================
1382    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1383    #=====================================================
1384
1385    # Is it an R_OUT file (not R_IN) ?
1386    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1387    #if [ $? -eq 0 ] ; then
1388    #    # Yes  ? then we try to get it in SCRATCHDIR
1389    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1390    #    if [ -f ${file_work[0]} ] ; then
1391    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1392    #   IGCM_debug_PopStack "IGCM_sys_Get"
1393    #   return
1394    #    fi
1395    #fi
1396
1397    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1398    status=$?
1399    if [ ${status} -gt 0 ] ; then
1400      echo "WARNING IGCM_sys_Get : error code ${status}"
1401      cat out_rsync
1402      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1403    fi
1404
1405    #if [ ${status} -gt 0 ] ; then
1406    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1407    #   cat out_rsync
1408    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1409    #   sleep 30
1410    #   echo "We try another time"
1411    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1412    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1413    #   status=$?
1414    #   if [ ${status} -gt 0 ] ; then
1415    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1416    #       cat out_rsync
1417    #       IGCM_debug_Exit "IGCM_sys_Get"
1418    #   fi
1419    #    else
1420    #   echo "ERROR IGCM_sys_Get : demigration error :"
1421    #   cat out_rsync
1422    #   IGCM_debug_Exit "IGCM_sys_Get"
1423    #    fi
1424    #fi
1425
1426    #   #RSYNC WITH NETWORK SSH CALL
1427    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1428    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1429
1430    #   #RSYNC WITH NFS USE
1431    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1432    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1433
1434    #   status=$?
1435    #   IGCM_sys_Rsync_out $status
1436
1437    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1438    #   (( status=status+$? ))
1439
1440    #USUAL WAY
1441    if [ X${1} = X'/l' ] ; then
1442      for target in ${dm_liste[*]} ; do
1443        local_file=$( basename ${target} )
1444        # test if the target file is present before the loop
1445        IGCM_sys_TestFileArchive ${target}
1446        status=$?
1447        if [ ${status} -gt 0 ] ; then
1448          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1449          IGCM_debug_Exit "IGCM_sys_Get"
1450        else
1451          i=0
1452          while [ $i -lt $NB_ESSAI ] ; do
1453            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1454            status=$?
1455            if [ ${status} -gt 0 ]; then
1456              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1457              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1458              sleep $DELAI
1459            else
1460              break
1461            fi
1462            (( i = i + 1 ))
1463          done
1464          if [ ${status} -gt 0 ] ; then
1465            echo "IGCM_sys_Get : error"
1466            cat out_rsync
1467            \rm out_rsync
1468            IGCM_debug_Exit "IGCM_sys_Get"
1469          else
1470            \rm out_rsync
1471          fi
1472        fi
1473      done
1474    else
1475      i=0
1476      while [ $i -lt $NB_ESSAI ] ; do
1477        \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1478        status=$?
1479        if [ ${status} -gt 0 ]; then
1480          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1481          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1482          sleep $DELAI
1483        else
1484          break
1485        fi
1486        (( i = i + 1 ))
1487      done
1488      if [ ${status} -gt 0 ] ; then
1489        echo "IGCM_sys_Get : error"
1490        cat out_rsync
1491        \rm out_rsync
1492        IGCM_debug_Exit "IGCM_sys_Get"
1493      else
1494        \rm out_rsync
1495      fi
1496    fi
1497  else
1498    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1499  fi
1500  IGCM_debug_PopStack "IGCM_sys_Get"
1501}
1502
1503#D-#==================================================
1504#D-function IGCM_sys_GetBuffer
1505#D-* Purpose: Get a file from ${SCRATCHDIR}
1506#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1507#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1508function IGCM_sys_GetBuffer {
1509  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1510
1511  typeset DEST buf_liste ifile target file_work
1512  typeset NB_ESSAI DELAI status i
1513
1514  if ( $DEBUG_sys ) ; then
1515    echo "IGCM_sys_GetBuffer :" $@
1516  fi
1517
1518  # number of tentative
1519  NB_ESSAI=3
1520  # time delay between tentative
1521  DELAI=2
1522
1523  if [ $DRYRUN -le 2 ]; then
1524    if [ X${1} = X'/l' ] ; then
1525      # test if the first file is present in the old computation :
1526      eval set +A buf_liste \${${2}}
1527    else
1528      eval set +A buf_liste ${1}
1529    fi
1530    eval DEST=\${${#}}
1531
1532    #USUAL WAY
1533    if [ X${1} = X'/l' ] ; then
1534      for target in ${buf_liste[*]} ; do
1535        local_file=$( basename ${target} )
1536        i=0
1537        while [ $i -lt $NB_ESSAI ] ; do
1538          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1539          status=$?
1540          if [ ${status} -gt 0 ]; then
1541            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1542            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1543            sleep $DELAI
1544          else
1545            break
1546          fi
1547          (( i = i + 1 ))
1548        done
1549        if [ ${status} -gt 0 ] ; then
1550          echo "IGCM_sys_Get : error"
1551          cat out_rsync
1552          \rm out_rsync
1553          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1554        else
1555          \rm out_rsync
1556        fi
1557      done
1558    else
1559      i=0
1560      while [ $i -lt $NB_ESSAI ] ; do
1561        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1562        status=$?
1563        if [ ${status} -gt 0 ]; then
1564          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1565          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1566          sleep $DELAI
1567        else
1568          break
1569        fi
1570        (( i = i + 1 ))
1571      done
1572      if [ ${status} -gt 0 ] ; then
1573        echo "IGCM_sys_Get : error"
1574        cat out_rsync
1575        \rm out_rsync
1576        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1577      else
1578        \rm out_rsync
1579      fi
1580    fi
1581  else
1582    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1583  fi
1584  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1585}
1586
1587#D-#==================================================
1588#D-function IGCM_sys_GetDate_FichWork
1589#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1590#D-* Examples:
1591#D-
1592function IGCM_sys_GetDate_FichWork {
1593  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1594  if ( $DEBUG_sys ) ; then
1595    echo "IGCM_sys_GetDate_FichWork :" $@
1596  fi
1597  typeset dateF
1598  set +A dateF -- $( IGCM_sys_RshMaster "ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1}" )
1599  eval ${2}=${dateF[5]}
1600
1601    # donne la date filesys d'un fichier sur la machine work
1602  IGCM_debug_PopStack "IGCM_sys_FichWork"
1603}
1604
1605#D-#==================================================
1606#D-function IGCM_sys_GetDate_FichArchive
1607#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1608#D-* Examples:
1609#D-
1610function IGCM_sys_GetDate_FichArchive {
1611  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1612  if ( $DEBUG_sys ) ; then
1613    echo "IGCM_sys_GetDate_FichArchive :" $@
1614  fi
1615  typeset dateF
1616  set +A dateF -- $( IGCM_sys_RshMaster "ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1}" )
1617  eval ${2}=${dateF[5]}
1618
1619  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1620}
1621
1622##############################################################
1623# REBUILD OPERATOR
1624
1625function IGCM_sys_rebuild {
1626  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1627  if ( $DEBUG_sys ) ; then
1628    echo "IGCM_sys_rebuild :" $@
1629  fi
1630
1631  typeset NB_ESSAI DELAI status i firstArg
1632  # number of tentative
1633  NB_ESSAI=3
1634  # time delay between tentative
1635  DELAI=2
1636
1637  i=0
1638  while [ $i -lt $NB_ESSAI ] ; do
1639      /home/cont003/p86ipsl/SX8/bin/rebuild -f -o $@ > out_rsync 2>&1
1640    status=$?
1641    if [ ${status} -gt 0 ] ; then
1642      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1643      cat out_rsync
1644      \rm out_rsync
1645      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1646      firstArg=${1}
1647      \rm ${firstArg}
1648      sleep $DELAI
1649    else
1650      \rm out_rsync
1651      break
1652    fi
1653    (( i = i + 1 ))
1654  done
1655
1656  if [ ${status} -gt 0 ] ; then
1657    echo "IGCM_sys_rebuild : rebuild error"
1658    IGCM_debug_Exit "rebuild"
1659  fi
1660
1661  IGCM_debug_PopStack "IGCM_sys_rebuild"
1662}
1663
1664function IGCM_sys_rebuild_station {
1665  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1666  typeset i list_opt file_in file_out prefix_invert list_invert
1667  if ( $DEBUG_sys ) ; then
1668    echo "IGCM_sys_rebuild_station :" $@
1669  fi
1670  list_opt=$@
1671
1672  # Invert Axis : t,x -> x,t
1673  #               t,pres,x -> x,t,pres
1674  # So that we can concatenate along x
1675  i=0
1676  for file_in in ${list_opt} ; do
1677    (( i = i + 1))
1678    [ ${i} = 1 ] && file_out=${file_in} && continue
1679    prefix_invert=$( basename ${file_in} .nc )
1680    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1681    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1682  done
1683
1684  # Concatenate
1685  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1686
1687  # Re-ivert file
1688  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1689
1690  # Station re-ordering is too expansive to be run within libICGM
1691  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1692  # This re-ordering must be done "in memory" by the cmorization process
1693  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1694  # BEGIN reordering
1695
1696  # Only LMDZ text output contains the exact ordering of the station.
1697  # We isolate this in the code below:
1698  #  0  38  -157.5000000000000  70.98591549295774
1699  #  0  54  27.49999999999999   67.18309859154928
1700  #  0  56  -62.50000000000001  82.39436619718309
1701  #  0  79  12.49999999999999   78.59154929577466
1702  #  0  116 -165.0000000000000  76.05633802816901
1703  #  0  117 130.0000000000000   70.98591549295774
1704  #  0  118 110.0000000000000   87.46478873239437
1705  #  1  40  4.999999999999995   51.97183098591550
1706#  typeset iStation iProc list_opt file_in file_out prefix_invert
1707#  typeset -Z4 j4
1708#  typeset -Z3 j3
1709
1710#  unset list_opt
1711#  set +A list_opt $@
1712
1713  # Filename after rebuild
1714#  file_out=${list_opt[0]}
1715  # Prefix of output files
1716#  prefix_invert=$( basename ${file_out} .nc )
1717  # Number of procs
1718#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1719
1720#  iProc=0
1721#  while [ ${iProc} -lt ${num_proc} ] ; do
1722    # Array containing Station as a number
1723#    unset proc_stn
1724#    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}' )
1725    # Number of stations produced by processor proc
1726#    stationLast=${#proc_stn[*]}
1727    # Proc number on 4 digits
1728#    j4=${iProc}
1729    # Init
1730#    iStation=0
1731#    while [ ${iStation} -lt ${stationLast} ] ; do
1732      # Station number on 3 digits
1733#      j3=${proc_stn[${iStation}]}
1734      # Extract station
1735      # Invert Axis : t,x -> x,t
1736      #               t,pres,x -> x,t,pres
1737      # So that we can concatenate along x
1738#      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
1739#      (( iStation = iStation + 1 ))
1740#    done
1741#    (( iProc = iProc + 1 ))
1742#  done
1743
1744  # Concatenate all station along x
1745#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1746
1747  # Re-invert file
1748#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1749
1750  # END reordering
1751
1752  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1753}
1754
1755############################################################
1756# Activate Running Environnment Variables
1757
1758function IGCM_sys_activ_variables {
1759  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1760  if ( $DEBUG_sys ) ; then
1761    echo "IGCM_sys_activ_variables"
1762  fi
1763
1764# --------------------------------------------------------------------
1765#D- MPI specifications
1766# --------------------------------------------------------------------
1767
1768#D-- MPISUSPEND
1769  export MPISUSPEND=${MPISUSPEND:=OFF}
1770
1771#D-- MPIPROGINF #other choices : ALL_DETAIL2
1772  export MPIPROGINF=ALL
1773#D- activate ftrace (with -ftrace)
1774  export F_FTRACE=YES
1775#D- communication information (with -ftrace)
1776  export MPICOMMINF=DETAIL
1777
1778# --------------------------------------------------------------------
1779#D- Other specifications
1780# --------------------------------------------------------------------
1781
1782#D- max number of character/line in output job
1783  export F_SYSLEN=5000
1784#D- number of error that can be admitted on the NEC
1785  export F_ERRCNT=0
1786#D- global performance
1787  export F_PROGINF=DETAIL
1788
1789#D- I/O performance (FORTRAN I/O only not netCDF)
1790  export F_FILEINF=${F_FILEINF:=NO}
1791#D- netCDF I/O performance
1792  export NC_FILEINF=${NC_FILEINF:=NO}
1793
1794  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1795}
1796
1797############################################################
1798# Desactivate Running Environnment Variables
1799
1800function IGCM_sys_desactiv_variables {
1801  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1802  if ( $DEBUG_sys ) ; then
1803    echo "IGCM_sys_desactiv_variables"
1804  fi
1805# --------------------------------------------------------------------
1806#D- MPI specifications
1807# --------------------------------------------------------------------
1808
1809#D-- MPIPROGINF
1810  export MPIPROGINF=NO
1811
1812# --------------------------------------------------------------------
1813#D- Other specifications
1814# --------------------------------------------------------------------
1815
1816#D- global performance
1817  export F_PROGINF=NO 
1818
1819  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1820}
1821
1822############################################################
1823# Build MPI/OMP scripts
1824function IGCM_sys_build_execution_scripts
1825{
1826  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1827  if ( $DEBUG_sys ) ; then
1828    echo "IGCM_sys_build_execution_scripts " $@
1829  fi
1830
1831  typeset NbNodes_Job NbProc_Job comp_proc_mpi_loc comp_proc_omp_loc mpi_count
1832 
1833  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1834    IGCM_debug_Exit "IGCM_sys_mercurex9 build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1835  fi
1836
1837  if ( ${OK_PARA_MPMD} ) ; then
1838
1839    if [ -f run_file ] ; then
1840      IGCM_sys_Rm -f run_file
1841    fi
1842    touch run_file
1843
1844    if ( ${OK_PARA_OMP} ) ; then
1845      IGCM_debug_Print 2 "Error in config.card on SX9 : OpenMP not available"
1846      exit 1
1847    else
1848# OLD :
1849#PBS -v BATCH_NUM_PROC_TOT=4
1850#PBS -l cpunum_job=${BATCH_NUM_PROC_TOT}
1851      echo "Job_${config_UserChoices_JobName} includes BATCH_NUM_PROC_TOT = \c"
1852      cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep -- "-v *BATCH_NUM_PROC_TOT" | sed -e "s/.*BATCH_NUM_PROC_TOT *= *//" 
1853      NbProc_Job=$( cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep -- "-v *BATCH_NUM_PROC_TOT" | sed -e "s/.*BATCH_NUM_PROC_TOT *= *//" )
1854      NbProc_Job=${NbProc_Job:=0}
1855      if [ ${NbProc_Job} -eq 0 ] ; then
1856        IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources : no BATCH_NUM_PROC_TOT defined with MPI only run."
1857        exit 1
1858      fi
1859    fi
1860
1861# run_file construction
1862
1863# Then first loop on the components for the coupler ie oasis
1864
1865### the coupler ie oasis must be the first one
1866    for comp in ${config_ListOfComponents[*]} ; do
1867     
1868      eval ExeNameIn=\${config_Executable_${comp}[0]}
1869      eval ExeNameOut=\${config_Executable_${comp}[1]}
1870     
1871      # for CPL component only
1872      if [ "X${comp}" = "XCPL" ] ; then
1873
1874        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1875        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1876       
1877        if ( ${OK_PARA_MPI} ) ; then
1878          echo "-p ${comp_proc_mpi_loc} -e ./${ExeNameOut}" >> run_file
1879        fi
1880      fi
1881    done
1882
1883# Then second loop on the components
1884
1885    for comp in ${config_ListOfComponents[*]} ; do
1886     
1887      eval ExeNameIn=\${config_Executable_${comp}[0]}
1888      eval ExeNameOut=\${config_Executable_${comp}[1]}
1889     
1890      # Only if we really have an executable for the component and not the coupler ie oasis:
1891      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1892
1893        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1894        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1895       
1896        if ( ${OK_PARA_MPI} ) ; then
1897          echo "-p ${comp_proc_mpi_loc} -e ./${ExeNameOut}" >> run_file
1898        fi
1899      fi
1900    done
1901
1902    EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1903
1904    IGCM_sys_Chmod u+x run_file
1905    if ( $DEBUG_sys ) ; then
1906      echo "run_file contains : "
1907      cat run_file
1908    fi
1909
1910  else # Only one executable. launch it.
1911
1912    for comp in ${config_ListOfComponents[*]} ; do
1913
1914      eval ExeNameIn=\${config_Executable_${comp}[0]}
1915      eval ExeNameOut=\${config_Executable_${comp}[1]}
1916
1917      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1918        EXECUTION="time mpirun -np ${BATCH_NUM_PROC_TOT} ./${ExeNameOut}"
1919      fi
1920    done
1921
1922  fi
1923
1924  IGCM_debug_Print 1 "sys mercurex9 : execution command is "
1925  IGCM_debug_Print 1 "$EXECUTION"
1926
1927  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1928
1929}
1930
1931function IGCM_sys_build_run_file {
1932
1933IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1934
1935}
1936
1937############################################################
1938# Check of space available on temporary filesytems
1939function IGCM_sys_check_quota {
1940  IGCM_debug_PushStack "IGCM_sys_check_quota" 
1941
1942  if ( $DEBUG_sys ) ; then
1943    echo "IGCM_sys_check_quota "
1944  fi
1945  # Limit of quota (in %)
1946  limit_quota=95
1947
1948  # Check of the volume (use of RshMaster waiting for ccc_quota command available on SX9 nodes)
1949#  volume_quota=$( IGCM_sys_RshMaster "/applications/ccc-tools/ccc_quota | grep ' scratch' | awk '{print \$2}'" )
1950#  volume_avail=$( IGCM_sys_RshMaster "/applications/ccc-tools/ccc_quota | grep ' scratch' | awk '{print \$3}'" )
1951
1952  volume_quota=$(quota -h | grep 'scratch' | awk '{print $2}')
1953  volume_avail=$(quota -h | grep 'scratch' | awk '{print $3}')
1954
1955  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
1956
1957    unit_quota=$( echo $volume_quota | awk '{print(substr($0, length($0), length($0)))}' )
1958    unit_avail=$( echo $volume_avail | awk '{print(substr($0, length($0), length($0)))}' )
1959
1960    if [ "${unit_quota}" = "*" ] ; then
1961        IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1962        IGCM_debug_Print 1 "More than 100% of your quota is used"
1963        IGCM_debug_Print 1 "Use the ccc_quota command to check"
1964        IGCM_debug_Print 1 "You must have more than 10% available to run"
1965        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1966        IGCM_debug_Verif_Exit
1967    fi
1968
1969    temp_avail=${volume_avail%%${unit_avail}*}
1970    temp_quota=${volume_quota%%${unit_quota}*}
1971
1972    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1973
1974    # Convertion
1975      if [ ${unit_avail} = "T" ] ; then
1976          (( temp_avail = temp_avail * 1000000000000 ))
1977      elif [ ${unit_avail} = "G" ] ; then
1978          (( temp_avail = temp_avail * 1000000000 ))
1979      elif [ ${unit_avail} = "M" ] ; then
1980          (( temp_avail = temp_avail * 1000000 ))
1981      elif [ ${unit_avail} = "k" ] ; then
1982          (( temp_avail = temp_avail * 1000 ))
1983      else
1984          (( temp_avail = volume_avail ))
1985      fi
1986      if [ ${unit_quota} = "T" ] ; then
1987          (( temp_quota = temp_quota * 1000000000000 ))
1988      elif [ ${unit_quota} = "G" ] ; then
1989          (( temp_quota = temp_quota * 1000000000 ))
1990      elif [ ${unit_quota} = "M" ] ; then
1991          (( temp_quota = temp_quota * 1000000 ))
1992      elif [ ${unit_quota} = "k" ] ; then
1993          (( temp_quota = temp_quota * 1000 ))
1994      else
1995          (( temp_quota = volume_quota ))
1996      fi
1997    fi
1998
1999    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2000#    echo "volume ratio is " $quota_volume
2001
2002    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2003      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2004      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2005      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2006      IGCM_debug_Print 1 "You must have more than 10% available to run"
2007      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2008      IGCM_debug_Verif_Exit
2009    fi
2010
2011  fi
2012  IGCM_debug_PopStack "IGCM_sys_check_quota"
2013}
Note: See TracBrowser for help on using the repository browser.