forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

text files

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
Anonymous
Guest





PostPosted: Wed May 03, 2006 9:07 am    Post subject: text files Reply with quote

How do you get ftn95 to read textfiles not created by ftn95?
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed May 03, 2006 9:37 am    Post subject: text files Reply with quote

If you know what is in the file you can use a standard Fortran READ statement after opening with OPEN.
Details can be found in any standard Fortran textbook.

At a lower level you can use the FTN95 READF@ and it associated routines. See the FTN95 help file for further information.
Back to top
View user's profile Send private message AIM Address
joeraney



Joined: 03 May 2006
Posts: 1

PostPosted: Wed May 03, 2006 11:17 am    Post subject: text files Reply with quote

I can OPEN and READ data files created by ftn95 but cannot OPEN non-ftn data files. HELP and ftn95 manual do not help, nor does debug info. Thanks.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed May 03, 2006 12:19 pm    Post subject: text files Reply with quote

Joseph

You can OPEN and READ any text file provided that you know what to expect and you create FORMAT expressions to match what is present in the file. If you were to use "list-directed" input then things might get a little tricky but you can certainly use formatted input.

The place to start is to read the IO chapter in a standard Fortran text book.
Back to top
View user's profile Send private message AIM Address
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Tue May 16, 2006 6:25 pm    Post subject: text files Reply with quote

You could open the file as transparent, and then read the file 1 character at a time.
You then have to interpret all the characters in the file, including <cr> and <lf>, as these can differ between Windows and Mac.
There is a problem with the fortran I/O libraries converting the tab character, but that can be turned off with a call to READ_TABS@(unitno)

Below is a sample of my code for reading RTF files using this method. I don't guarantee that the RTF reading logic is correct, but it gives an idea of addressing some control type characters.

open (unit=11, &
file=file_name, &
status='OLD', &
form='UNFORMATTED', &
access='TRANSPARENT', &
iostat=iostat)
write (*,*) 'Opening file ',trim(file_name),' iostat =',iostat
!
do i = 1,mc
read (unit=11, iostat=iostat) c
!
if (iostat /= 0) then
write (*,*) 'IOSTAT =',iostat
call write_line (line,n)
exit
end if
!
nc = nc+1
rtf_file(nc:nc) = c
!
ic = ichar(c)
if (ic >= 32 .AND. ic < 128) then
n = n+1
if (n <= len(line)) line(n:n) = c
if (n > m) m = n
!
if (c == '{') then ! new level reached
ii = nc - last_char
if (ii > 0) call write_rtf (rtf_file(last_char:nc-1), ii, rtf_count, m_rtf)
last_char = nc
levels = levels+1
if (levels > 512) then
write (*,*) ' In excess of 512 levels found at', i
stop
else
levels_in(levels) = ii
end if
else if (c == '}') then
ii = nc+1 - last_char
if (ii > 0) call write_rtf (rtf_file(last_char:nc), ii, rtf_count, m_rtf)
last_char = nc+1
write (*,*) ' end of level',levels,' found;',nc-levels_in(levels),' characters'
if (levels > 1) levels = levels-1
end if
else
if (n > 0) l = l+1
select case (ic)
case (13)
cr = cr+1
if (n==0) nul = nul+1
case (10)
lf = lf+1
case default
ot = ot+1
end select
call write_line (line,n)
! write (*,1001) iostat, ic
end if
!1001 format (i0,' <',i0,'>')
end do
Back to top
View user's profile Send private message
Anonymous
Guest





PostPosted: Sun May 21, 2006 1:50 pm    Post subject: text files Reply with quote

Thanks for your efforts, John, but as I anticipated, your program exited without reading a single character since iostat was -1. I am using Salford's personal (free) version of ftn95 on a Compaq computer. Is there a possibility that this free version is an inducement to buy by restricting the version to reading files produced by the free compiler? Such are the only files I can read!
Back to top
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sun May 21, 2006 5:44 pm    Post subject: text files Reply with quote

iostat = -1, implies an end of file.
What is the file you are using ?
Can you look at it with notepad ?
What is the directory information with regard to size ?
If it has information in it you should be able to read it. I have not experienced a problem, even with binary information. You should test the "character" c for not being a printable character. For text files, values < 32 are control characters, such as line feed or cariage return. Characters > 127 are not expected DOS characters, as they have the parity (8th) bit set. You have not indicated the source of the source of the file.
I'm not sure of all the conditions that could lead to a premature "end of file".
If DIR says there is information in it, then you should be able to read it.
You could check IOSTAT in the open.

I'm sure it is not the free nature of FTN95.
Back to top
View user's profile Send private message
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Mon May 22, 2006 4:13 am    Post subject: text files Reply with quote

The only way the personal edition of FTN95 differs from the licensed version is the banner that is displayed when a program compiled with the personal edition is ran.
Back to top
View user's profile Send private message
Anonymous
Guest





PostPosted: Wed May 24, 2006 4:48 pm    Post subject: text files Reply with quote

Must be something wrong with my computer then! I have made innumerable attempts to read text(data) files created by Notepad and Wordpad. I get nothing but -1 for iostat. Does the compiler not recognize these files? I cannot get FTN95 to read ANY files except when I create and read them within a program.
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu May 25, 2006 12:35 am    Post subject: text files Reply with quote

The only way forward is for you to post your program here together with a copy of the text file that you want to read.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu May 25, 2006 2:37 am    Post subject: text files Reply with quote

The text file that you are reading should be in the same folder as the executable otherwise you must give the full path of the text file when you open it.

In order to make sure that you are finding the input file you should use STATUS="OLD" in the OPEN statement. You should also check an IOSTAT variable after opening.
Back to top
View user's profile Send private message AIM Address
Anonymous
Guest





PostPosted: Fri Jun 09, 2006 9:20 am    Post subject: text files Reply with quote

Thank you, Paul--
I must have missed reading in my manuals about keeping programs and files in the same folder or else identify the PATH in detail. It was a simple but very frustrating problem to a novice using FTN95. It is a good thing that you have done. Thank you very much!!!!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group