Hi Whiteflags,
Thanks for your continued help. One of the things I noticed while reading more about vectors is the resize method. I have modified to use resize to increase the structure arrays based on user input. This seems to be more straightforward and works as expected. Do you see any drawback of using this method to resize arrays? Following is my updated code segments
Code:
struct AA
{
vector<int>grid_id;
vector<double>lv_x;
vector<double>lv_y;
vector<double>lv_z;
};
static vector<AA>load;
int idx;
// increase the structure array based on the size of idx
load.resize(idx);
// initialize members of structure load for the idx structure element of load
load[idx].grid_id.assign(ncases,0);
load[idx].lv_x.assign(ncases,0.0);
load[idx].lv_y.assign(ncases,0.0);
load[idx].lv_z.assign(ncases,0.0);
for(ii=0;ii<n_loads;ii++) {
for(jj=0;jj<ncases;jj++) {
load[idx].grid_id.push_back(grids[ii][jj]);
load[idx].lv_x.push_back(x_vec[ii][jj]);
load[idx].lv_y.push_back(y_vec[ii][jj]);
load[idx].lv_z.push_back(z_vec[ii][jj]);
}
}
// load the structure member arrays with values
for(ii=0;ii<n_loads;ii++) {
for(jj=0;jj<ncases;jj++) {
load[idx].grid_id.at(jj) = grids[ii][jj];
load[idx].lv_x.at(jj) = x_vec[ii][jj];
load[idx].lv_y.at(jj) = y_vec[ii][jj];
load[idx].lv_z.at(jj) = z_vec[ii][jj];
}
}