source: tags/libIGCM_v2.0/AA_pack_output @ 1170

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