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

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

mineur: preparation ajout du GCM ancienne physique, deplacement du dossier nouvelle physique et prise en compte dans runmeso

  • Property svn:executable set to *
File size: 19.2 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'
39calendar=${main_folder}'/LMD_MM_MARS/SIMU/calendar'
40simu_folder=$PWD
41
42
43################
44# WELCOME USER #
45################
46echo '**********************************************'
47echo '**** LMD Martian Mesoscale Model launcher ****'
48echo '**********************************************'
49#echo '** Hello '$(whoami)' on '$(hostname)' !'
50#echo '** ['$(uname -a)']'
51echo '** User                  >>> '$(whoami)
52echo '** Hostname              >>> '$(hostname)
53echo '** Hardware              >>> '$(uname -m)
54echo '** Processor             >>> '$(uname -p)
55echo '**********************************************'
56
57       ######## NEWPHYS ???
58       if [[ ! ( -f "run.def" ) ]]
59       then
60         newphys=0
61       else
62         echo '** New LMD physics       >>> YES [run.def is here]'
63         echo '**********************************************'
64         newphys=1
65       fi
66
67##########################
68# GET INFO FROM NAMELIST #
69##########################
70#echo '***********************'
71#echo '**** Your settings ****'
72#echo '***********************'
73echo '** Simulation directory  >>> '${simu_folder}
74if [[ ! ( -f "namelist.input" ) ]]
75then
76   echo 'no namelist.input file !'
77   exit
78fi
79#
80# READ INFO NEEDED FOR INIT
81#
82year=$(more ${simu_folder}/namelist.input | grep start_year | awk '{print $3}' | sed s+','+''+g)
83month=$(more ${simu_folder}/namelist.input | grep start_month | awk '{print $3}' | sed s+','+''+g)
84day=$(more ${simu_folder}/namelist.input | grep start_day | awk '{print $3}' | sed s+','+''+g)
85hour=$(more ${simu_folder}/namelist.input | grep start_hour | awk '{print $3}' | sed s+','+''+g)
86wrf_date=${year}'-'${month}'-'${day}'_00:00:00'
87daygcm=$(more ${calendar} | grep ${wrf_date} | awk '{print $2}')
88lsubs=$(more ${calendar} | grep ${wrf_date} | awk '{print $3}')
89eyear=$(more ${simu_folder}/namelist.input | grep end_year | awk '{print $3}' | sed s+','+''+g)
90emonth=$(more ${simu_folder}/namelist.input | grep end_month | awk '{print $3}' | sed s+','+''+g)
91eday=$(more ${simu_folder}/namelist.input | grep end_day | awk '{print $3}' | sed s+','+''+g)
92ehour=$(more ${simu_folder}/namelist.input | grep end_hour | awk '{print $3}' | sed s+','+''+g)
93ewrf_date=${eyear}'-'${emonth}'-'${eday}'_00:00:00'
94edaygcm=$(more ${calendar} | grep ${ewrf_date} | awk '{print $2}')
95elsubs=$(more ${calendar} | grep ${ewrf_date} | awk '{print $3}')
96echo '** Start date            >>> '${year}'-'${month}'-'${day}" [sol="${daygcm}", Ls="${lsubs}"]"
97echo '** End date              >>> '${eyear}'-'${emonth}'-'${eday}" [sol="${edaygcm}", Ls="${elsubs}"]"
98#
99# READ INFO NEEDED FOR DOMAIN
100#
101interval_seconds="$(more ${simu_folder}/namelist.input | grep -e '[^!]*interval_seconds *=')"
102if [[ "${interval_seconds}" = "" ]]
103then
104     interval_seconds="interval_seconds = 3700 !! (p2) Frequency of large-scale fields update (s)"
105fi
106#
107max_dom="$(more ${simu_folder}/namelist.input | grep -e '[^!]*max_dom *=')"
108if [[ "${max_dom}" = "" ]]
109then
110     max_dom="max_dom = 1 !! (r)(n)(p2) Total number of domains"
111fi
112#
113parent_id="$(more ${simu_folder}/namelist.input | grep -e '[^!]*parent_id *=')"
114if [[ "${parent_id}" = "" ]]
115then
116     parent_id="parent_id = 0, !! (n)(p2) Associated parent domain"
117fi
118#
119i_parent_start="$(more ${simu_folder}/namelist.input | grep -e '[^!]*i_parent_start *=')"
120if [[ "${i_parent_start}" = "" ]]
121then
122     i_parent_start="i_parent_start = 0, !! (n)(p2) x-position of the bottom-left nest corner"
123fi
124#
125j_parent_start="$(more ${simu_folder}/namelist.input | grep -e '[^!]*j_parent_start *=')"
126if [[ "${j_parent_start}" = "" ]]
127then
128     j_parent_start="j_parent_start = 0, !! (n)(p2) y-position of the bottom-left nest corner"
129fi
130#
131parent_grid_ratio="$(more ${simu_folder}/namelist.input | grep -e '[^!]*parent_grid_ratio *=')"
132if [[ "${parent_grid_ratio}" = "" ]]
133then
134     parent_grid_ratio="parent_grid_ratio = 1, !! (n)(p2) Ratio of horizontal resolution parent/nest"
135fi
136#
137e_we="$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_we *=')"
138e_sn="$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_sn *=')"
139#
140dx="$(more ${simu_folder}/namelist.input | grep -e '[^!]*dx *=' | awk '{print $3}' | sed s+','+''+g)"
141dy="$(more ${simu_folder}/namelist.input | grep -e '[^!]*dy *=' | awk '{print $3}' | sed s+','+''+g)"
142
143
144#
145# READ INFO NEEDED FOR COMPILATION
146#
147nx=$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_we *=' | awk '{print $3}' | sed s+','+''+g)
148ny=$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_sn *=' | awk '{print $3}' | sed s+','+''+g)
149nz=$(more ${simu_folder}/namelist.input | grep -e '[^!]*e_vert *=' | awk '{print $3}' | sed s+','+''+g)
150nest=$(more ${simu_folder}/namelist.input | grep -e '[^!]*max_dom *=' | awk '{print $3}' | sed s+','+''+g)
151  if [[ "${nest}" = "" ]]
152  then
153     nest='1'
154  fi
155  numcallphys=$(ls callphys*def | wc -l)
156  if [[ ${numcallphys} -lt ${nest} ]]
157  then
158        echo '**********'
159        echo You should have ${nest} callphys.def' file(s)' !!
160        exit
161  fi
162tracers=$(more ${simu_folder}/namelist.input | grep mars | awk '{print $3}' | sed s+','+''+g)
163  case ${tracers} in
164      0) tracers='1' ;;
165      1) tracers='2' ;;
166     11) tracers='5' ;;
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        if [[ ${newphys} -eq 0 ]]
402        then
403          cd ${main_folder}'/LMDZ.MARS/myGCM'
404        else
405          cd ${main_folder}'/LMDZ.MARS.new/myGCM'
406        fi
407         #echo '(during the run, you might like to check domain settings in '${work_folder}'/WPS)'
408        echo ${daygcm} | ./launch_gcm
409        #
410        # prepare files for WPS
411        #
412        cd ${work_folder}
413        if [[ -f ${work_folder}/PREP_MARS/create_readmeteo.exe && -f ${work_folder}/PREP_MARS/readmeteo.exe ]]
414        then
415              cd ${work_folder}/PREP_MARS/ 
416                ./compile_and_exec
417              #echo 1 | ./create_readmeteo.exe
418              #./readmeteo.exe < readmeteo.def
419        else
420              echo please compile the PREP_MARS utilities in ${work_folder}
421              exit
422        fi
423fi     
424
425###################################
426# 2. RUN WRF PREPROCESSING SYSTEM #
427###################################
428if [ ${wpsstep} -eq 1 ]
429then
430 echo '*****************************************'
431 echo '**** Step 2: Perform WPS interpolations *'
432 echo '*****************************************'
433        if [[ -f ${work_folder}/WPS/geogrid.exe && -f ${work_folder}/WPS/metgrid.exe ]]
434        then
435              \rm -rf ${simu_folder}/met_em 2> /dev/null
436              mkdir ${simu_folder}/met_em
437              cd ${work_folder}/WPS/
438              \rm -rf ${work_folder}/WPS/WRFFEED/current 2> /dev/null
439              mkdir ${work_folder}/WPS/WRFFEED/current
440              ln -sf ${simu_folder}/namelist.wps ${work_folder}/WPS/namelist.wps
441              #mv namelist.wps namelist.wps.tmp
442              #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
443              ./geogrid.exe
444              ./metgrid.exe
445              #mv namelist.wps ${simu_folder}
446              #mv namelist.wps.tmp namelist.wps 
447              namedata=$(date +simu_%d%h%Y_%H%M)
448              mv ${work_folder}/WPS/WRFFEED/current ${work_folder}'/WPS/WRFFEED/'${namedata}
449              echo met_em files in $namedata
450              cd ${simu_folder}/met_em
451              ln -sf ${work_folder}/WPS/WRFFEED/${namedata}/* .
452              cd ${simu_folder}
453        else
454              echo please compile the WPS utilities in ${work_folder}
455              exit
456        fi
457fi     
458
459###################
460# 3. RUN REAL.EXE #
461###################
462if [ ${realstep} -eq 1 ]
463then
464 echo '*******************************'
465 echo '**** Step 3: Execute real.exe *'
466 echo '*******************************'
467        cd ${simu_folder}
468        if [[ ! -d met_em ]]
469        then
470                ls
471                echo "PB: no met_em files:"
472                echo "mkdir met_em folder then link met_em** files !"
473                exit
474        fi
475        cd ${simu_folder}/met_em
476        ln -sf ${simu_folder}/namelist.input .
477        ln -sf ${simu_folder}/real.exe .
478        rm -rf ${simu_folder}/met_em/wrfbdy* 2> /dev/null
479        rm -rf ${simu_folder}/met_em/wrfinput* 2> /dev/null
480        if [[ ${compilo} -eq 3 ]]
481        then
482                rm -rf ${simu_folder}/met_em/rsl.* 2> /dev/null
483                echo "check in "${simu_folder}"/met_em/rsl.out.0000"
484                ./real.exe
485                tail -n 4 ${simu_folder}"/met_em/rsl.out.0000"
486        else
487                rm -rf ${simu_folder}/met_em/log* 2> /dev/null
488                echo "check in "${simu_folder}"/met_em/log_real"
489                real.exe > log_real
490                tail -n 4 ${simu_folder}"/met_em/log_real"
491        fi
492        if [[ -f ${simu_folder}/met_em/wrfinput_d01 && -f ${simu_folder}/met_em/wrfbdy_d01 ]]
493        then
494                echo ok... link ini and bdy conditions
495                cd ${simu_folder}
496                ln -sf ${simu_folder}/met_em/wrf*_d0* .
497        else
498                echo mmm... there was a problem, see log files in met_em
499                exit
500        fi
501fi
502
503##################
504# 4. RUN WRF.EXE #
505##################
506if [ ${wrfstep} -eq 1 ]
507then
508 xeyes &
509 echo '******************************'
510 echo '**** Step 4: Execute wrf.exe *'
511 echo '******************************'
512        cd ${simu_folder}
513        rm -rf ${simu_folder}/wrfout*
514        if [[ ${compilo} -eq 3 ]]
515        then
516                rm -rf ${simu_folder}/rsl.* 2> /dev/null
517#                ${WHERE_MPI}/mpirun -host smith -np ${numproc} wrf.exe < /dev/null &
518                ${WHERE_MPI}/mpirun -np ${numproc} wrf.exe < /dev/null &
519        else
520                rm -rf ${simu_folder}/log* 2> /dev/null
521                nohup wrf.exe > log_wrf &
522        fi
523echo OK ! Simulation should be running now !
524echo Check with the command: "ps -e -o '%u %p %C %x %c' | grep wrf.exe"
525echo '******************************'
526echo '**** End.'
527
528fi
529exit
530
531
532
Note: See TracBrowser for help on using the repository browser.