Re: [Question:]How to split one file into 3/4 using fortran?
From: Gary L. Scott (garyscott_at_ev1.net)
Date: 07/26/04
- Previous message: Kurda Yon: "random_seed"
- In reply to: Gary L. Scott: "Re: [Question:]How to split one file into 3/4 using fortran?"
- Next in thread: glen herrmannsfeldt: "Re: [Question:]How to split one file into 3/4 using fortran?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: Kurda Yon: "random_seed"
- In reply to: Gary L. Scott: "Re: [Question:]How to split one file into 3/4 using fortran?"
- Next in thread: glen herrmannsfeldt: "Re: [Question:]How to split one file into 3/4 using fortran?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|