Re: [Question:]How to split one file into 3/4 using fortran?

From: Gary L. Scott (garyscott_at_ev1.net)
Date: 07/26/04

  • Next message: Jan Vorbrüggen: "Re: random_seed"
    Date: Mon, 26 Jul 2004 07:17:47 -0500
    
    

    "Gary L. Scott" wrote:
    >
    > andy wrote:
    > >
    > > Hi there:
    > > I have a question about how to split a file following into 3
    > > different files.
    > >
    > > The file is like this:
    > >
    > > #comments 1
    > > #....
    > > #....
    > > .
    > > .
    > > .
    > >
    > > 12 23 45 34 24 56
    > > 12 33 23 45 32 34
    > > 32 1 1 2 34 -9
    > > ...
    > > ...
    > > ...
    > >
    > > #comments 2
    > > #....
    > > #....
    > > .
    > > .
    > > .
    > >
    > > 12 23 45 34 24 56
    > > 12 33 23 45 32 34
    > > 32 1 1 2 34 -9
    > > ...
    > > ...
    > > ...
    > >
    > > #comments 3
    > > #....
    > > #....
    > > .
    > > .
    > > .
    > >
    > > 12 23 45 34 24 56
    > > 12 33 23 45 32 34
    > > 32 1 1 2 34 -9
    > > ...
    > > ...
    > > ...
    > >
    > > My question is how to skip the comments part and use array to extract
    > > the numbers from the file and store the numbers into three different
    > > files? I have several files like this. In every file, the size of the
    > > comment part and number part are the same, but they are different in
    > > different file. I don't know how to open the array to store the
    > > numbers because I do not know how large the array I need to open and I
    > > also do not know when the end of number part reachs.
    > >
    > > Any idea? Thanks in advance!
    >
    > Is this a homework question? I would probably read each record of the
    > file in as text and check each row to see if it has a "#" character in
    > the first character. If not, then you can use a read statement maybe
    > like:
    >
    > read ( textinput, '(6(i2,1x))', iostat=ierror ) iarray

    for clarity, you may want to do (or not):

    read ( textinput, '(6(i2,1x))', iostat=ierror ) ( iarray( l ), l=1,6 )

    >
    > to get the array of numbers. That's assuming each group of 6 numbers
    > can be a separate array, maybe it can't, but if your goal is to write it
    > as 3 separate files, who will know (do you have to submit the code or
    > just get the result)??
    >
    > Spliting the file is simply a matter of writing each "group" to a
    > different file.
    >
    > Now if you know the EXACT format (exact number of comments, exact number
    > of groups) you can just use a bunch of read statements with an
    > appropriate format for each record.
    >
    > --
    >
    > Gary Scott
    > mailto:garyscott@ev1.net
    >
    > Fortran Library: http://www.fortranlib.com
    >
    > Support the Original G95 Project: http://www.g95.org
    > -OR-
    > Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html
    >
    > Why are there two? God only knows.
    >
    > Democracy is two wolves and a sheep, voting on what to eat for dinner...
    > Liberty is a well armed sheep contesting the vote. - Thomas Jefferson

    -- 
    Gary Scott
    mailto:garyscott@ev1.net
    Fortran Library:  http://www.fortranlib.com
    Support the Original G95 Project:  http://www.g95.org
    -OR-
    Support the GNU GFortran Project:  http://gcc.gnu.org/fortran/index.html
    Why are there two?  God only knows.
    Democracy is two wolves and a sheep, voting on what to eat for dinner...
    Liberty is a well armed sheep contesting the vote. - Thomas Jefferson
    

  • Next message: Jan Vorbrüggen: "Re: random_seed"

    Relevant Pages

    • rs232...
      ... Hello Scott and everyone else who will read this post. ... //immediatelly assigned to this array. ... // from the rs232 port), ... I thank Scott and all members of the news groups that have helped me on the ...
      (microsoft.public.vc.language)
    • Re: [Question:]How to split one file into 3/4 using fortran?
      ... I don't know how to open the array to store the ... Now if you know the EXACT format (exact number of comments, ... Fortran Library: http://www.fortranlib.com Support the Original G95 Project: http://www.g95.org -OR- ... Liberty is a well armed sheep contesting the vote. ...
      (comp.lang.fortran)
    • Re: Passing arrays ByVal vs ByRef
      ... If you pass a reference type (such as an Array), you get a copy of the reference, not the type and this explains why your original array is modified when you modify the passed parameter. ... Thanks for the information, Scott. ... So I just assumed that the array that I was passing was using pass-by-value. ...
      (microsoft.public.dotnet.languages.vb)
    • Re: Passing arrays ByVal vs ByRef
      ... "Scott M." wrote in message ... If you pass a reference type (such as an Array), you get a copy of the reference, not the type and this explains why your original array is modified when you modify the passed parameter. ... So I just assumed that the array that I was passing was using pass-by-value. ...
      (microsoft.public.dotnet.languages.vb)
    • Re: Enumerated types
      ... Scott. ... I now understand enumerated types rather ... One alternative I could try, in the mean time, is to declare a string array ...
      (microsoft.public.access.formscoding)