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

Home » Public Forums » archive » Re: read_ascii for many rows / possible to create automatic names for variables
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: read_ascii for many rows / possible to create automatic names for variables [message #57132] Wed, 05 December 2007 08:23 Go to next message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On Dec 5, 10:16 am, David Fanning <n...@dfanning.com> wrote:
> David Fanning writes:
>> I can't put my e-mail here because I already have
>> about 15 years supply of viagra.
>
> I can see I should have been clearer about this.
> This is left over from Coyote's order last month.
> He switched to Levitra after watching a commercial
> of some babe in a bathtub.
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Thanks for that chuckle this morning David, I really needed it.
Re: read_ascii for many rows / possible to create automatic names for variables [message #57135 is a reply to message #57132] Wed, 05 December 2007 08:16 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> I can't put my e-mail here because I already have
> about 15 years supply of viagra.

I can see I should have been clearer about this.
This is left over from Coyote's order last month.
He switched to Levitra after watching a commercial
of some babe in a bathtub.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57138 is a reply to message #57135] Wed, 05 December 2007 08:06 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Britta writes:

> this really confuses me. Sometimes i think i have a bad aura
> concerning computers :-). If you agree I would send you the original
> file for a short test, because at the moment i have no idea what my
> mistake is.
>
> The syntax I use is the copy of your suggestion (see below):
>
> ------------------------------------------------------------ ---
> rows = File_Lines('PATH\FILENAME.dat')
> Openr, lun, 'PATH\FILENAME.dat', /Get_Lun
> line = ""
> ReadF, lun, line
> cols = N_Elements(STRSPlit(line, ' ', /Extract))
> Point_lun, lun, 0
> data = FltArr(cols, rows)
> ReadF, lun, data
> Free_Lun, lun
>
> colMeans = Total(data, 2)/rows
>
> print, colMeans(6)
>
> end
> ------------------------------------------------------------ --------

Is 'PATH\FILENAME.dat' really the name of your file!?
I can see you have a literal programming mind. :-)

OK, look. You can't tell my wife about this, because
she thinks IDL consulting is what I get paid for. I can't
put my e-mail here because I already have about 15 years
supply of viagra. If you can figure out from my web page
how to e-mail me, send me the file, and I'll have a look
at it. But please name it something sensible before you
send it to me. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57139 is a reply to message #57138] Wed, 05 December 2007 07:57 Go to previous messageGo to next message
britta.mey is currently offline  britta.mey
Messages: 14
Registered: August 2007
Junior Member
On Dec 5, 4:40 pm, David Fanning <n...@dfanning.com> wrote:
> Britta writes:
>> The first column are seconds, second column - hour, third - minutes,
>> fourth - seconds (if idl doesn't count column 2 to 4 as one column) ,
>> sixth to tenth - data output from the spectrometer. The result of
>> colMeans(6) should be approximately 136 (more or less :-), in the
>> original file there are a lot more columns and also more rows). For
>> print, colMeans(6) i obtain 1974.44. :-(
>
> Well, if I take the data you sent me, and I run the program
> I sent you, then this is what I get:
>
> IDL> print, colmeans(6)
> 135.808
>
> So, I don't know what the problem might be.
>
> You will have a problem with that first column, since IDL won't
> read a number with two decimal points in it, but that is not
> changing things otherwise, and if you are not using the first
> column, I wouldn't worry about it.
>
>> Is the value 2 in colMeans = Total(data, 2)/rows the number of
>> dimensions? Why do i use 2? To obtain a 1-dimensional array (scalar)
>> as a result?
>
> The two indicates that the total should be obtained over the
> 2nd dimension. That is, over the rows. In other words, add up
> the values in the columns.
>
>> I'm quite sure that these are really stupid questions for you, so
>> thank you for your patience.
>
> No, the stupid questions I refuse to answer. :-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Hi,

this really confuses me. Sometimes i think i have a bad aura
concerning computers :-). If you agree I would send you the original
file for a short test, because at the moment i have no idea what my
mistake is.

The syntax I use is the copy of your suggestion (see below):

------------------------------------------------------------ ---
rows = File_Lines('PATH\FILENAME.dat')
Openr, lun, 'PATH\FILENAME.dat', /Get_Lun
line = ""
ReadF, lun, line
cols = N_Elements(STRSPlit(line, ' ', /Extract))
Point_lun, lun, 0
data = FltArr(cols, rows)
ReadF, lun, data
Free_Lun, lun

