title: I want to edit my fortran generated file in fortran
body: <p>I have a fortran 95 program, which writes an array in this form:</p>
  
  <pre><code>do temp = 1, temp_final 
    do MC = 1, N_MC
      do x = 0, N
        do y = 0, M
          write(1,*) x, y, array(x,y)
        enddo
      enddo
    enddo
      write(1,*) T
      T = T - temp*factor
  enddo
  </code></pre>
  
  <p>In my program, I am writing these values to a file, but between two temperature values, I am writing more than one time(but N_MC times) x, y array(x,y) values, as they are inside MC loop, going upto N_MC steps.</p>
  
  <p>As file is only generated, and program takes very long time to run, so if you can suggest any technique to edit already generated file and to keep only first set of values and transfer them to another file or edit the parent file, and keep the changes.</p>
  
  <p>My file looks like this</p>
  
  <pre><code> Temp  0.69999999999999998 !(initial value)
         0           0  -1.0000000000000000     
         0           1  -1.0000000000000000     
         0           2  -1.0000000000000000     
         0           3   1.0000000000000000     
         0           4   1.0000000000000000          
         1           0  -1.0000000000000000     
         1           1   1.0000000000000000     
         1           2   1.0000000000000000     
         1           3  -1.0000000000000000     
         1           4  -1.0000000000000000         
         2           0  -1.0000000000000000     
         2           1   1.0000000000000000     
         2           2  -1.0000000000000000     
         2           3   1.0000000000000000     
         2           4   1.0000000000000000         
         3           0  -1.0000000000000000     
         3           1  -1.0000000000000000     
         3           2   1.0000000000000000     
         3           3  -1.0000000000000000     
         3           4  -1.0000000000000000     
  
         0           0   1.0000000000000000     
         0           1  -1.0000000000000000     
         0           2   1.0000000000000000     
         0           3   1.0000000000000000     
         0           4  -1.0000000000000000          
         1           0   1.0000000000000000     
         1           1   1.0000000000000000     
         1           2   1.0000000000000000     
         1           3  -1.0000000000000000     
         1           4  -1.0000000000000000         
         2           0  -1.0000000000000000     
         2           1   1.0000000000000000     
         2           2  -1.0000000000000000     
         2           3   1.0000000000000000     
         2           4   1.0000000000000000         
         3           0  -1.0000000000000000     
         3           1  -1.0000000000000000     
         3           2   1.0000000000000000     
         3           3  -1.0000000000000000     
         3           4  -1.0000000000000000
         ..........       
          N_MC-2 times (as two sets are already shown) !( after that there is new temp having new array values)
  
   Temp  0.59999999999999998  ! like this, I am having array values for diff. temp
   .
   .
   .
   Temp  0.09999999999999998 !(final vaule)
  </code></pre>
  
  <p>I want to keep first set of values only not after that .......... N_MC times values between successive values of temp.</p>
  
  <p>I don't know how to call a file and remove particular section, which I don't want and save it again.</p>
  
  <p><strong>NB</strong></p>
  
  <p>I want to transfer only first set of values 0-3, 0-9, array(i,j)</p>
  
  <pre><code>       0           0  -1.0000000000000000     
         0           1  -1.0000000000000000     
         0           2  -1.0000000000000000     
         0           3   1.0000000000000000     
         0           4   1.0000000000000000          
         1           0  -1.0000000000000000     
         1           1   1.0000000000000000     
         1           2   1.0000000000000000     
         1           3  -1.0000000000000000     
         1           4  -1.0000000000000000         
         2           0  -1.0000000000000000     
         2           1   1.0000000000000000     
         2           2  -1.0000000000000000     
         2           3   1.0000000000000000     
         2           4   1.0000000000000000         
         3           0  -1.0000000000000000     
         3           1  -1.0000000000000000     
         3           2   1.0000000000000000     
         3           3  -1.0000000000000000     
         3           4  -1.0000000000000000
         ! Not after that for Temp = 0.6999999999990
  </code></pre>
  
  <p>to a file for a single temperature.</p>