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 =
'' 668 logical :: single_ = .false.
669 logical :: option_ = .false.
677 if (
present(single) )
then 681 if (
present(option) )
then 685 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
687 status = nf90_open( trim(fname), nf90_nowrite, ncid )
688 if (status /= nf90_noerr)
then 692 call handle_err(status, __line__)
697 call externaltakedimension( dims(:),ncid,mdlid )
699 if (
present(xstag) )
then 705 if (
present(ystag) )
then 710 allocate( var_org(nx,ny,tcount) )
712 status = nf90_inq_varid( ncid, trim(varname), varid )
713 if (status /= nf90_noerr)
call handle_err(status, __line__)
715 status = nf90_inquire_variable( ncid, varid, xtype=precis )
716 if(status /= nf90_noerr)
call handle_err(status, __line__)
717 if(precis /= nf90_float)
then 718 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead3DSP]' 722 status = nf90_get_var( ncid, varid, var_org(:,:,:), start = (/ 1,1,ts /), &
723 count = (/ nx,ny,tcount /) )
724 if (status /= nf90_noerr)
call handle_err(status, __line__)
726 status = nf90_close(ncid)
727 if (status /= nf90_noerr)
call handle_err(status, __line__)
729 call convertarrayorder( var,var_org,tcount,nx,ny )
731 deallocate( var_org )
750 real(DP),
intent(out) :: var(:,:,:)
751 character(len=*),
intent( in) :: basename
752 character(len=*),
intent( in) :: varname
753 integer,
intent( in) :: ts
754 integer,
intent( in) :: te
755 integer,
intent( in) :: myrank
756 integer,
intent( in) :: mdlid
757 logical,
intent( in),
optional :: single
758 logical,
intent( in),
optional :: xstag
759 logical,
intent( in),
optional :: ystag
761 real(DP),
allocatable :: var_org(:,:,:)
762 integer :: ncid, varid
769 character(len=H_LONG) :: fname =
'' 770 logical :: single_ = .false.
778 if (
present(single) )
then 784 call externalfilemakefname( fname,mdlid,basename,myrank,single )
786 status = nf90_open( trim(fname), nf90_nowrite, ncid )
787 if (status /= nf90_noerr)
call handle_err(status, __line__)
790 call externaltakedimension( dims(:),ncid,mdlid )
792 if (
present(xstag) )
then 798 if (
present(ystag) )
then 803 allocate( var_org(nx,ny,tcount) )
805 status = nf90_inq_varid( ncid, trim(varname), varid )
806 if (status /= nf90_noerr)
call handle_err(status, __line__)
808 status = nf90_inquire_variable( ncid, varid, xtype=precis )
809 if(status /= nf90_noerr)
call handle_err(status, __line__)
810 if(precis /= nf90_double)
then 811 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead3DDP]' 815 status = nf90_get_var( ncid, varid, var_org(:,:,:), start = (/ 1,1,ts /), &
816 count = (/ nx,ny,tcount /) )
817 if (status /= nf90_noerr)
call handle_err(status, __line__)
819 status = nf90_close(ncid)
820 if (status /= nf90_noerr)
call handle_err(status, __line__)
822 call convertarrayorder( var,var_org,tcount,nx,ny )
824 deallocate( var_org )
846 real(SP),
intent(out) :: var(:,:,:,:)
847 character(len=*),
intent( in) :: basename
848 character(len=*),
intent( in) :: varname
849 integer,
intent( in) :: ts
850 integer,
intent( in) :: te
851 integer,
intent( in) :: myrank
852 integer,
intent( in) :: mdlid
853 logical,
intent( in),
optional :: single
854 logical,
intent( in),
optional :: xstag
855 logical,
intent( in),
optional :: ystag
856 logical,
intent( in),
optional :: zstag
857 logical,
intent( in),
optional :: landgrid
858 logical,
intent( in),
optional :: option
860 real(SP),
allocatable :: var_org(:,:,:,:)
861 integer :: ncid, varid
864 integer :: nx, ny, nz
868 character(len=H_LONG) :: fname =
'' 869 logical :: single_ = .false.
870 logical :: option_ = .false.
878 if (
present(single) )
then 882 if (
present(option) )
then 886 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
888 status = nf90_open( trim(fname), nf90_nowrite, ncid )
889 if (status /= nf90_noerr)
then 893 write(*,*) trim(fname)
894 call handle_err(status, __line__)
899 call externaltakedimension( dims(:),ncid,mdlid )
901 if (
present(xstag) )
then 907 if (
present(ystag) )
then 913 if (
present(zstag) )
then 918 if (
present(landgrid) )
then 923 allocate( var_org(nx,ny,nz,tcount) )
925 status = nf90_inq_varid( ncid, trim(varname), varid )
926 if (status /= nf90_noerr)
call handle_err(status, __line__)
928 status = nf90_inquire_variable( ncid, varid, xtype=precis )
929 if(status /= nf90_noerr)
call handle_err(status, __line__)
930 if(precis /= nf90_float)
then 931 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead4DSP]' 935 status = nf90_get_var( ncid, varid, var_org(:,:,:,:), start = (/ 1,1,1,ts /), &
936 count = (/ nx,ny,nz,tcount /) )
937 if (status /= nf90_noerr)
call handle_err(status, __line__)
939 status = nf90_close(ncid)
940 if (status /= nf90_noerr)
call handle_err(status, __line__)
942 call convertarrayorder( var,var_org,tcount,nz,nx,ny )
944 deallocate( var_org )
965 real(DP),
intent(out) :: var(:,:,:,:)
966 character(len=*),
intent( in) :: basename
967 character(len=*),
intent( in) :: varname
968 integer,
intent( in) :: ts
969 integer,
intent( in) :: te
970 integer,
intent( in) :: myrank
971 integer,
intent( in) :: mdlid
972 logical,
intent( in),
optional :: single
973 logical,
intent( in),
optional :: xstag
974 logical,
intent( in),
optional :: ystag
975 logical,
intent( in),
optional :: zstag
976 logical,
intent( in),
optional :: landgrid
978 real(DP),
allocatable :: var_org(:,:,:,:)
979 integer :: ncid, varid
982 integer :: nx, ny, nz
986 character(len=H_LONG) :: fname =
'' 987 logical :: single_ = .false.
995 if (
present(single) )
then 1001 call externalfilemakefname( fname,mdlid,basename,myrank,single )
1003 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1004 if (status /= nf90_noerr)
call handle_err(status, __line__)
1007 call externaltakedimension( dims(:),ncid,mdlid )
1009 if (
present(xstag) )
then 1015 if (
present(ystag) )
then 1021 if (
present(zstag) )
then 1026 if (
present(landgrid) )
then 1027 if ( landgrid )
then 1031 allocate( var_org(nx,ny,nz,tcount) )
1033 status = nf90_inq_varid( ncid, trim(varname), varid )
1034 if (status /= nf90_noerr)
call handle_err(status, __line__)
1036 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1037 if(status /= nf90_noerr)
call handle_err(status, __line__)
1038 if(precis /= nf90_double)
then 1039 write(*,*)
'xxx Internal Error: [scale_external_io]/[ExternalFileRead4DDP]' 1043 status = nf90_get_var( ncid, varid, var_org(:,:,:,:), start = (/ 1,1,1,ts /), &
1044 count = (/ nx,ny,nz,tcount /) )
1045 if (status /= nf90_noerr)
call handle_err(status, __line__)
1047 status = nf90_close(ncid)
1048 if (status /= nf90_noerr)
call handle_err(status, __line__)
1050 call convertarrayorder( var,var_org,tcount,nz,nx,ny )
1052 deallocate( var_org )
1072 real(SP),
intent(out) :: var(:,:,:)
1073 character(len=*),
intent( in) :: basename
1074 character(len=*),
intent( in) :: varname
1075 integer,
intent( in) :: ts
1076 integer,
intent( in) :: te
1077 integer,
intent( in) :: myrank
1078 integer,
intent( in) :: mdlid
1079 logical,
intent( in),
optional :: single
1080 logical,
intent( in),
optional :: xstag
1081 logical,
intent( in),
optional :: ystag
1083 real(SP),
allocatable :: var_org(:,:,:)
1084 integer(2),
allocatable :: short(:,:,:)
1086 real(4) :: scale_factor, add_offset
1088 integer :: ncid, varid
1095 character(len=H_LONG) :: fname =
'' 1096 logical :: single_ = .false.
1102 tcount = te - ts + 1
1104 if (
present(single) )
then 1110 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
1112 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1113 if (status /= nf90_noerr)
call handle_err(status, __line__)
1116 call externaltakedimension( dims(:),ncid,mdlid )
1118 if (
present(xstag) )
then 1124 if (
present(ystag) )
then 1129 allocate( var_org(nx,ny,tcount) )
1130 allocate( short(nx,ny,tcount) )
1132 status = nf90_inq_varid( ncid, trim(varname), varid )
1133 if (status /= nf90_noerr)
call handle_err(status, __line__)
1135 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1136 if(status /= nf90_noerr)
call handle_err(status, __line__)
1138 if(precis /= nf90_short)
then 1139 status = nf90_get_var( ncid, varid, var_org(:,:,:), start = (/ 1,1,ts /), &
1140 count = (/ nx,ny,tcount /) )
1141 if (status /= nf90_noerr)
call handle_err(status, __line__)
1143 status = nf90_get_att(ncid, varid,
"scale_factor", scale_factor)
1144 if (status /= nf90_noerr)
call handle_err(status, __line__)
1146 status = nf90_get_att(ncid, varid,
"add_offset", add_offset)
1147 if (status /= nf90_noerr)
call handle_err(status, __line__)
1149 status = nf90_get_var( ncid, varid, short(:,:,:), start = (/ 1,1,ts /), &
1150 count = (/ nx,ny,tcount /) )
1151 if (status /= nf90_noerr)
call handle_err(status, __line__)
1153 var_org(:,:,:) =
real( short(:,:,:),kind=
sp )*scale_factor + add_offset
1156 status = nf90_close(ncid)
1157 if (status /= nf90_noerr)
call handle_err(status, __line__)
1159 call convertarrayorder( var,var_org,tcount,nx,ny )
1161 deallocate( var_org )
1181 real(DP),
intent(out) :: var(:,:,:)
1182 character(len=*),
intent( in) :: basename
1183 character(len=*),
intent( in) :: varname
1184 integer,
intent( in) :: ts
1185 integer,
intent( in) :: te
1186 integer,
intent( in) :: myrank
1187 integer,
intent( in) :: mdlid
1188 logical,
intent( in),
optional :: single
1189 logical,
intent( in),
optional :: xstag
1190 logical,
intent( in),
optional :: ystag
1192 real(DP),
allocatable :: var_org(:,:,:)
1193 integer(2),
allocatable :: short(:,:,:)
1195 real(4) :: scale_factor, add_offset
1197 integer :: ncid, varid
1204 character(len=H_LONG) :: fname =
'' 1205 logical :: single_ = .false.
1211 tcount = te - ts + 1
1213 if (
present(single) )
then 1219 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
1221 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1222 if (status /= nf90_noerr)
call handle_err(status, __line__)
1225 call externaltakedimension( dims(:),ncid,mdlid )
1227 if (
present(xstag) )
then 1233 if (
present(ystag) )
then 1238 allocate( var_org(nx,ny,tcount) )
1239 allocate( short(nx,ny,tcount) )
1241 status = nf90_inq_varid( ncid, trim(varname), varid )
1242 if (status /= nf90_noerr)
call handle_err(status, __line__)
1244 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1245 if(status /= nf90_noerr)
call handle_err(status, __line__)
1247 if(precis /= nf90_short)
then 1248 status = nf90_get_var( ncid, varid, var_org(:,:,:), start = (/ 1,1,ts /), &
1249 count = (/ nx,ny,tcount /) )
1250 if (status /= nf90_noerr)
call handle_err(status, __line__)
1252 status = nf90_get_att(ncid, varid,
"scale_factor", scale_factor)
1253 if (status /= nf90_noerr)
call handle_err(status, __line__)
1255 status = nf90_get_att(ncid, varid,
"add_offset", add_offset)
1256 if (status /= nf90_noerr)
call handle_err(status, __line__)
1258 status = nf90_get_var( ncid, varid, short(:,:,:), start = (/ 1,1,ts /), &
1259 count = (/ nx,ny,tcount /) )
1260 if (status /= nf90_noerr)
call handle_err(status, __line__)
1262 var_org(:,:,:) =
real( real(short(:,:,:),kind=
sp)*scale_factor + add_offset, kind=
dp )
1265 status = nf90_close(ncid)
1266 if (status /= nf90_noerr)
call handle_err(status, __line__)
1268 call convertarrayorder( var,var_org,tcount,nx,ny )
1270 deallocate( var_org )
1292 real(SP),
intent(out) :: var(:,:,:,:)
1293 character(len=*),
intent( in) :: basename
1294 character(len=*),
intent( in) :: varname
1295 integer,
intent( in) :: ts
1296 integer,
intent( in) :: te
1297 integer,
intent( in) :: myrank
1298 integer,
intent( in) :: mdlid
1299 logical,
intent( in),
optional :: single
1300 logical,
intent( in),
optional :: xstag
1301 logical,
intent( in),
optional :: ystag
1302 logical,
intent( in),
optional :: zstag
1303 logical,
intent( in),
optional :: landgrid
1305 real(SP),
allocatable :: var_org(:,:,:,:)
1306 integer(2),
allocatable :: short(:,:,:,:)
1308 real(4) :: scale_factor, add_offset
1310 integer :: ncid, varid
1313 integer :: nx, ny, nz
1317 character(len=H_LONG) :: fname =
'' 1318 logical :: single_ = .false.
1324 tcount = te - ts + 1
1326 if (
present(single) )
then 1332 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
1334 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1335 if (status /= nf90_noerr)
call handle_err(status, __line__)
1338 call externaltakedimension( dims(:),ncid,mdlid )
1340 if (
present(xstag) )
then 1346 if (
present(ystag) )
then 1352 if (
present(zstag) )
then 1357 if (
present(landgrid) )
then 1358 if ( landgrid )
then 1362 allocate( var_org(nx,ny,nz,tcount) )
1363 allocate( short(nx,ny,nz,tcount) )
1365 status = nf90_inq_varid( ncid, trim(varname), varid )
1366 if (status /= nf90_noerr)
call handle_err(status, __line__)
1368 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1369 if (status /= nf90_noerr)
call handle_err(status, __line__)
1371 if(precis /= nf90_short)
then 1372 status = nf90_get_var( ncid, varid, var_org(:,:,:,:), start = (/ 1,1,1,ts /), &
1373 count = (/ nx,ny,nz,tcount /) )
1374 if (status /= nf90_noerr)
call handle_err(status, __line__)
1376 status = nf90_get_att(ncid, varid,
"scale_factor", scale_factor)
1377 if (status /= nf90_noerr)
call handle_err(status, __line__)
1379 status = nf90_get_att(ncid, varid,
"add_offset", add_offset)
1380 if (status /= nf90_noerr)
call handle_err(status, __line__)
1382 status = nf90_get_var( ncid, varid, short(:,:,:,:), start = (/ 1,1,1,ts /), &
1383 count = (/ nx,ny,nz,tcount /) )
1384 if (status /= nf90_noerr)
call handle_err(status, __line__)
1386 var_org(:,:,:,:) =
real( short(:,:,:,:),kind=
sp )*scale_factor + add_offset
1389 status = nf90_close(ncid)
1390 if (status /= nf90_noerr)
call handle_err(status, __line__)
1392 call convertarrayorder( var,var_org,tcount,nz,nx,ny )
1394 deallocate( var_org )
1416 real(DP),
intent(out) :: var(:,:,:,:)
1417 character(len=*),
intent( in) :: basename
1418 character(len=*),
intent( in) :: varname
1419 integer,
intent( in) :: ts
1420 integer,
intent( in) :: te
1421 integer,
intent( in) :: myrank
1422 integer,
intent( in) :: mdlid
1423 logical,
intent( in),
optional :: single
1424 logical,
intent( in),
optional :: xstag
1425 logical,
intent( in),
optional :: ystag
1426 logical,
intent( in),
optional :: zstag
1427 logical,
intent( in),
optional :: landgrid
1429 real(DP),
allocatable :: var_org(:,:,:,:)
1430 integer(2),
allocatable :: short(:,:,:,:)
1432 real(4) :: scale_factor, add_offset
1434 integer :: ncid, varid
1437 integer :: nx, ny, nz
1441 character(len=H_LONG) :: fname =
'' 1442 logical :: single_ = .false.
1448 tcount = te - ts + 1
1450 if (
present(single) )
then 1456 call externalfilemakefname( fname,mdlid,basename,myrank,single_ )
1458 status = nf90_open( trim(fname), nf90_nowrite, ncid )
1459 if (status /= nf90_noerr)
call handle_err(status, __line__)
1462 call externaltakedimension( dims(:),ncid,mdlid )
1464 if (
present(xstag) )
then 1470 if (
present(ystag) )
then 1476 if (
present(zstag) )
then 1481 if (
present(landgrid) )
then 1482 if ( landgrid )
then 1486 allocate( var_org(nx,ny,nz,tcount) )
1487 allocate( short(nx,ny,nz,tcount) )
1489 status = nf90_inq_varid( ncid, trim(varname), varid )
1490 if (status /= nf90_noerr)
call handle_err(status, __line__)
1492 status = nf90_inquire_variable( ncid, varid, xtype=precis )
1493 if(status /= nf90_noerr)
call handle_err(status, __line__)
1495 if(precis /= nf90_short)
then 1496 status = nf90_get_var( ncid, varid, var_org(:,:,:,:), start = (/ 1,1,1,ts /), &
1497 count = (/ nx,ny,nz,tcount /) )
1498 if (status /= nf90_noerr)
call handle_err(status, __line__)
1500 status = nf90_get_att(ncid, varid,
"scale_factor", scale_factor)
1501 if (status /= nf90_noerr)
call handle_err(status, __line__)
1503 status = nf90_get_att(ncid, varid,
"add_offset", add_offset)
1504 if (status /= nf90_noerr)
call handle_err(status, __line__)
1506 status = nf90_get_var( ncid, varid, short(:,:,:,:), start = (/ 1,1,1,ts /), &
1507 count = (/ nx,ny,nz,tcount /) )
1508 if (status /= nf90_noerr)
call handle_err(status, __line__)
1510 var_org(:,:,:,:) =
real( real(short(:,:,:,:),kind=
sp)*scale_factor + add_offset, kind=
dp )
1513 status = nf90_close(ncid)
1514 if (status /= nf90_noerr)
call handle_err(status, __line__)
1516 call convertarrayorder( var,var_org,tcount,nz,nx,ny )
1518 deallocate( var_org )
1527 subroutine externalfilemakefname( &
1536 character(len=*),
intent(out) :: fname
1537 integer,
intent( in) :: mdlid
1538 character(len=*),
intent( in) :: basename
1539 integer,
intent( in) :: myrank
1540 logical,
intent( in) :: single
1548 fname = trim(basename)
1552 elseif( mdlid ==
inicam )
then 1554 fname = trim(basename)//
'.peall.nc' 1565 write(*,*)
'xxx failed, wrong filetype: [scale_external_io]/[ExternalFileMakeFName]' 1570 end subroutine externalfilemakefname
1575 subroutine externaltakedimension( &
1583 integer,
intent(out) :: dims(:)
1584 integer,
intent( in) :: ncid
1585 integer,
intent( in) :: mdlid
1595 status = nf90_inq_dimid( ncid,
"west_east", dimid )
1596 status = nf90_inquire_dimension( ncid, dimid,len=dims(1) )
1597 status = nf90_inq_dimid( ncid,
"south_north", dimid )
1598 status = nf90_inquire_dimension( ncid, dimid,len=dims(2) )
1599 status = nf90_inq_dimid( ncid,
"bottom_top", dimid )
1600 status = nf90_inquire_dimension( ncid, dimid,len=dims(3) )
1601 status = nf90_inq_dimid( ncid,
"west_east_stag", dimid )
1602 status = nf90_inquire_dimension( ncid, dimid,len=dims(4) )
1603 status = nf90_inq_dimid( ncid,
"south_north_stag", dimid )
1604 status = nf90_inquire_dimension( ncid, dimid,len=dims(5) )
1605 status = nf90_inq_dimid( ncid,
"bottom_top_stag", dimid )
1606 status = nf90_inquire_dimension( ncid, dimid,len=dims(6) )
1607 status = nf90_inq_dimid( ncid,
"soil_layers_stag", dimid )
1608 status = nf90_inquire_dimension( ncid, dimid,len=dims(7) )
1610 elseif( mdlid ==
inicam )
then 1611 status = nf90_inq_dimid( ncid,
"lon", dimid )
1612 status = nf90_inquire_dimension( ncid, dimid,len=dims(1) )
1613 status = nf90_inq_dimid( ncid,
"lat", dimid )
1614 status = nf90_inquire_dimension( ncid, dimid,len=dims(2) )
1615 status = nf90_inq_dimid( ncid,
"lev", dimid )
1616 status = nf90_inquire_dimension( ncid, dimid,len=dims(3) )
1619 write(*,*)
'xxx This external file format is not supported, Sorry.' 1624 end subroutine externaltakedimension
1635 real(SP),
intent(out) :: var(:,:)
1636 real(SP),
intent( in) :: var_org(:,:)
1637 integer,
intent( in) :: tcount
1638 integer,
intent( in) :: nx
1644 var(i,n) = var_org(i,n)
1650 subroutine convertarrayorderwrf2ddp( &
1658 real(DP),
intent(out) :: var(:,:)
1659 real(DP),
intent( in) :: var_org(:,:)
1660 integer,
intent( in) :: tcount
1661 integer,
intent( in) :: nx
1667 var(i,n) = var_org(i,n)
1672 end subroutine convertarrayorderwrf2ddp
1673 subroutine convertarrayorderwrf3dsp( &
1682 real(SP),
intent(out) :: var(:,:,:)
1683 real(SP),
intent( in) :: var_org(:,:,:)
1684 integer,
intent( in) :: tcount
1685 integer,
intent( in) :: nx
1686 integer,
intent( in) :: ny
1693 var(i,j,n) = var_org(i,j,n)
1699 end subroutine convertarrayorderwrf3dsp
1700 subroutine convertarrayorderwrf3ddp( &
1709 real(DP),
intent(out) :: var(:,:,:)
1710 real(DP),
intent( in) :: var_org(:,:,:)
1711 integer,
intent( in) :: tcount
1712 integer,
intent( in) :: nx
1713 integer,
intent( in) :: ny
1720 var(i,j,n) = var_org(i,j,n)
1726 end subroutine convertarrayorderwrf3ddp
1727 subroutine convertarrayorderwrf4dsp( &
1737 real(SP),
intent(out) :: var(:,:,:,:)
1738 real(SP),
intent( in) :: var_org(:,:,:,:)
1739 integer,
intent( in) :: tcount
1740 integer,
intent( in) :: nz
1741 integer,
intent( in) :: nx
1742 integer,
intent( in) :: ny
1743 integer :: n, k, i, j
1750 var(k,i,j,n) = var_org(i,j,k,n)
1757 end subroutine convertarrayorderwrf4dsp
1758 subroutine convertarrayorderwrf4ddp( &
1768 real(DP),
intent(out) :: var(:,:,:,:)
1769 real(DP),
intent( in) :: var_org(:,:,:,:)
1770 integer,
intent( in) :: tcount
1771 integer,
intent( in) :: nz
1772 integer,
intent( in) :: nx
1773 integer,
intent( in) :: ny
1774 integer :: n, k, i, j
1781 var(k,i,j,n) = var_org(i,j,k,n)
1788 end subroutine convertarrayorderwrf4ddp
1791 subroutine handle_err(status, line)
1796 integer,
intent(in) :: status
1797 integer,
intent(in) :: line
1799 write(*,*)
'xxx Error in scale_external_io.f90 at line', line
1800 write(*,*) nf90_strerror(status)
1805 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)
integer, parameter, public dp
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)
integer, parameter, public sp
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, 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)
subroutine externalfilegetglobalattvinteger(var, mdlid, basename, attname, myrank, single)