source: tags/libIGCM_v2.2/AA_pack_output

Last change on this file was 929, checked in by sdipsl, 11 years ago

machine cleanup
whitespace cleanup

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