Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:40:44+00:00 2026-06-03T07:40:44+00:00

I have an old Fortran program for reading records from text files. The records

  • 0

I have an old Fortran program for reading records from text files. The records are of the form:

record_type field1 field2 ... fieldN ;

These records might spread over several lines, the character ; shows that the record has finished. The old code is:

2 read(data,"(a130)",end=3)line
  shift=adrec(nbrec)-1
  read(line,*,end=1)typrec(nbrec),(field(shift+i),i=1,65)
1 do
    do j=shift+1,shift+i-1
      k=index(field(j),';')
      if(k .ne. 0)then
        if(k .eq. 1)then
          adrec(nbrec+1)=j
        else
          field(j)(k:)=''
          adrec(nbrec+1)=j+1
        endif
          go to 2
      endif
    endo
    read(data,"(a130)")line
    read(line,*,end=1)(field(shift+i),i=1,65)
  enddo
3 continue

This code works with Intel Compiler (ifort) as it is. With gfortran it fails! The first problem is that the implicit read on the third line, with ifort, gives i to be equal to the number of fields actually read, while in gfortran it always gives 65. The second problem is that in the same implicit read, with ifort, the character ; is read as a normal field but with gfortran is skipped.

Anyone can help me solve these two problems? Any other ideas for replacing the code all together are also welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:40:45+00:00Added an answer on June 3, 2026 at 7:40 am

    Does this work? Aside from do while (and exit control structures…), this is f77 compliant (I think). The do whiles could relatively easily be replaced by goto/continue if necessary. I don’t know what type you ultimately want the strings to be, so I return strings (and assume a field can’t be longer than 24 characters)…I also assume a “line” can’t be longer than 1024 characters.
    Sorry about the lack of comments, but the function names are descriptive enough I think. Generally, I think it is a good idea to use functions/subroutines when programming as that makes the code much more readible…

      program main
      character*1024 line
      integer stat,stat2,i,nf
      character*24 fld
      character*16 fmt
    
      open(unit=21,file='test.dat',status='old')
      stat=0
      do while(stat.eq.0)
         call readline(21,line,stat)
         stat2=0
         i=1
         do while(.true.)
            call getfield(line,fld,stat2)
            if(stat2.ne.0) exit
            i=i+1
            write(*,*) i,stat2,fld
         enddo
         write(*,*) " "
      enddo
    
    
      end
    
      subroutine getfield(line,field,stat)
      integer l,i,stat
      character*(*) line,field
      !Get first field and shift the line
      l=1
      if(line.eq.' ')then
         stat=1
      else
         stat=0
      endif
      do while (line(l:l).eq.' ')
         l=l+1
      enddo
      i=l
      do while (line(i:i).ne.' ')
         i=i+1
      enddo
    
      if((line(l:l).eq.'"').or.(line(l:l).eq."'"))then
         do while(line(i:i).ne.line(l:l))
            i=i+1
         enddo
      endif
    
      field=line(l:i)
      line=line(i+1:)
      return
      end
    
      subroutine readline(unit,line,stat)
      integer unit
      character*(*) line
      integer stat,i
      !read one "line"  Lines are sequences seperated by ';' (can have newlines in there) 
    
      stat=0
      i=1
      do while (.true.)
         read(unit,'(A)',end=100) line(i:)
         i=index(line,';')
         if(i.eq.0)then
            i=len_trim(line)+2
         else
            line(i:)=' ' !remove the trailing semicolon.
            exit
         endif
      enddo
    
      return
     100  continue
      stat=1
      return
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a old command line based program (its fortran if that matters) that
I have old .prc files (SQL Server Stored Procedures) which have exported from SQL
I have an old program pushing some data from a Microsoft SQL server database
I have some old fortran 77 I'm trying to port to gcc on Windows.
I have old code that uses size_t which IIRC comes from cstring.h. On OS
I have an old Fortran77 program that calls a C++ function and passes several
Today I was reading code from some very popular numerical libraries written in FORTRAN
I recently upgraded my computer, and moved from XP to Win7. We have old
I have some old (~1995) legacy fortran code which is compiled with g77 compiler
I have this old Fortran executable that can only be accessed through its GUI,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.