Skip to content

Commit b885868

Browse files
committed
add %open,%close for ease of typing
1 parent aafe60b commit b885868

15 files changed

+73
-72
lines changed

Examples/example1.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ program example1
99

1010
filename = 'nc4fortran_example1.nc'
1111

12-
call h%initialize(filename, status='replace')
12+
call h%open(filename, status='replace')
1313

1414
call h%write( 'x', 123)
1515

1616
call h%read('x', i32)
17-
call h%finalize()
17+
call h%close()
1818

1919
if (i32 /= 123) error stop 'incorrect value read'
2020

Examples/example2.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ program example2
1010

1111
filename = 'nc4fortran_example2.nc'
1212

13-
call h%initialize(filename, status='replace')
13+
call h%open(filename, status='replace')
1414
call h%write('x', 123)
15-
call h%finalize()
15+
call h%close()
1616

17-
call h%initialize(filename, status='old', action='r')
17+
call h%open(filename, status='old', action='r')
1818
call h%read('x', i32)
1919
if (i32 /= 123) error stop 'incorrect value read'
2020

Examples/fortran_interface.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ subroutine write_int32(filename, var_name, i32) bind(C)
1515
integer(C_INT32_T), intent(in) :: i32
1616
type(netcdf_file) :: h
1717

18-
call h%initialize(cstr2fstr(filename), status='replace')
18+
call h%open(cstr2fstr(filename), status='replace')
1919
call h%write(cstr2fstr(var_name), i32)
20-
call h%finalize()
20+
call h%close()
2121

2222
end subroutine write_int32
2323

@@ -28,9 +28,9 @@ subroutine read_int32(filename, var_name, i32) bind(C)
2828
integer(C_INT32_T), intent(out) :: i32
2929
type(netcdf_file) :: h
3030

31-
call h%initialize(cstr2fstr(filename), status='old', action='r')
31+
call h%open(cstr2fstr(filename), status='old', action='r')
3232
call h%read(cstr2fstr(var_name), i32)
33-
call h%finalize()
33+
call h%close()
3434

3535
end subroutine read_int32
3636

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,16 @@ If `ierr` is omitted, nc4fortran will `error stop` on error.
140140
### Create new NetCDF file, with variable "value1"
141141

142142
```fortran
143-
call hf%initialize('test.nc', status='new')
143+
call hf%open('test.nc', status='new')
144144
145145
call hf%write('value1', 123.)
146146
147-
call hf%finalize()
147+
call hf%close()
148148
```
149149

150150
### Check if variable exists
151151

152-
This will not raise error stop, even if the file isn't initialized, but it will print a message to stderr.
152+
This will not raise error stop, even if the file isn't opened, but it will print a message to stderr.
153153