colMeans = Total(data, 2)/rows

print, colMeans(6)

end
------------------------------------------------------------ --------

Cheers,

Britta
Re: read_ascii for many rows / possible to create automatic names for variables [message #57140 is a reply to message #57139] Wed, 05 December 2007 07:40 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Britta writes:

> The first column are seconds, second column - hour, third - minutes,
> fourth - seconds (if idl doesn't count column 2 to 4 as one column) ,
> sixth to tenth - data output from the spectrometer. The result of
> colMeans(6) should be approximately 136 (more or less :-), in the
> original file there are a lot more columns and also more rows). For
> print, colMeans(6) i obtain 1974.44. :-(

Well, if I take the data you sent me, and I run the program
I sent you, then this is what I get:

IDL> print, colmeans(6)
135.808

So, I don't know what the problem might be.

You will have a problem with that first column, since IDL won't
read a number with two decimal points in it, but that is not
changing things otherwise, and if you are not using the first
column, I wouldn't worry about it.

> Is the value 2 in colMeans = Total(data, 2)/rows the number of
> dimensions? Why do i use 2? To obtain a 1-dimensional array (scalar)
> as a result?

The two indicates that the total should be obtained over the
2nd dimension. That is, over the rows. In other words, add up
the values in the columns.

> I'm quite sure that these are really stupid questions for you, so
> thank you for your patience.

No, the stupid questions I refuse to answer. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57142 is a reply to message #57140] Wed, 05 December 2007 07:22 Go to previous messageGo to next message
britta.mey is currently offline  britta.mey
Messages: 14
Registered: August 2007
Junior Member
On Dec 5, 3:48 pm, bmey <britta....@gmail.com> wrote:
> On Dec 5, 3:38 pm, David Fanning <n...@dfanning.com> wrote:
>
>
>
>> bmey writes:
>>> i'm still a beginner in programming, therefore the next question.
>
>> I thought you might be. :-)
>
>>> When i read the whole array, how can i then proceed? I want to calculate
>>> for each pixel (each column) the arithmetic mean of the values and
>>> store these mean values as a new variable.
>
>> I would do something like this.
>
>> rows = File_Lines('myfile.dat')
>> Openr, lun, 'myfile.dat', /Get_Lun
>> line = ""
>> ReadF, lun, line
>> cols = N_Elements(StrSplit(line, ' ', /Extract))
>> Point_lun, lun, 0
>> data = FltArr(cols, rows)
>> ReadF, lun, data
>> Free_Lun, lun
>
>> colMeans = Total(data, 2) / rows
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> Hi,
>
> thaks. I'll try and hope i will manage this :-).
>
> Britta

Hi,

first i am happy that there didn't appear an error message (i am great
in producing syntax errors), therefore i did it copy correctly. :-)

But something seems to be wrong, because either IDL sorts the results
in a different order or (what makes more sense for me) i made a
mistake.

A part of the file looks like this, for example:

41.857.653 11 37 36.653 140 138 138 142 138
41.858.825 11 37 37.825 140 136 134 139 136
41.859.956 11 37 38.956 140 142 135 143 140
41.860.098 11 37 40.098 139 140 137 142 140
41.861.240 11 37 41.240 141 141 137 142 138
41.862.391 11 37 42.391 142 137 134 140 138
41.864.523 11 37 43.523 140 141 138 142 135
41.865.645 11 37 44.645 140 136 134 142 136
41.866.796 11 37 45.796 138 140 135 141 135
41.867.928 11 37 46.928 139 138 138 141 140
41.868.060 11 37 48.060 138 138 135 144 136
41.869.241 11 37 49.241 141 138 140 144 137
41.870.333 11 37 50.333 140 137 132 143 138
41.871.484 11 37 51.484 140 139 137 142 135
41.873.596 11 37 52.596 142 139 136 140 137
41.874.708 11 37 53.708 141 137 137 141 138
41.875.859 11 37 54.859 137 137 133 142 138
41.876.971 11 37 55.971 140 136 135 142 135
41.877.073 11 37 57.073 140 140 135 140 136
41.878.224 11 37 58.224 142 141 133 143 136
41.879.346 11 37 59.346 138 139 136 140 137
41.880.437 11 38 00.437 140 138 133 141 139
41.882.599 11 38 01.599 140 140 137 142 137
41.883.711 11 38 02.711 139 135 137 141 135
41.884.822 11 38 03.822 139 138 138 141 138
41.885.914 11 38 04.914 140 140 137 142 136


