@@ -5,17 +5,43 @@ program test_shape
55
66implicit none (type, external )
77
8- type (netcdf_file) :: h
9- character (* ), parameter :: path = ' test_shape.nc'
10- integer , allocatable :: dims(:)
11- character (NF90_MAX_NAME), allocatable :: dimnames(:)
8+ character (* ), parameter :: fn = ' test_shape.nc'
9+
10+
11+ call test_shape_write(fn)
12+
13+ call test_shape_read(fn)
14+ print * , " OK: test_shape"
1215
16+
17+ contains
18+
19+
20+ subroutine test_shape_write (fn )
21+
22+ character (* ), intent (in ) :: fn
23+
24+ type (netcdf_file) :: h
1325integer :: d2(3 ,4 ), d7(2 ,1 ,3 ,4 ,7 ,6 ,5 )
1426
15- call h% open (path , action= ' w' )
27+ call h% open (fn , action= ' w' )
1628call h% write (' d2' , d2)
1729call h% write (' d7' , d7, dims= [' x' ,' y' ,' z' , ' p' ,' q' ,' r' ,' s' ])
30+ call h% close ()
31+
32+ end subroutine test_shape_write
33+
1834
35+ subroutine test_shape_read (fn )
36+
37+ character (* ), intent (in ) :: fn
38+
39+ type (netcdf_file) :: h
40+ character (NF90_MAX_NAME), allocatable :: dimnames(:)
41+ integer , allocatable :: dims(:)
42+ integer :: d2(3 ,4 ), d7(2 ,1 ,3 ,4 ,7 ,6 ,5 )
43+
44+ call h% open (fn, action= ' r' )
1945call h% shape (' d2' , dims)
2046if (h% ndim(' d2' ) /= size (dims)) error stop ' rank /= size(dims)'
2147if (any (dims /= shape (d2))) error stop ' 2-D: file shape not match variable shape'
@@ -26,4 +52,6 @@ program test_shape
2652
2753call h% close ()
2854
55+ end subroutine test_shape_read
56+
2957end program
0 commit comments