Subject: Re: [Fwd: fortran read problem]
From: Tim Prince <[email-masked]>
To: Earnie Boyd <[email-masked]>
Cc: Xinan Zhou <[email-masked]>
Date: Wed, 12 Jun 2002 21:28:18 -0700

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" <[email-masked]>
>      To: <[email-masked]>
>
> hi, Earnie, sorry to send you mail directly. I registered
> [email-masked] mailing list, and got the confirm message. But I tried
> 2 days, failed to send the message to [email-masked]. 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/