4 # Check for command-line arguments
5 # At present, the only supported argument is --nowrf, which disables checks to
6 # find the path to the compiled WRF model.
10 if [ "${arg}" = "--nowrf" ]; then
17 if test -z "$NETCDF" ; then
18 for p
in /usr
/local
/netcdf
27 if test -z "$NETCDF" ; then
29 if [ `hostname | cut -c 1-2` = "bs" -o \
30 `hostname | cut -c 1-2` = "bv" -o \
31 `hostname` = "tempest" -o `hostname` = "lightning" ] ; then
32 echo 'Compiling on an NCAR system with weird paths to NetCDF'
33 echo 'Setting up a local NetCDF directory with symlinks'
34 if ( test -d .
/netcdf_links
) ; then
35 echo 'A directory ./netcdf_links already exists. Continuing.'
38 if [ -z "$OBJECT_MODE" ] ; then
42 if [ $OBJECT_MODE -ne 64 -a \
( `hostname | cut -c 1-2` = "bs" \
) ] ; then
43 ( cd .
/netcdf_links
; ln -s /usr
/local
/lib32
/r4i4 .
/lib
; \
44 ln -s /usr
/local
/include .
/include
)
46 ( cd .
/netcdf_links
; ln -s /usr
/local
/lib64
/r4i4 .
/lib
; \
47 ln -s /usr
/local
/include .
/include
)
50 NETCDF
=`pwd`/netcdf_links
56 if [ -d .
/netcdf_links
] ; then
57 echo '** There is an existing ./netcdf_links file. Should I use? [y]'
59 if [ "$resp" = "y" ] ; then
60 NETCDF
=`pwd`/netcdf_links
63 echo 'Removing existing ./netcdf_links directory'
64 /bin
/rm -fr .
/netcdf_links
67 echo '** WARNING: No path to NETCDF and environment variable NETCDF not set.'
68 echo '** would you like me to try to fix? [y]'
72 while [ -z "$bedone" ] ; do
74 if [ "$resp" = "y" -o -z "$resp" ] ; then
75 if [ -d .
/netcdf_links
] ; then
76 echo 'There is already a ./netcdf_links directory. Okay to use links'
77 echo 'in this directory for NetCDF include and lib dirs? [y]'
79 if [ "$resp" = "y" ] ; then
80 NETCDF
=`pwd`/netcdf_links
86 if [ -z "$netcdfipath" ] ; then
87 echo 'Enter full path to NetCDF include directory on your system'
89 if [ ! -d "$resp" ] ; then
90 echo "invalid path: $resp. Try again? [y]" ; continue
94 if [ -z "$netcdflpath" ] ; then
95 echo 'Enter full path to NetCDF library directory on your system'
97 if [ ! -d "$resp" ] ; then
98 echo "invalid path: $resp. Try again? [y]" ; continue
103 if [ -n "$netcdflpath" -a -n "$netcdfipath" ] ; then
104 if [ -d .
/netcdf_links
] ; then
105 echo 'Existing ./netcdf_links directory. Okay to remove. [y]'
107 if [ "$resp" = "y" ] ; then
108 /bin
/rm -fr .
/netcdf_links
113 ln -s "$netcdfipath" include
114 ln -s "$netcdflpath" lib
116 echo created new .
/netcdf_links directory
117 /bin
/ls -lF .
/netcdf_links
118 NETCDF
=`pwd`/netcdf_links
129 if [ -n "$NETCDF" ] ; then
130 echo "Will use NETCDF in dir: $NETCDF"
131 # for 3.6.2 and greater there might be a second library, libnetcdff.a . Check for this and use
134 if [ -f "$NETCDF/lib/libnetcdff.a" ] ; then
138 echo "Will configure for use without NetCDF"
141 # if the uname command exists, give it a shot and see if
142 # we can narrow the choices; otherwise, spam 'em
145 type uname
> /dev
/null
146 if [ $?
-eq 0 ] ; then
148 if [ "$os" = "AIX" -o "$os" = "IRIX" -o "$os" = "IRIX64" -o "$os" = "SunOS" -o "$os" = "HP-UX" -o "$os" = "Darwin" ] ; then
151 xxx
=`expr "$os" : '\(.........\).*'`
152 if [ "$xxx" = "CYGWIN_NT" ] ; then
155 if [ "$os" = "OSF1" -o "$os" = "Linux" -o "$os" = "UNICOS/mp" -o "$os" = "UNIX_System_V" -o "$os" = "CYGWIN_NT" ] ; then
165 standard_wrf_dirs
="WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3"
167 if [ ${nowrf} -eq 0 ]; then
169 # If no WRF_DIR environment variable is set, try to locate a WRF build in one
170 # of the expected directory names one directory level up; otherwise, try to use
171 # the WRF I/O library from the code in $WRF_DIR
173 if [ -z "$WRF_DIR" ]; then
174 # for d in WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3; do
175 for d
in ${standard_wrf_dirs}; do
176 if [ -e ..
/${d}/external
/io_netcdf
/libwrfio_nf.a
]; then
177 echo "Found what looks like a valid WRF I/O library in ../${d}"
183 if [ ! -e ${WRF_DIR}/external
/io_netcdf
/libwrfio_nf.a
]; then
185 echo "Error: The \$WRF_DIR environment variable was set, but the WRF code at"
186 echo " ${WRF_DIR} doesn't appear to have been successfully compiled"
191 echo "Using WRF I/O library in WRF build identified by \$WRF_DIR: ${WRF_DIR}"
195 if [ $wrf_dir = "none" ]; then
197 echo "Error: No compiled WRF code found. Please check that the WRF model has been compiled"
198 echo " one directory level up (i.e., ../) in a directory named 'WRF', 'WRF-4.0.3', 'WRF-4.0.2', etc.,"
199 echo " or specify the full path to the compiled WRF model with the environment variable \$WRF_DIR ."
201 echo "Alternatively, if only WPS components that do no depend on WRF I/O libraries are needed, re-run"
202 echo "the configure script with the --nowrf option."
208 ********************************************************************************
209 Configuring the WPS without a compiled WRF model.
210 It will not be possible to build the following WPS components, which depend on
211 the WRF I/O libraries:
215 ********************************************************************************
219 # Found perl, so proceed with configuration
220 perl arch
/Config.pl
-perl=$PERL -netcdf=$NETCDF -netcdff=$NETCDFF -os=$os -mach=$mach -wrfdir=$wrf_dir
223 #Checking cross-compiling capability for some particular environment
224 #on Linux and Mac box
226 if [ $os = "Linux" -o $os = "Darwin" ]; then
228 SFC
=`grep '^SFC' configure.wps | awk '{print $3}'`
229 SCC
=`grep '^SCC' configure.wps | awk '{print $3}'`
231 SFC
="`type $SFC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
232 SCC
="`type $SCC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
234 if [ -e $NETCDF/lib
/libnetcdf.a
-a "$SFC" != "" -a "$SCC" != "" ]; then
243 echo Testing
for NetCDF
, C and Fortran compiler
247 int main(int argc, char ** argv)
255 integer :: STATUS = 0
257 end program test_exit
260 nct
=`nm $NETCDF/lib/libnetcdf.a | grep '^0' | cut -d' ' -f 1 | head -1 | wc -c | awk '{print $1+0}'`
261 if [ "$nct" -eq "9" ]; then
267 $SFC -o ${foo} ${foo}.f
> /dev
/null
2>&1
268 SFC_arch
="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
269 rm ${foo} ${foo}.o
2> /dev
/null
271 $SCC -o ${foo} ${foo}.c
> /dev
/null
2>&1
272 SCC_arch
="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
273 rm ${foo} ${foo}.o
2> /dev
/null
275 if [ "$SFC_arch" = "" -o "$SCC_arch" = "" ]; then
276 echo " One of compilers testing failed!"
277 echo " Please check your compiler"
279 rm -f ${foo} ${foo}.
[cfo
] 2> /dev
/null
282 cp configure.wps configure.wps.edit
289 if [ "$SFC_arch" = "64-bit" ] ; then
291 $SFC -m32 -o ${foo} ${foo}.f
> /dev
/null
2>&1
294 sed '/^SFC.*=/s/$/ -m32/' configure.wps.edit
> configure.wps.tmp
295 mv configure.wps.tmp configure.wps.edit
298 if [ "$SCC_arch" = "64-bit" ] ; then
300 $SCC -m32 -o ${foo} ${foo}.c
> /dev
/null
2>&1
303 sed '/^SCC.*=/s/$/ -m32/' configure.wps.edit
> configure.wps.tmp
304 mv configure.wps.tmp configure.wps.edit
308 if [ $CROSS_COMPILING -eq 1 ] ; then
310 echo This installation NetCDF is
32-bit
311 if [ \
( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" = "64-bit" \
) \
312 -o \
( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" = "64-bit" \
) ] ; then
313 rm configure.wps.edit
314 echo One of compilers is
64-bit and doesn
\'t support cross-compiling.
315 echo Please check your NETCDF lib and compiler
317 echo -m32 is appended to configure.wps
318 echo It will be forced to build
in 32-bit.
319 echo If you don
\'t want
32-bit binaries
, please use
64-bit NetCDF
, and re-run the configure
script.
326 if [ "$SFC_arch" = "32-bit" -o "$SFC_arch" = "i386" ] ; then
328 $SFC -m64 -o ${foo} ${foo}.f
> /dev
/null
2>&1
331 sed '/^SFC.*=/s/$/ -m64/' configure.wps.edit
> configure.wps.tmp
332 mv configure.wps.tmp configure.wps.edit
335 if [ "$SCC_arch" = "32-bit" -o "$SCC_arch" = "i386" ] ; then
337 $SCC -m64 -o ${foo} ${foo}.c
> /dev
/null
2>&1
340 sed '/^SCC.*=/s/$/ -m64/' configure.wps.edit
> configure.wps.tmp
341 mv configure.wps.tmp configure.wps.edit
345 if [ $CROSS_COMPILING -eq 1 ] ; then
347 echo This installation NetCDF is
64-bit
348 if [ \
( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" != "64-bit" \
) \
349 -o \
( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" != "64-bit" \
) ]; then
350 rm configure.wps.edit
351 echo One of Compilers is
32-bit and doesn
\'t support cross-compiling.
352 echo Please check your NetCDF lib and compiler
354 echo -m64 is appended to configure.wps
355 echo It will be forced to build
in 64-bit.
356 echo If you don
\'t want
64-bit binaries
, please use
32-bit NetCDF
, and re-run the configure
script.
361 rm -f ${foo} ${foo}.
[cfo
] 2> /dev
/null
363 if [ -e configure.wps.edit
]; then
364 mv configure.wps.edit configure.wps
367 if [ $CROSS_COMPILING -eq 0 ] ; then
368 echo This installation NetCDF is
$netcdf_arch
369 echo C compiler is
$SCC_arch
370 echo Fortran compiler is
$SFC_arch
374 # Does our Fortran work with the given NETCDF library.
376 /bin
/rm -f fort_netcdf.f fort_netcdf
377 cat > fort_netcdf.f
<<EOF
380 integer ncid , status
381 status = nf_open ( 'foo.nc' , 0 , ncid )
382 print *,'status = ',status
385 FFLAGS
=`grep ^FFLAGS configure.wps | cut -d"=" -f2-`
386 cp $NETCDF/include
/netcdf.inc .
387 FC
=`grep ^SFC configure.wps | cut -d"=" -f2-`
388 $FC ${FFLAGS} fort_netcdf.f
-o fort_netcdf
-L${NETCDF}/lib
$NETCDFF -lnetcdf > /dev
/null
2>&1
389 if [ -f "fort_netcdf" ] ; then
390 .
/fort_netcdf
> /dev
/null
2>&1
392 /bin
/rm -f fort_netcdf.f fort_netcdf.o fort_netcdf netcdf.inc
395 echo "Your Fortran + NETCDF did not run successfully."
400 echo "Your versions of Fortran and NETCDF are not consistent."
407 # define C_TEST c_test
409 # if defined ( F2CSTYLE ) || defined ( _DOUBLEUNDERSCORE )
410 # define C_TEST c_test__
412 # define C_TEST c_test_
418 int C_TEST ( float *xx, int *ii )
421 printf("OK print in C function. \n" ) ;
422 printf("Values are xx = %5.2f and ii = %d \n", *xx, *ii ) ;
426 CFLAGS
=`grep ^CFLAGS configure.wps | cut -d"=" -f2-`
427 CPPFLAGS
=`grep ^CPPFLAGS configure.wps | cut -d"=" -f2-`
428 CC
=`grep ^SCC configure.wps | cut -d"=" -f2-`
429 ${CC} -c ${CFLAGS} ${CPPFLAGS} c_test.c
431 cat > f_test.f90
<<EOF
439 CALL c_test ( xx , ii )
443 $FC ${FFLAGS} f_test.f90
-o cf_test c_test.o
> /dev
/null
2>&1
444 if [ -f "cf_test" ] ; then
445 .
/cf_test
> /dev
/null
2>&1
447 /bin
/rm -f cf_test c_test.c c_test.o f_test.f90 f_test.o
450 echo "Your Fortran + C did not run successfully."
455 echo "Your versions of Fortran and C are not consistent."