danhm
July 6th, 2007, 01:45 PM
For one of my astronomy professors, I'm writing a small program in C++ that takes a whole bunch of data points from satellites and formats them into something ArcMap (GIS software) can use. There are three files that are read in -- a file containing longitudes, a file containing latitudes, and a file contain some sort of data about the perspective lat/lon point (right now it is albedo values, but could be anything).
Currently, my program can successfully read in the files, "guess" what any missing longitude or latitude value should have been (sometimes the satellite returned something that wasn't a number when it should have), and I can output these values into a simple list format (ID #, Longitude, Latitude, Data newline). The problem arises when I try to output these into a "box" format. They are a little more complicated than the list. They are listed as:
ID #, Top left lon, data value
top right lon, top right lat
bottom right lon, bottom right lat
bottom left lon, bottom left lat
END
I think that should be enough background information. If not, feel free to ask me for more.
The offending code (with some extra cout statements I left in for debugging the segfault) is:
//This takes an integer, which is really a location in formatted. It assumes that the point given to it is
//the top left corner of the box it makes up. It gets its neighboring points and stores them to be ouput
//later. Should the point fall in the right-most column or the bottom row (places where there are no points
//to the right or below it), this will project points to be used, so a box can still be drawn.
void merger :: makeBoxes (int whichone) {
cout << "on try #" << whichone << endl;
/*
+1 moves to the right by one. -1 moves to the left by one
+WIDTH moves directly below. -WIDTH moves directly above.
*/
if( whichone+WIDTH < MAX - 1 && !onRight(whichone)){
cout << "made it in\n";
data_points[whichone].topleftLon = data_points[whichone].longitude_point;
data_points[whichone].topleftLat = data_points[whichone].latitude_point;
data_points[whichone].toprightLon = data_points[whichone+1].longitude_point;
data_points[whichone].toprightLat = data_points[whichone+1].latitude_point;
data_points[whichone].bottomleftLon = data_points[whichone+WIDTH].longitude_point;
data_points[whichone].bottomleftLat = data_points[whichone+WIDTH].latitude_point;
data_points[whichone].bottomrightLon = data_points[whichone+WIDTH+1].longitude_point;
data_points[whichone].bottomrightLat = data_points[whichone+WIDTH+1].latitude_point;
}
else if ( ((whichone+WIDTH) < (MAX - 1)) && onRight(whichone)){
data_points[whichone].topleftLon = data_points[whichone-1].longitude_point;
data_points[whichone].topleftLat = data_points[whichone-1].latitude_point;
data_points[whichone].toprightLon = data_points[whichone].longitude_point;
data_points[whichone].toprightLat = data_points[whichone].latitude_point;
data_points[whichone].bottomleftLon = data_points[whichone+WIDTH-1].longitude_point;
data_points[whichone].bottomleftLat = data_points[whichone+WIDTH-1].latitude_point;
data_points[whichone].bottomrightLon = data_points[whichone+WIDTH].longitude_point;
data_points[whichone].bottomrightLat = data_points[whichone+WIDTH].latitude_point;
}
else if ( ((whichone+WIDTH) > (MAX-1)) && !onRight(whichone)){
data_points[whichone].topleftLon = data_points[whichone-1].longitude_point;
data_points[whichone].topleftLat = data_points[whichone-1].latitude_point;
data_points[whichone].toprightLon = data_points[whichone].longitude_point;
data_points[whichone].toprightLat = data_points[whichone].latitude_point;
data_points[whichone].bottomleftLon = data_points[whichone-WIDTH].longitude_point;
data_points[whichone].bottomleftLat = data_points[whichone-WIDTH].latitude_point;
data_points[whichone].bottomrightLon = data_points[whichone-WIDTH-1].longitude_point;
data_points[whichone].bottomrightLat = data_points[whichone-WIDTH-1].latitude_point;
}
else if ( ((whichone+WIDTH) > (MAX-1)) && onRight(whichone)){
data_points[whichone].topleftLon = data_points[whichone-1].longitude_point;
data_points[whichone].topleftLat = data_points[whichone-1].latitude_point;
data_points[whichone].toprightLon = data_points[whichone].longitude_point;
data_points[whichone].toprightLat = data_points[whichone].latitude_point;
data_points[whichone].bottomleftLon = data_points[whichone-WIDTH].longitude_point;
data_points[whichone].bottomleftLat = data_points[whichone-WIDTH].latitude_point;
data_points[whichone].bottomrightLon = data_points[whichone-WIDTH-1].longitude_point;
data_points[whichone].bottomrightLat = data_points[whichone-WIDTH-1].latitude_point;
}
}
//Is it on the right-most column?
bool merger :: onRight(int whichone) {
cout << "start " << whichone << endl;
if (whichone % WIDTH == 0) { //if this is true, it is on the right most column.
cout << "true\n";
return true;
}
cout << "false\n";
return false;
}
data_points is an array of a struct I made, whichone is the location in the array, and WIDTH is how many data points per row.
When I try to run it, it does not get very far.
on try #0
start 0
true
start 0
true
Segmentation fault (core dumped)
I've been looking at this code for about a day now, and I can't figure out what's happening. I know it isn't going out of the array since I've made it much bigger than it would ever have to be (25,000 when I know it is supposed to be 5,563).
Does anyone have any suggestions? It's really appreciated.
Currently, my program can successfully read in the files, "guess" what any missing longitude or latitude value should have been (sometimes the satellite returned something that wasn't a number when it should have), and I can output these values into a simple list format (ID #, Longitude, Latitude, Data newline). The problem arises when I try to output these into a "box" format. They are a little more complicated than the list. They are listed as:
ID #, Top left lon, data value
top right lon, top right lat
bottom right lon, bottom right lat
bottom left lon, bottom left lat
END
I think that should be enough background information. If not, feel free to ask me for more.
The offending code (with some extra cout statements I left in for debugging the segfault) is:
//This takes an integer, which is really a location in formatted. It assumes that the point given to it is
//the top left corner of the box it makes up. It gets its neighboring points and stores them to be ouput
//later. Should the point fall in the right-most column or the bottom row (places where there are no points
//to the right or below it), this will project points to be used, so a box can still be drawn.
void merger :: makeBoxes (int whichone) {
cout << "on try #" << whichone << endl;
/*
+1 moves to the right by one. -1 moves to the left by one
+WIDTH moves directly below. -WIDTH moves directly above.
*/
if( whichone+WIDTH < MAX - 1 && !onRight(whichone)){
cout << "made it in\n";
data_points[whichone].topleftLon = data_points[whichone].longitude_point;
data_points[whichone].topleftLat = data_points[whichone].latitude_point;
data_points[whichone].toprightLon = data_points[whichone+1].longitude_point;
data_points[whichone].toprightLat = data_points[whichone+1].latitude_point;
data_points[whichone].bottomleftLon = data_points[whichone+WIDTH].longitude_point;
data_points[whichone].bottomleftLat = data_points[whichone+WIDTH].latitude_point;
data_points[whichone].bottomrightLon = data_points[whichone+WIDTH+1].longitude_point;
data_points[whichone].bottomrightLat = data_points[whichone+WIDTH+1].latitude_point;
}
else if ( ((whichone+WIDTH) < (MAX - 1)) && onRight(whichone)){
data_points[whichone].topleftLon = data_points[whichone-1].longitude_point;
data_points[whichone].topleftLat = data_points[whichone-1].latitude_point;
data_points[whichone].toprightLon = data_points[whichone].longitude_point;
data_points[whichone].toprightLat = data_points[whichone].latitude_point;
data_points[whichone].bottomleftLon = data_points[whichone+WIDTH-1].longitude_point;
data_points[whichone].bottomleftLat = data_points[whichone+WIDTH-1].latitude_point;
data_points[whichone].bottomrightLon = data_points[whichone+WIDTH].longitude_point;
data_points[whichone].bottomrightLat = data_points[whichone+WIDTH].latitude_point;
}
else if ( ((whichone+WIDTH) > (MAX-1)) && !onRight(whichone)){
data_points[whichone].topleftLon = data_points[whichone-1].longitude_point;
data_points[whichone].topleftLat = data_points[whichone-1].latitude_point;
data_points[whichone].toprightLon = data_points[whichone].longitude_point;
data_points[whichone].toprightLat = data_points[whichone].latitude_point;
data_points[whichone].bottomleftLon = data_points[whichone-WIDTH].longitude_point;
data_points[whichone].bottomleftLat = data_points[whichone-WIDTH].latitude_point;
data_points[whichone].bottomrightLon = data_points[whichone-WIDTH-1].longitude_point;
data_points[whichone].bottomrightLat = data_points[whichone-WIDTH-1].latitude_point;
}
else if ( ((whichone+WIDTH) > (MAX-1)) && onRight(whichone)){
data_points[whichone].topleftLon = data_points[whichone-1].longitude_point;
data_points[whichone].topleftLat = data_points[whichone-1].latitude_point;
data_points[whichone].toprightLon = data_points[whichone].longitude_point;
data_points[whichone].toprightLat = data_points[whichone].latitude_point;
data_points[whichone].bottomleftLon = data_points[whichone-WIDTH].longitude_point;
data_points[whichone].bottomleftLat = data_points[whichone-WIDTH].latitude_point;
data_points[whichone].bottomrightLon = data_points[whichone-WIDTH-1].longitude_point;
data_points[whichone].bottomrightLat = data_points[whichone-WIDTH-1].latitude_point;
}
}
//Is it on the right-most column?
bool merger :: onRight(int whichone) {
cout << "start " << whichone << endl;
if (whichone % WIDTH == 0) { //if this is true, it is on the right most column.
cout << "true\n";
return true;
}
cout << "false\n";
return false;
}
data_points is an array of a struct I made, whichone is the location in the array, and WIDTH is how many data points per row.
When I try to run it, it does not get very far.
on try #0
start 0
true
start 0
true
Segmentation fault (core dumped)
I've been looking at this code for about a day now, and I can't figure out what's happening. I know it isn't going out of the array since I've made it much bigger than it would ever have to be (25,000 when I know it is supposed to be 5,563).
Does anyone have any suggestions? It's really appreciated.