Hi I've a loop inside another loop and would like to separate them into two different loops and keep the same functionality, since I'm having trouble with probably memory allocation
Here are the code:
ofstream myfile1;
ofstream grid;
myfile1.open ("fine-time.txt");
grid.open ("grid.txt");
//myfile << "Writing this to a file.\n";
double temp=0;
myfile1 << setw(16) ;
for (int k=1; k<nz+1;k++){
for (int j=1; j<ny+1;j++){
for (int i=1; i<nx+1;i++){
index= (k-1) * nx * ny +(j-1) * (nx) + (i-1) ;
/*if(Final_T[index]==inf){
Final_T[index]=1.;
}*/
myfile1 <<Final_T[index]<< setw(16) ;
// save fine scale time
time_orig[index]= Final_T[index];
//myfile1 <<F[index]<< setw(16) ;
temp=temp+Final_T[index];
}
myfile1 << endl ;
}
}
//variables for tempery values and to count # of grids
double temp1,val=0.0;
int count=0;
//sorting Final_T array using buble sort algorithm
for(i=0;i<npixels;i++){
for(j=0;j<npixels-1;j++){
You can't separate nested loops, that's the point of nesting them. The problem must be somewhere else in your code - trying to un-nest the loops will not help. You can cure pain by removing the brain, but that doesn't help.