SCALE-RM
Data Types | Functions/Subroutines | Variables
gtool_file Module Reference

module GTOOL_FILE More...

Functions/Subroutines

subroutine, public filecreate (fid, existed, basename, title, source, institution, master, myrank, rankidx, single, time_units, append)
 
subroutine, public filesetoption (fid, filetype, key, val)
 
subroutine, public fileopen (fid, basename, mode, single)
 
subroutine, public filesettattr (fid, vname, key, val)
 
subroutine, public filegetshape (dims, basename, varname, myrank, single)
 
subroutine, public filegetdatainfo (basename, varname, myrank, istep, single, description, units, datatype, dim_rank, dim_name, dim_size, time_start, time_end, time_units)
 
subroutine, public filegetalldatainfo (step_limit, dim_limit, basename, varname, myrank, step_nmax, description, units, datatype, dim_rank, dim_name, dim_size, time_start, time_end, time_units, single)
 
subroutine, public fileclose (fid)
 
subroutine, public filecloseall
 
subroutine, public filemakefname (fname, basename, prefix, myrank, len)
 

Variables

real(dp), parameter, public rmiss = -9.9999e+30
 

Detailed Description

module GTOOL_FILE

Description
unified hundring of various kinds of files
Author
Team SCALE
History
  • 2012-06-12 (S.Nishizawa) [new] Imported from SCALE-LES

Function/Subroutine Documentation

◆ filecreate()

subroutine, public gtool_file::filecreate ( integer, intent(out)  fid,
logical, intent(out)  existed,
character(len=*), intent(in)  basename,
character(len=*), intent(in)  title,
character(len=*), intent(in)  source,
character(len=*), intent(in)  institution,
integer, intent(in)  master,
integer, intent(in)  myrank,
integer, dimension(:), intent(in)  rankidx,
logical, intent(in), optional  single,
character(len=*), intent(in), optional  time_units,
logical, intent(in), optional  append 
)

Definition at line 150 of file gtool_file.f90.

References gtool_file_h::file_fappend, gtool_file_h::file_fwrite, file_get_global_attribute_double(), file_get_global_attribute_float(), file_get_global_attribute_int(), file_get_global_attribute_text(), file_set_global_attribute_double(), file_set_global_attribute_float(), file_set_global_attribute_int(), file_set_global_attribute_text(), file_set_tunits(), dc_log::log(), and gtool_file_h::success_code.

Referenced by scale_fileio::fileio_write_1d(), scale_fileio::fileio_write_2d(), scale_fileio::fileio_write_3d(), scale_fileio::fileio_write_3d_t(), scale_fileio::fileio_write_4d(), and gtool_history::historyaddvariable().

150  implicit none
151 
152  integer, intent(out) :: fid
153  logical, intent(out) :: existed
154  character(LEN=*), intent( in) :: basename
155  character(LEN=*), intent( in) :: title
156  character(LEN=*), intent( in) :: source
157  character(LEN=*), intent( in) :: institution
158  integer, intent( in) :: master
159  integer, intent( in) :: myrank
160  integer, intent( in) :: rankidx(:)
161  character(LEN=*), intent( in), optional :: time_units
162  logical, intent( in), optional :: single
163  logical, intent( in), optional :: append
164 
165  character(len=File_HMID) :: time_units_
166  logical :: single_
167  integer :: mode
168  integer :: error
169 
170  intrinsic size
171 
172  if ( present(time_units) ) then
173  time_units_ = time_units
174  else
175  time_units_ = 'seconds'
176  end if
177 
178  mpi_myrank = myrank
179 
180  if ( present(single) ) then
181  if ( single .and. (myrank .ne. master) ) return
182  single_ = single
183  else
184  single_ = .false.
185  endif
186 
187  mode = file_fwrite
188  if ( present(append) ) then
189  if ( append ) mode = file_fappend
190  end if
191 
192  call filegetfid( &
193  fid, & ! (out)
194  existed, & ! (out)
195  basename, & ! (in)
196  mode, & ! (in)
197  single_ & ! (in)
198  )
199 
200  if ( existed ) return
201 
202  !--- append package header to the file
203  call filesetglobalattribute( fid, & ! (in)
204  "title", title ) ! (in)
205  call filesetglobalattribute( fid, & ! (in)
206  "source", source ) ! (in)
207  call filesetglobalattribute( fid, & ! (in)
208  "institution", institution ) ! (in)
209  call filesetglobalattribute( fid, & ! (in)
210  "myrank", (/myrank/) ) ! (in)
211  call filesetglobalattribute( fid, & ! (in)
212  "rankidx", rankidx ) ! (in)
213 
214  call file_set_tunits( fid, & ! (in)
215  time_units_, & ! (in)
216  error ) ! (out)
217  if ( error /= success_code ) then
218  call log('E', 'xxx failed to set time units')
219  end if
220 
221  return
int32_t file_set_tunits(int32_t fid, char *time_units)
Definition: gtool_netcdf.c:439
subroutine, public log(type, message)
Definition: dc_log.f90:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesetoption()