The first column are seconds, second column - hour, third - minutes,
fourth - seconds (if idl doesn't count column 2 to 4 as one column) ,
sixth to tenth - data output from the spectrometer. The result of
colMeans(6) should be approximately 136 (more or less :-), in the
original file there are a lot more columns and also more rows). For
print, colMeans(6) i obtain 1974.44. :-(

Is the value 2 in colMeans = Total(data, 2)/rows the number of
dimensions? Why do i use 2? To obtain a 1-dimensional array (scalar)
as a result?

I'm quite sure that these are really stupid questions for you, so
thank you for your patience.

Britta
Re: read_ascii for many rows / possible to create automatic names for variables [message #57147 is a reply to message #57142] Wed, 05 December 2007 06:48 Go to previous messageGo to next message
britta.mey is currently offline  britta.mey
Messages: 14
Registered: August 2007
Junior Member
On Dec 5, 3:38 pm, David Fanning <n...@dfanning.com> wrote:
> bmey writes:
>> i'm still a beginner in programming, therefore the next question.
>
> I thought you might be. :-)
>
>> When i read the whole array, how can i then proceed? I want to calculate
>> for each pixel (each column) the arithmetic mean of the values and
>> store these mean values as a new variable.
>
> I would do something like this.
>
> rows = File_Lines('myfile.dat')
> Openr, lun, 'myfile.dat', /Get_Lun
> line = ""
> ReadF, lun, line
> cols = N_Elements(StrSplit(line, ' ', /Extract))
> Point_lun, lun, 0
> data = FltArr(cols, rows)
> ReadF, lun, data
> Free_Lun, lun
>
> colMeans = Total(data, 2) / rows
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Hi,

thaks. I'll try and hope i will manage this :-).

Britta
Re: read_ascii for many rows / possible to create automatic names for variables [message #57149 is a reply to message #57147] Wed, 05 December 2007 06:38 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
bmey writes:

> i'm still a beginner in programming, therefore the next question.

I thought you might be. :-)

> When i read the whole array, how can i then proceed? I want to calculate
> for each pixel (each column) the arithmetic mean of the values and
> store these mean values as a new variable.

I would do something like this.

rows = File_Lines('myfile.dat')
Openr, lun, 'myfile.dat', /Get_Lun
line = ""
ReadF, lun, line
cols = N_Elements(StrSplit(line, ' ', /Extract))
Point_lun, lun, 0
data = FltArr(cols, rows)
ReadF, lun, data
Free_Lun, lun

colMeans = Total(data, 2) / rows

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57152 is a reply to message #57149] Wed, 05 December 2007 06:05 Go to previous messageGo to next message
britta.mey is currently offline  britta.mey
Messages: 14
Registered: August 2007
Junior Member
On Dec 5, 2:55 pm, David Fanning <n...@dfanning.com> wrote:
> bmey writes:
>> as output from a spectrometer i obtain an ascii-file with many (more
>> than 1024) columns and a few hundred rows. Most of the columns (1024
>> of them) refer to a specific pixel of the spectrometer.
>> Is there an effective way to read this file and to obtain each column
>> as own variable? I do not want to type an own name for each of the
>> columns, so i hope that there is a way to have a "dynamic name".
>
>> Something like:
>
>> data=read_ascii(file) & data=data.(0)
>
>> pixel1=data(4,*)
>> pixel2=data(5,*)
>> ....
>> pixel1024=data(1027,*)
>
>> But to have idl to count from 1 to 1024.
>
>> I hope it is possible to understand what i want to do.
>
> I think you ought to be SURE that's what you want. It
> doesn't sound like a good idea to me. Just read the
> data all at once, and you have any column you like,
> just as an index into the data array.
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Hello,

i'm still a beginner in programming, therefore the next question. When
i read the whole array, how can i then proceed? I want to calculate
for each pixel (each column) the arithmetic mean of the values and
store these mean values as a new variable.
Until now i have only worked with only few columns, the readf command
and then continued with these (1,*)-dimensional arrays.

Thank you for your help,

Britta
Re: read_ascii for many rows / possible to create automatic names for variables [message #57153 is a reply to message #57152] Wed, 05 December 2007 05:55 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
bmey writes:

> as output from a spectrometer i obtain an ascii-file with many (more
> than 1024) columns and a few hundred rows. Most of the columns (1024
> of them) refer to a specific pixel of the spectrometer.
> Is there an effective way to read this file and to obtain each column
> as own variable? I do not want to type an own name for each of the
> columns, so i hope that there is a way to have a "dynamic name".
>
> Something like:
>
> data=read_ascii(file) & data=data.(0)
>
> pixel1=data(4,*)
> pixel2=data(5,*)
> ....
> pixel1024=data(1027,*)
>
> But to have idl to count from 1 to 1024.
>
> I hope it is possible to understand what i want to do.

I think you ought to be SURE that's what you want. It
doesn't sound like a good idea to me. Just read the
data all at once, and you have any column you like,
just as an index into the data array.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57199 is a reply to message #57153] Thu, 06 December 2007 07:10 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mike writes:

> I don't think this one will need regexps (although if you are entering
> a Buddhist monastery, a good foundation in regexps will help your
> meditation practice tremendously!). If no pattern is passed to
> strsplit, it splits on whitespace (runs of spaces or tabs). So
> strsplit(line, /extract) aught to do it.

Oh, that's helpful. I would have read the documentation,
but, well, you know.

Cheers,

David

P.S. I think you are right about that meditation practice! :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57202 is a reply to message #57153] Thu, 06 December 2007 06:52 Go to previous messageGo to next message
Mike[2] is currently offline  Mike[2]
Messages: 99
Registered: December 2005
Member
On Dec 5, 12:15 pm, David Fanning <n...@dfanning.com> wrote:

> The other alternative (besides shooting the programmer,
> I mean) is to use a regular expression as the column
> separator in StrSplit.

I don't think this one will need regexps (although if you are entering
a Buddhist monastery, a good foundation in regexps will help your
meditation practice tremendously!). If no pattern is passed to
strsplit, it splits on whitespace (runs of spaces or tabs). So
strsplit(line, /extract) aught to do it.

