title: C code inside a loop not being executed
body: <p>Background: the overall program is designed to carry out 2D DIC between a refference image and 1800 target images, (for tomographic reconstruction) In my code, there is this for loop block </p>
  
  <pre><code>for (k=0; k&lt;kmax; k++)
  {
      K=nm12+(k*(h-n+1))/(kmax-1);
      printf("\nk=%d\nL= ", K);
      for (l=0; l&lt;lmax; l++)
      {
          ///For each subset, calculate and store its mean and standard deviation.   
          ///Also want to know the sum and sum of squares of subset, but in two sections, stored in fm/df[k][l][0 and 1].
          L=nm12+(l*(w-n+1))/(lmax-1);
          printf("%d ", L);
          fm[k][l][0]=0;
          df[k][l][0]=0;
          fm[k][l][1]=0;
          df[k][l][1]=0;
          ///loops are j then i as it is more efficient (saves m-1 recalculations of b=j+L; 
          for (j=0; j&lt;m; j++)
          {
              b=j+L;
              for (i=0; i&lt;M; i++)
              {
                  a=i+K;
                  fm[k][l][0]+=ref[a][b];
                  df[k][l][0]+=ref[a][b]*ref[a][b];
              }
  
              for (i=M; i&lt;m; i++)
              {
                  a=i+K;
                  fm[k][l][1]+=ref[a][b];
                  df[k][l][1]+=ref[a][b]*ref[a][b];
              }
          }
          fm[k][l][2]=m2r*(fm[k][l][1]+fm[k][l][0]);
          df[k][l][2]=sqrt(df[k][l][1]+df[k][l][0]-m2*fm[k][l][2]*fm[k][l][2]);
          a+=1;
      }
  }
  </code></pre>
  
  <p>Each time l reaches 10 the line <code>df[k][l][2]=sqrt(df[k][l][1]+df[k][l][0]-m2*fm[k][l][2]*fm[k][l][2]);</code> appears to no longer be executed. By this I mean the debugger shows that the value of df[k][l][2] is not changed from zero to the sum correctly. Also, df[k][l][0 and 1] remain fixed regardless of k and l, just as long as l>=10.</p>
  
  <p>kmax=15, lmax=20, n=121, m=21, M=(3*m)/4=15, nm12=(n-m+1)/2=50.</p>
  
  <p>The arrays fm and df are double arrays, declared <code>double fm[kmax][lmax][3], df[kmax][lmax][3];</code> </p>
  
  <p>Also, the line <code>a+=1;</code> is just there to be used as a breakpoint to check the value of df[k][l][2], and has no affect on the code functionality.</p>
  
  <p>Any help as to why this is happening, how to fix, etc will be muchly appreciated!</p>
  
  <p>EDIT: MORE INFO.</p>
  
  <p>The array ref (containing the reference image pixel values) is a dynamic array, with memory allocated using malloc, in this code block:</p>
  
  <pre><code>    double **dark, **flat, **ref, **target, **target2, ***gm, ***dg;
      dark=(double**)malloc(h * sizeof(double*));
      flat=(double**)malloc(h * sizeof(double*));
      ref=(double**)malloc(h * sizeof(double*));
      target=(double**)malloc(h * sizeof(double*));
      target2=(double**)malloc(h * sizeof(double*));
      size_t wd=w*sizeof(double);
      for (a=0; a&lt;h; a++)
      {
          dark[a]=(double*)malloc(wd);
          flat[a]=(double*)malloc(wd);
          ref[a]=(double*)malloc(wd);
          target[a]=(double*)malloc(wd);
          target2[a]=(double*)malloc(wd);
      }
  </code></pre>
  
  <p>where h=1040 and w=1388 the dimensions of the image.</p>