comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: reading multiple data types into arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: reading multiple data types into arrays [message #54689] Tue, 10 July 2007 12:49
Josh is currently offline  Josh
Messages: 21
Registered: June 2007
Junior Member
On Jul 10, 12:57 am, greg.a...@googlemail.com wrote:
> On Jul 10, 12:36 am, Josh <joshuamonta...@gmail.com> wrote:
>
>
>
>> Hi,
>
>> I'm trying to read in data from a file that has the following format:
>
>> 231359152 09/25/2003 18:38:35.816 20.013574 25.668425
>> 626.779 14.396667
>
>> I'm having no problems getting the fourth, fifth, and sixth columns of
>> data into double arrays with a statement like this:
>
>> readf, lun, recNum, date, time, lat, lon, elev, geoid
>
>> and a for loop. But I would like to get the second column in an
>> array, too. My intuition says it should be a string because of the
>> nasty /'s in it (ultimately, I'd like these dates to be the
>> independant axis values).
>
>> I tried declaring the variable date as a string beforehand (date = '
>> '), but then that slurps the entire line (all columns) into that
>> variable. If I don't declare it as a string and try to put it into a
>> string array (strArr), it becomes 9.00000.
>
>> I'm reading the documentation for explicitly formatted input, but am
>> having trouble figuring out how to apply it here.
>
>> As always, all suggestions are greatly appreciated!
>> -Josh
>
> I'd probably read the whole line as a string then split it on the
> spaces with strsplit() and convert after. Better still, you might just
> read the whole file into a string array and chop it up with strpos()
> and strmid().
>
> Greg



Thanks, Greg. For me, this turned out to be the easiest way to
achieve this task. Much appreciated. -J
Re: reading multiple data types into arrays [message #54706 is a reply to message #54689] Tue, 10 July 2007 08:03 Go to previous message
Matt[2] is currently offline  Matt[2]
Messages: 69
Registered: March 2007
Member
Josh <joshuamontague@gmail.com> writes:
> I'm trying to read in data from a file that has the following format:
>
> 231359152 09/25/2003 18:38:35.816 20.013574 25.668425
> 626.779 14.396667
>
> I'm having no problems getting the fourth, fifth, and sixth columns of
> data into double arrays with a statement like this:
>
> readf, lun, recNum, date, time, lat, lon, elev, geoid


If you want to read it in one line. I'm going to take a stab.

; i_rec_ndx MM/DD/YYYY HH:MM:SS.sss Lat Lon i_elev(meters)
interpolated(i_gdHt)(meters)
;
; format='(%"%11d %2.2d/%2.2d/%4.4d %2.2d:%2.2d:%2.2d.%3.3d %10.6f
%10.6f %11.3f %15.6f")';


I think that should work for your data. Not that I have any knowledge
of how it's written....



--
Matthew Savoie - Scientific Programmer
National Snow and Ice Data Center
(303) 735-0785 http://nsidc.org
Re: reading multiple data types into arrays [message #54711 is a reply to message #54706] Tue, 10 July 2007 06:42 Go to previous message
Gadhavi is currently offline  Gadhavi
Messages: 5
Registered: February 2005
Junior Member
>> I tried declaring the variable date as a string beforehand (date = '
>> '), but then that slurps the entire line (all columns) into that
>> variable. If I don't declare it as a string and try to put

I also face the same problem as that of Josh. The real problem is to
have one column of string type with many columns to read. Currently I
handle this problem by either reading whole line as string and later
on splitting it, or using explicit format statement as mentioned in
previous two posts.

However, I wish there would have been someway to specify multiple
delimiter such as ",", "/", tab and spaces in one-go for free format
statement, that will make things much easier.

hari
Re: reading multiple data types into arrays [message #54714 is a reply to message #54711] Tue, 10 July 2007 04:28 Go to previous message
rkombiyil is currently offline  rkombiyil
Messages: 59
Registered: March 2006
Member
On Jul 10, 7:36 am, Josh <joshuamonta...@gmail.com> wrote:
> Hi,
>
> I'm trying to read in data from a file that has the following format:
>
> 231359152 09/25/2003 18:38:35.816 20.013574 25.668425
> 626.779 14.396667
>
> I'm having no problems getting the fourth, fifth, and sixth columns of
> data into double arrays with a statement like this:
>
> readf, lun, recNum, date, time, lat, lon, elev, geoid
>
> and a for loop. But I would like to get the second column in an
> array, too. My intuition says it should be a string because of the
> nasty /'s in it (ultimately, I'd like these dates to be the
> independant axis values).
>
> I tried declaring the variable date as a string beforehand (date = '
> '), but then that slurps the entire line (all columns) into that
> variable. If I don't declare it as a string and try to put it into a
> string array (strArr), it becomes 9.00000.
>
> I'm reading the documentation for explicitly formatted input, but am
> having trouble figuring out how to apply it here.
>
> As always, all suggestions are greatly appreciated!
> -Josh

I usually use structures for my needs. You could just declare them as
integers and read with a format specifier for these leaving out the
slashes.
Assuming data is like above and with the 'nX' denoting the number of
spaces I have between your data (in my file - may be different for
you.), you can use:
;type declaration
IDL> recnum=0L & day=0 & month=0 & yyyy=0
IDL> hh=0 & mm=0 & ss=0 & dec_sec=0
IDL> lat=0. & lon=0. & elev=0. & geoid=0.
;read data from lun=2
IDL>readf,2,recnum,day,month,yyyy,hh,mm,ss,dec_sec,$
lat,lon,elev,geoid,$
format='(i9,1x,2(i2,1x),i4,1x,3(i2,1x),i3,2(2x,f9.6),$
1x,f7.3,1x,f9.6)'
IDL>print,recnum,day,month,yyyy,hh,mm,ss,dec_sec,lat,lon,$
elev,geoid
231359152 9 25 2003 18 38 35
816 20.0136 25.6684 626.779 14.3967
--
I suggest using structures. I found them very helpful. And if you have
header information that you need to make use of, for your calculations
(I do), then open the file, read in those required header info first,
and then define structure for the (homogeneous) data part like above,
and then use "replicate" to populate.
--
Hth,
/rk
Re: reading multiple data types into arrays [message #54718 is a reply to message #54714] Mon, 09 July 2007 23:57 Go to previous message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
On Jul 10, 12:36 am, Josh <joshuamonta...@gmail.com> wrote:
> Hi,
>
> I'm trying to read in data from a file that has the following format:
>
> 231359152 09/25/2003 18:38:35.816 20.013574 25.668425
> 626.779 14.396667
>
> I'm having no problems getting the fourth, fifth, and sixth columns of
> data into double arrays with a statement like this:
>
> readf, lun, recNum, date, time, lat, lon, elev, geoid
>
> and a for loop. But I would like to get the second column in an
> array, too. My intuition says it should be a string because of the
> nasty /'s in it (ultimately, I'd like these dates to be the
> independant axis values).
>
> I tried declaring the variable date as a string beforehand (date = '
> '), but then that slurps the entire line (all columns) into that
> variable. If I don't declare it as a string and try to put it into a
> string array (strArr), it becomes 9.00000.
>
> I'm reading the documentation for explicitly formatted input, but am
> having trouble figuring out how to apply it here.
>
> As always, all suggestions are greatly appreciated!
> -Josh

I'd probably read the whole line as a string then split it on the
spaces with strsplit() and convert after. Better still, you might just
read the whole file into a string array and chop it up with strpos()
and strmid().

Greg
Re: reading multiple data types into arrays [message #54719 is a reply to message #54718] Mon, 09 July 2007 15:38 Go to previous message
Josh is currently offline  Josh
Messages: 21
Registered: June 2007
Junior Member
(to clarify: the example data I gave is all on one line. this post
makes it look like two lines on my computer) -josh
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: A Challenge?
Next Topic: Re: MOD43B3 Col.4 Processing. unexpected error message. why?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:10:08 PDT 2025

Total time taken to generate the page: 0.01574 seconds