35 public :: fileio_check_coordinates
37 public :: fileio_write
44 public :: fileio_write_var
47 interface fileio_check_coordinates
49 module procedure fileio_check_coordinates_id
50 end interface fileio_check_coordinates
62 end interface fileio_read
64 interface fileio_write
70 end interface fileio_write
72 interface fileio_write_var
78 end interface fileio_write_var
90 private :: getcftunits
98 real(RP),
private :: FILEIO_datacheck_criteria
100 real(RP),
private,
allocatable :: AXIS_LON (:,:)
101 real(RP),
private,
allocatable :: AXIS_LONX (:,:)
102 real(RP),
private,
allocatable :: AXIS_LONY (:,:)
103 real(RP),
private,
allocatable :: AXIS_LONXY(:,:)
104 real(RP),
private,
allocatable :: AXIS_LAT (:,:)
105 real(RP),
private,
allocatable :: AXIS_LATX (:,:)
106 real(RP),
private,
allocatable :: AXIS_LATY (:,:)
107 real(RP),
private,
allocatable :: AXIS_LATXY(:,:)
108 real(RP),
private,
allocatable :: AXIS_HZXY (:,:,:)
109 real(RP),
private,
allocatable :: AXIS_HWXY (:,:,:)
111 integer,
private,
parameter :: File_nfile_max = 512
113 logical,
private :: File_axes_written(0:File_nfile_max-1)
115 logical,
private :: File_closed(0:File_nfile_max-1)
116 logical,
private :: File_nozcoord(0:File_nfile_max-1)
117 integer,
private :: write_buf_amount = 0
120 integer,
private :: XSB, XEB, YSB, YEB
122 integer,
private :: startXY (3), countXY (3)
123 integer,
private :: startZX (2), countZX (2)
124 integer,
private :: startZXY (4), countZXY (4)
125 integer,
private :: startLAND (3), countLAND (3)
126 integer,
private :: startURBAN(3), countURBAN(3)
129 integer,
private :: etype
132 integer,
private :: centerTypeXY
133 integer,
private :: centerTypeZX
134 integer,
private :: centerTypeZXY
135 integer,
private :: centerTypeLAND
136 integer,
private :: centerTypeURBAN
138 logical,
private :: set_coordinates = .false.
156 namelist / param_fileio / &
157 fileio_datacheck_criteria
163 if(
io_l )
write(
io_fid_log,*)
'++++++ Module[FIELIO] / Categ[ATMOS-RM IO] / Origin[SCALElib]' 165 fileio_datacheck_criteria = eps * 10.0_rp
171 if(
io_l )
write(
io_fid_log,*)
'*** Not found namelist. Default used.' 172 elseif( ierr > 0 )
then 173 write(*,*)
'xxx Not appropriate names in namelist PARAM_FILEIO. Check!' 179 if(
io_l )
write(
io_fid_log,*)
'*** NetCDF header information ***' 183 if(
io_l )
write(
io_fid_log,*)
'*** Data consistency criteria : ', &
184 '(file-internal)/internal = ', fileio_datacheck_criteria
204 allocate( axis_lon(
ia,
ja) )
205 allocate( axis_lonx(0:
ia,
ja) )
206 allocate( axis_lony(
ia,0:
ja) )
207 allocate( axis_lonxy(0:
ia,0:
ja) )
208 allocate( axis_lat(
ia,
ja) )
209 allocate( axis_latx(0:
ia,
ja) )
210 allocate( axis_laty(
ia,0:
ja) )
211 allocate( axis_latxy(0:
ia,0:
ja) )
213 allocate( axis_hzxy(
ka,
ia,
ja) )
214 allocate( axis_hwxy(0:
ka,
ia,
ja) )
218 file_closed(:) = .true.
229 deallocate( axis_lon )
230 deallocate( axis_lonx )
231 deallocate( axis_lony )
232 deallocate( axis_lonxy )
233 deallocate( axis_lat )
234 deallocate( axis_latx )
235 deallocate( axis_laty )
236 deallocate( axis_latxy )
237 deallocate( axis_hzxy )
238 deallocate( axis_hwxy )
264 real(RP),
intent(in) :: lon (
ia,
ja)
265 real(RP),
intent(in) :: lonx (0:
ia,
ja)
266 real(RP),
intent(in) :: lony (
ia,0:
ja)
267 real(RP),
intent(in) :: lonxy(0:
ia,0:
ja)
268 real(RP),
intent(in) :: lat (
ia,
ja)
269 real(RP),
intent(in) :: latx (0:
ia,
ja)
270 real(RP),
intent(in) :: laty (
ia,0:
ja)
271 real(RP),
intent(in) :: latxy(0:
ia,0:
ja)
272 real(RP),
intent(in) :: cz (
ka,
ia,
ja)
273 real(RP),
intent(in) :: fz (0:
ka,
ia,
ja)
276 axis_lon(:,:) = lon(:,:) / d2r
277 axis_lonx(:,:) = lonx(:,:) / d2r
278 axis_lony(:,:) = lony(:,:) / d2r
279 axis_lonxy(:,:) = lonxy(:,:) / d2r
280 axis_lat(:,:) = lat(:,:) / d2r
281 axis_latx(:,:) = latx(:,:) / d2r
282 axis_laty(:,:) = laty(:,:) / d2r
283 axis_latxy(:,:) = latxy(:,:) / d2r
285 axis_hzxy(:,:,:) = cz(:,:,:)
286 axis_hwxy(:,:,:) = fz(:,:,:)
288 set_coordinates = .true.
303 character(len=*),
intent(in) :: basename
304 logical,
intent(in),
optional :: atmos
305 logical,
intent(in),
optional :: land
306 logical,
intent(in),
optional :: urban
307 logical,
intent(in),
optional :: transpose
312 logical :: transpose_
322 if(
present(atmos) ) atmos_ = atmos
323 if(
present(land ) ) land_ = land
324 if(
present(urban) ) urban_ = urban
325 if(
present(transpose) ) transpose_ = transpose
330 call fileio_check_coordinates_id( fid, &
331 atmos_, land_, urban_, &
339 subroutine fileio_check_coordinates_id( &
355 integer,
intent(in) :: fid
356 logical,
intent(in),
optional :: atmos
357 logical,
intent(in),
optional :: land
358 logical,
intent(in),
optional :: urban
359 logical,
intent(in),
optional :: transpose
364 logical :: transpose_
366 real(RP) :: buffer_z (KA)
367 real(RP) :: buffer_x (IA)
368 real(RP) :: buffer_y (JA)
369 real(RP) :: buffer_xy (IA,JA)
370 real(RP) :: buffer_zxy(KA,IA,JA)
371 real(RP) :: buffer_l (LKMAX)
372 real(RP) :: buffer_u (UKMAX)
376 if(
io_l )
write(
io_fid_log,*)
'*** Check consistency of axis ***' 383 if(
present(atmos) ) atmos_ = atmos
384 if(
present(land ) ) land_ = land
385 if(
present(urban) ) urban_ = urban
386 if(
present(transpose) ) transpose_ = transpose
394 if ( set_coordinates )
then 397 call check_2d( axis_lon(xsb:xeb,ysb:yeb), buffer_xy(xsb:xeb,ysb:yeb),
'lon' )
401 call check_2d( axis_lat(xsb:xeb,ysb:yeb), buffer_xy(xsb:xeb,ysb:yeb),
'lat' )
406 if ( .not. transpose_ )
then 411 if ( .not. transpose_ )
then 412 call check_3d( axis_hzxy(
ks:
ke,xsb:xeb,ysb:yeb), buffer_zxy(
ks:
ke,xsb:xeb,ysb:yeb),
'height', transpose_ )
429 end subroutine fileio_check_coordinates_id
442 integer :: err, order
443 integer :: sizes(3), subsizes(3), sub_off(3)
446 order = mpi_order_fortran
448 centertypexy = mpi_datatype_null
449 centertypezx = mpi_datatype_null
450 centertypezxy = mpi_datatype_null
451 centertypeland = mpi_datatype_null
452 centertypeurban = mpi_datatype_null
456 if(
rp == 8 ) etype = mpi_double_precision
465 startzxy(2:3) = startxy(1:2)
467 countzxy(2:3) = countxy(1:2)
479 call mpi_type_create_subarray(3, sizes, subsizes, sub_off, order, etype, centertypezxy, err)
480 call mpi_type_commit(centertypezxy, err)
484 startland(2:3) = startxy(1:2)
486 countland(2:3) = countxy(1:2)
492 call mpi_type_create_subarray(3, sizes, subsizes, sub_off, order, etype, centertypeland, err)
493 call mpi_type_commit(centertypeland, err)
497 starturban(2:3) = startxy(1:2)
498 counturban(1) =
ukmax 499 counturban(2:3) = countxy(1:2)
505 call mpi_type_create_subarray(3, sizes, subsizes, sub_off, order, etype, centertypeurban, err)
506 call mpi_type_commit(centertypeurban, err)
521 call mpi_type_create_subarray(2, sizes, subsizes, sub_off, order, etype, centertypezx, err)
522 call mpi_type_commit(centertypezx, err)
538 if( centertypexy /= mpi_datatype_null )
call mpi_type_free(centertypexy, err)
539 if( centertypezx /= mpi_datatype_null )
call mpi_type_free(centertypezx, err)
540 if( centertypezxy /= mpi_datatype_null )
call mpi_type_free(centertypezxy, err)
541 if( centertypeland /= mpi_datatype_null )
call mpi_type_free(centertypeland, err)
542 if( centertypeurban /= mpi_datatype_null )
call mpi_type_free(centertypeurban, err)
561 real(RP),
intent(out) :: var(:)
562 character(len=*),
intent(in) :: basename
563 character(len=*),
intent(in) :: varname
564 character(len=*),
intent(in) :: axistype
565 integer,
intent(in) :: step
574 fid, varname, axistype, step )
595 real(RP),
intent(out) :: var(:,:)
596 character(len=*),
intent(in) :: basename
597 character(len=*),
intent(in) :: varname
598 character(len=*),
intent(in) :: axistype
599 integer,
intent(in) :: step
608 fid, varname, axistype, step )
629 real(RP),
intent(out) :: var(:,:,:)
630 character(len=*),
intent(in) :: basename
631 character(len=*),
intent(in) :: varname
632 character(len=*),
intent(in) :: axistype
633 integer,
intent(in) :: step
642 fid, varname, axistype, step )
663 real(RP),
intent(out) :: var(:,:,:,:)
664 character(len=*),
intent(in) :: basename
665 character(len=*),
intent(in) :: varname
666 character(len=*),
intent(in) :: axistype
667 integer,
intent(in) :: step
676 fid, varname, axistype, step )
701 real(RP),
intent(out) :: var(:)
702 integer,
intent(in) :: fid
703 character(len=*),
intent(in) :: varname
704 character(len=*),
intent(in) :: axistype
705 integer,
intent(in) :: step
707 integer :: dim1_S, dim1_E
714 if(
io_l )
write(
io_fid_log,
'(1x,2A)')
'*** Read from file (1D), name : ', trim(varname)
718 if ( axistype ==
'Z' )
then 721 call fileread( var(
ks:
ke), fid, varname, step, &
722 ntypes=
kmax, dtype=etype, start=start, count=count )
723 elseif( axistype ==
'LZ' )
then 726 call fileread( var, fid, varname, step, &
727 ntypes=
lkmax, dtype=etype, start=start, count=count )
728 elseif( axistype ==
'UZ' )
then 731 call fileread( var, fid, varname, step, &
732 ntypes=
ukmax, dtype=etype, start=start, count=count )
733 elseif( axistype ==
'X' .OR. axistype ==
'CX' )
then 736 call fileread( var, fid, varname, step, &
737 ntypes=
ia, dtype=etype, start=start, count=count )
738 elseif( axistype ==
'Y' .OR. axistype ==
'CY' )
then 741 call fileread( var, fid, varname, step, &
742 ntypes=
ja, dtype=etype, start=start, count=count )
744 write(*,*)
'xxx [FILEIO_read_var_1D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
748 if ( axistype ==
'Z' )
then 751 elseif( axistype ==
'LZ' )
then 754 elseif( axistype ==
'UZ' )
then 757 elseif( axistype ==
'X' )
then 760 elseif( axistype ==
'CX' )
then 763 elseif( axistype ==
'Y' )
then 766 elseif( axistype ==
'CY' )
then 770 write(*,*)
'xxx [FILEIO_read_var_1D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
774 call fileread( var(dim1_s:dim1_e), fid, varname, step )
800 real(RP),
intent(out) :: var(:,:)
801 integer,
intent(in) :: fid
802 character(len=*),
intent(in) :: varname
803 character(len=*),
intent(in) :: axistype
804 integer,
intent(in) :: step
806 integer :: dim1_S, dim1_E
807 integer :: dim2_S, dim2_E
812 if(
io_l )
write(
io_fid_log,
'(1x,2A)')
'*** Read from file (2D), name : ', trim(varname)
816 if ( axistype ==
'XY' )
then 817 call fileread( var, fid, varname, step, &
818 ntypes=
ia*
ja, dtype=etype, start=startxy, count=countxy )
819 elseif( axistype ==
'ZX' )
then 822 call fileread( var, fid, varname, step, &
823 ntypes=1, dtype=centertypezx, start=startzx, count=countzx )
825 write(*,*)
'xxx [FILEIO_read_var_2D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
829 if ( axistype ==
'XY' )
then 834 elseif( axistype ==
'ZX' )
then 840 write(*,*)
'xxx [FILEIO_read_var_2D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
844 call fileread( var(dim1_s:dim1_e,dim2_s:dim2_e), fid, varname, step )
869 real(RP),
intent(out) :: var(:,:,:)
870 integer,
intent(in) :: fid
871 character(len=*),
intent(in) :: varname
872 character(len=*),
intent(in) :: axistype
873 integer,
intent(in) :: step
875 integer :: dim1_S, dim1_E
876 integer :: dim2_S, dim2_E
877 integer :: dim3_S, dim3_E
882 if(
io_l )
write(
io_fid_log,
'(1x,2A)')
'*** Read from file (3D), name : ', trim(varname)
888 if ( axistype ==
'ZXY' )
then 889 call fileread( var, fid, varname, step, &
890 ntypes=1, dtype=centertypezxy, start=startzxy, count=countzxy )
891 elseif( axistype ==
'XYT' )
then 894 call fileread( var, fid, varname, step, &
895 ntypes=step*
ia*
ja, dtype=etype, start=startxy, count=countxy )
896 elseif( axistype ==
'Land' )
then 897 call fileread( var, fid, varname, step, &
898 ntypes=1, dtype=centertypeland, start=startland, count=countland )
899 elseif( axistype ==
'Urban' )
then 900 call fileread( var, fid, varname, step, &
901 ntypes=1, dtype=centertypeurban, start=starturban, count=counturban )
903 write(*,*)
'xxx [FILEIO_read_var_3D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
907 if ( axistype ==
'ZXY' )
then 914 elseif( axistype ==
'XYT' )
then 921 elseif( axistype ==
'Land' )
then 928 elseif( axistype ==
'Urban' )
then 936 write(*,*)
'xxx [FILEIO_read_var_3D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
940 call fileread( var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
966 real(RP),
intent(out) :: var(:,:,:,:)
967 integer,
intent(in) :: fid
968 character(len=*),
intent(in) :: varname
969 character(len=*),
intent(in) :: axistype
970 integer,
intent(in) :: step
972 integer :: dim1_S, dim1_E
973 integer :: dim2_S, dim2_E
974 integer :: dim3_S, dim3_E
975 integer :: dim4_S, dim4_E
980 if(
io_l )
write(
io_fid_log,
'(1x,2A)')
'*** Read from file (4D), name : ', trim(varname)
984 if ( axistype ==
'ZXYT' )
then 987 call fileread( var, fid, varname, step, &
988 ntypes=step, dtype=centertypezxy, start=startzxy, count=countzxy )
990 write(*,*)
'xxx [FILEIO_read_var_4D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
994 if ( axistype ==
'ZXYT' )
then 1004 write(*,*)
'xxx [FILEIO_read_var_4D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
1008 call fileread( var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e,dim4_s:dim4_e), &
1009 fid, varname, step )
1034 filesetglobalattribute, &
1040 real(RP),
intent(in) :: var(:)
1041 character(len=*),
intent(in) :: basename
1042 character(len=*),
intent(in) :: title
1043 character(len=*),
intent(in) :: varname
1044 character(len=*),
intent(in) :: desc
1045 character(len=*),
intent(in) :: unit
1046 character(len=*),
intent(in) :: axistype
1047 character(len=*),
intent(in) :: datatype
1049 integer,
intent(in),
optional :: date(6)
1050 real(DP),
intent(in),
optional :: subsec
1051 logical,
intent(in),
optional :: append
1056 if(
io_l )
write(
io_fid_log,
'(1x,2A)')
'*** Write to file (1D), name : ', trim(varname)
1059 basename, title, datatype, date, subsec, append )
1061 call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype )
1089 filesetglobalattribute, &
1095 real(RP),
intent(in) :: var(:,:)
1096 character(len=*),
intent(in) :: basename
1097 character(len=*),
intent(in) :: title
1098 character(len=*),
intent(in) :: varname
1099 character(len=*),
intent(in) :: desc
1100 character(len=*),
intent(in) :: unit
1101 character(len=*),
intent(in) :: axistype
1102 character(len=*),
intent(in) :: datatype
1104 integer,
intent(in),
optional :: date(6)
1105 real(DP),
intent(in),
optional :: subsec
1106 logical,
intent(in),
optional :: append
1107 logical,
intent(in),
optional :: nohalo
1108 logical,
intent(in),
optional :: nozcoord
1113 if(
io_l )
write(
io_fid_log,
'(1x,2A)')
'*** Write to file (2D), name : ', trim(varname)
1116 basename, title, datatype, date, subsec, append, nozcoord )
1118 call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype )
1147 filesetglobalattribute, &
1154 real(RP),
intent(in) :: var(:,:,:)
1155 character(len=*),
intent(in) :: basename
1156 character(len=*),
intent(in) :: title
1157 character(len=*),
intent(in) :: varname
1158 character(len=*),
intent(in) :: desc
1159 character(len=*),
intent(in) :: unit
1160 character(len=*),
intent(in) :: axistype
1161 character(len=*),
intent(in) :: datatype
1163 integer,
intent(in),
optional :: date(6)
1164 real(DP),
intent(in),
optional :: subsec
1165 logical,
intent(in),
optional :: append
1166 logical,
intent(in),
optional :: nohalo
1171 if(
io_l )
write(
io_fid_log,
'(1x,2A)')
'*** Write to file (3D), name : ', trim(varname)
1174 basename, title, datatype, date, subsec, append )
1176 call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype )
1214 real(RP),
intent(in) :: var(:,:,:)
1215 character(len=*),
intent(in) :: basename
1216 character(len=*),
intent(in) :: title
1217 character(len=*),
intent(in) :: varname
1218 character(len=*),
intent(in) :: desc
1219 character(len=*),
intent(in) :: unit
1220 character(len=*),
intent(in) :: axistype
1221 character(len=*),
intent(in) :: datatype
1222 real(RP),
intent(in) :: timeintv
1223 integer ,
intent(in) :: tsince(6)
1225 logical,
intent(in),
optional :: append
1226 integer,
intent(in),
optional :: timetarg
1227 logical,
intent(in),
optional :: nohalo
1235 if(
io_l )
write(
io_fid_log,
'(1x,3A)')
'*** Write to file (3D), name : ', trim(varname),
'with time dimension' 1238 basename, title, datatype, tsince, append=append )
1240 if (
present(timetarg) )
then 1243 nsteps =
size(var,3)
1245 call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype, timeintv, nsteps )
1281 real(RP),
intent(in) :: var(:,:,:,:)
1282 character(len=*),
intent(in) :: basename
1283 character(len=*),
intent(in) :: title
1284 character(len=*),
intent(in) :: varname
1285 character(len=*),
intent(in) :: desc
1286 character(len=*),
intent(in) :: unit
1287 character(len=*),
intent(in) :: axistype
1288 character(len=*),
intent(in) :: datatype
1289 real(RP),
intent(in) :: timeintv
1290 integer,
intent(in) :: tsince(6)
1292 logical,
intent(in),
optional :: append
1293 integer,
intent(in),
optional :: timetarg
1294 logical,
intent(in),
optional :: nohalo
1302 if(
io_l )
write(
io_fid_log,
'(1x,2A)')
'*** Write to file (4D), name : ', trim(varname)
1305 basename, title, datatype, tsince, append=append )
1307 if (
present(timetarg) )
then 1310 nsteps =
size(var,3)
1312 call fileio_def_var( fid, vid, varname, desc, unit, axistype, datatype, timeintv, nsteps )
1333 use mpi,
only : mpi_comm_null
1336 integer,
intent(out) :: fid
1337 character(len=*),
intent(in) :: basename
1347 comm = mpi_comm_null
1356 file_closed(fid) = .false.
1381 filesetglobalattribute
1396 integer,
intent(out) :: fid
1397 character(len=*),
intent(in) :: basename
1398 character(len=*),
intent(in) :: title
1399 character(len=*),
intent(in) :: datatype
1401 integer,
intent(in),
optional :: date(6)
1402 real(DP),
intent(in),
optional :: subsec
1403 logical,
intent(in),
optional :: append
1404 logical,
intent(in),
optional :: nozcoord
1406 integer :: rankidx(2)
1408 logical :: append_sw
1409 character(len=34) :: tunits
1411 logical :: fileexisted
1412 character(len=H_SHORT) :: logical_str
1421 if ( datatype ==
'REAL8' )
then 1423 elseif( datatype ==
'REAL4' )
then 1428 elseif(
rp == 4 )
then 1431 write(*,*)
'xxx unsupported data type. Check!', trim(datatype)
1437 if (
present(append) )
then 1442 if (
present(date) )
then 1443 call getcftunits( tunits, date )
1451 comm = mpi_comm_null
1463 time_units = tunits, &
1464 append = append_sw, &
1467 if ( .NOT. fileexisted )
then 1469 file_axes_written(fid) = .false.
1470 if (
present( nozcoord ) )
then 1471 file_nozcoord(fid) = nozcoord
1473 file_nozcoord(fid) = .false.
1476 if (
present( subsec ) )
then 1477 call filesetglobalattribute( fid,
"time", (/subsec/) )
1479 call filesetglobalattribute( fid,
"time", (/nowms/) )
1481 if (
present( date ) )
then 1482 call getcftunits(tunits, date)
1484 call getcftunits(tunits, nowdate)
1486 call filesetglobalattribute( fid,
"time_units", tunits )
1487 call filesetglobalattribute( fid,
"IHALO", (/
ihalo/) )
1488 call filesetglobalattribute( fid,
"JHALO", (/
jhalo/) )
1489 logical_str =
"false" 1491 call filesetglobalattribute( fid,
"PRC_PERIODIC_X", trim(logical_str) )
1492 logical_str =
"false" 1494 call filesetglobalattribute( fid,
"PRC_PERIODIC_Y", trim(logical_str) )
1496 file_closed(fid) = .false.
1514 integer,
intent(in) :: fid
1522 if ( .NOT. file_axes_written(fid) )
then 1530 file_axes_written(fid) = .true.
1546 integer,
intent(in) :: fid
1570 integer,
intent(in) :: fid
1576 if ( .NOT. file_closed(fid) )
then 1580 if ( write_buf_amount > 0 )
then 1582 write_buf_amount = 0
1588 file_closed(fid) = .true.
1612 integer,
intent(in) :: fid
1613 integer,
intent(in) :: dtype
1614 logical,
intent(in),
optional :: xy
1616 character(len=2) :: AXIS_name(3)
1620 if (
present(xy) )
then 1626 if ( .NOT. xy_ )
then 1637 if ( .NOT. xy_ )
then 1638 call filedefaxis( fid,
'zh',
'Z (half level)',
'm',
'zh', dtype,
kmax )
1644 call filedefaxis( fid,
'xh',
'X (half level)',
'm',
'xh', dtype,
iag )
1645 call filedefaxis( fid,
'yh',
'Y (half level)',
'm',
'yh', dtype,
jag )
1648 if ( .NOT. xy_ )
then 1650 call filedefaxis( fid,
'lzh',
'LZ (half level)',
'm',
'lzh', dtype,
lkmax )
1652 call filedefaxis( fid,
'uzh',
'UZ (half level)',
'm',
'uzh', dtype,
ukmax )
1655 if ( .NOT. xy_ )
then 1656 call filedefaxis( fid,
'CZ',
'Atmos Grid Center Position Z',
'm',
'CZ', dtype,
ka )
1659 call filedefaxis( fid,
'CX',
'Atmos Grid Center Position X',
'm',
'CX', dtype,
ia )
1660 call filedefaxis( fid,
'CY',
'Atmos Grid Center Position Y',
'm',
'CY', dtype,
ja )
1662 call filedefaxis( fid,
'CX',
'Atmos Grid Center Position X',
'm',
'CX', dtype,
iag )
1663 call filedefaxis( fid,
'CY',
'Atmos Grid Center Position Y',
'm',
'CY', dtype,
jag )
1666 if ( .NOT. xy_ )
then 1667 call filedefaxis( fid,
'FZ',
'Atmos Grid Face Position Z',
'm',
'FZ', dtype,
ka+1 )
1670 call filedefaxis( fid,
'FX',
'Atmos Grid Face Position X',
'm',
'FX', dtype,
ia+1 )
1671 call filedefaxis( fid,
'FY',
'Atmos Grid Face Position Y',
'm',
'FY', dtype,
ja+1 )
1673 call filedefaxis( fid,
'FX',
'Atmos Grid Face Position X',
'm',
'FX', dtype,
iag+1 )
1674 call filedefaxis( fid,
'FY',
'Atmos Grid Face Position Y',
'm',
'FY', dtype,
jag+1 )
1677 if ( .NOT. xy_ )
then 1678 call filedefaxis( fid,
'CDZ',
'Grid Cell length Z',
'm',
'CZ', dtype,
ka )
1681 call filedefaxis( fid,
'CDX',
'Grid Cell length X',
'm',
'CX', dtype,
ia )
1682 call filedefaxis( fid,
'CDY',
'Grid Cell length Y',
'm',
'CY', dtype,
ja )
1684 call filedefaxis( fid,
'CDX',
'Grid Cell length X',
'm',
'CX', dtype,
iag )
1685 call filedefaxis( fid,
'CDY',
'Grid Cell length Y',
'm',
'CY', dtype,
jag )
1688 if ( .NOT. xy_ )
then 1689 call filedefaxis( fid,
'FDZ',
'Grid distance Z',
'm',
'FDZ', dtype,
ka-1 )
1692 call filedefaxis( fid,
'FDX',
'Grid distance X',
'm',
'FDX', dtype,
ia-1 )
1693 call filedefaxis( fid,
'FDY',
'Grid distance Y',
'm',
'FDY', dtype,
ja-1 )
1695 call filedefaxis( fid,
'FDX',
'Grid distance X',
'm',
'FDX', dtype,
iag-1 )
1696 call filedefaxis( fid,
'FDY',
'Grid distance Y',
'm',
'FDY', dtype,
jag-1 )
1699 if ( .NOT. xy_ )
then 1700 call filedefaxis( fid,
'LCZ',
'Land Grid Center Position Z',
'm',
'LCZ', dtype,
lkmax )
1701 call filedefaxis( fid,
'LFZ',
'Land Grid Face Position Z',
'm',
'LFZ', dtype,
lkmax+1 )
1702 call filedefaxis( fid,
'LCDZ',
'Land Grid Cell length Z',
'm',
'LCZ', dtype,
lkmax )
1704 call filedefaxis( fid,
'UCZ',
'Urban Grid Center Position Z',
'm',
'UCZ', dtype,
ukmax )
1705 call filedefaxis( fid,
'UFZ',
'Urban Grid Face Position Z',
'm',
'UFZ', dtype,
ukmax+1 )
1706 call filedefaxis( fid,
'UCDZ',
'Urban Grid Cell length Z',
'm',
'UCZ', dtype,
ukmax )
1709 if ( .NOT. xy_ )
then 1710 call filedefaxis( fid,
'CBFZ',
'Boundary factor Center Z',
'1',
'CZ', dtype,
ka )
1713 call filedefaxis( fid,
'CBFX',
'Boundary factor Center X',
'1',
'CX', dtype,
ia )
1714 call filedefaxis( fid,
'CBFY',
'Boundary factor Center Y',
'1',
'CY', dtype,
ja )
1716 call filedefaxis( fid,
'CBFX',
'Boundary factor Center X',
'1',
'CX', dtype,
iag )
1717 call filedefaxis( fid,
'CBFY',
'Boundary factor Center Y',
'1',
'CY', dtype,
jag )
1720 if ( .NOT. xy_ )
then 1721 call filedefaxis( fid,
'FBFZ',
'Boundary factor Face Z',
'1',
'CZ', dtype,
ka )
1724 call filedefaxis( fid,
'FBFX',
'Boundary factor Face X',
'1',
'CX', dtype,
ia )
1725 call filedefaxis( fid,
'FBFY',
'Boundary factor Face Y',
'1',
'CY', dtype,
ja )
1727 call filedefaxis( fid,
'FBFX',
'Boundary factor Face X',
'1',
'CX', dtype,
iag )
1728 call filedefaxis( fid,
'FBFY',
'Boundary factor Face Y',
'1',
'CY', dtype,
jag )
1732 call filedefaxis( fid,
'CXG',
'Grid Center Position X (global)',
'm',
'CXG', dtype,
iag )
1733 call filedefaxis( fid,
'CYG',
'Grid Center Position Y (global)',
'm',
'CYG', dtype,
jag )
1734 call filedefaxis( fid,
'FXG',
'Grid Face Position X (global)',
'm',
'FXG', dtype,
iag+1 )
1735 call filedefaxis( fid,
'FYG',
'Grid Face Position Y (global)',
'm',
'FYG', dtype,
jag+1 )
1737 call filedefaxis( fid,
'CBFXG',
'Boundary factor Center X (global)',
'1',
'CXG', dtype,
iag )
1738 call filedefaxis( fid,
'CBFYG',
'Boundary factor Center Y (global)',
'1',
'CYG', dtype,
jag )
1739 call filedefaxis( fid,
'FBFXG',
'Boundary factor Face X (global)',
'1',
'CXG', dtype,
iag )
1740 call filedefaxis( fid,
'FBFYG',
'Boundary factor Face Y (global)',
'1',
'CYG', dtype,
jag )
1743 axis_name(1:2) = (/
'x ',
'y '/)
1745 'degrees_east' , axis_name(1:2), dtype )
1746 axis_name(1:2) = (/
'xh',
'y '/)
1748 'degrees_east' , axis_name(1:2), dtype )
1749 axis_name(1:2) = (/
'x ',
'yh'/)
1751 'degrees_east' , axis_name(1:2), dtype )
1752 axis_name(1:2) = (/
'xh',
'yh'/)
1754 'degrees_east' , axis_name(1:2), dtype )
1755 axis_name(1:2) = (/
'x ',
'y '/)
1757 'degrees_north', axis_name(1:2), dtype )
1758 axis_name(1:2) = (/
'xh',
'y '/)
1760 'degrees_north', axis_name(1:2), dtype )
1761 axis_name(1:2) = (/
'x ',
'yh'/)
1763 'degrees_north', axis_name(1:2), dtype )
1764 axis_name(1:2) = (/
'xh',
'yh'/)
1766 'degrees_north', axis_name(1:2), dtype )
1768 if ( .NOT. xy_ )
then 1769 axis_name = (/
'z',
'x',
'y'/)
1771 'm', axis_name(1:3), dtype )
1772 axis_name = (/
'zh',
'x ',
'y '/)
1774 'm', axis_name(1:3), dtype )
1778 if ( .NOT. xy_ )
then 1799 filewriteassociatedcoordinates
1847 integer,
intent(in) :: fid
1848 logical,
intent(in),
optional :: xy
1855 integer :: rankidx(2)
1859 if (
present(xy) )
then 1880 put_z = ( .NOT. xy_ ) .AND. (
prc_myrank == 0 )
1881 put_x = ( rankidx(2) == 0 )
1882 put_y = ( rankidx(1) == 0 )
1884 put_z = ( .NOT. xy_ )
1893 call filewriteaxis( fid,
'z',
grid_cz(
ks:
ke), start )
1894 call filewriteaxis( fid,
'zh',
grid_fz(
ks:
ke), start )
1902 call filewriteaxis( fid,
'x',
grid_cx(xsb:xeb), start )
1903 call filewriteaxis( fid,
'xh',
grid_fx(xsb:xeb), start )
1907 call filewriteaxis( fid,
'y',
grid_cy(ysb:yeb), start )
1908 call filewriteaxis( fid,
'yh',
grid_fy(ysb:yeb), start )
1913 call filewriteaxis( fid,
'CZ',
grid_cz, start )
1914 call filewriteaxis( fid,
'FZ',
grid_fz, start )
1915 call filewriteaxis( fid,
'CDZ',
grid_cdz, start )
1916 call filewriteaxis( fid,
'FDZ',
grid_fdz, start )
1918 call filewriteaxis( fid,
'LCZ',
grid_lcz, start )
1919 call filewriteaxis( fid,
'LFZ',
grid_lfz, start )
1920 call filewriteaxis( fid,
'LCDZ',
grid_lcdz, start )
1922 call filewriteaxis( fid,
'UCZ',
grid_ucz, start )
1923 call filewriteaxis( fid,
'UFZ',
grid_ufz, start )
1924 call filewriteaxis( fid,
'UCDZ',
grid_ucdz, start )
1926 call filewriteaxis( fid,
'CBFZ',
grid_cbfz, start )
1927 call filewriteaxis( fid,
'FBFZ',
grid_fbfz, start )
1933 call filewriteaxis( fid,
'CX',
grid_cxg, start )
1934 call filewriteaxis( fid,
'CY',
grid_cyg, start )
1935 call filewriteaxis( fid,
'FX',
grid_fxg, start )
1936 call filewriteaxis( fid,
'FY',
grid_fyg, start )
1938 call filewriteaxis( fid,
'CDX',
grid_cdxg, start )
1939 call filewriteaxis( fid,
'CDY',
grid_cdyg, start )
1940 call filewriteaxis( fid,
'FDX',
grid_fdxg, start )
1941 call filewriteaxis( fid,
'FDY',
grid_fdyg, start )
1943 call filewriteaxis( fid,
'CBFX',
grid_cbfxg, start )
1944 call filewriteaxis( fid,
'CBFY',
grid_cbfyg, start )
1945 call filewriteaxis( fid,
'FBFX',
grid_fbfxg, start )
1946 call filewriteaxis( fid,
'FBFY',
grid_fbfyg, start )
1948 call filewriteaxis( fid,
'CXG',
grid_cxg, start )
1949 call filewriteaxis( fid,
'CYG',
grid_cyg, start )
1950 call filewriteaxis( fid,
'FXG',
grid_fxg, start )
1951 call filewriteaxis( fid,
'FYG',
grid_fyg, start )
1953 call filewriteaxis( fid,
'CBFXG',
grid_cbfxg, start )
1954 call filewriteaxis( fid,
'CBFYG',
grid_cbfyg, start )
1955 call filewriteaxis( fid,
'FBFXG',
grid_fbfxg, start )
1956 call filewriteaxis( fid,
'FBFYG',
grid_fbfyg, start )
1959 call filewriteaxis( fid,
'CX',
grid_cx )
1960 call filewriteaxis( fid,
'CY',
grid_cy )
1961 call filewriteaxis( fid,
'FX',
grid_fx )
1962 call filewriteaxis( fid,
'FY',
grid_fy )
1964 call filewriteaxis( fid,
'CDX',
grid_cdx )
1965 call filewriteaxis( fid,
'CDY',
grid_cdy )
1966 call filewriteaxis( fid,
'FDX',
grid_fdx )
1967 call filewriteaxis( fid,
'FDY',
grid_fdy )
1969 call filewriteaxis( fid,
'CBFX',
grid_cbfx )
1970 call filewriteaxis( fid,
'CBFY',
grid_cbfy )
1971 call filewriteaxis( fid,
'FBFX',
grid_fbfx )
1972 call filewriteaxis( fid,
'FBFY',
grid_fbfy )
1974 call filewriteaxis( fid,
'CXG',
grid_cxg )
1975 call filewriteaxis( fid,
'CYG',
grid_cyg )
1976 call filewriteaxis( fid,
'FXG',
grid_fxg )
1977 call filewriteaxis( fid,
'FYG',
grid_fyg )
1979 call filewriteaxis( fid,
'CBFXG',
grid_cbfxg )
1980 call filewriteaxis( fid,
'CBFYG',
grid_cbfyg )
1981 call filewriteaxis( fid,
'FBFXG',
grid_fbfxg )
1982 call filewriteaxis( fid,
'FBFYG',
grid_fbfyg )
1991 call filewriteassociatedcoordinates( fid,
'lon' , axis_lon(xsb:xeb,ysb:yeb), start )
1992 call filewriteassociatedcoordinates( fid,
'lon_uy', axis_lonx(xsb:xeb,ysb:yeb), start )
1993 call filewriteassociatedcoordinates( fid,
'lon_xv', axis_lony(xsb:xeb,ysb:yeb), start )
1994 call filewriteassociatedcoordinates( fid,
'lon_uv', axis_lonxy(xsb:xeb,ysb:yeb), start )
1995 call filewriteassociatedcoordinates( fid,
'lat' , axis_lat(xsb:xeb,ysb:yeb), start )
1996 call filewriteassociatedcoordinates( fid,
'lat_uy', axis_latx(xsb:xeb,ysb:yeb), start )
1997 call filewriteassociatedcoordinates( fid,
'lat_xv', axis_laty(xsb:xeb,ysb:yeb), start )
1998 call filewriteassociatedcoordinates( fid,
'lat_uv', axis_latxy(xsb:xeb,ysb:yeb), start )
2000 if ( .NOT. xy_ )
then 2006 call filewriteassociatedcoordinates( fid,
'height', axis_hzxy(
ks:
ke,xsb:xeb,ysb:yeb), start )
2007 call filewriteassociatedcoordinates( fid,
'height_wxy', axis_hwxy(
ks:
ke,xsb:xeb,ysb:yeb), start )
2034 integer,
intent(in) :: fid
2035 integer,
intent(out) :: vid
2036 character(len=*),
intent(in) :: varname
2037 character(len=*),
intent(in) :: desc
2038 character(len=*),
intent(in) :: unit
2039 character(len=*),
intent(in) :: axistype
2040 character(len=*),
intent(in) :: datatype
2042 real(RP),
intent(in),
optional :: timeintv
2043 integer,
intent(in),
optional :: nsteps
2045 integer :: dtype, ndims, elm_size
2046 character(len=2) :: dims(3)
2047 real(DP) :: time_interval
2052 if ( datatype ==
'REAL8' )
then 2055 elseif( datatype ==
'REAL4' )
then 2062 elseif(
rp == 4 )
then 2066 write(*,*)
'xxx unsupported data type. Check!', trim(datatype),
' item:',trim(varname)
2071 if ( axistype ==
'Z' )
then 2074 write_buf_amount = write_buf_amount +
ka * elm_size
2075 elseif( axistype ==
'X' )
then 2078 write_buf_amount = write_buf_amount +
ia * elm_size
2079 elseif( axistype ==
'Y' )
then 2082 write_buf_amount = write_buf_amount +
ja * elm_size
2083 elseif( axistype ==
'XY' )
then 2087 write_buf_amount = write_buf_amount +
ia *
ja * elm_size
2088 elseif( axistype ==
'UY' )
then 2092 write_buf_amount = write_buf_amount +
ia *
ja * elm_size
2093 elseif( axistype ==
'XV' )
then 2097 write_buf_amount = write_buf_amount +
ia *
ja * elm_size
2098 elseif( axistype ==
'UV' )
then 2102 write_buf_amount = write_buf_amount +
ia *
ja * elm_size
2103 elseif( axistype ==
'ZX' )
then 2107 write_buf_amount = write_buf_amount +
ka *
ia * elm_size
2108 elseif( axistype ==
'ZXY' )
then 2110 dims = (/
'z',
'x',
'y'/)
2111 write_buf_amount = write_buf_amount +
ka *
ia *
ja * elm_size
2112 elseif( axistype ==
'ZHXY' )
then 2114 dims = (/
'zh',
'x ',
'y '/)
2115 write_buf_amount = write_buf_amount +
ka *
ia *
ja * elm_size
2116 elseif( axistype ==
'ZXHY' )
then 2118 dims = (/
'z ',
'xh',
'y '/)
2119 write_buf_amount = write_buf_amount +
ka *
ia *
ja * elm_size
2120 elseif( axistype ==
'ZXYH' )
then 2122 dims = (/
'z ',
'x ',
'yh'/)
2123 write_buf_amount = write_buf_amount +
ka *
ia *
ja * elm_size
2124 elseif( axistype ==
'Land' )
then 2126 dims = (/
'lz',
'x ',
'y '/)
2127 write_buf_amount = write_buf_amount +
lkmax *
ia *
ja * elm_size
2128 elseif( axistype ==
'Urban' )
then 2130 dims = (/
'uz',
'x ',
'y '/)
2131 write_buf_amount = write_buf_amount +
ukmax *
ia *
ja * elm_size
2132 elseif( axistype ==
'XYT' )
then 2136 if (
present(nsteps) )
then 2137 write_buf_amount = write_buf_amount +
ia *
ja * elm_size * nsteps
2139 write_buf_amount = write_buf_amount +
ia *
ja * elm_size
2141 elseif( axistype ==
'ZXYT' )
then 2143 dims = (/
'z',
'x',
'y'/)
2144 if (
present(nsteps) )
then 2145 write_buf_amount = write_buf_amount +
ka *
ia *
ja * elm_size * nsteps
2147 write_buf_amount = write_buf_amount +
ka *
ia *
ja * elm_size
2150 write(*,*)
'xxx [FILEIO_def_var] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
2154 if (
present(timeintv) )
then 2155 time_interval = timeintv
2157 tint=time_interval )
2186 integer,
intent(in) :: fid
2187 integer,
intent(in) :: vid
2188 real(RP),
intent(in) :: var(:)
2189 character(len=*),
intent(in) :: varname
2190 character(len=*),
intent(in) :: axistype
2192 integer :: dim1_S, dim1_E
2193 integer :: rankidx(2)
2195 logical :: exec = .true.
2203 if ( axistype ==
'Z' )
then 2208 elseif( axistype ==
'X' )
then 2213 elseif( axistype ==
'Y' )
then 2219 write(*,*)
'xxx [FILEIO_write_var_1D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
2223 if( exec )
call filewrite( fid, vid, var(dim1_s:dim1_e), &
2224 nowsec, nowsec, start )
2255 integer,
intent(in) :: fid
2256 integer,
intent(in) :: vid
2257 real(RP),
intent(in) :: var(:,:)
2258 character(len=*),
intent(in) :: varname
2259 character(len=*),
intent(in) :: axistype
2260 logical,
intent(in),
optional :: nohalo
2262 real(RP) :: varhalo( size(var(:,1)), size(var(1,:)) )
2264 integer :: dim1_S, dim1_E
2265 integer :: dim2_S, dim2_E
2269 integer :: rankidx(2)
2271 logical :: exec = .true.
2283 if(
present(nohalo) ) nohalo_ = nohalo
2285 if ( axistype ==
'XY' &
2286 .OR. axistype ==
'UY' &
2287 .OR. axistype ==
'XV' &
2288 .OR. axistype ==
'UV' )
then 2294 if( rankidx(1) == 0 ) dim1_s = 1
2296 if( rankidx(2) == 0 ) dim2_s = 1
2299 elseif( axistype ==
'ZX' )
then 2308 if( rankidx(1) == 0 ) dim2_s = 1
2312 write(*,*)
'xxx [FILEIO_write_var_2D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
2318 varhalo(:,:) = var(:,:)
2323 varhalo(i,j) = rmiss
2329 varhalo(i,j) = rmiss
2335 varhalo(i,j) = rmiss
2341 varhalo(i,j) = rmiss
2345 call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e), &
2346 nowsec, nowsec, start )
2348 call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e), &
2349 nowsec, nowsec, start )
2383 integer,
intent(in) :: fid
2384 integer,
intent(in) :: vid
2385 real(RP),
intent(in) :: var(:,:,:)
2386 character(len=*),
intent(in) :: varname
2387 character(len=*),
intent(in) :: axistype
2389 logical,
intent(in),
optional :: nohalo
2391 real(RP) :: varhalo( size(var(:,1,1)), size(var(1,:,1)), size(var(1,1,:)) )
2393 integer :: dim1_S, dim1_E, dim1_max
2394 integer :: dim2_S, dim2_E
2395 integer :: dim3_S, dim3_E
2399 integer :: rankidx(2)
2406 if(
present(nohalo) ) nohalo_ = nohalo
2420 if( rankidx(1) == 0 ) dim2_s = 1
2422 if( rankidx(2) == 0 ) dim3_s = 1
2426 if ( axistype ==
'ZXY' &
2427 .OR. axistype ==
'ZHXY' &
2428 .OR. axistype ==
'ZXHY' &
2429 .OR. axistype ==
'ZXYH' )
then 2433 elseif( axistype ==
'Land' )
then 2437 elseif( axistype ==
'Urban' )
then 2442 write(*,*)
'xxx [FILEIO_write_var_3D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
2447 varhalo(:,:,:) = var(:,:,:)
2453 varhalo(k,i,j) = rmiss
2461 varhalo(k,i,j) = rmiss
2469 varhalo(k,i,j) = rmiss
2477 varhalo(k,i,j) = rmiss
2482 call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
2483 nowsec, nowsec, start )
2485 call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
2486 nowsec, nowsec, start )
2518 integer,
intent(in) :: fid
2519 integer,
intent(in) :: vid
2520 real(RP),
intent(in) :: var(:,:,:)
2521 character(len=*),
intent(in) :: varname
2522 character(len=*),
intent(in) :: axistype
2523 real(RP),
intent(in) :: timeintv
2525 integer,
intent(in),
optional :: timetarg
2526 logical,
intent(in),
optional :: nohalo
2528 real(RP) :: varhalo( size(var(:,1,1)), size(var(1,:,1)) )
2530 integer :: dim1_S, dim1_E
2531 integer :: dim2_S, dim2_E
2533 real(DP) :: time_interval, nowtime
2538 integer :: rankidx(2)
2545 if(
present(nohalo) ) nohalo_ = nohalo
2547 time_interval = timeintv
2548 step =
size(var(
isb,
jsb,:))
2553 if ( axistype ==
'XYT' )
then 2559 if( rankidx(1) == 0 ) dim1_s = 1
2561 if( rankidx(2) == 0 ) dim2_s = 1
2565 write(*,*)
'xxx [FILEIO_write_var_3D_t] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
2573 if (
present(timetarg) )
then 2574 nowtime = (timetarg-1) * time_interval
2577 varhalo(:,:) = var(:,:,timetarg)
2582 varhalo(i,j) = rmiss
2588 varhalo(i,j) = rmiss
2594 varhalo(i,j) = rmiss
2600 varhalo(i,j) = rmiss
2604 call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e), &
2605 nowtime, nowtime, start )
2607 call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,timetarg), &
2608 nowtime, nowtime, start )
2614 varhalo(:,:) = var(:,:,n)
2619 varhalo(i,j) = rmiss
2625 varhalo(i,j) = rmiss
2631 varhalo(i,j) = rmiss
2637 varhalo(i,j) = rmiss
2641 call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e), &
2642 nowtime, nowtime, start )
2644 call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,n), &
2645 nowtime, nowtime, start )
2647 nowtime = nowtime + time_interval
2680 integer,
intent(in) :: fid
2681 integer,
intent(in) :: vid
2682 real(RP),
intent(in) :: var(:,:,:,:)
2683 character(len=*),
intent(in) :: varname
2684 character(len=*),
intent(in) :: axistype
2685 real(RP),
intent(in) :: timeintv
2687 integer,
intent(in),
optional :: timetarg
2688 logical,
intent(in),
optional :: nohalo
2690 real(RP) :: varhalo( size(var(:,1,1,1)), size(var(1,:,1,1)), size(var(1,1,:,1)) )
2692 integer :: dim1_S, dim1_E, dim1_max
2693 integer :: dim2_S, dim2_E
2694 integer :: dim3_S, dim3_E
2696 real(DP) :: time_interval, nowtime
2699 integer :: i, j, k, n
2701 integer :: rankidx(2)
2708 if(
present(nohalo) ) nohalo_ = nohalo
2718 time_interval = timeintv
2721 if ( axistype ==
'ZXYT' )
then 2730 if( rankidx(1) == 0 ) dim2_s = 1
2732 if( rankidx(2) == 0 ) dim3_s = 1
2736 write(*,*)
'xxx [FILEIO_write_var_4D] unsupported axis type. Check! axistype:', trim(axistype),
', item:',trim(varname)
2740 if (
present(timetarg) )
then 2741 nowtime = (timetarg-1) * time_interval
2744 varhalo(:,:,:) = var(:,:,:,timetarg)
2750 varhalo(k,i,j) = rmiss
2758 varhalo(k,i,j) = rmiss
2766 varhalo(k,i,j) = rmiss
2774 varhalo(k,i,j) = rmiss
2779 call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
2780 nowtime, nowtime, start )
2782 call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e,timetarg), &
2783 nowtime, nowtime, start )
2789 varhalo(:,:,:) = var(:,:,:,n)
2795 varhalo(k,i,j) = rmiss
2803 varhalo(k,i,j) = rmiss
2811 varhalo(k,i,j) = rmiss
2819 varhalo(k,i,j) = rmiss
2824 call filewrite( fid, vid, varhalo(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e), &
2825 nowtime, nowtime, start )
2827 call filewrite( fid, vid, var(dim1_s:dim1_e,dim2_s:dim2_e,dim3_s:dim3_e,n), &
2828 nowtime, nowtime, start )
2830 nowtime = nowtime + time_interval
2846 do fid = 0, file_nfile_max-1
2851 end subroutine closeall
2854 subroutine getcftunits(tunits, date)
2857 character(len=34),
intent(out) :: tunits
2858 integer,
intent(in) :: date(6)
2861 write(tunits,
'(a,i4.4,"-",i2.2,"-",i2.2," ",i2.2,":",i2.2,":",i2.2)')
'seconds since ', date
2864 end subroutine getcftunits
2867 subroutine check_1d( &
2876 real(RP),
intent(in) :: expected(:)
2877 real(RP),
intent(in) :: buffer(:)
2878 character(len=*),
intent(in) :: name
2886 nmax =
size(expected)
2887 if (
size(buffer) /= nmax )
then 2888 write(*,*)
'xxx size of coordinate ('//trim(name)//
') is different:', nmax,
size(buffer)
2893 if ( abs(expected(n)) > eps )
then 2894 check = abs(buffer(n)-expected(n)) / abs(buffer(n)+expected(n)) * 2.0_rp
2896 check = abs(buffer(n)-expected(n))
2899 if ( check > fileio_datacheck_criteria )
then 2900 write(*,*)
'xxx value of coordinate ('//trim(name)//
') at ', n,
' is different:', &
2901 expected(n), buffer(n), check
2907 end subroutine check_1d
2910 subroutine check_2d( &
2919 real(RP),
intent(in) :: expected(:,:)
2920 real(RP),
intent(in) :: buffer(:,:)
2921 character(len=*),
intent(in) :: name
2924 integer :: imax, jmax
2930 imax =
size(expected,1)
2931 jmax =
size(expected,2)
2932 if (
size(buffer,1) /= imax )
then 2933 write(*,*)
'xxx the first size of coordinate ('//trim(name)//
') is different:', imax,
size(buffer,1)
2936 if (
size(buffer,2) /= jmax )
then 2937 write(*,*)
'xxx the second size of coordinate ('//trim(name)//
') is different:', jmax,
size(buffer,2)
2943 if ( abs(expected(i,j)) > eps )
then 2944 check = abs(buffer(i,j)-expected(i,j)) / abs(buffer(i,j)+expected(i,j)) * 2.0_rp
2946 check = abs(buffer(i,j)-expected(i,j))
2949 if ( check > fileio_datacheck_criteria )
then 2950 write(*,*)
'xxx value of coordinate ('//trim(name)//
') at (', i,
',', j,
') is different:', &
2951 expected(i,j), buffer(i,j), check
2958 end subroutine check_2d
2961 subroutine check_3d( &
2971 real(RP),
intent(in) :: expected(:,:,:)
2972 real(RP),
intent(in) :: buffer(:,:,:)
2973 character(len=*),
intent(in) :: name
2974 logical,
intent(in) :: transpose
2977 integer :: imax, jmax, kmax
2983 if ( transpose )
then 2984 kmax =
size(expected,3)
2985 imax =
size(expected,1)
2986 jmax =
size(expected,2)
2988 kmax =
size(expected,1)
2989 imax =
size(expected,2)
2990 jmax =
size(expected,3)
2992 if (
size(buffer,1) /= kmax )
then 2993 write(*,*)
'xxx the first size of coordinate ('//trim(name)//
') is different:', kmax,
size(buffer,1)
2996 if (
size(buffer,2) /= imax )
then 2997 write(*,*)
'xxx the second size of coordinate ('//trim(name)//
') is different:', imax,
size(buffer,2)
3000 if (
size(buffer,3) /= jmax )
then 3001 write(*,*)
'xxx the third size of coordinate ('//trim(name)//
') is different:', jmax,
size(buffer,3)
3005 if ( transpose )
then 3010 if ( abs(expected(k,i,j)) > eps )
then 3011 check = abs(buffer(i,j,k)-expected(k,i,j)) / abs(buffer(i,j,k)+expected(k,i,j)) * 2.0_rp
3013 check = abs(buffer(i,j,k)-expected(k,i,j))
3016 if ( check > fileio_datacheck_criteria )
then 3017 write(*,*)
'xxx value of coordinate ('//trim(name)//
') at ', i,
',', j,
',', k,
' is different:', &
3018 expected(k,i,j), buffer(i,j,k), check
3028 if ( abs(expected(k,i,j)) > eps )
then 3029 check = abs(buffer(k,i,j)-expected(k,i,j)) / abs(buffer(k,i,j)+expected(k,i,j)) * 2.0_rp
3031 check = abs(buffer(k,i,j)-expected(k,i,j))
3034 if ( check > fileio_datacheck_criteria )
then 3035 write(*,*)
'xxx value of coordinate ('//trim(name)//
') at ', k,
',', i,
',', j,
' is different:', &
3036 expected(k,i,j), buffer(k,i,j), check
3045 end subroutine check_3d
integer, public imax
of computational cells: x, local
integer, public prc_num_x
x length of 2D processor topology
integer, public is
start point of inner domain: x, local
integer, public je
end point of inner domain: y, local
subroutine fileio_read_1d(var, basename, varname, axistype, step)
Read 1D data from file.
real(rp), dimension(:), allocatable, public grid_cyg
center coordinate [m]: y, global
integer, public prc_local_comm_world
local communicator
subroutine, public prc_mpistop
Abort MPI.
real(rp), dimension(:), allocatable, public grid_cbfyg
center buffer factor (0-1): y, global
logical, public prc_periodic_y
periodic condition or not (Y)?
real(dp), public time_nowms
subsecond part of current time [millisec]
real(rp), dimension(:), allocatable, public grid_cxg
center coordinate [m]: x, global
real(rp), dimension(:), allocatable, public grid_fdy
y-length of grid(j+1) to grid(j) [m]
logical, public io_l
output log or not? (this process)
real(rp), dimension(:), allocatable, public grid_cdyg
center coordinate [m]: y, global
subroutine fileio_def_axes(fid, dtype, xy)
define axis variables in the file
real(rp), dimension(:), allocatable, public grid_cz
center coordinate [m]: z, local=global
real(rp), dimension(:), allocatable, public grid_fxg
face coordinate [m]: x, global
subroutine, public fileio_flush(fid)
Flush all pending requests to a netCDF file (PnetCDF only)
subroutine fileio_write_var_3d(fid, vid, var, varname, axistype, nohalo)
Write 3D data to file.
real(rp), dimension(:), allocatable, public grid_fbfy
face buffer factor (0-1): y
subroutine, public fileio_setup
Setup.
real(dp), public time_nowdaysec
second of current time [sec]
integer, public ke
end point of inner domain: z, local
subroutine fileio_write_3d_t(var, basename, title, varname, desc, unit, axistype, datatype, timeintv, tsince, append, timetarg, nohalo)
Write 3D data with time dimension to file.
real(rp), public const_d2r
degree to radian
subroutine fileio_write_4d(var, basename, title, varname, desc, unit, axistype, datatype, timeintv, tsince, append, timetarg, nohalo)
Write 4D data to file.
subroutine construct_derived_datatype
construct MPI derived datatypes for read buffers
module GRID (cartesian) for land
logical, public prc_periodic_x
periodic condition or not (X)?
real(rp), dimension(:), allocatable, public grid_cdxg
center coordinate [m]: x, global
subroutine fileio_write_axes(fid, xy)
write axis to the file
subroutine fileio_write_var_4d(fid, vid, var, varname, axistype, timeintv, timetarg, nohalo)
Write 4D data to file.
subroutine fileio_read_4d(var, basename, varname, axistype, step)
Read 4D data from file.
real(rp), dimension(:), allocatable, public grid_fx
face coordinate [m]: x, local
subroutine fileio_read_var_1d(var, fid, varname, axistype, step)
Read 1D data from file.
subroutine fileio_write_var_1d(fid, vid, var, varname, axistype)
Write 1D data to file.
real(rp), dimension(:), allocatable, public grid_lfz
face coordinate [m]: z, local=global
integer, public prc_num_y
y length of 2D processor topology
subroutine fileio_read_var_4d(var, fid, varname, axistype, step)
Read 4D data from file.
real(rp), dimension(:), allocatable, public grid_ucdz
z-length of control volume [m]
logical, public io_nml
output log or not? (for namelist, this process)
integer, public jsga
start point of the full domain: cy, global
integer, public ia
of whole cells: x, local, with HALO
character(len=h_mid), public h_source
for file header
integer, public jag
of computational grids
module GRID (cartesian) for urban
real(rp), dimension(:), allocatable, public grid_fbfx
face buffer factor (0-1): x
real(rp), dimension(:), allocatable, public grid_fdz
z-length of grid(k+1) to grid(k) [m]
real(rp), dimension(:), allocatable, public grid_ufz
face coordinate [m]: z, local=global
integer, public ka
of whole cells: z, local, with HALO
real(rp), dimension(:), allocatable, public grid_fbfxg
face buffer factor (0-1): x, global
real(rp), dimension(:), allocatable, public grid_fdyg
center coordinate [m]: y, global
subroutine fileio_write_2d(var, basename, title, varname, desc, unit, axistype, datatype, date, subsec, append, nohalo, nozcoord)
Write 2D data to file.
integer, public kmax
of computational cells: z, local
real(rp), dimension(:), allocatable, public grid_fz
face coordinate [m]: z, local=global
real(rp), dimension(:), allocatable, public grid_fbfz
face buffer factor (0-1): z
subroutine fileio_write_3d(var, basename, title, varname, desc, unit, axistype, datatype, date, subsec, append, nohalo)
Write 3D data to file.
subroutine fileio_write_var_3d_t(fid, vid, var, varname, axistype, timeintv, timetarg, nohalo)
Write 3D data with time dimension to file.
subroutine, public fileio_create(fid, basename, title, datatype, date, subsec, append, nozcoord)
Create/open a netCDF file.
integer, public jhalo
of halo cells: y
subroutine fileio_read_var_3d(var, fid, varname, axistype, step)
Read 3D data from file.
integer, public js
start point of inner domain: y, local
integer, public iag
of computational grids
real(rp), dimension(:), allocatable, public grid_cbfx
center buffer factor (0-1): x
real(rp), dimension(:), allocatable, public grid_fbfyg
face buffer factor (0-1): y, global
real(rp), dimension(:), allocatable, public grid_ucz
center coordinate [m]: z, local=global
subroutine fileio_read_var_2d(var, fid, varname, axistype, step)
Read 2D data from file.
integer, parameter, public prc_masterrank
master process in each communicator
integer, public is_ing
start point of the inner domain: cx, global
integer, public ks
start point of inner domain: z, local
real(rp), dimension(:), allocatable, public grid_cbfz
center buffer factor (0-1): z
integer, parameter, public khalo
of halo cells: z
integer, public prc_myrank
process num in local communicator
real(rp), dimension(:), allocatable, public grid_cx
center coordinate [m]: x, local
subroutine, public fileio_enddef(fid)
Exit netCDF file define mode.
subroutine, public prof_rapstart(rapname_base, level)
Start raptime.
subroutine, public fileio_cleanup
deallocate buffers
integer, public isga
start point of the full domain: cx, global
integer, public ie
end point of inner domain: x, local
real(rp), public const_eps
small number
real(rp), dimension(:), allocatable, public grid_lcdz
z-length of control volume [m]
character(len=h_mid), public h_institute
for file header
logical, public io_aggregate
do parallel I/O through PnetCDF
real(rp), dimension(:), allocatable, public grid_fdxg
center coordinate [m]: x, global
subroutine fileio_check_coordinates_name(basename, atmos, land, urban, transpose)
check coordinates in the file
subroutine, public fileio_open(fid, basename)
open a netCDF file for read
integer, dimension(:,:), allocatable, public prc_2drank
node index in 2D topology
real(rp), dimension(:), allocatable, public grid_cdz
z-length of control volume [m]
subroutine, public fileio_def_var(fid, vid, varname, desc, unit, axistype, datatype, timeintv, nsteps)
Define a variable to file.
real(rp), dimension(:), allocatable, public grid_fdx
x-length of grid(i+1) to grid(i) [m]
real(rp), dimension(:), allocatable, public grid_lcz
center coordinate [m]: z, local=global
real(rp), dimension(:), allocatable, public grid_cdy
y-length of control volume [m]
integer, public js_ing
start point of the inner domain: cy, global
real(rp), dimension(:), allocatable, public grid_cbfy
center buffer factor (0-1): y
integer, dimension(6), public time_nowdate
current time [YYYY MM DD HH MM SS]
subroutine, public fileio_close(fid)
Close a netCDF file.
subroutine, public fileio_set_coordinates(LON, LONX, LONY, LONXY, LAT, LATX, LATY, LATXY, CZ, FZ)
set latlon and z
integer, public io_fid_conf
Config file ID.
integer, public io_fid_log
Log file ID.
subroutine free_derived_datatype
free MPI derived datatypes
subroutine, public prof_rapend(rapname_base, level)
Save raptime.
integer, parameter, public rp
real(rp), dimension(:), allocatable, public grid_cdx
x-length of control volume [m]
integer, public jmax
of computational cells: y, local
subroutine fileio_write_var_2d(fid, vid, var, varname, axistype, nohalo)
Write 2D data to file.
integer, public io_fid_nml
Log file ID (only for output namelist)
real(rp), dimension(:), allocatable, public grid_fyg
face coordinate [m]: y, global
real(rp), dimension(:), allocatable, public grid_cy
center coordinate [m]: y, local
subroutine fileio_read_2d(var, basename, varname, axistype, step)
Read 2D data from file.
real(rp), dimension(:), allocatable, public grid_cbfxg
center buffer factor (0-1): x, global
subroutine fileio_read_3d(var, basename, varname, axistype, step)
Read 3D data from file.
integer, public ihalo
of halo cells: x
subroutine fileio_write_1d(var, basename, title, varname, desc, unit, axistype, datatype, date, subsec, append)
Write 1D data to file.
integer, public ja
of whole cells: y, local, with HALO
real(rp), dimension(:), allocatable, public grid_fy
face coordinate [m]: y, local