Skip to content

Commit 777af2a

Browse files
committed
remove open(status=) as it duplicates action= parameter
1 parent ddb5676 commit 777af2a

17 files changed

+82
-116
lines changed

CMakePresets.json

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
"name": "default",
77
"binaryDir": "${sourceDir}/build",
88
"generator": "Ninja",
9-
"cacheVariables": {"CMAKE_BUILD_TYPE": "Release"}
9+
"cacheVariables": {
10+
"CMAKE_BUILD_TYPE": "Release",
11+
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build"
12+
}
1013
},
1114
{
1215
"name": "notest", "inherits": "default",
1316
"displayName": "omit self-tests",
14-
"cacheVariables": {"BUILD_TESTING": false}
17+
"cacheVariables": {
18+
"BUILD_TESTING": false
19+
}
1520
},
1621
{
1722
"name": "build", "inherits": "default",
@@ -23,24 +28,11 @@
2328
},
2429
{
2530
"name": "intel", "inherits": "default",
26-
"displayName": "Intel Classic compiler: Linux/MacOS",
27-
"environment": {
28-
"CC": "icc",
29-
"CXX": "icpc",
30-
"FC": "ifort"
31-
}
32-
},
33-
{
34-
"name": "intelwin", "inherits": "intel",
35-
"displayName": "Intel Classic compiler: Windows",
36-
"environment": {
37-
"CC": "icl",
38-
"CXX": "icl"
39-
}
40-
},
41-
{
42-
"name": "intelnext", "inherits": "intel",
4331
"displayName": "Intel oneAPI LLVM",
32+
"binaryDir": "${sourceDir}/build-intel",
33+
"cacheVariables": {
34+
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build-intel"
35+
},
4436
"environment": {
4537
"CC": "icx",
4638
"CXX": "icx",
@@ -52,6 +44,10 @@
5244
{
5345
"name": "default",
5446
"configurePreset": "default"
47+
},
48+
{
49+
"name": "intel",
50+
"configurePreset": "intel"
5551
}
5652
],
5753
"testPresets": [
@@ -64,7 +60,12 @@
6460
},
6561
"execution": {
6662
"noTestsAction": "error",
67-
"stopOnFailure": false}
63+
"stopOnFailure": false
64+
}
65+
},
66+
{
67+
"name": "intel", "inherits": "default",
68+
"configurePreset": "intel"
6869
}
6970
]
7071
}

Examples/example1.f90

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

1010
filename = 'nc4fortran_example1.nc'
1111

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

14-
call h%write( 'x', 123)
14+
call h%write('x', 123)
1515

1616
call h%read('x', i32)
1717
call h%close()

Examples/example2.f90

Lines changed: 2 additions & 2 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%open(filename, status='replace')
13+
call h%open(filename, action='w')
1414
call h%write('x', 123)
1515
call h%close()
1616

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

Examples/fortran_interface.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ 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%open(cstr2fstr(filename), status='replace')
18+
call h%open(cstr2fstr(filename), action='w')
1919
call h%write(cstr2fstr(var_name), i32)
2020
call h%close()
2121

@@ -28,7 +28,7 @@ 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%open(cstr2fstr(filename), status='old', action='r')
31+
call h%open(cstr2fstr(filename), action='r')
3232
call h%read(cstr2fstr(var_name), i32)
3333
call h%close()
3434

README.md

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

140140
```fortran
141-
call hf%open('test.nc', status='new')
141+
call hf%open('test.nc', action='w')
142142
143143
call hf%write('value1', 123.)
144144
@@ -161,7 +161,7 @@ exists = hf%exist('fooname')
161161
* if file `test.nc` does not exist, create it and add a variable to it.
162162

163163
```fortran
164-
call hf%open('test.nc', status='unknown',action='rw')
164+
call hf%open('test.nc', action='rw')
165165
166166
call hf%write('value1', 123.)
167167
@@ -171,7 +171,7 @@ call hf%close()
171171
### Read scalar, 3-D array of unknown size
172172