Mike

--
Whitespace: the other white meat: http://imgs.xkcd.com/comics/python.png
Re: read_ascii for many rows / possible to create automatic names for variables [message #57312 is a reply to message #57153] Wed, 05 December 2007 09:57 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Britta writes:

> Great, thank's a lot. This works. Could you please short explain what
> you have done? Or please tell me, if this is correct, what I
> understood...
>
> parts = StrSplit(line, '[ ' + String(9B) + ']+', /REGEX, /EXTRACT)
>
> Here you separate the string of the first line into substrings (in the
> previous version you told IDL with (.., ' ',..) that a blank charakter
> is the separator, correct?), and the part '[ ' + String(9B) + ']+', /
> REGEX, means that the pattern of the ascii file contains not only
> blank characters but any combination of blank characters and tabs. Am
> I right up to here?

Yes, you understand perfectly so far.

> So IDL moves forward starting from one column until the binary code is
> different from the code of a blank character or a tab and "knows" that
> there is the next column.

Well, you give IDL too much credit. :-)

I would say that what I am doing is separating the first line of
the file into "parts", based on finding either a blank character
or a tab character. I simply count the number of parts I find
and use that as a surrogate for the number of columns in the
file. This usually works brilliantly with just looking for
blank characters, but perhaps a better solution is to look
for all "white space characters". If we use the IDL definition,
we might look for blank characters, tabs, and commas. That way
we would pretty much cover all the bases. But mixing tabs and
spaces in a line!? Never seen that before.