subroutine, public gtool_file::filesetoption ( integer, intent(in)  fid,
character(len=*), intent(in)  filetype,
character(len=*), intent(in)  key,
character(len=*), intent(in)  val 
)

Definition at line 422 of file gtool_file.f90.

References file_set_option(), dc_log::log(), and gtool_file_h::success_code.

Referenced by gtool_history::historyaddvariable().

422  integer, intent(in) :: fid
423  character(LEN=*), intent(in) :: filetype
424  character(LEN=*), intent(in) :: key
425  character(LEN=*), intent(in) :: val
426 
427  integer error
428 
429  call file_set_option( fid, & ! (in)
430  filetype, key, val, & ! (in)
431  error ) ! (out)
432  if ( error /= success_code ) then
433  call log('E', 'xxx failed to set option')
434  end if
435 
436  return
subroutine, public log(type, message)
Definition: dc_log.f90:133
int32_t file_set_option(int32_t fid, char *filetype, char *key, char *val)
Definition: gtool_netcdf.c:146
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fileopen()

subroutine, public gtool_file::fileopen ( integer, intent(out)  fid,
character(len=*), intent(in)  basename,
integer, intent(in)  mode,
logical, intent(in), optional  single 
)

Definition at line 446 of file gtool_file.f90.

References gtool_file_h::already_existed_code, dc_types::dp, file_add_variable(), file_put_associated_coordinates(), file_put_axis(), dc_log::log(), dc_types::sp, and gtool_file_h::success_code.

Referenced by filegetalldatainfo(), filegetdatainfo(), and filegetshape().

446  implicit none
447 
448  integer, intent(out) :: fid
449  character(LEN=*), intent( in) :: basename
450  integer, intent( in) :: mode
451  logical, intent( in), optional :: single
452 
453  logical :: existed
454  logical :: single_ = .false.
455 
456  if ( present(single) ) single_ = single
457 
458  call filegetfid( fid, & ! (out)
459  existed, & ! (out)
460  basename, mode, single_ ) ! (in)
461 
462  return
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesettattr()

subroutine, public gtool_file::filesettattr ( integer, intent(in)  fid,
character(len=*), intent(in)  vname,
character(len=*), intent(in)  key,
character(len=*), intent(in)  val 
)

Definition at line 942 of file gtool_file.f90.

References gtool_file_h::already_existed_code, file_set_tattr(), dc_log::log(), and gtool_file_h::success_code.

Referenced by scale_fileio::fileio_set_axes(), gtool_history::historyaddvariable(), and gtool_history::historysettattr().

