| 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.
|
|
|
|