source: trunk/libIGCM/AA_pack_output @ 837

Last change on this file since 837 was 837, checked in by labetoulle, 11 years ago

On Curie, ins_job sets up project ID. See #98.

Add

#-Q- curie #MSUB -A ::default_project::

to job headers, to be replaced by proper project ID by ins_job.

  • Property svn:keywords set to Revision Author Date
File size: 12.3 KB
Line 
1#-Q- curie ######################
2#-Q- curie ## CURIE   TGCC/CEA ##
3#-Q- curie ######################
4#-Q- curie #MSUB -r PACKOUTPUT     # Nom du job
5#-Q- curie #MSUB -eo
6#-Q- curie #MSUB -n 1              # Reservation du processus
7#-Q- curie #MSUB -T 86400          # Limite de temps elapsed du job
8#-Q- curie #MSUB -q xlarge
9#-Q- curie #MSUB -Q normal
10#-Q- curie #MSUB -A ::default_project::
11#-Q- curie set +x
12#-Q- ada #!/bin/ksh
13#-Q- ada #######################
14#-Q- ada ##   VARGAS   IDRIS  ##
15#-Q- ada #######################
16#-Q- ada # Temps Elapsed max. d'une requete hh:mm:ss
17#-Q- ada # @ wall_clock_limit = 10:00:00
18#-Q- ada # Nom du travail LoadLeveler
19#-Q- ada # @ job_name   = PACKOUTPUT
20#-Q- ada # Fichier de sortie standard du travail
21#-Q- ada # @ output     = $(job_name).$(jobid)
22#-Q- ada # Fichier de sortie d'erreur du travail
23#-Q- ada # @ error      =  $(job_name).$(jobid)
24#-Q- ada # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
25#-Q- ada # @ notification = error
26#-Q- ada # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $DateBegin ; $DateEnd ; $PeriodPack ; $StandAlone ; $MASTER
27#-Q- ada # @ queue
28#-Q- sx9mercure #!/bin/ksh
29#-Q- sx9mercure ######################
30#-Q- sx9mercure ## SX9MERCURE  CCRT ##
31#-Q- sx9mercure ######################
32#-Q- sx9mercure #PBS -N PACKOUTPUT          # Nom du job
33#-Q- sx9mercure #PBS -j o                    # regroupement des stdout et stderr
34#-Q- sx9mercure #PBS -S /usr/bin/ksh         # shell de soumission
35#-Q- sx9mercure #PBS -l memsz_job=1gb        # Limite memoire a 1 Go
36#-Q- sx9mercure #PBS -l elapstim_req=48:00:00  # Limite temps a 1 heures
37#-Q- sx9mercure #PBS -q scalaire
38#-Q- sx9mercure #PBS -r n
39#-Q- titane #!/bin/ksh
40#-Q- titane ######################
41#-Q- titane ## TITANE   CEA     ##
42#-Q- titane ######################
43#-Q- titane #MSUB -r PACKOUTPUT    # Nom du job
44#-Q- titane #MSUB -eo
45#-Q- titane #MSUB -n 1              # Reservation du processus
46#-Q- titane #MSUB -T 86400          # Limite de temps elapsed du job
47#-Q- titane #MSUB -q mono
48#-Q- titane #MSUB -E '-rn'
49#-Q- lxiv8 ######################
50#-Q- lxiv8 ## OBELIX      LSCE ##
51#-Q- lxiv8 ######################
52#-Q- lxiv8 #PBS -N PACKOUTPUT
53#-Q- lxiv8 #PBS -m a
54#-Q- lxiv8 #PBS -j oe
55#-Q- lxiv8 #PBS -q medium
56#-Q- lxiv8 #PBS -o PACKOUTPUT.$$
57#-Q- lxiv8 #PBS -S /bin/ksh
58#-Q- default #!/bin/ksh
59#-Q- default ##################
60#-Q- default ## DEFAULT HOST ##
61#-Q- default ##################
62
63#**************************************************************
64# Author: Sebastien Denvil
65# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
66# $Revision::                                          $ Revision of last commit
67# $Author::                                            $ Author of last commit
68# $Date::                                              $ Date of last commit
69# IPSL (2006)
70#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
71#
72#**************************************************************
73
74#set -eu
75#set -vx
76
77date
78
79#D- Task type (computing or post-processing)
80TaskType=post-processing
81
82########################################################################
83
84#D- Flag to determine if this job in a standalone mode
85#D- Default : value from AA_job if any
86StandAlone=${StandAlone:=true}
87
88#D- Path to libIGCM
89#D- Default : value from AA_job if any
90# WARNING For StandAlone use : To run this script on some machine (ulam and cesium)
91# WARNING you must check MirrorlibIGCM variable in sys library.
92# WARNING If this variable is true, you must use libIGCM_POST path instead
93# WARNING of your running libIGCM directory.
94libIGCM=${libIGCM:=::modipsl::/libIGCM}
95
96#-D- $hostname of the MASTER job when SUBMIT_DIR is not visible on postprocessing computer.
97MASTER=${MASTER:=mercure|titane|brodie|vargas}
98
99#D- Flag to determine begin date for restart pack
100#D- Default : value from AA_job if any
101DateBegin=${DateBegin:=20000101}
102
103#D- Flag to determine end date for restart pack
104#D- Default : value from AA_job if any
105DateEnd=${DateEnd:=20691231}
106
107#D- Flag to determine pack period
108#D- Default : value from AA_job if any
109PeriodPack=${PeriodPack:=10Y}
110
111#D- Uncomment to run interactively
112#D- For testing purpose, will be remove
113#SUBMIT_DIR=${PWD}
114#RUN_DIR_PATH=${SCRATCHDIR}/Pack_Test
115
116#D- Increased verbosity (1, 2, 3)
117#D- Default : value from AA_job if any
118Verbosity=${Verbosity:=3}
119
120#D- Low level debug : to bypass lib test checks and stack construction
121#D- Default : value from AA_job if any
122DEBUG_debug=${DEBUG_debug:=false}
123
124########################################################################
125
126. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
127. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
128. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
129#-------
130. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
131. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
132. ${libIGCM}/libIGCM_post/libIGCM_post.ksh
133#-------
134( ${DEBUG_debug} ) && IGCM_debug_Check
135( ${DEBUG_debug} ) && IGCM_card_Check
136( ${DEBUG_debug} ) && IGCM_date_Check
137
138########################################################################
139
140#set -vx
141
142RUN_DIR=${RUN_DIR_PATH}
143IGCM_sys_MkdirWork ${RUN_DIR}
144IGCM_sys_Cd ${RUN_DIR}
145
146# ------------------------------------------------------------------
147# Test if all was right before proceeding further
148# ------------------------------------------------------------------
149IGCM_debug_Verif_Exit_Post
150
151if [ ${StandAlone} = true ] ; then
152    CARD_DIR=${SUBMIT_DIR}
153else
154    CARD_DIR=${RUN_DIR_PATH}
155    IGCM_sys_Get_Master ${SUBMIT_DIR}/config.card ${RUN_DIR_PATH}
156    IGCM_sys_Get_Master ${SUBMIT_DIR}/run.card    ${RUN_DIR_PATH}
157    IGCM_sys_Get_Master ${SUBMIT_DIR}/COMP        ${RUN_DIR_PATH}
158    IGCM_sys_Get_Master ${SUBMIT_DIR}/POST        ${RUN_DIR_PATH}
159fi
160
161#==================================
162# First of all
163#
164# Read libIGCM compatibility version in config.card
165# Read UserChoices section
166# Read Ensemble section
167# Read Post section
168# Define all netcdf output directories
169#==================================
170IGCM_config_CommonConfiguration ${CARD_DIR}/config.card
171
172#==================================
173# Read ListOfComponents section
174# to drive the loop over find
175IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card ListOfComponents
176#
177IGCM_sys_TestDirArchive ${R_SAVE}
178[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
179
180# Where to store used file list /!\ TEMPORARY /!\
181STORE_DEBUG=${R_SAVE}/DEBUG
182
183# Switch to script variables meaning (try to be compatible with ipsl_pack TGCC moving procedure)
184JobName=${config_UserChoices_JobName}
185echo $JobName $DateBegin $DateEnd
186
187# ------------------------------------------------------------------
188# Test if all was right before proceeding further
189# ------------------------------------------------------------------
190IGCM_debug_Verif_Exit_Post
191
192IGCM_debug_Print 1 "Check coherence between PackFrequency and PeriodLength"
193IGCM_post_CheckModuloFrequency PeriodPack config_UserChoices_PeriodLength NbPeriodPerFrequency
194# ------------------------------------------------------------------
195# Test if all was right before proceeding further
196# ------------------------------------------------------------------
197IGCM_debug_Verif_Exit_Post
198
199IGCM_debug_Print 1 "We must process ${NbPeriodPerFrequency} files for each pack"
200
201# Init loop
202date_begin_pack=${DateBegin}
203date_end_simulation=${DateEnd}
204number_pack=1
205
206IGCM_debug_PrintVariables 3 date_begin_pack
207IGCM_debug_PrintVariables 3 date_end_simulation
208
209while [ ${date_begin_pack} -le ${date_end_simulation} ] ; do
210
211  IGCM_debug_PrintVariables 3 number_pack
212  DaysTemp=$( IGCM_date_DaysInCurrentPeriod ${date_begin_pack} ${PeriodPack} )
213  date_end_pack=$( IGCM_date_AddDaysToGregorianDate ${date_begin_pack} $(( ${DaysTemp} - 1 )) )
214
215  for comp in ${config_ListOfComponents[*]} ; do
216    dirList=$( find ${R_BUFR}/${comp}/Output -maxdepth 1 -mindepth 1 -type d )
217    for dir in ${dirList} ; do
218      # dirID is like ATM.Output.MO
219      dirID=$( echo $dir | sed "s:${R_BUFR}/::" | sed "s:/:.:g" )
220      # Sort what's in the directory
221      find ${dir} -type f -name "${JobName}*.nc" -ls | sort -k 11 > liste_files.${dirID}.txt
222      # How much file type. Example : 1M_histmthCOSP.nc, 1M_histmth.nc, 1M_histmthNMC.nc, 1M_paramLMDZ_phy.nc
223      # /!\ fileType include the .nc extension /!\
224      fileType=$( gawk '{print $11}' liste_files.${dirID}.txt | gawk -F$dir/ '{print $2}' | sed "s:${JobName}_[0-9]\{8,9\}_[0-9]\{8,9\}_::g" | sort | uniq )
225      # Loop over the file type and pack them when in between date_begin_pack and date_end_pack
226      for myType in ${fileType} ; do
227        grep ${myType} liste_files.${dirID}.txt > liste_files.${dirID}.${myType}.txt
228        nbfile=0
229        for file in $( gawk '{print $11}' liste_files.${dirID}.${myType}.txt ); do
230          extract_date_file=$( echo ${file}  | sed -e "s/.*${JobName}_[0-9]*_//" )
231          date_file=$( echo ${extract_date_file} | sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
232          # echo pack n°${number_pack}  ${date_file} ${date_begin_pack} ${date_end_pack}
233          if [ ${date_file} -le ${date_end_pack} ] && [ ${date_file} -ge ${date_begin_pack} ] ; then
234            echo ${file} >> liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt
235            ncdump -h ${file} | grep -E 'float|double' | cut -f 1 -d '(' | cut -f 2 -d ' ' >> liste_variables_${myType}_${date_begin_pack}_${date_end_pack}.txt
236            (( nbfile = nbfile + 1 ))
237          fi
238        done
239
240        if [ ${nbfile} = 0 ] ; then
241          IGCM_debug_Print 1 "We found no file to process"
242          IGCM_debug_Print 1 "We should have found ${NbPeriodPerFrequency} files"
243          IGCM_debug_Print 1 "As some files can be produced only for some selected period we consider we can move to the next file type"
244          continue
245        fi
246
247        # Select list of variables to work with
248        list_var=$( cat liste_variables_${myType}_${date_begin_pack}_${date_end_pack}.txt | sort | uniq -c | awk -v nbfile=$nbfile '{if ($1 != nbfile) {print $2}}' | paste -s -d ',' )
249        liste_file_tmp=$( for i in $( cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt ) ; do basename $i ; done )
250        # Create packed files
251        IGCM_debug_Print 1 "Ncrcat ongoing for ${dir} and ${myType}"
252        if [ ! ${nbfile} = ${NbPeriodPerFrequency} ] ; then
253          IGCM_debug_Print 1 "Number of files to process is not equal to what it should be"
254          IGCM_debug_Print 1 "We found ${nbfile} files and it should have been ${NbPeriodPerFrequency} files"
255          IGCM_debug_Exit "ERROR in number of files to process. STOP HERE INCLUDING THE COMPUTING JOB"
256          IGCM_debug_Verif_Exit
257        fi
258        output=${JobName}_${date_begin_pack}_${date_end_pack}_${myType}
259        #cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt | xargs ncrcat -v ${list_var} -o ${output}
260        if [ X${list_var} = X ] ; then
261          IGCM_sys_ncrcat -p ${dir} ${liste_file_tmp} --output ${output}
262        else
263          IGCM_sys_ncrcat -x -v ${list_var} -p ${dir} ${liste_file_tmp} --output ${output}
264        fi
265        # ------------------------------------------------------------------
266        # Test if all was right before proceeding further
267        # ------------------------------------------------------------------
268        IGCM_debug_Verif_Exit_Post
269        # Save it
270        IGCM_sys_Put_Out ${output} ${R_SAVE}/$( echo $dir | sed "s:${R_BUFR}/::" )/${output}
271        # Clean file produced by ncrcat
272        IGCM_sys_Rm ${output}
273        # ------------------------------------------------------------------
274        # Test if all was right before proceeding further
275        # ------------------------------------------------------------------
276        IGCM_debug_Verif_Exit_Post
277        # Clean files used by ncrcat
278        cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt | xargs rm
279        # Save the list of files that has been pack (ncrcat)
280        #mv liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt ${STORE_DEBUG}
281        IGCM_debug_Print 1 "Ncrcat and cleaning done for ${dir} and ${myType}"
282        echo
283      done
284    done
285  done
286  (( number_pack = number_pack + 1 ))
287  # Add 1 day to date_end_pack to have the new date_begin_pack
288  date_begin_pack=$( IGCM_date_AddDaysToGregorianDate ${date_end_pack} 1 )
289done
290
291# Flush post-processing submission
292if [ -f ${R_BUFR}/FlushPost_${DateEnd}.ksh ] ; then
293  . ${R_BUFR}/FlushPost_${DateEnd}.ksh
294  IGCM_FlushPost
295  #IGCM_sys_Rm -f ${R_BUFR}/FlushPost_${DateEnd}.ksh
296fi
297
298# Clean RUN_DIR_PATH (necessary for cesium and titane only)
299IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
300
301date
Note: See TracBrowser for help on using the repository browser.