0

I am trying to write a program that would simply read a table defining a dependency of a coefficient on temperature (table of 2 columns, 27 lines) and that would use the data in an equation. The rest of the variables defined in the subroutine are provided by a FEM program (t(1) and timinc).

My program seems to loop through the whole table, but I have a suspicion that it reads the last row of the table 27 times. Please can someone explain to me the problem?

      subroutine mycode(eqcpnc,t,timinc)
#ifdef _IMPLICITNONE
      implicit none
#else
      implicit logical (a-z)
#endif
      real*8 a, dtdl, eqcpnc, t, timinc
      integer iostat, ios, n
      dimension t(1), dtdl(1)
c
      open (1, file='Coefficient.txt', iostat=ios)
      n=0
      do
            read(1, *, iostat=ios) dtdl(1), a
            if (ios/=0) exit
            n=n+1
      enddo
      rewind(1, iostat=ios)
c
      eqcpnc=t(1)*a**timinc
c
      close(1) 
      return
      end

The original table 'Coefficient.txt' looks like this:

27.85   5.22E-19
77.85   1.47E-18
127.85  4.17E-18
177.85  1.19E-17
227.85  3.44E-17
277.85  1.02E-16
327.85  3.23E-16
377.85  1.12E-15
427.85  4.50E-15
477.85  2.23E-14
527.85  1.42E-13
577.85  1.16E-12
627.85  1.20E-11
677.85  1.44E-10
727.85  1.69E-09
777.85  1.85E-08
827.85  2.31E-07
877.85  5.69E-07
927.85  1.34E-06
977.85  3.04E-06
1027.85 6.64E-06
1077.85 1.40E-05
1127.85 2.84E-05
1177.85 5.61E-05
1227.85 1.08E-04
1277.85 2.01E-04
1327.85 3.65E-04
Pisi
  • 1
  • 1
    Welcome. Please take the [tour]. What is the output you are getting? A self-contained code that we could try would help, see [mcve]. Just make a short program that calls the subroutine and prints the result. – Vladimir F Героям слава Nov 09 '20 at 11:58
  • Your code reads each line of the file into the **same** variables `dtdl(1), a` s.t. you actually **overwrite** the data from the previous line. You should allocate arrays of correct size and write into different elements of those arrays. – jack Nov 09 '20 at 12:03
  • The loop that you have is merely counting the number of rows (and storing just the last pair of values read). Once you have the number of rows and you've rewound, you need to allocate memory and then read in the contents. There are many ways to read unknown length files, such as [in here](https://stackoverflow.com/q/44256136/3157076). – francescalus Nov 09 '20 at 12:24

0 Answers0