source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_titane.ksh @ 742

Last change on this file since 742 was 742, checked in by sdipsl, 12 years ago
  • ensemble handling : remove machine specific
  • Property svn:keywords set to Revision Author Date
File size: 84.2 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.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 Titane
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# $hostname of the MASTER job
70typeset MASTER=titane
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# Submit command
78typeset SUBMIT=${SUBMIT:=ccc_mprun}
79# rsync with path
80typeset -r RSYNC=/usr/bin/rsync
81# RSYNC_opt args to rsync
82typeset -r RSYNC_opt="-va"
83# ie storage filesystem
84typeset -r STOREHOST=${MASTER}
85
86#====================================================
87# Source default environment
88#====================================================
89. /etc/profile
90
91#====================================================
92# Set environment tools (ferret, nco, cdo)
93#====================================================
94. /home/cont003/p86ipsl/.atlas_env_titane_ksh
95if ( [ X${LSB_QUEUE} = Xmono ] || [ X${LSB_QUEUE} = Xmonoext ] ) ; then
96  module switch nco/3.9.4 nco/3.9.4_netcdf4
97fi
98
99#====================================================
100# Specific for ocean additionnal diagnostic
101export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
102export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
103
104#====================================================
105# Host specific DIRECTORIES
106#====================================================
107
108# ============ CESIUM START ============ #
109
110#====================================================
111#- Mirror libIGCM from titane to cesium if needed
112#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
113#if [ ! ${ROOTSYS} = "home" ] ; then
114#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
115#else
116#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
117#fi
118
119#====================================================
120#- libIGCM_POST
121#if ( ${MirrorlibIGCM} ) ; then
122#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
123#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
124#else
125#  typeset -r libIGCM_POST=${libIGCM}
126#fi
127
128# ============ CESIUM  END  ============ #
129
130#====================================================
131#- MirrorlibIGCM for frontend
132typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
133
134#====================================================
135#- libIGCM_POST for frontend
136typeset -r libIGCM_POST=${libIGCM}
137
138#====================================================
139#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
140typeset -r R_EXE="${MODIPSL}/bin"
141
142#====================================================
143#- SUBMIT_DIR : submission dir
144typeset SUBMIT_DIR=${SUBMIT_DIR:=${LS_SUBCWD}}
145
146#====================================================
147#- IN
148typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
149typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/ccc/work/cont003/dsm/p24data}
150
151#====================================================
152#- ARCHIVE (dedicated to large files)
153typeset ARCHIVE=${CCCSTOREDIR}
154
155#====================================================
156#- STORAGE (dedicated to small/medium files)
157typeset STORAGE=${CCCWORKDIR}
158
159#====================================================
160#- R_OUT
161typeset R_OUT=${ARCHIVE}/IGCM_OUT
162
163#====================================================
164#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
165typeset R_FIG=${STORAGE}/IGCM_OUT
166
167#====================================================
168#- R_BUF (ONLY FOR double copy an scratch)
169typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
170
171#====================================================
172#- BIG_DIR : BIG_DIR to store files waiting for rebuild
173typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
174
175#====================================================
176#- OUT_POST
177typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
178
179#====================================================
180#- RUN_DIR_PATH : Temporary working directory (=> TMP)
181if ( [ ! X${LSB_QUEUE} = Xmono ] && [ ! X${LSB_QUEUE} = Xmonoext ] ) ; then
182  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${LSB_JOBID}}
183else
184  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/TMPDIR_IGCM/${LSB_JOBID}}
185fi
186
187#====================================================
188#- HOST_MPIRUN_COMMAND
189typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
190
191#====================================================
192#- Max number of arguments passed to nco operator or demigration command
193UNIX_MAX_LIMIT=360
194
195#====================================================
196#- set PackDefault true on titane
197PackDefault=true
198
199#====================================================
200#- Number of core per node (max number of OpenMP task)
201NUM_COREPERNODE=8
202
203#====================================================
204#- Default number of MPI task for IPSL coupled model
205#- required for backward compatibility
206#-
207DEFAULT_NUM_PROC_OCE=5
208DEFAULT_NUM_PROC_CPL=1
209(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
210DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
211
212#D-#==================================================
213#D-function IGCM_sys_ChangeArchive
214#D-* Purpose: if SpaceName=TEST everything is stored on SCRATCHDIR
215#D-* Examples:
216#D-
217function IGCM_sys_ChangeArchive {
218  IGCM_debug_PushStack "IGCM_sys_ChangeArchive"
219
220  ARCHIVE=${SCRATCHDIR}
221  STORAGE=${SCRATCHDIR}
222  R_OUT=${ARCHIVE}/IGCM_OUT
223  R_FIG=${STORAGE}/IGCM_OUT
224
225  IGCM_debug_Print 1 "ARCHIVE has been redefined = ${ARCHIVE}"
226  IGCM_debug_Print 1 "STORAGE has been redefined = ${STORAGE}"
227  IGCM_debug_Print 1 "R_OUT   has been redefined = ${R_OUT}"
228  IGCM_debug_Print 1 "R_FIG   has been redefined = ${R_FIG}"
229
230  IGCM_debug_PopStack "IGCM_sys_ChangeArchive"
231}
232
233#D-#==================================================
234#D-function IGCM_sys_RshMaster
235#D-* Purpose: Connection to frontend machine.
236#D-* Examples:
237#D-
238function IGCM_sys_RshMaster {
239  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
240  /bin/ksh <<-EOF
241    export libIGCM=${libIGCM}
242    export DEBUG_debug=${DEBUG_debug}
243    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
244    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
245    ${@}
246EOF
247  if [ $? -gt 0 ] ; then
248    echo "IGCM_sys_RshMaster : erreur."
249    IGCM_debug_Exit "IGCM_sys_RshMaster"
250  fi
251  IGCM_debug_PopStack "IGCM_sys_RshMaster"
252}
253
254#D-#==================================================
255#D-function IGCM_sys_RshArchive
256#D-* Purpose: Archive rsh command
257#D-* Examples:
258#D-
259function IGCM_sys_RshArchive {
260  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
261  /bin/ksh <<-EOF
262    ${@}
263EOF
264  if [ $? -gt 0 ] ; then
265    echo "IGCM_sys_RshArchive : erreur."
266    IGCM_debug_Exit "IGCM_sys_RshArchive"
267  fi
268  IGCM_debug_PopStack "IGCM_sys_RshArchive"
269}
270
271#D-#==================================================
272#D-function IGCM_sys_RshPost
273#D-* Purpose: Post-process rsh command
274#D-* Examples:
275#D-
276function IGCM_sys_RshPost {
277  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
278  if ( $DEBUG_sys ) ; then
279    echo "IGCM_sys_RshPost :" $@
280  fi
281
282  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
283  #cat tmp_IGCM_sys_RshPost_$$
284  # keep standard input (stdin) for the loop onto temporary file
285  cat >tmp_IGCM_sys_RshPost_$$
286
287# ============ FRONTEND START ============ #
288
289  /bin/ksh <tmp_IGCM_sys_RshPost_$$
290  if [ $? -gt 0 ] ; then
291    echo "IGCM_sys_RshPost : erreur."
292    IGCM_debug_Exit "IGCM_sys_RshPost"
293  fi
294  # delete temporary file
295  \rm tmp_IGCM_sys_RshPost_$$
296
297# ============ FRONTEND  END  ============ #
298
299# ============ CESIUM START ============ #
300#  typeset NB_ESSAI DELAI status i
301#  if [ "X$( grep rebuild_from tmp_IGCM_sys_RshPost_$$ )" != "X" ] ; then
302#    #little hack so that rebuild submission is done on titane not an cesium
303#
304#    libIGCM_POST_sed=$( echo $libIGCM_POST | sed 's/\//\\\//g' )
305#    POST_DIR_sed=$( echo ${POST_DIR} | sed 's/\//\\\//g' )
306#    sed "s/IGCM_sys_QsubPost/IGCM_sys_Qsub/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
307#    sed "s/ rebuild_fromWorkdir/ ${libIGCM_POST_sed}\/rebuild_fromWorkdir.job/g" tmp.txt > tmp_IGCM_sys_RshPost_$$
308#    sed "s/ rebuild_fromArchive/ ${libIGCM_POST_sed}\/rebuild_fromArchive.job/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
309#    sed "s/Script_Post_Output=/Script_Output=${POST_DIR_sed}\//g" tmp.txt > tmp_IGCM_sys_RshPost_$$
310#    \mv tmp.txt tmp_IGCM_sys_RshPost_$$
311#
312#    echo cat tmp_IGCM_sys_RshPost_$$ AFTER
313#    cat tmp_IGCM_sys_RshPost_$$
314#
315#    /bin/ksh <tmp_IGCM_sys_RshPost_$$
316#    if [ $? -gt 0 ] ; then
317#      echo "IGCM_sys_RshPost : erreur."
318#      IGCM_debug_Exit "IGCM_sys_RshPost"
319#    fi
320#    # delete temporary file
321#    \rm tmp_IGCM_sys_RshPost_$$
322#
323#  else
324#    # number of tentative
325#    NB_ESSAI=10
326#    # time delay between tentative
327#    DELAI=10
328#    i=0
329#    while [ $i -ne $NB_ESSAI ] ; do
330#      ssh -t titane996 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
331#      status=$?
332#      if [ ${status} -ne 0 ];
333#      then
334#       sleep $DELAI
335#      else
336#       break
337#      fi
338#      let i=$i+1
339#    done
340#    # delete temporary file
341#    \rm tmp_IGCM_sys_RshPost_$$
342#
343#    if [ ${status} -gt 0 ] ; then
344#      echo "IGCM_sys_RshPost : erreur."
345#      IGCM_debug_Exit "IGCM_sys_RshPost"
346#    fi
347#  fi
348
349# ============ CESIUM  END  ============ #
350
351  IGCM_debug_PopStack "IGCM_sys_RshPost"
352}
353
354#D-#==================================================
355#D-function IGCM_sys_SendMail
356#D-* Purpose: Send mail when simulation is over
357#D-* Examples:
358#D-
359function IGCM_sys_SendMail {
360  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
361  if ( $DEBUG_sys ) ; then
362    echo "IGCM_sys_SendMail :" $@
363  fi
364
365  if ( ${ExitFlag} ) ; then
366    status=failed
367  else
368    status=completed
369  fi
370
371  cat  << END_MAIL > job_end.mail
372Dear ${LOGIN},
373
374  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
375  Job started : ${DateBegin}
376  Job ended   : ${DateEnd}
377  Output files are available in ${R_SAVE}
378  Files to be rebuild are temporarily available in ${REBUILD_DIR}
379  Pre-packed files are temporarily available in ${R_BUFR}
380  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
381END_MAIL
382
383    if [ ! -z ${config_UserChoices_MailName} ] ; then
384        mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < job_end.mail
385    elif [ -f ~/.forward ] ; then
386        mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
387    fi
388    sleep 10
389    rm -f job_end.mail
390
391  if [ $? -gt 0 ] ; then
392    echo "IGCM_sys_SendMail : erreur."
393    IGCM_debug_Exit "IGCM_sys_SendMail"
394  fi
395  IGCM_debug_PopStack "IGCM_sys_SendMail"
396}
397
398#D-#==================================================
399#D-function IGCM_sys_Mkdir
400#D-* Purpose: Master locale mkdir command
401#D-* Examples:
402#D-
403function IGCM_sys_Mkdir {
404  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
405  if ( $DEBUG_sys ) ; then
406    echo "IGCM_sys_Mkdir :" $@
407  fi
408  if [ ! -d ${1} ]; then
409    \mkdir -p $1
410    if [ $? -gt 0 ] ; then
411      echo "IGCM_sys_Mkdir : erreur."
412      IGCM_debug_Exit "IGCM_sys_Mkdir"
413    fi
414  fi
415  # vérification :
416  if [ ! -d ${1} ] ; then
417    echo "IGCM_sys_Mkdir : erreur."
418    IGCM_debug_Exit "IGCM_sys_Mkdir"
419  fi
420  IGCM_debug_PopStack "IGCM_sys_Mkdir"
421}
422
423#D-#==================================================
424#D-function IGCM_sys_MkdirArchive
425#D-* Purpose: Mkdir on Archive
426#D-* Examples:
427#D-
428function IGCM_sys_MkdirArchive {
429  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
430  if ( $DEBUG_sys ) ; then
431    echo "IGCM_sys_MkdirArchive :" $@
432  fi
433  #- creation de repertoire sur le serveur fichier
434  if [ ! -d ${1} ]; then
435    \mkdir -p $1
436    if [ $? -gt 0 ] ; then
437      echo "IGCM_sys_MkdirArchive : erreur."
438      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
439    fi
440  fi
441  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
442}
443
444#D-#==================================================
445#D-function IGCM_sys_MkdirWork
446#D-* Purpose: Mkdir on Work
447#D-* Examples:
448#D-
449function IGCM_sys_MkdirWork {
450  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
451  if ( $DEBUG_sys ) ; then
452    echo "IGCM_sys_MkdirWork :" $@
453  fi
454  #- creation de repertoire sur le serveur fichier
455  if [ ! -d ${1} ]; then
456    \mkdir -p $1
457    if [ $? -gt 0 ] ; then
458      echo "IGCM_sys_MkdirWork : erreur."
459      IGCM_debug_Exit "IGCM_sys_MkdirWork"
460    fi
461  fi
462  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
463}
464
465#D-#==================================================
466#D-function IGCM_sys_Cd
467#D-* Purpose: master cd command
468#D-* Examples:
469#D-
470function IGCM_sys_Cd {
471  IGCM_debug_PushStack "IGCM_sys_Cd" $@
472  if ( $DEBUG_sys ) ; then
473    echo "IGCM_sys_Cd :" $@
474  fi
475  \cd $1
476  if [ $? -gt 0 ] ; then
477    echo "IGCM_sys_Cd : erreur."
478    IGCM_debug_Exit "IGCM_sys_Cd"
479  fi
480  IGCM_debug_PopStack "IGCM_sys_Cd"
481}
482
483#D-#==================================================
484#D-function IGCM_sys_Chmod
485#D-* Purpose: Chmod
486#D-* Examples:
487#D-
488function IGCM_sys_Chmod {
489  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
490  if ( $DEBUG_sys ) ; then
491    echo "IGCM_sys_Chmod :" $@
492  fi
493  if [ $DRYRUN -le 1 ]; then
494    \chmod $@
495    if [ $? -gt 0 ] ; then
496      echo "IGCM_sys_Chmod : erreur."
497      IGCM_debug_Exit "IGCM_sys_Chmod"
498    fi
499  else
500    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
501  fi
502  IGCM_debug_PopStack "IGCM_sys_Chmod"
503}
504
505#D-#==================================================
506#D-function IGCM_sys_FileSize
507#D-* Purpose: Filesize
508#D-* Examples:
509#D-
510function IGCM_sys_FileSize {
511  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
512
513  typeset sizeF
514  set +A sizeF -- $( ls -la ${1} )
515  if [ $? -gt 0 ] ; then
516    IGCM_debug_Exit "IGCM_sys_FileSize"
517  fi
518  eval ${2}=${sizeF[4]}
519
520  IGCM_debug_PopStack "IGCM_sys_FileSize"
521}
522
523#D-#==================================================
524#D-function IGCM_sys_TestDir
525#D-* Purpose: Test Directory that must exists
526#D-* Examples:
527#D-
528function IGCM_sys_TestDir {
529  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
530  if ( $DEBUG_sys ) ; then
531    echo "IGCM_sys_TestDir :" $@
532  fi
533  typeset ExistFlag
534  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
535  IGCM_debug_PopStack "IGCM_sys_TestDir"
536
537  return ${ExistFlag}
538}
539
540#D-#==================================================
541#D-function IGCM_sys_TestDirArchive
542#D-* Purpose: Test Directory that must exists on Archive
543#D-* Examples:
544#D-
545function IGCM_sys_TestDirArchive {
546  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
547  if ( $DEBUG_sys ) ; then
548    echo "IGCM_sys_TestDirArchive :" $@
549  fi
550  typeset ExistFlag
551  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
552  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
553
554  return ${ExistFlag}
555}
556
557#D-#==================================================
558#D-function IGCM_sys_IsFileArchived
559#D-* Purpose: Test file that must NOT EXISTS on Archive
560#D-* Examples:
561#D-
562function IGCM_sys_IsFileArchived {
563  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
564  if ( $DEBUG_sys ) ; then
565    echo "IGCM_sys_IsFileArchived :" $@
566  fi
567  typeset IsArchivedFlag
568  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
569  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
570
571  return ${IsArchivedFlag}
572}
573
574#D-#==================================================
575#D-function IGCM_sys_TestFileArchive
576#D-* Purpose: Test file that must NOT EXISTS on Archive
577#D-* Examples:
578#D-
579function IGCM_sys_TestFileArchive {
580  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
581  typeset ExistFlag
582  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
583  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
584
585  return ${ExistFlag}
586}
587
588#D-#==================================================
589#D-function IGCM_sys_TestFileBuffer
590#D-* Purpose: Test file that must NOT EXISTS on Buffer
591#D-* Examples:
592#D-
593function IGCM_sys_TestFileBuffer {
594  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
595  typeset ExistFlag
596  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
597  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
598
599  return ${ExistFlag}
600}
601
602#D-#==================================================
603#D-function IGCM_sys_CountFileArchive
604#D-* Purpose: Count files on Archive filesystem
605#D-* Examples:
606#D-
607function IGCM_sys_CountFileArchive {
608  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
609  ls ${@} 2>/dev/null | wc -l
610  if [ $? -gt 0 ] ; then
611    echo "IGCM_sys_CountFileArchive : erreur."
612  fi
613  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
614}
615
616#D-#==================================================
617#D-function IGCM_sys_CountFileBuffer
618#D-* Purpose: Count files on Scratch filesystem
619#D-* Examples:
620#D-
621function IGCM_sys_CountFileBuffer {
622  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
623  ls ${@} 2>/dev/null | wc -l
624  if [ $? -gt 0 ] ; then
625    echo "IGCM_sys_CountFileBuffer : erreur."
626  fi
627  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
628}
629
630#D-#==================================================
631#D-function IGCM_sys_Tree
632#D-* Purpose: Tree directories with files on ${ARCHIVE}
633#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
634#D-
635function IGCM_sys_Tree {
636  IGCM_debug_PushStack "IGCM_sys_Tree" $@
637  if ( $DEBUG_sys ) ; then
638    echo "IGCM_sys_Tree :" $@
639  fi
640
641  \ls -lR ${@}
642
643  IGCM_debug_PopStack "IGCM_sys_Tree"
644}
645
646#D-#==================================================
647#D-function IGCM_sys_Tar
648#D-* Purpose: master tar command
649#D-* Examples:
650#D-
651function IGCM_sys_Tar {
652  IGCM_debug_PushStack "IGCM_sys_Tar" $@
653  if ( $DEBUG_sys ) ; then
654    echo "IGCM_sys_Tar :" $@
655  fi
656  \tar cf $@
657  if [ $? -gt 0 ] ; then
658    echo "IGCM_sys_Tar : erreur."
659    IGCM_debug_Exit "IGCM_sys_Tar"
660  fi
661  IGCM_debug_PopStack "IGCM_sys_Tar"
662}
663
664#D-#==================================================
665#D-function IGCM_sys_UnTar
666#D-* Purpose: master un-tar command
667#D-* Examples:
668#D-
669function IGCM_sys_UnTar {
670  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
671  if ( $DEBUG_sys ) ; then
672    echo "IGCM_sys_UnTar :" $@
673  fi
674  \tar xvf $1
675  if [ $? -gt 0 ] ; then
676    echo "IGCM_sys_UnTar : erreur."
677    IGCM_debug_Exit "IGCM_sys_UnTar"
678  fi
679  IGCM_debug_PopStack "IGCM_sys_UnTar"
680}
681
682#D-#==================================================
683#D-function IGCM_sys_Qsub
684#D-* Purpose: Qsub new job
685#D-* Examples:
686#D-
687function IGCM_sys_Qsub {
688  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
689  if ( $DEBUG_sys ) ; then
690    echo "IGCM_sys_Qsub :" $@
691  fi
692  typeset options
693  if [ ${config_UserChoices_JobName}.${CumulPeriod} = "." ] ; then
694    options=" -o ${Script_Output} -e ${Script_Output}"
695  else
696    options=" -o ${Script_Output} -e ${Script_Output} -r ${config_UserChoices_JobName}.${CumulPeriod}"
697  fi
698
699  /usr/local/bin/ccc_msub ${options} < $1
700  if [ $? -gt 0 ] ; then
701    echo "IGCM_sys_Qsub : erreur ${options} $1"
702    IGCM_debug_Exit "IGCM_sys_Qsub"
703  fi
704  IGCM_debug_PopStack "IGCM_sys_Qsub"
705}
706
707#D-#==================================================
708#D-function IGCM_sys_QsubPost
709#D-* Purpose: Qsub new job on scalaire
710#D-* Examples:
711#D-
712function IGCM_sys_QsubPost {
713  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
714  if ( $DEBUG_sys ) ; then
715    echo "IGCM_sys_QsubPost :" $@
716  fi
717
718  # Need to export listVarEnv for cesium
719  # NO Need to export listVarEnv for titane
720# ============ FRONTEND START ============ #
721
722  /usr/local/bin/ccc_msub -p ${BRIDGE_MSUB_PROJECT} -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out ${libIGCM_POST}/$1.job
723
724# ============ FRONTEND  END  ============ #
725
726# ============ CESIUM START ============ #
727#  typeset NB_ESSAI DELAI status i
728#  # number of tentative
729#  NB_ESSAI=10
730#  # time delay between tentative
731#  DELAI=10
732#  (( i = 0 ))
733#  while [ $i -lt $NB_ESSAI ] ; do
734#    /usr/local/bin/ccc_msub -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.e.out -E "-v ${listVarEnv}" ${libIGCM_POST}/$1.job
735#    status=$?
736#    if [ ${status} -gt 0 ]; then
737#      sleep $DELAI
738#    else
739#      break
740#    fi
741#    (( i = i + 1 ))
742#  done
743# ============ CESIUM  END  ============ #
744
745  if [ $? -gt 0 ] ; then
746    echo "IGCM_sys_QsubPost : erreur " $@
747    IGCM_debug_Exit "IGCM_sys_QsubPost"
748  fi
749  IGCM_debug_PopStack "IGCM_sys_QsubPost"
750}
751
752#D-*************************
753#D- File transfer functions
754#D-*************************
755#D-
756
757#D-#==================================================
758#D-function IGCM_sys_Rsync_out
759#D-* Purpose: treat return val of rsync
760#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
761#D-  Error values and explanations can depend on your system version.
762function IGCM_sys_Rsync_out {
763  status=$1
764  if [ ! $status ] ; then
765    echo "rsync error !"
766  fi
767
768  if [ $MYLANG = "fr" ]; then
769    case $status in
770    0)  return ;;
771    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
772      echo "Erreur de syntaxe ou d'utilisation."
773      return;;
774    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
775      echo "Incompatibilité de protocole."
776      return;;
777    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
778      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
779      echo "répertoires"
780      return;;
781    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
782      echo "Action demandée non supportée : une tentative de manipulation de"
783      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
784      echo "été faite ; ou une option qui est supportée par le  client  mais"
785      echo "pas par le serveur a été spécifiée."
786      return;;
787    10) echo "Erreur de rsync ; RERR_SOCKETIO"
788      echo "Erreur dans le socket d'entrée sortie"
789      return;;
790    11) echo "Erreur de rsync ; RERR_FILEIO"
791      echo "Erreur d'entrée sortie fichier"
792      return;;
793    12) echo "Erreur de rsync ; RERR_STREAMIO"
794      echo "Erreur dans flux de donnée du protocole rsync"
795      return;;
796    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
797      echo "Erreur avec les diagnostics du programme"
798      return;;
799    14) echo "Erreur de rsync ; RERR_IPC"
800      echo "Erreur dans le code IPC"
801      return;;
802    20) echo "Erreur de rsync ; RERR_SIGNAL"
803      echo "SIGUSR1 ou SIGINT reçu"
804      return;;
805    21) echo "Erreur de rsync ; RERR_WAITCHILD"
806      echo "Une erreur retournée par waitpid()"
807      return;;
808    22) echo "Erreur de rsync ; RERR_MALLOC"
809      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
810      return;;
811    23) echo ""
812      echo "Erreur fichier inexistant"
813      return;;
814    30) echo "Erreur de rsync ; RERR_TIMEOUT"
815      echo "Temps d'attente écoulé dans l'envoi/réception de données"
816      return;;
817    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
818      return;;
819    esac
820  elif [ $MYLANG = "en" ] ; then
821    case $status in
822    0)  return;;
823    1)  echo "rsync error : Syntax or usage error "
824      return;;
825    2)  echo "rsync error : Protocol incompatibility "
826      return;;
827    3)  echo "rsync error : Errors selecting input/output files, dirs"
828      return;;
829    4)  echo "rsync error : Requested action not supported: an attempt"
830      echo "was made to manipulate 64-bit files on a platform that cannot support"
831      echo "them; or an option was specified that is supported by the client and"
832      echo "not by the server."
833      return;;
834    5)  echo "rsync error : Error starting client-server protocol"
835      return;;
836    10) echo "rsync error : Error in socket I/O "
837      return;;
838    11) echo "rsync error : Error in file I/O "
839      return;;
840    12) echo "rsync error : Error in rsync protocol data stream "
841      return;;
842    13) echo "rsync error : Errors with program diagnostics "
843      return;;
844    14) echo "rsync error : Error in IPC code "
845      return;;
846    20) echo "rsync error : Received SIGUSR1 or SIGINT "
847      return;;
848    21) echo "rsync error : Some error returned by waitpid() "
849      return;;
850    22) echo "rsync error : Error allocating core memory buffers "
851      return;;
852    23) echo "rsync error : Partial transfer due to error"
853      return;;
854    24) echo "rsync error : Partial transfer due to vanished source files"
855      return;;
856    30) echo "rsync error : Timeout in data send/receive "
857      return;;
858    *)  echo "rsync error : return code of rsync unknown :" $status
859      return;;
860    esac
861  else
862    echo "unknown language $MYLANG."
863    return
864  fi
865}
866
867#D-#==================================================
868#D-function IGCM_sys_Miror_libIGCM
869#D-* Purpose: Mirror libIGCM PATH and lib to cesium
870#D-* Examples:
871#D-
872function IGCM_sys_Mirror_libIGCM {
873  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
874  if ( $DEBUG_sys ) ; then
875    echo "IGCM_sys_Mirror_libIGCM"
876  fi
877
878  typeset status DEST
879
880  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
881
882  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
883  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
884  status=$?
885
886  if [ ${status} -gt 0 ] ; then
887    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on cesium."
888    cat out_rsync
889  fi
890  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
891}
892
893#D-#==================================================
894#D-function IGCM_sys_Cp
895#D-* Purpose: generic cp
896#D-* Examples:
897#D-
898function IGCM_sys_Cp {
899  IGCM_debug_PushStack "IGCM_sys_Cp" $@
900  if ( $DEBUG_sys ) ; then
901    echo "IGCM_sys_Cp :" $@
902  fi
903
904  typeset status
905
906  echo cp $@ > out_rsync 2>&1
907  \cp $@ >> out_rsync 2>&1
908  status=$?
909
910  if [ ${status} -gt 0 ] ; then
911    echo "IGCM_sys_Cp : error code ${status}"
912    cat out_rsync
913    IGCM_debug_Exit "IGCM_sys_Cp"
914  else
915    \rm out_rsync
916  fi
917  IGCM_debug_PopStack "IGCM_sys_Cp"
918}
919
920#D-#==================================================
921#D-function IGCM_sys_Rm
922#D-* Purpose: generic rm
923#D-* Examples:
924#D-
925function IGCM_sys_Rm {
926  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
927  if ( $DEBUG_sys ) ; then
928    echo "IGCM_sys_Rm :" $@
929  fi
930
931  typeset status
932
933  echo rm $@ > out_rsync 2>&1
934  \rm $@ >> out_rsync 2>&1
935  status=$?
936
937  if [ ${status} -gt 0 ] ; then
938    echo "IGCM_sys_Rm : error code ${status}"
939    cat out_rsync
940    IGCM_debug_Exit "IGCM_sys_Rm"
941  else
942    \rm out_rsync
943  fi
944  IGCM_debug_PopStack "IGCM_sys_Rm"
945}
946
947#D-#==================================================
948#D-function IGCM_sys_RmRunDir
949#D-* Purpose: rm tmpdir (dummy function most of the time batch
950#D-                      scheduler will do the job)
951#D-* Examples:
952#D-
953function IGCM_sys_RmRunDir {
954  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
955  if ( $DEBUG_sys ) ; then
956    echo "IGCM_sys_RmRunDir :" $@
957  fi
958
959  typeset status
960
961  echo rm $@ > out_rsync 2>&1
962  \rm $@ >> out_rsync 2>&1
963  status=$?
964
965  if [ ${status} -gt 0 ] ; then
966    echo "IGCM_sys_RmRunDir : error code ${status}"
967    cat out_rsync
968    IGCM_debug_Exit "IGCM_sys_RmRunDir"
969  else
970    \rm out_rsync
971  fi
972  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
973}
974
975#D-#==================================================
976#D-function IGCM_sys_Mv
977#D-* Purpose: generic move
978#D-* Examples:
979#D-
980function IGCM_sys_Mv {
981  IGCM_debug_PushStack "IGCM_sys_Mv" $@
982  if ( $DEBUG_sys ) ; then
983    echo "IGCM_sys_Mv :" $@
984  fi
985
986  if [ $DRYRUN = 0 ]; then
987
988    typeset status
989
990    echo mv $@ > out_rsync 2>&1
991    \mv $@ >> out_rsync 2>&1
992    status=$?
993
994    if [ ${status} -gt 0 ] ; then
995      echo "IGCM_sys_Mv : error code ${status}"
996      cat out_rsync
997      IGCM_debug_Exit "IGCM_sys_Mv"
998    else
999      \rm out_rsync
1000    fi
1001  else
1002    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1003  fi
1004
1005  IGCM_debug_PopStack "IGCM_sys_Mv"
1006}
1007
1008#D-#==================================================
1009#D-function IGCM_sys_Put_Dir
1010#D-* Purpose: Copy a complete directory on $(ARCHIVE)
1011#D-* Examples:
1012#D-
1013function IGCM_sys_Put_Dir {
1014  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
1015  if ( $DEBUG_sys ) ; then
1016    echo "IGCM_sys_Put_Dir :" $@
1017  fi
1018  if [ $DRYRUN = 0 ]; then
1019    if [ ! -d ${1} ] ; then
1020      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
1021      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1022      return
1023    fi
1024
1025    typeset status
1026
1027    # Only if we use rsync
1028    #IGCM_sys_TestDirArchive $( dirname $2 )
1029    #
1030    #USUAL WAY
1031    \cp -r $1 $2 > out_rsync 2>&1
1032    status=$?
1033
1034    if [ ${status} -gt 0 ] ; then
1035      echo "IGCM_sys_Put_Dir : error code ${status}"
1036      cat out_rsync
1037      IGCM_debug_Exit "IGCM_sys_Put_Dir"
1038    else
1039      \rm out_rsync
1040    fi
1041  else
1042    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1043  fi
1044  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1045}
1046
1047#D-#==================================================
1048#D-function IGCM_sys_Get_Dir
1049#D-* Purpose: Copy a complete directory from ${ARCHIVE}
1050#D-* Examples:
1051#D-
1052function IGCM_sys_Get_Dir {
1053  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
1054  if ( $DEBUG_sys ) ; then
1055    echo "IGCM_sys_Get_Dir :" $@
1056  fi
1057  if [ $DRYRUN = 0 ]; then
1058#    if [ ! -d ${1} ] ; then
1059#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
1060#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1061#      return
1062#    fi
1063
1064    typeset NB_ESSAI DELAI status i
1065    # number of tentative
1066    NB_ESSAI=3
1067    # time delay between tentative
1068    DELAI=2
1069
1070    # Only if we use rsync
1071    #IGCM_sys_TestDirArchive $( dirname $2 )
1072    #
1073    # USUAL WAY
1074    # add dmfind/dmget (to demigrate all offline files) :
1075    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
1076    ccc_hsm get -r $1
1077
1078    i=0
1079    while [ $i -lt $NB_ESSAI ] ; do
1080      \cp -ur $1 $2 >> out_rsync 2>&1
1081      status=$?
1082      if [ ${status} -gt 0 ]; then
1083        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}"
1084        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
1085        sleep $DELAI
1086      else
1087        break
1088      fi
1089      (( i = i + 1 ))
1090    done
1091
1092    if [ ${status} -gt 0 ] ; then
1093      echo "IGCM_sys_Get_Dir : error."
1094      cat out_rsync
1095      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1096    else
1097      \rm out_rsync
1098    fi
1099  else
1100    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1101  fi
1102  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1103}
1104
1105#D-#==================================================
1106#D-function IGCM_sys_Get_Master
1107#D-* Purpose: Copy a complete directory from MASTER filesystem
1108#D-* Examples:
1109#D-
1110function IGCM_sys_Get_Master {
1111  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1112  if ( $DEBUG_sys ) ; then
1113    echo "IGCM_sys_Get_Master :" $@
1114  fi
1115  if [ $DRYRUN = 0 ]; then
1116    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
1117      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1118      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1119      return
1120    fi
1121
1122    typeset NB_ESSAI DELAI status i
1123    # number of tentative
1124    NB_ESSAI=3
1125    # time delay between tentative
1126    DELAI=2
1127
1128    i=0
1129    while [ $i -lt $NB_ESSAI ] ; do
1130      \cp -urL $1 $2 > out_rsync 2>&1
1131      status=$?
1132      if [ ${status} -gt 0 ]; then
1133        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
1134        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
1135        sleep $DELAI
1136      else
1137        break
1138      fi
1139      (( i = i + 1 ))
1140    done
1141
1142    if [ ${status} -gt 0 ] ; then
1143      echo "IGCM_sys_Get_Master : error."
1144      cat out_rsync
1145      IGCM_debug_Exit "IGCM_sys_Get_Master"
1146    else
1147      \rm out_rsync
1148    fi
1149  else
1150    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1151  fi
1152  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1153}
1154
1155#====================================================
1156#- Call IGCM_sys_Mirror_libIGCM now !
1157if ( $MirrorlibIGCM ) ; then
1158  IGCM_sys_Mirror_libIGCM
1159fi
1160
1161#D-#==================================================
1162#D-function IGCM_sys_Put_Rest
1163#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1164#D-           File and target directory must exist.
1165#D-* Examples:
1166#D-
1167function IGCM_sys_Put_Rest {
1168  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1169  if ( $DEBUG_sys ) ; then
1170    echo "IGCM_sys_Put_Rest :" $@
1171  fi
1172  if [ $DRYRUN = 0 ]; then
1173    if [ ! -f ${1} ] ; then
1174      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1175      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1176    fi
1177
1178    typeset status
1179    #
1180    if [ X${JobType} = XRUN ] ; then
1181      IGCM_sys_Chmod 444 ${1}
1182    fi
1183
1184    #
1185    # USUAL WAY
1186    \cp $1 $2 > out_rsync 2>&1
1187    status=$?
1188
1189#       #RSYNC WITH NETWORK SSH CALL
1190#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1191#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1192
1193#       #RSYNC WITH NFS USE
1194#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1195#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1196
1197#       status=$?
1198#       IGCM_sys_Rsync_out $status
1199
1200#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1201#       (( status=status+$? ))
1202
1203    if [ ${status} -gt 0 ] ; then
1204      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
1205      cat out_rsync
1206      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1207    else
1208      \rm out_rsync
1209    fi
1210  else
1211    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1212  fi
1213  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1214}
1215
1216#D-#==================================================
1217#D-function IGCM_sys_PutBuffer_Rest
1218#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1219#D-           File and target directory must exist.
1220#D-* Examples:
1221#D-
1222function IGCM_sys_PutBuffer_Rest {
1223  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1224  if ( $DEBUG_sys ) ; then
1225    echo "IGCM_sys_PutBuffer_Rest :" $@
1226  fi
1227  if [ $DRYRUN = 0 ]; then
1228    if [ ! -f ${1} ] ; then
1229      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1230      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1231    fi
1232
1233    typeset status
1234    #
1235    if [ X${JobType} = XRUN ] ; then
1236      IGCM_sys_Chmod 444 ${1}
1237    fi
1238
1239    #
1240    # USUAL WAY
1241    \cp $1 $2 > out_rsync 2>&1
1242    status=$?
1243
1244    if [ ${status} -gt 0 ] ; then
1245      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1246      cat out_rsync
1247      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1248    else
1249      \rm out_rsync
1250    fi
1251  else
1252    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1253  fi
1254  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1255}
1256
1257#D-#==================================================
1258#D-function IGCM_sys_Put_Out
1259#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1260#D-* Examples:
1261#D-
1262function IGCM_sys_Put_Out {
1263  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1264  if ( $DEBUG_sys ) ; then
1265    echo "IGCM_sys_Put_Out :" $@
1266  fi
1267
1268  typeset NB_ESSAI DELAI status i exist skip
1269
1270  # number of tentative
1271  NB_ESSAI=3
1272  # time delay between tentative
1273  DELAI=2
1274
1275  if [ $DRYRUN = 0 ]; then
1276    if [ ! -f ${1} ] ; then
1277      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1278      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1279      return 1
1280    fi
1281    #
1282    IGCM_sys_MkdirArchive $( dirname $2 )
1283    #
1284
1285    #=====================================================
1286    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1287    #=====================================================
1288
1289    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1290    #if [ $? -eq 0 ] ; then
1291    #    typeset WORKPATH FILEPATH
1292    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1293    #    IGCM_sys_MkdirWork ${WORKPATH}
1294    #    FILEPATH=${WORKPATH}/$( basename $2 )
1295    #    #
1296    #    IGCM_sys_Cp ${1} ${FILEPATH}
1297    #fi
1298
1299    if [ X${JobType} = XRUN ] ; then
1300      if [ X${3} = X ] ; then
1301        IGCM_sys_Chmod 444 ${1}
1302      fi
1303    fi
1304    #
1305
1306    exist=false
1307    skip=false
1308    if [ -f $2 ] ; then
1309      IGCM_debug_Print 1 "$2 already exist"
1310      #dmget $2
1311      ccc_hsm get $2
1312      exist=true
1313      if [ "X$( diff $1 $2 )" = X ] ; then
1314        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1315        skip=true
1316      else
1317        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1318        skip=false
1319      fi
1320    fi
1321    #
1322    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1323      IGCM_sys_Chmod u+w $2
1324    fi
1325
1326    if [ X${skip} = Xfalse ] ; then
1327      i=0
1328      while [ $i -lt $NB_ESSAI ] ; do
1329        # USUAL WAY
1330        \cp $1 $2 > out_rsync 2>&1
1331        status=$?
1332        if [ ${status} -gt 0 ]; then
1333          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1334          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1335          if [ -f $2 ] ; then
1336            if [ "X$( diff $1 $2 )" = X ] ; then
1337              IGCM_debug_Print 2 "$1 and $2 are the same file"
1338              IGCM_debug_Print 2 "Cp gave an error but the file has been copied properly!"
1339              break
1340            else
1341              IGCM_debug_Print 2 "$1 and $2 are not the same file, we continue to try"
1342              \rm $2
1343            fi
1344          fi
1345          sleep $DELAI
1346        else
1347          break
1348        fi
1349        (( i = i + 1 ))
1350      done
1351    fi
1352
1353#       #RSYNC WITH NETWORK SSH CALL
1354#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1355#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1356
1357#       #RSYNC WITH NFS USE
1358#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1359#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1360
1361#       status=$?
1362#       IGCM_sys_Rsync_out $status
1363
1364#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1365#       (( status=status+$? ))
1366
1367    if [ ${status} -gt 0 ] ; then
1368      echo "IGCM_sys_Put_Out : error."
1369      cat out_rsync
1370      IGCM_debug_Exit "IGCM_sys_Put_Out"
1371    else
1372      \rm out_rsync
1373    fi
1374  else
1375    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1376  fi
1377  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1378  return 0
1379}
1380
1381#D-#==================================================
1382#D-function IGCM_sys_PutBuffer_Out
1383#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1384#D-* Examples:
1385#D-
1386function IGCM_sys_PutBuffer_Out {
1387  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1388  if ( $DEBUG_sys ) ; then
1389    echo "IGCM_sys_PutBuffer_Out :" $@
1390  fi
1391
1392  typeset NB_ESSAI DELAI status i exist skip
1393
1394  # number of tentative
1395  NB_ESSAI=3
1396  # time delay between tentative
1397  DELAI=2
1398
1399  if [ $DRYRUN = 0 ]; then
1400    if [ ! -f ${1} ] ; then
1401      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1402      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1403      return 1
1404    fi
1405    #
1406    IGCM_sys_Mkdir $( dirname $2 )
1407    #
1408
1409    if [ X${JobType} = XRUN ] ; then
1410      if [ X${3} = X ] ; then
1411        IGCM_sys_Chmod 444 ${1}
1412      fi
1413    fi
1414
1415    exist=false
1416    skip=false
1417    if [ -f $2 ] ; then
1418      IGCM_debug_Print 1 "$2 already exist"
1419      exist=true
1420      if [ "X$( diff $1 $2 )" = X ] ; then
1421        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1422        skip=true
1423      else
1424        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1425        skip=false
1426      fi
1427    fi
1428    #
1429    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1430      IGCM_sys_Chmod u+w $2
1431    fi
1432
1433    if [ X${skip} = Xfalse ] ; then
1434      i=0
1435      while [ $i -lt $NB_ESSAI ] ; do
1436        # USUAL WAY
1437        \cp $1 $2 > out_rsync 2>&1
1438        status=$?
1439        if [ ${status} -gt 0 ]; then
1440          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1441          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1442          sleep $DELAI
1443        else
1444          break
1445        fi
1446        (( i = i + 1 ))
1447      done
1448    fi
1449
1450    if [ ${status} -gt 0 ] ; then
1451      echo "IGCM_sys_PutBuffer_Out : error."
1452      cat out_rsync
1453      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1454    else
1455      \rm out_rsync
1456    fi
1457  else
1458    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1459  fi
1460  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1461  return 0
1462}
1463
1464#D-#==================================================
1465#D-function IGCM_sys_Get
1466#D-* Purpose: Get a file from ${ARCHIVE}
1467#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1468#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1469function IGCM_sys_Get {
1470  IGCM_debug_PushStack "IGCM_sys_Get" $@
1471
1472  typeset DEST dm_liste ifile target file_work
1473  typeset NB_ESSAI DELAI status i
1474
1475  if ( $DEBUG_sys ) ; then
1476    echo "IGCM_sys_Get :" $@
1477  fi
1478
1479  # number of tentative
1480  NB_ESSAI=3
1481  # time delay between tentative
1482  DELAI=2
1483
1484  if [ $DRYRUN -le 2 ]; then
1485    if [ X${1} = X'/l' ] ; then
1486      # test if the first file is present in the old computation :
1487      eval set +A dm_liste \${${2}}
1488    else
1489      eval set +A dm_liste ${1}
1490    fi
1491    eval DEST=\${${#}}
1492
1493    #=====================================================
1494    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1495    #=====================================================
1496
1497    # Is it an R_OUT file (not R_IN) ?
1498    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1499    #if [ $? -eq 0 ] ; then
1500    #    # Yes  ? then we try to get it in SCRATCHDIR
1501    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1502    #    if [ -f ${file_work[0]} ] ; then
1503    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1504    #   IGCM_debug_PopStack "IGCM_sys_Get"
1505    #   return
1506    #    fi
1507    #fi
1508
1509    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1510    status=$?
1511    if [ ${status} -gt 0 ] ; then
1512      echo "WARNING IGCM_sys_Get : error code ${status}"
1513      cat out_rsync
1514      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1515    fi
1516
1517    #if [ ${status} -gt 0 ] ; then
1518    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1519    #   cat out_rsync
1520    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1521    #   sleep 30
1522    #   echo "We try another time"
1523    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1524    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1525    #   status=$?
1526    #   if [ ${status} -gt 0 ] ; then
1527    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1528    #       cat out_rsync
1529    #       IGCM_debug_Exit "IGCM_sys_Get"
1530    #   fi
1531    #    else
1532    #   echo "ERROR IGCM_sys_Get : demigration error :"
1533    #   cat out_rsync
1534    #   IGCM_debug_Exit "IGCM_sys_Get"
1535    #    fi
1536    #fi
1537
1538    #   #RSYNC WITH NETWORK SSH CALL
1539    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1540    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1541
1542    #   #RSYNC WITH NFS USE
1543    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1544    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1545
1546    #   status=$?
1547    #   IGCM_sys_Rsync_out $status
1548
1549    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1550    #   (( status=status+$? ))
1551
1552    #USUAL WAY
1553    if [ X${1} = X'/l' ] ; then
1554      for target in ${dm_liste[*]} ; do
1555        local_file=$( basename ${target} )
1556        # test if the target file is present before the loop
1557        IGCM_sys_TestFileArchive ${target}
1558        status=$?
1559        if [ ${status} -gt 0 ] ; then
1560          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1561          IGCM_debug_Exit "IGCM_sys_Get"
1562        else
1563          i=0
1564          while [ $i -lt $NB_ESSAI ] ; do
1565            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1566            status=$?
1567            if [ ${status} -gt 0 ]; then
1568              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1569              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1570              sleep $DELAI
1571            else
1572              break
1573            fi
1574            (( i = i + 1 ))
1575          done
1576          if [ ${status} -gt 0 ] ; then
1577            echo "IGCM_sys_Get : error"
1578            cat out_rsync
1579            \rm out_rsync
1580            IGCM_debug_Exit "IGCM_sys_Get"
1581          else
1582            \rm out_rsync
1583          fi
1584        fi
1585      done
1586    else
1587      i=0
1588      while [ $i -lt $NB_ESSAI ] ; do
1589        \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1590        status=$?
1591        if [ ${status} -gt 0 ]; then
1592          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1593          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1594          sleep $DELAI
1595        else
1596          break
1597        fi
1598        (( i = i + 1 ))
1599      done
1600      if [ ${status} -gt 0 ] ; then
1601        echo "IGCM_sys_Get : error"
1602        cat out_rsync
1603        \rm out_rsync
1604        IGCM_debug_Exit "IGCM_sys_Get"
1605      else
1606        \rm out_rsync
1607      fi
1608    fi
1609  else
1610    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1611  fi
1612  IGCM_debug_PopStack "IGCM_sys_Get"
1613}
1614
1615#D-#==================================================
1616#D-function IGCM_sys_GetBuffer
1617#D-* Purpose: Get a file from ${SCRATCHDIR}
1618#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1619#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1620function IGCM_sys_GetBuffer {
1621  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1622
1623  typeset DEST buf_liste ifile target file_work
1624  typeset NB_ESSAI DELAI status i
1625
1626  if ( $DEBUG_sys ) ; then
1627    echo "IGCM_sys_GetBuffer :" $@
1628  fi
1629
1630  # number of tentative
1631  NB_ESSAI=3
1632  # time delay between tentative
1633  DELAI=2
1634
1635  if [ $DRYRUN -le 2 ]; then
1636    if [ X${1} = X'/l' ] ; then
1637      # test if the first file is present in the old computation :
1638      eval set +A buf_liste \${${2}}
1639    else
1640      eval set +A buf_liste ${1}
1641    fi
1642    eval DEST=\${${#}}
1643
1644    #USUAL WAY
1645    if [ X${1} = X'/l' ] ; then
1646      for target in ${buf_liste[*]} ; do
1647        local_file=$( basename ${target} )
1648        i=0
1649        while [ $i -lt $NB_ESSAI ] ; do
1650          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1651          status=$?
1652          if [ ${status} -gt 0 ]; then
1653            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1654            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1655            sleep $DELAI
1656          else
1657            break
1658          fi
1659          (( i = i + 1 ))
1660        done
1661        if [ ${status} -gt 0 ] ; then
1662          echo "IGCM_sys_Get : error"
1663          cat out_rsync
1664          \rm out_rsync
1665          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1666        else
1667          \rm out_rsync
1668        fi
1669      done
1670    else
1671      i=0
1672      while [ $i -lt $NB_ESSAI ] ; do
1673        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1674        status=$?
1675        if [ ${status} -gt 0 ]; then
1676          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1677          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1678          sleep $DELAI
1679        else
1680          break
1681        fi
1682        (( i = i + 1 ))
1683      done
1684      if [ ${status} -gt 0 ] ; then
1685        echo "IGCM_sys_Get : error"
1686        cat out_rsync
1687        \rm out_rsync
1688        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1689      else
1690        \rm out_rsync
1691      fi
1692    fi
1693  else
1694    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1695  fi
1696  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1697}
1698
1699#D-#==================================================
1700#D-function IGCM_sys_GetDate_FichWork
1701#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1702#D-* Examples:
1703#D-
1704function IGCM_sys_GetDate_FichWork {
1705  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1706  if ( $DEBUG_sys ) ; then
1707    echo "IGCM_sys_GetDate_FichWork :" $@
1708  fi
1709  typeset dateF
1710  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1711  eval ${2}=${dateF[5]}
1712
1713    # donne la date filesys d'un fichier sur la machine work
1714  IGCM_debug_PopStack "IGCM_sys_FichWork"
1715}
1716
1717#D-#==================================================
1718#D-function IGCM_sys_GetDate_FichArchive
1719#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1720#D-* Examples:
1721#D-
1722function IGCM_sys_GetDate_FichArchive {
1723  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1724  if ( $DEBUG_sys ) ; then
1725    echo "IGCM_sys_GetDate_FichArchive :" $@
1726  fi
1727  typeset dateF
1728  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1729  eval ${2}=${dateF[5]}
1730
1731  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1732}
1733
1734#D-#==================================================
1735#D-function IGCM_sys_Dods_Rm
1736#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1737#D-* Examples:
1738#D-
1739function IGCM_sys_Dods_Rm {
1740  if ( $DEBUG_sys ) ; then
1741    echo "IGCM_sys_Dods_Rm :" $@
1742  fi
1743  typeset status
1744  if [ $DRYRUN = 0 ]; then
1745
1746#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1747#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1748#      echo "Nothing has been done."
1749#      return
1750#    fi
1751
1752    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1753    status=$?
1754
1755#       if [ ${status} -gt 0 ] ; then
1756#           echo "IGCM_sys_Dods_Rm : error."
1757#           cat out_dods_rm
1758#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1759#       else
1760#           rm out_dods_rm
1761#       fi
1762
1763  else
1764    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1765  fi
1766  return $status
1767}
1768
1769#D-#==================================================
1770#D-function IGCM_sys_Dods_Cp
1771#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1772#D-* Examples:
1773#D-
1774function IGCM_sys_Dods_Cp {
1775  if ( $DEBUG_sys ) ; then
1776    echo "IGCM_sys_Dods_Cp :" $@
1777  fi
1778  typeset status
1779  if [ $DRYRUN = 0 ]; then
1780
1781#    if [ ! -d ${R_SAVE}/${1} ] ; then
1782#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1783#      echo "Nothing has been done."
1784#      return
1785#    fi
1786
1787    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1788    status=$?
1789
1790#       if [ ${status} -gt 0 ] ; then
1791#           echo "IGCM_sys_Dods_Cp : error."
1792#           cat out_dods_cp
1793#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1794#       else
1795#           rm out_dods_cp
1796#       fi
1797
1798  else
1799    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1800  fi
1801  return $status
1802}
1803
1804#D-#==================================================
1805#D-function IGCM_sys_Put_Dods
1806#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1807#D-* Examples:
1808#D-
1809function IGCM_sys_Put_Dods {
1810  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1811  if ( $DEBUG_sys ) ; then
1812    echo "IGCM_sys_Put_Dods :" $@
1813  fi
1814  #set -vx
1815  typeset status
1816  if [ $DRYRUN = 0 ]; then
1817    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1818      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1819      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1820      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1821      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1822      return
1823    fi
1824
1825    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1826      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1827      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1828      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1829      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1830      return
1831    fi
1832    #
1833    if [ -d ${R_SAVE}/${1} ] ; then
1834      cd ${R_SAVE}
1835    elif [ -d ${R_FIGR}/${1} ] ; then
1836      cd ${R_FIGR}
1837    fi
1838
1839    IGCM_sys_Dods_Rm ${1}
1840    IGCM_sys_Dods_Cp ${1}
1841    status=0
1842
1843    if [ ${status} -gt 0 ] ; then
1844      echo "IGCM_sys_Put_Dods : error."
1845      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1846    fi
1847  else
1848    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1849  fi
1850  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1851}
1852
1853##############################################################
1854# REBUILD OPERATOR
1855
1856function IGCM_sys_rebuild {
1857  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1858  if ( $DEBUG_sys ) ; then
1859    echo "IGCM_sys_rebuild :" $@
1860  fi
1861
1862  typeset NB_ESSAI DELAI status i firstArg
1863  # number of tentative
1864  NB_ESSAI=3
1865  # time delay between tentative
1866  DELAI=2
1867
1868  i=0
1869  while [ $i -lt $NB_ESSAI ] ; do
1870      /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@ > out_rsync 2>&1
1871    status=$?
1872    if [ ${status} -gt 0 ] ; then
1873      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1874      cat out_rsync
1875      \rm out_rsync
1876      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1877      firstArg=${1}
1878      \rm ${firstArg}
1879      sleep $DELAI
1880    else
1881      \rm out_rsync
1882      break
1883    fi
1884    (( i = i + 1 ))
1885  done
1886
1887  if [ ${status} -gt 0 ] ; then
1888    echo "IGCM_sys_rebuild : rebuild error"
1889    IGCM_debug_Exit "rebuild"
1890  fi
1891
1892  IGCM_debug_PopStack "IGCM_sys_rebuild"
1893}
1894
1895function IGCM_sys_rebuild_station {
1896  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1897  typeset i list_opt file_in file_out prefix_invert list_invert
1898  if ( $DEBUG_sys ) ; then
1899    echo "IGCM_sys_rebuild_station :" $@
1900  fi
1901  list_opt=$@
1902
1903  # Invert Axis : t,x -> x,t
1904  #               t,pres,x -> x,t,pres
1905  # So that we can concatenate along x
1906  i=0
1907  for file_in in ${list_opt} ; do
1908    (( i = i + 1))
1909    [ ${i} = 1 ] && file_out=${file_in} && continue
1910    prefix_invert=$( basename ${file_in} .nc )
1911    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1912    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1913  done
1914
1915  # Concatenate
1916  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1917
1918  # Re-ivert file
1919  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1920
1921  # Station re-ordering is too expansive to be run within libICGM
1922  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1923  # This re-ordering must be done "in memory" by the cmorization process
1924  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1925  # BEGIN reordering
1926
1927  # Only LMDZ text output contains the exact ordering of the station.
1928  # We isolate this in the code below:
1929  #  0  38  -157.5000000000000  70.98591549295774
1930  #  0  54  27.49999999999999   67.18309859154928
1931  #  0  56  -62.50000000000001  82.39436619718309
1932  #  0  79  12.49999999999999   78.59154929577466
1933  #  0  116 -165.0000000000000  76.05633802816901
1934  #  0  117 130.0000000000000   70.98591549295774
1935  #  0  118 110.0000000000000   87.46478873239437
1936  #  1  40  4.999999999999995   51.97183098591550
1937#  typeset iStation iProc list_opt file_in file_out prefix_invert
1938#  typeset -Z4 j4
1939#  typeset -Z3 j3
1940
1941#  unset list_opt
1942#  set +A list_opt $@
1943
1944  # Filename after rebuild
1945#  file_out=${list_opt[0]}
1946  # Prefix of output files
1947#  prefix_invert=$( basename ${file_out} .nc )
1948  # Number of procs
1949#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1950
1951#  iProc=0
1952#  while [ ${iProc} -lt ${num_proc} ] ; do
1953    # Array containing Station as a number
1954#    unset proc_stn
1955#    set +A proc_stn $( grep "iophy_mpi rank ip lon lat  $iProc" ${PREFIX}_${Exe_Output} | sed -e "s/iophy_mpi rank ip lon lat //g" | awk ' {print $2}' )
1956    # Number of stations produced by processor proc
1957#    stationLast=${#proc_stn[*]}
1958    # Proc number on 4 digits
1959#    j4=${iProc}
1960    # Init
1961#    iStation=0
1962#    while [ ${iStation} -lt ${stationLast} ] ; do
1963      # Station number on 3 digits
1964#      j3=${proc_stn[${iStation}]}
1965      # Extract station
1966      # Invert Axis : t,x -> x,t
1967      #               t,pres,x -> x,t,pres
1968      # So that we can concatenate along x
1969#      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs -d x,$iStation,$iStation ${prefix_invert}_${j4}.nc ${prefix_invert}_stn_${j3}.nc
1970#      (( iStation = iStation + 1 ))
1971#    done
1972#    (( iProc = iProc + 1 ))
1973#  done
1974
1975  # Concatenate all station along x
1976#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1977
1978  # Re-invert file
1979#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1980
1981  # END reordering
1982
1983  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1984}
1985
1986############################################################
1987# Activate Running Environnment Variables
1988
1989function IGCM_sys_activ_variables {
1990  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1991  if ( $DEBUG_sys ) ; then
1992    echo "IGCM_sys_activ_variables"
1993  fi
1994
1995  ulimit -s unlimited
1996
1997  export KMP_STACKSIZE=3g
1998  export KMP_LIBRARY=turnaround
1999  export MKL_SERIAL=YES
2000  unset MPI_PLACING_MODE
2001
2002  # add module load nb of threads for core placement
2003  (( max_omp = 0 ))
2004
2005  for comp in ${config_ListOfComponents[*]} ; do
2006    eval ExeNameIn=\${config_Executable_${comp}[0]}
2007    eval ExeNameOut=\${config_Executable_${comp}[1]}
2008
2009    # Only if we really have an executable for the component :
2010    if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2011      eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2012      if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
2013        (( max_omp = comp_proc_omp_loc ))
2014      fi
2015    fi
2016  done
2017
2018  ( [ X${max_omp} = X4 ] || [ X${max_omp} = X8 ] ) &&  { module load openmp/${max_omp}thds ; IGCM_debug_Print 1 "module load openmp/${max_omp}thds" ; }
2019
2020  IGCM_debug_PopStack "IGCM_sys_activ_variables"
2021}
2022
2023############################################################
2024# Desactivate Running Environnment Variables
2025
2026function IGCM_sys_desactiv_variables {
2027  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
2028  if ( $DEBUG_sys ) ; then
2029    echo "IGCM_sys_desactiv_variables"
2030  fi
2031  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
2032}
2033
2034############################################################
2035# Build MPI/OMP scripts run file (dummy function)
2036
2037function IGCM_sys_build_run_file {
2038
2039IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
2040
2041}
2042
2043############################################################
2044# Build MPI/OMP scripts
2045function IGCM_sys_build_execution_scripts
2046{
2047  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
2048  if ( $DEBUG_sys ) ; then
2049    echo "IGCM_sys_build_execution_scripts " $@
2050  fi
2051  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
2052  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
2053  typeset num_corempi nombre_restant_node nombre_restant_comp
2054  typeset IGCM_OMP
2055
2056  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
2057    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
2058  fi
2059
2060  if ( ${OK_PARA_MPMD} ) ; then
2061
2062    if [ -f run_file ] ; then
2063      IGCM_sys_Rm -f run_file
2064    fi
2065    touch run_file
2066
2067    if ( ${OK_PARA_OMP} ) ; then
2068
2069      #  Hosts treatment
2070
2071      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
2072
2073      i=0
2074      rm -f hosts
2075      IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
2076      for nodes in `cat hosts.tmp` ; do
2077        host[$i]=$nodes
2078        echo "${host[$i]} slots=8 max_slots=8" >> hosts
2079        IGCM_debug_Print 1 ${host[$i]}
2080        i=$((i+1))
2081      done
2082      rm -f hosts.tmp
2083
2084      listnodes=${host[*]}
2085
2086      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
2087
2088      # Initialisation
2089
2090      init_node=y
2091      node_num_current=0
2092      start_num=0
2093      init_exec=n
2094
2095      # Test : if oasis is there, we put it at the first position
2096
2097      for comp in ${config_ListOfComponents[*]} ; do
2098
2099        if [ "X${comp}" = "XCPL" ]  ; then
2100
2101          eval ExeNameIn=\${config_Executable_${comp}[0]}
2102          eval ExeNameOut=\${config_Executable_${comp}[1]}
2103
2104          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2105          echo ""  >> script_${ExeNameOut}.ksh
2106          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2107          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2108          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2109          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
2110          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2111
2112          init_node=n
2113
2114          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
2115          node_num_current=0
2116          node_current=${host[${node_num_current}]}
2117
2118          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
2119
2120          init_exec=y
2121          start_num=1
2122
2123        fi
2124
2125      done
2126
2127      # Then loop on the components (except for oasis)
2128
2129      for comp in ${config_ListOfComponents[*]} ; do
2130
2131        eval ExeNameIn=\${config_Executable_${comp}[0]}
2132        eval ExeNameOut=\${config_Executable_${comp}[1]}
2133
2134        # Only if we really have an executable for the component :
2135        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
2136
2137          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2138          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2139
2140          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
2141          # echo "set -vx" >> script_${ExeNameOut}.ksh
2142          echo ""  >> script_${ExeNameOut}.ksh
2143          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
2144          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
2145          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
2146          echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
2147          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
2148          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
2149          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
2150
2151          node_num=0
2152
2153          # We define the number of MPI process to be assigned for the component
2154
2155          nombre_restant_comp=${comp_proc_mpi_loc}
2156
2157          # Loop on the allocated nodes
2158
2159          for node in ${listnodes} ; do
2160
2161            # We go to the current node
2162            if [ ${node_num} = ${node_num_current} ] ; then
2163
2164              node_current=${host[${node_num_current}]}
2165
2166              # If first time on the node : initialisation
2167
2168              if [ ${init_node} = y ] ; then
2169                nombre_restant_node=${NUM_COREPERNODE}
2170              fi
2171
2172              # Test on the number of OMP threads
2173
2174              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
2175                (( node_num = node_num + 1 ))
2176                node_num_current=${node_num}
2177                init_node=y
2178                continue
2179              fi
2180
2181              # Number of MPI process to assign
2182
2183              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
2184
2185              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
2186                num_corempi=${nombre_restant_comp}
2187              fi
2188
2189              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
2190              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
2191
2192              if [ ${init_exec} = y ] ; then
2193                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
2194              else
2195                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
2196                init_exec=y
2197              fi
2198
2199              ((  start_num = num_corempi + start_num ))
2200
2201            else
2202
2203              (( node_num = node_num + 1 ))
2204              continue
2205            fi
2206
2207            # Test on the number of core/process remaining on the node/component
2208
2209            if [ ${nombre_restant_node} = 0 ] ; then
2210              (( node_num = node_num + 1 ))
2211              node_num_current=${node_num}
2212              init_node=y
2213
2214              if [ ${nombre_restant_comp} = 0 ] ; then
2215                break 1
2216              fi
2217            else
2218
2219              node_num_current=${node_num}
2220              init_node=n
2221
2222              if [ ${nombre_restant_comp} = 0 ] ; then
2223                break 1
2224              fi
2225            fi
2226          done
2227        fi
2228      done
2229
2230    else
2231
2232        # Then first loop on the components for the coupler ie oasis
2233
2234        ## the coupler ie oasis must be the first one
2235        for comp in ${config_ListOfComponents[*]} ; do
2236
2237            eval ExeNameOut=\${config_Executable_${comp}[1]}
2238
2239        # for CPL component only
2240            if [ "X${comp}" = "XCPL" ] ; then
2241                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2242                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
2243            fi
2244        done
2245
2246        # Then second loop on the components
2247
2248        for comp in ${config_ListOfComponents[*]} ; do
2249
2250            eval ExeNameOut=\${config_Executable_${comp}[1]}
2251
2252            # Only if we really have an executable for the component and not the coupler ie oasis:
2253            if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
2254                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2255                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
2256            fi
2257        done
2258        IGCM_sys_Chmod u+x run_file
2259
2260        EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
2261
2262    fi
2263
2264  else # Only one executable.
2265      # Check has to be added with :
2266      # Job :
2267      # #MSUB -n 8 # reservation des processeurs pour le job
2268      # #MSUB -N 4 # reservation des nodes pour le job
2269      # BATCH_NUM_PROC_TOT=32
2270      #
2271      # config.card :
2272      # ATM= (gcm.e, lmdz.x, 8MPI, 4OMP)
2273      #
2274      # tested with :
2275      # Job :
2276      # #MSUB -n 32
2277      # BATCH_NUM_PROC_TOT=32
2278      #
2279      # config.card :
2280      # ATM= (gcm.e, lmdz.x)
2281
2282
2283      for comp in ${config_ListOfComponents[*]} ; do
2284
2285          # Only if we really have an executable for the component :
2286          eval ExeNameOut=\${config_Executable_${comp}[1]}
2287###       if ( [ "X${ExeNameOut}" != X\"\" ] ) ; then
2288          if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
2289
2290              IGCM_OMP=1
2291
2292              if ( ${OK_PARA_OMP} ) ; then
2293                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
2294                  export OMP_NUM_THREADS=${comp_proc_omp_loc}
2295                  IGCMG_OMP=${comp_proc_omp_loc}
2296              fi
2297              if  ( ${OK_PARA_MPI} ) ; then
2298                  eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
2299                  # Default : mpirun used if nb_proc gt 1
2300                  # pour sortie out/err par process ? more test required
2301                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
2302                  EXECUTION="${HOST_MPIRUN_COMMAND} -np ${comp_proc_mpi_loc} ./${ExeNameOut}"
2303              else
2304                  # Check if BATCH_NUM_PROC_TOT = IGCMG_OMP
2305                  if ( [  ${IGCM_OMP} -ne ${BATCH_NUM_PROC_TOT} ] ) ; then
2306                      IGCM_debug_Print 1 "sys Titane : BATCH_NUM_PROC_TOT <> ${comp}_PROC_OMP : ${BATCH_NUM_PROC_TOT} <> ${BRIDGE_MSUB_NPROC} "
2307                      IGCM_debug_Print 1 "sys Titane : Check #MSUB -n xx into Job"
2308                      IGCM_debug_Exit "IGCM_sys_build_execution_scripts"
2309                  fi
2310                  # Default : mpirun is NOT used if nb_proc eq 1
2311                  # pour sortie out/err par process ? more test required
2312                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
2313                  EXECUTION="/usr/bin/time ./${ExeNameOut}"
2314              fi
2315          fi
2316      done
2317
2318  fi
2319
2320  IGCM_debug_Print 1 "sys Titane : La commande d execution est "
2321  IGCM_debug_Print 1 "$EXECUTION"
2322
2323  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
2324}
2325
2326############################################################
2327# Check of space available on temporary filesytems
2328function IGCM_sys_check_quota {
2329  IGCM_debug_PushStack "IGCM_sys_check_quota"
2330  if ( $DEBUG_sys ) ; then
2331    echo "IGCM_sys_check_quota "
2332  fi
2333  # Limit of quota (in %)
2334  limit_quota=90
2335
2336  # Check of the volume
2337  volume_quota=$(ccc_quota | grep ' scratch' | awk '{print $2}')
2338  volume_avail=$(ccc_quota | grep ' scratch' | awk '{print $3}')
2339
2340  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
2341
2342    unit_avail=${volume_avail: -1}
2343    unit_quota=${volume_quota: -1}
2344
2345    if [ "${unit_quota}" = "*" ] ; then
2346        IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2347        IGCM_debug_Print 1 "More than 100% of your quota is used"
2348        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2349        IGCM_debug_Print 1 "You must have more than 10% available to run"
2350        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2351        IGCM_debug_Verif_Exit
2352    fi
2353
2354    temp_avail=${volume_avail%%${volume_avail: -1}*}
2355    temp_quota=${volume_quota%%${volume_quota: -1}*}
2356
2357    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2358
2359    # Convertion
2360      if [ ${volume_avail: -1} = "T" ] ; then
2361        (( temp_avail = temp_avail * 1000000000000 ))
2362      elif [ ${volume_avail: -1} = "G" ] ; then
2363        (( temp_avail = temp_avail * 1000000000 ))
2364      elif [ ${volume_avail: -1} = "M" ] ; then
2365        (( temp_avail = temp_avail * 1000000 ))
2366      elif [ ${volume_avail: -1} = "k" ] ; then
2367        (( temp_avail = temp_avail * 1000 ))
2368      else
2369        (( temp_avail = volume_avail ))
2370      fi
2371      if [ ${volume_quota: -1} = "T" ] ; then
2372        (( temp_quota = temp_quota * 1000000000000 ))
2373      elif [ ${volume_quota: -1} = "G" ] ; then
2374        (( temp_quota = temp_quota * 1000000000 ))
2375      elif [ ${volume_quota: -1} = "M" ] ; then
2376        (( temp_quota = temp_quota * 1000000 ))
2377      elif [ ${volume_quota: -1} = "k" ] ; then
2378        (( temp_quota = temp_quota * 1000 ))
2379      else
2380        (( temp_quota = volume_quota ))
2381      fi
2382    fi
2383
2384    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2385#    echo "volume ratio is " $quota_volume
2386
2387    if [ ${quota_volume} -ge ${limit_quota} ] ; then
2388      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
2389      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2390      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2391      IGCM_debug_Print 1 "You must have more than 10% available to run"
2392      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2393      IGCM_debug_Verif_Exit
2394    fi
2395
2396  fi
2397
2398# Check of the number of inodes
2399
2400  inode_quota=$(ccc_quota | grep ' scratch' | awk '{print $6}')
2401  inode_avail=$(ccc_quota | grep ' scratch' | awk '{print $7}')
2402
2403  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
2404
2405    unit_avail=${inode_avail: -1}
2406    unit_quota=${inode_quota: -1}
2407
2408    if [ "${unit_quota}" = "*" ] ; then
2409        IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2410        IGCM_debug_Print 1 "More than 100% of your quota is used"
2411        IGCM_debug_Print 1 "Use the ccc_quota command to check"
2412        IGCM_debug_Print 1 "You must have more than 10% available to run"
2413        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2414        IGCM_debug_Verif_Exit
2415    fi
2416
2417    temp_avail=${inode_avail%%${inode_avail: -1}*}
2418    temp_quota=${inode_quota%%${inode_quota: -1}*}
2419
2420    if [ ! ${unit_avail} = ${unit_quota} ] ; then
2421
2422    # Convertion
2423      if [ ${inode_avail: -1} = "T" ] ; then
2424        (( temp_avail = temp_avail * 1000000000000 ))
2425      elif [ ${inode_avail: -1} = "G" ] ; then
2426        (( temp_avail = temp_avail * 1000000000 ))
2427      elif [ ${inode_avail: -1} = "M" ] ; then
2428        (( temp_avail = temp_avail * 1000000 ))
2429      elif [ ${inode_avail: -1} = "k" ] ; then
2430        (( temp_avail = temp_avail * 1000 ))
2431      else
2432        (( temp_avail = inode_avail ))
2433      fi
2434
2435      if [ ${inode_quota: -1} = "T" ] ; then
2436        (( temp_quota = temp_quota * 1000000000000 ))
2437      elif [ ${inode_quota: -1} = "G" ] ; then
2438        (( temp_quota = temp_quota * 1000000000 ))
2439      elif [ ${inode_quota: -1} = "M" ] ; then
2440        (( temp_quota = temp_quota * 1000000 ))
2441      elif [ ${inode_quota: -1} = "k" ] ; then
2442        (( temp_quota = temp_quota * 1000 ))
2443      else
2444        (( temp_quota = inode_quota ))
2445      fi
2446    fi
2447    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
2448#    echo "inode ratio is " $quota_inode
2449
2450    if [ ${quota_inode} -ge ${limit_quota} ] ; then
2451      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
2452      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
2453      IGCM_debug_Print 1 "Use the ccc_quota command to check"
2454      IGCM_debug_Print 1 "You must have more than 10% available to run"
2455      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2456      IGCM_debug_Verif_Exit
2457    fi
2458
2459  fi
2460  IGCM_debug_PopStack "IGCM_sys_check_quota"
2461}
2462
2463##############################################################
2464# NCO OPERATOR
2465
2466function IGCM_sys_ncap2 {
2467  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2468  if ( $DEBUG_sys ) ; then
2469    echo "IGCM_sys_ncap2 :" $@
2470  fi
2471
2472  typeset NB_ESSAI DELAI status i
2473  # number of tentative
2474  NB_ESSAI=3
2475  # time delay between tentative
2476  DELAI=2
2477
2478  i=0
2479  while [ $i -lt $NB_ESSAI ] ; do
2480    ncap2 "$@" > out_rsync 2>&1
2481    status=$?
2482    if [ ${status} -gt 0 ] ; then
2483      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2484      cat out_rsync
2485      \rm out_rsync
2486      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2487      sleep $DELAI
2488    else
2489      \rm out_rsync
2490      break
2491    fi
2492    (( i = i + 1 ))
2493  done
2494
2495  if [ ${status} -gt 0 ] ; then
2496      echo "IGCM_sys_ncap2 : ncap2 error"
2497      IGCM_debug_Exit "ncap2"
2498  fi
2499
2500  IGCM_debug_PopStack "IGCM_sys_ncap2"
2501}
2502
2503function IGCM_sys_ncatted {
2504  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2505  if ( $DEBUG_sys ) ; then
2506    echo "IGCM_sys_ncatted :" $@
2507  fi
2508
2509  typeset NB_ESSAI DELAI status i
2510  # number of tentative
2511  NB_ESSAI=3
2512  # time delay between tentative
2513  DELAI=2
2514
2515  i=0
2516  while [ $i -lt $NB_ESSAI ] ; do
2517    ncatted "$@" > out_rsync 2>&1
2518    status=$?
2519    if [ ${status} -gt 0 ] ; then
2520      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2521      cat out_rsync
2522      \rm out_rsync
2523      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2524      sleep $DELAI
2525    else
2526      \rm out_rsync
2527      break
2528    fi
2529    (( i = i + 1 ))
2530  done
2531
2532  if [ ${status} -gt 0 ] ; then
2533      echo "IGCM_sys_ncatted : ncatted error"
2534      IGCM_debug_Exit "ncatted"
2535  fi
2536
2537  IGCM_debug_PopStack "IGCM_sys_ncatted"
2538}
2539
2540function IGCM_sys_ncbo {
2541  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2542  if ( $DEBUG_sys ) ; then
2543    echo "IGCM_sys_ncbo :" $@
2544  fi
2545
2546  typeset NB_ESSAI DELAI status i
2547  # number of tentative
2548  NB_ESSAI=3
2549  # time delay between tentative
2550  DELAI=2
2551
2552  i=0
2553  while [ $i -lt $NB_ESSAI ] ; do
2554    ncbo $@ > out_rsync 2>&1
2555    status=$?
2556    if [ ${status} -gt 0 ] ; then
2557      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2558      cat out_rsync
2559      \rm out_rsync
2560      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2561      sleep $DELAI
2562    else
2563      \rm out_rsync
2564      break
2565    fi
2566    (( i = i + 1 ))
2567  done
2568
2569  if [ ${status} -gt 0 ] ; then
2570      echo "IGCM_sys_ncbo : ncbo error"
2571      IGCM_debug_Exit "ncbo"
2572  fi
2573
2574  IGCM_debug_PopStack "IGCM_sys_ncbo"
2575}
2576
2577function IGCM_sys_ncdiff {
2578  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2579  if ( $DEBUG_sys ) ; then
2580    echo "IGCM_sys_ncdiff :" $@
2581  fi
2582
2583  typeset NB_ESSAI DELAI status i
2584  # number of tentative
2585  NB_ESSAI=3
2586  # time delay between tentative
2587  DELAI=2
2588
2589  i=0
2590  while [ $i -lt $NB_ESSAI ] ; do
2591    ncdiff $@ > out_rsync 2>&1
2592    status=$?
2593    if [ ${status} -gt 0 ] ; then
2594      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2595      cat out_rsync
2596      \rm out_rsync
2597      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2598      sleep $DELAI
2599    else
2600      \rm out_rsync
2601      break
2602    fi
2603    (( i = i + 1 ))
2604  done
2605
2606  if [ ${status} -gt 0 ] ; then
2607      echo "IGCM_sys_ncdiff : ncdiff error"
2608      IGCM_debug_Exit "ncdiff"
2609  fi
2610
2611  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2612}
2613
2614function IGCM_sys_ncea {
2615  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2616  if ( $DEBUG_sys ) ; then
2617    echo "IGCM_sys_ncea :" $@
2618  fi
2619
2620  typeset NB_ESSAI DELAI status i
2621  # number of tentative
2622  NB_ESSAI=3
2623  # time delay between tentative
2624  DELAI=2
2625
2626  i=0
2627  while [ $i -lt $NB_ESSAI ] ; do
2628    ncea $@ > out_rsync 2>&1
2629    status=$?
2630    if [ ${status} -gt 0 ] ; then
2631      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2632      cat out_rsync
2633      \rm out_rsync
2634      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2635      sleep $DELAI
2636    else
2637      \rm out_rsync
2638      break
2639    fi
2640    (( i = i + 1 ))
2641  done
2642
2643  if [ ${status} -gt 0 ] ; then
2644      echo "IGCM_sys_ncea : ncea error"
2645      IGCM_debug_Exit "ncea"
2646  fi
2647
2648  IGCM_debug_PopStack "IGCM_sys_ncea"
2649}
2650
2651function IGCM_sys_ncecat {
2652  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2653  if ( $DEBUG_sys ) ; then
2654    echo "IGCM_sys_ncecat :" $@
2655  fi
2656
2657  typeset NB_ESSAI DELAI status i
2658  # number of tentative
2659  NB_ESSAI=3
2660  # time delay between tentative
2661  DELAI=2
2662
2663  i=0
2664  while [ $i -lt $NB_ESSAI ] ; do
2665    ncecat $@ > out_rsync 2>&1
2666    status=$?
2667    if [ ${status} -gt 0 ] ; then
2668      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2669      cat out_rsync
2670      \rm out_rsync
2671      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2672      sleep $DELAI
2673    else
2674      \rm out_rsync
2675      break
2676    fi
2677    (( i = i + 1 ))
2678  done
2679
2680  if [ ${status} -gt 0 ] ; then
2681      echo "IGCM_sys_ncecat : ncecat error"
2682      IGCM_debug_Exit "ncecat"
2683  fi
2684
2685  IGCM_debug_PopStack "IGCM_sys_ncecat"
2686}
2687
2688function IGCM_sys_ncflint {
2689  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2690  if ( $DEBUG_sys ) ; then
2691    echo "IGCM_sys_ncflint :" $@
2692  fi
2693
2694  typeset NB_ESSAI DELAI status i
2695  # number of tentative
2696  NB_ESSAI=3
2697  # time delay between tentative
2698  DELAI=2
2699
2700  i=0
2701  while [ $i -lt $NB_ESSAI ] ; do
2702    ncflint $@ > out_rsync 2>&1
2703    status=$?
2704    if [ ${status} -gt 0 ] ; then
2705      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2706      cat out_rsync
2707      \rm out_rsync
2708      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2709      sleep $DELAI
2710    else
2711      \rm out_rsync
2712      break
2713    fi
2714    (( i = i + 1 ))
2715  done
2716
2717  if [ ${status} -gt 0 ] ; then
2718      echo "IGCM_sys_ncflint : ncflint error"
2719      IGCM_debug_Exit "ncflint"
2720  fi
2721
2722  IGCM_debug_PopStack "IGCM_sys_ncflint"
2723}
2724
2725function IGCM_sys_ncks {
2726  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2727  if ( $DEBUG_sys ) ; then
2728    echo "IGCM_sys_ncks :" $@
2729  fi
2730
2731  typeset NB_ESSAI DELAI status i
2732  # number of tentative
2733  NB_ESSAI=3
2734  # time delay between tentative
2735  DELAI=2
2736
2737  i=0
2738  while [ $i -lt $NB_ESSAI ] ; do
2739    ncks $@ > out_rsync 2>&1
2740    status=$?
2741    if [ ${status} -gt 0 ] ; then
2742      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2743      cat out_rsync
2744      \rm out_rsync
2745      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2746      sleep $DELAI
2747    else
2748      \rm out_rsync
2749      break
2750    fi
2751    (( i = i + 1 ))
2752  done
2753
2754  if [ ${status} -gt 0 ] ; then
2755      echo "IGCM_sys_ncks : ncks error"
2756      IGCM_debug_Exit "ncks"
2757  fi
2758
2759  IGCM_debug_PopStack "IGCM_sys_ncks"
2760}
2761
2762function IGCM_sys_ncpdq {
2763  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2764  if ( $DEBUG_sys ) ; then
2765    echo "IGCM_sys_ncpdq :" $@
2766  fi
2767
2768  typeset NB_ESSAI DELAI status i
2769  # number of tentative
2770  NB_ESSAI=3
2771  # time delay between tentative
2772  DELAI=2
2773
2774  i=0
2775  while [ $i -lt $NB_ESSAI ] ; do
2776    ncpdq $@ > out_rsync 2>&1
2777    status=$?
2778    if [ ${status} -gt 0 ] ; then
2779      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2780      cat out_rsync
2781      \rm out_rsync
2782      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2783      sleep $DELAI
2784    else
2785      \rm out_rsync
2786      break
2787    fi
2788    (( i = i + 1 ))
2789  done
2790
2791  if [ ${status} -gt 0 ] ; then
2792      echo "IGCM_sys_ncpdq : ncpdq error"
2793      IGCM_debug_Exit "ncpdq"
2794  fi
2795
2796  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2797}
2798
2799function IGCM_sys_ncra {
2800  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2801  if ( $DEBUG_sys ) ; then
2802    echo "IGCM_sys_ncra :" $@
2803  fi
2804
2805  typeset NB_ESSAI DELAI status i
2806  # number of tentative
2807  NB_ESSAI=3
2808  # time delay between tentative
2809  DELAI=2
2810
2811  i=0
2812  while [ $i -lt $NB_ESSAI ] ; do
2813    ncra $@ > out_rsync 2>&1
2814    status=$?
2815    if [ ${status} -gt 0 ] ; then
2816      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2817      cat out_rsync
2818      \rm out_rsync
2819      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2820      sleep $DELAI
2821    else
2822      \rm out_rsync
2823      break
2824    fi
2825    (( i = i + 1 ))
2826  done
2827
2828  if [ ${status} -gt 0 ] ; then
2829      echo "IGCM_sys_ncra : ncra error"
2830      IGCM_debug_Exit "ncra"
2831  fi
2832
2833  IGCM_debug_PopStack "IGCM_sys_ncra"
2834}
2835
2836function IGCM_sys_ncrcat {
2837  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2838  if ( $DEBUG_sys ) ; then
2839    echo "IGCM_sys_ncrcat :" $@
2840  fi
2841
2842  typeset NB_ESSAI DELAI status i
2843  # number of tentative
2844  NB_ESSAI=3
2845  # time delay between tentative
2846  DELAI=2
2847
2848  i=0
2849  while [ $i -lt $NB_ESSAI ] ; do
2850    ncrcat $@ > out_rsync 2>&1
2851    status=$?
2852    if [ ${status} -gt 0 ] ; then
2853      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2854      cat out_rsync
2855      \rm out_rsync
2856      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2857      sleep $DELAI
2858    else
2859      \rm out_rsync
2860      break
2861    fi
2862    (( i = i + 1 ))
2863  done
2864
2865  if [ ${status} -gt 0 ] ; then
2866      echo "IGCM_sys_ncrcat : ncrcat error"
2867      #IGCM_debug_Exit "ncrcat"
2868  fi
2869
2870  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2871}
2872
2873function IGCM_sys_ncrename {
2874  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2875  if ( $DEBUG_sys ) ; then
2876    echo "IGCM_sys_ncrename :" $@
2877  fi
2878
2879  typeset NB_ESSAI DELAI status i
2880  # number of tentative
2881  NB_ESSAI=3
2882  # time delay between tentative
2883  DELAI=2
2884
2885  i=0
2886  while [ $i -lt $NB_ESSAI ] ; do
2887    ncrename $@ > out_rsync 2>&1
2888    status=$?
2889    if [ ${status} -gt 0 ] ; then
2890      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2891      cat out_rsync
2892      \rm out_rsync
2893      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2894      sleep $DELAI
2895    else
2896      \rm out_rsync
2897      break
2898    fi
2899    (( i = i + 1 ))
2900  done
2901
2902  if [ ${status} -gt 0 ] ; then
2903      echo "IGCM_sys_ncrename : ncrename error"
2904      IGCM_debug_Exit "ncrename"
2905  fi
2906
2907  IGCM_debug_PopStack "IGCM_sys_ncrename"
2908}
2909
2910function IGCM_sys_ncwa {
2911  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2912  if ( $DEBUG_sys ) ; then
2913    echo "IGCM_sys_ncwa :" $@
2914  fi
2915
2916  typeset NB_ESSAI DELAI status i
2917  # number of tentative
2918  NB_ESSAI=3
2919  # time delay between tentative
2920  DELAI=2
2921
2922  i=0
2923  while [ $i -lt $NB_ESSAI ] ; do
2924    ncwa $@ > out_rsync 2>&1
2925    status=$?
2926    if [ ${status} -gt 0 ] ; then
2927      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2928      cat out_rsync
2929      \rm out_rsync
2930      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2931      sleep $DELAI
2932    else
2933      \rm out_rsync
2934      break
2935    fi
2936    (( i = i + 1 ))
2937  done
2938
2939  if [ ${status} -gt 0 ] ; then
2940      echo "IGCM_sys_ncwa : ncwa error"
2941      IGCM_debug_Exit "ncwa"
2942  fi
2943
2944  IGCM_debug_PopStack "IGCM_sys_ncwa"
2945}
2946
2947##############################################################
2948# CDO OPERATOR
2949
2950function IGCM_sys_cdo {
2951  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2952  if ( $DEBUG_sys ) ; then
2953    echo "IGCM_sys_cdo :" $@
2954  fi
2955
2956  typeset status
2957
2958  \cdo $@ > out_rsync 2>&1
2959  status=$?
2960  if [ ${status} -gt 0 ] ; then
2961    echo "IGCM_sys_cdo : error code ${status}"
2962    cat out_rsync
2963    \rm out_rsync
2964    IGCM_debug_PopStack "IGCM_sys_cdo"
2965    return 1
2966  else
2967    IGCM_debug_PopStack "IGCM_sys_cdo"
2968    return 0
2969  fi
2970
2971  IGCM_debug_PopStack "IGCM_sys_cdo"
2972}
Note: See TracBrowser for help on using the repository browser.