Skip to content

Conversation

davidbrochart
Copy link
Member

@davidbrochart davidbrochart commented Jun 8, 2019

I'm just trying to see if I'm at least going in the right direction, so please ignore the hacks for now (global variable...).

The following code:

#define XFRAME_DEFAULT_LABEL_LIST xtl::mpl::vector<double, int, std::size_t, char, XFRAME_STRING_LABEL>

double global_tolerance = 0.;

#include "xframe/xvariable.hpp"
#include "xframe/xvariable_view.hpp"

int main(int argc, char* argv[])
{
    using coordinate_type = xf::xcoordinate<xf::fstring>;
    using variable_type = xf::xvariable<double, coordinate_type>;
    
    xt::xarray<double> data
          {{1., 2., 3.},
           {4., 5., 6.},
           {7., 8., 9.}};
    
    auto lat = xf::axis({0., -0.1, -0.2});
    auto lon = xf::axis({0., 0.1, 0.2});
    
    auto var = variable_type(
        data,
        {
            {"lat", lat},
            {"lon", lon}
        }
    );

    std::cout << var << std::endl;

    std::cout << xf::select(var, {{"lat", xf::range(0., -0.1)}, {"lon", xf::range(0.11, 0.19)}}, 0.02) << std::endl;

    return 0;
}

Produces the following output:

{{1, 2, 3},
 {4, 5, 6},
 {7, 8, 9}}
Coordinates:
lat: (0, -0.1, -0.2, )
lon: (0, 0.1, 0.2, )

(2, 3, )
(5, 6, )
Coordinates:
lat: (0, -0.1, )
lon: (0.1, 0.2, )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant