HAZE
haze is a drop-in replacement to process water vapor to be used with FORCE
Loading...
Searching...
No Matches
api.h
1#ifndef API_H
2#define API_H
15
16#include "types.h"
17#include <gdal/ogr_core.h>
18#include <stddef.h>
19#include <curl/curl.h>
20#include <jansson.h>
21
22#define BASEURL "https://cds.climate.copernicus.eu/api"
23
35struct curl_slist *customHeader(struct curl_slist *list, const option_t *options);
36
48int initializeHandle(CURL **handle, const struct curl_slist *headerList);
49
59CURL *newHandleWithOptions(struct curl_slist **list, const option_t *options);
60
72size_t writeString(char *ptr, size_t size, size_t nmemb, void *userdata);
73
85size_t discardWrite(char *ptr, size_t size, size_t nmemb, void *userdata);
86
97json_t *getKeyRecursively(json_t *root, const char *key);
98
109json_t *jsonArrayFromIntegers(const int *arr, size_t elements, const char *formatString);
110
134char *constructStringRequest(const int *years, const int *months, const int *days, const int *hours,
135 const size_t yearsElements, const size_t monthsElements, const size_t daysElements,
136 const size_t hoursElements, const OGREnvelope *aoi);
137
150[[nodiscard]] int download(CURL *handle, const option_t *options, const OGREnvelope *aoi);
151
163char *slurpAndGetString(const char *input, const char *key);
164
186[[nodiscard]] int handleDownloadChain(CURL *handle, const option_t *options, const OGREnvelope *aoi,
187 const char *outputPath, const int *subsetYears, const int *subsetMonths, const int *subsetDays,
188 const int *subsetHours, const size_t yearsElements, const size_t monthsElements,
189 const size_t daysElements, const size_t hoursElements, const unsigned int maxAttempts);
190
213char *cdsRequestProduct(CURL *handle, const int *years, const int *months, const int *days,
214 const int *hours, const size_t yearsElements, const size_t monthsElements,
215 const size_t daysElements, const size_t hoursElements, const OGREnvelope *aoi,
216 const option_t *options);
217
226productStatus cdsGetProductStatus(CURL *handle, const char *requestId,
227 const option_t *options); // Result.update
228
236
251int cdsWaitForProduct(CURL *handle, const char *requestId, const option_t *options,
252 unsigned int maxAttempts);
253
265int cdsDownloadProduct(CURL *handle, const char *requestId,
266 const char *outputPath, const option_t
267 *options); // same URL as product status but with /results appended which then returns the actual download URL
268
277int cdsDeleteProductRequest(CURL *handle, const char *requestId,
278 const option_t *options); // Result.delete
279 // end of group
281#endif // API_H
size_t discardWrite(char *ptr, size_t size, size_t nmemb, void *userdata)
Discard delivered data from API request.
int cdsWaitForProduct(CURL *handle, const char *requestId, const option_t *options, unsigned int maxAttempts)
Wait for a product request to be downloadable with a binary exponential backoff.
productStatus cdsGetProductStatus(CURL *handle, const char *requestId, const option_t *options)
Query the CDS API for the status of a previously created product request.
char * cdsRequestProduct(CURL *handle, const int *years, const int *months, const int *days, const int *hours, const size_t yearsElements, const size_t monthsElements, const size_t daysElements, const size_t hoursElements, const OGREnvelope *aoi, const option_t *options)
Perform product request with CDS API.
int download(CURL *handle, const option_t *options, const OGREnvelope *aoi)
Perform product request and download of ERA-5 products.
int cdsDownloadProduct(CURL *handle, const char *requestId, const char *outputPath, const option_t *options)
Download data related to previously made request to local file.
int binaryExponentialBackoff(int attempt)
Compute binary exponential backoff.
int handleDownloadChain(CURL *handle, const option_t *options, const OGREnvelope *aoi, const char *outputPath, const int *subsetYears, const int *subsetMonths, const int *subsetDays, const int *subsetHours, const size_t yearsElements, const size_t monthsElements, const size_t daysElements, const size_t hoursElements, const unsigned int maxAttempts)
Wrapper around chain of API requests needed to perform a download.
CURL * newHandleWithOptions(struct curl_slist **list, const option_t *options)
Create a new cURL handle and initialize it.
json_t * jsonArrayFromIntegers(const int *arr, size_t elements, const char *formatString)
Convert an array of integers to their string representations with customizable formats.
int cdsDeleteProductRequest(CURL *handle, const char *requestId, const option_t *options)
Delete a prodcut request from personal CDS space.
int initializeHandle(CURL **handle, const struct curl_slist *headerList)
Initialize cURL handle in place.
json_t * getKeyRecursively(json_t *root, const char *key)
Search JSON object recursively for a key with DFS and return first occurence.
size_t writeString(char *ptr, size_t size, size_t nmemb, void *userdata)
Concatenate chunked response from API request into string.
struct curl_slist * customHeader(struct curl_slist *list, const option_t *options)
Create a new header list for cURL with CDS API token field.
char * constructStringRequest(const int *years, const int *months, const int *days, const int *hours, const size_t yearsElements, const size_t monthsElements, const size_t daysElements, const size_t hoursElements, const OGREnvelope *aoi)
Construct a JSON object for CDS API product request.
Definition types.h:198