Re: File Reading

From: Paul Van Delst (paul.vandelst_at_noaa.gov)
Date: 07/28/04


Date: Wed, 28 Jul 2004 16:54:28 -0400

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 string "buffer",
examine the string for "#". If it's there, save the buffer string in a separate "comments"
string. If it's not, use an internal read to extract the numbers from the buffer string.

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

cheers,

paulv



Relevant Pages

  • Re: Formatting String for Excel
    ... You can also use the Ext/Fract String to Number.vi (String conversion palette) to convert your string to a number, making sure that you have a double wired to the type input. ... http://forums.ni.com/attachments/ni/170/291609/1/save buffer string to excel 8.2.vi ...
    (comp.lang.labview)
  • Re: Proper way to input a dynamically-allocated string
    ... > I know it must sound like a newbie question, but I never really had to ... > array of char that's dynamically allocated. ... Every string container must have a ... for a really correct and useful solution you have to roll your ...
    (comp.lang.c)
  • Re: Newbie Q: Explain: string Name = dept.FindChairperson().Name
    ... Quick newbie question: I am NOT looking for some code solution - I am ... "FindChairperson" is a method within the dept object. ... The return type of FindChairperson has a property Name of type string (or a ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: sed command to replace text with blank spaces
    ... >Newbie question here. ... Using 'perl' also gives you the option to make the '.*' ... then inserting it back into the string. ...
    (comp.unix.shell)
  • String to Int
    ... Richard Blewett - DevelopMentor ... Kind of a newbie question, but I need to be able to convert a string to ...
    (microsoft.public.dotnet.languages.csharp)