Skip to content

Commit

Permalink
Merge pull request #410 from Roy-KC/build-win32
Browse files Browse the repository at this point in the history
Fix Stack Overflow problem by moving large arrays from the stack to the heap
  • Loading branch information
WardF authored Apr 23, 2024
2 parents 7e13971 + 70583c9 commit 6302daa
Show file tree
Hide file tree
Showing 11 changed files with 566 additions and 455 deletions.
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#Minimum required CMake Version
cmake_minimum_required(VERSION 3.12.0)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

#Project Name for netCDF-Fortran
PROJECT (NC4F
LANGUAGES C Fortran
Expand Down Expand Up @@ -175,6 +177,12 @@ IF(NOT ENABLE_COVERAGE_TESTS)
string(APPEND CMAKE_C_FLAGS " -O2")
ENDIF()

IF(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
IF(MSVC)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /heap-arrays:1")
ENDIF()
ENDIF()

# Supress CRT Warnings.
# Only necessary for Windows
IF(MSVC)
Expand Down Expand Up @@ -326,7 +334,7 @@ ENDMACRO()
# CRT libs, MT tells VS to use the static CRT libs.
#
# Taken From:
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
#
MACRO(specify_static_crt_flag)

Expand Down Expand Up @@ -472,6 +480,7 @@ IF (NETCDF_C_INCLUDE_DIR)
string(REGEX MATCH "[01]" USE_NETCDF4 "${macrodef}")
IF (USE_NETCDF4)
MESSAGE(STATUS "Whether NetCDF-C built with HDF5 enabled: yes")
FIND_PACKAGE(HDF5 COMPONENTS C HL REQUIRED)
ELSE()
MESSAGE(STATUS "Whether NetCDF-C built with HDF5 enabled: no")
ENDIF()
Expand Down Expand Up @@ -629,7 +638,7 @@ CHECK_LIBRARY_EXISTS(${NETCDF_C_LIBRARY} oc_open "" BUILD_DAP)
###
# Check to see if szip write capability is present in netcdf-c.
###
SET(CMAKE_REQUIRED_INCLUDES ${NETCDF_INCLUDE_DIR})
SET(CMAKE_REQUIRED_INCLUDES ${NETCDF_C_INCLUDE_DIR})
CHECK_C_SOURCE_COMPILES("
#include <netcdf_meta.h>
#if !NC_HAS_SZIP_WRITE
Expand All @@ -640,7 +649,7 @@ int main() {return 0;}" HAVE_SZIP_WRITE)
###
# Check to see if quantize capability is present in netcdf-c.
###
SET(CMAKE_REQUIRED_INCLUDES ${NETCDF_INCLUDE_DIR})
SET(CMAKE_REQUIRED_INCLUDES ${NETCDF_C_INCLUDE_DIR})
CHECK_C_SOURCE_COMPILES("
#include <netcdf_meta.h>
#if !NC_HAS_QUANTIZE
Expand Down Expand Up @@ -672,7 +681,7 @@ endif()
OPTION(DISABLE_ZSTANDARD_PLUGIN "Disable ZStandard plugin detection and functionality, even if libnetcdf was compiled with plugin support" OFF)

IF(NOT DISABLE_ZSTANDARD_PLUGIN)
SET(CMAKE_REQUIRED_INCLUDES ${NETCDF_INCLUDE_DIR})
SET(CMAKE_REQUIRED_INCLUDES ${NETCDF_C_INCLUDE_DIR})
CHECK_C_SOURCE_COMPILES("
#include <netcdf_meta.h>
#if !NC_HAS_ZSTD
Expand Down
42 changes: 23 additions & 19 deletions fortran/gen.m4
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
define(NVES, dnl
`define(`NUMDIMS',0)dnl # not used, but permits sharing f90aux.m4
`define(`NUMDIMS',0)dnl # not used, but permits sharing f90aux.m4
define(`KINDVALUE',$1)dnl
define(`PUTORGET', $2)dnl
include(f90aux.m4)dnl
include(nves.m4)
')dnl

define(NVESPUT48, dnl
`define(`NUMDIMS',0)dnl # not used, but permits sharing f90aux.m4
`define(`NUMDIMS',0)dnl # not used, but permits sharing f90aux.m4
define(`KINDVALUE',$1)dnl
define(`PUTORGET', $2)dnl
include(f90aux.m4)dnl
include(nvesput48.m4)
')dnl

define(NVESGET48, dnl
`define(`NUMDIMS',0)dnl # not used, but permits sharing f90aux.m4
`define(`NUMDIMS',0)dnl # not used, but permits sharing f90aux.m4
define(`KINDVALUE',$1)dnl
define(`PUTORGET', $2)dnl
include(f90aux.m4)dnl
Expand Down Expand Up @@ -49,13 +49,11 @@ include(nveaget48.m4)
NVES(OneByteInt, put)
NVES(TwoByteInt, put)
NVESPUT48(FourByteInt, put)
NVESPUT48(EightByteInt, put)
NVES(FourByteReal, put)
NVES(EightByteReal, put)
NVES(OneByteInt, get)
NVES(TwoByteInt, get)
NVESGET48(FourByteInt, get)
NVESGET48(EightByteInt, get)
NVES(FourByteReal, get)
NVES(EightByteReal, get)

Expand All @@ -80,13 +78,6 @@ NVEAPUT48(4, FourByteInt, put)
NVEAPUT48(5, FourByteInt, put)
NVEAPUT48(6, FourByteInt, put)
NVEAPUT48(7, FourByteInt, put)
NVEAPUT48(1, EightByteInt, put)
NVEAPUT48(2, EightByteInt, put)
NVEAPUT48(3, EightByteInt, put)
NVEAPUT48(4, EightByteInt, put)
NVEAPUT48(5, EightByteInt, put)
NVEAPUT48(6, EightByteInt, put)
NVEAPUT48(7, EightByteInt, put)
NVEA(1, FourByteReal, put)
NVEA(2, FourByteReal, put)
NVEA(3, FourByteReal, put)
Expand Down Expand Up @@ -122,13 +113,6 @@ NVEAGET48(4, FourByteInt, get)
NVEAGET48(5, FourByteInt, get)
NVEAGET48(6, FourByteInt, get)
NVEAGET48(7, FourByteInt, get)
NVEAGET48(1, EightByteInt, get)
NVEAGET48(2, EightByteInt, get)
NVEAGET48(3, EightByteInt, get)
NVEAGET48(4, EightByteInt, get)
NVEAGET48(5, EightByteInt, get)
NVEAGET48(6, EightByteInt, get)
NVEAGET48(7, EightByteInt, get)
NVEA(1, FourByteReal, get)
NVEA(2, FourByteReal, get)
NVEA(3, FourByteReal, get)
Expand All @@ -143,3 +127,23 @@ NVEA(4, EightByteReal, get)
NVEA(5, EightByteReal, get)
NVEA(6, EightByteReal, get)
NVEA(7, EightByteReal, get)

NVEAPUT48(1, EightByteInt, put)
NVEAPUT48(2, EightByteInt, put)
NVEAPUT48(3, EightByteInt, put)
NVEAPUT48(4, EightByteInt, put)
NVEAPUT48(5, EightByteInt, put)
NVEAPUT48(6, EightByteInt, put)
NVEAPUT48(7, EightByteInt, put)

NVEAGET48(1, EightByteInt, get)
NVEAGET48(2, EightByteInt, get)
NVEAGET48(3, EightByteInt, get)
NVEAGET48(4, EightByteInt, get)
NVEAGET48(5, EightByteInt, get)
NVEAGET48(6, EightByteInt, get)
NVEAGET48(7, EightByteInt, get)

NVESPUT48(EightByteInt, put)
NVESGET48(EightByteInt, get)

Loading

0 comments on commit 6302daa

Please sign in to comment.