173173
```fortran
174-
call ncf%open('test.nc', status='old',action='r')
174+
call ncf%open('test.nc', action='r')
175175
176176
integer, allocatable :: dims(:)
177177
real, allocatable :: A(:,:,:)
@@ -185,10 +185,10 @@ call ncf%close()
185185

186186
## Permissive syntax
187187

188-
We make the ncf%open(..., status=...) like Fortran open()
188+
We make the ncf%open(..., action=...) like Fortran open()
189189

190-
* overwrite (truncate) existing file: open with `status='new'` or `status='replace'`
191-
* append to existing file or create file: `status='old'` or `status='unknown'`
190+
* overwrite (truncate) existing file: open with `action='w'`
191+
* append to existing file or create file: `action='rw'`
192192

193193
## Notes
194194

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.2
1+
1.4.0

src/interface.f90

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module nc4fortran
2727
logical :: verbose = .false.
2828
logical :: debug = .false.
2929
logical :: is_open = .false.
30-
logical :: is_scratch = .false.
3130
!! will be auto-deleted on close
3231
character(80) :: libversion
3332

@@ -470,12 +469,12 @@ subroutine nc_initialize(self,filename,ierr, status,action,comp_lvl,verbose,debu
470469
class(netcdf_file), intent(inout) :: self
471470
character(*), intent(in) :: filename
472471
integer, intent(out), optional :: ierr
473-
character(*), intent(in), optional :: status
472+
character(*), intent(in), optional :: status !< DEPRECATED
474473
character(*), intent(in), optional :: action
475474
integer, intent(in), optional :: comp_lvl
476475
logical, intent(in), optional :: verbose, debug
477476

478-
character(:), allocatable :: lstatus, laction
477+
character(:), allocatable :: laction
479478
integer :: ier
480479

481480
if (self%is_open) then
@@ -492,50 +491,37 @@ subroutine nc_initialize(self,filename,ierr, status,action,comp_lvl,verbose,debu
492491
!> get library version
493492
self%libversion = nf90_inq_libvers()
494493

495-
lstatus = 'unknown'
496-
if(present(status)) lstatus = status
494+
if(present(status)) write(stderr,*) 'nc4fortran:WARNING: status is deprecated. use action instead.'
497495

498496
laction = 'rw'
499497
if(present(action)) laction = action
500498

501-
select case(lstatus)
502-
case ('old', 'unknown')
503-
select case(laction)
504-
case('read','r')
505-
ier = nf90_open(self%filename, NF90_NOWRITE, self%ncid)
506-
case('r+')
507-
ier = nf90_open(self%filename, NF90_NETCDF4, self%ncid)
508-
case('readwrite', 'rw', 'append', 'a')
509-
if(is_netcdf(filename)) then
510-
!! NF90_WRITE is necessary to be in true read/write mode
511-
ier = nf90_open(self%filename, ior(NF90_WRITE, NF90_NETCDF4), self%ncid)
512-
else
513-
ier = nf90_create(self%filename, ior(NF90_CLOBBER, NF90_NETCDF4), self%ncid)
514-
endif
515-
case('w','write')
516-
ier = nf90_create(self%filename, ior(NF90_CLOBBER, NF90_NETCDF4), self%ncid)
517-
case default
518-
write(stderr,*) 'Unsupported action -> ' // laction
519-
error stop 128
520-
end select
521-
case('new','replace')
522-
ier = nf90_create(self%filename, ior(NF90_CLOBBER, NF90_NETCDF4), self%ncid)
523-
case('scratch')
499+
select case(laction)
500+
case('read','r')
501+
ier = nf90_open(self%filename, NF90_NOWRITE, self%ncid)
502+
case('r+')
503+
ier = nf90_open(self%filename, NF90_NETCDF4, self%ncid)
504+
case('readwrite', 'rw', 'append', 'a')
505+
if(is_netcdf(filename)) then
506+
!! NF90_WRITE is necessary to be in true read/write mode
507+
ier = nf90_open(self%filename, ior(NF90_WRITE, NF90_NETCDF4), self%ncid)
508+
else
524509
ier = nf90_create(self%filename, ior(NF90_CLOBBER, NF90_NETCDF4), self%ncid)
525-
self%is_scratch = .true.
526-
if(.not.is_absolute_path(filename)) self%filename = get_tempdir() // '/' // filename
510+
endif
511+
case('w','write')
512+
ier = nf90_create(self%filename, ior(NF90_CLOBBER, NF90_NETCDF4), self%ncid)
527513
case default
528-
write(stderr,*) 'Unsupported status -> '// lstatus
529-
error stop 128
514+
error stop 'nc4fortran: Unsupported action -> ' // laction
530515
end select
531516

517+
532518
if (present(ierr)) ierr = ier
533519
if (ier == NF90_NOERR) then
534520
self%is_open = .true.
535521
return
536522
endif
537523

538-
write(stderr,*) 'ERROR:initialize ' // filename // ' could not be created'
524+
write(stderr,*) 'nc4fortran:ERROR: initialize ' // filename // ' could not be created'
539525
if (present(ierr)) return
540526
error stop
541527

@@ -573,10 +559,6 @@ subroutine nc_finalize(self, ierr)
573559
error stop
574560
endif
575561

576-
if(self%is_scratch) then
577-
if (std_unlink(self%filename)) write(stderr,*) 'WARNING: could not delete scratch file: ' // self%filename
578-
endif
579-
580562
self%is_open = .false.
581563

582564
end subroutine nc_finalize

src/read.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
type(netcdf_file) :: h
8484

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

src/tests/test_array.f90

Lines changed: 2 additions & 2 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%open(filename, status='replace', comp_lvl=1)
44+
call h%open(filename, action='w', comp_lvl=1)
4545

4646
call h%write('int32-1d', i1)
4747
call h%write('int32-2d', i2, ['x', 'y'])
@@ -60,7 +60,7 @@ subroutine test_basic_array()
6060
call h%close()
6161

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

6565
!> int32
6666
call h%read('int32-1d', i1t)

src/tests/test_attributes.f90

Lines changed: 2 additions & 2 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%open(path, status='replace')
23+
call h%open(path, action='w')
2424

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

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

4747
integer :: x
4848

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

5151
call h%read('x', x)
5252
if (x/=1) error stop 'read_attribute: unexpected value'

0 commit comments

Comments
 (0)