MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Multiple Headers in Data File


Hi Chris,

> I would like to read in data from a data file that contains multiple
> headers. Each header line begins with  the pound character. I would like to
> read the data into a 2-D matrix. Note that I would like to test for the
> pound character since I don't know the exact number of header lines in each
> case.
> 
> Here is an example of the input data file:
> -----------------------------------------
> # beginning of file
> 
> # coherence data
> # nx=4 ny=5
> # x y y2
> 0.2     1.23    1.34E-9
> NaN     -2.454  0.23E12
> 2.3     -9      1.23E-4
> 
> # coherence data 2
> # nx=4 ny=5
> # x y y3
> -0.0    NaN     1.34E-9
> NaN     -2.454  -0.23E12
> 122.3   2.34    3.43E-4
> 3.12    NaN     4.5
> 
> #end of file
> ---------------------------
> 
> Then the 4x6 Matrix should look like this:
> 
> 0.2     1.23    1.34E-9                 -0.0    NaN     1.34E-9
> NaN     -2.454  0.23E12         NaN     -2.454  -0.23E12
> 2.3     -9      1.23E-4         122.3   2.34    3.43E-4
>                                 3.12    NaN     4.5
> Note that the first three entries in the 4th row are absent. It would be
> okay to fill the empty slots with either NaN or leave them blank all
> together. Whichever is easier to program.
> 
> Any ideas on how to read in such a matrix would be greatly appreciated.

After Skip[]'ing the first line, the way I'd be tempted to go would be 
to 

data = ReadList[..., Record, RecordSeparator->"coherence data"];

I would think it a straightforward task to pick off the array dimensions 
and to repartion the data.

Regards,

-- 
 ==================================================================
 David Annetts                                       _____________
 http://www.ocs.mq.edu.au/~dannetts/                |C R C A M E T|
                                                    |-------------|
                                                    |_____        |
 CRC for Australian Mineral                         |````` \      |
 Exploration Technologies                           |`````/$\     |
 Earth & Planetary Sciences                         |````/$$$\____|
 Macquarie University, NSW 2109                     |```/$$$/.....|
 AUSTRALIA                                          |``/$$$/......|
 phone: +(1-61-2) 9850 9280, fax (1-61-2) 9850 8366  -------------
 ==================================================================


  • Prev by Date: Re: BarChart Bug?
  • Next by Date: Re: ISING model
  • Previous by thread: Multiple Headers in Data File
  • Next by thread: ContourPlots,DensityPlots