! ! sample reads ! use wgrib2api real, allocatable :: grid(:,:), lat(:,:), lon(:,:) integer (kind=8) :: date character (len=200) :: file, inv, var, str_date, desc file = 'gep19.t00z.pgrb2af180.jpeg' inv = '@mem:0' ! make inv file, save in memory file #0 iret = grb2_mk_inv(file, inv) if (iret.ne.0) stop 1 ! search using variable and regular date YYYYMMDDHH var = ':HGT:500 mb:' date = 2009060500_8 iret = grb2_inq(file,inv,var,ref_date=date,nx=nx,ny=ny,data2=grid) if (iret.ne.1) then if (iret.eq.0) write(*,*) 'could not find message' if (iret.gt.1) write(*,*) 'found multiple messages ', iret stop 2 endif write(*,*) 'SP value=',grid(1,1),' grid=',nx,ny ! search using variable and extended date YYYYMMDDHHMMSS var = ':HGT:700 mb:' date = 20090605000000_8 iret = grb2_inq(file,inv,var,ref_edate=date,data2=grid) if (iret.ne.1) then if (iret.eq.0) write(*,*) 'could not find message' if (iret.gt.1) write(*,*) 'found multiple messages ', iret stop 3 endif write(*,*) 'SP value=',grid(1,1) ! search using variable and string date var = ':TMP:500 mb:' str_date = ':d=2009060500:' iret = grb2_inq(file,inv,var,str_date,data2=grid,lat=lat,lon=lon) if (iret.ne.1) then if (iret.eq.0) write(*,*) 'could not find message' if (iret.gt.1) write(*,*) 'found multiple messages ', iret stop 4 endif write(*,*) 'SP(1,1) =',grid(1,1),' lat/lon=',lat(1,1), lon(1,1) ! what happens with no search term iret = grb2_inq(file,inv,data2=grid,lat=lat,lon=lon) write(*,*) 'no search term, iret=',iret i = iret do j = 1, i iret = grb2_inq(file,inv,desc=desc,sequential=j-1) write(*,*) j, iret, trim(desc) enddo stop end