HTTP abstraction layer for Deutsche Wetterdienst (DWD) API. This module
must be linked against libcurl (-lcurl
).
To fetch weather data, create an URL of the DWD weather report directory
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(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()
C-interoperable write callback function for libcurl. Writes response
chunks to file unit in passed client data of type response_type
.
Type | Intent | Optional | 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. |
Number of bytes consumed.
Returns allocatable string of URL to DWD weather report endpoint of
given station id id
. Uses the URL API of libcurl to create the
URL. The function returns an empty string on error. TLS is disabled
by default.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=DWD_MOSMIX_STATION_ID_LEN), | intent(in) | :: | id |
MOSMIX station id. |
||
logical, | intent(in), | optional | :: | tls |
Use HTTPS. |
DWD weather report URL.