[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Solved differently] Re: Hpw to assign a struct to a cell array element
From: |
Philip Nienhuis |
Subject: |
[Solved differently] Re: Hpw to assign a struct to a cell array element in an .oct file |
Date: |
Sat, 19 Dec 2015 21:37:17 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0 SeaMonkey/2.38 |
Hi Endre:
Kozma, Endre wrote:
On Sat, 2015-12-19 at 07:55 -0800, PhilipNienhuis wrote:
The setup of the (AFAIU) relevant statements goes as follows:
:
int band_count = poDS->GetRasterCount(); // call a GDAL library function
:
Cell m_band(band_count); // declare m_band to be a cell array
:
for (int curr_band = 0; curr_band < band_count; curr_band++) {
:
< generate struct with raster info for current band >
< finally resulting in a struct (octave_scalar_map) band_struct >
:
m_band(curr_band) = band_struct; // crash if curr_band > 0
:
I'm afraid something went wrong with the generation of band_struct.
Could you not post this part of code?
I suggest replacing the struct generation temporarily with something
very simple thing like this
octave_scalar_map band_struct;
band_struct.assign("answer", 42);
and checking whether it crashes. I use a very similar code-structure as
you do, except I assign my structs to an octave_value_list.
Note, there is a more appropriate type for index variables:
octave_idx_type.
Thanks.
No, filling band_struct works perfectly for 1-band raster data so that
part works. It is the assignment to a cell array that is flawed in the
function.
In the mean time I sought an alternative solution; rather than returning
a cell array of structs, I preferred a struct array anyway. The original
author didn't want that but as package maintainer I have some degrees of
freedom :-)
So I scoured octave's sources for an example and found __magic_read__.cc
Copying some constructs from it the function "gdalread.cc" can now read
multi-band raster data fine.
Indeed the index should be "octave_idx_type"; I had already tried that
but that didn't help with cell arrays. For the struct arrays it seems to
be required (they won't get "filled" otherwise).
So now I have the following code:
:
static const char *fields[] = {"bbox", "data", "min", "max", "ndv"};
octave_map m_band (dim_vector (band_count, 1), string_vector (fields));
/// line wrap
octave_idx_type curr_band;
octave_scalar_map band_struct = (string_vector (fields));
:
for (octave_idx_type curr_band = 0; curr_band < band_count; curr_band++)
{
:
< fill up band_struct with raster data>
:
m_band.fast_elem_insert (curr_band, band_struct);
}
Philip