summaryrefslogtreecommitdiffstats
path: root/fortran/src/H5fortkit.F90
blob: b745c22e5ee9f5a6f66dd0f1819239424da4983f (plain)
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
!****h* ROBODoc/H5fortkit
!
! NAME
!  MODULE H5fortkit
!
! FILE
!  fortran/src/H5fortkit.F90
!
! PURPOSE
!  Routines to deal with C-FORTRAN issues.
!
! COPYRIGHT
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
!   Copyright by The HDF Group.                                               *
!   All rights reserved.                                                      *
!                                                                             *
!   This file is part of HDF5.  The full HDF5 copyright notice, including     *
!   terms governing use, modification, and redistribution, is contained in    *
!   the COPYING file, which can be found at the root of the source code       *
!   distribution tree, or in https://www.hdfgroup.org/licenses.               *
!   If you do not have access to either file, you may request a copy from     *
!   help@hdfgroup.org.                                                        *
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
!
!*****
MODULE H5fortkit

CONTAINS

!****if* H5fortkit/HD5c2fstring
! NAME
!  HD5c2fstring
! INPUTS
!  cstring  -  C string stored as a string array of size 'len' of string size LEN=1
!  len      -  length of Fortran string
! OUTPUT
!   fstring -  Fortran string array of LEN=1
! PURPOSE
!   Copies a Fortran array of strings having a length of one to a fortran string and removes the C Null
!   terminator. The Null terminator is returned from C when calling the C APIs directly.
!
!   The fortran standard does not allow C_LOC to be used on a character string of
!   length greater than one, which is why we use the array of characters instead.
!
! SOURCE
  SUBROUTINE HD5c2fstring(fstring,cstring,len)
!*****
    IMPLICIT NONE

    INTEGER :: i
    INTEGER :: len
    CHARACTER(LEN=len) :: fstring
    CHARACTER(LEN=1), DIMENSION(1:len) :: cstring

    fstring = ''
    DO i = 1, len
       IF (cstring(i)(1:1)==CHAR(0)) EXIT
       fstring(i:i) = cstring(i)(1:1)
    END DO

  END SUBROUTINE HD5c2fstring

END MODULE H5fortkit