942  integer, intent(in) :: fid
943  character(len=*), intent(in) :: vname
944  character(len=*), intent(in) :: key
945  character(len=*), intent(in) :: val
946 
947  integer :: error
948 
949  call file_set_tattr( &
950  fid, vname, & ! (in)
951  key, val, & ! (in)
952  error ) ! (out)
953  if ( error /= success_code .and. error /= already_existed_code ) then
954  call log('E', 'xxx failed to put axis')
955  end if
956 
957  return
int32_t file_set_tattr(int32_t fid, char *vname, char *key, char *val)
Definition: gtool_netcdf.c:447
subroutine, public log(type, message)
Definition: dc_log.f90:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filegetshape()

subroutine, public gtool_file::filegetshape ( integer, dimension(:), intent(out)  dims,
character(len=*), intent(in)  basename,
character(len=*), intent(in)  varname,
integer, intent(in)  myrank,
logical, intent(in), optional  single 
)

Definition at line 970 of file gtool_file.f90.

References gtool_file_h::file_fread, file_get_datainfo(), fileopen(), dc_log::log(), and gtool_file_h::success_code.

Referenced by mod_realinput_nicam::parentatomsetupnicam(), mod_realinput_nicam::parentlandsetupnicam(), mod_realinput_nicam::parentoceansetupnicam(), and mod_mkinit::read_sounding().

