dm_dwd_api Module

HTTP abstraction layer for Deutsche Wetterdienst (DWD) API. This module must be linked against libcurl (-lcurl).

To fetch weather data, create the URL to the DWD weather report and make an HTTP GET request. The data will be cached in a scratch file. The file may be opened as formatted or unformatted (byte stream):

character(len=:), allocatable :: url
integer                       :: rc
type(rpc_request_type)        :: request
type(rpc_response_type)       :: response

type(dwd_weather_report_type), allocatable :: reports(:)

rc = dm_rpc_init()

open (action='readwrite', form='formatted', newunit=response%unit, status='scratch')

url = dm_dwd_api_weather_report_url(station_id='10281', tls=.false.)
rc  = dm_rpc_get(request, response, url, callback=dm_dwd_api_callback)

rewind (response%unit)

rc = dm_dwd_weather_report_read(reports, response%unit)

close (response%unit)

call dm_rpc_shutdown()

See the DWD Open Data Server for the terms and conditions of the service:

  • https://opendata.dwd.de/README.txt

Legal notice:

  • https://www.dwd.de/EN/service/legal_notice/legal_notice_node.html

Uses

  • module~~dm_dwd_api~~UsesGraph module~dm_dwd_api dm_dwd_api iso_c_binding iso_c_binding module~dm_dwd_api->iso_c_binding module~dm_dwd dm_dwd module~dm_dwd_api->module~dm_dwd module~dm_error dm_error module~dm_dwd_api->module~dm_error module~dm_kind dm_kind module~dm_dwd_api->module~dm_kind module~dm_dwd->module~dm_error module~dm_dwd->module~dm_kind module~dm_file dm_file module~dm_dwd->module~dm_file module~dm_time dm_time module~dm_dwd->module~dm_time module~dm_util dm_util module~dm_dwd->module~dm_util module~dm_error->module~dm_kind module~dm_ascii dm_ascii module~dm_error->module~dm_ascii iso_fortran_env iso_fortran_env module~dm_kind->iso_fortran_env module~dm_file->module~dm_error module~dm_file->module~dm_kind module~dm_time->module~dm_error module~dm_time->module~dm_kind module~dm_time->module~dm_util unix unix module~dm_time->unix module~dm_util->module~dm_error module~dm_util->module~dm_kind

Used by

  • module~~dm_dwd_api~~UsedByGraph module~dm_dwd_api dm_dwd_api module~dmpack dmpack module~dmpack->module~dm_dwd_api

Functions

public function dm_dwd_api_callback(ptr, sz, nmemb, data) result(n) bind(c))

C-interoperable write callback function for libcurl. Writes response chunks to file unit in passed client data of type response_type.

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in), value :: ptr

C pointer to a chunk of the response.

integer(kind=c_size_t), intent(in), value :: sz

Always 1.

integer(kind=c_size_t), intent(in), value :: nmemb

Size of the response chunk.

type(c_ptr), intent(in), value :: data

C pointer to argument passed by caller.

Return Value integer(kind=c_size_t)

Number of bytes consumed.

public function dm_dwd_api_weather_report_url(station_id, tls) result(url)

Returns allocatable string of URL to DWD weather report endpoint of given station id station_id. Uses the URL API of libcurl to create the URL. The function returns an empty string on error. TLS is disabled by default.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: station_id

MOSMIX station id.

logical, intent(in), optional :: tls

Use HTTPS.

Return Value character(len=:), allocatable

DWD weather report URL.