@@ -18,6 +18,8 @@ module pio_support
18
18
public :: CheckMPIreturn
19
19
public :: pio_readdof
20
20
public :: pio_writedof
21
+ public :: pio_write_nc_dof
22
+ public :: pio_read_nc_dof
21
23
public :: replace_c_null
22
24
23
25
logical , public :: Debug= .FALSE. ! < debug mode
@@ -173,6 +175,76 @@ end function PIOc_writemap_from_f90
173
175
174
176
end subroutine pio_writedof
175
177
178
+ ! >
179
+ ! ! Fortran interface to write a netcdf format mapping file.
180
+ ! !
181
+ ! ! @param ios : The iosystem structure
182
+ ! ! @param filename : The file where the decomp map will be written.
183
+ ! ! @param cmode : The netcdf creation mode.
184
+ ! ! @param iodesc : The io descriptor structure
185
+ ! ! @param title : An optional title to add to the netcdf attributes
186
+ ! ! @param history : An optional history to add to the netcdf attributes
187
+ ! ! @param fortran_order : Optional logical - Should multidimensional arrays be written in fortran order?
188
+ ! ! @param ret : Return code 0 if success
189
+ ! <
190
+
191
+ subroutine pio_write_nc_dof (ios , filename , cmode , iodesc , ret , title , history , fortran_order )
192
+ use pio_types, only : iosystem_desc_t, io_desc_t
193
+ type (iosystem_desc_t) :: ios
194
+ character (len=* ) :: filename
195
+ integer :: cmode
196
+ type (io_desc_t) :: iodesc
197
+ integer :: ret
198
+ character (len=* ), optional :: title
199
+ character (len=* ), optional :: history
200
+ logical , optional :: fortran_order
201
+
202
+ interface
203
+ integer (c_int) function PIOc_write_nc_decomp(iosysid, filename, cmode, &
204
+ ioid, title, history, fortran_order) &
205
+ bind(C,name= " PIOc_write_nc_decomp" )
206
+ use iso_c_binding
207
+ integer (C_INT), value :: iosysid
208
+ character (kind= c_char) :: filename
209
+ integer (C_INT), value :: cmode
210
+ integer (c_int), value :: ioid
211
+ character (kind= c_char) :: title
212
+ character (kind= c_char) :: history
213
+ integer (c_int), value :: fortran_order
214
+ end function PIOc_write_nc_decomp
215
+ end interface
216
+ character (len= :), allocatable :: ctitle, chistory
217
+ integer :: nl
218
+ integer :: forder
219
+ integer :: i
220
+
221
+
222
+ if (present (title)) then
223
+ ctitle = trim (title)// C_NULL_CHAR
224
+ else
225
+ ctitle = C_NULL_CHAR
226
+ endif
227
+
228
+ if (present (history)) then
229
+ chistory = trim (history)// C_NULL_CHAR
230
+ else
231
+ chistory = C_NULL_CHAR
232
+ endif
233
+
234
+ if (present (fortran_order)) then
235
+ if (fortran_order) then
236
+ forder = 1
237
+ else
238
+ forder = 0
239
+ endif
240
+ endif
241
+ nl = len_trim (filename)
242
+ ret = PIOc_write_nc_decomp(ios% iosysid, filename(:nl)// C_NULL_CHAR, cmode, iodesc% ioid, ctitle, chistory, forder)
243
+
244
+ end subroutine pio_write_nc_dof
245
+
246
+
247
+
176
248
! >
177
249
! ! Fortran interface to read a mapping file.
178
250
! !
@@ -217,4 +289,54 @@ end function PIOc_readmap_from_f90
217
289
! DOF = DOF+1
218
290
end subroutine pio_readdof
219
291
292
+ ! >
293
+ ! ! Fortran interface to read a netcdf format mapping file.
294
+ ! !
295
+ ! ! @param ios : The iosystem structure
296
+ ! ! @param filename : The file where the decomp map will be written.
297
+ ! ! @param iodesc : The io descriptor structure returned
298
+ ! ! @param ret : Return code 0 if success
299
+ ! ! @param title : An optional title to add to the netcdf attributes
300
+ ! ! @param history : An optional history to add to the netcdf attributes
301
+ ! ! @param fortran_order : An optional logical - should arrays be read in fortran order
302
+ ! <
303
+
304
+ subroutine pio_read_nc_dof (ios , filename , iodesc , ret , title , history , fortran_order )
305
+ use pio_types, only : iosystem_desc_t, io_desc_t
306
+ type (iosystem_desc_t) :: ios
307
+ character (len=* ) :: filename
308
+ type (io_desc_t) :: iodesc
309
+ integer :: ret
310
+ character (len=* ), optional :: title
311
+ character (len=* ), optional :: history
312
+ logical , optional :: fortran_order
313
+
314
+ interface
315
+ integer (c_int) function PIOc_read_nc_decomp(iosysid, filename, ioid, &
316
+ title, history, fortran_order) &
317
+ bind(C,name= " PIOc_read_nc_decomp" )
318
+ use iso_c_binding
319
+ integer (C_INT), value :: iosysid
320
+ character (kind= c_char) :: filename
321
+ integer (c_int) :: ioid
322
+ character (kind= c_char) :: title
323
+ character (kind= c_char) :: history
324
+ integer (c_int), value :: fortran_order
325
+ end function PIOc_read_nc_decomp
326
+ end interface
327
+ character (len= :), allocatable :: ctitle, chistory
328
+ integer :: nl
329
+ integer :: forder
330
+
331
+ nl = len_trim (filename)
332
+ ret = PIOc_read_nc_decomp(ios% iosysid, filename(:nl)// C_NULL_CHAR, iodesc% ioid, title, history, forder)
333
+ if (present (fortran_order)) then
334
+ if (forder /= 0 ) then
335
+ fortran_order = .true.
336
+ else
337
+ fortran_order = .true.
338
+ endif
339
+ endif
340
+ end subroutine pio_read_nc_dof
341
+
220
342
end module pio_support
0 commit comments