Skip to content

Commit 2799c4f

Browse files
committed
optimize array decl
1 parent cdea264 commit 2799c4f

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

cmake/Modules/FindHDF5.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ if(NOT HDF5MPI_ROOT AND DEFINED ENV{HDF5MPI_ROOT})
688688
endif()
689689

690690
if(NOT HDF5_ROOT)
691-
if(HDF5MPI_ROOT)
691+
if(HDF5MPI_ROOT AND parallel IN_LIST HDF5_FIND_COMPONENTS)
692692
set(HDF5_ROOT ${HDF5MPI_ROOT})
693693
elseif(DEFINED ENV{HDF5_ROOT})
694694
set(HDF5_ROOT $ENV{HDF5_ROOT})

cmake/Modules/FindNetCDF.cmake

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,20 @@ if(PkgConfig_FOUND AND NOT NetCDF_Fortran_LIBRARY)
9898
endif()
9999

100100
find_path(NetCDF_Fortran_INCLUDE_DIR
101-
names netcdf.mod
102-
HINTS ${pc_ncf_INCLUDE_DIRS}
103-
DOC "NetCDF Fortran Include")
101+
names netcdf.mod
102+
HINTS ${pc_ncf_INCLUDE_DIRS}
103+
DOC "NetCDF Fortran Include"
104+
)
104105

105106
if(NOT NetCDF_Fortran_INCLUDE_DIR)
106107
return()
107108
endif()
108109

109110
find_library(NetCDF_Fortran_LIBRARY
110-
NAMES netcdff
111-
HINTS ${pc_ncf_LIBRARY_DIRS} ${pc_ncf_LIBDIR}
112-
DOC "NetCDF Fortran library")
111+
NAMES netcdff
112+
HINTS ${pc_ncf_LIBRARY_DIRS} ${pc_ncf_LIBDIR}
113+
DOC "NetCDF Fortran library"
114+
)
113115

114116
if(NOT NetCDF_Fortran_LIBRARY)
115117
return()
@@ -163,8 +165,10 @@ mark_as_advanced(NetCDF_C_INCLUDE_DIR NetCDF_Fortran_INCLUDE_DIR NetCDF_C_LIBRAR
163165

164166
include(FindPackageHandleStandardArgs)
165167
find_package_handle_standard_args(NetCDF
166-
REQUIRED_VARS _ncdf_req
167-
HANDLE_COMPONENTS)
168+
REQUIRED_VARS _ncdf_req
169+
HANDLE_COMPONENTS
170+
HANDLE_VERSION_RANGE
171+
)
168172

169173
if(NetCDF_FOUND)
170174
set(NetCDF_C_INCLUDE_DIRS ${NetCDF_C_INCLUDE_DIR})

cmake/netcdf.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ set(netcdf_c_cmake_args
4141
-DENABLE_DAP:BOOL=OFF
4242
-DENABLE_DAP2:BOOL=OFF
4343
-DENABLE_DAP4:BOOL=OFF
44+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
45+
-DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER}
4446
)
4547

4648
ExternalProject_Add(NETCDF_C

src/interface.f90

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,49 +66,49 @@ module subroutine nc_write_1d(self, dname, value, dims)
6666
class(netcdf_file), intent(in) :: self
6767
character(*), intent(in) :: dname
6868
class(*), intent(in) :: value(:)
69-
character(*), intent(in), optional :: dims(:)
69+
character(*), intent(in), optional :: dims(1)
7070
end subroutine nc_write_1d
7171

7272
module subroutine nc_write_2d(self, dname, value, dims)
7373
class(netcdf_file), intent(in) :: self
7474
character(*), intent(in) :: dname
7575
class(*), intent(in) :: value(:,:)
76-
character(*), intent(in), optional :: dims(:)
76+
character(*), intent(in), optional :: dims(2)
7777
end subroutine nc_write_2d
7878

7979
module subroutine nc_write_3d(self, dname, value, dims)
8080
class(netcdf_file), intent(in) :: self
8181
character(*), intent(in) :: dname
8282
class(*), intent(in) :: value(:,:,:)
83-
character(*), intent(in), optional :: dims(:)
83+
character(*), intent(in), optional :: dims(3)
8484
end subroutine nc_write_3d
8585

8686
module subroutine nc_write_4d(self, dname, value, dims)
8787
class(netcdf_file), intent(in) :: self
8888
character(*), intent(in) :: dname
8989
class(*), intent(in) :: value(:,:,:,:)
90-
character(*), intent(in), optional :: dims(:)
90+
character(*), intent(in), optional :: dims(4)
9191
end subroutine nc_write_4d
9292

9393
module subroutine nc_write_5d(self, dname, value, dims)
9494
class(netcdf_file), intent(in) :: self
9595
character(*), intent(in) :: dname
9696
class(*), intent(in) :: value(:,:,:,:,:)
97-
character(*), intent(in), optional :: dims(:)
97+
character(*), intent(in), optional :: dims(5)
9898
end subroutine nc_write_5d
9999

100100
module subroutine nc_write_6d(self, dname, value, dims)
101101
class(netcdf_file), intent(in) :: self
102102
character(*), intent(in) :: dname
103103
class(*), intent(in) :: value(:,:,:,:,:,:)
104-
character(*), intent(in), optional :: dims(:)
104+
character(*), intent(in), optional :: dims(6)
105105
end subroutine nc_write_6d
106106

107107
module subroutine nc_write_7d(self, dname, value, dims)
108108
class(netcdf_file), intent(in) :: self
109109
character(*), intent(in) :: dname
110110
class(*), intent(in) :: value(:,:,:,:,:,:,:)
111-
character(*), intent(in), optional :: dims(:)
111+
character(*), intent(in), optional :: dims(7)
112112
end subroutine nc_write_7d
113113

114114
end interface

src/reader_template.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
ier = nf90_inquire_variable(self%ncid, varid, ndims=drank)
99
if(drank /= rank(value)) then
10-
ier = NF90_EDIMSIZE
11-
write(stderr,*) 'ERROR: ' // dname // ' rank ', drank, ' /= variable rank ',rank(value)
12-
return
10+
write(stderr,*) 'ERROR:nc4fortran:read ' // dname // ' rank ', drank, ' /= variable rank ',rank(value)
11+
error stop
1312
endif
1413
if (check_error(ier, dname)) error stop 'nc4fortran:read inquire ' // dname // ' in ' // self%filename
1514

src/tests/test_array.f90

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ subroutine test_basic_array()
6969
call h%read('int32-2d', i2_8(2:5,3:6))
7070
if (.not.all(i2_8(2:5,3:6) == i2)) error stop 'read into larger array fail'
7171

72-
!> check error for reading array dimension mismatch
73-
74-
!> check that 1D disk into 2D raises error
75-
call h%read('int32-1d', i2)
76-
7772
!> real
7873
call h%shape('real32-2d',dims)
7974
allocate(rr2(dims(1), dims(2)))

src/tests/test_exist.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ subroutine test_exist()
3939
call h%close()
4040
if(.not.is_netcdf(fn)) error stop 'file does not exist'
4141

42-
call h%open(fn)
42+
call h%open(fn, "r")
4343
if (.not.h%is_open) error stop 'file is open'
4444
if (.not. h%exist('x')) error stop 'x exists'
4545

0 commit comments

Comments
 (0)