> I wish you a nice day (for me it's time to leave off work).

Alas, I've got to work until midnight to make up all the time
I've lost fooling around here this morning. :-(

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57314 is a reply to message #57153] Wed, 05 December 2007 09:47 Go to previous messageGo to next message
britta.mey is currently offline  britta.mey
Messages: 14
Registered: August 2007
Junior Member
On Dec 5, 6:15 pm, David Fanning <n...@dfanning.com> wrote:
> Britta writes:
>> Thank you, the file is on its way.
>
> Ah, well, ain't that interesting!
>
> The problem here is that while *most* of your columns
> are separated by blank characters, two of your columns
> are separated by tabs. What this basically means is that
> you should find a gun and shoot the person who created
> this data file. :-)
>
> What is happening is that I used a blank character as
> the separator for calculating the number of columns in
> the file, and because of the two tabs, I come up two
> columns short in the calculation. I calculate 1030 and
> there are really 1032. Thus, my columns are totally
> messed up, and I never read all the data in the file.
>
> So, since these data files are probably identical from one
> run to the next, you could probably just use the number 1032
> for the number of columns and the code would work perfectly.
>
> The other alternative (besides shooting the programmer,
> I mean) is to use a regular expression as the column
> separator in StrSplit. As you are a beginner, and as this
> is something even I don't understand, we will leave it
> to our betters to fill us in on how THIS can be done. :-)
>
> My best guess is that it is something like this:
>
> parts = StrSplit(line, '[ ' + String(9B) + ']+', /REGEX, /EXTRACT)
> cols = N_Elements(parts)
>
> Hope that helps. I haven't see *this* problem before. :-)
>
> Cheers,
>
> David
>
> P.S. It looks to me like I got that expression right from the
> quick test I just ran.
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Great, thank's a lot. This works. Could you please short explain what
you have done? Or please tell me, if this is correct, what I
understood...

parts = StrSplit(line, '[ ' + String(9B) + ']+', /REGEX, /EXTRACT)

Here you separate the string of the first line into substrings (in the
previous version you told IDL with (.., ' ',..) that a blank charakter
is the separator, correct?), and the part '[ ' + String(9B) + ']+', /
REGEX, means that the pattern of the ascii file contains not only
blank characters but any combination of blank characters and tabs. Am
I right up to here?
So IDL moves forward starting from one column until the binary code is
different from the code of a blank character or a tab and "knows" that
there is the next column.

I wish you a nice day (for me it's time to leave off work).

Cheers,

Britta
Re: read_ascii for many rows / possible to create automatic names for variables [message #57317 is a reply to message #57153] Wed, 05 December 2007 09:21 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> P.S. It looks to me like I got that expression right from the
> quick test I just ran.

There were actually three tabs, so plug him at least
three times for me. The actual number of columns is 1033.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57318 is a reply to message #57153] Wed, 05 December 2007 09:15 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Britta writes:

> Thank you, the file is on its way.

Ah, well, ain't that interesting!

The problem here is that while *most* of your columns
are separated by blank characters, two of your columns
are separated by tabs. What this basically means is that
you should find a gun and shoot the person who created
this data file. :-)

What is happening is that I used a blank character as
the separator for calculating the number of columns in
the file, and because of the two tabs, I come up two
columns short in the calculation. I calculate 1030 and
there are really 1032. Thus, my columns are totally
messed up, and I never read all the data in the file.

So, since these data files are probably identical from one
run to the next, you could probably just use the number 1032
for the number of columns and the code would work perfectly.

The other alternative (besides shooting the programmer,
I mean) is to use a regular expression as the column
separator in StrSplit. As you are a beginner, and as this
is something even I don't understand, we will leave it
to our betters to fill us in on how THIS can be done. :-)

My best guess is that it is something like this:

parts = StrSplit(line, '[ ' + String(9B) + ']+', /REGEX, /EXTRACT)
cols = N_Elements(parts)

Hope that helps. I haven't see *this* problem before. :-)

Cheers,

David

