Code seems to skip the while loop:
int i,j;
i= floor((Lx-23.61)/0.1);
j=0;
while(Nh - modSED[i][j] > 0.0){
j++;
}
if(j>0 && modSED[i][j]-Nh > Nh-modSED[i][j-1]){
fileNH=modSED[i][j-1];
}else{
fileNH=modSED[i][j];
}
It’s more or less a crude linear search through an array of doubles (the i-index is preset by another part of the code and shouldn’t be a problem). The code seems to misbehave when I look at GDB:
Breakpoint 1, mag (filter=4, Lx=23.930108812418158, z=0.57071772467724535, Nh=0.011911981460606383) at infopt.c:45
45 while(Nh-modSED[i][j]>0.0){
(gdb) print Nh-modSED[i][j]
$1 = 0.001911981460606383
(gdb) n
48 if(j>0 && modSED[i][j]-Nh > Nh-modSED[i][j-1]){
(gdb)
and it has just skipped the j++ segment, even though the while loop should evaluate to true.
Thanks,
Josh
The external 2D array modSED was declared with the wrong dimensions (different from the c file in which it was initialized), so either the program, gdb, or both were confused. Fixing the dimensions of the declaration fixed the problem. (Here the problem refers to the larger issue that I wasn’t getting the correct value returned from modSED.) Since GDB seemed to give the wrong output, though, I was getting hung up on the wrong part of the code.
Perhaps this in turn led to GDB seeming to defy logic and skip the while loop? (Running the program now, GDB has no trouble incrementing j and showing that it has done so.)