1 | module nf95_create_single_m |
---|
2 | |
---|
3 | use netcdf, only: NF90_MAX_NAME |
---|
4 | |
---|
5 | implicit none |
---|
6 | |
---|
7 | type coord_def |
---|
8 | character(len = NF90_MAX_NAME) name |
---|
9 | integer nclen |
---|
10 | character(len = :), allocatable:: attr_name(:), attr_val(:) |
---|
11 | end type coord_def |
---|
12 | |
---|
13 | private NF90_MAX_NAME |
---|
14 | |
---|
15 | contains |
---|
16 | |
---|
17 | subroutine nf95_create_single(name, coordinates, ncid, varid, varid_coord) |
---|
18 | |
---|
19 | ! Shortcut to create a file containing a single primary variable. |
---|
20 | |
---|
21 | use netcdf, only: NF90_CLOBBER, NF90_FLOAT |
---|
22 | |
---|
23 | use nf95_create_m, only: nf95_create |
---|
24 | use nf95_def_dim_m, only: nf95_def_dim |
---|
25 | use nf95_def_var_m, only: nf95_def_var |
---|
26 | use nf95_put_att_m, only: nf95_put_att |
---|
27 | |
---|
28 | character(len = *), intent(in):: name |
---|
29 | type(coord_def), intent(in):: coordinates(:) |
---|
30 | integer, intent(out):: ncid, varid, varid_coord(:) |
---|
31 | |
---|
32 | ! Local: |
---|
33 | integer i, j |
---|
34 | integer dimids(size(coordinates)) |
---|
35 | |
---|
36 | !---------------------------------------------------------------------- |
---|
37 | |
---|
38 | call nf95_create(name // ".nc", NF90_CLOBBER, ncid) |
---|
39 | |
---|
40 | do i = 1, size(coordinates) |
---|
41 | call nf95_def_dim(ncid, coordinates(i)%name, coordinates(i)%nclen, & |
---|
42 | dimids(i)) |
---|
43 | call nf95_def_var(ncid, coordinates(i)%name, NF90_FLOAT, dimids(i), & |
---|
44 | varid_coord(i)) |
---|
45 | |
---|
46 | do j = 1, size(coordinates(i)%attr_name) |
---|
47 | call nf95_put_att(ncid, varid_coord(i), coordinates(i)%attr_name(j), & |
---|
48 | coordinates(i)%attr_val(j)) |
---|
49 | end do |
---|
50 | end do |
---|
51 | |
---|
52 | call nf95_def_var(ncid, name, NF90_FLOAT, dimids, varid) |
---|
53 | |
---|
54 | end subroutine nf95_create_single |
---|
55 | |
---|
56 | end module nf95_create_single_m |
---|