diff --git a/lis/core/LIS_dataAssimMod.F90 b/lis/core/LIS_dataAssimMod.F90 index 458cb15ad..aa05c55ad 100644 --- a/lis/core/LIS_dataAssimMod.F90 +++ b/lis/core/LIS_dataAssimMod.F90 @@ -49,6 +49,7 @@ module LIS_dataAssimMod ! 27 Feb 2005 Sujay Kumar; Initial Specification ! 7 Sep 2017 Mahdi Navari; set a condition to deal the skewness of the both model and obs CDF ! 1 Apr 2019 Yonghwan Kwon; include an option to read soil moisture CDF information for each month separately +! 5 Mar 2021 Eric Kemp; reduced memory usage in read_CDFdata_month ! ! !USES: use ESMF @@ -998,15 +999,15 @@ subroutine read_CDFdata_all(n, k, nbins, ntimes, ngrid, & end subroutine read_CDFdata_all !BOP -! !ROUTINE: read_CDFdata_month +! !ROUTINE: read_CDFdata_month ! \label{read_CDFdata_month} ! -! !INTERFACE: +! !INTERFACE: subroutine read_CDFdata_month(n, k, nbins, ntimes, ngrid, & filename, varname, xrange, cdf, imonth) implicit none -! !ARGUMENTS: +! !ARGUMENTS: integer, intent(in) :: n integer, intent(in) :: k integer, intent(in) :: nbins @@ -1015,16 +1016,16 @@ subroutine read_CDFdata_month(n, k, nbins, ntimes, ngrid, & integer, intent(in) :: imonth character(len=*) :: filename character(len=*) :: varname - real :: xrange(ngrid,1, nbins) - real :: cdf(ngrid,1, nbins) + real :: xrange(ngrid, 1, nbins) + real :: cdf(ngrid, 1, nbins) -! -! !DESCRIPTION: +! +! !DESCRIPTION: ! This routine reads the input CDF file (generated by LDT in NETCDF format) -! The xrange values and the corresponding CDFs are read for each grid point. -! Both these fields are expected to be in the 1-d grid vector dimension. -! -! The arguments are: +! The xrange values and the corresponding CDFs are read for each grid point. +! Both these fields are expected to be in the 1-d grid vector dimension. +! +! The arguments are: ! \begin{description} ! \item[n] index of the nest ! \item[nbins] number of bins used to compute the model and obs CDFs @@ -1044,74 +1045,86 @@ subroutine read_CDFdata_month(n, k, nbins, ntimes, ngrid, & TRACE_ENTER("DA_readCDF") #if(defined USE_NETCDF3 || defined USE_NETCDF4) - write(LIS_logunit,*) '[INFO] Reading CDF file ',trim(filename) + write(LIS_logunit,*) '[INFO] Reading monthly CDF file ', trim(filename) if(ngrid.gt.0) then - call LIS_verify(nf90_open(path=trim(filename),mode=NF90_NOWRITE,& - ncid=nid),'failed to open file '//trim(filename)) + call LIS_verify(nf90_open(path=trim(filename), mode=NF90_NOWRITE, & + ncid=nid), 'failed to open file '//trim(filename)) - call LIS_verify(nf90_inq_dimid(nid,"ngrid",ngridId), & + call LIS_verify(nf90_inq_dimid(nid, "ngrid", ngridId), & 'nf90_inq_dimid failed for ngrid') - call LIS_verify(nf90_inq_dimid(nid,"nbins",nbinsId), & + call LIS_verify(nf90_inq_dimid(nid, "nbins", nbinsId), & 'nf90_inq_dimid failed for nbins') - call LIS_verify(nf90_inq_dimid(nid,trim(varname)//"_levels",nlevsId), & + call LIS_verify(nf90_inq_dimid(nid, & + trim(varname)//"_levels", nlevsId), & 'nf90_inq_dimid failed for '//trim(varname)//"_levels") - call LIS_verify(nf90_inquire_dimension(nid,ngridId, len=ngrid_file),& + call LIS_verify(nf90_inquire_dimension(nid, ngridId, len=ngrid_file),& 'nf90_inquire_dimension failed for ngrid') - call LIS_verify(nf90_inquire_dimension(nid,nbinsId, len=nbins_file),& + call LIS_verify(nf90_inquire_dimension(nid, nbinsId, len=nbins_file),& 'nf90_inquire_dimension failed for nbins') - call LIS_verify(nf90_inquire_dimension(nid,nlevsId, len=nlevs_file),& + call LIS_verify(nf90_inquire_dimension(nid, nlevsId, len=nlevs_file),& 'nf90_inquire_dimension failed for nbins') - if(nbins.ne.nbins_file) then - write(LIS_logunit,*) '[ERR] The number of bins specified in the file '//& + if (nbins .ne. nbins_file) then + write(LIS_logunit,*) & + '[ERR] The number of bins specified in the file '//& trim(filename) - write(LIS_logunit,*) '[ERR] (',nbins_file, & + write(LIS_logunit,*) '[ERR] (', nbins_file, & ') is different from the number of bins specified' - write(LIS_logunit,*) '[ERR] in the lis.config file (',nbins,')' + write(LIS_logunit,*) '[ERR] in the lis.config file (', nbins, ')' call LIS_endrun() endif - allocate(xrange_file(ngrid_file,nlevs_file, nbins)) - allocate(cdf_file(ngrid_file,nlevs_file, nbins)) + ! EMK...Reorganized code to reduce memory usage. The _xrange file data + ! is handled first, then the _CDF file data. - call LIS_verify(nf90_inq_varid(nid,trim(varname)//'_xrange',xid),& + ! First, handle _xrange + call LIS_verify(nf90_inq_varid(nid,trim(varname)//'_xrange', xid),& 'nf90_inq_varid failed for for '//trim(varname)//'_xrange') - call LIS_verify(nf90_inq_varid(nid,trim(varname)//'_CDF',cdfid),& - 'nf90_inq_varid failed for '//trim(varname)//'_CDF') - - call LIS_verify(nf90_get_var(nid,xid,xrange_file, & - start=(/1,imonth,1,1/), count=(/ngrid_file,1,nlevs_file,nbins/)),& + allocate(xrange_file(ngrid_file, nlevs_file, nbins)) + xrange_file = 0 + call LIS_verify(nf90_get_var(nid, xid, xrange_file, & + start=(/1, imonth, 1, 1/), & + count=(/ngrid_file, 1, nlevs_file,nbins/)),& 'nf90_get_var failed for '//trim(varname)//'_xrange') - call LIS_verify(nf90_get_var(nid,cdfid,cdf_file,& - start=(/1,imonth,1,1/), count=(/ngrid_file,1,nlevs_file,nbins/)),& - 'nf90_get_var failed for '//trim(varname)//'_CDF') - - if(ngrid.gt.0) then - do kk=1,nbins - call LIS_convertObsVarToLocalSpace(n,k,xrange_file(:,1,kk), & + if (ngrid .gt. 0) then + do kk = 1, nbins + call LIS_convertObsVarToLocalSpace(n, k, & + xrange_file(:,1,kk), & xrange(:,1,kk)) - call LIS_convertObsVarToLocalSpace(n,k,cdf_file(:,1,kk), & - cdf(:,1,kk)) enddo endif - -! xrange = xrange_file -! cdf = cdf_file - deallocate(xrange_file) + + ! Next, handle _CDF + call LIS_verify(nf90_inq_varid(nid, trim(varname)//'_CDF', cdfid),& + 'nf90_inq_varid failed for '//trim(varname)//'_CDF') + allocate(cdf_file(ngrid_file, nlevs_file, nbins)) + cdf_file = 0 + call LIS_verify(nf90_get_var(nid, cdfid, cdf_file,& + start=(/1, imonth, 1, 1/), & + count=(/ngrid_file, 1, nlevs_file, nbins/)),& + 'nf90_get_var failed for '//trim(varname)//'_CDF') + if (ngrid .gt. 0) then + do kk = 1, nbins + call LIS_convertObsVarToLocalSpace(n, k, cdf_file(:,1,kk), & + cdf(:,1,kk)) + enddo + endif deallocate(cdf_file) + ! Finish with the file call LIS_verify(nf90_close(nid),& 'failed to close file '//trim(filename)) - write(LIS_logunit,*) '[INFO] Successfully read CDF file ',trim(filename) + write(LIS_logunit,*) '[INFO] Successfully read CDF file ', & + trim(filename) endif #endif TRACE_EXIT("DA_readCDF") end subroutine read_CDFdata_month !BOP -! !ROUTINE: read_MeanSigmaData_all +! !ROUTINE: read_MeanSigmaData_all ! \label{read_MeanSigmaData_all} ! ! !INTERFACE: