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

Last change on this file since 582 was 582, checked in by sdipsl, 12 years ago
  • Put output in the buffer as well, together with restart and debug files
  • Post-process mercure sx9 on mercure front-end
  • Property svn:keywords set to Revision Author Date
File size: 41.4 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# rsync with path
81typeset -r RSYNC=/home/cont003/p86denv/SX_RSYNC/bin/rsync
82# RSYNC_opt args to rsync
83typeset -r RSYNC_opt="-va"
84# ie storage filesystem
85typeset -r STOREHOST=${MASTER}
86
87#====================================================
88# Host specific DIRECTORIES
89#====================================================
90
91#====================================================
92#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
93typeset -r R_EXE="${MODIPSL}/bin"
94
95#====================================================
96#- SUBMIT_DIR : submission dir
97typeset SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
98
99#====================================================
100#- ARCHIVE
101typeset -r ARCHIVE=${DMFDIR}
102
103# ============ CESIUM START ============ #
104
105#====================================================
106#- Mirror libIGCM from mercure to cesium if needed
107ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
108if [ ! ${ROOTSYS} = "home" ] ; then
109  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
110else
111  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
112fi
113
114#====================================================
115#- libIGCM_POST
116if ( ${MirrorlibIGCM} ) ; then
117  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
118  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
119else
120  typeset -r libIGCM_POST=${libIGCM}
121fi
122
123# ============ CESIUM  END  ============ #
124
125#====================================================
126#- MirrorlibIGCM uncomment for frontend
127#typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
128
129#====================================================
130#- libIGCM_POST uncomment for frontend
131#typeset -r libIGCM_POST=${libIGCM}
132
133#====================================================
134#- IN
135typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
136typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
137
138#====================================================
139#- R_OUT
140typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
141
142#====================================================
143#- R_BUF (ONLY FOR double copy an scratch)
144typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
145
146#====================================================
147#- BIG_DIR : BIG_DIR to store files waiting for rebuild
148typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
149
150#====================================================
151#- OUT_POST
152typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
153
154#====================================================
155#- RUN_DIR_PATH : Temporary working directory (=> TMP)
156typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${LOCALTMPDIR}}
157
158#====================================================
159#- HOST_MPIRUN_COMMAND
160typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="mpirun"}
161
162#====================================================
163#- Max number of arguments passed to nco operator or demigration command
164UNIX_MAX_LIMIT=360
165
166#D-#==================================================
167#D-function IGCM_sys_RshMaster
168#D-* Purpose: Connection to frontend machine.
169#D-* Examples:
170#D-
171function IGCM_sys_RshMaster {
172  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
173  ssh -t ${MASTER} /bin/ksh <<-EOF
174  export libIGCM=${libIGCM}
175  export DEBUG_debug=${DEBUG_debug}
176  . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
177  . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
178  ${@}
179EOF
180  if [ $? -gt 0 ] ; then
181    echo "IGCM_sys_RshMaster : erreur."
182    IGCM_debug_Exit "IGCM_sys_RshMaster"
183  fi
184  IGCM_debug_PopStack "IGCM_sys_RshMaster"
185}
186
187#D-#==================================================
188#D-function IGCM_sys_RshArchive
189#D-* Purpose: Archive rsh command
190#D-* Examples:
191#D-
192function IGCM_sys_RshArchive {
193  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
194  /bin/ksh <<-EOF
195    ${@}
196EOF
197  if [ $? -gt 0 ] ; then
198    echo "IGCM_sys_RshArchive : erreur."
199    IGCM_debug_Exit "IGCM_sys_RshArchive"
200  fi
201  IGCM_debug_PopStack "IGCM_sys_RshArchive"
202}
203
204#D-#==================================================
205#D-function IGCM_sys_RshPost
206#D-* Purpose: Post-process rsh command
207#D-* Examples:
208#D-
209function IGCM_sys_RshPost {
210  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
211  if ( $DEBUG_sys ) ; then
212    echo "IGCM_sys_RshPost :" $@
213  fi
214
215  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
216  #cat tmp_IGCM_sys_RshPost_$$
217  # keep standard input (stdin) for the loop onto temporary file
218  cat >tmp_IGCM_sys_RshPost_$$
219
220# ============ FRONTEND START ============ #
221
222  /bin/ksh <tmp_IGCM_sys_RshPost_$$
223  if [ $? -gt 0 ] ; then
224    echo "IGCM_sys_RshPost : erreur."
225    IGCM_debug_Exit "IGCM_sys_RshPost"
226  fi
227  \rm tmp_IGCM_sys_RshPost_$$
228
229# ============ FRONTEND  END  ============ #
230
231# ============ CESIUM START ============ #
232#  typeset NB_ESSAI DELAI status i
233#  # number of tentative
234#  NB_ESSAI=10
235#  # time delay between tentative
236#  DELAI=10
237#  (( i = 0 ))
238#  while [ $i -lt $NB_ESSAI ] ; do
239#    ssh -t mercure01 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
240#    status=$?
241#    if [ ${status} -gt 0 ]; then
242#      IGCM_debug_Print 2 "IGCM_sys_RshPost : ssh failed ${i}/${NB_ESSAI}"
243#      IGCM_debug_Print 2 "IGCM_sys_RshPost : sleep ${DELAI} seconds and try again."
244#      sleep $DELAI
245#    else
246#      break
247#    fi
248#    (( i = i + 1 ))
249#  done
250#  # delete temporary file
251#  /bin/rm tmp_IGCM_sys_RshPost_$$
252# ============ CESIUM  END  ============ #
253
254  IGCM_debug_PopStack "IGCM_sys_RshPost"
255}
256
257#D-#==================================================
258#D-function IGCM_sys_SendMail
259#D-* Purpose: Send mail when simulation is over
260#D-* Examples:
261#D-
262function IGCM_sys_SendMail {
263  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
264  if ( $DEBUG_sys ) ; then
265    echo "IGCM_sys_SendMail :" $@
266  fi
267
268  if ( ${ExitFlag} ) ; then
269    status=failed
270  else
271    status=completed
272  fi
273  cat  << END_MAIL > job_end.mail
274  Dear ${LOGIN},
275
276  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
277  Job started : ${DateBegin}
278  Job ended   : ${DateEnd}
279  Output files are available in ${R_SAVE}
280  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
281END_MAIL
282
283  if  [ X"${config_UserChoices_MailName}" != X ] ; then
284    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
285  elif [ -f ~/.forward ] ; then
286    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
287  else
288    mailx -s "${config_UserChoices_JobName} ${status}" ${LOGIN} < job_end.mail
289  fi
290
291  if [ $? -gt 0 ] ; then
292    echo "IGCM_sys_SendMail : erreur."
293    IGCM_debug_Exit "IGCM_sys_SendMail"
294  fi
295  IGCM_debug_PopStack "IGCM_sys_SendMail"
296}
297
298#D-#==================================================
299#D-function IGCM_sys_Mkdir
300#D-* Purpose: Master locale mkdir command
301#D-* Examples:
302#D-
303function IGCM_sys_Mkdir {
304  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
305  if ( $DEBUG_sys ) ; then
306    echo "IGCM_sys_Mkdir :" $@
307  fi
308  if [ ! -d ${1} ]; then
309    \mkdir -p $1
310    if [ $? -gt 0 ] ; then
311      echo "IGCM_sys_Mkdir : erreur."
312      IGCM_debug_Exit "IGCM_sys_Mkdir"
313    fi
314  fi
315  # vérification :
316  if [ ! -d ${1} ] ; then
317    echo "IGCM_sys_Mkdir : erreur."
318    IGCM_debug_Exit "IGCM_sys_Mkdir"
319  fi
320  IGCM_debug_PopStack "IGCM_sys_Mkdir"
321}
322
323#D-#==================================================
324#D-function IGCM_sys_MkdirArchive
325#D-* Purpose: Mkdir on Archive
326#D-* Examples:
327#D-
328function IGCM_sys_MkdirArchive {
329  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
330  if ( $DEBUG_sys ) ; then
331    echo "IGCM_sys_MkdirArchive :" $@
332  fi
333  #- creation de repertoire sur le serveur fichier
334  if [ ! -d ${1} ]; then 
335    \mkdir -p $1
336    if [ $? -gt 0 ] ; then
337      echo "IGCM_sys_MkdirArchive : erreur."
338      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
339    fi
340  fi
341  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
342}
343
344#D-#==================================================
345#D-function IGCM_sys_MkdirWork
346#D-* Purpose: Mkdir on Work
347#D-* Examples:
348#D-
349function IGCM_sys_MkdirWork {
350  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
351  if ( $DEBUG_sys ) ; then
352    echo "IGCM_sys_MkdirWork :" $@
353  fi
354  #- creation de repertoire sur le serveur fichier
355  if [ ! -d ${1} ]; then 
356    \mkdir -p $1
357    if [ $? -gt 0 ] ; then
358      echo "IGCM_sys_MkdirWork : erreur."
359      IGCM_debug_Exit "IGCM_sys_MkdirWork"
360    fi
361  fi
362  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
363}
364
365#D-#==================================================
366#D-function IGCM_sys_Cd
367#D-* Purpose: master cd command
368#D-* Examples:
369#D-
370function IGCM_sys_Cd {
371  IGCM_debug_PushStack "IGCM_sys_Cd" $@
372  if ( $DEBUG_sys ) ; then
373    echo "IGCM_sys_Cd :" $@
374  fi
375  \cd $1
376  if [ $? -gt 0 ] ; then
377    echo "IGCM_sys_Cd : erreur."
378    IGCM_debug_Exit "IGCM_sys_Cd"
379  fi
380  IGCM_debug_PopStack "IGCM_sys_Cd"
381}
382
383#D-#==================================================
384#D-function IGCM_sys_Chmod
385#D-* Purpose: Chmod
386#D-* Examples:
387#D-
388function IGCM_sys_Chmod {
389  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
390  if ( $DEBUG_sys ) ; then
391    echo "IGCM_sys_Chmod :" $@
392  fi
393  if [ $DRYRUN -le 1 ]; then
394    \chmod $@
395    if [ $? -gt 0 ] ; then
396      echo "IGCM_sys_Chmod : erreur."
397      IGCM_debug_Exit "IGCM_sys_Chmod"
398    fi
399  else
400    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
401  fi
402  IGCM_debug_PopStack "IGCM_sys_Chmod"
403}
404
405#D-#==================================================
406#D-function IGCM_sys_FileSize
407#D-* Purpose: Filesize
408#D-* Examples:
409#D-
410function IGCM_sys_FileSize {
411  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
412
413  typeset sizeF
414  set +A sizeF -- $( ls -la ${1} )
415  if [ $? -gt 0 ] ; then
416    IGCM_debug_Exit "IGCM_sys_FileSize"
417  fi
418  eval ${2}=${sizeF[4]}
419
420  IGCM_debug_PopStack "IGCM_sys_FileSize"
421}
422
423#D-#==================================================
424#D-function IGCM_sys_TestDir
425#D-* Purpose: Test Directory that must exists
426#D-* Examples:
427#D-
428function IGCM_sys_TestDir {
429  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
430  if ( $DEBUG_sys ) ; then
431    echo "IGCM_sys_TestDir :" $@
432  fi
433  typeset ExistFlag
434  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
435  IGCM_debug_PopStack "IGCM_sys_TestDir"
436
437  return ${ExistFlag}
438}
439
440#D-#==================================================
441#D-function IGCM_sys_TestDirArchive
442#D-* Purpose: Test Directory that must exists on Archive
443#D-* Examples:
444#D-
445function IGCM_sys_TestDirArchive {
446  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
447  if ( $DEBUG_sys ) ; then
448    echo "IGCM_sys_TestDirArchive :" $@
449  fi
450  typeset ExistFlag
451  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
452  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
453
454  return ${ExistFlag}
455}
456
457#D-#==================================================
458#D-function IGCM_sys_IsFileArchived
459#D-* Purpose: Test file that must NOT EXISTS on Archive
460#D-* Examples:
461#D-
462function IGCM_sys_IsFileArchived {
463  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
464  if ( $DEBUG_sys ) ; then
465    echo "IGCM_sys_IsFileArchived :" $@
466  fi
467  typeset IsArchivedFlag
468  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/dmnfs ) != X ] && echo 0 || echo 1 )
469  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
470
471  return ${IsArchivedFlag}
472}
473
474#D-#==================================================
475#D-function IGCM_sys_TestFileArchive
476#D-* Purpose: Test file that must NOT EXISTS on Archive
477#D-* Examples:
478#D-
479function IGCM_sys_TestFileArchive {
480  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
481  if ( $DEBUG_sys ) ; then
482    echo "IGCM_sys_TestFileArchive :" $@
483  fi
484  typeset ExistFlag
485  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
486  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
487
488  return ${ExistFlag}
489}
490
491#D-#==================================================
492#D-function IGCM_sys_TestFileBuffer
493#D-* Purpose: Test file that must NOT EXISTS on Buffer
494#D-* Examples:
495#D-
496function IGCM_sys_TestFileBuffer {
497  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
498  typeset ExistFlag
499  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
500  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
501
502  return ${ExistFlag}
503}
504
505#D-#==================================================
506#D-function IGCM_sys_CountFileArchive
507#D-* Purpose: Count files on Archive filesystem
508#D-* Examples:
509#D-
510function IGCM_sys_CountFileArchive {
511  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
512  ls ${@} 2>/dev/null | wc -l
513  if [ $? -gt 0 ] ; then
514    echo "IGCM_sys_CountFileArchive : erreur."
515  fi
516  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
517}
518
519#D-#==================================================
520#D-function IGCM_sys_CountFileBuffer
521#D-* Purpose: Count files on Scratch filesystem
522#D-* Examples:
523#D-
524function IGCM_sys_CountFileBuffer {
525  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
526  ls ${@} 2>/dev/null | wc -l
527  if [ $? -gt 0 ] ; then
528    echo "IGCM_sys_CountFileBuffer : erreur."
529  fi
530  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
531}
532
533#D-#==================================================
534#D-function IGCM_sys_Tree
535#D-* Purpose: Tree directories with files on ${ARCHIVE}
536#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
537#D-
538function IGCM_sys_Tree {
539  IGCM_debug_PushStack "IGCM_sys_Tree" $@
540  if ( $DEBUG_sys ) ; then
541    echo "IGCM_sys_Tree :" $@
542  fi
543
544  \ls -lR ${@}
545
546  IGCM_debug_PopStack "IGCM_sys_Tree"
547}
548
549#D-#==================================================
550#D-function IGCM_sys_Tar
551#D-* Purpose: master tar command
552#D-* Examples:
553#D-
554function IGCM_sys_Tar {
555  IGCM_debug_PushStack "IGCM_sys_Tar" $@
556  if ( $DEBUG_sys ) ; then
557    echo "IGCM_sys_Tar :" $@
558  fi
559  \tar cf $@
560  if [ $? -gt 0 ] ; then
561    echo "IGCM_sys_Tar : erreur."
562    IGCM_debug_Exit "IGCM_sys_Tar"
563  fi
564  IGCM_debug_PopStack "IGCM_sys_Tar"
565}
566
567#D-#==================================================
568#D-function IGCM_sys_UnTar
569#D-* Purpose: master un-tar command
570#D-* Examples:
571#D-
572function IGCM_sys_UnTar {
573  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
574  if ( $DEBUG_sys ) ; then
575    echo "IGCM_sys_UnTar :" $@
576  fi
577  \tar xvf $1
578  if [ $? -gt 0 ] ; then
579    echo "IGCM_sys_UnTar : erreur."
580    IGCM_debug_Exit "IGCM_sys_UnTar"
581  fi
582  IGCM_debug_PopStack "IGCM_sys_UnTar"
583}
584
585#D-#==================================================
586#D-function IGCM_sys_Qsub
587#D-* Purpose: Qsub new job
588#D-* Examples:
589#D-
590function IGCM_sys_Qsub {
591  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
592  if ( $DEBUG_sys ) ; then
593    echo "IGCM_sys_Qsub :" $@
594  fi
595  /usr/bin/nqsII/qsub -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} < $1
596  if [ $? -gt 0 ] ; then
597    echo "IGCM_sys_Qsub : erreur -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} $@."
598    IGCM_debug_Exit "IGCM_sys_Qsub"
599  fi
600  IGCM_debug_PopStack "IGCM_sys_Qsub"
601}
602
603#D-#==================================================
604#D-function IGCM_sys_QsubPost
605#D-* Purpose: Qsub new job on scalaire
606#D-* Examples:
607#D-
608function IGCM_sys_QsubPost {
609  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
610  if ( $DEBUG_sys ) ; then
611    echo "IGCM_sys_QsubPost :" $@
612  fi
613
614# ============ FRONTEND START ============ #
615
616  /usr/bin/nqsII/qsub -q scalaire -o ${POST_DIR}/${Script_Post_Output}.out ${libIGCM}/$1.job -v ${listVarEnv}
617
618# ============ FRONTEND  END  ============ #
619
620# ============ CESIUM START ============ #
621#  typeset NB_ESSAI DELAI status i
622#  # number of tentative
623#  NB_ESSAI=10
624#  # time delay between tentative
625#  DELAI=10
626#  (( i = 0 ))
627#  while [ $i -lt $NB_ESSAI ] ; do
628#    /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
629#    status=$?
630#    if [ ${status} -gt 0 ]; then
631#      sleep $DELAI
632#    else
633#      break
634#    fi
635#    (( i = i + 1 ))
636#  done
637# ============ CESIUM  END  ============ #
638
639  if [ $? -gt 0 ] ; then
640    echo "IGCM_sys_QsubPost : erreur " $@
641    IGCM_debug_Exit "IGCM_sys_QsubPost"
642  fi
643  IGCM_debug_PopStack "IGCM_sys_QsubPost"
644}
645
646#D-*************************
647#D- File transfer functions
648#D-*************************
649#D-
650
651#D-#==================================================
652#D-function IGCM_sys_Rsync_out
653#D-* Purpose: treat return val of rsync
654#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
655#D-  Error values and explanations can depend on your system version.
656function IGCM_sys_Rsync_out {
657  RET=$1
658  if [ ! $RET ] ; then
659    echo "rsync error !"
660  fi
661
662  if [ $MYLANG = "fr" ]; then
663    case $RET in
664    0)  return ;;
665    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
666      echo "Erreur de syntaxe ou d'utilisation."
667      return;;
668    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
669      echo "Incompatibilité de protocole."
670      return;;
671    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
672      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
673      echo "répertoires"
674      return;;
675    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
676      echo "Action demandée non supportée : une tentative de manipulation de"
677      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
678      echo "été faite ; ou une option qui est supportée par le  client  mais"
679      echo "pas par le serveur a été spécifiée."
680      return;;
681    10) echo "Erreur de rsync ; RERR_SOCKETIO"
682      echo "Erreur dans le socket d'entrée sortie"
683      return;;
684    11) echo "Erreur de rsync ; RERR_FILEIO"
685      echo "Erreur d'entrée sortie fichier"
686      return;;
687    12) echo "Erreur de rsync ; RERR_STREAMIO"
688      echo "Erreur dans flux de donnée du protocole rsync"
689      return;;
690    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
691      echo "Erreur avec les diagnostics du programme"
692      return;;
693    14) echo "Erreur de rsync ; RERR_IPC"
694      echo "Erreur dans le code IPC"
695      return;;
696    20) echo "Erreur de rsync ; RERR_SIGNAL"
697      echo "SIGUSR1 ou SIGINT reçu"
698      return;;
699    21) echo "Erreur de rsync ; RERR_WAITCHILD"
700      echo "Une erreur retournée par waitpid()"
701      return;;
702    22) echo "Erreur de rsync ; RERR_MALLOC"
703      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
704      return;;
705    23) echo ""
706      echo "Erreur fichier inexistant"
707      return;;
708    30) echo "Erreur de rsync ; RERR_TIMEOUT"
709      echo "Temps d'attente écoulé dans l'envoi/réception de données"
710      return;;
711    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
712      return;;
713    esac
714  elif [ $MYLANG = "en" ] ; then
715    case $RET in
716    0)  return;;               
717    1)  echo "rsync error : Syntax or usage error "
718      return;;
719    2)  echo "rsync error : Protocol incompatibility "
720      return;;
721    3)  echo "rsync error : Errors selecting input/output files, dirs"
722      return;;
723    4)  echo "rsync error : Requested action not supported: an attempt"
724      echo "was made to manipulate 64-bit files on a platform that cannot support"
725      echo "them; or an option was specified that is supported by the client and"
726      echo "not by the server."
727      return;;
728    5)  echo "rsync error : Error starting client-server protocol"
729      return;;
730    10) echo "rsync error : Error in socket I/O "
731      return;;
732    11) echo "rsync error : Error in file I/O "
733      return;;
734    12) echo "rsync error : Error in rsync protocol data stream "
735      return;;
736    13) echo "rsync error : Errors with program diagnostics "
737      return;;
738    14) echo "rsync error : Error in IPC code "
739      return;;
740    20) echo "rsync error : Received SIGUSR1 or SIGINT "
741      return;;
742    21) echo "rsync error : Some error returned by waitpid() "
743      return;;
744    22) echo "rsync error : Error allocating core memory buffers "
745      return;;
746    23) echo "rsync error : Partial transfer due to error"
747      return;;
748    24) echo "rsync error : Partial transfer due to vanished source files"
749      return;;
750    30) echo "rsync error : Timeout in data send/receive "
751      return;;
752    *)  echo "rsync error : return code of rsync unknown :" $RET
753      return;;
754    esac
755  else
756    echo "unknown language $MYLANG."
757    return
758  fi
759}
760
761#D-#==================================================
762#D-function IGCM_sys_Miror_libIGCM
763#D-* Purpose: Mirror libIGCM PATH and lib to cesium
764#D-* Examples:
765#D-
766function IGCM_sys_Mirror_libIGCM {
767  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
768  if ( $DEBUG_sys ) ; then
769    echo "IGCM_sys_Mirror_libIGCM"
770  fi
771
772  typeset RET DEST
773
774  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
775
776  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
777  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
778  RET=$?
779
780  if [ ${RET} -gt 0 ] ; then
781    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on cesium."
782    cat out_rsync
783  fi
784  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
785}
786
787#====================================================
788#- Call IGCM_sys_Mirror_libIGCM now !
789if ( $MirrorlibIGCM ) ; then
790  IGCM_sys_Mirror_libIGCM
791fi
792
793#D-#==================================================
794#D-function IGCM_sys_Cp
795#D-* Purpose: generic cp
796#D-* Examples:
797#D-
798function IGCM_sys_Cp {
799  IGCM_debug_PushStack "IGCM_sys_Cp" $@
800  if ( $DEBUG_sys ) ; then
801    echo "IGCM_sys_Cp :" $@
802  fi
803
804  typeset RET
805
806  echo cp $@ > out_rsync 2>&1
807  \cp $@ >> out_rsync 2>&1
808  RET=$?
809
810  if [ ${RET} -gt 0 ] ; then
811    echo "IGCM_sys_Cp : error."
812    cat out_rsync
813    IGCM_debug_Exit "IGCM_sys_Cp"
814  else
815    \rm out_rsync
816  fi
817  IGCM_debug_PopStack "IGCM_sys_Cp"
818}
819
820#D-#==================================================
821#D-function IGCM_sys_Rm
822#D-* Purpose: generic rm
823#D-* Examples:
824#D-
825function IGCM_sys_Rm {
826  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
827  if ( $DEBUG_sys ) ; then
828    echo "IGCM_sys_Rm :" $@
829  fi
830
831  typeset RET
832
833  echo rm $@ > out_rsync 2>&1
834  \rm $@ >> out_rsync 2>&1
835  RET=$?
836
837  if [ ${RET} -gt 0 ] ; then
838    echo "IGCM_sys_Rm : error."
839    cat out_rsync
840    IGCM_debug_Exit "IGCM_sys_Rm"
841  else
842    \rm out_rsync
843  fi
844  IGCM_debug_PopStack "IGCM_sys_Rm"
845}
846
847#D-#==================================================
848#D-function IGCM_sys_Mv
849#D-* Purpose: generic move
850#D-* Examples:
851#D-
852function IGCM_sys_Mv {
853  IGCM_debug_PushStack "IGCM_sys_Mv" $@
854  if ( $DEBUG_sys ) ; then
855    echo "IGCM_sys_Mv :" $@
856  fi
857
858  if [ $DRYRUN = 0 ]; then
859
860    typeset RET
861   
862    echo mv $@ > out_rsync 2>&1
863    \mv $@ >> out_rsync 2>&1
864    RET=$?
865   
866    if [ ${RET} -gt 0 ] ; then
867      echo "IGCM_sys_Mv : error in mv."
868      cat out_rsync
869      IGCM_debug_Exit "IGCM_sys_Mv"
870    else
871      \rm out_rsync
872    fi
873  else
874    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
875  fi
876
877  IGCM_debug_PopStack "IGCM_sys_Mv"
878}
879
880#D-#==================================================
881#D-function IGCM_sys_Put_Dir
882#D-* Purpose: Copy a complete directory on $(ARCHIVE)
883#D-* Examples:
884#D-
885function IGCM_sys_Put_Dir {
886  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
887  if ( $DEBUG_sys ) ; then
888    echo "IGCM_sys_Put_Dir :" $@
889  fi
890  if [ $DRYRUN = 0 ]; then
891    if [ ! -d ${1} ] ; then
892      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
893      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
894      return
895    fi
896
897    typeset RET
898
899    # Only if we use rsync
900    #IGCM_sys_TestDirArchive $( dirname $2 )
901    #
902    #USUAL WAY
903    \cp -r $1 $2 > out_rsync 2>&1
904    RET=$?
905
906    if [ ${RET} -gt 0 ] ; then
907      echo "IGCM_sys_Put_Dir : error."
908      cat out_rsync
909      IGCM_debug_Exit "IGCM_sys_Put_Dir"
910    else
911      \rm out_rsync
912    fi
913  else
914    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
915  fi
916  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
917}
918
919#D-#==================================================
920#D-function IGCM_sys_Get_Dir
921#D-* Purpose: Copy a complete directory from ${ARCHIVE}
922#D-* Examples:
923#D-
924function IGCM_sys_Get_Dir {
925  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
926  if ( $DEBUG_sys ) ; then
927    echo "IGCM_sys_Get_Dir :" $@
928  fi
929  if [ $DRYRUN = 0 ]; then
930#    if [ ! -d ${1} ] ; then
931#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
932#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
933#      return
934#    fi
935
936    typeset RET
937
938    # Only if we use rsync
939    #IGCM_sys_TestDirArchive $( dirname $2 )
940    #
941    # USUAL WAY
942    # add dmfind/dmget (to demigrate all offline files) :
943    dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
944    \cp -r $1 $2 > out_rsync 2>&1
945    RET=$?
946
947    if [ ${RET} -gt 0 ] ; then
948      echo "IGCM_sys_Get_Dir : error."
949      cat out_rsync
950      IGCM_debug_Exit "IGCM_sys_Get_Dir"
951    else
952      \rm out_rsync
953    fi
954  else
955    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
956  fi
957  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
958}
959
960#D-#==================================================
961#D-function IGCM_sys_Put_Rest
962#D-* Purpose: Put computied restarts on ${ARCHIVE}.
963#D-           File and target directory must exist.
964#D-* Examples:
965#D-
966function IGCM_sys_Put_Rest {
967  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
968  if ( $DEBUG_sys ) ; then
969    echo "IGCM_sys_Put_Rest :" $@
970  fi
971  if [ $DRYRUN = 0 ]; then
972    if [ ! -f ${1} ] ; then
973      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
974      IGCM_debug_Exit "IGCM_sys_Put_Rest"
975    fi
976
977    typeset RET
978    #
979    if [ X${JobType} = XRUN ] ; then
980      IGCM_sys_Chmod 444 ${1}
981    fi
982
983    #
984    # USUAL WAY
985    \cp $1 $2 > out_rsync 2>&1
986    RET=$?
987
988#       #RSYNC WITH NETWORK SSH CALL
989#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
990#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
991
992#       #RSYNC WITH NFS USE
993#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
994#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
995
996#       RET=$?
997#       IGCM_sys_Rsync_out $RET
998
999#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1000#       (( RET=RET+$? ))
1001
1002    if [ ${RET} -gt 0 ] ; then
1003      echo "IGCM_sys_Put_Rest : error."
1004      cat out_rsync
1005      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1006    else
1007      \rm out_rsync
1008    fi
1009  else
1010    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1011  fi
1012  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1013}
1014
1015#D-#==================================================
1016#D-function IGCM_sys_PutBuffer_Rest
1017#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1018#D-           File and target directory must exist.
1019#D-* Examples:
1020#D-
1021function IGCM_sys_PutBuffer_Rest {
1022  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1023  if ( $DEBUG_sys ) ; then
1024    echo "IGCM_sys_PutBuffer_Rest :" $@
1025  fi
1026  if [ $DRYRUN = 0 ]; then
1027    if [ ! -f ${1} ] ; then
1028      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1029      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1030    fi
1031
1032    typeset RET
1033    #
1034    if [ X${JobType} = XRUN ] ; then
1035      IGCM_sys_Chmod 444 ${1}
1036    fi
1037
1038    #
1039    # USUAL WAY
1040    \cp $1 $2 > out_rsync 2>&1
1041    RET=$?
1042
1043    if [ ${RET} -gt 0 ] ; then
1044      echo "IGCM_sys_PutBuffer_Rest : error."
1045      cat out_rsync
1046      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1047    else
1048      \rm out_rsync
1049    fi
1050  else
1051    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1052  fi
1053  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1054}
1055
1056#D-#==================================================
1057#D-function IGCM_sys_Put_Out
1058#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1059#D-* Examples:
1060#D-
1061function IGCM_sys_Put_Out {
1062  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1063  if ( $DEBUG_sys ) ; then
1064    echo "IGCM_sys_Put_Out :" $@
1065  fi
1066  if [ $DRYRUN = 0 ]; then
1067    if [ ! -f ${1} ] ; then
1068      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1069      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1070      return 1
1071    fi
1072    #
1073    IGCM_sys_MkdirArchive $( dirname $2 )
1074    #
1075    typeset RET
1076
1077    #=====================================================
1078    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1079    #=====================================================
1080
1081    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1082    #if [ $? -eq 0 ] ; then
1083    #    typeset WORKPATH FILEPATH
1084    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1085    #    IGCM_sys_MkdirWork ${WORKPATH}
1086    #    FILEPATH=${WORKPATH}/$( basename $2 )
1087    #    #
1088    #    IGCM_sys_Cp ${1} ${FILEPATH}
1089    #fi
1090
1091    if [ X${JobType} = XRUN ] ; then
1092      if [ X${3} = X ] ; then
1093        IGCM_sys_Chmod 444 ${1}
1094      fi
1095    fi
1096    #
1097    # USUAL WAY
1098    \cp $1 $2 > out_rsync 2>&1
1099    RET=$?
1100
1101#       #RSYNC WITH NETWORK SSH CALL
1102#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1103#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1104
1105#       #RSYNC WITH NFS USE
1106#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1107#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1108
1109#       RET=$?
1110#       IGCM_sys_Rsync_out $RET
1111
1112#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1113#       (( RET=RET+$? ))
1114
1115    if [ ${RET} -gt 0 ] ; then
1116      echo "IGCM_sys_Put_Out : error."
1117      cat out_rsync
1118      IGCM_debug_Exit "IGCM_sys_Put_Out"
1119    else
1120      \rm out_rsync
1121    fi
1122  else
1123    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1124  fi
1125  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1126  return 0
1127}
1128
1129#D-#==================================================
1130#D-function IGCM_sys_PutBuffer_Out
1131#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1132#D-* Examples:
1133#D-
1134function IGCM_sys_PutBuffer_Out {
1135  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1136  if ( $DEBUG_sys ) ; then
1137    echo "IGCM_sys_PutBuffer_Out :" $@
1138  fi
1139  if [ $DRYRUN = 0 ]; then
1140    if [ ! -f ${1} ] ; then
1141      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1142      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1143      return 1
1144    fi
1145    #
1146    IGCM_sys_Mkdir $( dirname $2 )
1147    #
1148    typeset RET
1149
1150    if [ X${JobType} = XRUN ] ; then
1151      if [ X${3} = X ] ; then
1152        IGCM_sys_Chmod 444 ${1}
1153      fi
1154    fi
1155    #
1156    # USUAL WAY
1157    \cp $1 $2 > out_rsync 2>&1
1158    RET=$?
1159
1160    if [ ${RET} -gt 0 ] ; then
1161      echo "IGCM_sys_PutBuffer_Out : error."
1162      cat out_rsync
1163      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1164    else
1165      \rm out_rsync
1166    fi
1167  else
1168    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1169  fi
1170  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1171  return 0
1172}
1173
1174#D-#==================================================
1175#D-function IGCM_sys_Get
1176#D-* Purpose: Get a file from ${ARCHIVE}
1177#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1178#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1179function IGCM_sys_Get {
1180  IGCM_debug_PushStack "IGCM_sys_Get" $@
1181
1182  typeset DEST RET dm_liste ifile target file_work
1183
1184  if ( $DEBUG_sys ) ; then
1185    echo "IGCM_sys_Get :" $@
1186  fi
1187  if [ $DRYRUN -le 2 ]; then
1188    if [ X${1} = X'/l' ] ; then
1189      # test if the first file is present in the old computation :
1190      eval set +A dm_liste \${${2}}
1191    else
1192      eval set +A dm_liste ${1}
1193    fi
1194    eval DEST=\${${#}}
1195
1196    #=====================================================
1197    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1198    #=====================================================
1199
1200    # Is it an R_OUT file (not R_IN) ?
1201    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1202    #if [ $? -eq 0 ] ; then
1203    #    # Yes  ? then we try to get it in SCRATCHDIR
1204    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1205    #    if [ -f ${file_work[0]} ] ; then
1206    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1207    #   IGCM_debug_PopStack "IGCM_sys_Get"
1208    #   return
1209    #    fi
1210    #fi
1211
1212    # test if the (first) file is present in the old computation :
1213    IGCM_sys_TestFileArchive ${dm_liste[0]}
1214    RET=$?
1215    if [ ${RET} -gt 0 ] ; then
1216      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1217      IGCM_debug_Exit "IGCM_sys_Get"
1218    fi
1219
1220    dmget ${dm_liste[*]} > out_rsync 2>&1
1221    RET=$?
1222    if [ ${RET} -gt 0 ] ; then
1223      echo "WARNING IGCM_sys_Get : demigration error."
1224      cat out_rsync
1225      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1226    fi
1227
1228    #if [ ${RET} -gt 0 ] ; then
1229    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1230    #   cat out_rsync
1231    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1232    #   sleep 30
1233    #   echo "We try another time"
1234    #   dmget ${dm_liste[*]} > out_rsync 2>&1
1235    #   RET=$?
1236    #   if [ ${RET} -gt 0 ] ; then
1237    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1238    #       cat out_rsync
1239    #       IGCM_debug_Exit "IGCM_sys_Get"
1240    #   fi
1241    #    else
1242    #   echo "ERROR IGCM_sys_Get : demigration error :"
1243    #   cat out_rsync
1244    #   IGCM_debug_Exit "IGCM_sys_Get"
1245    #    fi
1246    #fi
1247
1248    #USUAL WAY
1249    if [ X${1} = X'/l' ] ; then
1250      (( RET=0 ))
1251      for target in ${dm_liste[*]} ; do
1252        local_file=$( basename ${target} )
1253        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1254        (( RET = RET + $? ))
1255      done
1256    else
1257      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1258      RET=$?
1259    fi
1260
1261#       #RSYNC WITH NETWORK SSH CALL
1262#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1263#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1264
1265#       #RSYNC WITH NFS USE
1266#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1267#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1268
1269#       RET=$?
1270#       IGCM_sys_Rsync_out $RET
1271
1272#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1273#       (( RET=RET+$? ))
1274
1275    if [ ${RET} -gt 0 ] ; then
1276      echo "IGCM_sys_Get : copy error."
1277      cat out_rsync
1278      IGCM_debug_Exit "IGCM_sys_Get"
1279    else
1280      \rm out_rsync
1281    fi
1282  else
1283    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1284  fi
1285  IGCM_debug_PopStack "IGCM_sys_Get"
1286}
1287
1288#D-#==================================================
1289#D-function IGCM_sys_GetBuffer
1290#D-* Purpose: Get a file from ${SCRATCHDIR}
1291#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1292#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1293function IGCM_sys_GetBuffer {
1294  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1295
1296  typeset DEST RET buf_liste ifile target file_work
1297
1298  if ( $DEBUG_sys ) ; then
1299    echo "IGCM_sys_GetBuffer :" $@
1300  fi
1301  if [ $DRYRUN -le 2 ]; then
1302    if [ X${1} = X'/l' ] ; then
1303      # test if the first file is present in the old computation :
1304      eval set +A buf_liste \${${2}}
1305    else
1306      eval set +A buf_liste ${1}
1307    fi
1308    eval DEST=\${${#}}
1309
1310    #USUAL WAY
1311    if [ X${1} = X'/l' ] ; then
1312      (( RET=0 ))
1313      for target in ${buf_liste[*]} ; do
1314        local_file=$( basename ${target} )
1315        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1316        (( RET = RET + $? ))
1317      done
1318    else
1319      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1320      RET=$?
1321    fi
1322
1323    if [ ${RET} -gt 0 ] ; then
1324      echo "IGCM_sys_GetBuffer : copy error."
1325      cat out_rsync
1326      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1327    else
1328      \rm out_rsync
1329    fi
1330  else
1331    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1332  fi
1333  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1334}
1335
1336#D-#==================================================
1337#D-function IGCM_sys_GetDate_FichWork
1338#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1339#D-* Examples:
1340#D-
1341function IGCM_sys_GetDate_FichWork {
1342  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1343  if ( $DEBUG_sys ) ; then
1344    echo "IGCM_sys_GetDate_FichWork :" $@
1345  fi
1346  typeset dateF
1347  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1348  eval ${2}=${dateF[5]}
1349
1350    # donne la date filesys d'un fichier sur la machine work
1351  IGCM_debug_PopStack "IGCM_sys_FichWork"
1352}
1353
1354#D-#==================================================
1355#D-function IGCM_sys_GetDate_FichArchive
1356#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1357#D-* Examples:
1358#D-
1359function IGCM_sys_GetDate_FichArchive {
1360  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1361  if ( $DEBUG_sys ) ; then
1362    echo "IGCM_sys_GetDate_FichArchive :" $@
1363  fi
1364  typeset dateF
1365  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1366  eval ${2}=${dateF[5]}
1367
1368  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1369}
1370
1371##############################################################
1372# REBUILD OPERATOR
1373
1374function IGCM_sys_rebuild {
1375  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1376  if ( $DEBUG_sys ) ; then
1377    echo "IGCM_sys_rebuild :" $@
1378  fi
1379  /home/cont003/p86ipsl/SX8/bin/rebuild -f -o $@
1380  if [ $? -gt 0 ] ; then
1381    echo "IGCM_sys_rebuild : erreur ${@}."
1382    IGCM_debug_Exit "rebuild"
1383  fi
1384
1385  IGCM_debug_PopStack "IGCM_sys_rebuild"
1386}
1387
1388############################################################
1389# Activate Running Environnment Variables
1390
1391function IGCM_sys_activ_variables {
1392  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1393  if ( $DEBUG_sys ) ; then
1394    echo "IGCM_sys_activ_variables"
1395  fi
1396
1397# --------------------------------------------------------------------
1398#D- MPI specifications
1399# --------------------------------------------------------------------
1400
1401#D-- MPISUSPEND
1402  export MPISUSPEND=${MPISUSPEND:=OFF}
1403
1404#D-- MPIPROGINF #other choices : ALL_DETAIL2
1405  export MPIPROGINF=ALL
1406#D- activate ftrace (with -ftrace)
1407  export F_FTRACE=YES
1408#D- communication information (with -ftrace)
1409  export MPICOMMINF=DETAIL
1410
1411# --------------------------------------------------------------------
1412#D- Other specifications
1413# --------------------------------------------------------------------
1414
1415#D- max number of character/line in output job
1416  export F_SYSLEN=5000
1417#D- number of error that can be admitted on the NEC
1418  export F_ERRCNT=0
1419#D- global performance
1420  export F_PROGINF=DETAIL
1421
1422#D- I/O performance (FORTRAN I/O only not netCDF)
1423  export F_FILEINF=${F_FILEINF:=NO}
1424#D- netCDF I/O performance
1425  export NC_FILEINF=${NC_FILEINF:=NO}
1426
1427  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1428}
1429
1430############################################################
1431# Desactivate Running Environnment Variables
1432
1433function IGCM_sys_desactiv_variables {
1434  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1435  if ( $DEBUG_sys ) ; then
1436    echo "IGCM_sys_desactiv_variables"
1437  fi
1438# --------------------------------------------------------------------
1439#D- MPI specifications
1440# --------------------------------------------------------------------
1441
1442#D-- MPIPROGINF
1443  export MPIPROGINF=NO
1444
1445# --------------------------------------------------------------------
1446#D- Other specifications
1447# --------------------------------------------------------------------
1448
1449#D- global performance
1450  export F_PROGINF=NO 
1451
1452  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1453}
1454
1455############################################################
1456# Build run file
1457
1458function IGCM_sys_build_run_file {
1459  IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1460  if ( $DEBUG_sys ) ; then
1461    echo "IGCM_sys_build_run_file " $@
1462  fi
1463  (( NUM_PROC_ATM = BATCH_NUM_PROC_TOT - 1 ))
1464  (( NUM_PROC_OASIS = BATCH_NUM_PROC_TOT - NUM_PROC_ATM ))
1465  (( NUM_PROC_OCE = BATCH_NUM_PROC_TOT - NUM_PROC_ATM ))
1466 
1467  if [ $1 = MPI2 ]; then
1468    cat <<EOF > run_file
1469-p 1 -np 1 -e ./oasis
1470EOF
1471    (( NUM_PROCESS = BATCH_NUM_PROC_TOT + 1 ))
1472    config_UserChoices_JobRunOptions='"-max_np ${NUM_PROCESS} -f"'
1473
1474  elif [ $1 = MPI1 ]; then
1475    cat <<EOF > run_file
1476-p $NUM_PROC_OASIS -e ./oasis
1477-p $NUM_PROC_ATM -e ./lmdz.x
1478-p $NUM_PROC_OCE -e ./opa.xx
1479EOF
1480  fi
1481  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1482}
Note: See TracBrowser for help on using the repository browser.