34 public :: externalfilegetglobalattv
37 public :: externalfileread
38 public :: externalfilereadoffset
40 interface externalfilegetglobalattv
44 end interface externalfilegetglobalattv
46 interface externalfileread
53 end interface externalfileread
55 interface externalfilereadoffset
62 end interface externalfilereadoffset
68 integer,
public,
parameter ::
iscale = 1
70 integer,
public,
parameter ::
inicam = 3
71 integer,
public,
parameter ::
igrads = 4
78 private :: externalfilemakefname
79 private :: externaltakedimension
80 private :: convertarrayorder
83 interface convertarrayorder
85 module procedure convertarrayorderwrf2ddp
86 module procedure convertarrayorderwrf3dsp
87 module procedure convertarrayorderwrf3ddp
88 module procedure convertarrayorderwrf4dsp
89 module procedure convertarrayorderwrf4ddp
90 end interface convertarrayorder
113 integer,
intent(out) :: dims(:)
114 integer,
intent(out) :: timelen
115 integer,
intent( in) :: mdlid
116 character(len=*),
intent( in) :: basename
117 integer,
intent( in) :: myrank
118 logical,
intent( in),
optional :: single
121 integer :: ncid, unlimid
122 integer :: dims_org(7)
123 character(len=NF90_MAX_NAME) :: tname
124 character(len=H_LONG) :: fname =
'' 125 logical :: single_ = .false.
131 if (
present(single) )
then 137 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
139 status = nf90_open( trim(fname), nf90_nowrite, ncid )
140 if (status /= nf90_noerr)
call handle_err(status, __line__)
142 status = nf90_inquire( ncid, unlimiteddimid=unlimid )
143 if (status /= nf90_noerr)
call handle_err(status, __line__)
145 status = nf90_inquire_dimension( ncid, unlimid, tname, timelen )
146 if (status /= nf90_noerr)
call handle_err(status, __line__)
148 if( trim(tname)==
'time' .OR. trim(tname)==
'Time' )
then 149 if(
io_l )
write(
io_fid_log,*)
'Time Dimension Name: '//trim(tname)
151 write(*,*)
'xxx Not appropriate time dimension is used in the external file. Check!' 155 call externaltakedimension( dims_org(:),ncid,mdlid )
159 dims(1) = dims_org(3)
160 dims(2) = dims_org(1)
161 dims(3) = dims_org(2)
162 dims(4) = dims_org(6)
163 dims(5) = dims_org(4)
164 dims(6) = dims_org(5)
165 dims(7) = dims_org(7)
167 dims(:) = dims_org(:)
170 status = nf90_close(ncid)
171 if (status /= nf90_noerr)
call handle_err(status, __line__)
190 integer,
intent(out) :: var(:)
191 integer,
intent( in) :: mdlid
192 character(len=*),
intent( in) :: basename
193 character(len=*),
intent( in) :: attname
194 integer,
intent( in) :: myrank
195 logical,
intent( in),
optional :: single
197 integer,
allocatable :: work(:)
200 integer :: i, ncid, length
201 character(len=H_LONG) :: fname =
'' 202 logical :: single_ = .false.
208 if (
present(single) )
then 214 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
216 status = nf90_open( trim(fname), nf90_nowrite, ncid )
217 if (status /= nf90_noerr)
call handle_err(status, __line__)
219 status = nf90_inquire_attribute(ncid, nf90_global, trim(attname), len=length)
220 if (status /= nf90_noerr)
call handle_err(status, __line__)
222 allocate( work(length) )
224 status = nf90_get_att(ncid, nf90_global, trim(attname), work)
225 if (status /= nf90_noerr)
call handle_err(status, __line__)
231 status = nf90_close(ncid)
232 if (status /= nf90_noerr)
call handle_err(status, __line__)
252 real(SP),
intent(out) :: var(:)
253 integer,
intent( in) :: mdlid
254 character(len=*),
intent( in) :: basename
255 character(len=*),
intent( in) :: attname
256 integer,
intent( in) :: myrank
257 logical,
intent( in),
optional :: single
259 real(SP),
allocatable :: work(:)
262 integer :: i, ncid, length
263 character(len=H_LONG) :: fname =
'' 264 logical :: single_ = .false.
270 if (
present(single) )
then 276 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
278 status = nf90_open( trim(fname), nf90_nowrite, ncid )
279 if (status /= nf90_noerr)
call handle_err(status, __line__)
281 status = nf90_inquire_attribute(ncid, nf90_global, trim(attname), len=length)
282 if (status /= nf90_noerr)
call handle_err(status, __line__)
284 allocate( work(length) )
286 status = nf90_get_att(ncid, nf90_global, trim(attname), work)
287 if (status /= nf90_noerr)
call handle_err(status, __line__)
293 status = nf90_close(ncid)
294 if (status /= nf90_noerr)
call handle_err(status, __line__)
314 real(DP),
intent(out) :: var(:)
315 integer,
intent( in) :: mdlid
316 character(len=*),
intent( in) :: basename
317 character(len=*),
intent( in) :: attname
318 integer,
intent( in) :: myrank
319 logical,
intent( in),
optional :: single
321 real(DP),
allocatable :: work(:)
324 integer :: i, ncid, length
325 character(len=H_LONG) :: fname =
'' 326 logical :: single_ = .false.
332 if (
present(single) )
then 338 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
340 status = nf90_open( trim(fname), nf90_nowrite, ncid )
341 if (status /= nf90_noerr)
call handle_err(status, __line__)
343 status = nf90_inquire_attribute(ncid, nf90_global, trim(attname), len=length)
344 if (status /= nf90_noerr)
call handle_err(status, __line__)
346 allocate( work(length) )
348 status = nf90_get_att(ncid, nf90_global, trim(attname), work)
349 if (status /= nf90_noerr)
call handle_err(status, __line__)
355 status = nf90_close(ncid)
356 if (status /= nf90_noerr)
call handle_err(status, __line__)
376 character(len=*),
intent(out) :: chr(:)
377 integer,
intent( in) :: mdlid
378 character(len=*),
intent( in) :: basename
379 character(len=*),
intent( in) :: attname
380 integer,
intent( in) :: myrank
381 logical,
intent( in),
optional :: single
384 integer :: ncid, length
385 character(len=H_LONG) :: fname =
'' 386 character(len=80) :: work
387 logical :: single_ = .false.
393 if (
present(single) )
then 399 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
401 status = nf90_open( trim(fname), nf90_nowrite, ncid )
402 if (status /= nf90_noerr)
call handle_err(status, __line__)
404 status = nf90_inquire_attribute(ncid, nf90_global, trim(attname), len=length)
405 if (status /= nf90_noerr)
call handle_err(status, __line__)
407 if( len(work) < length )
then 408 write(*,*)
'xxx Not enough space to put attribute values. [externalio/scalelib]' 412 status = nf90_get_att(ncid, nf90_global, trim(attname), work)
413 if (status /= nf90_noerr)
call handle_err(status, __line__)
434 logical,
intent(out) :: existence
435 character(len=*),
intent( in) :: basename
436 character(len=*),
intent( in) :: varname
437 integer,
intent( in) :: myrank
438 integer,
intent( in) :: mdlid
439 logical,
intent( in),
optional :: single
441 integer :: ncid, varid
444 character(len=H_LONG) :: fname =
'' 445 logical :: single_ = .false.
451 if (
present(single) )
then 457 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
459 status = nf90_open( trim(fname), nf90_nowrite, ncid )
460 if (status /= nf90_noerr)
call handle_err(status, __line__)
462 status = nf90_inq_varid( ncid, trim(varname), varid )
463 if (status == nf90_noerr)
then 467 if(
io_l )
write(
io_fid_log,*)
'+++ not exist variable: ', trim(varname)
470 status = nf90_close(ncid)
471 if (status /= nf90_noerr)
call handle_err(status, __line__)
493 real(SP),
intent(out) :: var(:,:)
494 character(len=*),
intent( in) :: basename
495 character(len=*),
intent( in) :: varname
496 integer,
intent( in) :: ts
497 integer,
intent( in) :: te
498 integer,
intent( in) :: myrank
499 integer,
intent( in) :: mdlid
500 integer,
intent( in) :: nx
501 logical,
intent( in),
optional :: single
503 real(SP),
allocatable :: var_org(:,:)
504 integer :: ncid, varid
509 character(len=H_LONG) :: fname =
'' 510 logical :: single_ = .false.
518 if (
present(single) )
then 524 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
526 status = nf90_open( trim(fname), nf90_nowrite, ncid )
527 if (status /= nf90_noerr)
call handle_err(status, __line__)
530 allocate( var_org(nx,tcount) )
532 status = nf90_inq_varid( ncid, trim(varname), varid )
533 if (status /= nf90_noerr)
call handle_err(status, __line__)
535 status = nf90_inquire_variable( ncid, varid, xtype=precis )
536 if(status /= nf90_noerr)
call handle_err(status, __line__)
537 if(precis /= nf90_float)
then 538 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead2DSP]' 542 status = nf90_get_var( ncid, varid, var_org(:,:), start = (/ 1,ts /), &
543 count = (/ nx,tcount /) )
544 if (status /= nf90_noerr)
call handle_err(status, __line__)
546 status = nf90_close(ncid)
547 if (status /= nf90_noerr)
call handle_err(status, __line__)
549 call convertarrayorder( var,var_org,tcount,nx )
551 deallocate( var_org )
569 real(DP),
intent(out) :: var(:,:)
570 character(len=*),
intent( in) :: basename
571 character(len=*),
intent( in) :: varname
572 integer,
intent( in) :: ts
573 integer,
intent( in) :: te
574 integer,
intent( in) :: myrank
575 integer,
intent( in) :: mdlid
576 integer,
intent( in) :: nx
577 logical,
intent( in),
optional :: single
579 real(DP),
allocatable :: var_org(:,:)
580 integer :: ncid, varid
585 character(len=H_LONG) :: fname =
'' 586 logical :: single_ = .false.
594 if (
present(single) )
then 600 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
602 status = nf90_open( trim(fname), nf90_nowrite, ncid )
603 if (status /= nf90_noerr)
call handle_err(status, __line__)
606 allocate( var_org(nx,tcount) )
608 status = nf90_inq_varid( ncid, trim(varname), varid )
609 if (status /= nf90_noerr)
call handle_err(status, __line__)
611 status = nf90_inquire_variable( ncid, varid, xtype=precis )
612 if(status /= nf90_noerr)
call handle_err(status, __line__)
613 if(precis /= nf90_double)
then 614 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead2DDP]' 618 status = nf90_get_var( ncid, varid, var_org(:,:), start = (/ 1,ts /), &
619 count = (/ nx,tcount /) )
620 if (status /= nf90_noerr)
call handle_err(status, __line__)
622 status = nf90_close(ncid)
623 if (status /= nf90_noerr)
call handle_err(status, __line__)
625 call convertarrayorder( var,var_org,tcount,nx )
627 deallocate( var_org )
647 real(SP),
intent(out) :: var(:,:,:)
648 character(len=*),
intent( in) :: basename
649 character(len=*),
intent( in) :: varname
650 integer,
intent( in) :: ts
651 integer,
intent( in) :: te
652 integer,
intent( in) :: myrank
653 integer,
intent( in) :: mdlid
654 logical,
intent( in),
optional :: single
655 logical,
intent( in),
optional :: xstag
656 logical,
intent( in),
optional :: ystag
657 logical,
intent( in),
optional :: option
659 real(SP),
allocatable :: var_org(:,:,:)
660 integer :: ncid, varid
667 character(len=H_LONG) :: fname =
'' 680 if (
present(single) )
then 684 if (
present(option) )
then 688 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
690 status = nf90_open( trim(fname), nf90_nowrite, ncid )
691 if (status /= nf90_noerr)
then 695 call handle_err(status, __line__)
700 call externaltakedimension( dims(:),ncid,mdlid )
702 if (
present(xstag) )
then 708 if (
present(ystag) )
then 713 allocate( var_org(nx,ny,tcount) )
715 status = nf90_inq_varid( ncid, trim(varname), varid )
716 if (status /= nf90_noerr)
call handle_err(status, __line__)
718 status = nf90_inquire_variable( ncid, varid, xtype=precis )
719 if(status /= nf90_noerr)
call handle_err(status, __line__)
720 if(precis /= nf90_float)
then 721 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead3DSP]' 725 status = nf90_get_var( ncid, varid, var_org(:,:,:), start = (/ 1,1,ts /), &
726 count = (/ nx,ny,tcount /) )
727 if (status /= nf90_noerr)
call handle_err(status, __line__)
729 status = nf90_close(ncid)
730 if (status /= nf90_noerr)
call handle_err(status, __line__)
732 call convertarrayorder( var,var_org,tcount,nx,ny )
734 deallocate( var_org )
753 real(DP),
intent(out) :: var(:,:,:)
754 character(len=*),
intent( in) :: basename
755 character(len=*),
intent( in) :: varname
756 integer,
intent( in) :: ts
757 integer,
intent( in) :: te
758 integer,
intent( in) :: myrank
759 integer,
intent( in) :: mdlid
760 logical,
intent( in),
optional :: single
761 logical,
intent( in),
optional :: xstag
762 logical,
intent( in),
optional :: ystag
764 real(DP),
allocatable :: var_org(:,:,:)
765 integer :: ncid, varid
772 character(len=H_LONG) :: fname =
'' 773 logical :: single_ = .false.
781 if (
present(single) )
then 787 call externalfilemakefname( fname,mdlid,basename,myrank,single )
789 status = nf90_open( trim(fname), nf90_nowrite, ncid )
790 if (status /= nf90_noerr)
call handle_err(status, __line__)
793 call externaltakedimension( dims(:),ncid,mdlid )
795 if (
present(xstag) )
then 801 if (
present(ystag) )
then 806 allocate( var_org(nx,ny,tcount) )
808 status = nf90_inq_varid( ncid, trim(varname), varid )
809 if (status /= nf90_noerr)
call handle_err(status, __line__)
811 status = nf90_inquire_variable( ncid, varid, xtype=precis )
812 if(status /= nf90_noerr)
call handle_err(status, __line__)
813 if(precis /= nf90_double)
then 814 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead3DDP]' 818 status = nf90_get_var( ncid, varid, var_org(:,:,:), start = (/ 1,1,ts /), &
819 count = (/ nx,ny,tcount /) )
820 if (status /= nf90_noerr)
call handle_err(status, __line__)
822 status = nf90_close(ncid)
823 if (status /= nf90_noerr)
call handle_err(status, __line__)
825 call convertarrayorder( var,var_org,tcount,nx,ny )
827 deallocate( var_org )
849 real(SP),
intent(out) :: var(:,:,:,:)
850 character(len=*),
intent( in) :: basename
851 character(len=*),
intent( in) :: varname
852 integer,
intent( in) :: ts
853 integer,
intent( in) :: te
854 integer,
intent( in) :: myrank
855 integer,
intent( in) :: mdlid
856 logical,
intent( in),
optional :: single
857 logical,
intent( in),
optional :: xstag
858 logical,
intent( in),
optional :: ystag
859 logical,
intent( in),
optional :: zstag
860 logical,
intent( in),
optional :: landgrid
861 logical,
intent( in),
optional :: option
863 real(SP),
allocatable :: var_org(:,:,:,:)
864 integer :: ncid, varid
867 integer :: nx, ny, nz
871 character(len=H_LONG) :: fname =
'' 884 if (
present(single) )
then 888 if (
present(option) )
then 892 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
894 status = nf90_open( trim(fname), nf90_nowrite, ncid )
895 if (status /= nf90_noerr)
then 899 write(*,*) trim(fname)
900 call handle_err(status, __line__)
905 call externaltakedimension( dims(:),ncid,mdlid )
907 if (
present(xstag) )
then 913 if (
present(ystag) )
then 919 if (
present(zstag) )
then 924 if (
present(landgrid) )
then 929 allocate( var_org(nx,ny,nz,tcount) )
931 status = nf90_inq_varid( ncid, trim(varname), varid )
932 if (status /= nf90_noerr)
call handle_err(status, __line__)
934 status = nf90_inquire_variable( ncid, varid, xtype=precis )
935 if(status /= nf90_noerr)
call handle_err(status, __line__)
936 if(precis /= nf90_float)
then 937 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead4DSP]' 941 status = nf90_get_var( ncid, varid, var_org(:,:,:,:), start = (/ 1,1,1,ts /), &
942 count = (/ nx,ny,nz,tcount /) )
943 if (status /= nf90_noerr)
call handle_err(status, __line__)
945 status = nf90_close(ncid)
946 if (status /= nf90_noerr)
call handle_err(status, __line__)
948 call convertarrayorder( var,var_org,tcount,nz,nx,ny )
950 deallocate( var_org )
971 real(DP),
intent(out) :: var(:,:,:,:)
972 character(len=*),
intent( in) :: basename
973 character(len=*),
intent( in) :: varname
974 integer,
intent( in) :: ts
975 integer,
intent( in) :: te
976 integer,
intent( in) :: myrank
977 integer,
intent( in) :: mdlid
978 logical,
intent( in),
optional :: single
979 logical,
intent( in),
optional :: xstag
980 logical,
intent( in),
optional :: ystag
981 logical,
intent( in),
optional :: zstag
982 logical,
intent( in),
optional :: landgrid
984 real(DP),
allocatable :: var_org(:,:,:,:)
985 integer :: ncid, varid
988 integer :: nx, ny, nz
992 character(len=H_LONG) :: fname =
'' 993 logical :: single_ = .false.
1001 if (
present(single) )
then 1007 call externalfilemakefname( fname,mdlid,basename,myrank,single )
1009 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1010 if (status /= nf90_noerr)
call handle_err(status, __line__)
1013 call externaltakedimension( dims(:),ncid,mdlid )
1015 if (
present(xstag) )
then 1021 if (
present(ystag) )
then 1027 if (
present(zstag) )
then 1032 if (
present(landgrid) )
then 1033 if ( landgrid )
then 1037 allocate( var_org(nx,ny,nz,tcount) )
1039 status = nf90_inq_varid( ncid, trim(varname), varid )
1040 if (status /= nf90_noerr)
call handle_err(status, __line__)
1042 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1043 if(status /= nf90_noerr)
call handle_err(status, __line__)
1044 if(precis /= nf90_double)
then 1045 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead4DDP]' 1049 status = nf90_get_var( ncid, varid, var_org(:,:,:,:), start = (/ 1,1,1,ts /), &
1050 count = (/ nx,ny,nz,tcount /) )
1051 if (status /= nf90_noerr)
call handle_err(status, __line__)
1053 status = nf90_close(ncid)
1054 if (status /= nf90_noerr)
call handle_err(status, __line__)
1056 call convertarrayorder( var,var_org,tcount,nz,nx,ny )
1058 deallocate( var_org )
1078 real(SP),
intent(out) :: var(:,:,:)
1079 character(len=*),
intent( in) :: basename
1080 character(len=*),
intent( in) :: varname
1081 integer,
intent( in) :: ts
1082 integer,
intent( in) :: te
1083 integer,
intent( in) :: myrank
1084 integer,
intent( in) :: mdlid
1085 logical,
intent( in),
optional :: single
1086 logical,
intent( in),
optional :: xstag
1087 logical,
intent( in),
optional :: ystag
1089 real(SP),
allocatable :: var_org(:,:,:)
1090 integer(2),
allocatable :: short(:,:,:)
1092 real(4) :: scale_factor, add_offset
1094 integer :: ncid, varid
1101 character(len=H_LONG) :: fname =
'' 1102 logical :: single_ = .false.
1108 tcount = te - ts + 1
1110 if (
present(single) )
then 1116 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
1118 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1119 if (status /= nf90_noerr)
call handle_err(status, __line__)
1122 call externaltakedimension( dims(:),ncid,mdlid )
1124 if (
present(xstag) )
then 1130 if (
present(ystag) )
then 1135 allocate( var_org(nx,ny,tcount) )
1136 allocate( short(nx,ny,tcount) )
1138 status = nf90_inq_varid( ncid, trim(varname), varid )
1139 if (status /= nf90_noerr)
call handle_err(status, __line__)
1141 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1142 if(status /= nf90_noerr)
call handle_err(status, __line__)
1144 if(precis /= nf90_short)
then 1145 status = nf90_get_var( ncid, varid, var_org(:,:,:), start = (/ 1,1,ts /), &
1146 count = (/ nx,ny,tcount /) )
1147 if (status /= nf90_noerr)
call handle_err(status, __line__)
1149 status = nf90_get_att(ncid, varid,
"scale_factor", scale_factor)
1150 if (status /= nf90_noerr)
call handle_err(status, __line__)
1152 status = nf90_get_att(ncid, varid,
"add_offset", add_offset)
1153 if (status /= nf90_noerr)
call handle_err(status, __line__)
1155 status = nf90_get_var( ncid, varid, short(:,:,:), start = (/ 1,1,ts /), &
1156 count = (/ nx,ny,tcount /) )
1157 if (status /= nf90_noerr)
call handle_err(status, __line__)
1159 var_org(:,:,:) =
real( short(:,:,:),kind=
sp )*scale_factor + add_offset
1162 status = nf90_close(ncid)
1163 if (status /= nf90_noerr)
call handle_err(status, __line__)
1165 call convertarrayorder( var,var_org,tcount,nx,ny )
1167 deallocate( var_org )
1187 real(DP),
intent(out) :: var(:,:,:)
1188 character(len=*),
intent( in) :: basename
1189 character(len=*),
intent( in) :: varname
1190 integer,
intent( in) :: ts
1191 integer,
intent( in) :: te
1192 integer,
intent( in) :: myrank
1193 integer,
intent( in) :: mdlid
1194 logical,
intent( in),
optional :: single
1195 logical,
intent( in),
optional :: xstag
1196 logical,
intent( in),
optional :: ystag
1198 real(DP),
allocatable :: var_org(:,:,:)
1199 integer(2),
allocatable :: short(:,:,:)
1201 real(4) :: scale_factor, add_offset
1203 integer :: ncid, varid
1210 character(len=H_LONG) :: fname =
'' 1211 logical :: single_ = .false.
1217 tcount = te - ts + 1
1219 if (
present(single) )
then 1225 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
1227 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1228 if (status /= nf90_noerr)
call handle_err(status, __line__)
1231 call externaltakedimension( dims(:),ncid,mdlid )
1233 if (
present(xstag) )
then 1239 if (
present(ystag) )
then 1244 allocate( var_org(nx,ny,tcount) )
1245 allocate( short(nx,ny,tcount) )
1247 status = nf90_inq_varid( ncid, trim(varname), varid )
1248 if (status /= nf90_noerr)
call handle_err(status, __line__)
1250 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1251 if(status /= nf90_noerr)
call handle_err(status, __line__)
1253 if(precis /= nf90_short)
then 1254 status = nf90_get_var( ncid, varid, var_org(:,:,:), start = (/ 1,1,ts /), &
1255 count = (/ nx,ny,tcount /) )
1256 if (status /= nf90_noerr)
call handle_err(status, __line__)
1258 status = nf90_get_att(ncid, varid,
"scale_factor", scale_factor)
1259 if (status /= nf90_noerr)
call handle_err(status, __line__)
1261 status = nf90_get_att(ncid, varid,
"add_offset", add_offset)
1262 if (status /= nf90_noerr)
call handle_err(status, __line__)
1264 status = nf90_get_var( ncid, varid, short(:,:,:), start = (/ 1,1,ts /), &
1265 count = (/ nx,ny,tcount /) )
1266 if (status /= nf90_noerr)
call handle_err(status, __line__)
1268 var_org(:,:,:) =
real( real(short(:,:,:),kind=
sp)*scale_factor + add_offset, kind=
dp )
1271 status = nf90_close(ncid)
1272 if (status /= nf90_noerr)
call handle_err(status, __line__)
1274 call convertarrayorder( var,var_org,tcount,nx,ny )
1276 deallocate( var_org )
1298 real(SP),
intent(out) :: var(:,:,:,:)
1299 character(len=*),
intent( in) :: basename
1300 character(len=*),
intent( in) :: varname
1301 integer,
intent( in) :: ts
1302 integer,
intent( in) :: te
1303 integer,
intent( in) :: myrank
1304 integer,
intent( in) :: mdlid
1305 logical,
intent( in),
optional :: single
1306 logical,
intent( in),
optional :: xstag
1307 logical,
intent( in),
optional :: ystag
1308 logical,
intent( in),
optional :: zstag
1309 logical,
intent( in),
optional :: landgrid
1311 real(SP),
allocatable :: var_org(:,:,:,:)
1312 integer(2),
allocatable :: short(:,:,:,:)
1314 real(4) :: scale_factor, add_offset
1316 integer :: ncid, varid
1319 integer :: nx, ny, nz
1323 character(len=H_LONG) :: fname =
'' 1324 logical :: single_ = .false.
1330 tcount = te - ts + 1
1332 if (
present(single) )
then 1338 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
1340 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1341 if (status /= nf90_noerr)
call handle_err(status, __line__)
1344 call externaltakedimension( dims(:),ncid,mdlid )
1346 if (
present(xstag) )
then 1352 if (
present(ystag) )
then 1358 if (
present(zstag) )
then 1363 if (
present(landgrid) )
then 1364 if ( landgrid )
then 1368 allocate( var_org(nx,ny,nz,tcount) )
1369 allocate( short(nx,ny,nz,tcount) )
1371 status = nf90_inq_varid( ncid, trim(varname), varid )
1372 if (status /= nf90_noerr)
call handle_err(status, __line__)
1374 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1375 if (status /= nf90_noerr)
call handle_err(status, __line__)
1377 if(precis /= nf90_short)
then 1378 status = nf90_get_var( ncid, varid, var_org(:,:,:,:), start = (/ 1,1,1,ts /), &
1379 count = (/ nx,ny,nz,tcount /) )
1380 if (status /= nf90_noerr)
call handle_err(status, __line__)
1382 status = nf90_get_att(ncid, varid,
"scale_factor", scale_factor)
1383 if (status /= nf90_noerr)
call handle_err(status, __line__)
1385 status = nf90_get_att(ncid, varid,
"add_offset", add_offset)
1386 if (status /= nf90_noerr)
call handle_err(status, __line__)
1388 status = nf90_get_var( ncid, varid, short(:,:,:,:), start = (/ 1,1,1,ts /), &
1389 count = (/ nx,ny,nz,tcount /) )
1390 if (status /= nf90_noerr)
call handle_err(status, __line__)
1392 var_org(:,:,:,:) =
real( short(:,:,:,:),kind=
sp )*scale_factor + add_offset
1395 status = nf90_close(ncid)
1396 if (status /= nf90_noerr)
call handle_err(status, __line__)
1398 call convertarrayorder( var,var_org,tcount,nz,nx,ny )
1400 deallocate( var_org )
1422 real(DP),
intent(out) :: var(:,:,:,:)
1423 character(len=*),
intent( in) :: basename
1424 character(len=*),
intent( in) :: varname
1425 integer,
intent( in) :: ts
1426 integer,
intent( in) :: te
1427 integer,
intent( in) :: myrank
1428 integer,
intent( in) :: mdlid
1429 logical,
intent( in),
optional :: single
1430 logical,
intent( in),
optional :: xstag
1431 logical,
intent( in),
optional :: ystag
1432 logical,
intent( in),
optional :: zstag
1433 logical,
intent( in),
optional :: landgrid
1435 real(DP),
allocatable :: var_org(:,:,:,:)
1436 integer(2),
allocatable :: short(:,:,:,:)
1438 real(4) :: scale_factor, add_offset
1440 integer :: ncid, varid
1443 integer :: nx, ny, nz
1447 character(len=H_LONG) :: fname =
'' 1448 logical :: single_ = .false.
1454 tcount = te - ts + 1
1456 if (
present(single) )
then 1462 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
1464 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1465 if (status /= nf90_noerr)
call handle_err(status, __line__)
1468 call externaltakedimension( dims(:),ncid,mdlid )
1470 if (
present(xstag) )
then 1476 if (
present(ystag) )
then 1482 if (
present(zstag) )
then 1487 if (
present(landgrid) )
then 1488 if ( landgrid )
then 1492 allocate( var_org(nx,ny,nz,tcount) )
1493 allocate( short(nx,ny,nz,tcount) )
1495 status = nf90_inq_varid( ncid, trim(varname), varid )
1496 if (status /= nf90_noerr)
call handle_err(status, __line__)
1498 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1499 if(status /= nf90_noerr)
call handle_err(status, __line__)
1501 if(precis /= nf90_short)
then 1502 status = nf90_get_var( ncid, varid, var_org(:,:,:,:), start = (/ 1,1,1,ts /), &
1503 count = (/ nx,ny,nz,tcount /) )
1504 if (status /= nf90_noerr)
call handle_err(status, __line__)
1506 status = nf90_get_att(ncid, varid,
"scale_factor", scale_factor)
1507 if (status /= nf90_noerr)
call handle_err(status, __line__)
1509 status = nf90_get_att(ncid, varid,
"add_offset", add_offset)
1510 if (status /= nf90_noerr)
call handle_err(status, __line__)
1512 status = nf90_get_var( ncid, varid, short(:,:,:,:), start = (/ 1,1,1,ts /), &
1513 count = (/ nx,ny,nz,tcount /) )
1514 if (status /= nf90_noerr)
call handle_err(status, __line__)
1516 var_org(:,:,:,:) =
real( real(short(:,:,:,:),kind=
sp)*scale_factor + add_offset, kind=
dp )
1519 status = nf90_close(ncid)
1520 if (status /= nf90_noerr)
call handle_err(status, __line__)
1522 call convertarrayorder( var,var_org,tcount,nz,nx,ny )
1524 deallocate( var_org )
1533 subroutine externalfilemakefname( &
1542 character(len=*),
intent(out) :: fname
1543 integer,
intent( in) :: mdlid
1544 character(len=*),
intent( in) :: basename
1545 integer,
intent( in) :: myrank
1546 logical,
intent( in) :: single
1554 fname = trim(basename)
1558 elseif( mdlid ==
inicam )
then 1560 fname = trim(basename)//
'.peall.nc' 1571 write(*,*)
'xxx failed, wrong filetype: [scale_external_io]/[ExternalFileMakeFName]' 1576 end subroutine externalfilemakefname
1581 subroutine externaltakedimension( &
1589 integer,
intent(out) :: dims(:)
1590 integer,
intent( in) :: ncid
1591 integer,
intent( in) :: mdlid
1601 status = nf90_inq_dimid( ncid,
"west_east", dimid )
1602 status = nf90_inquire_dimension( ncid, dimid,len=dims(1) )
1603 status = nf90_inq_dimid( ncid,
"south_north", dimid )
1604 status = nf90_inquire_dimension( ncid, dimid,len=dims(2) )
1605 status = nf90_inq_dimid( ncid,
"bottom_top", dimid )
1606 status = nf90_inquire_dimension( ncid, dimid,len=dims(3) )
1607 status = nf90_inq_dimid( ncid,
"west_east_stag", dimid )
1608 status = nf90_inquire_dimension( ncid, dimid,len=dims(4) )
1609 status = nf90_inq_dimid( ncid,
"south_north_stag", dimid )
1610 status = nf90_inquire_dimension( ncid, dimid,len=dims(5) )
1611 status = nf90_inq_dimid( ncid,
"bottom_top_stag", dimid )
1612 status = nf90_inquire_dimension( ncid, dimid,len=dims(6) )
1613 status = nf90_inq_dimid( ncid,
"soil_layers_stag", dimid )
1614 status = nf90_inquire_dimension( ncid, dimid,len=dims(7) )
1616 elseif( mdlid ==
inicam )
then 1617 status = nf90_inq_dimid( ncid,
"lon", dimid )
1618 status = nf90_inquire_dimension( ncid, dimid,len=dims(1) )
1619 status = nf90_inq_dimid( ncid,
"lat", dimid )
1620 status = nf90_inquire_dimension( ncid, dimid,len=dims(2) )
1621 status = nf90_inq_dimid( ncid,
"lev", dimid )
1622 status = nf90_inquire_dimension( ncid, dimid,len=dims(3) )
1625 write(*,*)
'xxx This external file format is not supported, Sorry.' 1630 end subroutine externaltakedimension
1641 real(SP),
intent(out) :: var(:,:)
1642 real(SP),
intent( in) :: var_org(:,:)
1643 integer,
intent( in) :: tcount
1644 integer,
intent( in) :: nx
1650 var(i,n) = var_org(i,n)
1656 subroutine convertarrayorderwrf2ddp( &
1664 real(DP),
intent(out) :: var(:,:)
1665 real(DP),
intent( in) :: var_org(:,:)
1666 integer,
intent( in) :: tcount
1667 integer,
intent( in) :: nx
1673 var(i,n) = var_org(i,n)
1678 end subroutine convertarrayorderwrf2ddp
1679 subroutine convertarrayorderwrf3dsp( &
1688 real(SP),
intent(out) :: var(:,:,:)
1689 real(SP),
intent( in) :: var_org(:,:,:)
1690 integer,
intent( in) :: tcount
1691 integer,
intent( in) :: nx
1692 integer,
intent( in) :: ny
1699 var(i,j,n) = var_org(i,j,n)
1705 end subroutine convertarrayorderwrf3dsp
1706 subroutine convertarrayorderwrf3ddp( &
1715 real(DP),
intent(out) :: var(:,:,:)
1716 real(DP),
intent( in) :: var_org(:,:,:)
1717 integer,
intent( in) :: tcount
1718 integer,
intent( in) :: nx
1719 integer,
intent( in) :: ny
1726 var(i,j,n) = var_org(i,j,n)
1732 end subroutine convertarrayorderwrf3ddp
1733 subroutine convertarrayorderwrf4dsp( &
1743 real(SP),
intent(out) :: var(:,:,:,:)
1744 real(SP),
intent( in) :: var_org(:,:,:,:)
1745 integer,
intent( in) :: tcount
1746 integer,
intent( in) :: nz
1747 integer,
intent( in) :: nx
1748 integer,
intent( in) :: ny
1749 integer :: n, k, i, j
1756 var(k,i,j,n) = var_org(i,j,k,n)
1763 end subroutine convertarrayorderwrf4dsp
1764 subroutine convertarrayorderwrf4ddp( &
1774 real(DP),
intent(out) :: var(:,:,:,:)
1775 real(DP),
intent( in) :: var_org(:,:,:,:)
1776 integer,
intent( in) :: tcount
1777 integer,
intent( in) :: nz
1778 integer,
intent( in) :: nx
1779 integer,
intent( in) :: ny
1780 integer :: n, k, i, j
1787 var(k,i,j,n) = var_org(i,j,k,n)
1794 end subroutine convertarrayorderwrf4ddp
1797 subroutine handle_err(status, line)
1802 integer,
intent(in) :: status
1803 integer,
intent(in) :: line
1805 write(*,*)
'xxx Error in scale_external_io.f90 at line', line
1806 write(*,*) nf90_strerror(status)
1810 end subroutine handle_err
subroutine externalfileread2drealdp(var, basename, varname, ts, te, myrank, mdlid, nx, single)
subroutine, public externalfilevarexistence(existence, basename, varname, myrank, mdlid, single)
Check Existence of a Variable.
subroutine, public prc_mpistop
Abort MPI.
integer, parameter, public inicam
logical, public io_l
output log or not? (this process)
subroutine convertarrayorderwrf2dsp(var, var_org, tcount, nx)
integer, parameter, public igrads
integer, parameter, public iwrfarw
integer, parameter, public iscale
subroutine externalfileread3drealdp(var, basename, varname, ts, te, myrank, mdlid, single, xstag, ystag)
subroutine externalfileread2drealsp(var, basename, varname, ts, te, myrank, mdlid, nx, single)
File Read.
subroutine externalfileread4drealdp(var, basename, varname, ts, te, myrank, mdlid, single, xstag, ystag, zstag, landgrid)
subroutine externalfilereadoffset3drealdp(var, basename, varname, ts, te, myrank, mdlid, single, xstag, ystag)
subroutine, public externalfilegetshape(dims, timelen, mdlid, basename, myrank, single)
subroutine externalfilegetglobalattvrealsp(var, mdlid, basename, attname, myrank, single)
subroutine, public externalfilegetglobalattc(chr, mdlid, basename, attname, myrank, single)
subroutine externalfileread4drealsp(var, basename, varname, ts, te, myrank, mdlid, single, xstag, ystag, zstag, landgrid, option)
subroutine externalfilereadoffset3drealsp(var, basename, varname, ts, te, myrank, mdlid, single, xstag, ystag)
subroutine externalfilereadoffset4drealsp(var, basename, varname, ts, te, myrank, mdlid, single, xstag, ystag, zstag, landgrid)
integer, parameter, public sp
integer, public io_fid_log
Log file ID.
subroutine externalfileread3drealsp(var, basename, varname, ts, te, myrank, mdlid, single, xstag, ystag, option)
subroutine externalfilereadoffset4drealdp(var, basename, varname, ts, te, myrank, mdlid, single, xstag, ystag, zstag, landgrid)
subroutine externalfilegetglobalattvrealdp(var, mdlid, basename, attname, myrank, single)
integer, parameter, public dp
subroutine externalfilegetglobalattvinteger(var, mdlid, basename, attname, myrank, single)