2

I have been working with Fortran for my physics project and I have to read data from a file. I need to find a specific matrix and then print the said matrix onto a different file and diagonalize it. How do I read the matrix that follows a specific line. My file looks like this:

       14-  16 P  
                                         1.020E-01 0.000E+00 1.998E-01 0.000E+00

 OVERLAP MATRIX - CELL N.   1(  0  0  0)

              1           2           3           4           5           6           7           8           9          10

   1     1.0000E+00
   2     6.5891E-01  1.0000E+00
   3     0.0000E+00  0.0000E+00  1.0000E+00
   4     0.0000E+00  0.0000E+00  0.0000E+00  1.0000E+00
   5     0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  1.0000E+00
   6     0.0000E+00  0.0000E+00  6.7373E-01  0.0000E+00  0.0000E+00  1.0000E+00
   7     0.0000E+00  0.0000E+00  0.0000E+00  6.7373E-01  0.0000E+00  0.0000E+00  1.0000E+00
   8     0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  6.7373E-01  0.0000E+00  0.0000E+00  1.0000E+00
   9     3.5521E-02  1.2488E-01 -9.4002E-02  9.4002E-02  9.4002E-02 -1.7531E-01  1.7531E-01  1.7531E-01  1.0000E+00
  10     1.1830E-01  2.7534E-01 -1.8038E-01  1.8038E-01  1.8038E-01 -3.1590E-01  3.1590E-01  3.1590E-01  6.8256E-01  1.0000E+00

I need to find the line "OVERLAP MATRIX" and if it exists then read the matrix below and write the matrix in a separate file.

  • You can use the approach in the linked question, but note that instead of reading the rest of the line once it's been identified you continue from that point to read the value. – francescalus Mar 10 '19 at 11:50

0 Answers0