source: trunk/libIGCM/AA_pack_output @ 785

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

Cosmetics :

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