Skip to content

Commit bfca19a

Browse files
committed
ncid => file_id
1 parent 666c730 commit bfca19a

File tree

10 files changed

+102
-103
lines changed

10 files changed

+102
-103
lines changed

src/attributes.f90

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111

1212
if(.not.self%is_open) error stop 'nc4fortran:write_attribute: file handle not open'
1313

14-
ier = nf90_inq_varid(self%ncid, dname, varid)
14+
ier = nf90_inq_varid(self%file_id, dname, varid)
1515

1616
if(ier == nf90_noerr) then
1717
select type(value)
1818
type is (character(*))
19-
ier = nf90_put_att(self%ncid, varid, attrname, value)
19+
ier = nf90_put_att(self%file_id, varid, attrname, value)
2020
type is (real(real32))
21-
ier = nf90_put_att(self%ncid, varid, attrname, value)
21+
ier = nf90_put_att(self%file_id, varid, attrname, value)
2222
type is (real(real64))
23-
ier = nf90_put_att(self%ncid, varid, attrname, value)
23+
ier = nf90_put_att(self%file_id, varid, attrname, value)
2424
type is (integer(int32))
25-
ier = nf90_put_att(self%ncid, varid, attrname, value)
25+
ier = nf90_put_att(self%file_id, varid, attrname, value)
2626
class default
2727
ier = NF90_EBADTYPE
2828
end select
@@ -38,18 +38,18 @@
3838

3939
if(.not.self%is_open) error stop 'nc4fortran:read_attribute: file handle not open'
4040

41-
ier = nf90_inq_varid(self%ncid, dname, varid)
41+
ier = nf90_inq_varid(self%file_id, dname, varid)
4242

4343
if(ier == nf90_noerr) then
4444
select type (value)
4545
type is (character(*))
46-
ier = nf90_get_att(self%ncid, varid, attrname, value)
46+
ier = nf90_get_att(self%file_id, varid, attrname, value)
4747
type is (real(real32))
48-
ier = nf90_get_att(self%ncid, varid, attrname, value)
48+
ier = nf90_get_att(self%file_id, varid, attrname, value)
4949
type is (real(real64))
50-
ier = nf90_get_att(self%ncid, varid, attrname, value)
50+
ier = nf90_get_att(self%file_id, varid, attrname, value)
5151
type is (integer(int32))
52-
ier = nf90_get_att(self%ncid, varid, attrname, value)
52+
ier = nf90_get_att(self%file_id, varid, attrname, value)
5353
class default
5454
ier = NF90_EBADTYPE
5555
end select

src/interface.f90

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module nc4fortran
2121
type :: netcdf_file
2222

2323
character(:), allocatable :: filename
24-
integer :: ncid !< location identifier
24+
integer :: file_id !< location identifier
2525

2626
integer :: comp_lvl = 0 !< compression level (1-9) 0: disable compression
2727
logical :: verbose = .false.
@@ -201,46 +201,53 @@ module subroutine nc_read_scalar(self, dname, value)
201201
!! inout for character
202202
end subroutine
203203

204-
module subroutine nc_read_1d(self, dname, value)
204+
module subroutine nc_read_1d(self, dname, value, istart, iend)
205205
class(netcdf_file), intent(in) :: self
206206
character(*), intent(in) :: dname
207207
class(*), intent(inout) :: value(:)
208+
integer, intent(in), dimension(1), optional :: istart, iend
208209
end subroutine
209210

210-
module subroutine nc_read_2d(self, dname, value)
211+
module subroutine nc_read_2d(self, dname, value, istart, iend)
211212
class(netcdf_file), intent(in) :: self
212213
character(*), intent(in) :: dname
213214
class(*), intent(inout) :: value(:,:)
215+
integer, intent(in), dimension(2), optional :: istart, iend
214216
end subroutine
215217

