How to read data with format codes? [message #70073] |
Sat, 13 March 2010 16:38  |
Adam Solomon
Messages: 11 Registered: July 2009
|
Junior Member |
|
|
Hi all, I've been pulling my hair out over using readf with a format
code. So I have a data file with three columns of floats, all
separated by a |. Here's an example:
| 355.9559189095| -79.4625574877| 0.279817 |
| 355.5057979042| -79.4067330132| 0.189663 |
| 359.5215546187| -79.7976864503| 0.161308 |
| 357.7890741750| -79.6427829568| 0.026100 |
| 354.7163524970| -79.3099884939| 0.026578 |
| 354.6329916471| -79.3061286761| 0.025486 |
| 0.0561720211 | -79.8234642170| 0.025670 |
| 357.3786228505| -79.5728335169| 0.000030 |
| 356.7569554568| -79.5138546776| 0.199416 |
| 355.0388858964| -79.3264538270| 0.190393 |
| 354.8099356150| -79.2912157538| 0.026006 |
| 352.5968356937| -79.0184276231| 0.207497 |
| 352.4362834602| -79.0094360366| 0.217226 |
| 0.1800716026 | -79.8081762850| 0.091767 |
| 359.0525340400| -79.7227001135| 0.205676 |
| 354.7045386126| -79.2652363648| 0.119250 |
So every format code I've used which has even come close to working
runs into issues at one point or another, probably because of the
variable spacing. I want to read this file into three arrays, or a
3xlots array, or whatever - just any way to read in this data!! It's
unbelievable that such a simple task is proving to be so difficult.
I won't bore you with all the format codes I've tried (none of which
have worked) but here's the most recent example:
data=fltarr(3,rows-100);the 100 is so i don't run into EOF issues yet,
just for testing
readf,lun,data,format='(3(2x,F0.0))'
The problems with this particular one are that when the first column
is longer (as in most of these examples), the minus sign doesn't get
read in the second column, and there may be issues reading the third
column (not sure; will look into it some more).
What's the appropriate way to read these data in?
|
|
|
Re: How to read data with format codes? [message #70135 is a reply to message #70073] |
Tue, 16 March 2010 08:59  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Mar 16, 11:26 am, "H. Evans" <bloggs...@googlemail.com> wrote:
> I would have thought the simplest solution using only IDL functions
> was:
>
> x = (read_ascii('test.lis',delim="|")).field1[[1,2,3],*]
That is right. I forgot that read_ascii can take just the delimiter as
a keyword, without needing the whole template.
|
|
|
Re: How to read data with format codes? [message #70141 is a reply to message #70073] |
Tue, 16 March 2010 07:26  |
H. Evans
Messages: 18 Registered: December 2009
|
Junior Member |
|
|
On Mar 14, 1:38 am, Adam Solomon <rampa...@gmail.com> wrote:
>
> What's the appropriate way to read these data in?
I would have thought the simplest solution using only IDL functions
was:
x = (read_ascii('test.lis',delim="|")).field1[[1,2,3],*]
H.
|
|
|
Re: How to read data with format codes? [message #70163 is a reply to message #70073] |
Sun, 14 March 2010 19:39  |
Gray
Messages: 253 Registered: February 2010
|
Senior Member |
|
|
On Mar 13, 8:38 pm, Adam Solomon <rampa...@gmail.com> wrote:
> Hi all, I've been pulling my hair out over using readf with a format
> code. So I have a data file with three columns of floats, all
> separated by a |. Here's an example:
>
> | 355.9559189095| -79.4625574877| 0.279817 |
> | 355.5057979042| -79.4067330132| 0.189663 |
> | 359.5215546187| -79.7976864503| 0.161308 |
> | 357.7890741750| -79.6427829568| 0.026100 |
> | 354.7163524970| -79.3099884939| 0.026578 |
> | 354.6329916471| -79.3061286761| 0.025486 |
> | 0.0561720211 | -79.8234642170| 0.025670 |
> | 357.3786228505| -79.5728335169| 0.000030 |
> | 356.7569554568| -79.5138546776| 0.199416 |
> | 355.0388858964| -79.3264538270| 0.190393 |
> | 354.8099356150| -79.2912157538| 0.026006 |
> | 352.5968356937| -79.0184276231| 0.207497 |
> | 352.4362834602| -79.0094360366| 0.217226 |
> | 0.1800716026 | -79.8081762850| 0.091767 |
> | 359.0525340400| -79.7227001135| 0.205676 |
> | 354.7045386126| -79.2652363648| 0.119250 |
>
> So every format code I've used which has even come close to working
> runs into issues at one point or another, probably because of the
> variable spacing. I want to read this file into three arrays, or a
> 3xlots array, or whatever - just any way to read in this data!! It's
> unbelievable that such a simple task is proving to be so difficult.
>
> I won't bore you with all the format codes I've tried (none of which
> have worked) but here's the most recent example:
>
> data=fltarr(3,rows-100);the 100 is so i don't run into EOF issues yet,
> just for testing
> readf,lun,data,format='(3(2x,F0.0))'
>
> The problems with this particular one are that when the first column
> is longer (as in most of these examples), the minus sign doesn't get
> read in the second column, and there may be issues reading the third
> column (not sure; will look into it some more).
>
> What's the appropriate way to read these data in?
I's just use readcol from Astrolib.
|
|
|