source: trunk/MESOSCALE_DEV/WORK/notes/makemeso_bak2 @ 402

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

spiga@svn-planeto:ajoute le modele meso-echelle martien

  • Property svn:executable set to *
File size: 14.6 KB
Line 
1#! /bin/bash
2
3
4##################################
5# makemeso allows you to compile #
6# WRF with modified LMD physics  #
7##################################
8
9##############################
10# Author: A. Spiga           #
11# New version : October 2008 #
12# Last update : January 2009 #
13##############################
14
15#############################
16# Use:   
17#
18# makemeso                   ## basic use (real configuration)
19#
20# makemeso -d                ## no compilation, just check the name of the compile folder
21#
22# makemeso -c real           ## real-case mode [default]
23# makemeso -c convection     ## idealized mode: convective cell
24#
25# makemeso < last            ## basic use + skip questions [! script must have been executed at least once]
26# makemeso -r < last         ## basic use + skip questions + only known config
27# makemeso -nr < last        ## basic use + skip questions + only known config + no LMD phys recompile
28#
29# makemeso -j                ## just compile the LMD physics
30#
31# makemeso -g                ## debug mode
32#
33# makemeso -h                ## display options
34#
35#############################
36
37
38# todo: netcdf support
39
40
41##############################################################################################
42##############################################################################################
43##############################################################################################
44##############################################################################################
45
46donotcompile=0
47donotallow=0
48config='real'
49donotcompilephys=0
50justphys=0
51debug=0
52while getopts "drc:njhg" options; do
53  case $options in
54   d ) donotcompile=1;;     ## just to check the compile folder
55   r ) donotallow=1;;       ## allow only known config (useful with 'makemeso < last')
56   c ) config="${OPTARG}";; ## idealized cases
57   n ) donotcompilephys=1;; ## do not recompile physics
58   j ) justphys=1;;         ## just compile LMD physics
59   g ) debug=1;;            ## debug mode
60   h ) echo "
61# Use:   
62#
63# makemeso                   ## basic use (real configuration)
64#
65# makemeso -d                ## no compilation, just check the name of the compile folder
66#
67# makemeso -c real           ## real-case mode [default]
68# makemeso -c convection     ## idealized mode: convective cell
69#
70# makemeso < last            ## basic use + skip questions [! script must have been executed at least once]
71# makemeso -r < last         ## basic use + skip questions + only known config
72# makemeso -nr < last        ## basic use + skip questions + only known config + no LMD phys recompile
73#
74# makemeso -j                ## just compile the LMD physics
75#
76# makemeso -g                ## debug mode
77#
78# makemeso -h                ## display options
79" ; exit ;;
80  esac
81done   
82
83#--------------
84# talk w/ user
85#--------------
86  echo '****************************************'
87  echo 'Welcome.'
88  echo '****************************************'
89  # computer
90  uname -a | grep x86_64 > /dev/null
91  if [[ "$?" == 0 ]]
92  then
93    machine='64'
94  else
95    machine='32'
96  fi
97  # compilator
98  echo '>>>' supported compiler options are 1. pgf90, 2. g95, 3. mpi+pgf90, 4. ifort - your choice ? ; read reply
99  case ${reply} in
100    1) compilo='pgf' ; numproc=1 ;;
101    2) compilo='g95' ; numproc=1 ;;
102    3) compilo='mpi'
103       if [[ "${WHERE_MPI}" = "" ]]
104       then
105         echo Please initialize the variable WHERE_MPI in your environnement
106         exit
107       fi
108       echo '>>>' how many processors ? 1, 2, 4, 6, 8, 12, 16 ; read numproc ;;
109    4) compilo='ifort' ; numproc=1 ;;
110    *) echo not supported by this script ; exit ;;
111  esac
112  # dimensions
113  if [ ${donotcompile} -eq 0 ]
114  then   
115  echo '>>>' grid points in longitude ? ; read lon
116  echo '>>>' grid points in latitude ? ; read lat
117  echo '>>>' number of vertical levels ? ; read level
118  fi
119  echo '>>>' number of domains ? ; read dom
120
121###PB lecture dom si < last
122
123    case ${dom} in
124       1) single='_single' ;;
125       *) single='_nest' ;;
126    esac
127      if [[ "${compilo}" = "mpi" ]]
128      then
129           single=''
130      fi
131      testflag=''
132####
133#testflag='_test'
134####
135    conf_wrf="${compilo}_${machine}${single}${testflag}"
136    \rm what_folder 2> /dev/null
137    echo ${conf_wrf} > what_folder
138         if [ ${donotcompile} -eq 1 ]
139         then
140            #\rm what_folder 2> /dev/null
141            #echo '**********************'
142            #echo '*** Your folder is ...'
143            #echo '**********************'
144            #echo ${conf_wrf} | tee what_folder
145            #cat what_folder
146            #echo ${conf_wrf} > what_folder
147            #echo ${reply} > what_compilo
148            #echo ${numproc} > what_numproc
149            exit
150         fi
151  echo '>>>' number of tracers ? ; read tra
152         if [ ${tra} -eq 0 ]
153         then
154            tra=1       
155         fi
156  # folder
157  mkdir ${conf_wrf} 2> /dev/null
158  if [[ "$?" == 0 ]]
159  then
160    echo new folder ... link sources
161    ./copy_model
162    mv WRFV2 ${conf_wrf}/
163    cd ${conf_wrf}/WRFV2
164    cd Registry ; Registry.bash ; cd ..
165  else
166    cd ${conf_wrf}/WRFV2
167    echo '>>>' did you modify anything in the Registry or clean ? y for yes, any key for no ; read answer
168    case ${answer} in
169      y) cd Registry ; mv Registry Registry.bak ; Registry.bash ; cd .. ;;
170      *) answer='no' ;;
171    esac
172  fi
173  # summary
174  echo '**********************'
175  echo '*** Your folder is ...'
176  echo '**********************'
177  echo ${conf_wrf}
178  echo '**********************'
179  echo '****************************************'
180  echo so ...
181  echo your computer is ${machine} bits
182  echo ${compilo} is your compiler
183       if [[ "${compilo}" = "mpi" ]]
184       then
185         echo MPICH is in ${WHERE_MPI}
186       fi
187  echo you will use ${numproc} processors
188  echo you have ${lon} x points
189  echo '         '${lat} y points
190  echo '         '${level} z points
191  echo '         '${dom} domains
192  echo '         '${tra} tracers
193  echo '****************************************'
194  # save answer
195  \rm last 2> /dev/null
196  touch last
197  echo ${reply} >> last
198     if [[ "${compilo}" = "mpi" ]]
199     then
200     echo ${numproc} >> last
201     fi
202  echo ${lon} >> last
203  echo ${lat} >> last
204  echo ${level} >> last
205  echo ${dom} >> last
206  echo ${tra} >> last
207  echo ${answer} >> last
208
209
210#------------
211# log files
212#------------
213  \rm log_compile 2> /dev/null
214  \rm log_error 2> /dev/null
215
216#-----------------
217# configure WRF
218#-----------------
219  mv configure.wrf configure.wrf.bak 2> /dev/null
220  ########################
221  case ${conf_wrf} in
222                     # PGF90, 32 bits, no nesting
223     pgf_32_single)    echo 1 | configure > log_compile 2> log_error ;;
224                     # PGF90, 32 bits, nesting
225     pgf_32_nest)      echo 2 | configure > log_compile 2> log_error ;;
226                     # PGF90, 64 bits, no nesting
227     pgf_64_single)    echo 1 | configure > log_compile 2> log_error ;;
228                     # PGF90, 64 bits, nesting
229     pgf_64_nest)      cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
230                       echo 4 | configure > log_compile 2> log_error ;;
231                     # G95, 32 bits, no nesting
232     g95_32_single)    echo 13 | configure > log_compile 2> log_error ;;
233                     # IFORT, 64 bits, no nesting
234     ifort_64_single)  echo 5 | configure > log_compile 2> log_error ;;
235                     # MPICH, 64 bits, no nesting / nesting
236     mpi_64)           cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
237                       echo 3 | configure > log_compile 2> log_error
238                       sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g | sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g > yeah
239#| sed s+"fastsse"+"fast"+g > yeah
240                       mv -f yeah configure.wrf ;;
241                     # MPICH, 64 bits, OK with periodic BC but no positive definite
242     mpi_64_test)      cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
243                       echo 2 | configure > log_compile 2> log_error
244                       sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g | sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g > yeah
245                       mv -f yeah configure.wrf ;;
246                     # ANYTHING ELSE
247     *)                echo NO PRESETS ...
248                       if [ ${donotallow} -eq 0 ] 
249                       then
250                         configure
251                       else
252                         # problem when an input file is used
253                         echo 'please cd to '$PWD' and type ./configure' 
254                         exit   
255                       fi ;;
256  esac
257  ########################
258  sed -f mars.sed configure.wrf > yeah
259  mv -f yeah configure.wrf
260
261  if [ ${debug} -ne 0 ]
262  then
263    echo 'DEBUG DEBUG DEBUG DEBUG'
264    sed s+"#-g"+"-g"+g configure.wrf > yeah
265    mv -f yeah configure.wrf
266  fi
267
268##################################################
269# compile physics
270##################################################
271if [ ${donotcompilephys} -eq 0 ]
272then
273
274  cd mars_lmd/
275
276  # required size
277  #----------------
278  case ${numproc} in
279    1) physx=$(expr ${lon} - 1)
280       physy=$(expr ${lat} - 1)
281       physz=$(expr ${level} - 1) ;;
282    2) physx=$(expr ${lon} - 1)
283       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 2)
284       physz=$(expr ${level} - 1) ;;
285    4) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
286       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 2)
287       physz=$(expr ${level} - 1) ;;
288    6) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
289       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 3)
290       physz=$(expr ${level} - 1) ;;
291    8) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
292       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
293       physz=$(expr ${level} - 1) ;;
294    12) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 3)
295        physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
296        physz=$(expr ${level} - 1) ;;
297    16) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 4)
298        physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
299        physz=$(expr ${level} - 1) ;;
300    *) echo not supported ; exit
301  esac
302
303  # change this if you change num_soil_layers in WRF
304  # -- default is 10
305  soilsize=10
306
307  # GCM environment variables
308  #--------------------------
309  export LMDGCM=$PWD
310  export LIBOGCM=$PWD/libo
311
312  # generate the appropriate dimphys
313  #---------------------------------
314  cd libf/phymars
315  \rm dimphys.h 2> /dev/null
316  physize=$(expr ${physx} \* ${physy})
317  sed s/--xsize--/${physx}/g meso_dimphys.h_ref | sed s/--ysize--/${physy}/g | sed s/--physize--/${physize}/g | sed s/--zsize--/${physz}/g | sed s/--soilsize--/${soilsize}/g > dimphys.h
318  #head -15 dimphys.h
319  cd ../..
320
321  # prepare for nesting
322  #---------------------
323  cd libf
324  duplicate${dom} 2> /dev/null
325  cd ..
326
327  # compile physics
328  #--------------------------
329  \rm libf/grid/dimensions.h 2> /dev/null
330  \rm -rf libo/* 2> /dev/null
331  echo 1. compiling LMD physics ...
332  echo compilation info in:
333  echo $PWD/libo/log_compile_phys
334  if [ ${debug} -ne 0 ]
335  then
336    echo 'DEBUG DEBUG DEBUG DEBUG'
337    nohup makegcm_${compilo} -debug -t ${tra} -p mars -d ${physz} meso_testphys1d | tee libo/log_compile_phys | grep 'warnings' >> libo/log_compile_phys
338  else
339    nohup makegcm_${compilo} -t ${tra} -p mars -d ${physz} meso_testphys1d | tee libo/log_compile_phys | grep 'warnings' >> libo/log_compile_phys
340  fi
341  echo ... done
342        # clean the duplicate routines
343        cd libf
344        duplicate1 2> /dev/null
345        cd ..
346
347  # merge LMD executables in one lib
348  #--------------------------------------
349  cd libo
350  mkdir temp
351  #cp -f LINUXfastI._${physz}_t${tra}_reg/*.a temp
352  cp -f LINUX*/*.a temp
353  cd temp
354  ar x libbibio.a
355  ar x libphymars.a
356  ar x libaeronomars.a
357  \rm *.a
358  ar r liblmd.a *
359  cp -f liblmd.a ..
360  cd ..
361  \rm -r temp
362  nm liblmd.a > liblmd_content
363  # finish merge
364  cd ..
365
366  # save a copy
367  #--------------
368  cp -f libo/liblmd.a libo/liblmd.a_${lon}_${lat}_${level}_${dom}_${tra}
369  echo '****************************************'
370
371  # ok
372  #----
373  cd ..
374
375  # manage nest includes in module_lmd_driver.F
376  #----
377  cp call_meso_inifis$dom.inc call_meso_inifis.inc
378  cp call_meso_physiq$dom.inc call_meso_physiq.inc
379
380
381fi
382##################################################
383# END compile physics
384##################################################
385
386#------------------
387# compile WRF
388#------------------
389if [ ${justphys} -eq 0 ]
390then
391
392  echo 2. compiling WRF dynamical core ...
393
394  if [[ ! ( -f "call_meso_physiq.inc" ) ]]
395  then
396   echo 'did you compile the physics ? no call_meso_physiq.inc !'
397   exit
398  fi
399
400  # be sure to compile with the most recent physics
401  touch phys/module_lmd_driver.F
402
403  # talk to user
404  echo '>>> YOUR CONFIG IS : '${config}
405  echo '>>> compiling ... this may be long ... <<<'
406  echo check progress in:
407  echo $PWD/log_compile
408  echo check possible errors in:
409  echo $PWD/log_error
410 
411  # compile ...
412  case ${config} in
413    'real')         compile em_real > log_compile 2> log_error
414                    # save executables 
415                    cd main
416                      if [[ -f wrf.exe ]]
417                      then
418                        echo 'Looks good ! wrf.exe is here...'
419                      fi
420                    cp -f real.exe ../../real_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
421                    cp -f wrf.exe ../../wrf_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
422                    cd ..  ;;
423    'convection')   #mkdir 'test/em_quarter_ss' 2> /dev/null
424                    compile em_quarter_ss > log_compile 2> log_error
425                    # save executables 
426                    cd main
427                      if [[ -f wrf.exe ]]
428                      then
429                        echo 'Looks good ! wrf.exe is here...'
430                      fi
431                    cp -f ideal.exe ../../ideal_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
432                    cp -f wrf.exe ../../wrf_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
433                    cd ..  ;;
434    *)              echo not supported please use ; echo real convection ; exit ;;
435  esac
436  echo '*******last lines from log_error*********'
437  tail -n 20 log_error
438fi
439
440  # the end
441  echo '****************************************'
442  echo 'done.'
443  echo '****************************************'
444  cp last ../makemeso_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}
445  mv last ../../
446
447  # add here specific messages
448  if [[ "${dom}" != "1" ]]
449  then
450  nest=$(expr ${lon} + 4)
451  echo NB: in namelist.input, please set:
452  echo '
453  max_dom = '$dom'
454  s_we    = 1,1,
455  e_we    = '$lon','$nest',
456  s_sn    = 1,1,
457  e_sn    = '$lat','$nest',
458  s_vert  = 1,1,
459  e_vert  = '$level','$level','
460  fi
461
Note: See TracBrowser for help on using the repository browser.