Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

File Reading
Hi, All!

This might be a newbie question but I don't know the solution. So
forgive me if it is too simple.

I am planning to read a file in Fortran (CVF 6.6), which contains both
text and numbers. It is looks like this:
# text 1
12	34	56
# text 2
# text 3
12	34
The number records in each line are known but the positions of the text,
which is supposed to be the comments, are not. I hope I made the problem
clear.
What I want to do is exam each line before I read in, if it begins with
"#", I will ignore it. Otherwise, I will re-read the line and get the
numbers out.
I know this can be done easily in c but I could not find a simple
solution using Fortran. I would really appreciate if somebody could
offer me a solution.

Thanks!

Report this thread to moderator Post Follow-up to this message
Old Post
David Young
07-29-04 08:56 AM


Re: File Reading
David Young wrote:
> Hi, All!
>
> This might be a newbie question but I don't know the solution. So
> forgive me if it is too simple.
>
> I am planning to read a file in Fortran (CVF 6.6), which contains both
> text and numbers. It is looks like this:
> # text 1
> 12    34    56
> # text 2
>     # text 3
> 12    34
> The number records in each line are known but the positions of the text,
> which is supposed to be the comments, are not. I hope I made the problem
> clear.
> What I want to do is exam each line before I read in, if it begins with
> "#", I will ignore it. Otherwise, I will re-read the line and get the
> numbers out.
> I know this can be done easily in c but I could not find a simple
> solution using Fortran. I would really appreciate if somebody could
> offer me a solution.

Sounds like a homework problem.

My approach to this sort of problem is to read each line into a character st
ring "buffer",
examine the string for "#". If it's there, save the buffer string in a separ
ate "comments"
string. If it's not, use an internal read to extract the numbers from the bu
ffer string.

A variation on this would be to read the entire file line by line first to d
etermine the
number of comment and data lines and then allocate arrays to the required si
ze before
rewinding the file and reading them proper, like.

cheers,

paulv


Report this thread to moderator Post Follow-up to this message
Old Post
Paul Van Delst
07-29-04 08:56 AM


Re: File Reading
On Wed, 28 Jul 2004 14:31:43 -0500, David Young <davids9999@yahoo.com>
wrote in <ce8uur$eou$1@mozo.cc.purdue.edu>:
> I am planning to read a file in Fortran (CVF 6.6), which contains both
> text and numbers. It is looks like this:
> # text 1
> 12	34	56
> # text 2
> 	# text 3
> 12	34
> The number records in each line are known but the positions of the text,
> which is supposed to be the comments, are not. I hope I made the problem
> clear.
> What I want to do is exam each line before I read in, if it begins with
> "#", I will ignore it. Otherwise, I will re-read the line and get the
> numbers out.
> I know this can be done easily in c but I could not find a simple
> solution using Fortran. I would really appreciate if somebody could
> offer me a solution.

Standard way to do this is to read a line into a sufficiently-
large CHARACTER variable.  Examine the string for signs of a comment and
loop to the next read if found.  Then use an "iternal read" to read the
numbers from the string, and process them.  Internal reads are the same
for most purposes as normal reads except you give the name of the
character variable instead of an I/O unit number:

read(mystring,'(3i6)')i,j,k

--
Ivan Reid, Electronic & Computer Engineering,     ___     CMS  Collaboration
,
Brunel University.     Ivan.Reid@brunel.ac.uk             Room 40-1-B12, CER
N
KotPT -- "for stupidity above and beyond the call of duty".

Report this thread to moderator Post Follow-up to this message
Old Post
Dr Ivan D. Reid
07-29-04 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:28 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.