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

Last change on this file since 545 was 545, checked in by sdipsl, 12 years ago
  • clean_month.job adapted to R_BUFR
  • R_IN points to CCCWORKDIR /ccc/work/cont003/dsm/p86ipsl/IGCM
  • bugfixes, simplification, refactoring, cosmetics
  • Property svn:keywords set to Revision Author Date
File size: 40.9 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for Mercure SX9
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34# gawk specific location on SX9
35export PATH=/applications/gawk-3.0.4/bin:${PATH}
36
37#====================================================
38# set DEBUG_sys to true to output calls of function
39typeset -r DEBUG_sys=${DEBUG_sys:=true}
40
41#====================================================
42# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
43typeset -r DRYRUN=${DRYRUN:=0}
44
45# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
46# -------------------------------------------------------------------------------------
47# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
48# |          |  Cp/Exe param files |            |  Chmod  |                           |
49# |          |      Qsub           |            |         |                           |
50# -------------------------------------------------------------------------------------
51# |    0     |       yes           |    yes     |  yes    |      yes                  |
52# -------------------------------------------------------------------------------------
53# |    1     |       yes           |    yes     |  yes    |      no                   |
54# -------------------------------------------------------------------------------------
55# |    2     |       yes           |    yes     |  no     |      no                   |
56# -------------------------------------------------------------------------------------
57# |    3     |       yes           |    no      |  no     |      no                   |
58# -------------------------------------------------------------------------------------
59
60#=====================================================
61# Global Variables :
62#=====================================================
63# Language : "fr" or "en"
64typeset -r MYLANG="fr"
65
66#=====================================================
67# Host and user names
68# $hostname ou hostname
69typeset  HOST=${HOST:=$( hostname )}
70# $username ou whoami
71typeset  LOGIN=${LOGIN:=$( whoami )}
72# $hostname of the MASTER job
73typeset -r MASTER=mercure
74
75#D-
76#D-#==================================================
77#D-Program used in libIGCM
78#D-#==================================================
79
80# 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_TestFileArchive
459#D-* Purpose: Test file that must NOT EXISTS on Archive
460#D-* Examples:
461#D-
462function IGCM_sys_TestFileArchive {
463  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
464  if ( $DEBUG_sys ) ; then
465    echo "IGCM_sys_TestFileArchive :" $@
466  fi
467  typeset ExistFlag
468  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
469  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
470
471  return ${ExistFlag}
472}
473
474#D-#==================================================
475#D-function IGCM_sys_TestFileBuffer
476#D-* Purpose: Test file that must NOT EXISTS on Buffer
477#D-* Examples:
478#D-
479function IGCM_sys_TestFileBuffer {
480  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
481  typeset ExistFlag
482  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
483  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
484
485  return ${ExistFlag}
486}
487
488#D-#==================================================
489#D-function IGCM_sys_CountFileArchive
490#D-* Purpose: Count files on Archive filesystem
491#D-* Examples:
492#D-
493function IGCM_sys_CountFileArchive {
494  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
495  ls ${@} 2>/dev/null | wc -l
496  if [ $? -gt 0 ] ; then
497    echo "IGCM_sys_CountFileArchive : erreur."
498  fi
499  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
500}
501
502#D-#==================================================
503#D-function IGCM_sys_CountFileBuffer
504#D-* Purpose: Count files on Scratch filesystem
505#D-* Examples:
506#D-
507function IGCM_sys_CountFileBuffer {
508  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
509  ls ${@} 2>/dev/null | wc -l
510  if [ $? -gt 0 ] ; then
511    echo "IGCM_sys_CountFileBuffer : erreur."
512  fi
513  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
514}
515
516#D-#==================================================
517#D-function IGCM_sys_Tree
518#D-* Purpose: Tree directories with files on ${ARCHIVE}
519#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
520#D-
521function IGCM_sys_Tree {
522  IGCM_debug_PushStack "IGCM_sys_Tree" $@
523  if ( $DEBUG_sys ) ; then
524    echo "IGCM_sys_Tree :" $@
525  fi
526
527  \ls -lR ${@}
528
529  IGCM_debug_PopStack "IGCM_sys_Tree"
530}
531
532#D-#==================================================
533#D-function IGCM_sys_Tar
534#D-* Purpose: master tar command
535#D-* Examples:
536#D-
537function IGCM_sys_Tar {
538  IGCM_debug_PushStack "IGCM_sys_Tar" $@
539  if ( $DEBUG_sys ) ; then
540    echo "IGCM_sys_Tar :" $@
541  fi
542  \tar cf $@
543  if [ $? -gt 0 ] ; then
544    echo "IGCM_sys_Tar : erreur."
545    IGCM_debug_Exit "IGCM_sys_Tar"
546  fi
547  IGCM_debug_PopStack "IGCM_sys_Tar"
548}
549
550#D-#==================================================
551#D-function IGCM_sys_UnTar
552#D-* Purpose: master un-tar command
553#D-* Examples:
554#D-
555function IGCM_sys_UnTar {
556  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
557  if ( $DEBUG_sys ) ; then
558    echo "IGCM_sys_UnTar :" $@
559  fi
560  \tar xvf $1
561  if [ $? -gt 0 ] ; then
562    echo "IGCM_sys_UnTar : erreur."
563    IGCM_debug_Exit "IGCM_sys_UnTar"
564  fi
565  IGCM_debug_PopStack "IGCM_sys_UnTar"
566}
567
568#D-#==================================================
569#D-function IGCM_sys_Qsub
570#D-* Purpose: Qsub new job
571#D-* Examples:
572#D-
573function IGCM_sys_Qsub {
574  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
575  if ( $DEBUG_sys ) ; then
576    echo "IGCM_sys_Qsub :" $@
577  fi
578  /usr/bin/nqsII/qsub -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} < $1
579  if [ $? -gt 0 ] ; then
580    echo "IGCM_sys_Qsub : erreur -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} $@."
581    IGCM_debug_Exit "IGCM_sys_Qsub"
582  fi
583  IGCM_debug_PopStack "IGCM_sys_Qsub"
584}
585
586#D-#==================================================
587#D-function IGCM_sys_QsubPost
588#D-* Purpose: Qsub new job on scalaire
589#D-* Examples:
590#D-
591function IGCM_sys_QsubPost {
592  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
593  if ( $DEBUG_sys ) ; then
594    echo "IGCM_sys_QsubPost :" $@
595  fi
596
597# ============ FRONTEND START ============ #
598
599#  /usr/bin/nqsII/qsub -o ${POST_DIR}/${Script_Post_Output}.out ${libIGCM}/$1.job -v ${listVarEnv}
600
601# ============ FRONTEND  END  ============ #
602
603# ============ CESIUM START ============ #
604  typeset NB_ESSAI DELAI status i
605  # number of tentative
606  NB_ESSAI=10
607  # time delay between tentative
608  DELAI=10
609  (( i = 0 ))
610  while [ $i -lt $NB_ESSAI ] ; do
611    /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
612    status=$?
613    if [ ${status} -gt 0 ]; then
614      sleep $DELAI
615    else
616      break
617    fi
618    (( i = i + 1 ))
619  done 
620# ============ CESIUM  END  ============ #
621
622  if [ $? -gt 0 ] ; then
623    echo "IGCM_sys_QsubPost : erreur " $@
624    IGCM_debug_Exit "IGCM_sys_QsubPost"
625  fi
626  IGCM_debug_PopStack "IGCM_sys_QsubPost"
627}
628
629#D-*************************
630#D- File transfer functions
631#D-*************************
632#D-
633
634#D-#==================================================
635#D-function IGCM_sys_Rsync_out
636#D-* Purpose: treat return val of rsync
637#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
638#D-  Error values and explanations can depend on your system version.
639function IGCM_sys_Rsync_out {
640  RET=$1
641  if [ ! $RET ] ; then
642    echo "rsync error !"
643  fi
644
645  if [ $MYLANG = "fr" ]; then
646    case $RET in
647    0)  return ;;
648    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
649      echo "Erreur de syntaxe ou d'utilisation."
650      return;;
651    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
652      echo "Incompatibilité de protocole."
653      return;;
654    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
655      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
656      echo "répertoires"
657      return;;
658    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
659      echo "Action demandée non supportée : une tentative de manipulation de"
660      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
661      echo "été faite ; ou une option qui est supportée par le  client  mais"
662      echo "pas par le serveur a été spécifiée."
663      return;;
664    10) echo "Erreur de rsync ; RERR_SOCKETIO"
665      echo "Erreur dans le socket d'entrée sortie"
666      return;;
667    11) echo "Erreur de rsync ; RERR_FILEIO"
668      echo "Erreur d'entrée sortie fichier"
669      return;;
670    12) echo "Erreur de rsync ; RERR_STREAMIO"
671      echo "Erreur dans flux de donnée du protocole rsync"
672      return;;
673    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
674      echo "Erreur avec les diagnostics du programme"
675      return;;
676    14) echo "Erreur de rsync ; RERR_IPC"
677      echo "Erreur dans le code IPC"
678      return;;
679    20) echo "Erreur de rsync ; RERR_SIGNAL"
680      echo "SIGUSR1 ou SIGINT reçu"
681      return;;
682    21) echo "Erreur de rsync ; RERR_WAITCHILD"
683      echo "Une erreur retournée par waitpid()"
684      return;;
685    22) echo "Erreur de rsync ; RERR_MALLOC"
686      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
687      return;;
688    23) echo ""
689      echo "Erreur fichier inexistant"
690      return;;
691    30) echo "Erreur de rsync ; RERR_TIMEOUT"
692      echo "Temps d'attente écoulé dans l'envoi/réception de données"
693      return;;
694    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
695      return;;
696    esac
697  elif [ $MYLANG = "en" ] ; then
698    case $RET in
699    0)  return;;               
700    1)  echo "rsync error : Syntax or usage error "
701      return;;
702    2)  echo "rsync error : Protocol incompatibility "
703      return;;
704    3)  echo "rsync error : Errors selecting input/output files, dirs"
705      return;;
706    4)  echo "rsync error : Requested action not supported: an attempt"
707      echo "was made to manipulate 64-bit files on a platform that cannot support"
708      echo "them; or an option was specified that is supported by the client and"
709      echo "not by the server."
710      return;;
711    5)  echo "rsync error : Error starting client-server protocol"
712      return;;
713    10) echo "rsync error : Error in socket I/O "
714      return;;
715    11) echo "rsync error : Error in file I/O "
716      return;;
717    12) echo "rsync error : Error in rsync protocol data stream "
718      return;;
719    13) echo "rsync error : Errors with program diagnostics "
720      return;;
721    14) echo "rsync error : Error in IPC code "
722      return;;
723    20) echo "rsync error : Received SIGUSR1 or SIGINT "
724      return;;
725    21) echo "rsync error : Some error returned by waitpid() "
726      return;;
727    22) echo "rsync error : Error allocating core memory buffers "
728      return;;
729    23) echo "rsync error : Partial transfer due to error"
730      return;;
731    24) echo "rsync error : Partial transfer due to vanished source files"
732      return;;
733    30) echo "rsync error : Timeout in data send/receive "
734      return;;
735    *)  echo "rsync error : return code of rsync unknown :" $RET
736      return;;
737    esac
738  else
739    echo "unknown language $MYLANG."
740    return
741  fi
742}
743
744#D-#==================================================
745#D-function IGCM_sys_Miror_libIGCM
746#D-* Purpose: Mirror libIGCM PATH and lib to cesium
747#D-* Examples:
748#D-
749function IGCM_sys_Mirror_libIGCM {
750  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
751  if ( $DEBUG_sys ) ; then
752    echo "IGCM_sys_Mirror_libIGCM"
753  fi
754
755  typeset RET DEST
756
757  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
758
759  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
760  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
761  RET=$?
762
763  if [ ${RET} -gt 0 ] ; then
764    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on cesium."
765    cat out_rsync
766  fi
767  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
768}
769
770#====================================================
771#- Call IGCM_sys_Mirror_libIGCM now !
772if ( $MirrorlibIGCM ) ; then
773  IGCM_sys_Mirror_libIGCM
774fi
775
776#D-#==================================================
777#D-function IGCM_sys_Cp
778#D-* Purpose: generic cp
779#D-* Examples:
780#D-
781function IGCM_sys_Cp {
782  IGCM_debug_PushStack "IGCM_sys_Cp" $@
783  if ( $DEBUG_sys ) ; then
784    echo "IGCM_sys_Cp :" $@
785  fi
786
787  typeset RET
788
789  echo cp $@ > out_rsync 2>&1
790  \cp $@ >> out_rsync 2>&1
791  RET=$?
792
793  if [ ${RET} -gt 0 ] ; then
794    echo "IGCM_sys_Cp : error."
795    cat out_rsync
796    IGCM_debug_Exit "IGCM_sys_Cp"
797  else
798    \rm out_rsync
799  fi
800  IGCM_debug_PopStack "IGCM_sys_Cp"
801}
802
803#D-#==================================================
804#D-function IGCM_sys_Rm
805#D-* Purpose: generic rm
806#D-* Examples:
807#D-
808function IGCM_sys_Rm {
809  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
810  if ( $DEBUG_sys ) ; then
811    echo "IGCM_sys_Rm :" $@
812  fi
813
814  typeset RET
815
816  echo rm $@ > out_rsync 2>&1
817  \rm $@ >> out_rsync 2>&1
818  RET=$?
819
820  if [ ${RET} -gt 0 ] ; then
821    echo "IGCM_sys_Rm : error."
822    cat out_rsync
823    IGCM_debug_Exit "IGCM_sys_Rm"
824  else
825    \rm out_rsync
826  fi
827  IGCM_debug_PopStack "IGCM_sys_Rm"
828}
829
830#D-#==================================================
831#D-function IGCM_sys_Mv
832#D-* Purpose: generic move
833#D-* Examples:
834#D-
835function IGCM_sys_Mv {
836  IGCM_debug_PushStack "IGCM_sys_Mv" $@
837  if ( $DEBUG_sys ) ; then
838    echo "IGCM_sys_Mv :" $@
839  fi
840
841  if [ $DRYRUN = 0 ]; then
842
843    typeset RET
844   
845    echo mv $@ > out_rsync 2>&1
846    \mv $@ >> out_rsync 2>&1
847    RET=$?
848   
849    if [ ${RET} -gt 0 ] ; then
850      echo "IGCM_sys_Mv : error in mv."
851      cat out_rsync
852      IGCM_debug_Exit "IGCM_sys_Mv"
853    else
854      \rm out_rsync
855    fi
856  else
857    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
858  fi
859
860  IGCM_debug_PopStack "IGCM_sys_Mv"
861}
862
863#D-#==================================================
864#D-function IGCM_sys_Put_Dir
865#D-* Purpose: Copy a complete directory on $(ARCHIVE)
866#D-* Examples:
867#D-
868function IGCM_sys_Put_Dir {
869  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
870  if ( $DEBUG_sys ) ; then
871    echo "IGCM_sys_Put_Dir :" $@
872  fi
873  if [ $DRYRUN = 0 ]; then
874    if [ ! -d ${1} ] ; then
875      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
876      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
877      return
878    fi
879
880    typeset RET
881
882    # Only if we use rsync
883    #IGCM_sys_TestDirArchive $( dirname $2 )
884    #
885    #USUAL WAY
886    \cp -r $1 $2 > out_rsync 2>&1
887    RET=$?
888
889    if [ ${RET} -gt 0 ] ; then
890      echo "IGCM_sys_Put_Dir : error."
891      cat out_rsync
892      IGCM_debug_Exit "IGCM_sys_Put_Dir"
893    else
894      \rm out_rsync
895    fi
896  else
897    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
898  fi
899  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
900}
901
902#D-#==================================================
903#D-function IGCM_sys_Get_Dir
904#D-* Purpose: Copy a complete directory from ${ARCHIVE}
905#D-* Examples:
906#D-
907function IGCM_sys_Get_Dir {
908  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
909  if ( $DEBUG_sys ) ; then
910    echo "IGCM_sys_Get_Dir :" $@
911  fi
912  if [ $DRYRUN = 0 ]; then
913#    if [ ! -d ${1} ] ; then
914#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
915#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
916#      return
917#    fi
918
919    typeset RET
920
921    # Only if we use rsync
922    #IGCM_sys_TestDirArchive $( dirname $2 )
923    #
924    # USUAL WAY
925    # add dmfind/dmget (to demigrate all offline files) :
926    dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
927    \cp -r $1 $2 > out_rsync 2>&1
928    RET=$?
929
930    if [ ${RET} -gt 0 ] ; then
931      echo "IGCM_sys_Get_Dir : error."
932      cat out_rsync
933      IGCM_debug_Exit "IGCM_sys_Get_Dir"
934    else
935      \rm out_rsync
936    fi
937  else
938    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
939  fi
940  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
941}
942
943#D-#==================================================
944#D-function IGCM_sys_Put_Rest
945#D-* Purpose: Put computied restarts on ${ARCHIVE}.
946#D-           File and target directory must exist.
947#D-* Examples:
948#D-
949function IGCM_sys_Put_Rest {
950  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
951  if ( $DEBUG_sys ) ; then
952    echo "IGCM_sys_Put_Rest :" $@
953  fi
954  if [ $DRYRUN = 0 ]; then
955    if [ ! -f ${1} ] ; then
956      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
957      IGCM_debug_Exit "IGCM_sys_Put_Rest"
958    fi
959
960    typeset RET
961    #
962    if [ X${JobType} = XRUN ] ; then
963      IGCM_sys_Chmod 444 ${1}
964    fi
965
966    #
967    # USUAL WAY
968    \cp $1 $2 > out_rsync 2>&1
969    RET=$?
970
971#       #RSYNC WITH NETWORK SSH CALL
972#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
973#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
974
975#       #RSYNC WITH NFS USE
976#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
977#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
978
979#       RET=$?
980#       IGCM_sys_Rsync_out $RET
981
982#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
983#       (( RET=RET+$? ))
984
985    if [ ${RET} -gt 0 ] ; then
986      echo "IGCM_sys_Put_Rest : error."
987      cat out_rsync
988      IGCM_debug_Exit "IGCM_sys_Put_Rest"
989    else
990      \rm out_rsync
991    fi
992  else
993    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
994  fi
995  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
996}
997
998#D-#==================================================
999#D-function IGCM_sys_PutBuffer_Rest
1000#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1001#D-           File and target directory must exist.
1002#D-* Examples:
1003#D-
1004function IGCM_sys_PutBuffer_Rest {
1005  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1006  if ( $DEBUG_sys ) ; then
1007    echo "IGCM_sys_PutBuffer_Rest :" $@
1008  fi
1009  if [ $DRYRUN = 0 ]; then
1010    if [ ! -f ${1} ] ; then
1011      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1012      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1013    fi
1014
1015    typeset RET
1016    #
1017    if [ X${JobType} = XRUN ] ; then
1018      IGCM_sys_Chmod 444 ${1}
1019    fi
1020
1021    #
1022    # USUAL WAY
1023    \cp $1 $2 > out_rsync 2>&1
1024    RET=$?
1025
1026    if [ ${RET} -gt 0 ] ; then
1027      echo "IGCM_sys_PutBuffer_Rest : error."
1028      cat out_rsync
1029      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1030    else
1031      \rm out_rsync
1032    fi
1033  else
1034    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1035  fi
1036  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1037}
1038
1039#D-#==================================================
1040#D-function IGCM_sys_Put_Out
1041#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1042#D-* Examples:
1043#D-
1044function IGCM_sys_Put_Out {
1045  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1046  if ( $DEBUG_sys ) ; then
1047    echo "IGCM_sys_Put_Out :" $@
1048  fi
1049  if [ $DRYRUN = 0 ]; then
1050    if [ ! -f ${1} ] ; then
1051      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1052      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1053      return 1
1054    fi
1055    #
1056    IGCM_sys_MkdirArchive $( dirname $2 )
1057    #
1058    typeset RET
1059
1060    #=====================================================
1061    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1062    #=====================================================
1063
1064    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1065    #if [ $? -eq 0 ] ; then
1066    #    typeset WORKPATH FILEPATH
1067    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1068    #    IGCM_sys_MkdirWork ${WORKPATH}
1069    #    FILEPATH=${WORKPATH}/$( basename $2 )
1070    #    #
1071    #    IGCM_sys_Cp ${1} ${FILEPATH}
1072    #fi
1073
1074    if [ X${JobType} = XRUN ] ; then
1075      if [ X${3} = X ] ; then
1076        IGCM_sys_Chmod 444 ${1}
1077      fi
1078    fi
1079    #
1080    # USUAL WAY
1081    \cp $1 $2 > out_rsync 2>&1
1082    RET=$?
1083
1084#       #RSYNC WITH NETWORK SSH CALL
1085#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1086#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1087
1088#       #RSYNC WITH NFS USE
1089#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1090#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1091
1092#       RET=$?
1093#       IGCM_sys_Rsync_out $RET
1094
1095#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1096#       (( RET=RET+$? ))
1097
1098    if [ ${RET} -gt 0 ] ; then
1099      echo "IGCM_sys_Put_Out : error."
1100      cat out_rsync
1101      IGCM_debug_Exit "IGCM_sys_Put_Out"
1102    else
1103      \rm out_rsync
1104    fi
1105  else
1106    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1107  fi
1108  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1109  return 0
1110}
1111
1112#D-#==================================================
1113#D-function IGCM_sys_PutBuffer_Out
1114#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1115#D-* Examples:
1116#D-
1117function IGCM_sys_PutBuffer_Out {
1118  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1119  if ( $DEBUG_sys ) ; then
1120    echo "IGCM_sys_PutBuffer_Out :" $@
1121  fi
1122  if [ $DRYRUN = 0 ]; then
1123    if [ ! -f ${1} ] ; then
1124      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1125      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1126      return 1
1127    fi
1128    #
1129    IGCM_sys_Mkdir $( dirname $2 )
1130    #
1131    typeset RET
1132
1133    if [ X${JobType} = XRUN ] ; then
1134      if [ X${3} = X ] ; then
1135        IGCM_sys_Chmod 444 ${1}
1136      fi
1137    fi
1138    #
1139    # USUAL WAY
1140    \cp $1 $2 > out_rsync 2>&1
1141    RET=$?
1142
1143    if [ ${RET} -gt 0 ] ; then
1144      echo "IGCM_sys_PutBuffer_Out : error."
1145      cat out_rsync
1146      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1147    else
1148      \rm out_rsync
1149    fi
1150  else
1151    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1152  fi
1153  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1154  return 0
1155}
1156
1157#D-#==================================================
1158#D-function IGCM_sys_Get
1159#D-* Purpose: Get a file from ${ARCHIVE}
1160#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1161#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1162function IGCM_sys_Get {
1163  IGCM_debug_PushStack "IGCM_sys_Get" $@
1164
1165  typeset DEST RET dm_liste ifile target file_work
1166
1167  if ( $DEBUG_sys ) ; then
1168    echo "IGCM_sys_Get :" $@
1169  fi
1170  if [ $DRYRUN -le 2 ]; then
1171    if [ X${1} = X'/l' ] ; then
1172      # test if the first file is present in the old computation :
1173      eval set +A dm_liste \${${2}}
1174    else
1175      eval set +A dm_liste ${1}
1176    fi
1177    eval DEST=\${${#}}
1178
1179    #=====================================================
1180    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1181    #=====================================================
1182
1183    # Is it an R_OUT file (not R_IN) ?
1184    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1185    #if [ $? -eq 0 ] ; then
1186    #    # Yes  ? then we try to get it in SCRATCHDIR
1187    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1188    #    if [ -f ${file_work[0]} ] ; then
1189    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1190    #   IGCM_debug_PopStack "IGCM_sys_Get"
1191    #   return
1192    #    fi
1193    #fi
1194
1195    # test if the (first) file is present in the old computation :
1196    IGCM_sys_TestFileArchive ${dm_liste[0]}
1197    RET=$?
1198    if [ ${RET} -gt 0 ] ; then
1199      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1200      IGCM_debug_Exit "IGCM_sys_Get"
1201    fi
1202
1203    dmget ${dm_liste[*]} > out_rsync 2>&1
1204    RET=$?
1205    if [ ${RET} -gt 0 ] ; then
1206      echo "WARNING IGCM_sys_Get : demigration error."
1207      cat out_rsync
1208      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1209    fi
1210
1211    #if [ ${RET} -gt 0 ] ; then
1212    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1213    #   cat out_rsync
1214    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1215    #   sleep 30
1216    #   echo "We try another time"
1217    #   dmget ${dm_liste[*]} > out_rsync 2>&1
1218    #   RET=$?
1219    #   if [ ${RET} -gt 0 ] ; then
1220    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1221    #       cat out_rsync
1222    #       IGCM_debug_Exit "IGCM_sys_Get"
1223    #   fi
1224    #    else
1225    #   echo "ERROR IGCM_sys_Get : demigration error :"
1226    #   cat out_rsync
1227    #   IGCM_debug_Exit "IGCM_sys_Get"
1228    #    fi
1229    #fi
1230
1231    #USUAL WAY
1232    if [ X${1} = X'/l' ] ; then
1233      (( RET=0 ))
1234      for target in ${dm_liste[*]} ; do
1235        local_file=$( basename ${target} )
1236        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1237        (( RET = RET + $? ))
1238      done
1239    else
1240      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1241      RET=$?
1242    fi
1243
1244#       #RSYNC WITH NETWORK SSH CALL
1245#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1246#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1247
1248#       #RSYNC WITH NFS USE
1249#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1250#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1251
1252#       RET=$?
1253#       IGCM_sys_Rsync_out $RET
1254
1255#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1256#       (( RET=RET+$? ))
1257
1258    if [ ${RET} -gt 0 ] ; then
1259      echo "IGCM_sys_Get : copy error."
1260      cat out_rsync
1261      IGCM_debug_Exit "IGCM_sys_Get"
1262    else
1263      \rm out_rsync
1264    fi
1265  else
1266    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1267  fi
1268  IGCM_debug_PopStack "IGCM_sys_Get"
1269}
1270
1271#D-#==================================================
1272#D-function IGCM_sys_GetBuffer
1273#D-* Purpose: Get a file from ${SCRATCHDIR}
1274#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1275#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1276function IGCM_sys_GetBuffer {
1277  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1278
1279  typeset DEST RET buf_liste ifile target file_work
1280
1281  if ( $DEBUG_sys ) ; then
1282    echo "IGCM_sys_GetBuffer :" $@
1283  fi
1284  if [ $DRYRUN -le 2 ]; then
1285    if [ X${1} = X'/l' ] ; then
1286      # test if the first file is present in the old computation :
1287      eval set +A buf_liste \${${2}}
1288    else
1289      eval set +A buf_liste ${1}
1290    fi
1291    eval DEST=\${${#}}
1292
1293    #USUAL WAY
1294    if [ X${1} = X'/l' ] ; then
1295      (( RET=0 ))
1296      for target in ${buf_liste[*]} ; do
1297        local_file=$( basename ${target} )
1298        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1299        (( RET = RET + $? ))
1300      done
1301    else
1302      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1303      RET=$?
1304    fi
1305
1306    if [ ${RET} -gt 0 ] ; then
1307      echo "IGCM_sys_GetBuffer : copy error."
1308      cat out_rsync
1309      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1310    else
1311      \rm out_rsync
1312    fi
1313  else
1314    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1315  fi
1316  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1317}
1318
1319#D-#==================================================
1320#D-function IGCM_sys_GetDate_FichWork
1321#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1322#D-* Examples:
1323#D-
1324function IGCM_sys_GetDate_FichWork {
1325  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1326  if ( $DEBUG_sys ) ; then
1327    echo "IGCM_sys_GetDate_FichWork :" $@
1328  fi
1329  typeset dateF
1330  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1331  eval ${2}=${dateF[5]}
1332
1333    # donne la date filesys d'un fichier sur la machine work
1334  IGCM_debug_PopStack "IGCM_sys_FichWork"
1335}
1336
1337#D-#==================================================
1338#D-function IGCM_sys_GetDate_FichArchive
1339#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1340#D-* Examples:
1341#D-
1342function IGCM_sys_GetDate_FichArchive {
1343  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1344  if ( $DEBUG_sys ) ; then
1345    echo "IGCM_sys_GetDate_FichArchive :" $@
1346  fi
1347  typeset dateF
1348  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1349  eval ${2}=${dateF[5]}
1350
1351  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1352}
1353
1354##############################################################
1355# REBUILD OPERATOR
1356
1357function IGCM_sys_rebuild {
1358  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1359  if ( $DEBUG_sys ) ; then
1360    echo "IGCM_sys_rebuild :" $@
1361  fi
1362  /home/cont003/p86ipsl/SX8/bin/rebuild -f -o $@
1363  if [ $? -gt 0 ] ; then
1364    echo "IGCM_sys_rebuild : erreur ${@}."
1365    IGCM_debug_Exit "rebuild"
1366  fi
1367
1368  IGCM_debug_PopStack "IGCM_sys_rebuild"
1369}
1370
1371############################################################
1372# Activate Running Environnment Variables
1373
1374function IGCM_sys_activ_variables {
1375  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1376  if ( $DEBUG_sys ) ; then
1377    echo "IGCM_sys_activ_variables"
1378  fi
1379
1380# --------------------------------------------------------------------
1381#D- MPI specifications
1382# --------------------------------------------------------------------
1383
1384#D-- MPISUSPEND
1385  export MPISUSPEND=${MPISUSPEND:=OFF}
1386
1387#D-- MPIPROGINF #other choices : ALL_DETAIL2
1388  export MPIPROGINF=ALL
1389#D- activate ftrace (with -ftrace)
1390  export F_FTRACE=YES
1391#D- communication information (with -ftrace)
1392  export MPICOMMINF=DETAIL
1393
1394# --------------------------------------------------------------------
1395#D- Other specifications
1396# --------------------------------------------------------------------
1397
1398#D- max number of character/line in output job
1399  export F_SYSLEN=5000
1400#D- number of error that can be admitted on the NEC
1401  export F_ERRCNT=0
1402#D- global performance
1403  export F_PROGINF=DETAIL
1404
1405#D- I/O performance (FORTRAN I/O only not netCDF)
1406  export F_FILEINF=${F_FILEINF:=NO}
1407#D- netCDF I/O performance
1408  export NC_FILEINF=${NC_FILEINF:=NO}
1409
1410  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1411}
1412
1413############################################################
1414# Desactivate Running Environnment Variables
1415
1416function IGCM_sys_desactiv_variables {
1417  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1418  if ( $DEBUG_sys ) ; then
1419    echo "IGCM_sys_desactiv_variables"
1420  fi
1421# --------------------------------------------------------------------
1422#D- MPI specifications
1423# --------------------------------------------------------------------
1424
1425#D-- MPIPROGINF
1426  export MPIPROGINF=NO
1427
1428# --------------------------------------------------------------------
1429#D- Other specifications
1430# --------------------------------------------------------------------
1431
1432#D- global performance
1433  export F_PROGINF=NO 
1434
1435  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1436}
1437
1438############################################################
1439# Build run file
1440
1441function IGCM_sys_build_run_file {
1442  IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1443  if ( $DEBUG_sys ) ; then
1444    echo "IGCM_sys_build_run_file " $@
1445  fi
1446  (( NUM_PROC_ATM = BATCH_NUM_PROC_TOT - 1 ))
1447  (( NUM_PROC_OASIS = BATCH_NUM_PROC_TOT - NUM_PROC_ATM ))
1448  (( NUM_PROC_OCE = BATCH_NUM_PROC_TOT - NUM_PROC_ATM ))
1449 
1450  if [ $1 = MPI2 ]; then
1451    cat <<EOF > run_file
1452-p 1 -np 1 -e ./oasis
1453EOF
1454    (( NUM_PROCESS = BATCH_NUM_PROC_TOT + 1 ))
1455    config_UserChoices_JobRunOptions='"-max_np ${NUM_PROCESS} -f"'
1456
1457  elif [ $1 = MPI1 ]; then
1458    cat <<EOF > run_file
1459-p $NUM_PROC_OASIS -e ./oasis
1460-p $NUM_PROC_ATM -e ./lmdz.x
1461-p $NUM_PROC_OCE -e ./opa.xx
1462EOF
1463  fi
1464  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1465}
Note: See TracBrowser for help on using the repository browser.