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

Last change on this file since 28 was 28, checked in by aslmd, 14 years ago

LMD_MM_MARS: ancienne et nouvelle physique sur le mm coeur dynamique

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