get_data.f90

How to get latitude/longitude/values.

00001 ! Copyright 2005-2014 ECMWF
00002 ! This software is licensed under the terms of the Apache Licence Version 2.0
00003 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
00004 ! 
00005 ! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
00006 ! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
00007 !
00008 !
00009 !  Description: how to get lat/lon/values.
00010 !
00011 !
00012 !  Author: Enrico Fucile
00013 !
00014 !
00015 program get_data
00016 use grib_api
00017 implicit none
00018   integer            :: ifile
00019   integer            :: iret,i
00020   real(kind=8),dimension(:),allocatable     :: lats,lons,values
00021   integer(4)        :: numberOfPoints
00022   real(8)  :: missingValue=9999
00023   integer           :: count=0
00024   character(len=256) :: filename
00025 
00026 !     Message identifier.
00027   integer            :: igrib
00028 
00029   ifile=5
00030 
00031   call grib_open_file(ifile, &
00032        '../../data/reduced_latlon_surface.grib1','R')
00033 
00034 ! Loop on all the messages in a file.
00035 
00036   call grib_new_from_file(ifile,igrib,iret)
00037 
00038   do while (iret/=GRIB_END_OF_FILE)
00039     count=count+1
00040     print *, "===== Message #",count
00041     call grib_get(igrib,'numberOfPoints',numberOfPoints)
00042     call grib_set(igrib,'missingValue',missingValue)
00043 
00044     allocate(lats(numberOfPoints))
00045     allocate(lons(numberOfPoints))
00046     allocate(values(numberOfPoints))
00047 
00048     call grib_get_data(igrib,lats,lons,values)
00049 
00050     do i=1,numberOfPoints
00051       if (values(i) /= missingValue) then
00052         print *, lats(i),lons(i),values(i)
00053       end if
00054     enddo
00055 
00056     deallocate(lats)
00057     deallocate(lons)
00058     deallocate(values)
00059 
00060     call grib_release(igrib)
00061     call grib_new_from_file(ifile,igrib, iret)
00062 
00063   end do 
00064 
00065 
00066   call grib_close_file(ifile)
00067 
00068 end program 

Generated on Tue Sep 22 15:18:21 2009 for grib_api by  doxygen 1.5.3