| 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 |
! This module contains the attributes interface |
| 14 |
! |
| 15 |
!------------------------------------------------------------- |
| 16 |
module h5partattrib |
| 17 |
use, intrinsic :: iso_c_binding, only:c_char,c_int,c_int64_t,c_double,c_float |
| 18 |
implicit none |
| 19 |
! |
| 20 |
! interfaces provided by this module |
| 21 |
! |
| 22 |
public :: h5pt_getnfileattribs,h5pt_getfileattribinfo |
| 23 |
public :: h5pt_getnstepattribs,h5pt_getstepattribinfo |
| 24 |
public :: h5pt_writefileattrib,h5pt_readfileattrib |
| 25 |
public :: h5pt_writestepattrib,h5pt_readstepattrib |
| 26 |
! |
| 27 |
! the type-specific routines are also public |
| 28 |
! (could make these private to allow only |
| 29 |
! the generic interface to be used) |
| 30 |
! |
| 31 |
public :: h5pt_writefileattrib_i4,h5pt_writefileattrib_i8, & |
| 32 |
h5pt_writefileattrib_r4,h5pt_writefileattrib_r8, & |
| 33 |
h5pt_writefileattrib_string |
| 34 |
public :: h5pt_readfileattrib_i4,h5pt_readfileattrib_i8, & |
| 35 |
h5pt_readfileattrib_r4,h5pt_readfileattrib_r8, & |
| 36 |
h5pt_readfileattrib_string |
| 37 |
public :: h5pt_writestepattrib_i4,h5pt_writestepattrib_i8, & |
| 38 |
h5pt_writestepattrib_r4,h5pt_writestepattrib_r8, & |
| 39 |
h5pt_writestepattrib_string |
| 40 |
public :: h5pt_readstepattrib_i4,h5pt_readstepattrib_i8, & |
| 41 |
h5pt_readstepattrib_r4,h5pt_readstepattrib_r8, & |
| 42 |
h5pt_readstepattrib_string |
| 43 |
|
| 44 |
private |
| 45 |
|
| 46 |
! |
| 47 |
! generic interface for writing file attributes of any type |
| 48 |
! |
| 49 |
interface h5pt_writefileattrib |
| 50 |
module procedure h5pt_writefileattrib_i4,h5pt_writefileattrib_i8, & |
| 51 |
h5pt_writefileattrib_r4,h5pt_writefileattrib_r8, & |
| 52 |
h5pt_writefileattrib_string |
| 53 |
|
| 54 |
end interface h5pt_writefileattrib |
| 55 |
! |
| 56 |
! generic interface for reading file attributes of any type |
| 57 |
! |
| 58 |
interface h5pt_readfileattrib |
| 59 |
module procedure h5pt_readfileattrib_i4,h5pt_readfileattrib_i8, & |
| 60 |
h5pt_readfileattrib_r4,h5pt_readfileattrib_r8, & |
| 61 |
h5pt_readfileattrib_string |
| 62 |
|
| 63 |
end interface h5pt_readfileattrib |
| 64 |
! |
| 65 |
! generic interface for writing step attributes of any type |
| 66 |
! |
| 67 |
interface h5pt_writestepattrib |
| 68 |
module procedure h5pt_writestepattrib_i4,h5pt_writestepattrib_i8, & |
| 69 |
h5pt_writestepattrib_r4,h5pt_writestepattrib_r8, & |
| 70 |
h5pt_writestepattrib_string |
| 71 |
|
| 72 |
end interface h5pt_writestepattrib |
| 73 |
! |
| 74 |
! generic interface for reading step attributes of any type |
| 75 |
! |
| 76 |
interface h5pt_readstepattrib |
| 77 |
module procedure h5pt_readstepattrib_i4,h5pt_readstepattrib_i8, & |
| 78 |
h5pt_readstepattrib_r4,h5pt_readstepattrib_r8, & |
| 79 |
h5pt_readstepattrib_string |
| 80 |
|
| 81 |
end interface h5pt_readstepattrib |
| 82 |
|
| 83 |
!--------------------------- |
| 84 |
! |
| 85 |
! interfaces to c routines |
| 86 |
! |
| 87 |
!--------------------------- |
| 88 |
interface |
| 89 |
! |
| 90 |
! file attributes: interfaces to c routines |
| 91 |
! |
| 92 |
integer(kind=c_int64_t) function h5pt_getnfileattribs (filehandle) bind(C,name="h5ptc_getnfileattribs") |
| 93 |
import |
| 94 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 95 |
end function |
| 96 |
|
| 97 |
integer(kind=c_int64_t) function h5ptc_getfileattribinfo (filehandle,idx,name,nelem,l_name) bind(C) |
| 98 |
import |
| 99 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 100 |
integer(kind=c_int64_t), intent(in) :: idx !< index of the attribute to query (starting from 0) |
| 101 |
character(kind=c_char), dimension(1), intent(out) :: name !< buffer to read the attribute name into |
| 102 |
integer(kind=c_int64_t), intent(out) :: nelem !< number of elements in the attribute's array |
| 103 |
integer(kind=c_int64_t), intent(in) :: l_name !< size of name |
| 104 |
end function |
| 105 |
|
| 106 |
integer(kind=c_int64_t) function h5ptc_writefileattrib_r8 ( filehandle, name, data, nelem) bind(C) |
| 107 |
import |
| 108 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 109 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 110 |
real(kind=c_double), intent(in) :: data(*) !< the array of data to write into the attribute |
| 111 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 112 |
end function |
| 113 |
|
| 114 |
integer(kind=c_int64_t) function h5ptc_readfileattrib_r8 ( filehandle, name, data ) bind(C) |
| 115 |
import |
| 116 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 117 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 118 |
real(kind=c_double), intent(out) :: data(*) !< buffer to read value into |
| 119 |
end function |
| 120 |
|
| 121 |
integer(kind=c_int64_t) function h5ptc_writefileattrib_r4 ( filehandle, name, data, nelem) bind(C) |
| 122 |
import |
| 123 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 124 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 125 |
real(kind=c_float), intent(in) :: data(*) !< the array of data to write into the attribute |
| 126 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 127 |
end function |
| 128 |
|
| 129 |
integer(kind=c_int64_t) function h5ptc_readfileattrib_r4 ( filehandle, name, data ) bind(C) |
| 130 |
import |
| 131 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 132 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 133 |
real(kind=c_float), intent(out) :: data(*) !< buffer to read value into |
| 134 |
end function |
| 135 |
|
| 136 |
integer(kind=c_int64_t) function h5ptc_writefileattrib_i8 ( filehandle, name, data, nelem) bind(C) |
| 137 |
import |
| 138 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 139 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 140 |
integer(kind=c_int64_t), intent(in) :: data(*) !< the array of data to write into the attribute |
| 141 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 142 |
end function |
| 143 |
|
| 144 |
integer(kind=c_int64_t) function h5ptc_readfileattrib_i8 ( filehandle, name, data ) bind(C) |
| 145 |
import |
| 146 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 147 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 148 |
integer(kind=c_int64_t), intent(out) :: data(*) !< buffer to read value into |
| 149 |
end function |
| 150 |
|
| 151 |
integer(kind=c_int64_t) function h5ptc_writefileattrib_i4 ( filehandle, name, data, nelem) bind(C) |
| 152 |
import |
| 153 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 154 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 155 |
integer(kind=c_int), intent(in) :: data(*) !< the array of data to write into the attribute |
| 156 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 157 |
end function |
| 158 |
|
| 159 |
integer(kind=c_int64_t) function h5ptc_readfileattrib_i4 ( filehandle, name, data ) bind(C) |
| 160 |
import |
| 161 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 162 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 163 |
integer(kind=c_int), intent(out) :: data(*) !< buffer to read value into |
| 164 |
end function |
| 165 |
|
| 166 |
integer(kind=c_int64_t) function h5ptc_writefileattrib_string (filehandle,name,value) bind(C) |
| 167 |
import |
| 168 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 169 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 170 |
character(kind=c_char), dimension(1), intent(in) :: value !< the string value to store |
| 171 |
end function |
| 172 |
|
| 173 |
integer(kind=c_int64_t) function h5ptc_readfileattrib_string (filehandle,name,value) bind(C) |
| 174 |
import |
| 175 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 176 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 177 |
character(kind=c_char), dimension(1), intent(out) :: value !< buffer to read the string value into |
| 178 |
end function |
| 179 |
|
| 180 |
! |
| 181 |
! step attributes: interfaces to c routines |
| 182 |
! |
| 183 |
integer(kind=c_int64_t) function h5pt_getnstepattribs (filehandle) bind(C,name="h5ptc_getnstepattribs") |
| 184 |
import |
| 185 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 186 |
end function |
| 187 |
|
| 188 |
integer(kind=c_int64_t) function h5ptc_getstepattribinfo (filehandle,idx,name,nelem,l_name) bind(C) |
| 189 |
import |
| 190 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 191 |
integer(kind=c_int64_t), intent(in) :: idx !< index of the attribute to query (starting from 0) |
| 192 |
character(kind=c_char), dimension(1), intent(out) :: name !< buffer to read the attribute name into |
| 193 |
integer(kind=c_int64_t), intent(out) :: nelem !< number of elements in the attribute's array |
| 194 |
integer(kind=c_int64_t), intent(in) :: l_name !< number of elements in the attribute's array |
| 195 |
end function |
| 196 |
|
| 197 |
integer(kind=c_int64_t) function h5ptc_writestepattrib_r8 ( filehandle, name, data, nelem) bind(C) |
| 198 |
import |
| 199 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 200 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 201 |
real(kind=c_double), intent(in) :: data(*) !< the array of data to write into the attribute |
| 202 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 203 |
end function |
| 204 |
|
| 205 |
integer(kind=c_int64_t) function h5ptc_readstepattrib_r8 ( filehandle, name, data ) bind(C) |
| 206 |
import |
| 207 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 208 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 209 |
real(kind=c_double), intent(out) :: data(*) !< buffer to read value into |
| 210 |
end function |
| 211 |
|
| 212 |
integer(kind=c_int64_t) function h5ptc_writestepattrib_r4 ( filehandle, name, data, nelem) bind(C) |
| 213 |
import |
| 214 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 215 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 216 |
real(kind=c_float), intent(in) :: data(*) !< the array of data to write into the attribute |
| 217 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 218 |
end function |
| 219 |
|
| 220 |
integer(kind=c_int64_t) function h5ptc_readstepattrib_r4 ( filehandle, name, data ) bind(C) |
| 221 |
import |
| 222 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 223 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 224 |
real(kind=c_float), intent(out) :: data(*) !< buffer to read value into |
| 225 |
end function |
| 226 |
|
| 227 |
integer(kind=c_int64_t) function h5ptc_writestepattrib_i8 ( filehandle, name, data, nelem) bind(C) |
| 228 |
import |
| 229 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 230 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 231 |
integer(kind=c_int64_t), intent(in) :: data(*) !< the array of data to write into the attribute |
| 232 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 233 |
end function |
| 234 |
|
| 235 |
integer(kind=c_int64_t) function h5ptc_readstepattrib_i8 ( filehandle, name, data ) bind(C) |
| 236 |
import |
| 237 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 238 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 239 |
integer(kind=c_int64_t), intent(out) :: data(*) !< buffer to read value into |
| 240 |
end function |
| 241 |
|
| 242 |
integer(kind=c_int64_t) function h5ptc_writestepattrib_i4 ( filehandle, name, data, nelem) bind(C) |
| 243 |
import |
| 244 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 245 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 246 |
integer(kind=c_int), intent(in) :: data(*) !< the array of data to write into the attribute |
| 247 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 248 |
end function |
| 249 |
|
| 250 |
integer(kind=c_int64_t) function h5ptc_readstepattrib_i4 ( filehandle, name, data ) bind(C) |
| 251 |
import |
| 252 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 253 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 254 |
integer(kind=c_int), intent(out) :: data(*) !< buffer to read value into |
| 255 |
end function |
| 256 |
|
| 257 |
! |
| 258 |
! read/write string |
| 259 |
! |
| 260 |
integer(kind=c_int64_t) function h5ptc_writestepattrib_string (filehandle,name,value) bind(C) |
| 261 |
import |
| 262 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 263 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 264 |
character(kind=c_char), dimension(1), intent(in) :: value !< the string value to store |
| 265 |
end function |
| 266 |
|
| 267 |
integer(kind=c_int64_t) function h5ptc_readstepattrib_string (filehandle,name,value) bind(C) |
| 268 |
import |
| 269 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 270 |
character(kind=c_char), dimension(1), intent(in) :: name !< the name of the attribute |
| 271 |
character(kind=c_char), dimension(1), intent(out) :: value !< buffer to read the string value into |
| 272 |
end function |
| 273 |
|
| 274 |
end interface |
| 275 |
|
| 276 |
contains |
| 277 |
|
| 278 |
!--------------------------------------------------------------------------- |
| 279 |
! |
| 280 |
! wrappers for functions with string arguments: |
| 281 |
! converts strings into C strings |
| 282 |
! |
| 283 |
!--------------------------------------------------------------------------- |
| 284 |
|
| 285 |
! |
| 286 |
! file attributes |
| 287 |
! |
| 288 |
integer(kind=c_int64_t) function h5pt_getfileattribinfo (filehandle,idx,name,nelem) |
| 289 |
implicit none |
| 290 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 291 |
integer(kind=c_int64_t), intent(in) :: idx !< index of the attribute to query (starting from 0) |
| 292 |
character(len=*), intent(out) :: name !< buffer to read the attribute name into |
| 293 |
integer(kind=c_int64_t), intent(out) :: nelem !< number of elements in the attribute's array |
| 294 |
integer(kind=c_int64_t) :: l_name !< size of name |
| 295 |
|
| 296 |
l_name = len(name) |
| 297 |
h5pt_getfileattribinfo = h5ptc_getfileattribinfo (filehandle,idx,name,nelem,l_name) |
| 298 |
name = fstring(name) |
| 299 |
|
| 300 |
end function |
| 301 |
|
| 302 |
integer(kind=c_int64_t) function h5pt_writefileattrib_r8 ( filehandle, name, data, nelem) |
| 303 |
implicit none |
| 304 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 305 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 306 |
real(kind=c_double), intent(in) :: data(*) !< the array of data to write into the attribute |
| 307 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 308 |
|
| 309 |
h5pt_writefileattrib_r8 = h5ptc_writefileattrib_r8 ( filehandle, cstring(name), data, nelem) |
| 310 |
|
| 311 |
end function h5pt_writefileattrib_r8 |
| 312 |
|
| 313 |
integer(kind=c_int64_t) function h5pt_readfileattrib_r8 ( filehandle, name, data ) |
| 314 |
implicit none |
| 315 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 316 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 317 |
real(kind=c_double), intent(out) :: data(*) !< buffer to read value into |
| 318 |
|
| 319 |
h5pt_readfileattrib_r8 = h5ptc_readfileattrib_r8 ( filehandle, cstring(name), data ) |
| 320 |
|
| 321 |
end function |
| 322 |
|
| 323 |
integer(kind=c_int64_t) function h5pt_writefileattrib_r4 ( filehandle, name, data, nelem) |
| 324 |
implicit none |
| 325 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 326 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 327 |
real(kind=c_float), intent(in) :: data(*) !< the array of data to write into the attribute |
| 328 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 329 |
|
| 330 |
h5pt_writefileattrib_r4 = h5ptc_writefileattrib_r4( filehandle, cstring(name), data, nelem) |
| 331 |
|
| 332 |
end function |
| 333 |
|
| 334 |
integer(kind=c_int64_t) function h5pt_readfileattrib_r4 ( filehandle, name, data ) |
| 335 |
implicit none |
| 336 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 337 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 338 |
real(kind=c_float), intent(out) :: data(*) !< buffer to read value into |
| 339 |
|
| 340 |
h5pt_readfileattrib_r4 = h5ptc_readfileattrib_r4( filehandle, cstring(name), data ) |
| 341 |
|
| 342 |
end function |
| 343 |
|
| 344 |
integer(kind=c_int64_t) function h5pt_writefileattrib_i8 ( filehandle, name, data, nelem) |
| 345 |
implicit none |
| 346 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 347 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 348 |
integer(kind=c_int64_t), intent(in) :: data(*) !< the array of data to write into the attribute |
| 349 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 350 |
|
| 351 |
h5pt_writefileattrib_i8 = h5ptc_writefileattrib_i8( filehandle, cstring(name), data, nelem) |
| 352 |
|
| 353 |
end function |
| 354 |
|
| 355 |
integer(kind=c_int64_t) function h5pt_readfileattrib_i8 ( filehandle, name, data ) |
| 356 |
implicit none |
| 357 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 358 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 359 |
integer(kind=c_int64_t), intent(out) :: data(*) !< buffer to read value into |
| 360 |
|
| 361 |
h5pt_readfileattrib_i8 = h5ptc_readfileattrib_i8( filehandle, cstring(name), data ) |
| 362 |
|
| 363 |
end function |
| 364 |
|
| 365 |
integer(kind=c_int64_t) function h5pt_writefileattrib_i4 ( filehandle, name, data, nelem) |
| 366 |
implicit none |
| 367 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 368 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 369 |
integer(kind=c_int), intent(in) :: data(*) !< the array of data to write into the attribute |
| 370 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 371 |
|
| 372 |
h5pt_writefileattrib_i4 = h5ptc_writefileattrib_i4( filehandle, cstring(name), data, nelem) |
| 373 |
|
| 374 |
end function |
| 375 |
|
| 376 |
integer(kind=c_int64_t) function h5pt_readfileattrib_i4 ( filehandle, name, data ) |
| 377 |
implicit none |
| 378 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 379 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 380 |
integer(kind=c_int), intent(out) :: data(*) !< buffer to read value into |
| 381 |
|
| 382 |
h5pt_readfileattrib_i4 = h5ptc_readfileattrib_i4 ( filehandle, cstring(name), data ) |
| 383 |
|
| 384 |
end function |
| 385 |
|
| 386 |
integer(kind=c_int64_t) function h5pt_writefileattrib_string ( filehandle, name, value) |
| 387 |
implicit none |
| 388 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 389 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 390 |
character(len=*), intent(in) :: value !< the string value to store |
| 391 |
|
| 392 |
h5pt_writefileattrib_string = h5ptc_writefileattrib_string ( filehandle, cstring(name), cstring(value)) |
| 393 |
|
| 394 |
end function |
| 395 |
|
| 396 |
integer(kind=c_int64_t) function h5pt_readfileattrib_string ( filehandle, name, value) |
| 397 |
implicit none |
| 398 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 399 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 400 |
character(len=*), intent(out) :: value !< buffer to read the string value into |
| 401 |
|
| 402 |
h5pt_readfileattrib_string = h5ptc_readfileattrib_string ( filehandle, cstring(name), value) |
| 403 |
value = fstring(value) |
| 404 |
|
| 405 |
end function |
| 406 |
|
| 407 |
! |
| 408 |
! step attributes: |
| 409 |
! |
| 410 |
integer(kind=c_int64_t) function h5pt_getstepattribinfo (filehandle,idx,name,nelem) |
| 411 |
implicit none |
| 412 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 413 |
integer(kind=c_int64_t), intent(in) :: idx !< index of the attribute to query (starting from 0) |
| 414 |
character(len=*), intent(out) :: name !< buffer to read the attribute name into |
| 415 |
integer(kind=c_int64_t), intent(out) :: nelem !< number of elements in the attribute's array |
| 416 |
integer(kind=c_int64_t) :: l_name !< number of elements in the attribute's array |
| 417 |
|
| 418 |
l_name = len(name) |
| 419 |
h5pt_getstepattribinfo = h5ptc_getstepattribinfo (filehandle,idx,name,nelem,l_name) |
| 420 |
name = fstring(name) |
| 421 |
|
| 422 |
end function |
| 423 |
|
| 424 |
integer(kind=c_int64_t) function h5pt_writestepattrib_r8 ( filehandle, name, data, nelem) |
| 425 |
implicit none |
| 426 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 427 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 428 |
real(kind=c_double), intent(in) :: data(*) !< the array of data to write into the attribute |
| 429 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 430 |
|
| 431 |
h5pt_writestepattrib_r8 = h5ptc_writestepattrib_r8 ( filehandle, cstring(name), data, nelem) |
| 432 |
|
| 433 |
end function |
| 434 |
|
| 435 |
integer(kind=c_int64_t) function h5pt_readstepattrib_r8 ( filehandle, name, data ) |
| 436 |
implicit none |
| 437 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 438 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 439 |
real(kind=c_double), intent(out) :: data(*) !< buffer to read value into |
| 440 |
|
| 441 |
h5pt_readstepattrib_r8 = h5ptc_readstepattrib_r8 ( filehandle, cstring(name), data ) |
| 442 |
|
| 443 |
end function |
| 444 |
|
| 445 |
integer(kind=c_int64_t) function h5pt_writestepattrib_r4 ( filehandle, name, data, nelem) |
| 446 |
implicit none |
| 447 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 448 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 449 |
real(kind=c_float), intent(in) :: data(*) !< the array of data to write into the attribute |
| 450 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 451 |
|
| 452 |
h5pt_writestepattrib_r4 = h5ptc_writestepattrib_r4 ( filehandle, cstring(name), data, nelem) |
| 453 |
|
| 454 |
end function |
| 455 |
|
| 456 |
integer(kind=c_int64_t) function h5pt_readstepattrib_r4 ( filehandle, name, data ) |
| 457 |
implicit none |
| 458 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 459 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 460 |
real(kind=c_float), intent(out) :: data(*) !< buffer to read value into |
| 461 |
|
| 462 |
h5pt_readstepattrib_r4 = h5ptc_readstepattrib_r4 ( filehandle, cstring(name), data ) |
| 463 |
|
| 464 |
end function |
| 465 |
|
| 466 |
integer(kind=c_int64_t) function h5pt_writestepattrib_i8 ( filehandle, name, data, nelem) |
| 467 |
implicit none |
| 468 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 469 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 470 |
integer(kind=c_int64_t), intent(in) :: data(*) !< the array of data to write into the attribute |
| 471 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 472 |
|
| 473 |
h5pt_writestepattrib_i8 = h5ptc_writestepattrib_i8 ( filehandle, cstring(name), data, nelem) |
| 474 |
|
| 475 |
end function |
| 476 |
|
| 477 |
integer(kind=c_int64_t) function h5pt_readstepattrib_i8 ( filehandle, name, data ) |
| 478 |
implicit none |
| 479 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 480 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 481 |
integer(kind=c_int64_t), intent(out) :: data(*) !< buffer to read value into |
| 482 |
|
| 483 |
h5pt_readstepattrib_i8 = h5ptc_readstepattrib_i8 ( filehandle, cstring(name), data ) |
| 484 |
|
| 485 |
end function |
| 486 |
|
| 487 |
integer(kind=c_int64_t) function h5pt_writestepattrib_i4 ( filehandle, name, data, nelem) |
| 488 |
implicit none |
| 489 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 490 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 491 |
integer(kind=c_int), intent(in) :: data(*) !< the array of data to write into the attribute |
| 492 |
integer(kind=c_int64_t), intent(in) :: nelem !< the number of elements in the array |
| 493 |
|
| 494 |
h5pt_writestepattrib_i4 = h5ptc_writestepattrib_i4 ( filehandle, cstring(name), data, nelem) |
| 495 |
|
| 496 |
end function |
| 497 |
|
| 498 |
integer(kind=c_int64_t) function h5pt_readstepattrib_i4 ( filehandle, name, data ) |
| 499 |
implicit none |
| 500 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned at file open |
| 501 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 502 |
integer(kind=c_int), intent(out) :: data(*) !< buffer to read value into |
| 503 |
|
| 504 |
h5pt_readstepattrib_i4 = h5ptc_readstepattrib_i4 ( filehandle, cstring(name), data ) |
| 505 |
|
| 506 |
end function |
| 507 |
! |
| 508 |
! read/write string |
| 509 |
! |
| 510 |
integer(kind=c_int64_t) function h5pt_writestepattrib_string ( filehandle, name, value) |
| 511 |
implicit none |
| 512 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 513 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 514 |
character(len=*), intent(in) :: value !< the string value to store |
| 515 |
|
| 516 |
h5pt_writestepattrib_string = h5ptc_writestepattrib_string ( filehandle, cstring(name), cstring(value)) |
| 517 |
|
| 518 |
end function |
| 519 |
|
| 520 |
integer(kind=c_int64_t) function h5pt_readstepattrib_string ( filehandle, name, value) |
| 521 |
implicit none |
| 522 |
integer(kind=c_int64_t), intent(in) :: filehandle !< the handle returned during file open |
| 523 |
character(len=*), intent(in) :: name !< the name of the attribute |
| 524 |
character(len=*), intent(out) :: value !< buffer to read the string value into |
| 525 |
|
| 526 |
h5pt_readstepattrib_string = h5ptc_readstepattrib_string ( filehandle, cstring(name), value) |
| 527 |
value = fstring(value) |
| 528 |
|
| 529 |
end function |
| 530 |
|
| 531 |
!--------------------------------------------------------------------------- |
| 532 |
! |
| 533 |
! function to safely convert a string to c format (ie. with a terminating |
| 534 |
! ascii null character) |
| 535 |
! |
| 536 |
!--------------------------------------------------------------------------- |
| 537 |
function cstring(string) |
| 538 |
implicit none |
| 539 |
character(len=*), intent(in) :: string |
| 540 |
character(len=len(string)+1) :: cstring |
| 541 |
|
| 542 |
cstring = trim(string)//char(0) |
| 543 |
|
| 544 |
end function cstring |
| 545 |
!--------------------------------------------------------------------------- |
| 546 |
! |
| 547 |
! function to safely convert a string from c format (ie. with a terminating |
| 548 |
! ascii null character) back to a normal Fortran string |
| 549 |
! |
| 550 |
!--------------------------------------------------------------------------- |
| 551 |
function fstring(string) |
| 552 |
implicit none |
| 553 |
character(len=*), intent(in) :: string !< the name of the dataset |
| 554 |
character(len=len(string)) :: fstring |
| 555 |
integer :: idx |
| 556 |
|
| 557 |
idx = index(string,char(0)) |
| 558 |
if (idx.gt.1) then |
| 559 |
fstring = string(1:idx-1) |
| 560 |
else |
| 561 |
fstring = '' |
| 562 |
endif |
| 563 |
|
| 564 |
end function fstring |
| 565 |
|
| 566 |
|
| 567 |
end module h5partattrib |