216-
module subroutine nc_read_3d(self, dname, value)
218+
module subroutine nc_read_3d(self, dname, value, istart, iend)
217219
class(netcdf_file), intent(in) :: self
218220
character(*), intent(in) :: dname
219221
class(*), intent(inout) :: value(:,:,:)
222+
integer, intent(in), dimension(3), optional :: istart, iend
220223
end subroutine
221224

222-
module subroutine nc_read_4d(self, dname, value)
225+
module subroutine nc_read_4d(self, dname, value, istart, iend)
223226
class(netcdf_file), intent(in) :: self
224227
character(*), intent(in) :: dname
225228
class(*), intent(inout) :: value(:,:,:,:)
229+
integer, intent(in), dimension(4), optional :: istart, iend
226230
end subroutine
227231

228-
module subroutine nc_read_5d(self, dname, value)
232+
module subroutine nc_read_5d(self, dname, value, istart, iend)
229233
class(netcdf_file), intent(in) :: self
230234
character(*), intent(in) :: dname
231235
class(*), intent(inout) :: value(:,:,:,:,:)
236+
integer, intent(in), dimension(5), optional :: istart, iend
232237
end subroutine
233238

234-
module subroutine nc_read_6d(self, dname, value)
239+
module subroutine nc_read_6d(self, dname, value, istart, iend)
235240
class(netcdf_file), intent(in) :: self
236241
character(*), intent(in) :: dname
237242
class(*), intent(inout) :: value(:,:,:,:,:,:)
243+
integer, intent(in), dimension(6), optional :: istart, iend
238244
end subroutine
239245

240-
module subroutine nc_read_7d(self, dname, value)
246+
module subroutine nc_read_7d(self, dname, value, istart, iend)
241247
class(netcdf_file), intent(in) :: self
242248
character(*), intent(in) :: dname
243249
class(*), intent(inout) :: value(:,:,:,:,:,:,:)
250+
integer, intent(in), dimension(7), optional :: istart, iend
244251
end subroutine
245252

246253
end interface

src/read.f90

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
chunk_size = -1
1616

17-
i = nf90_inq_varid(self%ncid, dname, varid)
17+
i = nf90_inq_varid(self%file_id, dname, varid)
1818
if (i/=NF90_NOERR) error stop 'ERROR:nc4fortran:chunk: cannot find variable: ' // dname
1919

20-
i = nf90_inquire_variable(self%ncid, varid, contiguous=contig)
20+
i = nf90_inquire_variable(self%file_id, varid, contiguous=contig)
2121
if (i/=NF90_NOERR) error stop 'ERROR:nc4fortran:chunk: cannot get variable properties' // dname
2222

2323
if(contig) return
24-
i = nf90_inquire_variable(self%ncid, varid, chunksizes=chunk_size)
24+
i = nf90_inquire_variable(self%file_id, varid, chunksizes=chunk_size)
2525
if (i/=NF90_NOERR) error stop 'ERROR:nc4fortran:chunk: cannot get variable properties' // dname
2626

2727
end procedure get_chunk
@@ -34,14 +34,14 @@
3434

3535
get_deflate = .false.
3636

37-
i = nf90_inq_varid(self%ncid, dname, varid)
37+
i = nf90_inq_varid(self%file_id, dname, varid)
3838
if (i/=NF90_NOERR) error stop 'ERROR:nc4fortran:get_deflate: cannot find variable: ' // dname
3939

40-
i = nf90_inquire_variable(self%ncid, varid, contiguous=contig)
40+
i = nf90_inquire_variable(self%file_id, varid, contiguous=contig)
4141
if (i/=NF90_NOERR) error stop 'ERROR:nc4fortran:get_deflate: cannot get variable properties' // dname
4242

4343
if(contig) return
44-
i = nf90_inquire_variable(self%ncid, varid, deflate_level=deflate_level)
44+
i = nf90_inquire_variable(self%file_id, varid, deflate_level=deflate_level)
4545
if (i/=NF90_NOERR) error stop 'ERROR:nc4fortran:get_deflate: cannot get variable properties' // dname
4646