970  implicit none
971 
972  integer, intent(out) :: dims(:)
973  character(LEN=*), intent( in) :: basename
974  character(LEN=*), intent( in) :: varname
975  integer, intent( in) :: myrank
976  logical, intent( in), optional :: single
977 
978  integer :: fid
979  type(datainfo) :: dinfo
980  integer :: error
981  integer :: n
982 
983  logical :: single_ = .false.
984 
985  intrinsic size
986  intrinsic shape
987  !---------------------------------------------------------------------------
988 
989  mpi_myrank = myrank
990 
991  if ( present(single) ) single_ = single
992 
993  !--- search/register file
994  call fileopen( fid, & ! (out)
995  basename, file_fread, single_ ) ! (in)
996 
997  !--- get data information
998  call file_get_datainfo( dinfo, & ! (out)
999  fid, varname, 1, .false., & ! (in)
1000  error ) ! (out)
1001 
1002  !--- verify
1003  if ( error /= success_code ) then
1004  call log('E', 'xxx failed to get data information :'//trim(varname))
1005  end if
1006 
1007  if ( dinfo%rank /= size(dims) ) then
1008  write(message,*) 'xxx rank is different, ', size(dims), dinfo%rank
1009  call log('E', message)
1010  end if
1011  do n = 1, size(dims)
1012  dims(n) = dinfo%dim_size(n)
1013  end do
1014 
1015  return
int32_t file_get_datainfo(datainfo_t *dinfo, int32_t fid, char *varname, int32_t step, int32_t suppress)
Definition: gtool_netcdf.c:162
subroutine, public log(type, message)
Definition: dc_log.f90:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filegetdatainfo()

subroutine, public gtool_file::filegetdatainfo ( character(len=*), intent(in)  basename,
character(len=*), intent(in)  varname,
integer, intent(in)  myrank,
integer, intent(in)  istep,
logical, intent(in), optional  single,
character(len=file_hmid), intent(out), optional  description,
character(len=file_hshort), intent(out), optional  units,
integer, intent(out), optional  datatype,
integer, intent(out), optional  dim_rank,
character(len=file_hshort), dimension(:), intent(out), optional  dim_name,
integer, dimension(:), intent(out), optional  dim_size,
real(dp), intent(out), optional  time_start,
real(dp), intent(out), optional  time_end,
character(len=file_hmid), intent(out), optional  time_units 
)

Definition at line 1036 of file gtool_file.f90.

References gtool_file_h::file_fread, file_get_datainfo(), fileopen(), dc_log::log(), and gtool_file_h::success_code.

Referenced by mod_admin_time::admin_time_setup().

1036  implicit none
1037  character(len=*), intent(in) :: basename
1038  character(len=*), intent(in) :: varname
1039  integer, intent(in) :: myrank
1040  integer, intent(in) :: istep
1041  logical, intent(in), optional :: single
1042 
1043  character(len=File_HMID), intent(out), optional :: description
1044  character(len=File_HSHORT), intent(out), optional :: units
1045  integer, intent(out), optional :: datatype
1046  integer, intent(out), optional :: dim_rank
1047  character(len=File_HSHORT), intent(out), optional :: dim_name(:)
1048  integer, intent(out), optional :: dim_size(:)
1049  real(DP), intent(out), optional :: time_start
1050  real(DP), intent(out), optional :: time_end
1051  character(len=File_HMID), intent(out), optional :: time_units
1052 
1053  integer :: fid
1054  type(datainfo) :: dinfo
1055 
1056  integer :: ndim, idim
1057  real(DP):: time(1)
1058 
1059  integer :: error
1060  logical :: single_ = .false.
1061 
1062  intrinsic size
1063  !---------------------------------------------------------------------------
1064 
1065  mpi_myrank = myrank
1066 
1067  if ( present(single) ) single_ = single
1068 
1069  !--- search/register file
1070  call fileopen( fid, & ! [OUT]
1071  basename, & ! [IN]
1072  file_fread, & ! [IN]
1073  single_ ) ! [IN]
1074 
1075  !--- get data information
1076  call file_get_datainfo( dinfo, & ! [OUT]
1077  fid, & ! [IN]
1078  varname, & ! [IN]
1079  istep, & ! [IN]
1080  .false., & ! [IN]
1081  error ) ! [OUT]
1082 
1083  !--- verify and exit
1084  if ( error /= success_code ) then
1085  call log('E', 'xxx data info not found in '//trim(basename))
1086  endif
1087 
1088  if ( present(description) ) description = dinfo%description
1089  if ( present(units) ) units = dinfo%units
1090  if ( present(datatype) ) datatype = dinfo%datatype
1091  if ( present(dim_rank) ) dim_rank = dinfo%rank
1092 
1093  if ( present(dim_name) ) then
1094  ndim = min( dinfo%rank, size(dim_name) ) ! limit dimension rank
1095  do idim = 1, ndim
1096  dim_name(idim) = dinfo%dim_name(idim)
1097  enddo
1098  end if
1099  if ( present(dim_size) ) then
1100  ndim = min( dinfo%rank, size(dim_size) ) ! limit dimension rank
1101  do idim = 1, ndim
1102  dim_size(idim) = dinfo%dim_size(idim)
1103  enddo
1104  end if
1105 
1106  if ( present(time_units) ) then
1107  if ( dinfo%time_units == "" ) then
1108  call filegetglobalattribute( fid, "time_units", time_units )
1109  else
1110  time_units = dinfo%time_units
1111  end if
1112  end if
1113  if ( present(time_start) ) then
1114  if ( dinfo%time_units == "" ) then
1115  call filegetglobalattribute( fid, "time", time )
1116  time_start = time(1)
1117  else
1118  time_start = dinfo%time_start
1119  end if
1120  end if
1121  if ( present(time_end) ) then
1122  if ( dinfo%time_units == "" ) then
1123  call filegetglobalattribute( fid, "time", time )
1124  time_end = time(1)
1125  else
1126  time_end = dinfo%time_end
1127  end if
1128  end if
1129 
1130  return
int32_t file_get_datainfo(datainfo_t *dinfo, int32_t fid, char *varname, int32_t step, int32_t suppress)
Definition: gtool_netcdf.c:162
subroutine, public log(type, message)
Definition: dc_log.f90:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filegetalldatainfo()

subroutine, public gtool_file::filegetalldatainfo ( integer, intent(in)  step_limit,
integer, intent(in)  dim_limit,
character(len=*), intent(in)  basename,
character(len=*), intent(in)  varname,
integer, intent(in)  myrank,
integer, intent(out)  step_nmax,
character(len=file_hmid), intent(out)  description,
character(len=file_hshort), intent(out)  units,
integer, intent(out)  datatype,
integer, intent(out)  dim_rank,
character(len=file_hshort), dimension (dim_limit), intent(out)  dim_name,
integer, dimension (dim_limit), intent(out)  dim_size,
real(dp), dimension(step_limit), intent(out)  time_start,
real(dp), dimension (step_limit), intent(out)  time_end,
character(len=file_hmid), intent(out)  time_units,
logical, intent(in), optional  single 
)

Definition at line 1153 of file gtool_file.f90.

References dc_types::dp, gtool_file_h::file_fread, file_get_datainfo(), file_read_data(), file_write_data(), fileopen(), dc_log::log(), rmiss, dc_types::sp, and gtool_file_h::success_code.

Referenced by scale_external_input::extin_setup().

1153  implicit none
1154 
1155  integer, intent(in) :: step_limit
1156  integer, intent(in) :: dim_limit
1157  character(len=*), intent(in) :: basename
1158  character(len=*), intent(in) :: varname
1159  integer, intent(in) :: myrank
1160  integer, intent(out) :: step_nmax
1161  character(len=File_HMID), intent(out) :: description
1162  character(len=File_HSHORT), intent(out) :: units
1163  integer, intent(out) :: datatype
1164  integer, intent(out) :: dim_rank
1165  character(len=File_HSHORT), intent(out) :: dim_name (dim_limit)
1166  integer, intent(out) :: dim_size (dim_limit)
1167  real(DP), intent(out) :: time_start(step_limit)
1168  real(DP), intent(out) :: time_end (step_limit)
1169  character(len=File_HMID), intent(out) :: time_units
1170 
1171  logical, intent(in), optional :: single
1172 
1173  integer :: fid
1174  type(datainfo) :: dinfo
1175 
1176  integer :: ndim
1177  integer :: istep, idim
1178  logical :: flag_first = .true.
1179 
1180  integer :: error
1181  logical :: single_ = .false.
1182  !---------------------------------------------------------------------------
1183 
1184  mpi_myrank = myrank
1185 
1186  if ( present(single) ) single_ = single
1187 
1188  !--- search/register file
1189  call fileopen( fid, & ! [OUT]
1190  basename, & ! [IN]
1191  file_fread, & ! [IN]
1192  single_ ) ! [IN]
1193 
1194  ! initialize
1195  description = ""
1196  units = ""
1197  datatype = -1
1198  dim_rank = -1
1199  dim_name(:) = ""
1200  dim_size(:) = -1
1201  time_start(:) = rmiss
1202  time_end(:) = rmiss
1203 
1204  do istep = 1, step_limit
1205  !--- get data information
1206  call file_get_datainfo( dinfo, & ! [OUT]
1207  fid, & ! [IN]
1208  varname, & ! [IN]
1209  istep, & ! [IN]
1210  .true., & ! [IN]
1211  error ) ! [OUT]
1212 
1213  !--- verify and exit
1214  if ( error /= success_code ) then
1215  step_nmax = istep - 1
1216  exit
1217  endif
1218 
1219  if ( flag_first ) then
1220  flag_first = .false.
1221 
1222  description = dinfo%description
1223  units = dinfo%units
1224  datatype = dinfo%datatype
1225  dim_rank = dinfo%rank
1226 
1227  ndim = min( dinfo%rank, dim_limit ) ! limit dimension rank
1228  do idim = 1, ndim
1229  dim_name(idim) = dinfo%dim_name(idim)
1230  dim_size(idim) = dinfo%dim_size(idim)
1231  enddo
1232 
1233  time_units = dinfo%time_units
1234  endif
1235 
1236  time_start(istep) = dinfo%time_start
1237  time_end(istep) = dinfo%time_end
1238  enddo
1239 
1240  return
int32_t file_get_datainfo(datainfo_t *dinfo, int32_t fid, char *varname, int32_t step, int32_t suppress)
Definition: gtool_netcdf.c:162
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fileclose()

subroutine, public gtool_file::fileclose ( integer, intent(in)  fid)

Definition at line 2199 of file gtool_file.f90.

References gtool_file_h::already_closed_code, file_close(), dc_log::log(), and gtool_file_h::success_code.

Referenced by filecloseall(), and gtool_history::historyfinalize().

2199  implicit none
2200 
2201  integer, intent(in) :: fid
2202 
2203  character(LEN=File_HLONG) :: fname
2204  integer :: error
2205  integer :: n
2206  !---------------------------------------------------------------------------
2207 
2208  if ( fid < 0 ) return
2209 
2210  do n = 1, file_fid_count-1
2211  if ( file_fid_list(n) == fid ) exit
2212  end do
2213  if ( fid /= file_fid_list(n) ) then
2214  write(message,*) 'xxx invalid fid' , fid
2215  call log('E', message)
2216  end if
2217  call file_close( fid , & ! (in)
2218  error ) ! (out)
2219  if ( error == success_code ) then
2220  write(message, '(1x,A,i3)') '*** [File] File Close : NO.', n
2221  call log('I', message)
2222  call log('I', '*** closed filename: ' // trim(file_fname_list(n)))
2223  else if ( error /= already_closed_code ) then
2224  call log('E', 'xxx failed to close file')
2225  end if
2226 
2227  do n = 1, file_fid_count-1
2228  if ( file_fid_list(n) == fid ) then
2229  file_fid_list(n) = -1
2230  file_fname_list(n) = ''
2231  end if
2232  end do
2233 
2234  return
subroutine, public log(type, message)
Definition: dc_log.f90:133
int32_t file_close(int32_t fid)
Definition: gtool_netcdf.c:852
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filecloseall()

subroutine, public gtool_file::filecloseall ( )

Definition at line 2238 of file gtool_file.f90.

References fileclose().

Referenced by scale_process::prc_mpitimestat(), mod_rm_driver::scalerm(), scalerm_launcher(), and mod_rm_prep::scalerm_prep().

2238  implicit none
2239 
2240  integer n
2241  !---------------------------------------------------------------------------
2242 
2243  do n = 1, file_fid_count-1
2244  call fileclose( file_fid_list(n) )
2245  enddo
2246 
2247  return
Here is the call graph for this function:
Here is the caller graph for this function:

◆ filemakefname()

subroutine, public gtool_file::filemakefname ( character(len=*), intent(out)  fname,
character(len=*), intent(in)  basename,
character(len=*), intent(in)  prefix,
integer, intent(in)  myrank,
integer, intent(in)  len 
)

Definition at line 2259 of file gtool_file.f90.

References file_open(), dc_log::log(), and gtool_file_h::success_code.

Referenced by scale_external_io::externalfilereadoffset4drealdp().

2259  character(len=*), intent(out) :: fname
2260  character(len=*), intent( in) :: basename
2261  character(len=*), intent( in) :: prefix
2262  integer, intent( in) :: myrank
2263  integer, intent( in) :: len
2264 
2265  ! 12345678901234567
2266  character(len=17) :: fmt = "(A, '.', A, I*.*)"
2267  !---------------------------------------------------------------------------
2268 
2269  if ( len < 1 .or. len > 9 ) then
2270  call log('E', 'xxx len is invalid')
2271  end if
2272 
2273  write(fmt(14:14),'(I1)') len
2274  write(fmt(16:16),'(I1)') len
2275  write(fname, fmt) trim(basename), trim(prefix), myrank
2276 
2277  return
subroutine, public log(type, message)
Definition: dc_log.f90:133
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ rmiss

real(dp), parameter, public gtool_file::rmiss = -9.9999e+30