source: trunk/mesoscale/LMD_MM_MARS/makemeso @ 24

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

spiga:mineur diverses notes et tests g95 64bits

  • Property svn:executable set to *
File size: 20.2 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                     # G95, 64 bits, no nesting  ### we modify configure.defaults to add x86_64 next to g95 in the header comment
260     g95_64_single)    cd arch ; sed s/"PC Linux i486 i586 i686, g95 compiler"/"PC Linux i486 i586 i686 x86_64, g95 compiler"/g configure.defaults > yeahyeahyeah ; rm configure.defaults ; mv yeahyeahyeah configure.defaults ; cd ..
261                       echo 14 | configure > log_compile 2> log_error
262                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
263                       #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;;
264                     # IFORT, 64 bits, no nesting
265     ifort_64_single)  echo 5 | configure > log_compile 2> log_error
266                       sed s+"-DIFORT_KLUDGE"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
267                         ## !!! NETCDF must be defined
268                         sed s+"lio_grib_share"+"lio_grib_share -L../mars_lmd/libo -llmd $NETCDF/lib/libnetcdf.a"+g configure.wrf > yeah
269                         mv -f yeah configure.wrf ;;
270     mpifort_64)     # MPI+IFORT, 64 bits, no nesting / nesting
271                       echo 9 | configure > log_compile 2> log_error
272                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
273                       sed s+"-f90=ifort"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
274                       sed s+"-cc=icc"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
275                       sed s+"-DIFORT_KLUDGE"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
276                       sed s+"O3"+"O2"+g configure.wrf > yeah ; mv -f yeah configure.wrf
277                                        #sed s+"O3"+"O0"+g configure.wrf > yeah ; mv -f yeah configure.wrf  ### pour compilation rapide
278                                        #-w -ftz -align all -fno-alias -fp-model precise >>> options indiquees dans WRF3
279                                        #http://software.intel.com/en-us/articles/performance-tools-for-software-developers-building-wrf-with-the-intel-compilers/
280                            #### NB: RSL is replaced by RSL_LITE, better memory capacity, less seg fault
281                            sed s+"../external/RSL/RSL"+"../external/RSL_LITE"+g configure.wrf > yeah ; mv -f yeah configure.wrf
282                            sed s+"-DWRF_RSL_IO"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
283                            sed s+"-DRSL"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
284                            sed s+"librsl.a"+"librsl_lite.a"+g configure.wrf > yeah ; mv -f yeah configure.wrf
285                            sed s+"../external/RSL/gen"+"../external/RSL_LITE/gen"+g configure.wrf > yeah ; mv -f yeah configure.wrf
286                            sed s+"../external/RSL/module"+"../external/RSL_LITE/module"+g configure.wrf > yeah ; mv -f yeah configure.wrf
287                            sed s+"-lrsl"+"-lrsl_lite"+g configure.wrf > yeah ; mv -f yeah configure.wrf
288                            sed s+"linux"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
289                         ### necessary even if mpi-selector is used (no need in makegcm though)
290                         sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g > yeah ; mv -f yeah configure.wrf
291                         sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g configure.wrf > yeah ; mv -f yeah configure.wrf
292                         ## !!! NETCDF must be defined
293                         sed s+"-L../mars_lmd/libo -llmd"+"-L../mars_lmd/libo -llmd $NETCDF/lib/libnetcdf.a"+g configure.wrf > yeah
294                         mv -f yeah configure.wrf ;;
295                     # MPICH, 64 bits, no nesting / nesting
296     mpi_64)           cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
297                       echo 3 | configure > log_compile 2> log_error
298                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
299                       sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g | sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g > yeah
300                                #| sed s+"fastsse"+"fast"+g > yeah
301                       mv -f yeah configure.wrf ;;
302                     # MPICH, 64 bits, OK with periodic BC but no positive definite
303     mpi_64_test)      cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
304                       echo 2 | configure > log_compile 2> log_error
305                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
306                       sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g | sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g > yeah
307                       mv -f yeah configure.wrf ;;
308                     # XLF+MPICH on AIX machine (64 bits) with nesting, NB: the 32bits notice is not to be considered
309     mpixlf_32)        cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
310                       echo 3 | configure > log_compile 2> log_error
311                       sed -f mars.sed configure.wrf > yeah
312                       mv -f yeah configure.wrf ;;
313                     # ANYTHING ELSE
314     *)                echo NO PRESETS ...
315                       if [ ${donotallow} -eq 0 ] 
316                       then
317                         configure
318                       else
319                         # problem when an input file is used
320                         echo 'please cd to '$PWD' and type ./configure' 
321                         exit   
322                       fi ;;
323  esac
324  ########################
325
326
327  if [ ${debug} -ne 0 ]   # not working for xlf!
328  then
329    echo 'DEBUG DEBUG DEBUG DEBUG'
330    sed s+"#-g"+"-g"+g configure.wrf > yeah
331    mv -f yeah configure.wrf
332  fi
333
334
335
336##################################################
337# compile physics
338##################################################
339if [ ${donotcompilephys} -eq 0 ]
340then
341
342  cd mars_lmd/
343
344  # required size
345  #----------------
346  case ${numproc} in
347    1) physx=$(expr ${lon} - 1)
348       physy=$(expr ${lat} - 1)
349       physz=$(expr ${level} - 1) ;;
350    2) physx=$(expr ${lon} - 1)
351       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 2)
352       physz=$(expr ${level} - 1) ;;
353    4) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
354       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 2)
355       physz=$(expr ${level} - 1) ;;
356    6) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
357       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 3)
358       physz=$(expr ${level} - 1) ;;
359    8) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
360       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
361       physz=$(expr ${level} - 1) ;;
362    12) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 3)
363        physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
364        physz=$(expr ${level} - 1) ;;
365    16) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 4)
366        physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
367        physz=$(expr ${level} - 1) ;;
368    *) echo not supported ; exit
369  esac
370
371  # change this if you change num_soil_layers in WRF
372  # -- default is 10
373  soilsize=10
374
375  # GCM environment variables
376  #--------------------------
377  export LMDGCM=$PWD
378  export LIBOGCM=$PWD/libo
379
380  # generate the appropriate dimphys
381  #---------------------------------
382  cd libf/phymars
383  \rm dimphys.h 2> /dev/null
384  physize=$(expr ${physx} \* ${physy})
385  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
386  head -15 dimphys.h
387  cd ../..
388
389  # prepare for nesting
390  #---------------------
391  cd libf
392  duplicate${dom} 2> /dev/null
393  cd ..
394
395  # compile physics
396  #--------------------------
397  \rm libf/grid/dimensions.h 2> /dev/null
398  \rm -rf libo/* 2> /dev/null
399  echo 1. compiling LMD physics ...
400  echo compilation info in:
401  echo $PWD/libo/log_compile_phys
402
403  if [ ${debug} -ne 0 ]
404  then
405    echo 'DEBUG DEBUG DEBUG DEBUG'
406    nohup makegcm_${compilo} -debug -t ${tra} -p mars -d ${physz} meso_testphys1d | tee libo/log_compile_phys | grep 'warnings' >> libo/log_compile_phys
407  else
408    nohup makegcm_${compilo} -t ${tra} -p mars -d ${physz} meso_testphys1d | tee libo/log_compile_phys | grep 'warnings' >> libo/log_compile_phys
409  fi
410  echo ... done
411        # clean the duplicate routines
412        cd libf
413        duplicate1 2> /dev/null
414        cd ..
415
416  # merge LMD executables in one lib
417  #--------------------------------------
418  cd libo
419  mkdir temp
420  #cp -f LINUXfastI._${physz}_t${tra}_reg/*.a temp
421  cp -f LINUX*/*.a temp
422  cd temp
423  ar x libbibio.a
424  ar x libphymars.a
425  ar x libaeronomars.a
426  \rm *.a
427  ar r liblmd.a *
428  cp -f liblmd.a ..
429  cd ..
430  \rm -r temp
431  nm liblmd.a > liblmd_content
432  # finish merge
433  cd ..
434
435  # save a copy
436  #--------------
437  cp -f libo/liblmd.a libo/liblmd.a_${lon}_${lat}_${level}_${dom}_${tra}
438  echo '****************************************'
439
440  # ok
441  #----
442  cd ..
443
444  # manage nest includes in module_lmd_driver.F
445  #----
446  cp call_meso_inifis$dom.inc call_meso_inifis.inc
447  cp call_meso_physiq$dom.inc call_meso_physiq.inc
448
449
450fi
451##################################################
452# END compile physics
453##################################################
454
455#------------------
456# compile WRF
457#------------------
458if [ ${justphys} -eq 0 ]
459then
460
461  echo 2. compiling WRF dynamical core ...
462
463  if [[ ! ( -f "call_meso_physiq.inc" ) ]]
464  then
465   echo 'did you compile the physics ? no call_meso_physiq.inc !'
466   exit
467  fi
468
469  # be sure to compile with the most recent physics
470  touch phys/module_lmd_driver.F
471
472  # talk to user
473  echo '>>> YOUR CONFIG IS : '${config}
474  echo '>>> compiling ... this may be long ... <<<'
475  echo check progress in:
476  echo $PWD/log_compile
477  echo check possible errors in:
478  echo $PWD/log_error
479 
480  # compile ...
481  case ${config} in
482    'real')         compile em_real > log_compile 2> log_error
483                    # save executables 
484                    cd main
485                      if [[ -f wrf.exe ]]
486                      then
487                        echo 'Looks good ! wrf.exe is here...'
488                      fi
489                    cp -f real.exe ../../real_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
490                    cp -f wrf.exe ../../wrf_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
491                    cd ..  ;;
492    'convection')   #mkdir 'test/em_quarter_ss' 2> /dev/null
493                    compile em_quarter_ss > log_compile 2> log_error
494                    # save executables 
495                    cd main
496                      if [[ -f wrf.exe ]]
497                      then
498                        echo 'Looks good ! wrf.exe is here...'
499                      fi
500                    cp -f ideal.exe ../../ideal_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
501                    cp -f wrf.exe ../../wrf_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
502                    cd ..  ;;
503    *)              echo not supported please use ; echo real convection ; exit ;;
504  esac
505  echo '*******last lines from log_error*********'
506  tail -n 20 log_error
507fi
508
509  # the end
510  echo '****************************************'
511  echo 'done.'
512  echo '****************************************'
513  cp last ../makemeso_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}
514  mv last ../../
515
516  # add here specific messages
517  if [[ "${dom}" != "1" ]]
518  then
519  nest=$(expr ${lon} + 4)
520  echo NB: in namelist.input, please set:
521  echo '
522  max_dom = '$dom'
523  s_we    = 1,1,
524  e_we    = '$lon','$nest',
525  s_sn    = 1,1,
526  e_sn    = '$lat','$nest',
527  s_vert  = 1,1,
528  e_vert  = '$level','$level','
529  fi
530
Note: See TracBrowser for help on using the repository browser.