source: lmdz_wrf/trunk/WRFV3/compile @ 1573

Last change on this file since 1573 was 1, checked in by lfita, 10 years ago
  • -- --- Opening of the WRF+LMDZ coupling repository --- -- -

WRF: version v3.3
LMDZ: version v1818

More details in:

  • Property svn:executable set to *
File size: 14.4 KB
Line 
1#!/bin/csh -f
2
3setenv START_OF_COMPILE "`date`"
4
5cont1:
6
7if ( !  -e configure.wrf  ) then
8   if ( $1 == "all_wrfvar" ) then
9      ./configure wrfda
10      set dontask
11   else
12      ./configure $1
13      set dontask
14   endif
15endif
16
17
18#----------------------------------
19if ( ! $?WRF_KPP )   setenv WRF_KPP  0
20if ( $WRF_KPP == 1 ) then
21chem/KPP/compile_wkc
22endif
23
24#---------------------------------
25
26if ( ! $?dontask && $?prompt ) then
27  echo "This script assumes you have configured the code already."
28  echo "You only need to configure once."
29  echo "If you wish to reconfigure, type c at the prompt below"
30  echo " "
31  echo "Ready to compile? [ync]"
32  set resp=$<
33
34  if ( "$resp" == "c" ) then
35    ./configure
36    goto cont1
37  endif
38
39  if ( "$resp" == "n" ) then
40    exit 2
41  endif
42endif
43
44set arglist=""
45foreach a ( $argv )
46  if ( "$a" == "-h" ) then
47    goto hlp
48  else
49    if ( "$a" != "-d" ) then
50      set arglist = ( $arglist $a )
51    endif
52    if ( "$a" == "all_wrfvar" ) then
53      grep "DA_CORE=1" configure.wrf > /dev/null
54      if ( ! $status ) then 
55         # If configuration file has DA_CORE=1 hardwired, ok to set WRF_DA_CORE to 1
56         setenv WRF_DA_CORE 1
57      endif
58    endif
59    if ( "$a" == "nmm_real" ) then
60      grep "NMM_CORE=1" configure.wrf > /dev/null
61      if ( ! $status ) then 
62         # If configuration file has NMM_CORE=1 hardwired, ok to set WRF_NMM_CORE to 1
63         if ( ! $?WRF_NMM_CORE ) setenv WRF_NMM_CORE 1
64      endif
65    endif
66    if ( "$a" == "-j" ) then
67      shift argv
68      setenv J "-j $argv[1]"
69    endif
70  endif
71end
72
73if ( "$arglist" == "" ) then
74  goto hlp
75else
76  unsetenv A2DCASE
77  setenv A2DCASE `echo $arglist | grep 2d`
78
79  if ( ! (   $?WRF_EM_CORE  || $?WRF_NMM_CORE \
80          ||  $?WRF_COAMPS_CORE || $?WRF_EXP_CORE )) then
81    echo 'None of WRF_EM_CORE, WRF_NMM_CORE, '
82#    echo '        WRF_COAMPS_CORE, or WRF_EXP_CORE '
83    echo '        specified in shell environment.... '
84    setenv WRF_EM_CORE 1
85    setenv WRF_NMM_CORE 0
86    setenv WRF_COAMPS_CORE 0
87    setenv WRF_EXP_CORE 0
88  endif
89
90# these settings get passed down through the environment in the
91# calls to Make
92  if ( ! $?WRF_DA_CORE )     setenv WRF_DA_CORE 0
93  if ( ! $?WRF_EM_CORE )     setenv WRF_EM_CORE 0
94  if ( ! $?WRF_NMM_CORE )    setenv WRF_NMM_CORE 0
95  if ( ! $?WRF_NMM_NEST )    setenv WRF_NMM_NEST 0
96  if ( ! $?WRF_COAMPS_CORE ) setenv WRF_COAMPS_CORE 0
97  if ( ! $?WRF_EXP_CORE )    setenv WRF_EXP_CORE 0
98  if ( ! $?WRF_CHEM )        setenv WRF_CHEM 0
99  if ( ! $?WRF_DFI_RADAR )   setenv WRF_DFI_RADAR 0
100  if ( ! $?HWRF )            setenv HWRF 0
101  if ( ! $?WRF_CONVERT ) then
102     if ( "$arglist" == "convert_em" ) then
103       setenv WRF_CONVERT 1
104       setenv WRF_EM_CORE 0
105     else
106       setenv WRF_CONVERT 0
107     endif
108  endif
109
110  if ( ! $?DA_ARCHFLAGS )     setenv DA_ARCHFLAGS ""
111
112  if ( ( $WRF_DA_CORE == 1 )  && ( ! -d var ) ) then
113    echo "  "
114    echo "You need to download and untar the Var code, or"
115    echo "unset the WRF_DA_CORE env variable."
116    echo "  "
117    exit
118  endif
119
120  if ( ( $WRF_CHEM == 1 )  && ( ! -d chem ) ) then
121    echo "  "
122    echo "You need to download and untar the chem code, or"
123    echo "unset the WRF_CHEM env variable."
124    echo "  "
125    exit
126  endif
127
128  set overwrite=0
129  if ($WRF_NMM_CORE == 1 && $WRF_DFI_RADAR == 1 ) then
130    echo "radar dfi not yet supported in NMM core, set WRF_DFI_RADAR to 0 "
131  endif
132
133  if ($WRF_NMM_CORE == 1 && $WRF_CHEM == 1 ) then
134    echo "Chemistry not yet supported in NMM core, set WRF_CHEM to 0 "
135    if ( ! -f Registry/Registry ) then
136      echo Registry file does not exist
137      set overwrite=1
138    else
139      head -2 Registry/Registry | tail -1 | grep NMM_CHEM > /dev/null
140      if ( $status ) then
141        set overwrite=1
142      else
143        set nmm_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.NMM_CHEM' | grep -v 'Registry.NMM_CHEM.' | awk '{print $1}'`
144        set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
145        if ( $nmm_time > $rg_time ) set overwrite=1
146      endif
147    endif
148    if ( $overwrite ) then
149      echo copying Registry/Registry.NMM_CHEM to Registry/Registry
150      echo '## WARNING: this file is autogenerated from Registry/Registry.NMM_CHEM. Changes may be lost' > Registry/Registry
151      /bin/cat Registry/Registry.NMM_CHEM >> Registry/Registry
152    endif
153#   exit 2
154  endif
155
156
157  if ($WRF_EM_CORE == 1 && $WRF_NMM_CORE == 1 ) then
158    echo "Cannot compile both EM and NMM cores in same executable yet."
159    exit 2
160  endif
161  if ($WRF_EM_CORE == 0 && $WRF_NMM_CORE == 0 && ! $WRF_CONVERT == 1 ) then
162    echo "Cannot compile because both EM and NMM cores are set to 0."
163    exit 2
164  endif
165  if ("$arglist" == 'nmm_real' && $WRF_NMM_CORE == 0) then
166    echo WRF_NMM_CORE must be set to 1 in order to compile nmm_real
167    exit 2
168  endif
169  if (($WRF_EM_CORE == 1)&&($WRF_DA_CORE == 0 ) &&($WRF_CHEM == 0 )&&($WRF_CONVERT == 0))  then
170    if ( ! -f Registry/Registry ) then
171      set overwrite=1
172    else
173      head -2 Registry/Registry | tail -1 | grep EM > /dev/null
174      if ( $status ) then
175        set overwrite=1
176      else
177        set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM' | grep -v 'Registry.EM.' | awk '{print $1}'`
178        set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
179        if ( $em_time > $rg_time ) set overwrite=1
180      endif
181    endif
182    if ( $overwrite ) then
183      echo copying Registry/Registry.EM to Registry/Registry
184      echo '## WARNING: this file is autogenerated from Registry/Registry.EM. Changes may be lost' > Registry/Registry
185      /bin/cat Registry/Registry.EM >> Registry/Registry
186    endif
187  else if (($WRF_EM_CORE == 1)&&($WRF_CHEM == 1 ))  then
188    if ( ! -f Registry/Registry ) then
189      set overwrite=1
190    else
191      head -2 Registry/Registry | tail -1 | grep EM_CHEM > /dev/null
192      if ( $status ) then
193        set overwrite=1
194      else
195        set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM_CHEM' | grep -v 'Registry.EM_CHEM.' | awk '{print $1}'`
196        set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
197        if ( $em_time > $rg_time ) set overwrite=1
198      endif
199    endif
200    if ( $overwrite ) then
201      echo copying Registry/Registry.EM_CHEM to Registry/Registry
202      echo '## WARNING: this file is autogenerated from Registry/Registry.EM_CHEM. Changes may be lost' > Registry/Registry
203      /bin/cat Registry/Registry.EM_CHEM >> Registry/Registry
204    endif
205  else if (($WRF_EM_CORE == 1)&&($WRF_DFI_RADAR == 1 ))  then
206    if ( ! -f Registry/Registry ) then
207      set overwrite=1
208    endif
209    if ( $overwrite ) then
210      echo copying Registry/Registry.EM to Registry/Registry
211      echo '## WARNING: this file is autogenerated from Registry/Registry.EM. Changes may be lost' > Registry/Registry
212      /bin/cat Registry/Registry.EM >> Registry/Registry
213    endif
214  else if (($WRF_EM_CORE == 0)&&($WRF_CONVERT == 1 ))  then
215    if ( ! -f Registry/Registry ) then
216      set overwrite=1
217    else
218      head -2 Registry/Registry | tail -1 | grep EM_CONVERT > /dev/null
219      if ( $status ) then
220        set overwrite=1
221      else
222        set em_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.EM_CONVERT' | grep -v 'Registry.EM_CONVERT.' | awk '{print $1}'`
223        set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
224        if ( $em_time > $rg_time ) set overwrite=1
225      endif
226    endif
227    if ( $overwrite ) then
228      echo copying Registry/Registry.CONVERT to Registry/Registry
229      echo '## WARNING: this file is autogenerated from Registry/Registry.CONVERT. Changes may be lost' > Registry/Registry
230      /bin/cat Registry/Registry.CONVERT >> Registry/Registry
231    endif
232  else if ( $WRF_DA_CORE == 1 )  then
233    if ( ! -f Registry/Registry ) then
234      set overwrite=1
235    else
236      head -2 Registry/Registry | tail -1 | grep WRFVAR > /dev/null
237      if ( $status ) then
238        set overwrite=1
239      else
240        set nmm_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.NMM' | grep -v 'Registry.NMM.' | awk '{print $1}'`
241        set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
242        if ( $nmm_time > $rg_time ) set overwrite=1
243      endif
244    endif
245    if ( $overwrite ) then
246      echo copying Registry/Registry.wrfvar to Registry/Registry
247      echo '## WARNING: this file is autogenerated from Registry/Registry.wrfvar. Changes may be lost' > Registry/Registry
248      /bin/cat Registry/Registry.wrfvar >> Registry/Registry
249    endif
250    if ( $?CRTM ) then
251       if ( ! $?BUFR ) then
252          echo "  "
253          echo "BUFR library will be compiled for radiance data ingest."
254          echo "  "
255          setenv BUFR 1
256       endif
257       setenv CRTM_CPP "-DCRTM"
258       setenv CRTM_LIB "-L../external/crtm/libsrc -lCRTM"
259       setenv CRTM_SRC "-I../external/crtm/libsrc"
260       setenv SFC_CRTM `grep '^SFC' configure.wrf | awk '{print $3}' | sed -e 's/\// /g' | awk '{print $NF}'`
261       setenv ABI_CRTM `grep '^SFC' configure.wrf | grep -o -E "\-m[0-9]{2}"`
262    else
263       setenv CRTM_CPP " "
264       setenv CRTM_LIB " "
265       setenv CRTM_SRC " "
266    endif
267    if ( $?RTTOV ) then
268       if ( ! $?BUFR ) then
269          echo "  "
270          echo "BUFR library is needed for radiance data ingest."
271          echo "  "
272          setenv BUFR 1
273       endif
274       setenv RTTOV_CPP "-DRTTOV"
275       setenv RTTOV_LIB "-L${RTTOV}/lib -lrttov10.1.0_coef_io -lrttov10.1.0_emis_atlas -lrttov10.1.0_main"
276       setenv RTTOV_SRC "-I${RTTOV}/include -I${RTTOV}/mod"
277    else
278       setenv RTTOV_CPP " "
279       setenv RTTOV_LIB " "
280       setenv RTTOV_SRC " "
281    endif
282    if ( $?BUFR ) then
283       setenv BUFR_CPP "-DBUFR"
284       setenv BUFR_LIB "-L../external/bufr -lbufr"
285    else
286       setenv BUFR_CPP " "
287       setenv BUFR_LIB " "
288    endif
289    if ( $?WAVELET ) then
290       setenv WAVELET_LIB "../external/wavelet/libWavelet.a ../external/wavelet/lib_wavelet.a"
291    else
292       setenv WAVELET_LIB " "
293    endif
294    if ( $?MADIS ) then
295       setenv MADIS_CPP "-DMADIS"
296       setenv MADIS_STATIC ${MADIS}/static
297       setenv MADIS_LIB "-L${MADIS} -lmadis"
298    else
299       setenv MADIS_CPP " "
300       setenv MADIS_LIB " "
301    endif
302    setenv DA_ARCHFLAGS "${BUFR_CPP} ${MADIS_CPP} -DFFTPACK -DNORESHAPE"
303  endif
304  if (($WRF_NMM_CORE == 1)&&($WRF_CHEM == 0 )) then
305    if ( ! -f Registry/Registry ) then
306      set overwrite=1
307    else
308      head -2 Registry/Registry | tail -1 | grep NMM > /dev/null
309      if ( $status ) then
310        set overwrite=1
311      else
312        set nmm_time=`ls -1tr Registry | cat -n | grep -w 'Registry\.NMM' | grep -v 'Registry.NMM.' | awk '{print $1}'`
313        set rg_time=`ls -1tr Registry | cat -n | grep -w 'Registry' | grep -v 'Registry.' | awk '{print $1}'`
314        if ( $nmm_time > $rg_time ) set overwrite=1
315      endif
316    endif
317    if ( $overwrite ) then
318      if (($WRF_NMM_CORE == 1)&&($WRF_NMM_NEST == 1)) then
319        echo copying Registry/Registry.NMM_NEST to Registry/Registry
320        echo '## WARNING: this file is autogenerated from Registry/Registry.NMM_NEST. Changes may be lost' > Registry/Registry
321        /bin/cat Registry/Registry.NMM_NEST >> Registry/Registry
322      else
323        echo copying Registry/Registry.NMM to Registry/Registry
324        echo '## WARNING: this file is autogenerated from Registry/Registry.NMM. Changes may be lost' > Registry/Registry
325        /bin/cat Registry/Registry.NMM >> Registry/Registry
326      endif
327    endif
328# integrity check for a kludge where a hard coded value in the
329# registry must match the same value in arch/preamble_new
330    set registryvalue=`grep 'dimspec.* q ' Registry/registry.dimspec | sed -e 's/..*constant=//' -e 's/ ..*$//'`
331    set preamblevalue=`grep 'DNMM_MAX_DIM=.*' arch/preamble_new | sed -e 's/..*-DNMM_MAX_DIM=//' -e 's/ ..*$//'`
332    if ( $registryvalue != $preamblevalue ) then
333      echo "Harded coded value of dimspec q in Registry ($registryvalue) does not"
334      echo "equal the hard coded value of NMM_MAX_DIM in arch/preamble_new ($preamblevalue)"
335      echo "Please fix and try again."
336      exit 2
337    endif
338  endif
339
340  echo " "
341  echo -n "Compiling: "
342  if ( $WRF_DA_CORE ) echo -n "WRF_DA_CORE "
343  if ( $WRF_EM_CORE ) echo -n "WRF_EM_CORE "
344  if ( $WRF_NMM_CORE ) echo -n "WRF_NMM_CORE "
345  if ( $WRF_COAMPS_CORE ) echo -n "WRF_COAMPS_CORE "
346  if ( $WRF_EXP_CORE ) echo -n "WRF_EXP_CORE "
347  echo "."
348  echo " "
349
350  if ( ! $?WRF_SRC_ROOT_DIR ) setenv WRF_SRC_ROOT_DIR `pwd`
351
352# new dec 2009.  check to see if make supports parallel -j option
353  make -j 2 >& /dev/null
354  if ( $status == 0 ) then              # Parallel make ok
355    if ( ! $?J ) then                   # J not defined
356      echo setting parallel make -j 2   # Set default to 2
357      setenv J "-j 2"
358    else
359#     J is defined, check that it is a correctly formed variable
360      set first2chars = `echo $J | cut -c 1-2`         # Are 1st two chars are -j?
361      set second_word = `echo $J | cut -d" " -f2`      # Is second word a number?
362      if    ( "$first2chars" == "-j" ) then
363         if ( ( "$second_word" >= "2"  )  && \
364              ( "$second_word" <= "20" ) ) then
365            echo setting parallel make $J
366         else if ( "$second_word" == "1" ) then
367            echo setting serial make $J
368         else
369            echo "badly formed -j option for parallel make: $J"
370            echo "or you set the number of processors above 20 "
371            echo setting parallel make -j 2            # Set default to 2
372            setenv J "-j 2"
373         endif
374      else
375         if ( "$J" == "" ) then     # J blank is OK
376            echo setting serial make $J
377         else
378            echo "parallel option for make is -j, you entered: $first2chars"
379            echo setting parallel make -j 2               # Set default to 2
380            setenv J "-j 2"
381         endif
382      endif
383    endif
384  else
385    echo not setting parallel make
386  endif
387
388  make $arglist A2DCASE="$A2DCASE" WRF_SRC_ROOT_DIR="$WRF_SRC_ROOT_DIR"
389
390endif
391
392exit 0
393
394hlp:
395
396echo ' '
397echo 'Usage:'
398echo ' '
399echo '   compile [-d] [-j n] wrf   compile wrf in run dir (NOTE: no real.exe, ndown.exe, or ideal.exe generated)'
400echo ' '
401echo '   or choose a test case (see README_test_cases for details) :'
402foreach d ( `/bin/ls test` )
403  if ( "$d" != "CVS" ) then
404    echo "      compile $d"
405  endif
406end
407echo ' '
408echo '  compile -d                 compile without optimization and with debugging'
409echo '  compile -j n               parallel make using n tasks if supported (default 2)'
410echo '  compile -h                 help message'
411
412
Note: See TracBrowser for help on using the repository browser.