P.S. It looks to me like I got that expression right from the
quick test I just ran.
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57330 is a reply to message #57138] Wed, 05 December 2007 08:25 Go to previous messageGo to next message
britta.mey is currently offline  britta.mey
Messages: 14
Registered: August 2007
Junior Member
On Dec 5, 5:06 pm, David Fanning <n...@dfanning.com> wrote:
> Britta writes:
>> this really confuses me. Sometimes i think i have a bad aura
>> concerning computers :-). If you agree I would send you the original
>> file for a short test, because at the moment i have no idea what my
>> mistake is.
>
>> The syntax I use is the copy of your suggestion (see below):
>
>> ------------------------------------------------------------ ---
>> rows = File_Lines('PATH\FILENAME.dat')
>> Openr, lun, 'PATH\FILENAME.dat', /Get_Lun
>> line = ""
>> ReadF, lun, line
>> cols = N_Elements(STRSPlit(line, ' ', /Extract))
>> Point_lun, lun, 0
>> data = FltArr(cols, rows)
>> ReadF, lun, data
>> Free_Lun, lun
>
>> colMeans = Total(data, 2)/rows
>
>> print, colMeans(6)
>
>> end
>> ------------------------------------------------------------ --------
>
> Is 'PATH\FILENAME.dat' really the name of your file!?
> I can see you have a literal programming mind. :-)
>
> OK, look. You can't tell my wife about this, because
> she thinks IDL consulting is what I get paid for. I can't
> put my e-mail here because I already have about 15 years
> supply of viagra. If you can figure out from my web page
> how to e-mail me, send me the file, and I'll have a look
> at it. But please name it something sensible before you
> send it to me. :-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")


Thank you, the file is on its way.

Concerning my brilliant names for paths and files... I think it
wouldn't be possible to use my path, so I didn't want to bore everyone
with really loooooooooong paths. :-D

Cheers,

Britta
Re: read_ascii for many rows / possible to create automatic names for variables [message #57939 is a reply to message #57153] Sat, 05 January 2008 10:00 Go to previous message
britta.mey is currently offline  britta.mey
Messages: 14
Registered: August 2007
Junior Member
On Jan 5, 4:56 pm, David Fanning <n...@dfanning.com> wrote:
> Britta writes:
>> a Happy New Year and a new question concerning this stuff. I'd like to
>> use a for loop to use this routine for many files of the same type,
>> but i end alway up in errors (loops are really one of my
>> infirmnesses).
>
>> How can i deal with this?
>
> Ah, yes. Well, you need a doctor. You have come to the
> right place if you want a loopy one. :-)
>
>> Where do i have to use the indices for the
>> different files?
>
> The best thing for you to do is to probably learn
> how to put a breakpoint in your code so you can
> walk through it a couple of times, understanding
> how it works. Once you do that, I can't imagine
> you ever having trouble with loop indices again.
> It might help to have a piece of paper and a pencil
> handy, as well as a clear idea of what it is you
> *expect* the program to do.
>
>> ###############################
>
>> files = FILE_SEARCH('E:\Dissertation\field_campaigns
>> \Megacities07\spectrometer
>> \Megacities07_2\PC1_VIS_VN3_VN1\cosinus_vn1\90\normal\VISA-
>> CH2_VIS2\ALBEDO*.dat',count=nfiles)
>> files_dif= FILE_SEARCH('E:\Dissertation\field_campaigns
>> \Megacities07\spectrometer
>> \Megacities07_2\PC1_VIS_VN3_VN1\cosinus_vn1\90\dark\VISA-
>> CH2_VIS2\ALBEDO*.dat',count=nfiles_dif)
>
>> for i=0,nfiles-1 do begin
>
>> rows = File_Lines(files)
>
> Your immediate problem is here. The purpose of the line above
> is to find out how many rows there are in the file you are
> about to read. You have passed it the whole list of files.
> Naturally, FILE_LINES is confused. :-)
>
> Since files is a long list, and since you are doing this
> is a loop, with the index I, you will want to subscript this
> list with the index in order to find the right file:
>
> rows = File_Lines(files[I])
>
> Or, if I wanted this code to be even clearer, I might write
> something like this:
>
> FOR j=0,nfiles-1 to BEGIN
> thisfile = files[j]
> rows = File_Lines(thisfile)
>
> It is not clear to me from your code what you expect to do
> with this data you are collecting from all these files,
> but perhaps we can solve that problem later. :-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")


Hello David,

thank you. I'll try this. The data files are the output of a
spectrometer (measurements of solar radiation) and the output of the
calibration respectively. :-)

Cheers,
Britta
Re: read_ascii for many rows / possible to create automatic names for variables [message #57940 is a reply to message #57153] Sat, 05 January 2008 07:56 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Britta writes:

> a Happy New Year and a new question concerning this stuff. I'd like to
> use a for loop to use this routine for many files of the same type,
> but i end alway up in errors (loops are really one of my
> infirmnesses).
>
> How can i deal with this?

Ah, yes. Well, you need a doctor. You have come to the
right place if you want a loopy one. :-)

> Where do i have to use the indices for the
> different files?

