-
Notifications
You must be signed in to change notification settings - Fork 0
/
tripolegrid.F90
151 lines (113 loc) · 4.89 KB
/
tripolegrid.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
module tripolegrid
use gengrid_kinds, only: dbl_kind,int_kind,CM
use grdvars, only: ni,nj,nv,mastertask,nverts,ncoord
use grdvars, only: lonCt,latCt,lonCt_vert,latCt_vert
use grdvars, only: lonCu,latCu,lonCu_vert,latCu_vert
use grdvars, only: lonCv,latCv,lonCv_vert,latCv_vert
use grdvars, only: lonBu,latBu,lonBu_vert,latBu_vert
use grdvars, only: wet4,areaCt,angleT,dp4
use charstrings, only: logmsg,history
use vartypedefs, only: maxvars, fixvars, fixvars_typedefine
use netcdf
implicit none
private
public write_tripolegrid
contains
subroutine write_tripolegrid(fname)
character(len=*), intent(in) :: fname
! local variables
integer :: ii,id,rc, ncid, dim2(2),dim3(3)
integer :: idimid,jdimid,kdimid
!---------------------------------------------------------------------
! create the netcdf file
!---------------------------------------------------------------------
! define the output variables and file name
call fixvars_typedefine
! create the file
! 64_bit offset reqd for 008 grid
! produces b4b results for smaller grids
rc = nf90_create(trim(fname), nf90_64bit_offset, ncid)
if(mastertask) then
logmsg = '==> writing tripole grid to '//trim(fname)
print '(a)', trim(logmsg)
if(rc .ne. 0)print '(a)', 'nf90_create = '//trim(nf90_strerror(rc))
end if
rc = nf90_def_dim(ncid, 'ni', ni, idimid)
rc = nf90_def_dim(ncid, 'nj', nj, jdimid)
rc = nf90_def_dim(ncid, 'nv', nv, kdimid)
!mask
dim2(:) = (/idimid, jdimid/)
rc = nf90_def_var(ncid, 'wet', nf90_int, dim2, id)
rc = nf90_put_att(ncid, id, 'units', 'nd')
!area
rc = nf90_def_var(ncid, 'area', nf90_double, dim2, id)
rc = nf90_put_att(ncid, id, 'units', 'm2')
!angleT
rc = nf90_def_var(ncid, 'anglet', nf90_double, dim2, id)
rc = nf90_put_att(ncid, id, 'units', 'radians')
!bathymetry
rc = nf90_def_var(ncid, 'depth', nf90_float, dim2, id)
rc = nf90_put_att(ncid, id, 'units', 'm')
dim2(:) = (/idimid, jdimid/)
do ii = 1,ncoord
rc = nf90_def_var(ncid, trim(fixvars(ii)%var_name), nf90_double, dim2, id)
rc = nf90_put_att(ncid, id, 'units', trim(fixvars(ii)%unit_name))
rc = nf90_put_att(ncid, id, 'long_name', trim(fixvars(ii)%long_name))
if(trim(fixvars(ii)%var_name(1:3)) .eq. "lon")then
rc = nf90_put_att(ncid, id, 'lon_bounds', trim(fixvars(ii)%vertices))
else
rc = nf90_put_att(ncid, id, 'lat_bounds', trim(fixvars(ii)%vertices))
endif
enddo
dim3(:) = (/idimid, jdimid, kdimid/)
do ii = ncoord+1,ncoord+nverts
rc = nf90_def_var(ncid, trim(fixvars(ii)%var_name), nf90_double, dim3, id)
rc = nf90_put_att(ncid, id, 'units', trim(fixvars(ii)%unit_name))
rc = nf90_put_att(ncid, id, 'long_name', trim(fixvars(ii)%long_name))
enddo
rc = nf90_put_att(ncid, nf90_global, 'history', trim(history))
rc = nf90_enddef(ncid)
rc = nf90_inq_varid(ncid, 'wet', id)
rc = nf90_put_var(ncid, id, int(wet4))
rc = nf90_inq_varid(ncid, 'area', id)
rc = nf90_put_var(ncid, id, areaCt)
rc = nf90_inq_varid(ncid,'anglet', id)
rc = nf90_put_var(ncid, id, anglet)
rc = nf90_inq_varid(ncid, 'depth', id)
rc = nf90_put_var(ncid, id, dp4)
rc = nf90_inq_varid(ncid, 'lonCt', id)
rc = nf90_put_var(ncid, id, lonCt)
rc = nf90_inq_varid(ncid, 'latCt', id)
rc = nf90_put_var(ncid, id, latCt)
rc = nf90_inq_varid(ncid, 'lonCv', id)
rc = nf90_put_var(ncid, id, lonCv)
rc = nf90_inq_varid(ncid, 'latCv', id)
rc = nf90_put_var(ncid, id, latCv)
rc = nf90_inq_varid(ncid, 'lonCu', id)
rc = nf90_put_var(ncid, id, lonCu)
rc = nf90_inq_varid(ncid, 'latCu', id)
rc = nf90_put_var(ncid, id, latCu)
rc = nf90_inq_varid(ncid, 'lonBu', id)
rc = nf90_put_var(ncid, id, lonBu)
rc = nf90_inq_varid(ncid, 'latBu', id)
rc = nf90_put_var(ncid, id, latBu)
! vertices
rc = nf90_inq_varid(ncid, 'lonCt_vert', id)
rc = nf90_put_var(ncid, id, lonCt_vert)
rc = nf90_inq_varid(ncid, 'latCt_vert', id)
rc = nf90_put_var(ncid, id, latCt_vert)
rc = nf90_inq_varid(ncid, 'lonCv_vert', id)
rc = nf90_put_var(ncid, id, lonCv_vert)
rc = nf90_inq_varid(ncid, 'latCv_vert', id)
rc = nf90_put_var(ncid, id, latCv_vert)
rc = nf90_inq_varid(ncid, 'lonCu_vert', id)
rc = nf90_put_var(ncid, id, lonCu_vert)
rc = nf90_inq_varid(ncid, 'latCu_vert', id)
rc = nf90_put_var(ncid, id, latCu_vert)
rc = nf90_inq_varid(ncid, 'lonBu_vert', id)
rc = nf90_put_var(ncid, id, lonBu_vert)
rc = nf90_inq_varid(ncid, 'latBu_vert', id)
rc = nf90_put_var(ncid, id, latBu_vert)
rc = nf90_close(ncid)
end subroutine write_tripolegrid
end module tripolegrid