154154
```fortran
155155
logical :: exists
@@ -163,17 +163,17 @@ exists = hf%exist('fooname')
163163
* if file `test.nc` does not exist, create it and add a variable to it.
164164

165165
```fortran
166-
call hf%initialize('test.nc', status='unknown',action='rw')
166+
call hf%open('test.nc', status='unknown',action='rw')
167167
168168
call hf%write('value1', 123.)
169169
170-
call hf%finalize()
170+
call hf%close()
171171
```
172172

173173
### Read scalar, 3-D array of unknown size
174174

175175
```fortran
176-
call ncf%initialize('test.nc', status='old',action='r')
176+
call ncf%open('test.nc', status='old',action='r')
177177
178178
integer, allocatable :: dims(:)
179179
real, allocatable :: A(:,:,:)
@@ -182,7 +182,7 @@ call ncf%shape('foo', dims)
182182
allocate(A(dims(1), dims(2), dims(3)))
183183
call ncf%read('foo', A)
184184
185-
call ncf%finalize()
185+
call ncf%close()
186186
```
187187

188188
## Permissive syntax

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.6
1+
1.3.0

src/interface.f90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ module nc4fortran
3434
contains
3535

3636
!> methods used directly without type/rank agnosticism
37-
procedure, public :: initialize => nc_initialize, finalize => nc_finalize, &
37+
procedure, public :: initialize => nc_initialize, open => nc_initialize, &
38+
finalize => nc_finalize, close => nc_finalize, &
3839
shape => get_shape, ndims => get_ndims, write_attribute, read_attribute, flush=>nc_flush, &
3940
exist=>nc_check_exist, exists=>nc_check_exist, &
4041
is_chunked, is_contig, chunks=>get_chunk
@@ -469,7 +470,7 @@ subroutine nc_initialize(self,filename,ierr, status,action,comp_lvl,verbose,debu
469470
character(*), intent(in), optional :: status
470471
character(*), intent(in), optional :: action
471472
integer, intent(in), optional :: comp_lvl
472-
logical, intent(in), optional :: verbose, debug
473+
logical, intent(in), optional :: verbose, debug
473474

474475
character(:), allocatable :: lstatus, laction
475476
integer :: ier

src/read.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
case (NF90_NOERR)
6969
exists = .true.
7070
case (NF90_EBADID)
71-
write(stderr,*) 'check_exist: ERROR: is file initialized? ', self%filename
71+
write(stderr,*) 'check_exist: ERROR: is file opened? ', self%filename
7272
case (NF90_ENOTVAR)
7373
if (self%verbose) write(stderr,*) dname, ' does not exist in ', self%filename
7474
case default
@@ -82,9 +82,9 @@
8282

8383
type(netcdf_file) :: h
8484

85-
call h%initialize(filename, status='old', action='r')
85+
call h%open(filename, status='old', action='r')
8686
nc_exist = h%exist(dname)
87-
call h%finalize()
87+
call h%close()
8888

8989
end procedure nc_exist
9090

src/tests/test_array.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ subroutine test_basic_array()
4141
r1 = i1
4242
r2 = i2
4343

44-
call h%initialize(filename, status='replace', comp_lvl=1)
44+
call h%open(filename, status='replace', comp_lvl=1)
4545

4646
call h%write('int32-1d', i1)
4747
call h%write('int32-2d', i2, ['x', 'y'])
@@ -57,10 +57,10 @@ subroutine test_basic_array()
5757
call h%write('int32-1d', i2, ierr=ierr)
5858
if(ierr==0) error stop 'test_write_array: did not error for write array rank mismatch'
5959

60-
call h%finalize()
60+
call h%close()
6161

6262
!! read
63-
call h%initialize(filename, status='old', action='r')
63+
call h%open(filename, status='old', action='r')
6464

6565
!> int32
6666
call h%read('int32-1d', i1t)
@@ -96,7 +96,7 @@ subroutine test_basic_array()
9696
call h%read('nan',nant)
9797
if (.not.ieee_is_nan(nant)) error stop 'failed storing or reading NaN'
9898

99-
call h%finalize()
99+
call h%close()
100100

101101
end subroutine test_basic_array
102102

src/tests/test_attributes.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ subroutine test_write_attributes(path)
2020
type(netcdf_file) :: h
2121
character(*), intent(in) :: path
2222

23-
call h%initialize(path, status='replace')
23+
call h%open(path, status='replace')
2424

2525
call h%write('x', 1)
2626

@@ -30,7 +30,7 @@ subroutine test_write_attributes(path)
3030
call h%write_attribute('x', 'life_float', 42._real32)
3131
call h%write_attribute('x', 'life_double', 42._real64)
3232

33-
call h%finalize()
33+
call h%close()
3434

3535
end subroutine test_write_attributes
3636

@@ -46,7 +46,7 @@ subroutine test_read_attributes(path)
4646

4747
integer :: x
4848

49-
call h%initialize(path, status='old', action='r')
49+
call h%open(path, status='old', action='r')
5050

5151
call h%read('x', x)
5252
if (x/=1) error stop 'read_attribute: unexpected value'
@@ -63,7 +63,7 @@ subroutine test_read_attributes(path)
6363
call h%read_attribute('x', 'life_double', attr64)
6464
if (attr64 /= 42._real64) error stop 'read_attribute: real64'
6565

66-
call h%finalize()
66+
call h%close()
6767

6868
end subroutine test_read_attributes
6969

src/tests/test_deflate.f90

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ program deflate_test
2323
big2 = 0
2424
big3 = 0
2525

26-
call h%initialize(fn1, status='replace', comp_lvl=1, debug=.true.)
26+
call h%open(fn1, status='replace', comp_lvl=1, debug=.true.)
2727
call h%write('big2', big2, dims=['x','y'])
2828
call h%flush()
2929
!> turn compression off for following variables (must flush first)
3030
h%comp_lvl = 0
3131
call h%write('small_contig', big2(:5,:5), dims=['q','r'])
32-
call h%finalize()
32+
call h%close()
3333

3434
inquire(file=fn1, size=fsize)
3535
crat = (N*N*storage_size(big2)/8) / fsize
3636
print '(A,F6.2,A,I6)','#1 filesize (Mbytes): ',fsize/1e6, ' 2D compression ratio:',crat
3737
if (crat < 10) error stop '#1 2D low compression'
3838

39-
call h%initialize(fn1, status='old', action='r', debug=.false.)
39+
call h%open(fn1, status='old', action='r', debug=.false.)
4040

4141
if(.not. h%is_chunked('big2')) error stop '#1 not chunked layout'
4242

@@ -50,11 +50,11 @@ program deflate_test
5050
call h%chunks('small_contig', chunks(:2))
5151
if(any(chunks(:2) /= -1)) error stop '#1 get_chunk mismatch'
5252

53-
call h%finalize()
53+
call h%close()
5454

5555
! ======================================
5656

57-
call h%initialize(fn2, status='replace',comp_lvl=1, debug=.true.)
57+
call h%open(fn2, status='replace',comp_lvl=1, debug=.true.)
5858
call h%write('big3', big3)
5959

6060
call h%write('big3_autochunk', big3)
@@ -64,7 +64,7 @@ program deflate_test
6464
write(stderr,*) '#2 chunk size', chunks
6565
error stop '#2 auto chunk unexpected chunk size'
6666
endif
67-
call h%finalize()
67+
call h%close()
6868

6969
inquire(file=fn2, size=fsize)
7070
crat = (2*N*N*storage_size(big3)/8) / fsize
@@ -73,25 +73,25 @@ program deflate_test
7373

7474
! ======================================
7575

76-
call h%initialize(fn3, status='replace',comp_lvl=1, debug=.true.)
76+
call h%open(fn3, status='replace',comp_lvl=1, debug=.true.)
7777

7878
call h%write('ibig3', ibig3(:N-10,:N-20,:))
7979
call h%chunks('ibig3', chunks)
8080
if(any(chunks(:2) /= [N-10, N-20])) then
8181
write(stderr,*) '#3 chunk size', chunks
8282
error stop '#3 auto chunk unexpected chunk size'
8383
endif
84-
call h%finalize()
84+
call h%close()
8585

8686
inquire(file=fn3, size=fsize)
8787
crat = (N*N*storage_size(ibig3)/8) / fsize
8888
print '(A,F6.2,A,I6)','#3 filesize (Mbytes): ',fsize/1e6, ' 3D compression ratio:',crat
8989
if (h%comp_lvl > 0 .and. crat < 10) error stop '#3 3D low compression'
9090
! !======================================
9191

92-
call h%initialize(fn4, status='replace', comp_lvl=1, debug=.true.)
92+
call h%open(fn4, status='replace', comp_lvl=1, debug=.true.)
9393
call h%write('ibig2', ibig2)
94-
call h%finalize()
94+
call h%close()
9595

9696
inquire(file=fn4, size=fsize)
9797
crat = (N*N*storage_size(ibig2)/8) / fsize

0 commit comments

Comments
 (0)