Oyster Harvest Area Closure Analysis 0.1
Prediction and analysis of NSW oyster harvest area closures.
Loading...
Searching...
No Matches
stations.c File Reference
#include "BOM/stations.h"
Include dependency graph for stations.c:

Functions

static int8_t BOM_ParseStations (Utils_ReqData_TypeDef *stream, BOM_WeatherStations_TypeDef *stations)
 Parse .txt file into a BOM_Stations struct. More...
 
CURLcode BOM_GetWeatherStations (BOM_WeatherStations_TypeDef *stations)
 Get a list of NSW BOM weather stations. More...
 
int8_t BOM_LoadStationsFromTxt (const char *filename, BOM_WeatherStations_TypeDef *stations)
 Load BOM station list from cached .txt file (obtained from BOM FTP server) More...
 
int16_t BOM_ClosestStationIndex (double latitude, double longitude, BOM_WeatherStations_TypeDef *stations)
 Index of the closest BOM station to a define latitude and longitude. More...
 

Function Documentation

◆ BOM_ClosestStationIndex()

int16_t BOM_ClosestStationIndex ( double  latitude,
double  longitude,
BOM_WeatherStations_TypeDef stations 
)

Index of the closest BOM station to a define latitude and longitude.

Gets an index to the closest BOM weather station in reference to a provided latitude and longitude.

Parameters
latitudeLatitude of interest.
longitudeLongitude of interest.
stationsList of stations to search through.
Returns
Index of closest BOM station to provided lat and long.

◆ BOM_GetWeatherStations()

CURLcode BOM_GetWeatherStations ( BOM_WeatherStations_TypeDef stations)

Get a list of NSW BOM weather stations.

Get a list of NSW BOM weather station.

The BOM provides a list of weather stations as a .txt file on their FTP server. This function extracts the NSW locations and appends them to a list of stations within BOM_WeatherStations_TypeDef.

Parameters
stationsList of weather stations to popultate.
Returns
Curl error code.

◆ BOM_LoadStationsFromTxt()

int8_t BOM_LoadStationsFromTxt ( const char *  filename,
BOM_WeatherStations_TypeDef stations 
)

Load BOM station list from cached .txt file (obtained from BOM FTP server)

Reads a .txt from file to parse out a list of weather station.

A .txt file is loaded from a temporary directory. fgets() is used to parse the file line by line into a buffer. The buffer is scanned using sscanf() to extract each relevent weather station. Only NSW weather stations are used to populate a list of stations (provided). Weather stations that contain "AWS" have this string removed in their filename. This filename should correspond to the location in BOM's FTP server where historical data is found. E.g. .../filename/filename-date.csv or .../moyura_airport/moyura_airport-202206.csv

Parameters
filenameLocation of BOM weather stations .txt file.
stationsStations object to populate.
Returns
Error status code.

◆ BOM_ParseStations()

static int8_t BOM_ParseStations ( Utils_ReqData_TypeDef stream,
BOM_WeatherStations_TypeDef stations 
)
static

Parse .txt file into a BOM_Stations struct.

Parse BOM weather station .txt file from FTP server.

This function saves the downloaded raw text stream from the BOM FTP server into a temporary file (under the tmp) directory. This then calls BOM_LoadStationsFromTxt() to populate the list of BOM weather stations.

Parameters
streamRaw response from BOM FTP server download.
stationsStations object to populate.
Returns
Error code status if file can no the written to.