meteo-vm2  2.0.11
source.f90

Example of a VM2 source table reader for Fortran90.

1 program source
2  implicit none
3  include "meteo-vm2-fortran.h"
4 
5  integer :: sourcehandle, errorcode
6 
7  integer :: ivalue
8  character (len=255) :: svalue
9 
10  ! Opening default attribute file
11  ! For a custom attribute file:
12  ! call meteovm2_source_open(sourcehandle, filename, errorcode)
13  call meteovm2_source_open(sourcehandle, errorcode)
14  if (errorcode .ne. 0) then
15  print *, "Error while opening default source"
16  stop 1
17  endif
18 
19  ! Reading the "lon" attribute (integer) of the station #1
20  call meteovm2_get_station_attr(sourcehandle, 1, "lon", ivalue, errorcode)
21 
22  if (errorcode .ne. 0) then
23  if (errorcode .eq. meteovm2_error_key_not_found) then
24  print *, "Key 'lon' not found"
25  else
26  print *, "Error while reading station attribute 'lon'"
27  stop 1
28  endif
29  else
30  print *, "Longitude: ", real(ivalue) / 100000
31  endif
32  ! Reading the "rep" attribute (string) of the station #1
33  call meteovm2_get_station_attr(sourcehandle, 1, "rep", svalue, errorcode)
34  if (errorcode .ne. 0) then
35  if (errorcode .eq. meteovm2_error_key_not_found) then
36  print *, "Key 'rep' not found"
37  else
38  print *, "Error while reading station attribute 'rep'"
39  stop 1
40  endif
41  else
42  print *, "Report: ", trim(svalue)
43  endif
44 
45  ! Closing attribute file
46  call meteovm2_source_close(sourcehandle, errorcode)
47 
48 end program source