| 1 |
!------------------------------------------------------------- |
| 2 |
! |
| 3 |
! Fortran 90 interface to H5Part, using |
| 4 |
! the Fortran 2003 C interoperability module (iso_c_binding) |
| 5 |
! |
| 6 |
! Written by Daniel Price 08/04/10 |
| 7 |
! [email protected] |
| 8 |
! |
| 9 |
! We first specify the interfaces to the C interface routines |
| 10 |
! used to handle the H5partfile container object. However, all |
| 11 |
! string conversion is done in the Fortran, not in the C. |
| 12 |
! |
| 13 |
!------------------------------------------------------------- |
| 14 |
module h5part |
| 15 |
use, intrinsic :: iso_c_binding, only:c_char,c_int,c_int64_t,c_double,c_float |
| 16 |
implicit none |
| 17 |
integer(kind=c_int64_t), parameter, public :: H5PART_INT64 = 1 |
| 18 |
integer(kind=c_int64_t), parameter, public :: H5PART_INT32 = 2 |
| 19 |
integer(kind=c_int64_t), parameter, public :: H5PART_FLOAT64 = 3 |
| 20 |
integer(kind=c_int64_t), parameter, public :: H5PART_FLOAT32 = 4 |
| 21 |
integer(kind=c_int64_t), parameter, public :: H5PART_CHAR = 5 |
| 22 |
integer(kind=c_int64_t), parameter, public :: H5PART_STRING = 6 |
| 23 |
character(len=7), dimension(6), parameter, public :: & |
| 24 |
h5part_type = (/'INT64 ',& |
| 25 |
'INT32 ',& |
| 26 |
'FLOAT64',& |
| 27 |
'FLOAT32',& |
| 28 |
'CHAR ',& |
| 29 |
'STRING '/) |
| 30 |
! |
| 31 |
! interfaces provided by this module |
| 32 |
! |
| 33 |
public :: h5pt_openr,h5pt_openw,h5pt_opena,h5pt_close |
| 34 |
public :: h5pt_openr_align,h5pt_openw_align,h5pt_opena_align |
| 35 |
|
| 36 |
#ifdef PARALLEL_IO |
| 37 |
public :: h5pt_openr_par,h5pt_openw_par,h5pt_opena_par |
| 38 |
public :: h5pt_openr_par_align,h5pt_openw_par_align,h5pt_opena_par_align |
| 39 |
#endif |
| 40 |
|
| 41 |
public :: h5pt_setnpoints,h5pt_setnpoints_strided |
| 42 |
public :: h5pt_getnpoints |
| 43 |
public :: h5pt_setstep,h5pt_getnsteps,h5pt_getndatasets |
| 44 |
public :: h5pt_getdatasetname,h5pt_getdatasetinfo |
| 45 |
|
| 46 |
public :: h5pt_setview,h5pt_setview_indices |
| 47 |
public :: h5pt_getview |
| 48 |
public :: h5pt_resetview,h5pt_hasview |
| 49 |
|
| 50 |
public :: h5pt_set_verbosity_level |
| 51 |
|
| 52 |
public :: h5pt_writedata |
| 53 |
public :: h5pt_readdata |
| 54 |
! |
| 55 |
! the type-specific routines are also public |
| 56 |
! (could make these private to allow only |
| 57 |
! the generic interface to be used) |
| 58 |
! |
| 59 |
public :: h5pt_writedata_r8,h5pt_writedata_r4, & |
| 60 |
h5pt_writedata_i8,h5pt_writedata_i4 |
| 61 |
public :: h5pt_readdata_r8,h5pt_readdata_r4, & |
| 62 |
h5pt_readdata_i8,h5pt_readdata_i4 |
| 63 |
|
| 64 |
private |
| 65 |
|
| 66 |
! |
| 67 |
! generic interface for writing data of any type |
| 68 |
! |
| 69 |
interface h5pt_writedata |
| 70 |
module procedure h5pt_writedata_i4,h5pt_writedata_i8, & |
| 71 |
h5pt_writedata_r4,h5pt_writedata_r8 |
| 72 |
end interface h5pt_writedata |
| 73 |
|
| 74 |
! |
| 75 |
! generic interface for reading data of any type |
| 76 |
! |
| 77 |
interface h5pt_readdata |
| 78 |
module procedure h5pt_readdata_i4,h5pt_readdata_i8, & |
| 79 |
h5pt_readdata_r4,h5pt_readdata_r8 |
| 80 |
end interface h5pt_readdata |
| 81 |
|
| 82 |
!--------------------------- |
| 83 |
! |
| 84 |
! interfaces to c routines |
| 85 |
! |
| 86 |
!--------------------------- |
| 87 |
interface |
| 88 |
! |
| 89 |
! Opening and closing files |
| 90 |
! |
| 91 |
integer(kind=c_int64_t) function h5ptc_openr( filename ) bind(C) |
| 92 |
import |
| 93 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for reading |
| 94 |
end function |
| 95 |
|
| 96 |
integer(kind=c_int64_t) function h5ptc_openw ( filename ) bind(C) |
| 97 |
import |
| 98 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for writing |
| 99 |
end function |
| 100 |
|
| 101 |
integer(kind=c_int64_t) function h5ptc_opena ( filename ) bind(C) |
| 102 |
import |
| 103 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for appending |
| 104 |
end function |
| 105 |
|
| 106 |
integer(kind=c_int64_t) function h5ptc_openr_align ( filename, align ) bind(C) |
| 107 |
import |
| 108 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for reading |
| 109 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 110 |
end function |
| 111 |
|
| 112 |
integer(kind=c_int64_t) function h5ptc_openw_align ( filename, align ) bind(C) |
| 113 |
import |
| 114 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for writing |
| 115 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 116 |
end function |
| 117 |
|
| 118 |
integer(kind=c_int64_t) function h5ptc_opena_align ( filename, align ) bind(C) |
| 119 |
import |
| 120 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for appending |
| 121 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 122 |
end function |
| 123 |
|
| 124 |
integer(kind=c_int64_t) function h5pt_close ( filehandle ) bind(C,name="h5ptc_close") |
| 125 |
import |
| 126 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 127 |
end function |
| 128 |
|
| 129 |
#ifdef PARALLEL_IO |
| 130 |
! |
| 131 |
! Opening files (parallel I/O) |
| 132 |
! |
| 133 |
integer(kind=c_int64_t) function h5ptc_openr_par ( filename, mpi_communicator ) bind(C) |
| 134 |
import |
| 135 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for reading |
| 136 |
integer, intent(in) :: mpi_communicator !< the MPI communicator used by the program |
| 137 |
end function |
| 138 |
|
| 139 |
integer(kind=c_int64_t) function h5ptc_openw_par ( filename, mpi_communicator ) bind(C) |
| 140 |
import |
| 141 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for writing |
| 142 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 143 |
end function |
| 144 |
|
| 145 |
integer(kind=c_int64_t) function h5ptc_opena_par ( filename, mpi_communicator ) bind(C) |
| 146 |
import |
| 147 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for appending |
| 148 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 149 |
end function |
| 150 |
|
| 151 |
integer(kind=c_int64_t) function h5ptc_openr_par_align ( filename, mpi_communicator, align ) bind(C) |
| 152 |
import |
| 153 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for reading |
| 154 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 155 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 156 |
end function |
| 157 |
|
| 158 |
integer(kind=c_int64_t) function h5ptc_openw_par_align ( filename, mpi_communicator, align, flags ) bind(C) |
| 159 |
import |
| 160 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for writing |
| 161 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 162 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 163 |
character(kind=c_char), dimension(1), intent(in) :: flags !< additional flags |
| 164 |
end function |
| 165 |
|
| 166 |
integer(kind=c_int64_t) function h5ptc_opena_par_align ( filename, mpi_communicator, align, flags ) bind(C) |
| 167 |
import |
| 168 |
character(kind=c_char), dimension(1), intent(in) :: filename !< the filename to open for appending |
| 169 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 170 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 171 |
character(kind=c_char), dimension(1), intent(in) :: flags !< additional flags |
| 172 |
end function |
| 173 |
#endif |
| 174 |
|
| 175 |
! |
| 176 |
! Setting up the data model |
| 177 |
! (where no strings are passed these are just interfaces to the c routines that convert the filehandle) |
| 178 |
! |
| 179 |
integer(kind=c_int64_t) function h5pt_setnpoints ( filehandle, npoints ) bind(C,name="h5ptc_setnpoints") |
| 180 |
import |
| 181 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 182 |
integer(kind=c_int64_t), intent(in) :: npoints !< the number of particles on *this* processor |
| 183 |
end function |
| 184 |
|
| 185 |
integer(kind=c_int64_t) function h5pt_setnpoints_strided ( filehandle, npoints, stride ) & |
| 186 |
bind(C,name="h5ptc_setnpoints_strided") |
| 187 |
import |
| 188 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 189 |
integer(kind=c_int64_t), intent(in) :: npoints !< the number of particles on *this* processor |
| 190 |
integer(kind=c_int64_t), intent(in) :: stride !< the stride value (e.g. the number of fields in the particle data array) |
| 191 |
end function |
| 192 |
|
| 193 |
integer(kind=c_int64_t) function h5pt_setstep (filehandle,step) bind(C,name="h5ptc_setstep") |
| 194 |
import |
| 195 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 196 |
integer(kind=c_int64_t), intent(in) :: step !< a timestep value >= 1 |
| 197 |
end function |
| 198 |
|
| 199 |
integer(kind=c_int64_t) function h5pt_getnsteps (filehandle) bind(C,name="h5ptc_getnsteps") |
| 200 |
import |
| 201 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 202 |
end function |
| 203 |
|
| 204 |
integer(kind=c_int64_t) function h5pt_getndatasets (filehandle) bind(C,name="h5ptc_getndatasets") |
| 205 |
import |
| 206 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 207 |
end function |
| 208 |
|
| 209 |
integer(kind=c_int64_t) function h5pt_getnpoints (filehandle) bind(C,name="h5ptc_getnpoints") |
| 210 |
import |
| 211 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 212 |
end function |
| 213 |
|
| 214 |
integer(kind=c_int64_t) function h5ptc_getdatasetname (filehandle,index,name,l_name) bind(C) |
| 215 |
import |
| 216 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 217 |
integer(kind=c_int64_t), intent(in) :: index !< index of dataset to query (starting from 0) |
| 218 |
character(kind=c_char), dimension(1), intent(out) :: name !< buffer to read the dataset name into |
| 219 |
integer(kind=c_int64_t), intent(in) :: l_name !< size of name |
| 220 |
end function |
| 221 |
|
| 222 |
integer(kind=c_int64_t) function h5ptc_getdatasetinfo (filehandle,index,name,data_type,nelem,l_name) bind(C) |
| 223 |
import |
| 224 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 225 |
integer(kind=c_int64_t), intent(in) :: index !< index of dataset to query (starting from 0) |
| 226 |
character(kind=c_char), dimension(1), intent(out) :: name !< buffer to read the dataset name into |
| 227 |
integer(kind=c_int64_t), intent(out) :: data_type !< type of data in dataset |
| 228 |
integer(kind=c_int64_t), intent(out) :: nelem !< number of elements |
| 229 |
integer(kind=c_int64_t), intent(in) :: l_name !< size of name |
| 230 |
end function |
| 231 |
|
| 232 |
! |
| 233 |
! Setting and getting views |
| 234 |
! (as no strings are passed these are just interfaces to the c routines that convert the filehandle) |
| 235 |
! |
| 236 |
integer(kind=c_int64_t) function h5pt_setview (filehandle,start,end) bind(C,name="h5ptc_setview") |
| 237 |
import |
| 238 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 239 |
integer(kind=c_int64_t), intent(in) :: start !< offset of the first particle in the view |
| 240 |
integer(kind=c_int64_t), intent(in) :: end !< offset of the last particle in the view (inclusive) |
| 241 |
end function |
| 242 |
|
| 243 |
integer(kind=c_int64_t) function h5pt_setview_indices (filehandle,indices,nelem) bind(C,name="h5ptc_setview_indices") |
| 244 |
import |
| 245 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 246 |
integer(kind=c_int64_t), intent(in) :: indices(*) !< list of indicies to select in this view |
| 247 |
integer(kind=c_int64_t), intent(in) :: nelem !< number of particles in the list |
| 248 |
end function |
| 249 |
|
| 250 |
integer(kind=c_int64_t) function h5pt_resetview (filehandle) bind(C,name="h5ptc_resetview") |
| 251 |
import |
| 252 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 253 |
end function |
| 254 |
|
| 255 |
integer(kind=c_int64_t) function h5pt_hasview (filehandle) bind(C,name="h5ptc_hasview") |
| 256 |
import |
| 257 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 258 |
end function |
| 259 |
|
| 260 |
integer(kind=c_int64_t) function h5pt_getview (filehandle,start,end) bind(C,name="h5ptc_getview") |
| 261 |
import |
| 262 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 263 |
integer(kind=c_int64_t), intent(out) :: start !< buffer to store the offset of the first particle in the view |
| 264 |
integer(kind=c_int64_t), intent(out) :: end !< buffer to store the offset of the last particle in the view (inclusive) |
| 265 |
end function |
| 266 |
|
| 267 |
! |
| 268 |
! Reading and writing datasets |
| 269 |
! |
| 270 |
integer(kind=c_int64_t) function h5ptc_writedata_r8 ( filehandle, name, data ) bind(C) |
| 271 |
import |
| 272 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 273 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the dataset |
| 274 |
real(kind=c_double), intent(in) :: data(*) !< the array of float64 data to write |
| 275 |
end function |
| 276 |
|
| 277 |
integer(kind=c_int64_t) function h5ptc_readdata_r8 (filehandle,name,data) bind(C) |
| 278 |
import |
| 279 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 280 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the dataset |
| 281 |
real(kind=c_double), intent(out) :: data(*) !< array to read float64 data into |
| 282 |
end function |
| 283 |
|
| 284 |
integer(kind=c_int64_t) function h5ptc_writedata_r4 ( filehandle, name, data ) bind(C) |
| 285 |
import |
| 286 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 287 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the dataset |
| 288 |
real(kind=c_float), intent(in) :: data(*) !< the array of float32 data to write |
| 289 |
end function |
| 290 |
|
| 291 |
integer(kind=c_int64_t) function h5ptc_readdata_r4 (filehandle,name,data) bind(C) |
| 292 |
import |
| 293 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 294 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the dataset |
| 295 |
real(kind=c_float), intent(out) :: data(*) !< array to read float32 data into |
| 296 |
end function |
| 297 |
|
| 298 |
integer(kind=c_int64_t) function h5ptc_writedata_i8 ( filehandle, name, data ) bind(C) |
| 299 |
import |
| 300 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 301 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the dataset |
| 302 |
integer(kind=c_int64_t), intent(in) :: data(*) !< the array of int64 data to write |
| 303 |
end function |
| 304 |
|
| 305 |
integer(kind=c_int64_t) function h5ptc_readdata_i8 (filehandle,name,data) bind(C) |
| 306 |
import |
| 307 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 308 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the dataset |
| 309 |
integer(kind=c_int64_t), intent(out) :: data(*) !< array to read int64 data into |
| 310 |
end function |
| 311 |
|
| 312 |
integer(kind=c_int64_t) function h5ptc_writedata_i4 ( filehandle, name, data ) bind(C) |
| 313 |
import |
| 314 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 315 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the dataset |
| 316 |
integer(kind=c_int), intent(in) :: data(*) !< the array of int32 data to write |
| 317 |
end function |
| 318 |
|
| 319 |
integer(kind=c_int64_t) function h5ptc_readdata_i4 (filehandle,name,data) bind(C) |
| 320 |
import |
| 321 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 322 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the dataset |
| 323 |
integer(kind=c_int), intent(out) :: data(*) !< array to read int32 data into |
| 324 |
end function |
| 325 |
|
| 326 |
! |
| 327 |
! routines where no conversion of anything is needed: i.e. just call H5Part C routines directly |
| 328 |
! |
| 329 |
integer(kind=c_int64_t) function h5pt_set_verbosity_level ( level ) bind(C,name="H5PartSetVerbosityLevel") |
| 330 |
import |
| 331 |
integer(kind=c_int64_t), intent(in) :: level !< the level from 0 (no output) to 5 (most detailed) |
| 332 |
end function |
| 333 |
|
| 334 |
end interface |
| 335 |
|
| 336 |
contains |
| 337 |
!--------------------------------------------------------------------------- |
| 338 |
! |
| 339 |
! wrappers for functions with string arguments: |
| 340 |
! converts strings into C strings |
| 341 |
! |
| 342 |
!--------------------------------------------------------------------------- |
| 343 |
integer(kind=c_int64_t) function h5pt_openr( filename ) |
| 344 |
implicit none |
| 345 |
character(len=*), intent(in) :: filename !< the filename to open for reading |
| 346 |
|
| 347 |
h5pt_openr = h5ptc_openr( cstring(filename) ) |
| 348 |
|
| 349 |
end function |
| 350 |
|
| 351 |
integer(kind=c_int64_t) function h5pt_openw ( filename ) |
| 352 |
implicit none |
| 353 |
character(len=*), intent(in) :: filename !< the filename to open for writing |
| 354 |
|
| 355 |
h5pt_openw = h5ptc_openw ( cstring(filename) ) |
| 356 |
|
| 357 |
end function |
| 358 |
|
| 359 |
integer(kind=c_int64_t) function h5pt_opena ( filename ) |
| 360 |
implicit none |
| 361 |
character(len=*), intent(in) :: filename !< the filename to open for appending |
| 362 |
|
| 363 |
h5pt_opena = h5ptc_opena ( cstring(filename) ) |
| 364 |
|
| 365 |
end function |
| 366 |
|
| 367 |
integer(kind=c_int64_t) function h5pt_openr_align ( filename, align ) |
| 368 |
implicit none |
| 369 |
character(len=*), intent(in) :: filename !< the filename to open for reading |
| 370 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 371 |
|
| 372 |
h5pt_openr_align = h5ptc_openr_align ( cstring(filename), align ) |
| 373 |
|
| 374 |
end function |
| 375 |
|
| 376 |
integer(kind=c_int64_t) function h5pt_openw_align ( filename, align ) |
| 377 |
implicit none |
| 378 |
character(len=*), intent(in) :: filename !< the filename to open for writing |
| 379 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 380 |
|
| 381 |
h5pt_openw_align = h5ptc_openw_align ( cstring(filename), align ) |
| 382 |
|
| 383 |
end function |
| 384 |
|
| 385 |
integer(kind=c_int64_t) function h5pt_opena_align ( filename, align ) |
| 386 |
implicit none |
| 387 |
character(len=*), intent(in) :: filename !< the filename to open for appending |
| 388 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 389 |
|
| 390 |
h5pt_opena_align = h5ptc_opena_align ( cstring(filename), align ) |
| 391 |
|
| 392 |
end function |
| 393 |
|
| 394 |
#ifdef PARALLEL_IO |
| 395 |
! |
| 396 |
! opening files (parallel I/O) |
| 397 |
! |
| 398 |
integer(kind=c_int64_t) function h5pt_openr_par ( filename, mpi_communicator ) |
| 399 |
implicit none |
| 400 |
character(len=*), intent(in) :: filename !< the filename to open for reading |
| 401 |
integer, intent(in) :: mpi_communicator !< the MPI communicator used by the program |
| 402 |
|
| 403 |
h5pt_openr_par = h5ptc_openr_par ( cstring(filename), mpi_communicator ) |
| 404 |
|
| 405 |
end function |
| 406 |
|
| 407 |
integer(kind=c_int64_t) function h5pt_openw_par ( filename, mpi_communicator ) |
| 408 |
implicit none |
| 409 |
character(len=*), intent(in) :: filename !< the filename to open for writing |
| 410 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 411 |
|
| 412 |
h5pt_openw_par = h5ptc_openw_par ( cstring(filename), mpi_communicator ) |
| 413 |
|
| 414 |
end function |
| 415 |
|
| 416 |
integer(kind=c_int64_t) function h5pt_opena_par ( filename, mpi_communicator ) |
| 417 |
implicit none |
| 418 |
character(len=*), intent(in) :: filename !< the filename to open for appending |
| 419 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 420 |
|
| 421 |
h5pt_opena_par = h5ptc_opena_par ( cstring(filename), mpi_communicator ) |
| 422 |
|
| 423 |
end function |
| 424 |
|
| 425 |
integer(kind=c_int64_t) function h5pt_openr_par_align ( filename, mpi_communicator, align ) |
| 426 |
implicit none |
| 427 |
character(len=*), intent(in) :: filename !< the filename to open for reading |
| 428 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 429 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 430 |
|
| 431 |
h5pt_openr_par_align = h5ptc_openr_par_align ( cstring(filename), mpi_communicator, align ) |
| 432 |
|
| 433 |
end function |
| 434 |
|
| 435 |
integer(kind=c_int64_t) function h5pt_openw_par_align ( filename, mpi_communicator, align, flags ) |
| 436 |
implicit none |
| 437 |
character(len=*), intent(in) :: filename !< the filename to open for writing |
| 438 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 439 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 440 |
character(len=*), intent(in) :: flags !< additional flags |
| 441 |
|
| 442 |
h5pt_openw_par_align = h5ptc_openw_par_align ( cstring(filename), mpi_communicator, align, cstring(flags) ) |
| 443 |
|
| 444 |
end function |
| 445 |
|
| 446 |
integer(kind=c_int64_t) function h5pt_opena_par_align ( filename, mpi_communicator, align, flags ) |
| 447 |
implicit none |
| 448 |
character(len=*), intent(in) :: filename !< the filename to open for appending |
| 449 |
integer, intent(in) :: mpi_communicator !< the MPI_Communicator used by the program |
| 450 |
integer(kind=c_int64_t), intent(in) :: align !< alignment value in bytes |
| 451 |
character(len=*), intent(in) :: flags !< additional flags |
| 452 |
|
| 453 |
h5pt_opena_par_align = h5ptc_opena_par_align ( cstring(filename), mpi_communicator, align, cstring(flags) ) |
| 454 |
|
| 455 |
end function |
| 456 |
#endif |
| 457 |
|
| 458 |
! |
| 459 |
! Setting up the data model |
| 460 |
! |
| 461 |
integer(kind=c_int64_t) function h5pt_getdatasetname (filehandle,index,name) |
| 462 |
implicit none |
| 463 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 464 |
integer(kind=c_int64_t), intent(in) :: index !< index of dataset to query (starting from 0) |
| 465 |
character(len=*), intent(out) :: name !< buffer to read the dataset name into |
| 466 |
integer(kind=c_int64_t) :: l_name |
| 467 |
|
| 468 |
l_name = len(name) |
| 469 |
h5pt_getdatasetname = h5ptc_getdatasetname(filehandle,index,name,l_name) |
| 470 |
name = fstring(name) |
| 471 |
|
| 472 |
end function h5pt_getdatasetname |
| 473 |
|
| 474 |
integer(kind=c_int64_t) function h5pt_getdatasetinfo(filehandle,idx,name,data_type,nelem) |
| 475 |
implicit none |
| 476 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 477 |
integer(kind=c_int64_t), intent(in) :: idx !< index of dataset to query (starting from 0) |
| 478 |
character(len=*), intent(out) :: name !< buffer to read the dataset name into |
| 479 |
integer(kind=c_int64_t), intent(out) :: data_type !< type of data in dataset |
| 480 |
integer(kind=c_int64_t), intent(out) :: nelem !< number of elements |
| 481 |
integer(kind=c_int64_t) :: l_name |
| 482 |
|
| 483 |
l_name = len(name) |
| 484 |
h5pt_getdatasetinfo = h5ptc_getdatasetinfo(filehandle,idx,name,data_type,nelem,l_name) |
| 485 |
name = fstring(name) |
| 486 |
|
| 487 |
end function h5pt_getdatasetinfo |
| 488 |
|
| 489 |
! |
| 490 |
! Reading and writing datasets |
| 491 |
! |
| 492 |
integer(kind=c_int64_t) function h5pt_writedata_r8 ( filehandle, name, data ) |
| 493 |
implicit none |
| 494 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 495 |
character(len=*), intent(in) :: name !< the name of the dataset |
| 496 |
real(kind=c_double), intent(in) :: data(*) !< the array of float64 data to write |
| 497 |
|
| 498 |
h5pt_writedata_r8 = h5ptc_writedata_r8 ( filehandle, cstring(name), data ) |
| 499 |
|
| 500 |
end function |
| 501 |
|
| 502 |
integer(kind=c_int64_t) function h5pt_readdata_r8 ( filehandle, name, data) |
| 503 |
implicit none |
| 504 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 505 |
character(len=*), intent(in) :: name !< the name of the dataset |
| 506 |
real(kind=c_double), intent(out) :: data(*) !< array to read float64 data into |
| 507 |
|
| 508 |
h5pt_readdata_r8 = h5ptc_readdata_r8 ( filehandle, cstring(name), data) |
| 509 |
|
| 510 |
end function |
| 511 |
|
| 512 |
integer(kind=c_int64_t) function h5pt_writedata_r4 ( filehandle, name, data ) |
| 513 |
implicit none |
| 514 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 515 |
character(len=*), intent(in) :: name !< the name of the dataset |
| 516 |
real(kind=c_float), intent(in) :: data(*) !< the array of float32 data to write |
| 517 |
|
| 518 |
h5pt_writedata_r4 = h5ptc_writedata_r4 ( filehandle, cstring(name), data ) |
| 519 |
|
| 520 |
end function |
| 521 |
|
| 522 |
integer(kind=c_int64_t) function h5pt_readdata_r4 ( filehandle, name, data) |
| 523 |
implicit none |
| 524 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 525 |
character(len=*), intent(in) :: name !< the name of the dataset |
| 526 |
real(kind=c_float), intent(out) :: data(*) !< array to read float32 data into |
| 527 |
|
| 528 |
h5pt_readdata_r4 = h5ptc_readdata_r4 ( filehandle, cstring(name), data) |
| 529 |
|
| 530 |
end function |
| 531 |
|
| 532 |
integer(kind=c_int64_t) function h5pt_writedata_i8 ( filehandle, name, data ) |
| 533 |
implicit none |
| 534 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 535 |
character(len=*), intent(in) :: name !< the name of the dataset |
| 536 |
integer(kind=c_int64_t), intent(in) :: data(*) !< the array of int64 data to write |
| 537 |
|
| 538 |
h5pt_writedata_i8 = h5ptc_writedata_i8 ( filehandle, cstring(name), data ) |
| 539 |
|
| 540 |
end function |
| 541 |
|
| 542 |
integer(kind=c_int64_t) function h5pt_readdata_i8 ( filehandle, name, data) |
| 543 |
implicit none |
| 544 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 545 |
character(len=*), intent(in) :: name !< the name of the dataset |
| 546 |
integer(kind=c_int64_t), intent(out) :: data(*) !< array to read int64 data into |
| 547 |
|
| 548 |
h5pt_readdata_i8 = h5ptc_readdata_i8 ( filehandle, cstring(name), data) |
| 549 |
|
| 550 |
end function |
| 551 |
|
| 552 |
integer(kind=c_int64_t) function h5pt_writedata_i4 ( filehandle, name, data ) |
| 553 |
implicit none |
| 554 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 555 |
character(len=*), intent(in) :: name !< the name of the dataset |
| 556 |
integer(kind=c_int), intent(in) :: data(*) !< the array of int32 data to write |
| 557 |
|
| 558 |
h5pt_writedata_i4 = h5ptc_writedata_i4 ( filehandle, cstring(name), data ) |
| 559 |
|
| 560 |
end function |
| 561 |
|
| 562 |
integer(kind=c_int64_t) function h5pt_readdata_i4 (filehandle,name,data) |
| 563 |
implicit none |
| 564 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 565 |
character(len=*), intent(in) :: name !< the name of the dataset |
| 566 |
integer(kind=c_int), intent(out) :: data(*) !< array to read int32 data into |
| 567 |
|
| 568 |
h5pt_readdata_i4 = h5ptc_readdata_i4 ( filehandle, cstring(name), data) |
| 569 |
|
| 570 |
end function |
| 571 |
|
| 572 |
!--------------------------------------------------------------------------- |
| 573 |
! |
| 574 |
! function to safely convert a string to c format (ie. with a terminating |
| 575 |
! ascii null character) |
| 576 |
! |
| 577 |
!--------------------------------------------------------------------------- |
| 578 |
function cstring(string) |
| 579 |
implicit none |
| 580 |
character(len=*), intent(in) :: string |
| 581 |
character(len=len(string)+1) :: cstring |
| 582 |
|
| 583 |
cstring = trim(string)//char(0) |
| 584 |
|
| 585 |
end function cstring |
| 586 |
|
| 587 |
!--------------------------------------------------------------------------- |
| 588 |
! |
| 589 |
! function to safely convert a string from c format (ie. with a terminating |
| 590 |
! ascii null character) back to a normal Fortran string |
| 591 |
! |
| 592 |
!--------------------------------------------------------------------------- |
| 593 |
function fstring(string) |
| 594 |
implicit none |
| 595 |
character(len=*), intent(in) :: string !< the name of the dataset |
| 596 |
character(len=len(string)) :: fstring |
| 597 |
integer :: idx |
| 598 |
|
| 599 |
idx = index(string,char(0)) |
| 600 |
if (idx.gt.1) then |
| 601 |
fstring = string(1:idx-1) |
| 602 |
else |
| 603 |
fstring = '' |
| 604 |
endif |
| 605 |
|
| 606 |
end function fstring |
| 607 |
|
| 608 |
end module h5part |