subroutine ANVarSearchNext(iter, url, end)
use an_types, only: AN_VARIABLE_SEARCH
use dc_types, only: string
use netcdf_f77
use dc_url, only: UrlMerge
use an_file, only: inquire, AnFileClose
use dc_trace, only: beginsub, endsub, DbgMessage
implicit none
type(AN_VARIABLE_SEARCH), intent(inout):: iter
character(len = *), intent(out):: url
logical, intent(out):: end
character(len = string):: filename
character(len = NF_MAX_NAME):: varname
integer:: stat, varid_tmp
continue
call beginsub('anvarsearchnext')
if (iter%fileid <= 0) then
end = .TRUE.
url = ''
call endsub('anvarsearchnext', "bad file %d", i=(/iter%fileid/))
return
endif
if (iter%varid >= 0) then
iter%varid = iter%varid + 1
stat = NF_INQ_VARNAME(iter%fileid, iter%varid, varname)
if (stat == NF_NOERR) goto 900
iter%varid = -1
endif
do while (iter%dimid >= 0)
iter%dimid = iter%dimid + 1
! --- 指定番号の次元がなければエラー ---
stat = NF_INQ_DIMNAME(iter%fileid, iter%dimid, varname)
if (stat /= NF_NOERR) exit
! --- 指定番号の次元と同名の変数があれば却下、次番号へ ---
stat = NF_INQ_VARID(iter%fileid, varname, varid_tmp)
if (stat /= NF_NOERR) goto 900
enddo
end = .TRUE.
url = ""
call ANFileClose(iter%fileid)
iter%dimid = -1
call endsub('anvarsearchnext', "end file %d", i=(/iter%fileid/))
return
900 continue
call inquire(iter%fileid, name=filename)
url = UrlMerge(file=trim(filename), var=trim(varname))
end = .FALSE.
call endsub('anvarsearchnext', "file=%d url=<%c>", i=(/iter%fileid/), c1=trim(url))
return
end subroutine