6 logical :: valid = .false.
8 integer :: nVertices = 0
10 integer :: maxEdges = 0
11 integer, dimension(:), pointer :: landmask => null()
12 integer, dimension(:), pointer :: nEdgesOnCell => null()
13 integer, dimension(:,:), pointer :: cellsOnCell => null()
14 integer, dimension(:,:), pointer :: verticesOnCell => null()
15 integer, dimension(:,:), pointer :: cellsOnVertex => null()
16 integer, dimension(:,:), pointer :: edgesOnCell => null()
17 integer, dimension(:,:), pointer :: cellsOnEdge => null()
18 real, dimension(:), pointer :: latCell => null()
19 real, dimension(:), pointer :: lonCell => null()
20 real, dimension(:), pointer :: latVertex => null()
21 real, dimension(:), pointer :: lonVertex => null()
22 real, dimension(:), pointer :: latEdge => null()
23 real, dimension(:), pointer :: lonEdge => null()
24 end type mpas_mesh_type
30 integer function mpas_mesh_setup(mesh_filename, mesh) result(stat)
34 character (len=*), intent(in) :: mesh_filename
35 type (mpas_mesh_type), intent(out) :: mesh
37 type (input_handle_type) :: handle
38 type (input_field_type) :: field
42 if (scan_input_open(mesh_filename, handle) /= 0) then
50 if (scan_input_for_field(handle, 'nEdgesOnCell', field) /= 0) then
55 mesh % nCells = field % dimlens(1)
56 mesh % nVertices = 2 * (mesh % nCells - 2)
57 mesh % nEdges = 3 * (mesh % nCells - 2)
59 stat = scan_input_read_field(field)
60 allocate(mesh % nEdgesOnCell(mesh % nCells))
61 mesh % nEdgesOnCell(:) = field % array1i(:)
62 stat = scan_input_free_field(field)
67 if (scan_input_for_field(handle, 'landmask', field) == 0) then
68 stat = scan_input_read_field(field)
69 allocate(mesh % landmask(mesh % nCells))
70 mesh % landmask(:) = field % array1i(:)
71 stat = scan_input_free_field(field)
72 else ! no landmask available
73 allocate(mesh % landmask(mesh % nCells))
74 mesh % landmask(:) = 1
80 if (scan_input_for_field(handle, 'cellsOnCell', field) /= 0) then
85 mesh % maxEdges = field % dimlens(1)
87 stat = scan_input_read_field(field)
88 allocate(mesh % cellsOnCell(mesh % maxEdges, mesh % nCells))
89 mesh % cellsOnCell(:,:) = field % array2i(:,:)
90 stat = scan_input_free_field(field)
95 if (scan_input_for_field(handle, 'verticesOnCell', field) /= 0) then
100 stat = scan_input_read_field(field)
101 allocate(mesh % verticesOnCell(mesh % maxEdges, mesh % nCells))
102 mesh % verticesOnCell(:,:) = field % array2i(:,:)
103 stat = scan_input_free_field(field)
108 if (scan_input_for_field(handle, 'cellsOnVertex', field) /= 0) then
113 stat = scan_input_read_field(field)
114 allocate(mesh % cellsOnVertex(3, mesh % nVertices))
115 mesh % cellsOnVertex(:,:) = field % array2i(:,:)
116 stat = scan_input_free_field(field)
121 if (scan_input_for_field(handle, 'edgesOnCell', field) /= 0) then
126 stat = scan_input_read_field(field)
127 allocate(mesh % edgesOnCell(mesh % maxEdges, mesh % nCells))
128 mesh % edgesOnCell(:,:) = field % array2i(:,:)
129 stat = scan_input_free_field(field)
134 if (scan_input_for_field(handle, 'cellsOnEdge', field) /= 0) then
139 stat = scan_input_read_field(field)
140 allocate(mesh % cellsOnEdge(2, mesh % nEdges))
141 mesh % cellsOnEdge(:,:) = field % array2i(:,:)
142 stat = scan_input_free_field(field)
147 if (scan_input_for_field(handle, 'latCell', field) /= 0) then
152 stat = scan_input_read_field(field)
153 allocate(mesh % latCell(mesh % nCells))
154 if (field % xtype == FIELD_TYPE_REAL) then
155 mesh % latCell(:) = field % array1r(:)
156 else if (field % xtype == FIELD_TYPE_DOUBLE) then
157 mesh % latCell(:) = real(field % array1d(:))
159 stat = scan_input_free_field(field)
164 if (scan_input_for_field(handle, 'lonCell', field) /= 0) then
169 stat = scan_input_read_field(field)
170 allocate(mesh % lonCell(mesh % nCells))
171 if (field % xtype == FIELD_TYPE_REAL) then
172 mesh % lonCell(:) = field % array1r(:)
173 else if (field % xtype == FIELD_TYPE_DOUBLE) then
174 mesh % lonCell(:) = real(field % array1d(:))
176 stat = scan_input_free_field(field)
181 if (scan_input_for_field(handle, 'latVertex', field) /= 0) then
186 stat = scan_input_read_field(field)
187 allocate(mesh % latVertex(mesh % nVertices))
188 if (field % xtype == FIELD_TYPE_REAL) then
189 mesh % latVertex(:) = field % array1r(:)
190 else if (field % xtype == FIELD_TYPE_DOUBLE) then
191 mesh % latVertex(:) = real(field % array1d(:))
193 stat = scan_input_free_field(field)
198 if (scan_input_for_field(handle, 'lonVertex', field) /= 0) then
203 stat = scan_input_read_field(field)
204 allocate(mesh % lonVertex(mesh % nVertices))
205 if (field % xtype == FIELD_TYPE_REAL) then
206 mesh % lonVertex(:) = field % array1r(:)
207 else if (field % xtype == FIELD_TYPE_DOUBLE) then
208 mesh % lonVertex(:) = real(field % array1d(:))
210 stat = scan_input_free_field(field)
215 if (scan_input_for_field(handle, 'latEdge', field) /= 0) then
220 stat = scan_input_read_field(field)
221 allocate(mesh % latEdge(mesh % nEdges))
222 if (field % xtype == FIELD_TYPE_REAL) then
223 mesh % latEdge(:) = field % array1r(:)
224 else if (field % xtype == FIELD_TYPE_DOUBLE) then
225 mesh % latEdge(:) = real(field % array1d(:))
227 stat = scan_input_free_field(field)
232 if (scan_input_for_field(handle, 'lonEdge', field) /= 0) then
237 stat = scan_input_read_field(field)
238 allocate(mesh % lonEdge(mesh % nEdges))
239 if (field % xtype == FIELD_TYPE_REAL) then
240 mesh % lonEdge(:) = field % array1r(:)
241 else if (field % xtype == FIELD_TYPE_DOUBLE) then
242 mesh % lonEdge(:) = real(field % array1d(:))
244 stat = scan_input_free_field(field)
246 stat = scan_input_close(handle)
248 mesh % valid = .true.
250 end function mpas_mesh_setup
253 integer function mpas_mesh_free(mesh) result(stat)
257 type (mpas_mesh_type), intent(inout) :: mesh
262 mesh % valid = .false.
268 if (associated(mesh % landmask)) then
269 deallocate(mesh % landmask)
271 if (associated(mesh % nEdgesOnCell)) then
272 deallocate(mesh % nEdgesOnCell)
274 if (associated(mesh % cellsOnCell)) then
275 deallocate(mesh % cellsOnCell)
277 if (associated(mesh % verticesOnCell)) then
278 deallocate(mesh % verticesOnCell)
280 if (associated(mesh % cellsOnVertex)) then
281 deallocate(mesh % cellsOnVertex)
283 if (associated(mesh % edgesOnCell)) then
284 deallocate(mesh % edgesOnCell)
286 if (associated(mesh % cellsOnEdge)) then
287 deallocate(mesh % cellsOnEdge)
289 if (associated(mesh % latCell)) then
290 deallocate(mesh % latCell)
292 if (associated(mesh % lonCell)) then
293 deallocate(mesh % lonCell)
295 if (associated(mesh % latVertex)) then
296 deallocate(mesh % latVertex)
298 if (associated(mesh % lonVertex)) then
299 deallocate(mesh % lonVertex)
301 if (associated(mesh % latEdge)) then
302 deallocate(mesh % latEdge)
304 if (associated(mesh % lonEdge)) then
305 deallocate(mesh % lonEdge)
308 end function mpas_mesh_free