André Almeida
André Almeida

Reputation: 509

Fortran: read numeric data from string

I've already checked a similarly existing topic (How to read numeric data from a string in FORTRAN), but I'm not being able to do what I want.

I need to open a file and read a numeric value from a string. Bellow there's a section of the file in question. I want to read the integer next to 'ELEMENTS:', but so far I'm not being able to do so.

      ELEMENT GROUP 2.4.6
GROUP:          1 ELEMENTS:     187169 MATERIAL:          2 NFLAGS:          1
                           fluid
       0
       1       2       3       4       5       6       7       8       9      10
      11      12      13      14      15      16      17      18      19      20
      21      22      23      24      25      26      27      28      29      30
      31      32      33      34      35      36      37      38      39      40

Can someone please help me here?

Upvotes: 0

Views: 224

Answers (1)

André Almeida
André Almeida

Reputation: 509

Ok guys, thanks to your answers the program is working!

For further reference, here's the reading part of the code:

READ(77,'(A)') str
ipos = INDEX(str,"ELEMENTS:",back=.true.) + 9
READ (str(1+ipos:),*) k
PRINT*, k

Thank for the answers.

Upvotes: 1

Related Questions