source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_cesium.ksh @ 591

Last change on this file since 591 was 591, checked in by sdipsl, 12 years ago
  • adapt TSC and create_ts to work with packed files
  • adapt dods related functions to work with work/store
  • bugfixes
  • replace tabulation by 2 space in TSC (svn diff -x -w)
    • sorry for the inconvenience but it will really help on the long run.
  • Property svn:keywords set to Revision Author Date
File size: 45.8 KB
RevLine 
[141]1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
[373]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
[141]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 Cesium
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
[217]65# $hostname ou hostname
[228]66typeset  HOST=${HOST:=$( hostname )}
[141]67# $username ou whoami
[228]68typeset  LOGIN=${LOGIN:=$( whoami )}
[141]69
70#D-
71#D-#==================================================
72#D-Program used in libIGCM
73#D-#==================================================
74
75# rsync with path
76typeset -r RSYNC=/usr/bin/rsync
77# RSYNC_opt args to rsync
[192]78typeset -r RSYNC_opt="-va"
[141]79# ie storage filesystem
[192]80typeset -r RHOST=cesium
[141]81
82#====================================================
[305]83# Source default environment
[141]84#====================================================
[184]85. /etc/profile
[141]86
87#====================================================
[305]88# Set environment tools (ferret, nco, cdo)
[141]89#====================================================
90. /home/cont003/p86ipsl/.atlas_env_cesium_ksh
91
92#====================================================
93# Specific for ocean additionnal diagnostic
94export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
95export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
96
97#====================================================
98# Host specific DIRECTORIES
99#====================================================
100
101#====================================================
102#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
103typeset -r R_EXE="${MODIPSL}/bin"
104
105#====================================================
106# For interactive jobs on cesium
107PBS_O_WORKDIR=${PBS_O_WORKDIR:=$(pwd)}
108
109#====================================================
110#- SUBMIT_DIR : submission dir
111typeset SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
112
113#====================================================
[587]114#- ARCHIVE (dedicated to large files)
115typeset -r ARCHIVE=${CCCSTOREDIR}
[141]116
[587]117#- ARCHIVE (dedicated to small/medium files)
118typeset -r STORAGE=${CCCWORKDIR}
119
[141]120#====================================================
[587]121
122#====================================================
[141]123#- IN
[545]124typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
[438]125typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
[141]126
127#====================================================
[544]128#- R_OUT
[141]129typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
130
131#====================================================
[587]132#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
133typeset -r R_FIG=${STORAGE}/IGCM_OUT
134
135#====================================================
[544]136#- R_BUF (ONLY FOR double copy an scratch)
137typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
[141]138
139#====================================================
140#- OUT_POST
141typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
142
143#====================================================
144#- RUN_DIR_PATH : Temporary working directory (=> TMP)
[331]145PBS_JOBID=${PBS_JOBID:=TEMPDIR$$}
[196]146typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/${PBS_JOBID}}
[141]147
148#====================================================
149#- Max number of arguments passed to nco operator or demigration command
150UNIX_MAX_LIMIT=360
151
152#D-#==================================================
153#D-function IGCM_sys_RshMaster
[192]154#D-* Purpose: Just a fake command to wrapp
155#D-           IGCM_card call in post-treatment
156#D-           Ulam do not see brodie filesystem
157#D-           Cesium do not see all mercure filesystem
158#D-           That's why we need this hack.
[141]159#D-* Examples:
160#D-
161function IGCM_sys_RshMaster {
[544]162  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
163  typeset NB_ESSAI DELAI status i
164  # number of tentative
165  NB_ESSAI=10
166  # time delay between tentative
167  DELAI=10
168  #
169  (( i = 0 ))
170  while [ $i -lt $NB_ESSAI ] ; do
171    ssh ${MASTER} exec /bin/ksh <<-EOF
[192]172    export libIGCM=${libIGCM_SX}
[141]173    export DEBUG_debug=${DEBUG_debug}
[192]174    . ${libIGCM_SX}/libIGCM_debug/libIGCM_debug.ksh
175    . ${libIGCM_SX}/libIGCM_card/libIGCM_card.ksh
[141]176    ${@}
177EOF
[544]178    status=$?
179    if [ ${status} -gt 0 ]; then
180      IGCM_debug_Print 2 "IGCM_sys_RshMaster : ssh failed ${i}/${NB_ESSAI}"
181      IGCM_debug_Print 2 "IGCM_sys_RshMaster : sleep ${DELAI} seconds and try again."
182      sleep $DELAI
183    else
184      break
185    fi
186    (( i = i + 1 ))
187  done
[396]188
[544]189  IGCM_debug_PopStack "IGCM_sys_RshMaster"
[141]190}
191
192#D-#==================================================
193#D-function IGCM_sys_RshArchive
194#D-* Purpose: Archive rsh command
195#D-* Examples:
196#D-
197function IGCM_sys_RshArchive {
[544]198  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
199  /bin/ksh <<-EOF
[141]200    ${@}
201EOF
[544]202  if [ $? -gt 0 ] ; then
203    echo "IGCM_sys_RshArchive : erreur."
204    IGCM_debug_Exit "IGCM_sys_RshArchive"
205  fi
206  IGCM_debug_PopStack "IGCM_sys_RshArchive"
[141]207}
208
209#D-#==================================================
210#D-function IGCM_sys_RshPost
[343]211#D-* Purpose: Post-process rsh command
[141]212#D-* Examples:
213#D-
214function IGCM_sys_RshPost {
[544]215  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
216  if ( $DEBUG_sys ) ; then
217    echo "IGCM_sys_RshPost :" $@
218  fi
219
220  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
221  #cat tmp_IGCM_sys_RshPost_$$
222  # keep standard input (stdin) for the loop onto temporary file
223  cat >tmp_IGCM_sys_RshPost_$$
224
225  /bin/ksh <tmp_IGCM_sys_RshPost_$$
226  if [ $? -gt 0 ] ; then
227    echo "IGCM_sys_RshPost : erreur."
228    IGCM_debug_Exit "IGCM_sys_RshPost"
229    cat tmp_IGCM_sys_RshPost_$$
230  fi
231  # delete temporary file
232  \rm tmp_IGCM_sys_RshPost_$$
233
234  IGCM_debug_PopStack "IGCM_sys_RshPost"
[141]235}
236
237#D-#==================================================
[228]238#D-function IGCM_sys_SendMail
239#D-* Purpose: Send mail when simulation is over
240#D-* Examples:
241#D-
242function IGCM_sys_SendMail {
[544]243  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
244  if ( $DEBUG_sys ) ; then
245    echo "IGCM_sys_SendMail :" $@
246  fi
[228]247
[544]248  if ( ${ExitFlag} ) ; then
249    status=failed
250  else
251    status=completed
252  fi
[452]253
[544]254  ssh mercure <<-EOF
[228]255    export LOGIN=${LOGIN}
256    export config_UserChoices_JobName=${config_UserChoices_JobName}
257    export config_UserChoices_MailName=${config_UserChoices_MailName}
258    export DateBegin=${DateBegin}
259    export DateEnd=${DateEnd}
260    export R_SAVE=${R_SAVE}
[288]261    export SUBMIT_DIR=${SUBMIT_DIR}
[452]262    export status=${status}
[228]263
264    cat  << END_MAIL > job_end.mail
265Dear ${LOGIN},
266
[452]267  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
[228]268  Job started : ${DateBegin}
269  Job ended   : ${DateEnd}
[434]270  Output files are available in ${R_SAVE}
[453]271  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
[228]272END_MAIL
273
274    if [ ! -z ${config_UserChoices_MailName} ] ; then
[440]275       mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
[228]276    elif [ -f ~/.forward ] ; then
[440]277       mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
[228]278    fi
279    sleep 10
280    rm -f job_end.mail
281EOF
282
[544]283  if [ $? -gt 0 ] ; then
284    echo "IGCM_sys_SendMail : erreur."
285    IGCM_debug_Exit "IGCM_sys_SendMail"
286  fi
287  IGCM_debug_PopStack "IGCM_sys_SendMail"
[228]288}
289
290#D-#==================================================
[141]291#D-function IGCM_sys_Mkdir
292#D-* Purpose: Master locale mkdir command
293#D-* Examples:
294#D-
295function IGCM_sys_Mkdir {
[544]296  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
297  if ( $DEBUG_sys ) ; then
298    echo "IGCM_sys_Mkdir :" $@
299  fi
300  if [ ! -d ${1} ]; then
301    \mkdir -p $1
302    if [ $? -gt 0 ] ; then
303      echo "IGCM_sys_Mkdir : erreur."
304      IGCM_debug_Exit "IGCM_sys_Mkdir"
[141]305    fi
[544]306  fi
307  # vérification :
308  if [ ! -d ${1} ] ; then
309    echo "IGCM_sys_Mkdir : erreur."
310    IGCM_debug_Exit "IGCM_sys_Mkdir"
311  fi
312  IGCM_debug_PopStack "IGCM_sys_Mkdir"
[141]313}
314
315#D-#==================================================
316#D-function IGCM_sys_MkdirArchive
317#D-* Purpose: Mkdir on Archive
318#D-* Examples:
319#D-
320function IGCM_sys_MkdirArchive {
[544]321  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
322  if ( $DEBUG_sys ) ; then
323    echo "IGCM_sys_MkdirArchive :" $@
324  fi
325  #- creation de repertoire sur le serveur fichier
326  if [ ! -d ${1} ]; then 
327    \mkdir -p $1
328    if [ $? -gt 0 ] ; then
329      echo "IGCM_sys_MkdirArchive : erreur."
330      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
[141]331    fi
[544]332  fi
333  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
[141]334}
335
336#D-#==================================================
337#D-function IGCM_sys_MkdirWork
338#D-* Purpose: Mkdir on Work
339#D-* Examples:
340#D-
341function IGCM_sys_MkdirWork {
[544]342  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
343  if ( $DEBUG_sys ) ; then
344    echo "IGCM_sys_MkdirWork :" $@
345  fi
346  #- creation de repertoire sur le serveur fichier
347  if [ ! -d ${1} ]; then 
348    \mkdir -p $1
349    if [ $? -gt 0 ] ; then
350      echo "IGCM_sys_MkdirWork : erreur."
351      IGCM_debug_Exit "IGCM_sys_MkdirWork"
[141]352    fi
[544]353  fi
354  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
[141]355}
356
357#D-#==================================================
358#D-function IGCM_sys_Cd
359#D-* Purpose: master cd command
360#D-* Examples:
361#D-
362function IGCM_sys_Cd {
[544]363  IGCM_debug_PushStack "IGCM_sys_Cd" $@
364  if ( $DEBUG_sys ) ; then
365    echo "IGCM_sys_Cd :" $@
366  fi
367  \cd $1
368  if [ $? -gt 0 ] ; then
369    echo "IGCM_sys_Cd : erreur."
370    IGCM_debug_Exit "IGCM_sys_Cd"
371  fi
372  IGCM_debug_PopStack "IGCM_sys_Cd"
[141]373}
374
375#D-#==================================================
376#D-function IGCM_sys_Chmod
377#D-* Purpose: Chmod
378#D-* Examples:
379#D-
380function IGCM_sys_Chmod {
[544]381  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
382  if ( $DEBUG_sys ) ; then
383    echo "IGCM_sys_Chmod :" $@
384  fi
385  if [ $DRYRUN -le 1 ]; then
386    \chmod $@
387    if [ $? -gt 0 ] ; then
388      echo "IGCM_sys_Chmod : erreur."
389      IGCM_debug_Exit "IGCM_sys_Chmod"
[141]390    fi
[544]391  else
392    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
393  fi
394  IGCM_debug_PopStack "IGCM_sys_Chmod"
[141]395}
396
397#D-#==================================================
398#D-function IGCM_sys_FileSize
399#D-* Purpose: Filesize
400#D-* Examples:
401#D-
402function IGCM_sys_FileSize {
[544]403  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
[141]404
[544]405  typeset sizeF
406  set +A sizeF -- $( ls -la ${1} )
407  if [ $? -gt 0 ] ; then
408    IGCM_debug_Exit "IGCM_sys_FileSize"
409  fi
410  eval ${2}=${sizeF[4]}
[141]411
[544]412  IGCM_debug_PopStack "IGCM_sys_FileSize"
[141]413}
414
415#D-#==================================================
416#D-function IGCM_sys_TestDir
417#D-* Purpose: Test Directory that must exists
418#D-* Examples:
419#D-
420function IGCM_sys_TestDir {
[544]421  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
422  if ( $DEBUG_sys ) ; then
423    echo "IGCM_sys_TestDir :" $@
424  fi
425  typeset ExistFlag
426  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
427  IGCM_debug_PopStack "IGCM_sys_TestDir"
[141]428
[544]429  return ${ExistFlag}
[141]430}
431
432#D-#==================================================
433#D-function IGCM_sys_TestDirArchive
434#D-* Purpose: Test Directory that must exists on Archive
435#D-* Examples:
436#D-
437function IGCM_sys_TestDirArchive {
[544]438  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
439  if ( $DEBUG_sys ) ; then
440    echo "IGCM_sys_TestDirArchive :" $@
441  fi
442  typeset ExistFlag
443  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
444  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
[141]445
[544]446  return ${ExistFlag}
[141]447}
448
449#D-#==================================================
[548]450#D-function IGCM_sys_IsFileArchived
451#D-* Purpose: Test file that must NOT EXISTS on Archive
452#D-* Examples:
453#D-
454function IGCM_sys_IsFileArchived {
455  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
456  if ( $DEBUG_sys ) ; then
457    echo "IGCM_sys_IsFileArchived :" $@
458  fi
459  typeset IsArchivedFlag
460  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/dmnfs ) != X ] && echo 0 || echo 1 )
461  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
462
463  return ${IsArchivedFlag}
464}
465
466#D-#==================================================
[141]467#D-function IGCM_sys_TestFileArchive
468#D-* Purpose: Test file that must NOT EXISTS on Archive
469#D-* Examples:
470#D-
471function IGCM_sys_TestFileArchive {
[544]472  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
473  if ( $DEBUG_sys ) ; then
474    echo "IGCM_sys_TestFileArchive :" $@
475  fi
476  typeset ExistFlag
477  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
478  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
[141]479
[544]480  return ${ExistFlag}
[141]481}
482
483#D-#==================================================
[544]484#D-function IGCM_sys_TestFileBuffer
485#D-* Purpose: Test file that must NOT EXISTS on Buffer
486#D-* Examples:
487#D-
488function IGCM_sys_TestFileBuffer {
489  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
490  typeset ExistFlag
491  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
492  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
493
494  return ${ExistFlag}
495}
496
497#D-#==================================================
[141]498#D-function IGCM_sys_CountFileArchive
499#D-* Purpose: Count files on Archive filesystem
500#D-* Examples:
501#D-
502function IGCM_sys_CountFileArchive {
[544]503  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
504  ls ${@} 2>/dev/null | wc -l
505  if [ $? -gt 0 ] ; then
506    echo "IGCM_sys_CountFileArchive : erreur."
507  fi
508  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
[141]509}
510
511#D-#==================================================
[544]512#D-function IGCM_sys_CountFileBuffer
513#D-* Purpose: Count files on Master Scratch filesystem
514#D-* Examples:
515#D-
516function IGCM_sys_CountFileBuffer {
517  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
518  ls ${@} 2>/dev/null | wc -l
519  if [ $? -gt 0 ] ; then
520    echo "IGCM_sys_CountFileBuffer : erreur."
521  fi
522  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
523}
524
525#D-#==================================================
[141]526#D-function IGCM_sys_Tree
527#D-* Purpose: Tree directories with files on ${ARCHIVE}
528#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
529#D-
530function IGCM_sys_Tree {
[544]531  IGCM_debug_PushStack "IGCM_sys_Tree" $@
532  if ( $DEBUG_sys ) ; then
533    echo "IGCM_sys_Tree :" $@
534  fi
[141]535
[544]536  \tree -f $@
[141]537
[544]538  IGCM_debug_PopStack "IGCM_sys_Tree"
[141]539}
540
541#D-#==================================================
542#D-function IGCM_sys_Tar
[544]543#D-* Purpose: master tar command
[141]544#D-* Examples:
545#D-
546function IGCM_sys_Tar {
[544]547  IGCM_debug_PushStack "IGCM_sys_Tar" $@
548  if ( $DEBUG_sys ) ; then
549    echo "IGCM_sys_Tar :" $@
550  fi
551  \tar cf $@
552  if [ $? -gt 0 ] ; then
553    echo "IGCM_sys_Tar : erreur."
554    IGCM_debug_Exit "IGCM_sys_Tar"
555  fi
556  IGCM_debug_PopStack "IGCM_sys_Tar"
[141]557}
558
559#D-#==================================================
560#D-function IGCM_sys_UnTar
561#D-* Purpose: master un-tar command
562#D-* Examples:
563#D-
564function IGCM_sys_UnTar {
[544]565  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
566  if ( $DEBUG_sys ) ; then
567    echo "IGCM_sys_UnTar :" $@
568  fi
569  \tar xvf $1
570  if [ $? -gt 0 ] ; then
571    echo "IGCM_sys_UnTar : erreur."
572    IGCM_debug_Exit "IGCM_sys_UnTar"
573  fi
574  IGCM_debug_PopStack "IGCM_sys_UnTar"
[141]575}
576
577#D-#==================================================
[228]578#D-function IGCM_sys_Qsub
579#D-* Purpose: Qsub new job
580#D-* Examples:
581#D-
582function IGCM_sys_Qsub {
[544]583  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
584  if ( $DEBUG_sys ) ; then
585    echo "IGCM_sys_Qsub :" $@
586  fi
587  /usr/local/bin/ccc_msub -o ${Script_Output} -e ${Script_Output}.e < $1
588  if [ $? -gt 0 ] ; then
589    echo "IGCM_sys_Qsub : erreur  -o ${Script_Output} -e ${Script_Output}.e $@"
590    IGCM_debug_Exit "IGCM_sys_Qsub"
591  fi
592  IGCM_debug_PopStack "IGCM_sys_Qsub"
[228]593}
594
595#D-#==================================================
[141]596#D-function IGCM_sys_QsubPost
597#D-* Purpose: Qsub new job on scalaire
598#D-* Examples:
599#D-
600function IGCM_sys_QsubPost {
[544]601  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
602  if ( $DEBUG_sys ) ; then
603    echo "IGCM_sys_QsubPost :" $@
604  fi
605  /usr/local/bin/ccc_msub -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.e.out -E "-v ${listVarEnv}" ${libIGCM}/$1.job
606  if [ $? -gt 0 ] ; then
607    echo "IGCM_sys_QsubPost : erreur " $@
608    IGCM_debug_Exit "IGCM_sys_QsubPost"
609  fi
610  IGCM_debug_PopStack "IGCM_sys_QsubPost"
[141]611}
612
613#D-*************************
614#D- File transfer functions
615#D-*************************
616#D-
617
618#D-#==================================================
619#D-function IGCM_sys_Rsync_out
620#D-* Purpose: treat return val of rsync
621#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
622#D-  Error values and explanations can depend on your system version.
623function IGCM_sys_Rsync_out {
[544]624  RET=$1
625  if [ ! $RET ] ; then
626    echo "rsync error !"
627  fi
[141]628
[544]629  if [ $MYLANG = "fr" ]; then
630    case $RET in
631    0)  return ;;
632    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
633      echo "Erreur de syntaxe ou d'utilisation."
634      return;;
635    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
636      echo "Incompatibilité de protocole."
637      return;;
638    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
639      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
640      echo "répertoires"
641      return;;
642    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
643      echo "Action demandée non supportée : une tentative de manipulation de"
644      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
645      echo "été faite ; ou une option qui est supportée par le  client  mais"
646      echo "pas par le serveur a été spécifiée."
647      return;;
648    10) echo "Erreur de rsync ; RERR_SOCKETIO"
649      echo "Erreur dans le socket d'entrée sortie"
650      return;;
651    11) echo "Erreur de rsync ; RERR_FILEIO"
652      echo "Erreur d'entrée sortie fichier"
653      return;;
654    12) echo "Erreur de rsync ; RERR_STREAMIO"
655      echo "Erreur dans flux de donnée du protocole rsync"
656      return;;
657    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
658      echo "Erreur avec les diagnostics du programme"
659      return;;
660    14) echo "Erreur de rsync ; RERR_IPC"
661      echo "Erreur dans le code IPC"
662      return;;
663    20) echo "Erreur de rsync ; RERR_SIGNAL"
664      echo "SIGUSR1 ou SIGINT reçu"
665      return;;
666    21) echo "Erreur de rsync ; RERR_WAITCHILD"
667      echo "Une erreur retournée par waitpid()"
668      return;;
669    22) echo "Erreur de rsync ; RERR_MALLOC"
670      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
671      return;;
672    23) echo ""
673      echo "Erreur fichier inexistant"
674      return;;
675    30) echo "Erreur de rsync ; RERR_TIMEOUT"
676      echo "Temps d'attente écoulé dans l'envoi/réception de données"
677      return;;
678    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
679      return;;
680    esac
681  elif [ $MYLANG = "en" ] ; then
682    case $RET in
683    0)  return;;               
684    1)  echo "rsync error : Syntax or usage error "
685      return;;
686    2)  echo "rsync error : Protocol incompatibility "
687      return;;
688    3)  echo "rsync error : Errors selecting input/output files, dirs"
689      return;;
690    4)  echo "rsync error : Requested action not supported: an attempt"
691      echo "was made to manipulate 64-bit files on a platform that cannot support"
692      echo "them; or an option was specified that is supported by the client and"
693      echo "not by the server."
694      return;;
695    5)  echo "rsync error : Error starting client-server protocol"
696      return;;
697    10) echo "rsync error : Error in socket I/O "
698      return;;
699    11) echo "rsync error : Error in file I/O "
700      return;;
701    12) echo "rsync error : Error in rsync protocol data stream "
702      return;;
703    13) echo "rsync error : Errors with program diagnostics "
704      return;;
705    14) echo "rsync error : Error in IPC code "
706      return;;
707    20) echo "rsync error : Received SIGUSR1 or SIGINT "
708      return;;
709    21) echo "rsync error : Some error returned by waitpid() "
710      return;;
711    22) echo "rsync error : Error allocating core memory buffers "
712      return;;
713    23) echo "rsync error : Partial transfer due to error"
714      return;;
715    24) echo "rsync error : Partial transfer due to vanished source files"
716      return;;
717    30) echo "rsync error : Timeout in data send/receive "
718      return;;
719    *)  echo "rsync error : return code of rsync unknown :" $RET
720      return;;
721    esac
722  else
723    echo "unknown language $MYLANG."
724    return
725  fi
[141]726}
[544]727
[141]728#D-#==================================================
729#D-function IGCM_sys_Cp
730#D-* Purpose: generic cp
731#D-* Examples:
732#D-
733function IGCM_sys_Cp {
[544]734  IGCM_debug_PushStack "IGCM_sys_Cp" $@
735  if ( $DEBUG_sys ) ; then
736    echo "IGCM_sys_Cp :" $@
737  fi
[141]738
[544]739  typeset RET
[141]740
[544]741  echo cp $@ > out_rsync 2>&1
742  \cp $@ >> out_rsync 2>&1
743  RET=$?
[141]744
[544]745  if [ ${RET} -gt 0 ] ; then
746    echo "IGCM_sys_Cp : error."
747    cat out_rsync
748    IGCM_debug_Exit "IGCM_sys_Cp"
749  else
750    \rm out_rsync
751  fi
752  IGCM_debug_PopStack "IGCM_sys_Cp"
[141]753}
754
755#D-#==================================================
756#D-function IGCM_sys_Rm
757#D-* Purpose: generic rm
758#D-* Examples:
759#D-
760function IGCM_sys_Rm {
[544]761  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
762  if ( $DEBUG_sys ) ; then
763    echo "IGCM_sys_Rm :" $@
764  fi
[141]765
[544]766  typeset RET
[141]767
[544]768  echo rm $@ > out_rsync 2>&1
769  \rm $@ >> out_rsync 2>&1
770  RET=$?
[192]771
[544]772  if [ ${RET} -gt 0 ] ; then
773    echo "IGCM_sys_Rm : error."
774    cat out_rsync
775    IGCM_debug_Exit "IGCM_sys_Rm"
776  else
777    \rm out_rsync
778  fi
779  IGCM_debug_PopStack "IGCM_sys_Rm"
[141]780}
781
782#D-#==================================================
[203]783#D-function IGCM_sys_RmRunDir
784#D-* Purpose: rm tmpdir (dummy function most of the time batch
785#D-                      scheduler will do the job)
786#D-* Examples:
787#D-
788function IGCM_sys_RmRunDir {
[544]789  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
790  if ( $DEBUG_sys ) ; then
791    echo "IGCM_sys_RmRunDir :" $@
792  fi
[203]793
[544]794  typeset RET
[203]795
[544]796  echo rm $@ > out_rsync 2>&1
797  \rm $@ >> out_rsync 2>&1
798  RET=$?
[203]799
[544]800  if [ ${RET} -gt 0 ] ; then
801    echo "IGCM_sys_RmRunDir : error."
802    cat out_rsync
803    IGCM_debug_Exit "IGCM_sys_RmRunDir"
804  else
805    \rm out_rsync
806  fi
807  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
[203]808}
809
810#D-#==================================================
[141]811#D-function IGCM_sys_Mv
812#D-* Purpose: generic move
813#D-* Examples:
814#D-
815function IGCM_sys_Mv {
[544]816  IGCM_debug_PushStack "IGCM_sys_Mv" $@
817  if ( $DEBUG_sys ) ; then
818    echo "IGCM_sys_Mv :" $@
819  fi
[141]820
[544]821  if [ $DRYRUN = 0 ]; then
[141]822
[544]823    typeset RET
[173]824   
[544]825    echo mv $@ > out_rsync 2>&1
826    \mv $@ >> out_rsync 2>&1
827    RET=$?
828   
829    if [ ${RET} -gt 0 ] ; then
830      echo "IGCM_sys_Mv : error in mv."
831      cat out_rsync
832      IGCM_debug_Exit "IGCM_sys_Mv"
[173]833    else
[544]834      \rm out_rsync
[141]835    fi
[544]836  else
837    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
838  fi
[141]839
[544]840  IGCM_debug_PopStack "IGCM_sys_Mv"
[141]841}
842
843#D-#==================================================
844#D-function IGCM_sys_Put_Dir
845#D-* Purpose: Copy a complete directory on $(ARCHIVE)
846#D-* Examples:
847#D-
848function IGCM_sys_Put_Dir {
[544]849  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
850  if ( $DEBUG_sys ) ; then
851    echo "IGCM_sys_Put_Dir :" $@
852  fi
853  if [ $DRYRUN = 0 ]; then
854    if [ ! -d ${1} ] ; then
855      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
856      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
857      return
[141]858    fi
859
[544]860    typeset RET
[141]861
[544]862    # Only if we use rsync
863    #IGCM_sys_TestDirArchive $( dirname $2 )
864    #
865    #USUAL WAY
866    \cp -r $1 $2 > out_rsync 2>&1
867    RET=$?
[141]868
[544]869    if [ ${RET} -gt 0 ] ; then
870      echo "IGCM_sys_Put_Dir : error."
871      cat out_rsync
872      IGCM_debug_Exit "IGCM_sys_Put_Dir"
[141]873    else
[544]874      \rm out_rsync
[141]875    fi
[544]876  else
877    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
878  fi
879  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
[141]880}
881
882#D-#==================================================
883#D-function IGCM_sys_Get_Dir
[544]884#D-* Purpose: Copy a complete directory from ${ARCHIVE}
[141]885#D-* Examples:
886#D-
887function IGCM_sys_Get_Dir {
[544]888  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
889  if ( $DEBUG_sys ) ; then
890    echo "IGCM_sys_Get_Dir :" $@
891  fi
892  if [ $DRYRUN = 0 ]; then
893#    if [ ! -d ${1} ] ; then
894#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
895#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
896#      return
897#    fi
[141]898
[544]899    typeset RET
[141]900
[544]901    # Only if we use rsync
902    #IGCM_sys_TestDirArchive $( dirname $2 )
903    #
904    # USUAL WAY
905    # add dmfind/dmget (to demigrate all offline files) :
[587]906    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
[544]907    \cp -r $1 $2 > out_rsync 2>&1
908    RET=$?
[141]909
[544]910    if [ ${RET} -gt 0 ] ; then
911      echo "IGCM_sys_Get_Dir : error."
912      cat out_rsync
913      IGCM_debug_Exit "IGCM_sys_Get_Dir"
[141]914    else
[544]915      \rm out_rsync
[141]916    fi
[544]917  else
918    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
919  fi
920  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
[141]921}
922
923#D-#==================================================
924#D-function IGCM_sys_Get_Master
925#D-* Purpose: Copy a complete directory from MASTER filesystem
926#D-* Examples:
927#D-
928function IGCM_sys_Get_Master {
[544]929  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
930  if ( $DEBUG_sys ) ; then
931    echo "IGCM_sys_Get_Master :" $@
932  fi
933  if [ $DRYRUN = 0 ]; then
934
935    typeset TEST NB_ESSAI DELAI status i
936   
937    TEST=$( IGCM_sys_RshMaster [ -d $1 ] && echo 1 || echo 0 )
938    if [ ${TEST} -ne 1 ] ; then
939      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ON ${MASTER}."
940      IGCM_debug_PopStack "IGCM_sys_Get_Master"
941      return
[141]942    fi
[387]943
[544]944    # number of tentative
945    NB_ESSAI=10
946    # time delay between tentative
947    DELAI=10
948    #
949    (( i = 0 ))
950    while [ $i -lt $NB_ESSAI ] ; do
[387]951            #USUAL WAY
[544]952      scp -r ${MASTER}:$1 $2 > out_rsync 2>&1
953      status=$?
954      if [ ${status} -gt 0 ]; then
955        IGCM_debug_Print 2 "IGCM_sys_Get_Master : scp failed ${i}/${NB_ESSAI}"
956        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
957        sleep $DELAI
958      else
959        break
960      fi
961      (( i = i + 1 ))
962    done
[141]963
[544]964    if [ ${status} -gt 0 ] ; then
965      echo "IGCM_sys_Get_Master : error."
966      cat out_rsync
967      IGCM_debug_Exit "IGCM_sys_Get_Master"
[141]968    else
[544]969      \rm out_rsync
[141]970    fi
[544]971  else
972    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
973  fi
974  IGCM_debug_PopStack "IGCM_sys_Get_Master"
[141]975}
976
977#D-#==================================================
[228]978#D-function IGCM_sys_Put_Rest
[544]979#D-* Purpose: Put computied restarts on ${ARCHIVE}.
[228]980#D-           File and target directory must exist.
981#D-* Examples:
982#D-
983function IGCM_sys_Put_Rest {
[544]984  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
985  if ( $DEBUG_sys ) ; then
986    echo "IGCM_sys_Put_Rest :" $@
987  fi
988  if [ $DRYRUN = 0 ]; then
989    if [ ! -f ${1} ] ; then
990      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
991      IGCM_debug_Exit "IGCM_sys_Put_Rest"
[228]992    fi
993
[544]994    typeset RET
995    #
996    if [ X${JobType} = XRUN ] ; then
997      IGCM_sys_Chmod 444 ${1}
998    fi
[228]999
[544]1000    #
1001    # USUAL WAY
1002    \cp $1 $2 > out_rsync 2>&1
1003    RET=$?
1004
[228]1005#       #RSYNC WITH NETWORK SSH CALL
[544]1006#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1007#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
[228]1008
1009#       #RSYNC WITH NFS USE
1010#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1011#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1012
1013#       RET=$?
1014#       IGCM_sys_Rsync_out $RET
1015
1016#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1017#       (( RET=RET+$? ))
1018
[544]1019    if [ ${RET} -gt 0 ] ; then
1020      echo "IGCM_sys_Put_Rest : error."
1021      cat out_rsync
1022      IGCM_debug_Exit "IGCM_sys_Put_Rest"
[228]1023    else
[544]1024      \rm out_rsync
[228]1025    fi
[544]1026  else
1027    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1028  fi
1029  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
[228]1030}
1031
1032#D-#==================================================
[141]1033#D-function IGCM_sys_Put_Out
[544]1034#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
[141]1035#D-* Examples:
1036#D-
1037function IGCM_sys_Put_Out {
[544]1038  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1039  if ( $DEBUG_sys ) ; then
1040    echo "IGCM_sys_Put_Out :" $@
1041  fi
1042  if [ $DRYRUN = 0 ]; then
1043    if [ ! -f ${1} ] ; then
1044      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1045      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1046      return 1
[141]1047    fi
[544]1048    #
1049    IGCM_sys_MkdirArchive $( dirname $2 )
1050    #
1051    typeset RET exist skip
[228]1052
[544]1053    #=====================================================
1054    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1055    #=====================================================
[228]1056
[544]1057    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1058    #if [ $? -eq 0 ] ; then
1059    #    typeset WORKPATH FILEPATH
1060    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1061    #    IGCM_sys_MkdirWork ${WORKPATH}
1062    #    FILEPATH=${WORKPATH}/$( basename $2 )
1063    #    #
1064    #    IGCM_sys_Cp ${1} ${FILEPATH}
1065    #fi
[228]1066
[544]1067    if [ X${JobType} = XRUN ] ; then
1068      if [ X${3} = X ] ; then
1069        IGCM_sys_Chmod 444 ${1}
1070      fi
1071    fi
[141]1072
[544]1073    exist=false
1074    skip=false
1075    if [ -f $2 ] ; then
1076      IGCM_debug_Print 1 "$2 already exist"
[587]1077      #dmget $2
1078      ccc_hsm get $2
[544]1079      exist=true
1080      if [ "X$( diff $1 $2 )" = X ] ; then
1081        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1082        skip=true
1083      else
1084        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
[360]1085        skip=false
[544]1086      fi
1087    fi
[358]1088        #
[544]1089    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1090      IGCM_sys_Chmod u+w $2
1091    fi
[358]1092        # USUAL WAY
[544]1093    if [ X${skip} = Xfalse ] ; then
1094      cp $1 $2 > out_rsync 2>&1
1095      RET=$?
1096      if [ ${RET} -gt 0 ] ; then
1097        echo "IGCM_sys_Put_Out : error."
1098        cat out_rsync
1099        IGCM_debug_Exit "IGCM_sys_Put_Out"
1100      else
1101        \rm out_rsync
1102      fi
1103    fi
[358]1104
[141]1105#       #RSYNC WITH NETWORK RSH CALL
[192]1106#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
1107#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
[141]1108
1109#       #RSYNC WITH NFS USE
[192]1110#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1111#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
[141]1112
1113#       RET=$?
1114#       IGCM_sys_Rsync_out $RET
1115
1116#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1117#       (( RET=RET+$? ))
1118
[358]1119
[544]1120  else
1121    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1122  fi
1123  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1124  return 0
[141]1125}
1126
1127#D-#==================================================
1128#D-function IGCM_sys_Get
1129#D-* Purpose: Get a file from ${ARCHIVE}
1130#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1131#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1132function IGCM_sys_Get {
[544]1133  IGCM_debug_PushStack "IGCM_sys_Get" $@
[141]1134
[544]1135  typeset DEST RET dm_liste ifile target file_work
[141]1136
[544]1137  if ( $DEBUG_sys ) ; then
1138    echo "IGCM_sys_Get :" $@
1139  fi
1140  if [ $DRYRUN -le 2 ]; then
1141    if [ X${1} = X'/l' ] ; then
1142      # test if the first file is present in the old computation :
1143      eval set +A dm_liste \${${2}}
1144    else
1145      eval set +A dm_liste ${1}
[141]1146    fi
[544]1147    eval DEST=\${${#}}
[141]1148
[544]1149    #=====================================================
1150    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1151    #=====================================================
[141]1152
[544]1153    # Is it an R_OUT file (not R_IN) ?
1154    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1155    #if [ $? -eq 0 ] ; then
1156    #    # Yes  ? then we try to get it in SCRATCHDIR
1157    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1158    #    if [ -f ${file_work[0]} ] ; then
1159    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1160    #   IGCM_debug_PopStack "IGCM_sys_Get"
1161    #   return
1162    #    fi
1163    #fi
[141]1164
[544]1165    # test if the (first) file is present in the old computation :
1166    IGCM_sys_TestFileArchive ${dm_liste[0]}
1167    RET=$?
1168    if [ ${RET} -gt 0 ] ; then
1169      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1170      IGCM_debug_Exit "IGCM_sys_Get"
1171    fi
[141]1172
[587]1173    #dmget ${dm_liste[*]} > out_rsync 2>&1
1174    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
[544]1175    RET=$?
1176    if [ ${RET} -gt 0 ] ; then
1177      echo "WARNING IGCM_sys_Get : demigration error."
1178      cat out_rsync
1179      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1180    fi
[520]1181
[544]1182    #if [ ${RET} -gt 0 ] ; then
1183    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1184    #   cat out_rsync
1185    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1186    #   sleep 30
1187    #   echo "We try another time"
[587]1188    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1189    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
[544]1190    #   RET=$?
1191    #   if [ ${RET} -gt 0 ] ; then
1192    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1193    #       cat out_rsync
1194    #       IGCM_debug_Exit "IGCM_sys_Get"
1195    #   fi
1196    #    else
1197    #   echo "ERROR IGCM_sys_Get : demigration error :"
1198    #   cat out_rsync
1199    #   IGCM_debug_Exit "IGCM_sys_Get"
1200    #    fi
1201    #fi
[141]1202
[544]1203    #USUAL WAY
1204    if [ X${1} = X'/l' ] ; then
1205      (( RET=0 ))
1206      for target in ${dm_liste[*]} ; do
1207        local_file=$( basename ${target} )
1208        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1209        (( RET = RET + $? ))
1210      done
1211    else
1212      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1213      RET=$?
1214    fi
[520]1215
[228]1216#       #RSYNC WITH NETWORK SSH CALL
[192]1217#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1218#       ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
[141]1219
1220#       #RSYNC WITH NFS USE
[192]1221#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1222#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
[141]1223
1224#       RET=$?
1225#       IGCM_sys_Rsync_out $RET
1226
1227#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1228#       (( RET=RET+$? ))
1229
[544]1230    if [ ${RET} -gt 0 ] ; then
1231      echo "IGCM_sys_Get : copy error."
1232      cat out_rsync
1233      IGCM_debug_Exit "IGCM_sys_Get"
[141]1234    else
[544]1235      \rm out_rsync
[141]1236    fi
[544]1237  else
1238    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1239  fi
1240  IGCM_debug_PopStack "IGCM_sys_Get"
[141]1241}
1242
1243#D-#==================================================
[544]1244#D-function IGCM_sys_GetBuffer
1245#D-* Purpose: Get a file from ${SCRATCHDIR}
1246#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1247#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1248function IGCM_sys_GetBuffer {
1249  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1250
1251  typeset DEST RET buf_liste ifile target file_work
1252
1253  if ( $DEBUG_sys ) ; then
1254    echo "IGCM_sys_GetBuffer :" $@
1255  fi
1256  if [ $DRYRUN -le 2 ]; then
1257    if [ X${1} = X'/l' ] ; then
1258      # test if the first file is present in the old computation :
1259      eval set +A buf_liste \${${2}}
1260    else
1261      eval set +A buf_liste ${1}
1262    fi
1263    eval DEST=\${${#}}
1264
1265    #USUAL WAY
1266    if [ X${1} = X'/l' ] ; then
1267      (( RET=0 ))
1268      for target in ${buf_liste[*]} ; do
1269        local_file=$( basename ${target} )
1270        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1271        (( RET = RET + $? ))
1272      done
1273    else
1274      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1275      RET=$?
1276    fi
1277
1278    if [ ${RET} -gt 0 ] ; then
1279      echo "IGCM_sys_GetBuffer : copy error."
1280      cat out_rsync
1281      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1282    else
1283      \rm out_rsync
1284    fi
1285  else
1286    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1287  fi
1288  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1289}
1290
1291#D-#==================================================
1292#D-function IGCM_sys_GetDate_FichWork
1293#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1294#D-* Examples:
1295#D-
1296function IGCM_sys_GetDate_FichWork {
1297  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1298  if ( $DEBUG_sys ) ; then
1299    echo "IGCM_sys_GetDate_FichWork :" $@
1300  fi
1301    # donne la date filesys d'un fichier sur la machine work
1302  IGCM_debug_PopStack "IGCM_sys_FichWork"
1303}
1304
1305#D-#==================================================
1306#D-function IGCM_sys_GetDate_FichArchive
1307#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1308#D-* Examples:
1309#D-
1310function IGCM_sys_GetDate_FichArchive {
1311  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1312  if ( $DEBUG_sys ) ; then
1313    echo "IGCM_sys_GetDate_FichArchive :" $@
1314  fi
1315  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1316}
1317
1318#D-#==================================================
[343]1319#D-function IGCM_sys_Dods_Rm
[544]1320#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
[343]1321#D-* Examples:
1322#D-
1323function IGCM_sys_Dods_Rm {
[544]1324  if ( $DEBUG_sys ) ; then
1325    echo "IGCM_sys_Dods_Rm :" $@
1326  fi
1327  typeset RET
1328  RET=0
1329  if [ $DRYRUN = 0 ]; then
[591]1330
1331#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1332#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1333#      echo "Nothing has been done."
1334#      return
1335#    fi
1336
1337    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
[544]1338    RET=$?
1339   
[418]1340#       if [ ${RET} -gt 0 ] ; then
1341#           echo "IGCM_sys_Dods_Rm : error."
1342#           cat out_dods_rm
1343#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1344#       else
1345#           rm out_dods_rm
1346#       fi
1347
[544]1348  else
1349    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1350  fi
1351  return $RET
[343]1352}
1353
1354#D-#==================================================
1355#D-function IGCM_sys_Dods_Cp
1356#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1357#D-* Examples:
1358#D-
1359function IGCM_sys_Dods_Cp {
[544]1360  if ( $DEBUG_sys ) ; then
1361    echo "IGCM_sys_Dods_Cp :" $@
1362  fi
1363  typeset RET
1364  RET=0
[591]1365
1366#  if [ $DRYRUN = 0 ]; then
1367#    if [ ! -d ${R_SAVE}/${1} ] ; then
1368#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1369#      echo "Nothing has been done."
1370#      return
1371#    fi
1372
1373    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
[544]1374    RET=$?
1375
[348]1376#       if [ ${RET} -gt 0 ] ; then
1377#           echo "IGCM_sys_Dods_Cp : error."
1378#           cat out_dods_cp
1379#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1380#       else
1381#           rm out_dods_cp
1382#       fi
[418]1383
[544]1384  else
1385    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1386  fi
1387  return $RET
[343]1388}
1389
1390#D-#==================================================
[141]1391#D-function IGCM_sys_Put_Dods
1392#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1393#D-* Examples:
1394#D-
1395function IGCM_sys_Put_Dods {
[544]1396  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1397  if ( $DEBUG_sys ) ; then
1398    echo "IGCM_sys_Put_Dods :" $@
1399  fi
[591]1400  typeset RET
[544]1401  if [ $DRYRUN = 0 ]; then
[591]1402
1403    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1404      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1405      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1406      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
[544]1407      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1408      return
[141]1409    fi
1410
[591]1411    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1412      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1413      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1414      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1415      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1416      return
1417    fi
1418    #
1419    if [ -d ${R_SAVE}/${1} ] ; then
1420      cd ${R_SAVE}
1421    elif [ -d ${R_FIGR}/${1} ] ; then
1422      cd ${R_FIGR}
1423    fi
1424
[544]1425    IGCM_sys_Dods_Rm ${1}
1426    IGCM_sys_Dods_Cp ${1}
1427    RET=0
1428   
1429    if [ ${RET} -gt 0 ] ; then
1430      echo "IGCM_sys_Put_Dods : error."
1431      IGCM_debug_Exit "IGCM_sys_Put_Dods"
[141]1432    fi
[544]1433  else
1434    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1435  fi
1436  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
[141]1437}
1438
[544]1439##############################################################
1440# REBUILD OPERATOR
[141]1441
[544]1442function IGCM_sys_rebuild {
1443  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1444  if ( $DEBUG_sys ) ; then
1445    echo "IGCM_sys_rebuild :" $@
1446  fi
1447  /home/cont003/p86ipsl/CESIUM/bin/rebuild -f -o $@
1448  if [ $? -gt 0 ] ; then
1449    echo "IGCM_sys_rebuild : erreur ${@}."
1450    IGCM_debug_Exit "rebuild"
1451  fi
1452
1453  IGCM_debug_PopStack "IGCM_sys_rebuild"
[141]1454}
1455
[544]1456
1457############################################################
1458# Activate Running Environnment Variables
1459
1460function IGCM_sys_activ_variables {
1461  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1462  if ( $DEBUG_sys ) ; then
1463    echo "IGCM_sys_activ_variables"
1464  fi
1465  IGCM_debug_PopStack "IGCM_sys_activ_variables"
[141]1466}
1467
[544]1468############################################################
1469# Desactivate Running Environnment Variables
[141]1470
[544]1471function IGCM_sys_desactiv_variables {
1472  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1473  if ( $DEBUG_sys ) ; then
1474    echo "IGCM_sys_desactiv_variables"
1475  fi
1476  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1477}
[141]1478
[544]1479############################################################
1480# Build run file
1481
1482function IGCM_sys_build_run_file {
1483  IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1484  if ( $DEBUG_sys ) ; then
1485    echo "IGCM_sys_build_run_file"
1486  fi
1487  IGCM_debug_PopStack "IGCM_sys_build_run_file"
[141]1488}
1489
1490##############################################################
1491# NCO OPERATOR
1492
[377]1493function IGCM_sys_ncap2 {
[544]1494  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1495  if ( $DEBUG_sys ) ; then
1496    echo "IGCM_sys_ncap2 :" $@
1497  fi
1498  ncap2 "$@"
1499  if [ $? -gt 0 ] ; then
1500    echo "IGCM_sys_ncap2 : erreur ${@}."
1501    IGCM_debug_Exit "ncap2"
1502  fi
[141]1503
[544]1504  IGCM_debug_PopStack "IGCM_sys_ncap2"
[141]1505}
1506
[375]1507function IGCM_sys_ncatted {
[544]1508  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1509  if ( $DEBUG_sys ) ; then
1510    echo "IGCM_sys_ncatted :" $@
1511  fi
1512  ncatted "$@"
1513  if [ $? -gt 0 ] ; then
1514    echo "IGCM_sys_ncatted : erreur ${@}."
1515    IGCM_debug_Exit "ncatted"
1516  fi
[141]1517
[544]1518  IGCM_debug_PopStack "IGCM_sys_ncatted"
[375]1519}
[141]1520
1521function IGCM_sys_ncbo {
[544]1522  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1523  if ( $DEBUG_sys ) ; then
1524    echo "IGCM_sys_ncbo :" $@
1525  fi
1526  ncbo $@
1527  if [ $? -gt 0 ] ; then
1528    echo "IGCM_sys_ncbo : erreur ${@}."
1529    IGCM_debug_Exit "ncbo"
1530  fi
[141]1531
[544]1532  IGCM_debug_PopStack "IGCM_sys_ncbo"
[141]1533}
1534
1535function IGCM_sys_ncdiff {
[544]1536  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1537  if ( $DEBUG_sys ) ; then
1538    echo "IGCM_sys_ncdiff :" $@
1539  fi
1540  ncdiff $@
1541  if [ $? -gt 0 ] ; then
1542    echo "IGCM_sys_ncdiff : erreur ${@}."
1543    IGCM_debug_Exit "ncdiff"
1544  fi
[141]1545
[544]1546  IGCM_debug_PopStack "IGCM_sys_ncdiff"
[141]1547}
1548
1549function IGCM_sys_ncea {
[544]1550  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1551  if ( $DEBUG_sys ) ; then
1552    echo "IGCM_sys_ncea :" $@
1553  fi
1554  ncea $@
1555  if [ $? -gt 0 ] ; then
1556    echo "IGCM_sys_ncea : erreur ${@}."
1557    IGCM_debug_Exit "ncea"
1558  fi
[141]1559
[544]1560  IGCM_debug_PopStack "IGCM_sys_ncea"
[141]1561}
1562
1563function IGCM_sys_ncecat {
[544]1564  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1565  if ( $DEBUG_sys ) ; then
1566    echo "IGCM_sys_ncecat :" $@
1567  fi
1568  ncecat $@
1569  if [ $? -gt 0 ] ; then
1570    echo "IGCM_sys_ncecat : erreur ${@}."
1571    IGCM_debug_Exit "ncecat"
1572  fi
[141]1573
[544]1574  IGCM_debug_PopStack "IGCM_sys_ncecat"
[141]1575}
1576
1577function IGCM_sys_ncflint {
[544]1578  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1579  if ( $DEBUG_sys ) ; then
1580    echo "IGCM_sys_ncflint :" $@
1581  fi
1582  ncflint $@
1583  if [ $? -gt 0 ] ; then
1584    echo "IGCM_sys_ncflint : erreur ${@}."
1585    IGCM_debug_Exit "ncflint"
1586  fi
[141]1587
[544]1588  IGCM_debug_PopStack "IGCM_sys_ncflint"
[141]1589}
1590
1591function IGCM_sys_ncks {
[544]1592  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1593  if ( $DEBUG_sys ) ; then
1594    echo "IGCM_sys_ncks :" $@
1595  fi
1596  ncks $@
1597  if [ $? -gt 0 ] ; then
1598    echo "IGCM_sys_ncks : erreur ${@}."
1599    IGCM_debug_Exit "ncks"
1600  fi
[141]1601
[544]1602  IGCM_debug_PopStack "IGCM_sys_ncks"
[141]1603}
1604
1605function IGCM_sys_ncpdq {
[544]1606  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1607  if ( $DEBUG_sys ) ; then
1608    echo "IGCM_sys_ncpdq :" $@
1609  fi
1610  ncpdq $@
1611  if [ $? -gt 0 ] ; then
1612    echo "IGCM_sys_ncpdq : erreur ${@}."
1613    IGCM_debug_Exit "ncpdq"
1614  fi
[141]1615
[544]1616  IGCM_debug_PopStack "IGCM_sys_ncpdq"
[141]1617}
1618
1619function IGCM_sys_ncra {
[544]1620  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1621  if ( $DEBUG_sys ) ; then
1622    echo "IGCM_sys_ncra :" $@
1623  fi
1624  ncra $@
1625  if [ $? -gt 0 ] ; then
1626    echo "IGCM_sys_ncra : erreur ${@}."
1627    IGCM_debug_Exit "ncra"
1628  fi
[141]1629
[544]1630  IGCM_debug_PopStack "IGCM_sys_ncra"
[141]1631}
1632
1633function IGCM_sys_ncrcat {
[544]1634  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1635  if ( $DEBUG_sys ) ; then
1636    echo "IGCM_sys_ncrcat :" $@
1637  fi
1638  ncrcat $@
1639  if [ $? -gt 0 ] ; then
1640    echo "IGCM_sys_ncrcat : erreur ${@}."
[141]1641#       IGCM_debug_Exit "ncrcat"
[544]1642  fi
[141]1643
[544]1644  IGCM_debug_PopStack "IGCM_sys_ncrcat"
[141]1645}
1646
1647function IGCM_sys_ncrename {
[544]1648  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1649  if ( $DEBUG_sys ) ; then
1650    echo "IGCM_sys_ncrename :" $@
1651  fi
1652  ncrename $@
1653  if [ $? -gt 0 ] ; then
1654    echo "IGCM_sys_ncrename : erreur ${@}."
1655    IGCM_debug_Exit "ncrename"
1656  fi
[141]1657
[544]1658  IGCM_debug_PopStack "IGCM_sys_ncrename"
[141]1659}
1660
1661function IGCM_sys_ncwa {
[544]1662  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1663  if ( $DEBUG_sys ) ; then
1664    echo "IGCM_sys_ncwa :" $@
1665  fi
1666  ncwa $@
1667  if [ $? -gt 0 ] ; then
1668    echo "IGCM_sys_ncwa : erreur ${@}."
1669    IGCM_debug_Exit "ncwa"
1670  fi
[141]1671
[544]1672  IGCM_debug_PopStack "IGCM_sys_ncwa"
[141]1673}
1674
[305]1675##############################################################
1676# CDO OPERATOR
1677
1678function IGCM_sys_cdo {
[544]1679  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
1680  if ( $DEBUG_sys ) ; then
1681    echo "IGCM_sys_cdo :" $@
1682  fi
1683  \cdo $@
1684  if [ $? -gt 0 ] ; then
1685    echo "IGCM_sys_cdo : erreur ${@}."
[305]1686    IGCM_debug_PopStack "IGCM_sys_cdo"
[544]1687    return 1
1688  else
1689    IGCM_debug_PopStack "IGCM_sys_cdo"
1690    return 0
1691  fi
[305]1692
[544]1693  IGCM_debug_PopStack "IGCM_sys_cdo"
[141]1694}
Note: See TracBrowser for help on using the repository browser.