source: trunk/MESOSCALE/LMD_MM_MARS/SIMU/runmeso @ 138

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

MESOSCALE: changements mineurs sur scripts recuperes de ciclad et gnome

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