reading files with date- and time - columns [message #23914] |
Mon, 26 February 2001 03:09  |
Zeschke
Messages: 2 Registered: December 2000
|
Junior Member |
|
|
Hallo,
I have files for example in such a format:
File : s.log
;DATE TIME n x VALUES
23.01.2001 08:39:41 21 21.4 0
23.01.2001 08:40:16 21 21.3 0
23.01.2001 08:40:51 21 21.3 0
23.01.2001 08:41:26 21 21.4 0
or such a format:
;DATE TIME n x VALUES
2/23/2001 08:39:41.643 34.660
2/23/2001 08:49:41.456 34.960
I cannot find a solution for reading the date- and timeformat. My best
result was this :
IDL> openr,1,'s.log'
IDL> readf,1,format='(C(CDI3,".",CMOI3,".",CYI4,"
",CHI2,":",CMI2,":",CSI2))',x
IDL> print,x
2.45193e+06
IDL> CALDAT, x, Month, Day, Year, Hour, Minute, Second
% Compiled module: CALDAT.
IDL>
IDL> print,Month, Day, Year, Hour, Minute, Second
1 23 2001 0 0 0.00000000
IDL> print,!version
{ alpha vms vms 5.4 Sep 25 2000 32 32}
IDL> close,1
But where are the hours, minutes and seconds.
Thanks in advance
Thomas Zeschke
|
|
|
Re: Reading files [message #64055 is a reply to message #23914] |
Sat, 29 November 2008 18:13  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Nov 29, 10:30 am, Wolfi <sfsdf.df...@yahoo.com> wrote:
> I'm trying to read a file, which is formed by words and numbers are
> follow
>
> name 0.2 4.1 6.0
> othename 1.6 3 .2 5.2
> ...
> etc etc ...
>
> Usually I have been using the routine readcol, which works just fine,
> though it's limited at max 25 column (and it's not so fast for very
> large array od data).
>
> I was thinking to use
>
> matrix=fltarr(size)
> openr,1,'myfile'
> readf,1,matrix
> close,1
>
> but of course it get stuck because the first row is actually a string.
> Any idea how to do?
You could always use sed or awk or something to get rid of the first
column before reading it into idl... something like:
matrix = fltarr(ncols,nrows)
spawn, 'sed -e "s/^[^ ]* //" < filename', strippedfile
reads, strippedfile, matrix
(of course, that assumes that you're using an OS that has sed)
> Question number two. I want to read different files, named
> file1,file2,file3 etc ...
> Is there any way I can use a counter something like
>
> for i=1,3 do begin
> readcol,'file"$i"'
>
> thanks in advance!
> M.
string(i, format='(%"file%d")')
-Jeremy.
|
|
|