The best thing for you to do is to probably learn
how to put a breakpoint in your code so you can
walk through it a couple of times, understanding
how it works. Once you do that, I can't imagine
you ever having trouble with loop indices again.
It might help to have a piece of paper and a pencil
handy, as well as a clear idea of what it is you
*expect* the program to do.


> ###############################
>
> files = FILE_SEARCH('E:\Dissertation\field_campaigns
> \Megacities07\spectrometer
> \Megacities07_2\PC1_VIS_VN3_VN1\cosinus_vn1\90\normal\VISA-
> CH2_VIS2\ALBEDO*.dat',count=nfiles)
> files_dif= FILE_SEARCH('E:\Dissertation\field_campaigns
> \Megacities07\spectrometer
> \Megacities07_2\PC1_VIS_VN3_VN1\cosinus_vn1\90\dark\VISA-
> CH2_VIS2\ALBEDO*.dat',count=nfiles_dif)
>
> for i=0,nfiles-1 do begin
>
> rows = File_Lines(files)

Your immediate problem is here. The purpose of the line above
is to find out how many rows there are in the file you are
about to read. You have passed it the whole list of files.
Naturally, FILE_LINES is confused. :-)

Since files is a long list, and since you are doing this
is a loop, with the index I, you will want to subscript this
list with the index in order to find the right file:

rows = File_Lines(files[I])

Or, if I wanted this code to be even clearer, I might write
something like this:

FOR j=0,nfiles-1 to BEGIN
thisfile = files[j]
rows = File_Lines(thisfile)

It is not clear to me from your code what you expect to do
with this data you are collecting from all these files,
but perhaps we can solve that problem later. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: read_ascii for many rows / possible to create automatic names for variables [message #57941 is a reply to message #57199] Sat, 05 January 2008 07:27 Go to previous message
britta.mey is currently offline  britta.mey
Messages: 14
Registered: August 2007
Junior Member
On Dec 6 2007, 4:10 pm, David Fanning <n...@dfanning.com> wrote:
> Mike writes:
>> I don't think this one will need regexps (although if you are entering
>> a Buddhist monastery, a good foundation in regexps will help your
>> meditation practice tremendously!). If no pattern is passed to
>> strsplit, it splits on whitespace (runs of spaces or tabs). So
>> strsplit(line, /extract) aught to do it.
>
> Oh, that's helpful. I would have read the documentation,
> but, well, you know.
>
> Cheers,
>
> David
>
> P.S. I think you are right about that meditation practice! :-)
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")


Hello,

a Happy New Year and a new question concerning this stuff. I'd like to
use a for loop to use this routine for many files of the same type,
but i end alway up in errors (loops are really one of my
infirmnesses).

How can i deal with this? Where do i have to use the indices for the
different files?

###############################

files = FILE_SEARCH('E:\Dissertation\field_campaigns
\Megacities07\spectrometer
\Megacities07_2\PC1_VIS_VN3_VN1\cosinus_vn1\90\normal\VISA-
CH2_VIS2\ALBEDO*.dat',count=nfiles)
files_dif= FILE_SEARCH('E:\Dissertation\field_campaigns
\Megacities07\spectrometer
\Megacities07_2\PC1_VIS_VN3_VN1\cosinus_vn1\90\dark\VISA-
CH2_VIS2\ALBEDO*.dat',count=nfiles_dif)

for i=0,nfiles-1 do begin

rows = File_Lines(files)
Openr, lun, files(i), /Get_Lun
line = ""
ReadF, lun, line
parts = StrSplit(line, '[ ' + String(9B) + ']+', /REGEX, /EXTRACT)
cols = N_Elements(parts)
Point_lun, lun, 0
data = FltArr(cols, rows)
ReadF, lun, data
Free_Lun, lun
colMeans = Total(data, 2)/rows

dir(1,i,l)=colMeans[4:n_pixel+3]

endfor

##################################################

At the moment i get an error message for line "data=FltArr(cols,rows)"
-> FLTARR: Expression must be a scalar or 1 element array in this
context: ROWS.

Cheers,

Britta
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: array operations and memory consumption
Next Topic: pson + !p.multi + xyouts

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

Current Time: Wed Oct 08 19:18:05 PDT 2025

Total time taken to generate the page: 0.00868 seconds