4747
get_deflate = deflate_level /= 0
@@ -56,10 +56,10 @@
5656

5757
drank = -1
5858

59-
ierr = nf90_inq_varid(self%ncid, dname, varid)
59+
ierr = nf90_inq_varid(self%file_id, dname, varid)
6060
if(ierr/=NF90_NOERR) error stop 'ERROR:nc4fortran:get_ndim: could not get variable ID for ' // dname
6161

62-
ierr = nf90_inquire_variable(self%ncid, varid, ndims=drank)
62+
ierr = nf90_inquire_variable(self%file_id, varid, ndims=drank)
6363
if(ierr/=NF90_NOERR) error stop 'ERROR:nc4fortran:get_ndim: could not get rank for ' // dname
6464

6565
end procedure get_ndim
@@ -75,19 +75,19 @@
7575

7676
allocate(dimids(N), dims(N))
7777

78-
ier = nf90_inq_varid(self%ncid, dname, varid)
78+
ier = nf90_inq_varid(self%file_id, dname, varid)
7979
if(check_error(ier, dname)) error stop 'ERROR:nc4fortran:get_shape: could not get variable ID for: ' // dname
8080

81-
ier = nf90_inquire_variable(self%ncid, varid, dimids = dimids)
81+
ier = nf90_inquire_variable(self%file_id, varid, dimids = dimids)
8282
if(check_error(ier, dname)) error stop 'ERROR:nc4fortran:get_shape: could not get dimension IDs for: ' // dname
8383

8484
if (present(dimnames)) allocate(tempnames(N))
8585

8686
do i = 1,N
8787
if(present(dimnames)) then
88-
ier = nf90_inquire_dimension(self%ncid, dimid=dimids(i), name=tempnames(i), len=dims(i))
88+
ier = nf90_inquire_dimension(self%file_id, dimid=dimids(i), name=tempnames(i), len=dims(i))
8989
else
90-
ier = nf90_inquire_dimension(self%ncid, dimid=dimids(i), len=dims(i))
90+
ier = nf90_inquire_dimension(self%file_id, dimid=dimids(i), len=dims(i))
9191
endif
9292
if(ier/=NF90_NOERR) error stop 'ERROR:nc4fortran:get_shape: querying dimension size'
9393
enddo
@@ -107,7 +107,7 @@
107107

108108
if(.not.self%is_open) error stop 'ERROR:nc4fortran:exist: file handle not open '
109109

110-
ierr = nf90_inq_varid(self%ncid, dname, varid)
110+
ierr = nf90_inq_varid(self%file_id, dname, varid)
111111

112112
select case (ierr)
113113
case (NF90_NOERR)

src/read_scalar.f90

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@
1212

1313
if(.not.self%is_open) error stop 'ERROR:nc4fortran:reader file handle not open'
1414

15-
ier = nf90_inq_varid(self%ncid, dname, varid)
15+
ier = nf90_inq_varid(self%file_id, dname, varid)
1616
if (check_error(ier, dname)) error stop 'ERROR:nc4fortran:read inquire_id ' // dname // ' in ' // self%filename
1717

1818
select type (value)
1919
type is (character(*))
2020
!! NetCDF4 requires knowing the exact character length as if it were an array without fill values
2121
!! HDF5 is not this strict; having a longer string variable than disk variable is OK in HDF5, but not NetCDF4
22-
ier = nf90_inquire_variable(self%ncid, varid, dimids = dimids)
22+
ier = nf90_inquire_variable(self%file_id, varid, dimids = dimids)
2323
if(check_error(ier, dname)) error stop 'ERROR:nc4fortran:read_scalar: could not get dimension IDs for: ' // dname
2424

