Merge pull request #22 from wirc-sjsu/develop-w21
[WRF-Fire-merge.git] / compile
blob74cf1fc74c84812f2014cd3c539c99f83f390232
1 #!/bin/csh -f
3 setenv START_OF_COMPILE "`date`"
6 cont1:
8 if ( ! -e configure.wrf ) then
9 echo ""
10 echo "You must run the 'configure' script before running the 'compile' script!"
11 echo "Exiting..."
12 echo ""
13 exit 1
14 endif
16 echo Building on `hostname` on `date`
18 #----------------------------------
19 # identify the commit where the compiled code came from
20 git log >& /dev/null
21 if ($status) then
22 set v='No git found or not a git repository, git commit version not available.'
23 else
24 set v=(git `git log | head -1` `git diff --shortstat`) >& /dev/null
25 endif
26 echo " CHARACTER (LEN=*), PARAMETER :: commit_version = '$v'" > inc/commit_decl
27 # make sure to recompile with the current inc/commit_decl
28 touch main/module_wrf_top.F
30 #----------------------------------
31 if ( ! $?WRF_KPP ) setenv WRF_KPP 0
32 if ( $WRF_KPP == 1 ) then
33 chem/KPP/compile_wkc
34 endif
36 #---------------------------------
38 set ZAP = .foofoo
39 set arglist=""
40 set prev_was_j = false
41 set count = 0
42 foreach a ( $argv )
43 @ count ++
44 if ( "$a" == "-h" ) then
45 goto hlp
46 else if ( "$a" == "all_wrfvar" || "$a" == "gen_be" ) then
47 set arglist = ( $arglist $a )
48 grep "DA_CORE=1" configure.wrf > /dev/null
49 if ( ! $status ) then
50 # If configuration file has DA_CORE=1, set WRF_DA_CORE to 1
51 setenv WRF_DA_CORE 1
52 else
53 # If the user ran the configure script without the "wrfda" option, "./compile all_wrfvar"
54 # will fail in non-obvious ways, and some executables will be created incorrectly.
55 # Let's just quit right away to avoid the hassle.
56 echo ""
57 echo "To build WRFDA, you must run the 'configure' script with the 'wrfda' option:"
58 echo " ./configure wrfda"
59 echo ""
60 echo "Exiting..."
61 echo ""
62 exit 1
63 endif
64 else if ( "$a" == "em_real" ) then
65 set arglist = ( $arglist $a )
66 set ZAP = ( main/wrf.exe main/real.exe main/ndown.exe main/tc.exe )
67 else if ( `echo $a | cut -c 1-3` == "em_" ) then
68 set arglist = ( $arglist $a )
69 set ZAP = ( main/wrf.exe main/ideal.exe )
70 else if ( "$a" == "io" ) then
71 set arglist = ( $arglist $a )
72 else if ( "$a" == "wrfplus" ) then
73 set arglist = ( $arglist $a )
74 set ZAP = ( main/wrfplus.exe )
75 setenv WRF_EM_CORE 1
76 setenv WRF_PLUS_CORE 1
77 else if ( "$a" == "wrf" ) then
78 set arglist = ( $arglist $a )
79 set ZAP = ( main/wrf.exe )
80 else if ( "$a" == "-j" ) then
81 @ JJ = $count + 1
82 setenv J "-j $argv[$JJ]"
83 set prev_was_j = true
84 else if ( "$prev_was_j" == "true" ) then
85 set prev_was_j = false
86 else if ( "$a" == "emi_conv" ) then
87 set arglist = ( $arglist $a )
88 set ZAP = ( chem/convert_emiss.exe )
89 else
90 echo "This option is not recognized: $a"
91 exit ( 1 )
92 endif
93 end
95 if ( "$arglist" == "" ) then
96 goto hlp
97 else
98 unsetenv A2DCASE
99 setenv A2DCASE `echo $arglist | grep 2d`
100 unsetenv A1DCASE
101 setenv A1DCASE `echo $arglist | grep scm`
103 if ( ! ( $?WRF_EM_CORE || $?WRF_PLUS_CORE ) ) then
104 echo 'Neither WRF_EM_CORE nor WRF_PLUS_CORE'
105 echo ' are explicitly specified in shell environment.... '
106 setenv WRF_EM_CORE 1
107 setenv WRF_COAMPS_CORE 0
108 setenv WRF_EXP_CORE 0
109 setenv WRF_PLUS_CORE 0
110 endif
112 # these settings get passed down through the environment in the
113 # calls to Make
114 if ( ! $?WRF_HYDRO ) then
115 setenv WRF_HYDRO 0
116 setenv LIB_WRF_HYDRO ""
117 else
118 if($WRF_HYDRO == 1) then
119 setenv LIB_WRF_HYDRO "-L../hydro/lib -lHYDRO"
120 else
121 setenv LIB_WRF_HYDRO ""
122 endif
123 endif
125 if ( ! $?WRF_DA_CORE ) setenv WRF_DA_CORE 0
126 if ( ! $?WRF_EM_CORE ) setenv WRF_EM_CORE 0
127 if ( ! $?WRF_COAMPS_CORE ) setenv WRF_COAMPS_CORE 0
128 if ( ! $?WRF_EXP_CORE ) setenv WRF_EXP_CORE 0
129 if ( ! $?WRF_PLUS_CORE ) setenv WRF_PLUS_CORE 0
130 if ( ! $?WRF_CHEM ) setenv WRF_CHEM 0
131 if ( ! $?WRF_DFI_RADAR ) setenv WRF_DFI_RADAR 0
132 if ( ! $?WRF_CONVERT ) then
133 if ( "$arglist" == "convert_em" ) then
134 setenv WRF_CONVERT 1
135 setenv WRF_EM_CORE 0
136 else
137 setenv WRF_CONVERT 0
138 endif
139 endif
141 # temporary - until all vestiges of NMM ifdefs are gone from WRF source
142 setenv WRF_NMM_CORE 0
143 setenv WRF_NMM_NEST 0
144 setenv HWRF 0
146 if ( ! $?DA_ARCHFLAGS ) setenv DA_ARCHFLAGS ""
148 # if ( ( $WRF_CHEM == 1 ) && ( $WRF_DA_CORE == 1 ) ) then
149 # echo " "
150 # echo "WRFDA can not be compiled with WRF_CHEM=1"
151 # echo "unset the WRF_CHEM env variable."
152 # echo " "
153 # exit
154 # endif
156 if ( ( $WRF_DA_CORE == 1 ) && ( ! -d var ) ) then
157 echo " "
158 echo "You need to download and untar the Var code, or"
159 echo "unset the WRF_DA_CORE env variable."
160 echo " "
161 exit
162 endif
164 if ( ( $WRF_CHEM == 1 ) && ( ! -d chem ) ) then
165 echo " "
166 echo "You need to download and untar the chem code, or"
167 echo "unset the WRF_CHEM env variable."
168 echo " "
169 exit
170 endif
172 set overwrite=0
175 if ($WRF_EM_CORE == 0 && ! $WRF_CONVERT == 1 ) then
176 echo "Cannot compile because both EM core is set to 0."
177 exit 2
178 endif
179 if (($WRF_EM_CORE == 1)&&($WRF_DA_CORE == 0 ) &&($WRF_CHEM == 0 )&&($WRF_CONVERT == 0)&&($WRF_PLUS_CORE == 0) ) then
180 if ( ! -f Registry/Registry ) then
181 set overwrite=1
182 else
183 head -2 Registry/Registry | tail -1 | grep EM > /dev/null
184 if ( $status ) then
185 set overwrite=1
186 else
187 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM' | grep -v 'Registry.EM.' | awk '{print $1}'`
188 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
189 if ( $em_time > $rg_time ) set overwrite=1
190 endif
191 endif
192 if ( $overwrite ) then
193 echo copying Registry/Registry.EM to Registry/Registry
194 echo '## WARNING: this file is autogenerated from Registry/Registry.EM. Changes may be lost' > Registry/Registry
195 /bin/cat Registry/Registry.EM >> Registry/Registry
196 endif
197 else if ( ($WRF_EM_CORE == 1)&&($WRF_PLUS_CORE == 1) ) then
198 if ( ! -f Registry/Registry ) then
199 set overwrite=1
200 else
201 head -2 Registry/Registry | tail -1 | grep WRFPLUS > /dev/null
202 if ( $status ) then
203 set overwrite=1
204 else
205 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.tladj' | grep -v 'Registry.tladj.' | awk '{print $1}'`
206 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
207 if ( $em_time > $rg_time ) set overwrite=1
208 endif
209 endif
210 if ( $overwrite ) then
211 echo copying Registry/Registry.tladj to Registry/Registry
212 echo '## WARNING: this file is autogenerated from Registry/Registry.tladj. Changes may be lost' > Registry/Registry
213 /bin/cat Registry/Registry.tladj >> Registry/Registry
214 endif
215 else if (($WRF_EM_CORE == 1)&&($WRF_CHEM == 1 )&&($WRF_DA_CORE == 0)) then
216 if ( ! -f Registry/Registry ) then
217 set overwrite=1
218 else
219 head -2 Registry/Registry | tail -1 | grep EM_CHEM > /dev/null
220 if ( $status ) then
221 set overwrite=1
222 else
223 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM_CHEM' | grep -v 'Registry.EM_CHEM.' | awk '{print $1}'`
224 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
225 if ( $em_time > $rg_time ) set overwrite=1
226 endif
227 endif
228 if ( $overwrite ) then
229 echo copying Registry/Registry.EM_CHEM to Registry/Registry
230 echo '## WARNING: this file is autogenerated from Registry/Registry.EM_CHEM. Changes may be lost' > Registry/Registry
231 /bin/cat Registry/Registry.EM_CHEM >> Registry/Registry
232 endif
233 else if (($WRF_EM_CORE == 1)&&($WRF_DFI_RADAR == 1 )) then
234 if ( ! -f Registry/Registry ) then
235 set overwrite=1
236 endif
237 if ( $overwrite ) then
238 echo copying Registry/Registry.EM to Registry/Registry
239 echo '## WARNING: this file is autogenerated from Registry/Registry.EM. Changes may be lost' > Registry/Registry
240 /bin/cat Registry/Registry.EM >> Registry/Registry
241 endif
242 else if (($WRF_EM_CORE == 0)&&($WRF_CONVERT == 1 )) then
243 if ( ! -f Registry/Registry ) then
244 set overwrite=1
245 else
246 head -2 Registry/Registry | tail -1 | grep EM_CONVERT > /dev/null
247 if ( $status ) then
248 set overwrite=1
249 else
250 set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM_CONVERT' | grep -v 'Registry.EM_CONVERT.' | awk '{print $1}'`
251 set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
252 if ( $em_time > $rg_time ) set overwrite=1
253 endif
254 endif
255 if ( $overwrite ) then
256 echo copying Registry/Registry.CONVERT to Registry/Registry
257 echo '## WARNING: this file is autogenerated from Registry/Registry.CONVERT. Changes may be lost' > Registry/Registry
258 /bin/cat Registry/Registry.CONVERT >> Registry/Registry
259 endif
260 else if ( $WRF_DA_CORE == 1 ) then
261 if ( ! -f Registry/Registry ) then
262 set overwrite=1
263 else
264 if ( $WRF_CHEM == 1 ) then
265 head -2 Registry/Registry | tail -1 | grep WRFCHEMVAR > /dev/null
266 else
267 head -2 Registry/Registry | tail -1 | grep WRFVAR > /dev/null
268 endif
269 if ( $status ) then
270 set overwrite=1
271 endif
272 endif
273 if ( $overwrite ) then
274 /bin/rm -f Registry/Registry.rconfig
275 /bin/cat Registry/Registry.EM_COMMON | grep '^rconfig' > Registry/Registry.rconfig
276 if ($WRF_CHEM == 1 ) then
277 echo copying Registry/Registry.wrfchemvar to Registry/Registry
278 echo '## WARNING: this file is autogenerated from Registry/Registry.wrfchemvar Registry/Registry.EM_COMMON.var. Changes may be lost' > Registry/Registry
279 /bin/cat Registry/Registry.wrfchemvar >> Registry/Registry
280 else
281 echo copying Registry/Registry.wrfvar to Registry/Registry
282 echo '## WARNING: this file is autogenerated from Registry/Registry.wrfvar Registry/Registry.EM_COMMON.var. Changes may be lost' > Registry/Registry
283 /bin/cat Registry/Registry.wrfvar >> Registry/Registry
284 endif
285 endif
287 set wrfpluspath = ( `grep "^WRFPLUSPATH" configure.wrf | cut -d"=" -f2-` )
288 if ( $wrfpluspath == "" ) then
289 setenv WRFPLUS_INC " "
290 else
291 setenv WRFPLUS_DIR $wrfpluspath
292 setenv WRFPLUS_INC "-I${wrfpluspath}/dyn_em -I${wrfpluspath}/main -I${wrfpluspath}/frame -I${wrfpluspath}/share -I${wrfpluspath}/wrftladj"
293 endif
295 setenv BUFR 1
296 set CRTM = ( `grep "\-DCRTM" configure.wrf | sed -e 's/\\//g' | sed 's/-//g' ` )
297 if ( $CRTM != "" ) then
298 echo " "
299 echo "Will compile with CRTM library"
300 echo " "
301 if ( ! $?BUFR ) then
302 echo " "
303 echo "BUFR library is needed for radiance data ingest."
304 echo "setting BUFR=1"
305 echo " "
306 setenv BUFR 1
307 endif
308 setenv CRTM_CPP "-DCRTM"
309 setenv CRTM_LIB "-L../external/crtm_2.3.0/libsrc -lCRTM"
310 setenv CRTM_SRC "-I../external/crtm_2.3.0/libsrc"
311 #setenv SFC_CRTM `grep '^SFC' configure.wrf | awk '{print $3}' | sed -e 's/\// /g' | awk '{print $NF}'`
312 #setenv ABI_CRTM `grep '^SFC' configure.wrf | sed -n 's/.*\(\-m[0-9]\{2\}\).*/\1/p'`
313 setenv CRTM 1
314 else
315 echo " "
316 echo "Compiling WRFDA without CRTM library"
317 echo " "
318 setenv CRTM_CPP " "
319 setenv CRTM_LIB " "
320 setenv CRTM_SRC " "
321 setenv CRTM 0
322 endif
323 set hdf5path = ( `grep "^HDF5PATH" configure.wrf | cut -d"=" -f2-` )
324 if ( $hdf5path == "" ) then
325 setenv HDF5_INC ""
326 unsetenv HDF5
327 else
328 echo " "
329 echo "Compiling with HDF5 libraries in:"
330 echo $hdf5path
331 echo " "
332 setenv HDF5_INC "-I${hdf5path}/include"
333 setenv HDF5 1
334 endif
335 set RTTOV = ( `grep "^RTTOVPATH" configure.wrf | cut -d"=" -f2-` )
336 if ( $RTTOV == "" ) then
337 setenv RTTOV_LIB " "
338 setenv RTTOV_SRC " "
339 unsetenv RTTOV
340 else
341 if ( $hdf5path == "" ) then
342 echo "As of version 12.1 of RTTOV, WRFDA requires HDF5 in order utilize the RTTOV library."
343 echo "RTTOV emissivity atlas files are now provided only in HDF5 format."
344 echo "Please supply an HDF5 path prior to configure or unset RTTOV."
345 exit 1
346 else
347 echo " "
348 echo "Compiling with RTTOV libraries in:"
349 echo $RTTOV
350 echo " "
351 if ( ! $?BUFR ) then
352 echo " "
353 echo "BUFR library is needed for radiance data ingest."
354 echo "setting BUFR=1"
355 echo " "
356 setenv BUFR 1
357 endif
358 if ( -e ${RTTOV}/lib/librttov12_main.a ) then
359 setenv RTTOV_LIB "-L${hdf5path}/lib -lhdf5hl_fortran -lhdf5_hl -lhdf5_fortran -lhdf5 -L${RTTOV}/lib -lrttov12_coef_io -lrttov12_emis_atlas -lrttov12_main -lrttov12_hdf"
360 else
361 echo "Can not find a compatible RTTOV library! Please ensure that your RTTOV build was successful,"
362 echo "your 'RTTOV' environment variable is set correctly, and you are using a supported version of RTTOV."
363 echo "Current supported version(s): 12.1"
365 exit 1
366 endif
367 setenv RTTOV_SRC "-I${RTTOV}/include -I${RTTOV}/mod"
368 endif
369 endif
371 if ( $?CLOUD_CV ) then
372 setenv CLOUD_CV_CPP "-DCLOUD_CV"
373 else
374 setenv CLOUD_CV_CPP " "
375 endif
376 if ( $?BUFR ) then
377 setenv BUFR_CPP "-DBUFR"
378 setenv BUFR_LIB "-L../external/bufr -lbufr"
379 else
380 setenv BUFR_CPP " "
381 setenv BUFR_LIB " "
382 endif
383 if ( $?WAVELET ) then
384 setenv WAVELET_LIB "../external/wavelet/libWavelet.a ../external/wavelet/lib_wavelet.a"
385 else
386 setenv WAVELET_LIB " "
387 endif
388 if ( $?MADIS ) then
389 setenv MADIS_CPP "-DMADIS"
390 setenv MADIS_STATIC ${MADIS}/static
391 setenv MADIS_LIB "-L${MADIS} -lmadis"
392 else
393 setenv MADIS_CPP " "
394 setenv MADIS_LIB " "
395 endif
396 setenv DA_ARCHFLAGS "${BUFR_CPP} ${MADIS_CPP} -DFFTPACK -DNORESHAPE"
397 endif
399 echo " "
400 echo "============================================================================================== "
401 echo " "
402 cat inc/version_decl | cut -d"'" -f2 | head -1
403 cat inc/commit_decl | cut -d"'" -f2
404 echo " "
405 echo -n "Compiling: "
406 if ( $WRF_DA_CORE ) echo -n "WRF_DA_CORE "
407 if ( $WRF_EM_CORE ) echo -n "WRF_EM_CORE "
408 if ( $WRF_COAMPS_CORE ) echo -n "WRF_COAMPS_CORE "
409 if ( $WRF_EXP_CORE ) echo -n "WRF_EXP_CORE "
410 echo " "
411 env | grep LARGE
412 echo " "
413 uname -a
414 echo " "
415 set comp = ( `grep "^SFC" configure.wrf | cut -d"=" -f2-` )
416 if ( "$comp[1]" == "gfortran" ) then
417 gfortran --version
418 else if ( "$comp[1]" == "pgf90" ) then
419 pgf90 --version
420 else if ( "$comp[1]" == "ifort" ) then
421 ifort -V
422 else
423 echo "Not sure how to figure out the version of this compiler: $comp[1]"
424 endif
425 echo " "
426 echo "============================================================================================== "
427 echo " "
429 if ( ! $?WRF_SRC_ROOT_DIR ) setenv WRF_SRC_ROOT_DIR `pwd`
431 # new dec 2009. check to see if make supports parallel -j option
432 make -j 2 >& /dev/null
433 if ( $status == 0 ) then # Parallel make ok
434 if ( ! $?J ) then # J not defined
435 echo setting parallel make -j 2 # Set default to 2
436 setenv J "-j 2"
437 else
438 # J is defined, check that it is a correctly formed variable
439 set first2chars = `echo $J | cut -c 1-2` # Are 1st two chars are -j?
440 set second_word = `echo $J | cut -d" " -f2` # Is second word a number?
441 if ( "$first2chars" == "-j" ) then
442 if ( ( "$second_word" >= "2" ) && \
443 ( "$second_word" <= "20" ) ) then
444 echo setting parallel make $J
445 else if ( "$second_word" == "1" ) then
446 echo setting serial make $J
447 else
448 echo "badly formed -j option for parallel make: $J"
449 echo "or you set the number of processors above 20 "
450 echo setting parallel make -j 2 # Set default to 2
451 setenv J "-j 2"
452 endif
453 else
454 if ( "$J" == "" ) then # J blank is OK
455 echo setting serial make $J
456 else
457 echo "parallel option for make is -j, you entered: $first2chars"
458 echo setting parallel make -j 2 # Set default to 2
459 setenv J "-j 2"
460 endif
461 endif
462 endif
463 else
464 echo not setting parallel make
465 endif
467 /bin/rm -f $ZAP >& /dev/null
468 make $arglist A2DCASE="$A2DCASE" WRF_SRC_ROOT_DIR="$WRF_SRC_ROOT_DIR"
470 endif
472 exit 0
474 hlp:
476 echo ' '
477 echo 'Usage:'
478 echo ' '
479 echo ' compile [-j n] wrf compile wrf in run dir (NOTE: no real.exe, ndown.exe, or ideal.exe generated)'
480 echo ' '
481 echo ' or choose a test case (see README_test_cases for details) :'
482 foreach d ( `/bin/ls test` )
483 if ( "$d" != "CVS" ) then
484 echo " compile [-j n] $d"
485 endif
487 echo ' '
488 echo ' compile -j n parallel make using n tasks if supported (default 2)'
489 echo ' compile -h help message'