struct dimension{
int dimlen;
nc_type xtype; // NC_DOUBLE or NC_FLOAT
void * dimdata;
double * bound_data;
double * edges_data;
};
void compute_bound_d ata(dimension * dim){
assert(dim->bound_data == 0 && dim->edges_data == 0);
assert(dim->bound_data = (double *)malloc(dim->dimlen));
assert(dim->edges_data = (double *)malloc(dim->dimlen+1));
double dimdata[dim->dimlen];
if(type_size(di m->xtype) == sizeof(float))
for(int i = 0; i < (int)dim->dimlen; i ++) dimdata[i] = *(((float
*)dim->dimdata)+i);
else
for(int i = 0; i < (int)dim->dimlen; i ++) dimdata[i] =
*(((double*)dim->dimdata)+i);
dim->edges_data[0] = dimdata[0] - (dimdata[1]-dimdata[0])/2;
for(int i = 1; i < (int)dim->dimlen; i ++) dim->edges_data[i] =
(dimdata[i-1] + dimdata[i])/2.;
dim->edges_data[dim->dimlen] = dimdata[dim->dimlen-1] +
(dimdata[dim->dimlen-1]-dimdata[dim->dimlen-2])/2.;
for(int i = 0; i < (int)dim->dimlen; i ++)
dim->bound_data[i] = (dim->edges_data)[i+1] - (dim->edges_data)[i];
}
For some wierd reason, when i = 6, the last line in compute_bound_d ata
starts to overwrite edges_data when everything about edges_data were on
LHS of the assignment...I can't fathom why it's happening...but it does
in the debugger. Any clue why it could have happened from this code
segment? The entire software package is too big to copy/paste.
int dimlen;
nc_type xtype; // NC_DOUBLE or NC_FLOAT
void * dimdata;
double * bound_data;
double * edges_data;
};
void compute_bound_d ata(dimension * dim){
assert(dim->bound_data == 0 && dim->edges_data == 0);
assert(dim->bound_data = (double *)malloc(dim->dimlen));
assert(dim->edges_data = (double *)malloc(dim->dimlen+1));
double dimdata[dim->dimlen];
if(type_size(di m->xtype) == sizeof(float))
for(int i = 0; i < (int)dim->dimlen; i ++) dimdata[i] = *(((float
*)dim->dimdata)+i);
else
for(int i = 0; i < (int)dim->dimlen; i ++) dimdata[i] =
*(((double*)dim->dimdata)+i);
dim->edges_data[0] = dimdata[0] - (dimdata[1]-dimdata[0])/2;
for(int i = 1; i < (int)dim->dimlen; i ++) dim->edges_data[i] =
(dimdata[i-1] + dimdata[i])/2.;
dim->edges_data[dim->dimlen] = dimdata[dim->dimlen-1] +
(dimdata[dim->dimlen-1]-dimdata[dim->dimlen-2])/2.;
for(int i = 0; i < (int)dim->dimlen; i ++)
dim->bound_data[i] = (dim->edges_data)[i+1] - (dim->edges_data)[i];
}
For some wierd reason, when i = 6, the last line in compute_bound_d ata
starts to overwrite edges_data when everything about edges_data were on
LHS of the assignment...I can't fathom why it's happening...but it does
in the debugger. Any clue why it could have happened from this code
segment? The entire software package is too big to copy/paste.
Comment