Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The attribute start_index is not read from file #3

Open
mooiman opened this issue Dec 21, 2021 · 0 comments
Open

The attribute start_index is not read from file #3

mooiman opened this issue Dec 21, 2021 · 0 comments

Comments

@mooiman
Copy link

mooiman commented Dec 21, 2021

Some variables on a UGRID file contain the indices of an array, these indices are zero- or one-based. The value of the start_index (0/1) determines if the array on file is zero- or one-based. Depending on the language which uses the UGrid-library the indices should be corrected by the start_index. Therefor the start_index should be read from file. Example: C++ uses zero-based indices and Fortran uses one-based indices.

For a 1D mesh I use the code:
`
{
// reading start_index, needed for edge_nodes array
int i_var;
int start_index = -2;
std::string var_edge_node;
std::string var_start_index;
std::string tmp_name(stripSpaces(m_mesh1d.name));
status = get_attribute_by_var_name(m_ncid, tmp_name, "edge_node_connectivity", &var_edge_node);
status = nc_inq_varid(m_ncid, var_edge_node.c_str(), &i_var);
status = nc_get_att_int(m_ncid, i_var, "start_index", &start_index);
m_mesh1d.start_index = start_index;

        if (m_mesh1d.start_index != 0)
        {
            for (int i = 0; i < m_mesh1d.num_edges * 2; ++i)
            {
                m_mesh1d.edge_node[i] -= m_mesh1d.start_index;
            }
        }
    }
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

No branches or pull requests

1 participant