meteo-vm2  2.0.11
VM2 attributes file

Format of a VM2 attributes file and how to read it.

Introduction

The attributes file is a Lua script that return a table with the stations and variables attributes:

return {
stations = {
[145] = { lon=1285000, lat=4412645, rep='synop' },
[218] = { mykey=4
},
variables = {
[245] = { ... }
}
}

You can create a meteo::vm2::Source instance to query the attributes file.

E.g., if you want the attributes associated to the station with id = 12:

// Open the attributes file "v2m.lua"
meteo::vm2::Source source("vm2.lua");
// Push the station 12 on top of the stack
source.lua_push_station(12);
// If stations 12 exists there's a table else a nil value
if (lua_istable(source.L,-1)) {
...
}
// Pop the table or the nil value
lua_pop(L,1);

Or, if you want the list of station id matching the attributes lon=1285000 and lat=4412645:

// Open the attributes file "v2m.lua"
meteo::vm2::Source source("vm2.lua");
// Create the query table
lua_newtable(source.L);
// Save the index of the query table
int idx = lua_gettop(source.L);
// Populate the query table
lua_pushnumber(source.L, 1285000);
lua_setfield(source.L, idx, "lon");
lua_pushnumber(source.L, 4412645);
lua_setfield(source.L, idx, "lat");
// Get the list of station id matching the query table
std::vector<int> stations = source.lua_find_stations(idx);

Dynamic attributes file

The attribute file is a Lua script, so it's possible to write a dynamic attributes table.

See http-source.lua and json-source-ws.py for a complete example.