source: palm/trunk/INSTALL/palm_installer_components @ 3628

Last change on this file since 3628 was 3628, checked in by knoop, 3 years ago

Added RRTMG installation capability to automatic installer

  • Property svn:executable set to *
File size: 25.8 KB
Line 
1#!/usr/bin/env bash
2#------------------------------------------------------------------------------#
3# This file is part of PALM.
4#
5# PALM is free software: you can redistribute it and/or modify it under the
6# terms of the GNU General Public License as published by the Free Software
7# Foundation, either version 3 of the License, or (at your option) any later
8# version.
9#
10# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# PALM. If not, see <http://www.gnu.org/licenses/>.
16#
17# Copyright 1997-2018  Leibniz Universitaet Hannover
18#------------------------------------------------------------------------------#
19# Temporary trunk side of the automatic installation scipt
20# WARNING: This script does not work as a standalone installer!
21#------------------------------------------------------------------------------#
22
23
24# install PALM
25palm_installer_build() {
26   printf "%s\n" "${program_name} installer is configuring using cmake..."
27   if [[ "$palm_installer_build_rrtmg" == "true" ]]; then
28      if [[ "$RRTMG_ROOT" == "" ]]; then
29         RRTMG_ROOT=${install_prefix}/rrtmg
30      fi
31   fi
32   palm_installer_create_files
33   rm -rf ${build_dir}
34   mkdir -p ${build_dir}
35   cd ${build_dir}
36   cp ${trunk_dir}/SCRIPTS/.palm.config.default.in ${source_dir}/.palm.config.default.in
37   cmake -Wno-dev ${CUSTOM_FORTRAN_COMPILER:+-DCMAKE_Fortran_COMPILER=}${CUSTOM_FORTRAN_COMPILER} \
38         ${NETCDF_C_ROOT:+-DNETCDF_C_ROOT=}${NETCDF_C_ROOT} \
39         ${NETCDF_FORTRAN_ROOT:+-DNETCDF_FORTRAN_ROOT=}${NETCDF_FORTRAN_ROOT} \
40         ${RRTMG_ROOT:+-DRRTMG_ROOT=}${RRTMG_ROOT} \
41         -DPALM_CORES=$NUM_PROC_BUILD \
42         -DCMAKE_BUILD_TYPE=Release \
43         ${install_prefix:+-DCMAKE_INSTALL_PREFIX=}${install_prefix} \
44         -DCMAKE_USERNAME=${USER} \
45         ${source_dir}
46   if [[ $? -ne 0 ]]; then
47      hrule
48      printf "| \e[1;31m%-${number_of_cols}s\e[0m |\n" "Configuration failed!"
49      palm_installer_ticket_message
50      hrule
51      exit 1
52   else
53      hrule
54      printf "| \e[1;32m%-${number_of_cols}s\e[0m |\n" "Configuration finished!"
55      hrule
56   fi
57   palm_read_yn "Please check the configuration!!! Would you like to continue?" "RESPONSE_CONFIGURE"
58   if [[ "$RESPONSE_CONFIGURE" != "y" ]]; then
59      palm_installer_abort_message
60   fi
61   if [[ "$palm_installer_build_rrtmg" == "true" ]]; then
62       palm_installer_build_rrtmg
63   fi
64   cd ${install_prefix}
65   rm -rf ${source_dir}
66   rm -rf MAKE_DEPOSITORY_parallel
67   bash ${trunk_dir}/SCRIPTS/palmbuild -v -c "default"
68}
69
70palm_installer_build_rrtmg() {
71   printf "%s\n" "${program_name} installer is building the RRTMG library..."
72   local version="1.0"
73   local prog="librrtmg"
74   build_dir_rrtmg=${source_dir}/rrtmg
75   mkdir -p ${build_dir_rrtmg}
76   cp ${trunk_dir}/LIB/rrtmg/*.f90  ${build_dir_rrtmg}/
77   cp ${trunk_dir}/LIB/rrtmg/Makefile  ${build_dir_rrtmg}/
78   cd ${build_dir_rrtmg}
79   bash ${build_dir_rrtmg}/build_rrtmg
80   mkdir -p ${build_dir_rrtmg}/lib
81   mkdir -p ${build_dir_rrtmg}/include
82   cp ${build_dir_rrtmg}/$prog.so ${build_dir_rrtmg}/lib/$prog.so.$version
83   cp ${build_dir_rrtmg}/*.mod    ${build_dir_rrtmg}/include/
84   mkdir -p ${RRTMG_ROOT}/lib
85   mkdir -p ${RRTMG_ROOT}/include
86   cp ${build_dir_rrtmg}/lib/$prog.so.$version ${RRTMG_ROOT}/lib/
87   cp ${build_dir_rrtmg}/include/*.mod ${RRTMG_ROOT}/include/
88   if [ -f ${RRTMG_ROOT}/lib/$prog.so.1 ]
89   then
90       rm ${RRTMG_ROOT}/lib/$prog.so.1
91   fi
92   ln -s ${RRTMG_ROOT}/lib/$prog.so.$version ${RRTMG_ROOT}/lib/$prog.so.1
93   if [ -f ${RRTMG_ROOT}/lib/$prog.so ]
94   then
95       rm ${RRTMG_ROOT}/lib/$prog.so
96   fi
97   ln -s ${RRTMG_ROOT}/lib/$prog.so.1 ${RRTMG_ROOT}/lib/$prog.so
98}
99
100palm_installer_set_path() {
101   [[ -w ${HOME}/.mybashrc ]] && shell_profile=${HOME}/.mybashrc
102   if [[ ! -w ${shell_profile} ]]; then
103      printf "\e[1;31mWARNING\e[0m: ${program_name} binary \e[1;31mpath could not be written\e[0m to \"${shell_profile}\"\n"
104      printf "In order to run the ${program_name} execution script \"mrun\" you need to set the following paths\n"
105      printf "   export PALM_BIN=${trunk_dir}/SCRIPTS\n"
106      printf "   export PATH=\$PALM_BIN:\$PATH\n"
107   elif grep -q "^export PALM_BIN=${trunk_dir}/SCRIPTS" ${shell_profile}; then
108      printf "${program_name} binary \e[1;32mpath already set correctly\e[0m in \"${shell_profile}\"\n"
109   else
110      if grep -q "PALM_BIN" ${shell_profile}; then
111         sed -i "s@^[^#]\(.*PALM_BIN.*\)@#e\1@" ${shell_profile}
112         printf "${program_name} binary \e[1;32mpath updated\e[0m in \"${shell_profile}\""
113      else
114         printf "${program_name} binary \e[1;32mpath written\e[0m to \"${shell_profile}\""
115      fi
116      cat >> ${shell_profile} << EOF
117#-------------------------------------------------------------------------------
118##PALM##
119export PALM_BIN=${trunk_dir}/SCRIPTS
120export PATH=\$PALM_BIN:\$PATH
121
122EOF
123   fi
124   export PALM_BIN=${trunk_dir}/SCRIPTS
125   export PATH=$PALM_BIN:$PATH
126   echo " "
127}
128
129palm_installer_test() {
130   hrule
131   printf "Testing ${program_name} with \"${1}\"... "
132   source ${shell_profile}
133   local input_dir=${install_prefix}/JOBS/${1}/INPUT/
134   local monitoring_dir=${install_prefix}/JOBS/${1}/MONITORING/
135   local test_dir=${trunk_dir}/INSTALL
136   if [[ ! -f ${test_dir}/${1}_p3d ]] || [[ ! -f ${test_dir}/${1}_rc ]]; then
137      printf "\e[1;31m test not found\e[0m\n"
138      return 1
139   fi
140   rm -rf ${monitoring_dir}
141   mkdir -p ${input_dir}
142   cp ${test_dir}/${1}_p3d ${input_dir}
143   [[ -f ${test_dir}/${1}_topo ]] && cp ${test_dir}/${1}_topo ${input_dir}
144   bash ${trunk_dir}/SCRIPTS/palmrun -r ${1} -a "d3#" -c "default" -X "$NUM_PROC_TEST" -T "$NUM_PROC_TEST" -v -B > ${install_prefix}/${logfile_test} 2>&1
145   grep -A 99999 "Run-control output" JOBS/${1}/MONITORING/${1}_rc 1> ${install_prefix}/RC_LOCAL 2> /dev/null
146   grep -A 99999 "Run-control output" ${test_dir}/${1}_rc 1> ${install_prefix}/RC_DEFAULT 2> /dev/null
147   diff_output=$(diff ${install_prefix}/RC_DEFAULT ${install_prefix}/RC_LOCAL)
148   rm ${install_prefix}/RC_LOCAL ${install_prefix}/RC_DEFAULT
149   if [[ "${diff_output}" == "" ]]; then
150      printf "\e[1;32m passed\e[0m\n"
151      return 0
152   else
153      printf "\e[1;31m failed\e[0m\n"
154      test_status="failed"
155      return 1
156   fi
157}
158
159palm_installer_test_suite() {
160   rm -f ${install_prefix}/${logfile_test}
161   for test_path in ${trunk_dir}/INSTALL/*_p3d; do
162      testname_p3d=$(basename $test_path)
163      palm_installer_test "${testname_p3d%_p3d}"
164   done
165   hrule
166   cat ${install_prefix}/${logfile_test} >> ${logfile_all}
167   if [[ "${test_status}" == "failed" ]]; then
168      printf "| \e[1;31m%-${number_of_cols}s\e[0m \n" "Some tests failed. ${program_name} installation not successful :-("
169      printf "| \e[1;31m%-${number_of_cols}s\e[0m \n" "More detailed information regarding the failure can be found in file:"
170      printf "| \e[1;31m%-${number_of_cols}s\e[0m \n" "      ${install_prefix}/${logfile_test}"
171      palm_installer_ticket_message
172      hrule
173      exit 1
174   else
175      printf "| \e[1;32m%-${number_of_cols}s\e[0m |\n" "All found tests passed. ${program_name} installation successful :-)"
176      rm -f ${install_prefix}/${logfile_test}
177      rm -rf ${install_prefix}/tmp/*
178      hrule
179   fi
180}
181
182palm_post_installer_help() {
183   hrule
184   printf "| %-${number_of_cols}s \n" " "
185   printf "| %-${number_of_cols}s \n" "-- To use ${program_name} it is required to update your PATH variable. Please type:"
186   printf "| %-${number_of_cols}s \n" " "
187   printf "| %-${number_of_cols}s \n" "      source ${shell_profile}"
188   printf "| %-${number_of_cols}s \n" " "
189   printf "| %-${number_of_cols}s \n" "   or restart your shell."
190   printf "| %-${number_of_cols}s \n" " "
191   printf "| %-${number_of_cols}s \n" "-- To work with ${program_name} please go to your ${program_name} base directory:"
192   printf "| %-${number_of_cols}s \n" " "
193   printf "| %-${number_of_cols}s \n" "      cd ${install_prefix}"
194   printf "| %-${number_of_cols}s \n" " "
195   printf "| %-${number_of_cols}s \n" "-- To start the model, please use \"palmrun\" with appropriate options. For example:"
196   printf "| %-${number_of_cols}s \n" " "
197   printf "| %-${number_of_cols}s \n" "      palmrun -r example_cbl -a \"d3#\" -c \"default\" -X \"$NUM_PROC_TEST\" -T \"$NUM_PROC_TEST\" "
198   printf "| %-${number_of_cols}s \n" "                      |           |          |        |     |            "
199   printf "| %-${number_of_cols}s \n" "                  Job name        |    configuration  | tasks per node   "
200   printf "| %-${number_of_cols}s \n" "                           I/O control list    number of cores           "
201   printf "| %-${number_of_cols}s \n" " "
202   printf "| %-${number_of_cols}s \n" "-- Edit \".palm.config.default\" to customize this ${program_name} installation."
203   printf "| %-${number_of_cols}s \n" "-- To rebuild ${program_name} type: palmbuild -c \"default\""
204   printf "| %-${number_of_cols}s \n" " "
205   printf "| %-${number_of_cols}s \n" "-- For further questions go to: https://palm.muk.uni-hannover.de/."
206   printf "| %-${number_of_cols}s \n" " "
207}
208
209palm_installer_create_files() {
210   mkdir -p ${source_dir}
211
212   cat > ${source_dir}/CMakeLists.txt << EOF
213# This is the CMake configuration file for PALM
214
215cmake_minimum_required (VERSION 2.8)
216
217# set program name
218set(PALM_PROGRAM_NAME "PALM")
219
220project(\${PALM_PROGRAM_NAME} NONE)
221exec_program( hostname OUTPUT_VARIABLE PALM_HOSTNAME)
222
223# .palm.config locations
224set(config_in \${CMAKE_CURRENT_SOURCE_DIR}/.palm.config.default.in)
225set(config \${CMAKE_INSTALL_PREFIX}/.palm.config.default)
226
227# palmtest.yml locations
228set(palmtest_in \${CMAKE_CURRENT_SOURCE_DIR}/.palmtest.yml.in)
229set(palmtest \${CMAKE_INSTALL_PREFIX}/palmtest.yml)
230
231# build_rrtmg locations
232set(build_rrtmg_in \${CMAKE_CURRENT_SOURCE_DIR}/build_rrtmg.in)
233set(build_rrtmg \${CMAKE_CURRENT_SOURCE_DIR}/rrtmg/build_rrtmg)
234
235# include local cmake files
236set(PALM_CMAKE_FILES \${CMAKE_CURRENT_SOURCE_DIR})
237list(APPEND CMAKE_MODULE_PATH \${PALM_CMAKE_FILES})
238
239# enabling Fortran language support
240enable_language(Fortran) # required to compile the main model and all utilities
241
242# check for Fortran MPI support
243find_package(MPI REQUIRED)
244
245# check for netCDF
246#set(NETCDF_C "YES")
247set(NETCDF_FORTRAN "YES")
248find_package (NetCDF REQUIRED)
249find_program(NETCDF_FORTRAN_COMPILER_FULL NAMES \${NETCDF_FORTRAN_COMPILER})
250if(NOT \${CMAKE_Fortran_COMPILER} STREQUAL \${NETCDF_FORTRAN_COMPILER_FULL} )
251   message(WARNING "Fortran compiler \"\${CMAKE_Fortran_COMPILER}\" does not match netCDF Fortran compiler \"\${NETCDF_FORTRAN_COMPILER_FULL}\".")
252else()
253   message(STATUS "Fortran compiler matches netCDF Fortran compiler.")
254endif()
255
256# extract subversion info
257if (${SVN_CMAKE_CHECK})
258find_package(Subversion)
259if(SUBVERSION_FOUND)
260   Subversion_WC_INFO(\${PROJECT_SOURCE_DIR}/../trunk PALM)
261   message(STATUS "Your \${PALM_PROGRAM_NAME} installation will be based on revision \${PALM_WC_REVISION}.")
262else(SUBVERSION_FOUND)
263   message(WARNING "Subversion not found. Wondering how you aquired the PALM code. :-)")
264endif(SUBVERSION_FOUND)
265endif()
266
267# check for fftw
268find_package(FFTW)
269if(FFTW_FOUND)
270   message(STATUS "\${PALM_PROGRAM_NAME} is using an external fftw library.")
271   list(APPEND PALM_CPP_OPTIONS __fftw)
272else(FFTW_FOUND)
273   message(STATUS "\${PALM_PROGRAM_NAME} is using the buildin fft algorithm.")
274endif(FFTW_FOUND)
275
276# compiler flag management
277if(\${CMAKE_Fortran_COMPILER_ID} STREQUAL "Cray")
278   set(PALM_COMPILER_OPTIONS "-em -K trap=fp -O3 -hnoomp -hnoacc -hfp3 -hdynamic")
279   set(PALM_LINKER_OPTIONS "\${PALM_COMPILER_OPTIONS} -dynamic")
280   set(PALM_CPP_FLAGS "-eZ")
281elseif(\${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
282   set(PALM_COMPILER_OPTIONS "-O3 -fp-model source -fno-alias -fpe0 -ftz -no-prec-div -no-prec-sqrt -ip -nbs -diag-disable 8290,8291")
283   set(PALM_LINKER_OPTIONS "\${PALM_COMPILER_OPTIONS}")
284   set(PALM_CPP_FLAGS "-cpp")
285   list(APPEND PALM_CPP_OPTIONS __intel_compiler)
286elseif(\${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU")
287   set(PALM_COMPILER_OPTIONS "-Ofast -ffree-line-length-none")
288   set(PALM_LINKER_OPTIONS "\${PALM_COMPILER_OPTIONS}")
289   set(PALM_CPP_FLAGS "-cpp")
290   list(APPEND PALM_CPP_OPTIONS __gfortran)
291endif()
292
293# workaround
294list(APPEND PALM_CPP_OPTIONS __parallel)
295
296# adding cpp options
297list(APPEND PALM_CPP_OPTIONS MPI_REAL=MPI_DOUBLE_PRECISION)
298list(APPEND PALM_CPP_OPTIONS MPI_2REAL=MPI_2DOUBLE_PRECISION)
299if(NETCDF_FOUND)
300   list(APPEND PALM_CPP_OPTIONS __netcdf)
301   set(PALM_COMPILER_OPTIONS "\${PALM_COMPILER_OPTIONS} -I \${NETCDF_INCLUDES}")
302   set(PALM_LINKER_OPTIONS "\${PALM_LINKER_OPTIONS} \${NETCDF_LIBRARIES}")
303   set(PALMTEST_NETCDF_INCLUDES "netcdf: \"-I \${NETCDF_INCLUDES}\"")
304   set(PALMTEST_NETCDF_LIBRARIES "netcdf: \"\${NETCDF_LIBRARIES}\"")
305endif()
306
307if(FFTW_FOUND)
308   set(PALM_COMPILER_OPTIONS "\${PALM_COMPILER_OPTIONS} -I \${FFTW_INCLUDES}")
309   set(PALM_LINKER_OPTIONS "\${PALM_LINKER_OPTIONS} \${FFTW_LIBRARIES}")
310   set(PALMTEST_FFTW_INCLUDES "fftw: \"-I \${FFTW_INCLUDES}\"")
311   set(PALMTEST_FFTW_LIBRARIES "fftw: \"\${FFTW_LIBRARIES}\"")
312endif()
313
314if(RRTMG_ROOT)
315   set(PALMTEST_RRTMG_INCLUDES "rrtmg: \"-I \${RRTMG_ROOT}/include\"")
316   set(PALMTEST_RRTMG_LIBRARIES "rrtmg: \"\${RRTMG_ROOT}/lib/librrtmg.so\"")
317endif()
318
319string(REPLACE ";" " -D" PALM_CPP_OPTIONS_STR_1 "\${PALM_CPP_OPTIONS}")
320set(PALM_CPP_OPTIONS_STR "\${PALM_CPP_FLAGS} -D\${PALM_CPP_OPTIONS_STR_1}")
321
322# configuring the .palm.config
323configure_file(\${config_in} \${config} @ONLY)
324
325# configuring the palmtest.yml
326configure_file(\${palmtest_in} \${palmtest} @ONLY)
327
328if(RRTMG_ROOT)
329   # configuring the build_rrtmg
330   configure_file(\${build_rrtmg_in} \${build_rrtmg} @ONLY)
331endif()
332
333EOF
334
335   cat > ${source_dir}/FindFFTW.cmake << EOF
336# - Find FFTW
337# Find the native FFTW includes and library
338#
339#  FFTW_INCLUDES    - where to find fftw3.h
340#  FFTW_LIBRARIES   - List of libraries when using FFTW.
341#  FFTW_FOUND       - True if FFTW found.
342
343if (FFTW_INCLUDES)
344  # Already in cache, be silent
345  set (FFTW_FIND_QUIETLY TRUE)
346endif (FFTW_INCLUDES)
347
348#exec_program(sed ARGS -i '/%fftw_inc.*/d' \${config})
349#list(APPEND NETCDF_HINTS "\$ENV{LD_LIBRARY_PATH}")
350
351find_path (FFTW_INCLUDES fftw3.f03 HINTS \${NETCDF_HINTS} ENV LD_LIBRARY_PATH  PATH_SUFFIXES include Include)
352find_library(NETCDF_FORTRAN_LIB netcdff HINTS \${NETCDF_HINTS} ENV LD_LIBRARY_PATH PATH_SUFFIXES lib lib64)
353
354find_library (FFTW_LIBRARIES NAMES fftw3)
355
356# handle the QUIETLY and REQUIRED arguments and set FFTW_FOUND to TRUE if
357# all listed variables are TRUE
358include (FindPackageHandleStandardArgs)
359find_package_handle_standard_args (FFTW DEFAULT_MSG FFTW_LIBRARIES FFTW_INCLUDES)
360
361mark_as_advanced (FFTW_LIBRARIES FFTW_INCLUDES)
362
363EOF
364
365   cat > ${source_dir}/FindNetCDF.cmake << EOF
366# - Find NetCDF
367# Find the native NetCDF includes and library
368#
369#  NETCDF_INCLUDES    - where to find netcdf.h, etc
370#  NETCDF_LIBRARIES   - Link these libraries when using NetCDF
371#  NETCDF_FOUND       - True if NetCDF found including required interfaces (see below)
372#
373# Your package can require certain interfaces to be FOUND by setting these
374#
375#  NETCDF_C           - require the C interface and link the C library
376#  NETCDF_CXX         - require the C++ interface and link the C++ library
377#  NETCDF_FORTRAN     - require the Fortran interface and link the Fortran library
378#
379# The following are not for general use and are included in
380# NETCDF_LIBRARIES if the corresponding option above is set.
381#
382#  NETCDF_LIBRARIES_C        - Just the C interface
383#  NETCDF_LIBRARIES_CXX      - C++ interface, if available
384#  NETCDF_LIBRARIES_FORTRAN  - Fortran 90 interface, if available
385#
386# Normal usage would be:
387#  set (NETCDF_FORTRAN "YES")
388#  find_package (NetCDF REQUIRED)
389#  target_link_libraries (uses_f90_interface \${NETCDF_LIBRARIES})
390
391if (NETCDF_INCLUDES AND NETCDF_LIBRARIES)
392  # Already in cache, be silent
393  set (NETCDF_FIND_QUIETLY TRUE)
394endif (NETCDF_INCLUDES AND NETCDF_LIBRARIES)
395
396
397macro(NETCDF_CONFIG flag output)
398    if(NETCDF_CONFIG_EXECUTABLE)
399        exec_program( \${NETCDF_CONFIG_EXECUTABLE} ARGS \${flag}
400            OUTPUT_VARIABLE \${output} RETURN_VALUE return_value)
401        if(NOT \${return_value} EQUAL 0 )
402            message( STATUS "Unable to determine \${flag} from \${NETCDF_CONFIG_EXECUTABLE}." )
403        endif()
404    endif(NETCDF_CONFIG_EXECUTABLE)
405endmacro()
406
407if(NETCDF_C_ROOT)
408   list(APPEND NETCDF_HINTS "\${NETCDF_C_ROOT}")
409else()
410   list(APPEND NETCDF_HINTS "\$ENV{NETCDF_ROOT}")
411endif()
412
413if(NETCDF_FORTRAN_ROOT)
414   list(APPEND NETCDF_HINTS "\${NETCDF_FORTRAN_ROOT}")
415else()
416   list(APPEND NETCDF_HINTS "\$ENV{NETCDF_ROOT}")
417endif()
418
419if(NETCDF_C_ROOT)
420   find_program(NETCDF_C_CONFIG_EXECUTABLE NAMES nc-config
421      HINTS \${NETCDF_HINTS} PATH_SUFFIXES bin Bin NO_DEFAULT_PATH
422      DOC "NETCDF CONFIG PROGRAM. Used to detect NETCDF compile flags." )
423else()
424   find_program(NETCDF_C_CONFIG_EXECUTABLE NAMES nc-config
425      HINTS \${NETCDF_HINTS} PATH_SUFFIXES bin Bin
426      DOC "NETCDF CONFIG PROGRAM. Used to detect NETCDF compile flags." )
427endif()
428
429set(NETCDF_CONFIG_EXECUTABLE \${NETCDF_C_CONFIG_EXECUTABLE})
430   if(NETCDF_C_CONFIG_EXECUTABLE)
431      NETCDF_CONFIG(--cc NETCDF_C_COMPILER_C)
432      NETCDF_CONFIG(--fc NETCDF_C_COMPILER_FORTRAN)
433      NETCDF_CONFIG(--prefix NETCDF_C_ROOT)
434      NETCDF_CONFIG(--includedir NETCDF_C_INCLUDE)
435      NETCDF_CONFIG(--version NETCDF_C_VERSION)
436      #NETCDF_CONFIG(--has-c++ NETCDF_C_CXX)
437      #NETCDF_CONFIG(--has-f77 NETCDF_C_F77)
438      NETCDF_CONFIG(--has-f90 NETCDF_C_F90)
439      #NETCDF_CONFIG(--has-dap NETCDF_C_DAP)
440      #NETCDF_CONFIG(--has-nc2 NETCDF_C_NC2)
441      #NETCDF_CONFIG(--has-nc4 NETCDF_C_NC4)
442      #NETCDF_CONFIG(--has-hdf4 NETCDF_C_HDF4)
443      #NETCDF_CONFIG(--has-hdf5 NETCDF_C_HDF5)
444      #NETCDF_CONFIG(--has-pnetcdf NETCDF_C_PARALLEL)
445      list(APPEND NETCDF_INCLUDE_HINTS "\${NETCDF_C_INCLUDE}")
446      list(APPEND NETCDF_HINTS "\${NETCDF_C_ROOT}")
447      message(STATUS "Found \${NETCDF_C_VERSION} compiled with \${NETCDF_C_COMPILER_C}")
448   else(NETCDF_C_CONFIG_EXECUTABLE)
449      message(STATUS "nc-config not found")
450   endif(NETCDF_C_CONFIG_EXECUTABLE)
451
452if(NETCDF_C_ROOT AND NETCDF_FORTRAN_ROOT)
453   find_program(NETCDF_FORTRAN_CONFIG_EXECUTABLE NAMES nf-config
454       HINTS \${NETCDF_HINTS} PATH_SUFFIXES bin Bin NO_DEFAULT_PATH
455       DOC "NETCDF CONFIG PROGRAM. Used to detect NETCDF compile flags." )
456else()
457   find_program(NETCDF_FORTRAN_CONFIG_EXECUTABLE NAMES nf-config
458       HINTS \${NETCDF_HINTS} PATH_SUFFIXES bin Bin
459       DOC "NETCDF CONFIG PROGRAM. Used to detect NETCDF compile flags." )
460endif()
461
462set(NETCDF_CONFIG_EXECUTABLE \${NETCDF_FORTRAN_CONFIG_EXECUTABLE})
463   if(NETCDF_FORTRAN_CONFIG_EXECUTABLE)
464      NETCDF_CONFIG(--cc NETCDF_FORTRAN_COMPILER_C)
465      NETCDF_CONFIG(--fc NETCDF_FORTRAN_COMPILER_FORTRAN)
466      NETCDF_CONFIG(--prefix NETCDF_FORTRAN_ROOT)
467      NETCDF_CONFIG(--includedir NETCDF_FORTRAN_INCLUDE)
468      NETCDF_CONFIG(--version NETCDF_FORTRAN_VERSION)
469      #NETCDF_CONFIG(--has-c++ NETCDF_FORTRAN_CXX)
470      #NETCDF_CONFIG(--has-f77 NETCDF_FORTRAN_F77)
471      NETCDF_CONFIG(--has-f90 NETCDF_FORTRAN_F90)
472      #NETCDF_CONFIG(--has-dap NETCDF_FORTRAN_DAP)
473      #NETCDF_CONFIG(--has-nc2 NETCDF_FORTRAN_NC2)
474      #NETCDF_CONFIG(--has-nc4 NETCDF_FORTRAN_NC4)
475      #NETCDF_CONFIG(--has-hdf4 NETCDF_FORTRAN_HDF4)
476      #NETCDF_CONFIG(--has-hdf5 NETCDF_FORTRAN_HDF5)
477      #NETCDF_CONFIG(--has-pnetcdf NETCDF_FORTRAN_PARALLEL)
478      list(APPEND NETCDF_INCLUDE_HINTS "\${NETCDF_FORTRAN_INCLUDE}")
479      list(APPEND NETCDF_HINTS "\${NETCDF_FORTRAN_ROOT}")
480      message(STATUS "Found \${NETCDF_FORTRAN_VERSION} compiled with \${NETCDF_FORTRAN_COMPILER_FORTRAN}")
481   else(NETCDF_FORTRAN_CONFIG_EXECUTABLE)
482      #message(STATUS "nf-config not found")
483      set(NETCDF_FORTRAN_COMPILER_C \${NETCDF_C_COMPILER_C})
484      set(NETCDF_FORTRAN_COMPILER_FORTRAN \${NETCDF_C_COMPILER_FORTRAN})
485      set(NETCDF_FORTRAN_ROOT \${NETCDF_C_ROOT})
486      set(NETCDF_FORTRAN_INCLUDE \${NETCDF_C_INCLUDE})
487      set(NETCDF_FORTRAN_VERSION \${NETCDF_C_VERSION})
488      #set(NETCDF_FORTRAN_CXX \${NETCDF_C_CXX})
489      #set(NETCDF_FORTRAN_F77 \${NETCDF_C_F77})
490      set(NETCDF_FORTRAN_F90 \${NETCDF_C_F90})
491      #set(NETCDF_FORTRAN_DAP \${NETCDF_C_DAP})
492      #set(NETCDF_FORTRAN_NC2 \${NETCDF_C_NC2})
493      #set(NETCDF_FORTRAN_NC4 \${NETCDF_C_NC4})
494      #set(NETCDF_FORTRAN_HDF4 \${NETCDF_C_HDF4})
495      #set(NETCDF_FORTRAN_HDF5 \${NETCDF_C_HDF5})
496      #set(NETCDF_FORTRAN_PARALLEL \${NETCDF_C_PARALLEL})
497      if(NETCDF_FORTRAN_F90)
498         message(STATUS "Found \${NETCDF_FORTRAN_VERSION} compiled with \${NETCDF_FORTRAN_COMPILER_FORTRAN}")
499      else(NETCDF_FORTRAN_F90)
500         message(STATUS "nc-config found no netCDF Fortran libraries")
501      endif(NETCDF_FORTRAN_F90)
502   endif(NETCDF_FORTRAN_CONFIG_EXECUTABLE)
503
504# find netcdf c
505if(NOT NETCDF_C_INCLUDE)
506   find_path(NETCDF_C_INCLUDE netcdf.h HINTS \${NETCDF_HINTS} PATH_SUFFIXES include Include)
507endif()
508find_library(NETCDF_C_LIB netcdf HINTS \${NETCDF_HINTS} PATH_SUFFIXES lib lib64)
509#message(STATUS "NETCDF_C_INCLUDE so far: \${NETCDF_C_INCLUDE}")
510#message(STATUS "NETCDF_C_LIB so far: \${NETCDF_C_LIB}")
511
512# find netcdf fortran
513if(NOT NETCDF_FORTRAN_INCLUDE)
514   find_path(NETCDF_FORTRAN_INCLUDE netcdf.mod HINTS \${NETCDF_HINTS} PATH_SUFFIXES include Include)
515endif()
516find_library(NETCDF_FORTRAN_LIB netcdff HINTS \${NETCDF_HINTS} PATH_SUFFIXES lib lib64)
517if(NOT NETCDF_FORTRAN_LIB)
518   find_library(NETCDF_FORTRAN_LIB netcdf HINTS \${NETCDF_HINTS} PATH_SUFFIXES lib lib64)
519endif()
520#message(STATUS "NETCDF_FORTRAN_INCLUDE so far: \${NETCDF_FORTRAN_INCLUDE}")
521#message(STATUS "NETCDF_FORTRAN_LIB so far: \${NETCDF_FORTRAN_LIB}")
522
523if ((NOT NETCDF_C_LIB) OR (NOT NETCDF_C_INCLUDE))
524   message(STATUS "Trying to find NetCDF using LD_LIBRARY_PATH (we're desperate)...")
525   file(TO_CMAKE_PATH "\$ENV{LD_LIBRARY_PATH}" LD_LIBRARY_PATH)
526   find_library(NETCDF_C_LIB NAMES netcdf HINTS \${LD_LIBRARY_PATH})
527
528   if (NETCDF_C_LIB)
529      get_filename_component(NETCDF_LIB_DIR \${NETCDF_C_LIB} PATH)
530      string(REGEX REPLACE "/lib/?\$" "/include" NETCDF_H_HINT \${NETCDF_LIB_DIR})
531      find_path (NETCDF_C_INCLUDE netcdf.h HINTS \${NETCDF_H_HINT} DOC "Path to netcdf.h")
532      message(STATUS "found netcdf.h in: \${NETCDF_C_INCLUDE}")
533      list(APPEND NETCDF_INCLUDE_HINTS "\${NETCDF_C_INCLUDE}")
534   endif()
535endif()
536
537get_filename_component (NETCDF_C_LIB_DIR "\${NETCDF_C_LIB}" PATH)
538get_filename_component (NETCDF_FORTRAN_LIB_DIR "\${NETCDF_FORTRAN_LIB}" PATH)
539list(APPEND NETCDF_LIB_HINTS "\${NETCDF_C_LIB_DIR}")
540list(APPEND NETCDF_LIB_HINTS "\${NETCDF_FORTRAN_LIB_DIR}")
541
542#message(STATUS "All include Hints: \${NETCDF_INCLUDE_HINTS}")
543#message(STATUS "All lib Hints: \${NETCDF_LIB_HINTS}")
544
545macro(NetCDF_add_interface lang)
546   if(NETCDF_\${lang})
547      if(NETCDF_\${lang}_INCLUDE AND NETCDF_\${lang}_LIB)
548         list(INSERT NetCDF_includes 0 \${NETCDF_\${lang}_INCLUDE})
549         list(INSERT NetCDF_libs 0 \${NETCDF_\${lang}_LIB}) # prepend so that -lnetcdf is last
550      else()
551         set(NetCDF_has_interfaces "NO")
552         message(STATUS "Failed to find NetCDF interface for \${lang}")
553      endif()
554   endif(NETCDF_\${lang})
555endmacro(NetCDF_add_interface)
556
557set(NetCDF_has_interfaces "YES") # will be set to NO if we're missing any interfaces
558NetCDF_add_interface(C)
559NetCDF_add_interface(CXX)
560NetCDF_add_interface(FORTRAN)
561
562# macro (NetCDF_check_interface lang header libs)
563#    if (NETCDF_\${lang})
564#       find_path (NETCDF_INCLUDES_\${lang} NAMES \${header} HINTS \${NETCDF_HINTS} PATH_SUFFIXES include Include NO_DEFAULT_PATH)
565#       find_library (NETCDF_LIBRARIES_\${lang} NAMES \${libs} HINTS \${NETCDF_HINTS} PATH_SUFFIXES lib lib64 NO_DEFAULT_PATH)
566#       mark_as_advanced (NETCDF_INCLUDES_\${lang} NETCDF_LIBRARIES_\${lang})
567#       if (NETCDF_INCLUDES_\${lang} AND NETCDF_LIBRARIES_\${lang})
568#          list (INSERT NetCDF_libs 0 \${NETCDF_LIBRARIES_\${lang}}) # prepend so that -lnetcdf is last
569#       else (NETCDF_INCLUDES_\${lang} AND NETCDF_LIBRARIES_\${lang})
570#          set (NetCDF_has_interfaces "NO")
571#          message (STATUS "Failed to find NetCDF interface for \${lang}")
572#       endif (NETCDF_INCLUDES_\${lang} AND NETCDF_LIBRARIES_\${lang})
573#    endif (NETCDF_\${lang})
574# endmacro (NetCDF_check_interface)
575#
576# set (NetCDF_has_interfaces "YES") # will be set to NO if we're missing any interfaces
577# NetCDF_check_interface (C netcdf.h netcdf)
578# NetCDF_check_interface (CXX netcdfcpp.h netcdf_c++)
579# NetCDF_check_interface (FORTRAN netcdf.mod  netcdff)
580
581set (NETCDF_C_COMPILER "\${NETCDF_C_COMPILER_C}" CACHE STRING "The C compiler used to build netCDF")
582set (NETCDF_FORTRAN_COMPILER "\${NETCDF_FORTRAN_COMPILER_FORTRAN}" CACHE STRING "The Fortran compiler used to build netCDF")
583set (NETCDF_INCLUDES "\${NetCDF_includes}" CACHE STRING "All NetCDF includes required for interface level")
584set (NETCDF_LIBRARIES "\${NetCDF_libs}" CACHE STRING "All NetCDF libraries required for interface level")
585
586# handle the QUIETLY and REQUIRED arguments and set NETCDF_FOUND to TRUE if
587# all listed variables are TRUE
588include (FindPackageHandleStandardArgs)
589find_package_handle_standard_args (NetCDF DEFAULT_MSG NETCDF_LIBRARIES NETCDF_INCLUDES NetCDF_has_interfaces)
590
591mark_as_advanced (NETCDF_LIBRARIES NETCDF_INCLUDES)
592
593#message(STATUS "netCDF library: \${NETCDF_LIBRARIES}")
594#message(STATUS "netCDF include: \${NETCDF_INCLUDES}")
595
596EOF
597
598   cat > ${source_dir}/.palmtest.yml.in << EOF
599---
600# this is a palmtest environments file
601
602palm_config_template:
603
604environments:
605
606  @CMAKE_Fortran_COMPILER_ID@:
607    executable: @CMAKE_Fortran_COMPILER@
608    mpi_wrapper: @MPI_Fortran_COMPILER@
609    include:
610      @PALMTEST_NETCDF_INCLUDES@
611      @PALMTEST_FFTW_INCLUDES@
612      @PALMTEST_RRTMG_INCLUDES@
613    lib:
614      @PALMTEST_NETCDF_LIBRARIES@
615      @PALMTEST_FFTW_LIBRARIES@
616      @PALMTEST_RRTMG_LIBRARIES@
617
618EOF
619
620   cat > ${source_dir}/build_rrtmg.in << EOF
621#!/usr/bin/env bash
622
623make -f Makefile F90=@MPI_Fortran_COMPILER@  PROG=librrtmg F90FLAGS="@PALM_COMPILER_OPTIONS@"
624
625EOF
626
627
628}
629
630################################################################################
631
632palm_installer_build
633palm_installer_set_path
634palm_installer_test_suite
635palm_post_installer_help
Note: See TracBrowser for help on using the repository browser.