[Fwd: fortran read problem]

Xinan Zhou zhoux@lifepredictiontech.com
Thu Jun 13 08:29:00 GMT 2002


Hi, Tim, thank you for your response.

What I want to do is to port worked program on Linux to cygwin. In the
ported program, the input file needs to be parsed and one entire line is
read in each time. The input file has the following format:

*HEADING
Model: beam
*NODE
1,0.,0.,0.
2,1.,0.,0.
......
*ELEMENT, TYPE=C3D20R
1,1,2,3,4,13,14,15,16,5,6,
  7,8,17,18,19,20,9,10,11,12
......

being able to read in one entire line each time will make parsing terse.

It did pass the compile and give the executable with g77 testRead.f. And the
same test program gives correct results  on MS Fortran.

Could you tell me how to fix the incompatible mixture of fixed and free
format input or your
modified one? Can your modified one read the entire line?

Thank you very much!
Have a nice day!

Xinan

----- Original Message -----
From: "Tim Prince" <tprince@computer.org>
To: "Earnie Boyd" <Cygwin@cygwin.com>
Cc: "Xinan Zhou" <zhoux@lifepredictiontech.com>
Sent: Thursday, June 13, 2002 12:28 AM
Subject: Re: [Fwd: fortran read problem]


> On Wednesday 12 June 2002 06:27, Earnie Boyd wrote:
> > Asking me directly, even though you have difficulty is not your best
> > option.  I've forwarded to the list, this time, and have set the
> > Reply-To to the list.
> >
> > Earnie.
> >
> > -------- Original Message --------
> > Subject: fortran read problem
> >    Date: Wed, 12 Jun 2002 08:59:05 -0400
> >    From: "Xinan Zhou" <zhoux@lifepredictiontech.com>
> >      To: <earnie_boyd@yahoo.com>
> >
> > hi, Earnie, sorry to send you mail directly. I registered
> > cygwin@cygwin.com mailing list, and got the confirm message. But I tried
> > 2 days, failed to send the message to cygwin@cygwin.com. Could you tell
> > me whom should I contact about this? I searched mailing list and found
> > you had message about fortran read.I conpile on bash console with g77
> > testRead.f. I found fortran read(1, '(a40)') did not behave properly on
> > cygwin.
> >
> > the input file has
> > 1,1,2,3,4,5,6,7,ELEMENT,TYPE
> >
> > but it cannot read it correctly.
> >
> > any suggestions are appreciated.
> >
> > thank you and have a nice day!
> >
> > Xinan
> > PS: test code attached.
> >
> >       subroutine openfile()
> > !
> >       implicit none
> > !
> >       logical exi
> >       character*132 jobname,fnin,fndat,fnfrd,fnsta
> >       integer i
> >
> >    write(*,*) 'please enter input file name'
> >       read(*,*) fnin
> > !
> >       inquire(file=fnin,exist=exi)
> >       if(exi) then
> >          open(1,file=fnin,status='old')
> >       else
> >          write(*,*) '*ERROR in openfile: input file',fnin
> >          write(*,*) 'does not exist'
> >          stop
> >       endif
> > !
> >       return
> >       end
> >
> >
> >       subroutine getnewline(istat,in,n,key)
> > !
> >       implicit none
> > !
> > !     parser for abainput
> > !
> > !     n = # comma's +1,
> > !
> >       integer istat,in,n,key,i,j,k
> > !
> >       character*40 textpart(16)
> >       character*132 text
> > !
> > !     reading a new line
> > !
> >       do
> >          text=''
> >          read(in,'(a40)',iostat=istat) text
> >          if(istat.lt.0) then
> >             if(text.eq.'') then
> >                if(in.ne.1) then
> >                   close(2)
> >                   in=1
> >                   cycle
> >                else
> >                   return
> >                endif
> >             else
> >                istat=0
> >             endif
> >          endif
> >          if((text(1:8).eq.'*include').or.
> >      &          (text(1:8).eq.'*INCLUDE')) then
> > !           call include(text,in)
> >    write(*,*)'should not have include'
> >          elseif(text(1:2).eq.'**') then
> >          else
> >             exit
> >          endif
> >       enddo
> > !
> >       key=0
> > !
> > !     only free format is supported
> > !
> >       if((text(1:1).eq.'*').and.(text(2:2).ne.'*')) then
> >          key=1
> >       endif
> > !
> >       n=1
> >       j=0
> >       do i=1,40
> >          if(text(i:i).ne.',') then
> >             if(j.eq.0) then
> >                if(text(i:i).eq.' ') cycle
> >             endif
> >             j=j+1
> >             if(j.le.40) textpart(n)(j:j)=text(i:i)
> >          else
> >             do k=j+1,40
> >                textpart(n)(k:k)=' '
> >             enddo
> >             n=n+1
> >             j=0
> >          endif
> >       enddo
> >       if(j.eq.0) n=n-1
> >    write(*,*)'text = '
> >       write(*,'(a40)') text
> >    write(*,*)'n = ',n
> >    write(*,*)'textpart1=',textpart(1)
> >    write(*,*)'textpart2=',textpart(2)
> >    write(*,*)'textpart3=',textpart(3)
> >    write(*,*)'textpart4=',textpart(4)
> >    write(*,*)'textpart5=',textpart(5)
> >    write(*,*)'textpart6=',textpart(6)
> >    write(*,*)'textpart7=',textpart(7)
> >    write(*,*)'textpart8=',textpart(8)
> >    write(*,*)'textpart9=',textpart(9)
> >    write(*,*)'textpart11=',textpart(10)
> >    write(*,*)'textpart11=',textpart(11)
> >    write(*,*)'textpart12=',textpart(12)
> >
> >
> > !
> > !     clearing all textpart fields not used
> > !
> >       do i=n+1,16
> >          textpart(i)='                                        '
> >       enddo
> > !
> >       return
> >       end
> >
> >
> >    PROGRAM TEST_READ
> >   IMPLICIT NONE
> >
> >    integer istat, in, n, key
> >
> >    in = 1
> >
> >    call openfile()
> >
> >    call getnewline(istat, in, n, key)
> >
> >   END PROGRAM TEST_READ
> You shouldn't be able to compile this without fixing the incompatible
mixture
> of fixed and free format input.  My cygwin g77 versions had no difficulty
> with this, when I used binary/unix files, and fixed the source code
format.
> I still wouldn't trust libf2c I/O library to read DOS text format files,
and
> I can't tell if that was what you wished to do.
> --
> Tim Prince
>
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
>
>
>



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list