SCALE-RM
scale_file_h.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
10 #include "scalelib.h"
12  use scale_precision, only: &
13  dp
14  use iso_c_binding
15  implicit none
16  private
17 
18 #include "scale_file_const.h"
19 
20  !--- character length
21  integer, public, parameter :: file_hshort = file_hshort
22  integer, public, parameter :: file_hmid = file_hmid
23  integer, public, parameter :: file_hlong = file_hlong
24 
25  !--- data type
26  integer, public, parameter :: file_real4 = file_real4
27  integer, public, parameter :: file_real8 = file_real8
28  integer, public, parameter :: file_integer2 = file_integer2
29  integer, public, parameter :: file_integer4 = file_integer4
30  integer, public, parameter :: file_integer8 = file_integer8
31  integer, public, parameter :: file_text = file_text
32 
33  !--- action type
34  integer, public, parameter :: file_fread = file_fread
35  integer, public, parameter :: file_fwrite = file_fwrite
36  integer, public, parameter :: file_fappend = file_fappend
37 
38  !--- return codes
39  integer, public, parameter :: file_error_code = error_code
40  integer, public, parameter :: file_success_code = success_code
41  integer, public, parameter :: file_already_closed_code = already_closed_code
42  integer, public, parameter :: file_already_existed_code = already_existed_code
43 
44  !--- max
45  integer, public, parameter :: file_file_max = file_max
46  integer, public, parameter :: file_var_max = var_max
47  integer, public, parameter :: file_rank_max = rank_max
48 
49  !--- missing value
50 #define DBL(v) v
51  real(dp), public, parameter :: file_rmiss = dbl(rmiss)_dp
52 
53  !--- struct for data infomation
54  type, public, Bind(C) :: datainfo
55  character(c_char) :: varname(file_hshort)
56  character(c_char) :: description(file_hmid)
57  character(c_char) :: units(file_hshort)
58  character(c_char) :: standard_name(file_hmid)
59  integer :: datatype
60  integer :: rank
61  character(c_char) :: dim_name(file_hshort,rank_max)
62  integer :: dim_size(rank_max)
63  integer :: step
64  logical(c_bool) :: has_tdim
65  real(dp) :: time_start
66  real(dp) :: time_end
67  character(c_char) :: time_units(file_hmid)
68  character(c_char) :: calendar(file_hshort)
69  integer :: natts
70  character(c_char) :: att_name(file_hshort,att_max)
71  integer :: att_type(att_max)
72  integer :: att_len (att_max)
73  integer :: fid
74  endtype datainfo
75 
76  integer, public, parameter :: file_preclist(0:3) = (/ 4, 8, 4, 8 /)
77 
78  character(len=FILE_HSHORT), public :: file_dtypelist(0:4)
79 
80  data file_dtypelist / "REAL4", "REAL8", "INTEGER2", "INTEGER4", "INTEGER8" /
81 
82  public :: cstr
83  public :: fstr
84 
85  interface fstr
86  module procedure fstr1
87  module procedure fstr2
88  end interface fstr
89 
90 contains
91 
92 
93  function cstr(str)
94  character(*), intent(in) :: str
95  character(:,c_char), allocatable, target :: cstr
96  cstr = trim(str) // c_null_char
97  end function cstr
98 
99  subroutine fstr1(str)
100  character(len=*), intent(inout) :: str
101  integer :: i, j
102  do i = 1, len(str)
103  if ( str(i:i) == c_null_char ) exit
104  end do
105  do j = i, len(str)
106  str(j:j) = " "
107  end do
108  return
109  end subroutine fstr1
110 
111  subroutine fstr2(fstr, cstr)
112  character(len=*), intent(out) :: fstr
113  character(c_char), intent(in) :: cstr(:)
114  integer :: i, j
115  do i = 1, len(fstr)
116  if ( cstr(i) == c_null_char ) exit
117  fstr(i:i) = cstr(i)
118  end do
119  do j = i, len(fstr)
120  fstr(j:j) = " "
121  end do
122  return
123  end subroutine fstr2
124 
125 
126 end module scale_file_h
scale_file_h::file_real4
integer, parameter, public file_real4
Definition: scale_file_h.F90:26
scale_file_h::file_integer8
integer, parameter, public file_integer8
Definition: scale_file_h.F90:30
scale_file_h::file_hlong
integer, parameter, public file_hlong
Definition: scale_file_h.F90:23
scale_file_h::file_already_closed_code
integer, parameter, public file_already_closed_code
Definition: scale_file_h.F90:41
scale_precision
module PRECISION
Definition: scale_precision.F90:14
scale_file_h::file_integer2
integer, parameter, public file_integer2
Definition: scale_file_h.F90:28
scale_file_h::file_dtypelist
character(len=file_hshort), dimension(0:4), public file_dtypelist
Definition: scale_file_h.F90:78
scale_file_h::file_hmid
integer, parameter, public file_hmid
Definition: scale_file_h.F90:22
scale_file_h::file_rmiss
real(dp), parameter, public file_rmiss
Definition: scale_file_h.F90:51
scale_file_h::file_preclist
integer, dimension(0:3), parameter, public file_preclist
Definition: scale_file_h.F90:76
scale_file_h::file_hshort
integer, parameter, public file_hshort
Definition: scale_file_h.F90:21
scale_file_h::file_rank_max
integer, parameter, public file_rank_max
Definition: scale_file_h.F90:47
scale_file_h::file_already_existed_code
integer, parameter, public file_already_existed_code
Definition: scale_file_h.F90:42
scale_file_h::file_text
integer, parameter, public file_text
Definition: scale_file_h.F90:31
scale_precision::dp
integer, parameter, public dp
Definition: scale_precision.F90:32
scale_file_h
module file_h
Definition: scale_file_h.F90:11
scale_file_h::file_fappend
integer, parameter, public file_fappend
Definition: scale_file_h.F90:36
scale_file_h::file_error_code
integer, parameter, public file_error_code
Definition: scale_file_h.F90:39
scale_file_h::file_fread
integer, parameter, public file_fread
Definition: scale_file_h.F90:34
scale_file_h::file_success_code
integer, parameter, public file_success_code
Definition: scale_file_h.F90:40
scale_file_h::file_var_max
integer, parameter, public file_var_max
Definition: scale_file_h.F90:46
scale_file_h::cstr
character(:, c_char) function, allocatable, target, public cstr(str)
Definition: scale_file_h.F90:94
scale_file_h::file_integer4
integer, parameter, public file_integer4
Definition: scale_file_h.F90:29
scale_file_h::datainfo
Definition: scale_file_h.F90:54
scale_file_h::file_file_max
integer, parameter, public file_file_max
Definition: scale_file_h.F90:45
scale_file_h::file_real8
integer, parameter, public file_real8
Definition: scale_file_h.F90:27
scale_file_h::file_fwrite
integer, parameter, public file_fwrite
Definition: scale_file_h.F90:35