25-
ier = nf90_inquire_dimension(self%ncid, dimid=dimids(1), len=dims)
25+
ier = nf90_inquire_dimension(self%file_id, dimid=dimids(1), len=dims)
2626
if(ier/=NF90_NOERR) error stop 'ERROR:nc4fortran:read_scalar: querying dimension size'
2727

2828
allocate(character(dims) :: buf)
29-
ier = nf90_get_var(self%ncid, varid, buf)
29+
ier = nf90_get_var(self%file_id, varid, buf)
3030
i = index(buf, c_null_char) - 1
3131
if(i == -1) i = len_trim(buf)
3232
value = buf(:i)
3333
type is (real(real64))
34-
ier = nf90_get_var(self%ncid, varid, value)
34+
ier = nf90_get_var(self%file_id, varid, value)
3535
type is (real(real32))
36-
ier = nf90_get_var(self%ncid, varid, value)
36+
ier = nf90_get_var(self%file_id, varid, value)
3737
type is (integer(int64))
38-
ier = nf90_get_var(self%ncid, varid, value)
38+
ier = nf90_get_var(self%file_id, varid, value)
3939
type is (integer(int32))
40-
ier = nf90_get_var(self%ncid, varid, value)
40+
ier = nf90_get_var(self%file_id, varid, value)
4141
class default
4242
ier = NF90_EBADTYPE
4343
end select

src/reader.inc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ integer :: varid, ier, drank
22

33
if(.not.self%is_open) error stop 'nc4fortran:reader file handle not open'
44

5-
ier = nf90_inq_varid(self%ncid, dname, varid)
5+
ier = nf90_inq_varid(self%file_id, dname, varid)
66
if (check_error(ier, dname)) error stop 'nc4fortran:read inquire_id ' // dname // ' in ' // self%filename
77

8-
ier = nf90_inquire_variable(self%ncid, varid, ndims=drank)
8+
ier = nf90_inquire_variable(self%file_id, varid, ndims=drank)
99
if (check_error(ier, dname)) error stop 'nc4fortran:read inquire ' // dname // ' in ' // self%filename
1010
if(drank /= rank(value)) then
1111
write(stderr,*) 'ERROR:nc4fortran:read ' // dname // ' rank ', drank, ' /= variable rank ',rank(value)
@@ -14,13 +14,13 @@ endif
1414

1515
select type (value)
1616
type is (real(real64))
17-
ier = nf90_get_var(self%ncid, varid, value)
17+
ier = nf90_get_var(self%file_id, varid, value)
1818
type is (real(real32))
19-
ier = nf90_get_var(self%ncid, varid, value)
19+
ier = nf90_get_var(self%file_id, varid, value)
2020
type is (integer(int64))
21-
ier = nf90_get_var(self%ncid, varid, value)
21+
ier = nf90_get_var(self%file_id, varid, value)
2222
type is (integer(int32))
23-
ier = nf90_get_var(self%ncid, varid, value)
23+
ier = nf90_get_var(self%file_id, varid, value)
2424
class default
2525
ier = NF90_EBADTYPE
2626
end select

src/utils.f90

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626

2727
select case(laction)
2828
case('r')
29-
ier = nf90_open(self%filename, NF90_NOWRITE, self%ncid)
29+
ier = nf90_open(self%filename, NF90_NOWRITE, self%file_id)
3030
case('r+')
31-
ier = nf90_open(self%filename, NF90_NETCDF4, self%ncid)
31+
ier = nf90_open(self%filename, NF90_NETCDF4, self%file_id)
3232
case('rw', 'a')
3333
if(is_netcdf(filename)) then
3434
!! NF90_WRITE is necessary to be in true read/write mode
35-
ier = nf90_open(self%filename, ior(NF90_WRITE, NF90_NETCDF4), self%ncid)
35+
ier = nf90_open(self%filename, ior(NF90_WRITE, NF90_NETCDF4), self%file_id)
3636
else
37-
ier = nf90_create(self%filename, ior(NF90_CLOBBER, NF90_NETCDF4), self%ncid)
37+
ier = nf90_create(self%filename, ior(NF90_CLOBBER, NF90_NETCDF4), self%file_id)
3838
endif
3939
case('w')
40-
ier = nf90_create(self%filename, ior(NF90_CLOBBER, NF90_NETCDF4), self%ncid)
40+
ier = nf90_create(self%filename, ior(NF90_CLOBBER, NF90_NETCDF4), self%file_id)
4141
case default
4242
error stop 'nc4fortran: Unsupported action -> ' // laction
4343
end select
@@ -68,7 +68,7 @@
6868
return
6969
endif
7070

