source: branches/libIGCM_MPI_OpenMP/libIGCM_sys/libIGCM_sys_cesium.ksh @ 571

Last change on this file since 571 was 571, checked in by mafoipsl, 12 years ago

First try to merge libIGCM_MPI_OpenMP branch with libIGCM trunk revision 569. Tested on vargas with PackFrequency?=NONE included into config.card.

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