0

In fortran ,what is the way of finding number of columns in a datafile containing a matrix?

This question How to read number of lines in Fortran 90 from a text file? addresses how to find the number of rows.

Is there any similar way for finding the number of columns?

My goal is reading a matrix from the datafile using an allocatable array of a(nrow,ncolumn) where nrow and ncolumn will be obtained from the datafile's row and column number.

user157588
  • 249
  • 1
  • 7
  • 1
    You don't need to know the maximum line length, non-advancing I/O and testing for end of record addresses that. – Ian Bush May 15 '20 at 07:11
  • There are multiple approaches. If you know you have numbers, you can try reading numbers as long as it is possible. Ot you can read individual characters and count the groups of whitespace characters between other non-whitespace characters. – Vladimir F Героям слава May 15 '20 at 08:24
  • Could you please add a small example program as an answer? – user157588 May 15 '20 at 08:28
  • 3
    Why don't you give it a go, and then we can point you in the right direction when you are stuck. You'll learn more that way – Ian Bush May 15 '20 at 08:34

0 Answers0