source: trunk/mesoscale/LMD_MM_MARS/SIMU/runmeso @ 43

Last change on this file since 43 was 32, checked in by aslmd, 15 years ago

LMD_MM_MARS: version universelle de runmeso + MAJ notes

  • Property svn:executable set to *
File size: 19.1 KB
Line 
1#! /bin/bash
2
3#########################################################
4# runmeso :                                             #
5# utility to combine compilation + preprocessing + run  #
6#########################################################
7###############################
8# Author: A. Spiga            #
9# New version : December 2008 #
10# Modified    : 2009-2010     #
11# New physics : 2011          #
12###############################
13
14# TODO: - GCM compile
15#       - NETCDF
16#       - (modif registry)
17#       - quick restart
18
19
20###########################################
21###########################################
22###########################################
23
24
25changeregis=0 ## 1 if changed registry
26#changeregis=1 ## 1 if changed registry
27i_want_to_compile=1
28
29if [[ "${LMDMOD}" = "" ]]
30then
31    echo "Please initialize the variable LMDMOD in your environnement (or modify scripts)"
32    exit
33fi
34####################################
35# A FEW DEFINITIONS YOU CAN MODIFY #
36####################################
37main_folder=$LMDMOD
38meso_folder=${main_folder}'/LMD_MM_MARS'
39gcm_folder=${main_folder}'/LMDZ.MARS/myGCM'
40calendar=${main_folder}'/LMD_MM_MARS/SIMU/calendar'
41simu_folder=$PWD
42
43
44################
45# WELCOME USER #
46################
47echo '**********************************************'
48echo '**** LMD Martian Mesoscale Model launcher ****'
49echo '**********************************************'
50#echo '** Hello '$(whoami)' on '$(hostname)' !'
51#echo '** ['$(uname -a)']'
52echo '** User                  >>> '$(whoami)
53echo '** Hostname              >>> '$(hostname)
54echo '** Hardware              >>> '$(uname -m)
55echo '** Processor             >>> '$(uname -p)
56echo '**********************************************'
57
58       ######## NEWPHYS ???
59       if [[ ! ( -f "run.def" ) ]]
60       then
61         newphys=0
62       else
63         echo '** New LMD physics       >>> YES [run.def is here]'
64         echo '**********************************************'
65         newphys=1
66       fi
67
68##########################
69# GET INFO FROM NAMELIST #
70##########################
71#echo '***********************'
72#echo '**** Your settings ****'
73#echo '***********************'
74echo '** Simulation directory  >>> '${simu_folder}
75if [[ ! ( -f "namelist.input" ) ]]
76then
77   echo 'no namelist.input file !'
78   exit
79fi
80#
81# READ INFO NEEDED FOR INIT
82#
83year=$(more ${simu_folder}/namelist.input | grep start_year | awk '{print $3}' | sed s+','+''+g)
84month=$(more ${simu_folder}/namelist.input | grep start_month | awk '{print $3}' | sed s+','+''+g)
85day=$(more ${simu_folder}/namelist.input | grep start_day | awk '{print $3}' | sed s+','+''+g)
86hour=$(more ${simu_folder}/namelist.input | grep start_hour | awk '{print $3}' | sed s+','+''+g)
87wrf_date=${year}'-'${month}'-'${day}'_00:00:00'
88daygcm=$(more ${calendar} | grep ${wrf_date} | awk '{print $2}')
89lsubs=$(more ${calendar} | grep ${wrf_date} | awk '{print $3}')
90eyear=$(more ${simu_folder}/namelist.input | grep end_year | awk '{print $3}' | sed s+','+''+g)
91emonth=$(more ${simu_folder}/namelist.input | grep end_month | awk '{print $3}' | sed s+','+''+g)
92eday=$(more ${simu_folder}/namelist.input | grep end_day | awk '{print $3}' | sed s+','+''+g)
93ehour=$(more ${simu_folder}/namelist.input | grep end_hour | awk '{print $3}' | sed s+','+''+g)
94ewrf_date=${eyear}'-'${emonth}'-'${eday}'_00:00:00'
95edaygcm=$(more ${calendar} | grep ${ewrf_date} | awk '{print $2}')
96elsubs=$(more ${calendar} | grep ${ewrf_date} | awk '{print $3}')
97echo '** Start date            >>> '${year}'-'${month}'-'${day}" [sol="${daygcm}", Ls="${lsubs}"]"
98echo '** End date              >>> '${eyear}'-'${emonth}'-'${eday}" [sol="${edaygcm}", Ls="${elsubs}"]"
99#
100# READ INFO NEEDED FOR DOMAIN
101#
102interval_seconds="$(more ${simu_folder}/namelist.input | grep -e '[^!]*interval_seconds *=')"
103if [[ "${interval_seconds}" = "" ]]
104then
105     interval_seconds="interval_seconds = 3700 !! (p2) Frequency of large-scale fields update (s)"
106fi
107#
108max_dom="$(more ${simu_folder}/namelist.input | grep -e '[^!]*max_dom *=')"
109if [[ "${max_dom}" = "" ]]
110then
111     max_dom="max_dom = 1 !! (r)(n)(p2) Total number of domains"
112fi
113#
114parent_id="$(more ${simu_folder}/namelist.input | grep -e '[^!]*parent_id *=')"
115if [[ "${parent_id}" = "" ]]
116then
117     parent_id="parent_id = 0, !! (n)(p2) Associated parent domain"
118fi
119#
120i_parent_start="$(more ${simu_folder}/namelist.input | grep -e '[^!]*i_parent_start *=')"
121if [[ "${i_parent_start}" = "" ]]
122then
123     i_parent_start="i_parent_start = 0, !! (n)(p2) x-position of the bottom-left nest corner"
124fi
125#
126j_parent_start="$(more ${simu_folder}/namelist.input | grep -e '[^!]*j_parent_start *=')"
127if [[ "${j_parent_start}" = "" ]]
128then
129     j_parent_start="j_parent_start = 0, !! (n)(p2) y-position of the bottom-left nest corner"
130fi
131#
132parent_grid_ratio="$(more ${simu_folder}/namelist.input | grep -e '[^!]*parent_grid_ratio *=')"
133if [[ "${parent_grid_ratio}" = "" ]]
134then
135     parent_grid_ratio="parent_grid_ratio = 1, !! (n)(p2) Ratio of horizontal resolution parent/nest"
136fi
137#
138e_we="$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_we *=')"
139e_sn="$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_sn *=')"
140#
141dx="$(more ${simu_folder}/namelist.input | grep -e '[^!]*dx *=' | awk '{print $3}' | sed s+','+''+g)"
142dy="$(more ${simu_folder}/namelist.input | grep -e '[^!]*dy *=' | awk '{print $3}' | sed s+','+''+g)"
143
144
145#
146# READ INFO NEEDED FOR COMPILATION
147#
148nx=$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_we *=' | awk '{print $3}' | sed s+','+''+g)
149ny=$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_sn *=' | awk '{print $3}' | sed s+','+''+g)
150nz=$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_vert *=' | awk '{print $3}' | sed s+','+''+g)
151nest=$(more ${simu_folder}/namelist.input | grep -e '[^!]*max_dom *=' | awk '{print $3}' | sed s+','+''+g)
152  if [[ "${nest}" = "" ]]
153  then
154     nest='1'
155  fi
156  numcallphys=$(ls callphys*def | wc -l)
157  if [[ ${numcallphys} -lt ${nest} ]]
158  then
159        echo '**********'
160        echo You should have ${nest} callphys.def' file(s)' !!
161        exit
162  fi
163tracers=$(more ${simu_folder}/namelist.input | grep mars | awk '{print $3}' | sed s+','+''+g)
164  case ${tracers} in
165      0) tracers='1' ;;
166      1) tracers='2' ;;
167      *) tracers='1' ;;
168  esac
169echo '** Domain(s)             >>> '${nest}
170echo '** Tracer(s)             >>> '${tracers}
171echo '** Grid points           >>> '${nx}" x "${ny}" x "${nz}
172echo '** Horizontal resolution >>> '${dx}
173#echo "OK ? ('no' to exit, any key if OK)" ; read wellok
174#  if [[ "${wellok}" = "no" ]]
175#  then
176#     exit
177#  fi
178
179###########
180# ACTIONS #
181###########
182#echo '***********************'
183#echo '****     Steps     ****'
184#echo '***********************'
185echo '**********************************************'
186echo "** This script will compile the model then :"
187echo "**      <1> Prepare GCM inputs          <-1> to skip compilation"
188echo "**      <2> Perform WPS interpolations  <-2> to skip compilation"
189echo "**      <3> Execute real.exe            <-3> to skip compilation"
190echo "**      <4> Execute wrf.exe             <-4> to skip compilation"
191echo "**      <5> Exit"
192echo "**      <9> Oops ! Exit now please."
193echo '**********************************************'
194#echo "Start at which step ? (1-4)" ; read step
195echo "Where shall we start ? 1, 2, 3, 4, 5 or 9" ; read step
196if [[ ${step} -lt 0 ]]
197then
198        step=$(expr 0 - ${step})
199        i_want_to_compile=0
200        echo ".... ok, I skip the compiling & linking step. you'll just be asked the compiler you previously defined."
201fi
202case ${step} in
203        9) exit ;;
204        5) gcmstep=0 ; wpsstep=0 ; realstep=0 ; wrfstep=0 ;;
205        1) gcmstep=1 ; wpsstep=1 ; realstep=1 ; wrfstep=1 ;;
206        2) gcmstep=0 ; wpsstep=1 ; realstep=1 ; wrfstep=1 ;;
207        3) gcmstep=0 ; wpsstep=0 ; realstep=1 ; wrfstep=1 ;;
208        4) gcmstep=0 ; wpsstep=0 ; realstep=0 ; wrfstep=1 ;;
209        *) echo "** I guess you do not know what to do. Let's start from the beginning." 
210           gcmstep=1 ; wpsstep=1 ; realstep=1 ; wrfstep=1 ;;
211esac
212
213
214###################################
215# LINK THE EXECUTABLES OR COMPILE #
216###################################
217 echo '**********************************************'
218 echo "** Compiling option "
219 echo "**      <1> pgf90"
220 echo "**      <2> g95"
221 echo "**      <3> mpi+pgf90"
222 echo "**      .... more in makemeso ...."
223 echo '**********************************************'
224 echo "Your choice ? (1-3)" ; read compilo
225   if [[ "${compilo}" == "" || ${compilo} -lt 1 || ${compilo} -gt 3 ]]
226   then
227       echo "** well, let's try g95"
228       compilo=2
229   fi
230   if [[ ${compilo} -eq 3 ]]
231   then
232       echo How many processors ? 1, 2, 4, 6, 8, 16 ; read numproc
233   else
234       numproc=1
235   fi
236#if [[ ${i_want_to_compile} -ge 1 ]]
237#then
238 cd ${meso_folder}
239 echo ${compilo} > tmp
240   if [[ ${compilo} -eq 3 ]]
241   then
242        echo ${numproc} >> tmp
243   fi
244 echo ${nest} >> tmp
245
246 if [[ ${newphys} -eq 0 ]]
247 then
248 ./makemeso -d < tmp > /dev/null
249 else
250 ./makemeso -d -p < tmp > /dev/null
251 fi
252
253 \rm tmp 2> /dev/null
254 work_folder=${meso_folder}'/'$(more what_folder)
255 echo 'work_folder : '${work_folder}
256 \rm what_folder 2> /dev/null
257
258 ##################### NB: define the domain if was not done yet
259   if [[ -f "${simu_folder}/namelist.wps" ]]
260   then
261     happy='y'
262   else
263     happy=''
264   fi
265           if [[ ${step} -le 2 ]]
266           then
267           while [[ "${happy}" != "y" ]]
268           do
269             #vi ${simu_folder}/namelist.input
270                if [[ ! ( -d "${work_folder}/WPS" ) ]]
271                then
272                    echo 'no WPS. you need to install it for your architecture'
273                    exit
274                fi
275             \rm ${simu_folder}/namelist.wps 2> /dev/null
276             echo '**********************************************'
277             echo "    !!!   NO namelist.wps FILE FOUND   !!!"   
278             echo '**********************************************'
279             echo 'Please define the domain (not for nests for the moment) : '
280             echo " - 1/4 Projection: polar lambert mercator ? previous is "${proj} ; read proj
281             echo " - 2/4 Data source (multiple if nests): 'gcm' '32ppd' '64ppd' '64ppd_noHRti' '32ppd_HRalb' ? previous is "${data_source} ; read data_source
282             echo " - 3/4 North Latitude of domain centre ? previous is "${lat} ; read lat
283             echo " - 4/4 East  Longitude of domain centre ? previous is "${lon} ; read lon
284             #####
285             sed s+"__INTERVAL_SECONDS__"+"${interval_seconds}"+g ${meso_folder}/SIMU/namelist.wps | sed s+"__MAX_DOM__"+"${max_dom}"+g | sed s+"__PARENT_ID__"+"${parent_id}"+g |  sed s+"__PARENT_GRID_RATIO__"+"${parent_grid_ratio}"+g |  sed s+"__I_PARENT_START__"+"${i_parent_start}"+g | sed s+"__J_PARENT_START__"+"${j_parent_start}"+g | sed s+"__E_WE__"+"${e_we}"+g | sed s+"__E_SN__"+"${e_sn}"+g | sed s+"__DX__"+"${dx}"+g | sed s+"__DY__"+"${dy}"+g | sed s+"__PROJ__"+"${proj}"+g | sed s+"__DATA_SOURCE__"+"${data_source}"+g | sed s+"__LAT__"+"${lat}"+g | sed s+"__LON__"+"${lon}"+g | sed s+'0000-00-00_00:00:00'+${year}'-'${month}'-'${day}'_'${hour}':00:00'+g | sed s+'1111-11-11_11:11:11'+${eyear}'-'${emonth}'-'${eday}'_'${ehour}':00:00'+g > ${simu_folder}/namelist.wps
286             ####
287             ln -sf ${simu_folder}/namelist.wps ${work_folder}/WPS/namelist.wps
288             #vi       ${work_folder}/WPS/namelist.wps
289             echo '**********************************************'
290             echo OK, thank you. Please wait... ncview will pop up soon !
291             cd ${work_folder}/WPS/
292             \rm geo_em.d0*.nc 2> /dev/null
293             ./geogrid.exe > /dev/null 2> /dev/null
294             ncview geo_em.d01.nc > /dev/null 2> /dev/null &
295                if [[ -f "geo_em.d02.nc" ]]
296                then
297                     ncview geo_em.d02.nc > /dev/null 2> /dev/null &
298                fi
299                if [[ -f "geo_em.d03.nc" ]]
300                then
301                     ncview geo_em.d03.nc > /dev/null 2> /dev/null &
302                fi
303             cd       ${simu_folder}/
304             echo     '**********************************************' 
305             echo     'Are you happy with the results ? type y if yes, any key if no' ; read happy
306            done
307            fi
308 #####################
309 if [[ ${i_want_to_compile} -ge 1 ]]
310 then
311 cd ${simu_folder}
312     ## corresponding executables
313    wrfexe=${work_folder}/wrf_x${nx}_y${ny}_z${nz}_d${nest}_t${tracers}_p${numproc}.exe
314    realexe=${work_folder}/real_x${nx}_y${ny}_z${nz}_d${nest}_t${tracers}_p${numproc}.exe
315 if [[ -f ${wrfexe} ]]
316 then
317     echo '**********************************************'
318     echo "    !!!   wrf.exe exists in ${work_folder}"
319     echo '**********************************************'
320     echo "Recompile ? ('yes' to accept, any key to refuse)" ; read reply
321 else
322     reply='yes'
323 fi
324 echo '********************************************** OK thanks. Now please wait...'
325 echo '                                       '
326 if [[ "${reply}" == "yes" ]]
327 then
328 #####################
329 echo "** "Begin compilation process...
330 \rm ${wrfexe} 2> /dev/null
331 \rm ${realexe} 2> /dev/null
332   #
333   # CREATE makemeso_input
334   #
335   \rm ${simu_folder}/makemeso_input 2> /dev/null
336   touch ${simu_folder}/makemeso_input
337   echo ${compilo} >> ${simu_folder}/makemeso_input
338   if [[ "${compilo}" = "3" ]]
339     then
340         echo ${numproc} >> ${simu_folder}/makemeso_input
341   fi
342   echo ${nx} >> ${simu_folder}/makemeso_input
343   echo ${ny} >> ${simu_folder}/makemeso_input
344   echo ${nz} >> ${simu_folder}/makemeso_input
345   echo ${nest} >> ${simu_folder}/makemeso_input
346   echo ${tracers} >> ${simu_folder}/makemeso_input
347   #echo 'y' >> ${simu_folder}/makemeso_input
348   #
349   # COMPILE THE MODEL
350   #
351   cd ${meso_folder}
352                      if [[ "${changeregis}" = "1" ]]
353                      then
354                          cd ${work_folder}/WRFV2/Registry
355                          \rm Registry 2> /dev/null
356                          ./Registry.bash
357                          cd ../../..
358                      fi
359
360     ##******
361     if [[ ${newphys} -eq 0 ]]
362     then
363       ./makemeso -r < ${simu_folder}/makemeso_input
364     else
365       ./makemeso -r -p < ${simu_folder}/makemeso_input
366     fi
367     ##******
368
369
370   if [[ -f ${wrfexe} ]]
371   then
372       echo "** "seems OK ... linking executables
373       ln -sf ${wrfexe} ${simu_folder}/wrf.exe
374       ln -sf ${realexe} ${simu_folder}/real.exe
375       chmod a+x ${realexe} ${wrfexe} ## sait-on jamais
376       cd $simu_folder
377   else
378       echo no ${wrfexe}
379       echo problem with the compilation
380       exit
381   fi
382 else
383     #echo simply linking existing executables...
384     ln -sf ${wrfexe} ${simu_folder}/wrf.exe
385     ln -sf ${realexe} ${simu_folder}/real.exe
386     chmod a+x ${realexe} ${wrfexe} ## sait-on jamais
387 fi
388fi
389
390######################################
391# 1. RUN GCM FOR INIT/BDY CONDITIONS #
392######################################
393if [ ${gcmstep} -eq 1 ]
394then
395 echo '************************************'
396 echo '**** Step 1: Prepare GCM inputs ****'
397 echo '************************************'
398        #
399        # run GCM
400        #
401        cd ${gcm_folder}
402         #echo '(during the run, you might like to check domain settings in '${work_folder}'/WPS)'
403        echo ${daygcm} | ./launch_gcm
404        #
405        # prepare files for WPS
406        #
407        cd ${work_folder}
408        if [[ -f ${work_folder}/PREP_MARS/create_readmeteo.exe && -f ${work_folder}/PREP_MARS/readmeteo.exe ]]
409        then
410              cd ${work_folder}/PREP_MARS/ 
411                ./compile_and_exec
412              #echo 1 | ./create_readmeteo.exe
413              #./readmeteo.exe < readmeteo.def
414        else
415              echo please compile the PREP_MARS utilities in ${work_folder}
416              exit
417        fi
418fi     
419
420###################################
421# 2. RUN WRF PREPROCESSING SYSTEM #
422###################################
423if [ ${wpsstep} -eq 1 ]
424then
425 echo '*****************************************'
426 echo '**** Step 2: Perform WPS interpolations *'
427 echo '*****************************************'
428        if [[ -f ${work_folder}/WPS/geogrid.exe && -f ${work_folder}/WPS/metgrid.exe ]]
429        then
430              \rm -rf ${simu_folder}/met_em 2> /dev/null
431              mkdir ${simu_folder}/met_em
432              cd ${work_folder}/WPS/
433              \rm -rf ${work_folder}/WPS/WRFFEED/current 2> /dev/null
434              mkdir ${work_folder}/WPS/WRFFEED/current
435              ln -sf ${simu_folder}/namelist.wps ${work_folder}/WPS/namelist.wps
436              #mv namelist.wps namelist.wps.tmp
437              #sed s+'0000-00-00_00:00:00'+${year}'-'${month}'-'${day}'_'${hour}':00:00'+g namelist.wps.tmp | sed s+'1111-11-11_11:11:11'+${eyear}'-'${emonth}'-'${eday}'_'${ehour}':00:00'+g > namelist.wps
438              ./geogrid.exe
439              ./metgrid.exe
440              #mv namelist.wps ${simu_folder}
441              #mv namelist.wps.tmp namelist.wps 
442              namedata=$(date +simu_%d%h%Y_%H%M)
443              mv ${work_folder}/WPS/WRFFEED/current ${work_folder}'/WPS/WRFFEED/'${namedata}
444              echo met_em files in $namedata
445              cd ${simu_folder}/met_em
446              ln -sf ${work_folder}/WPS/WRFFEED/${namedata}/* .
447              cd ${simu_folder}
448        else
449              echo please compile the WPS utilities in ${work_folder}
450              exit
451        fi
452fi     
453
454###################
455# 3. RUN REAL.EXE #
456###################
457if [ ${realstep} -eq 1 ]
458then
459 echo '*******************************'
460 echo '**** Step 3: Execute real.exe *'
461 echo '*******************************'
462        cd ${simu_folder}
463        if [[ ! -d met_em ]]
464        then
465                ls
466                echo "PB: no met_em files:"
467                echo "mkdir met_em folder then link met_em** files !"
468                exit
469        fi
470        cd ${simu_folder}/met_em
471        ln -sf ${simu_folder}/namelist.input .
472        ln -sf ${simu_folder}/real.exe .
473        rm -rf ${simu_folder}/met_em/wrfbdy* 2> /dev/null
474        rm -rf ${simu_folder}/met_em/wrfinput* 2> /dev/null
475        if [[ ${compilo} -eq 3 ]]
476        then
477                rm -rf ${simu_folder}/met_em/rsl.* 2> /dev/null
478                echo "check in "${simu_folder}"/met_em/rsl.out.0000"
479                ./real.exe
480                tail -n 4 ${simu_folder}"/met_em/rsl.out.0000"
481        else
482                rm -rf ${simu_folder}/met_em/log* 2> /dev/null
483                echo "check in "${simu_folder}"/met_em/log_real"
484                real.exe > log_real
485                tail -n 4 ${simu_folder}"/met_em/log_real"
486        fi
487        if [[ -f ${simu_folder}/met_em/wrfinput_d01 && -f ${simu_folder}/met_em/wrfbdy_d01 ]]
488        then
489                echo ok... link ini and bdy conditions
490                cd ${simu_folder}
491                ln -sf ${simu_folder}/met_em/wrf*_d0* .
492        else
493                echo mmm... there was a problem, see log files in met_em
494                exit
495        fi
496fi
497
498##################
499# 4. RUN WRF.EXE #
500##################
501if [ ${wrfstep} -eq 1 ]
502then
503 xeyes &
504 echo '******************************'
505 echo '**** Step 4: Execute wrf.exe *'
506 echo '******************************'
507        cd ${simu_folder}
508        rm -rf ${simu_folder}/wrfout*
509        if [[ ${compilo} -eq 3 ]]
510        then
511                rm -rf ${simu_folder}/rsl.* 2> /dev/null
512#                ${WHERE_MPI}/mpirun -host smith -np ${numproc} wrf.exe < /dev/null &
513                ${WHERE_MPI}/mpirun -np ${numproc} wrf.exe < /dev/null &
514        else
515                rm -rf ${simu_folder}/log* 2> /dev/null
516                nohup wrf.exe > log_wrf &
517        fi
518echo OK ! Simulation should be running now !
519echo Check with the command: "ps -e -o '%u %p %C %x %c' | grep wrf.exe"
520echo '******************************'
521echo '**** End.'
522
523fi
524exit
525
526
527
Note: See TracBrowser for help on using the repository browser.