source: trunk/mesoscale/LMD_MM_MARS/makemeso @ 13

Last change on this file since 13 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: 20.0 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#               November  09 #
14##############################
15
16#############################
17# Use:   
18#
19# makemeso                   ## basic use (real configuration)
20#
21# makemeso -d                ## no compilation, just check the name of the compile folder
22#
23# makemeso -c real           ## real-case mode [default]
24# makemeso -c convection     ## idealized mode: convective cell
25#
26# makemeso < last            ## basic use + skip questions [! script must have been executed at least once]
27# makemeso -r < last         ## basic use + skip questions + only known config
28# makemeso -nr < last        ## basic use + skip questions + only known config + no LMD phys recompile
29#
30# makemeso -j                ## just compile the LMD physics
31#
32# makemeso -g                ## debug mode
33#
34# makemeso -h                ## display options
35#
36#############################
37
38
39# todo: netcdf support
40
41
42##############################################################################################
43##############################################################################################
44##############################################################################################
45##############################################################################################
46
47donotcompile=0
48donotallow=0
49config='real'
50donotcompilephys=0
51justphys=0
52debug=0
53while getopts "drc:njhg" options; do
54  case $options in
55   d ) donotcompile=1;;     ## just to check the compile folder
56   r ) donotallow=1;;       ## allow only known config (useful with 'makemeso < last')
57   c ) config="${OPTARG}";; ## idealized cases
58   n ) donotcompilephys=1;; ## do not recompile physics
59   j ) justphys=1;;         ## just compile LMD physics
60   g ) debug=1;;            ## debug mode
61   h ) echo "
62# Use:   
63#
64# makemeso                   ## basic use (real configuration)
65#
66# makemeso -d                ## no compilation, just check the name of the compile folder
67#
68# makemeso -c real           ## real-case mode [default]
69# makemeso -c convection     ## idealized mode: convective cell
70#
71# makemeso < last            ## basic use + skip questions [! script must have been executed at least once]
72# makemeso -r < last         ## basic use + skip questions + only known config
73# makemeso -nr < last        ## basic use + skip questions + only known config + no LMD phys recompile
74#
75# makemeso -j                ## just compile the LMD physics
76#
77# makemeso -g                ## debug mode
78#
79# makemeso -h                ## display options
80" ; exit ;;
81  esac
82done   
83
84#--------------
85# talk w/ user
86#--------------
87  echo '****************************************'
88  echo ' LMD Mesoscale Model Compiler. Welcome.'
89  echo '****************************************'
90  # computer
91  uname -a | grep x86_64 > /dev/null
92  if [[ "$?" == 0 ]]
93  then
94    machine='64'
95  else
96    machine='32'
97  fi
98  # compiler
99  echo "Supported compiler options are "
100  echo "       <1> pgf90"
101  echo "       <2> g95"
102  echo "       <3> pgf90 + mpi"
103  echo "       <4> ifort"
104  echo "       <5> ifort + mpi"
105  echo "       <7> xlf + mpi (IBM AIX)"
106  echo "Your choice ?" ; read reply
107  case ${reply} in
108    1) compilo='pgf' ; numproc=1 ;;
109    2) compilo='g95' ; numproc=1 ;;
110    3) compilo='mpi'
111       if [[ "${WHERE_MPI}" = "" ]]
112       then
113         echo Please initialize the variable WHERE_MPI in your environnement
114         exit
115       fi
116       echo How many processors ? 1, 2, 4, 6, 8, 12, 16 ; read numproc ;;
117    4) compilo='ifort' ; numproc=1 ;;
118    5) compilo='mpifort' ; echo How many processors ? 1, 2, 4, 6, 8, 12, 16 ; read numproc ;;
119    7) compilo='mpixlf' ; echo How many processors ? 1, 2, 4, 6, 8, 12, 16 ; read numproc ;;
120### for tests
12199) compilo='gnu' ; numproc=1 ;;
122    *) echo not supported by this script ; exit ;;
123  esac
124  # dimensions
125  if [ ${donotcompile} -eq 0 ]
126  then   
127  echo Grid points in longitude ? ; read lon
128  echo Grid points in latitude ? ; read lat
129  echo Number of vertical levels ? ; read level
130  fi
131  echo Number of domains ? ; read dom
132
133###PB lecture dom si < last
134
135    case ${dom} in
136       1) single='_single' ;;
137       *) single='_nest' ;;
138    esac
139      if [ "${compilo}" = "mpi" -o "${compilo}" = "mpifort" -o "${compilo}" = "mpixlf" ]
140      then
141           single=''
142      fi
143
144testflag=''
145####
146#testflag='_test'
147####
148
149    conf_wrf="${compilo}_${machine}${single}${testflag}"
150    \rm what_folder 2> /dev/null
151    echo ${conf_wrf} > what_folder
152         if [ ${donotcompile} -eq 1 ]
153         then
154            #\rm what_folder 2> /dev/null
155            #echo '**********************'
156            #echo '*** Your folder is ...'
157            #echo '**********************'
158            #echo ${conf_wrf} | tee what_folder
159            #cat what_folder
160            #echo ${conf_wrf} > what_folder
161            #echo ${reply} > what_compilo
162            #echo ${numproc} > what_numproc
163            exit
164         fi
165  echo Number of tracers ? ; read tra
166         if [ ${tra} -eq 0 ]
167         then
168            tra=1       
169         fi
170  # folder
171  mkdir ${conf_wrf} 2> /dev/null
172  if [[ "$?" == 0 ]]
173  then
174    echo new folder ... link sources
175    ./copy_model
176    mv WRFV2 ${conf_wrf}/
177    cd ${conf_wrf}/WRFV2
178    cd Registry ; Registry.bash ; cd ..
179  else
180    cd ${conf_wrf}/WRFV2
181    echo Did you modify anything in the Registry or clean ? y for yes, any key for no ; read answer
182    case ${answer} in
183      y) cd Registry ; mv Registry Registry.bak ; Registry.bash ; cd .. ;;
184      *) answer='no' ;;
185    esac
186  fi
187  # summary
188  echo '**********************'
189  echo '*** Your folder is ...'
190  echo '**********************'
191  echo ${conf_wrf}
192  echo '**********************'
193  echo '****************************************'
194  echo so ...
195  echo your computer is ${machine} bits
196  echo ${compilo} is your compiler
197       if [[ "${compilo}" = "mpi" ]]
198       then
199         echo MPICH is in ${WHERE_MPI}
200       fi
201  echo you will use ${numproc} processors
202  echo you have ${lon} x points
203  echo '         '${lat} y points
204  echo '         '${level} z points
205  echo '         '${dom} domains
206  echo '         '${tra} tracers
207  echo '****************************************'
208  # save answer
209  \rm last 2> /dev/null
210  touch last
211  echo ${reply} >> last
212     if [ "${compilo}" = "mpi" -o "${compilo}" = "mpifort" -o "${compilo}" = "mpixlf" ]
213     then
214     echo ${numproc} >> last
215     fi
216  echo ${lon} >> last
217  echo ${lat} >> last
218  echo ${level} >> last
219  echo ${dom} >> last
220  echo ${tra} >> last
221  echo ${answer} >> last
222
223
224#------------
225# log files
226#------------
227  \rm log_compile 2> /dev/null
228  \rm log_error 2> /dev/null
229
230#-----------------
231# configure WRF
232#-----------------
233  mv configure.wrf configure.wrf.bak 2> /dev/null
234  ########################
235  case ${conf_wrf} in
236#######TEST TEST
237                     # GFORTRAN, 64 bits, no nesting     
238     gnu_64_single)    cd arch ; ln -sf ../configure.defaults.gfortran64 configure.defaults ; cd ..
239                       echo 15 | configure > log_compile 2> log_error
240                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf 
241                       sed s+"-L../mars_lmd/libo -llmd"+"-L../mars_lmd/libo -llmd $NETCDF/lib/libnetcdf.a"+g configure.wrf > yeah ; mv -f yeah configure.wrf ;;
242#######TEST TEST
243                     # PGF90, 32 bits, no nesting
244     pgf_32_single)    echo 1 | configure > log_compile 2> log_error
245                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
246                     # PGF90, 32 bits, nesting
247     pgf_32_nest)      echo 2 | configure > log_compile 2> log_error
248                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
249                     # PGF90, 64 bits, no nesting
250     pgf_64_single)    echo 1 | configure > log_compile 2> log_error
251                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
252                     # PGF90, 64 bits, nesting
253     pgf_64_nest)      cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
254                       echo 4 | configure > log_compile 2> log_error
255                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
256                     # G95, 32 bits, no nesting
257     g95_32_single)    echo 13 | configure > log_compile 2> log_error
258                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
259#
260#
261# TEST TEST: you also need to a modified configure.defaults (add x86_64 next to g95 in the header comment)
262#
263#
264                     # G95, 64 bits, no nesting
265     g95_64_single)    echo 14 | configure > log_compile 2> log_error
266                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
267                       sed s+"=       g95"+"=       /home/physastro/aspiga/mysoft/g95/g95-install/bin/x86_64-unknown-linux-gnu-g95"+g configure.wrf > yeah ; mv -f yeah configure.wrf;;
268#
269#
270# TEST TEST
271#
272#
273                     # IFORT, 64 bits, no nesting
274     ifort_64_single)  echo 5 | configure > log_compile 2> log_error
275                       sed s+"-DIFORT_KLUDGE"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
276                         ## !!! NETCDF must be defined
277                         sed s+"lio_grib_share"+"lio_grib_share -L../mars_lmd/libo -llmd $NETCDF/lib/libnetcdf.a"+g configure.wrf > yeah
278                         mv -f yeah configure.wrf ;;
279     mpifort_64)     # MPI+IFORT, 64 bits, no nesting / nesting
280                       echo 9 | configure > log_compile 2> log_error
281                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
282                       sed s+"-f90=ifort"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
283                       sed s+"-cc=icc"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
284                       sed s+"-DIFORT_KLUDGE"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
285                       sed s+"O3"+"O2"+g configure.wrf > yeah ; mv -f yeah configure.wrf
286                                        #sed s+"O3"+"O0"+g configure.wrf > yeah ; mv -f yeah configure.wrf  ### pour compilation rapide
287                                        #-w -ftz -align all -fno-alias -fp-model precise >>> options indiquees dans WRF3
288                                        #http://software.intel.com/en-us/articles/performance-tools-for-software-developers-building-wrf-with-the-intel-compilers/
289                            #### NB: RSL is replaced by RSL_LITE, better memory capacity, less seg fault
290                            sed s+"../external/RSL/RSL"+"../external/RSL_LITE"+g configure.wrf > yeah ; mv -f yeah configure.wrf
291                            sed s+"-DWRF_RSL_IO"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
292                            sed s+"-DRSL"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
293                            sed s+"librsl.a"+"librsl_lite.a"+g configure.wrf > yeah ; mv -f yeah configure.wrf
294                            sed s+"../external/RSL/gen"+"../external/RSL_LITE/gen"+g configure.wrf > yeah ; mv -f yeah configure.wrf
295                            sed s+"../external/RSL/module"+"../external/RSL_LITE/module"+g configure.wrf > yeah ; mv -f yeah configure.wrf
296                            sed s+"-lrsl"+"-lrsl_lite"+g configure.wrf > yeah ; mv -f yeah configure.wrf
297                            sed s+"linux"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
298                         ### necessary even if mpi-selector is used (no need in makegcm though)
299                         sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g > yeah ; mv -f yeah configure.wrf
300                         sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g configure.wrf > yeah ; mv -f yeah configure.wrf
301                         ## !!! NETCDF must be defined
302                         sed s+"-L../mars_lmd/libo -llmd"+"-L../mars_lmd/libo -llmd $NETCDF/lib/libnetcdf.a"+g configure.wrf > yeah
303                         mv -f yeah configure.wrf ;;
304                     # MPICH, 64 bits, no nesting / nesting
305     mpi_64)           cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
306                       echo 3 | configure > log_compile 2> log_error
307                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
308                       sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g | sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g > yeah
309                                #| sed s+"fastsse"+"fast"+g > yeah
310                       mv -f yeah configure.wrf ;;
311                     # MPICH, 64 bits, OK with periodic BC but no positive definite
312     mpi_64_test)      cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
313                       echo 2 | configure > log_compile 2> log_error
314                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
315                       sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g | sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g > yeah
316                       mv -f yeah configure.wrf ;;
317                     # XLF+MPICH on AIX machine (64 bits) with nesting, NB: the 32bits notice is not to be considered
318     mpixlf_32)        cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
319                       echo 3 | configure > log_compile 2> log_error
320                       sed -f mars.sed configure.wrf > yeah
321                       mv -f yeah configure.wrf ;;
322                     # ANYTHING ELSE
323     *)                echo NO PRESETS ...
324                       if [ ${donotallow} -eq 0 ] 
325                       then
326                         configure
327                       else
328                         # problem when an input file is used
329                         echo 'please cd to '$PWD' and type ./configure' 
330                         exit   
331                       fi ;;
332  esac
333  ########################
334
335
336  if [ ${debug} -ne 0 ]   # not working for xlf!
337  then
338    echo 'DEBUG DEBUG DEBUG DEBUG'
339    sed s+"#-g"+"-g"+g configure.wrf > yeah
340    mv -f yeah configure.wrf
341  fi
342
343
344
345##################################################
346# compile physics
347##################################################
348if [ ${donotcompilephys} -eq 0 ]
349then
350
351  cd mars_lmd/
352
353  # required size
354  #----------------
355  case ${numproc} in
356    1) physx=$(expr ${lon} - 1)
357       physy=$(expr ${lat} - 1)
358       physz=$(expr ${level} - 1) ;;
359    2) physx=$(expr ${lon} - 1)
360       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 2)
361       physz=$(expr ${level} - 1) ;;
362    4) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
363       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 2)
364       physz=$(expr ${level} - 1) ;;
365    6) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
366       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 3)
367       physz=$(expr ${level} - 1) ;;
368    8) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
369       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
370       physz=$(expr ${level} - 1) ;;
371    12) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 3)
372        physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
373        physz=$(expr ${level} - 1) ;;
374    16) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 4)
375        physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
376        physz=$(expr ${level} - 1) ;;
377    *) echo not supported ; exit
378  esac
379
380  # change this if you change num_soil_layers in WRF
381  # -- default is 10
382  soilsize=10
383
384  # GCM environment variables
385  #--------------------------
386  export LMDGCM=$PWD
387  export LIBOGCM=$PWD/libo
388
389  # generate the appropriate dimphys
390  #---------------------------------
391  cd libf/phymars
392  \rm dimphys.h 2> /dev/null
393  physize=$(expr ${physx} \* ${physy})
394  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
395  head -15 dimphys.h
396  cd ../..
397
398  # prepare for nesting
399  #---------------------
400  cd libf
401  duplicate${dom} 2> /dev/null
402  cd ..
403
404  # compile physics
405  #--------------------------
406  \rm libf/grid/dimensions.h 2> /dev/null
407  \rm -rf libo/* 2> /dev/null
408  echo 1. compiling LMD physics ...
409  echo compilation info in:
410  echo $PWD/libo/log_compile_phys
411
412  if [ ${debug} -ne 0 ]
413  then
414    echo 'DEBUG DEBUG DEBUG DEBUG'
415    nohup makegcm_${compilo} -debug -t ${tra} -p mars -d ${physz} meso_testphys1d | tee libo/log_compile_phys | grep 'warnings' >> libo/log_compile_phys
416  else
417    nohup makegcm_${compilo} -t ${tra} -p mars -d ${physz} meso_testphys1d | tee libo/log_compile_phys | grep 'warnings' >> libo/log_compile_phys
418  fi
419  echo ... done
420        # clean the duplicate routines
421        cd libf
422        duplicate1 2> /dev/null
423        cd ..
424
425  # merge LMD executables in one lib
426  #--------------------------------------
427  cd libo
428  mkdir temp
429  #cp -f LINUXfastI._${physz}_t${tra}_reg/*.a temp
430  cp -f LINUX*/*.a temp
431  cd temp
432  ar x libbibio.a
433  ar x libphymars.a
434  ar x libaeronomars.a
435  \rm *.a
436  ar r liblmd.a *
437  cp -f liblmd.a ..
438  cd ..
439  \rm -r temp
440  nm liblmd.a > liblmd_content
441  # finish merge
442  cd ..
443
444  # save a copy
445  #--------------
446  cp -f libo/liblmd.a libo/liblmd.a_${lon}_${lat}_${level}_${dom}_${tra}
447  echo '****************************************'
448
449  # ok
450  #----
451  cd ..
452
453  # manage nest includes in module_lmd_driver.F
454  #----
455  cp call_meso_inifis$dom.inc call_meso_inifis.inc
456  cp call_meso_physiq$dom.inc call_meso_physiq.inc
457
458
459fi
460##################################################
461# END compile physics
462##################################################
463
464#------------------
465# compile WRF
466#------------------
467if [ ${justphys} -eq 0 ]
468then
469
470  echo 2. compiling WRF dynamical core ...
471
472  if [[ ! ( -f "call_meso_physiq.inc" ) ]]
473  then
474   echo 'did you compile the physics ? no call_meso_physiq.inc !'
475   exit
476  fi
477
478  # be sure to compile with the most recent physics
479  touch phys/module_lmd_driver.F
480
481  # talk to user
482  echo '>>> YOUR CONFIG IS : '${config}
483  echo '>>> compiling ... this may be long ... <<<'
484  echo check progress in:
485  echo $PWD/log_compile
486  echo check possible errors in:
487  echo $PWD/log_error
488 
489  # compile ...
490  case ${config} in
491    'real')         compile em_real > log_compile 2> log_error
492                    # save executables 
493                    cd main
494                      if [[ -f wrf.exe ]]
495                      then
496                        echo 'Looks good ! wrf.exe is here...'
497                      fi
498                    cp -f real.exe ../../real_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
499                    cp -f wrf.exe ../../wrf_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
500                    cd ..  ;;
501    'convection')   #mkdir 'test/em_quarter_ss' 2> /dev/null
502                    compile em_quarter_ss > log_compile 2> log_error
503                    # save executables 
504                    cd main
505                      if [[ -f wrf.exe ]]
506                      then
507                        echo 'Looks good ! wrf.exe is here...'
508                      fi
509                    cp -f ideal.exe ../../ideal_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
510                    cp -f wrf.exe ../../wrf_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
511                    cd ..  ;;
512    *)              echo not supported please use ; echo real convection ; exit ;;
513  esac
514  echo '*******last lines from log_error*********'
515  tail -n 20 log_error
516fi
517
518  # the end
519  echo '****************************************'
520  echo 'done.'
521  echo '****************************************'
522  cp last ../makemeso_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}
523  mv last ../../
524
525  # add here specific messages
526  if [[ "${dom}" != "1" ]]
527  then
528  nest=$(expr ${lon} + 4)
529  echo NB: in namelist.input, please set:
530  echo '
531  max_dom = '$dom'
532  s_we    = 1,1,
533  e_we    = '$lon','$nest',
534  s_sn    = 1,1,
535  e_sn    = '$lat','$nest',
536  s_vert  = 1,1,
537  e_vert  = '$level','$level','
538  fi
539
Note: See TracBrowser for help on using the repository browser.