71-
ier = nf90_close(self%ncid)
71+
ier = nf90_close(self%file_id)
7272
if (ier /= NF90_NOERR) error stop 'ERROR:close: ' // self%filename
7373

7474
self%is_open = .false.
@@ -84,10 +84,10 @@
8484
module procedure is_contig
8585
integer :: ier, varid
8686

87-
ier = nf90_inq_varid(self%ncid, dname, varid)
87+
ier = nf90_inq_varid(self%file_id, dname, varid)
8888
if (ier/=NF90_NOERR) error stop 'nc4fortran:is_contig: cannot find variable: ' // dname
8989

90-
ier = nf90_inquire_variable(self%ncid, varid, contiguous=is_contig)
90+
ier = nf90_inquire_variable(self%file_id, varid, contiguous=is_contig)
9191
if (ier/=NF90_NOERR) error stop 'nc4fortran:is_contig: cannot get variable properties' // dname
9292

9393
end procedure is_contig
@@ -96,27 +96,27 @@
9696
module procedure is_chunked
9797
integer :: ier, varid
9898

99-
ier = nf90_inq_varid(self%ncid, dname, varid)
99+
ier = nf90_inq_varid(self%file_id, dname, varid)
100100
if (ier/=NF90_NOERR) error stop 'nc4fortran:is_chunked: cannot find variable: ' // dname
101101

102-
ier = nf90_inquire_variable(self%ncid, varid, contiguous=is_chunked)
102+
ier = nf90_inquire_variable(self%file_id, varid, contiguous=is_chunked)
103103
if (ier/=NF90_NOERR) error stop 'nc4fortran:is_chunked: cannot get variable properties' // dname
104104

105105
is_chunked = .not.is_chunked
106106
end procedure is_chunked
107107

108108

109109
module procedure is_netcdf
110-
integer :: ierr, ncid
110+
integer :: ierr, file_id
111111

112112
inquire(file=filename, exist=is_netcdf)
113113
!! avoid warning/error messages
114114
if (.not. is_netcdf) return
115115

116-
ierr = nf90_open(filename, NF90_NOWRITE, ncid)
116+
ierr = nf90_open(filename, NF90_NOWRITE, file_id)
117117
is_netcdf = ierr == 0
118118

119-
ierr = nf90_close(ncid)
119+
ierr = nf90_close(file_id)
120120

121121
end procedure is_netcdf
122122

@@ -140,9 +140,9 @@
140140
case (NF90_EBADDIM)
141141
m = 'ERROR: ' // dname // ' invalid dimension ID or Name'
142142
case (NF90_EBADGRPID)
143-
m = 'ERROR: ' // dname // ' bad group ID in ncid'
143+
m = 'ERROR: ' // dname // ' bad group ID in file_id'
144144
case (NF90_EBADID)
145-
m = 'ERROR: ' // dname // ' Bad group id or ncid invalid'
145+
m = 'ERROR: ' // dname // ' Bad group id or file_id invalid'
146146
case (NF90_ENOTVAR)
147147
m = 'ERROR: ' // dname // ' variable not found'
148148
case (NF90_ENOTNC)

0 commit comments

Comments
 (0)