comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: read_ascii for many rows / possible to create automatic names for variables

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.")
creator: David Fanning
date: 2007-12-05T13:55:58-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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
creator: britta.mey
date: 2007-12-05T14:05:51-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.")
creator: David Fanning
date: 2007-12-05T14:38:00-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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
creator: britta.mey
date: 2007-12-05T14:48:10-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.8…
creator: britta.mey
date: 2007-12-05T15:22:19-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.")
creator: David Fanning
date: 2007-12-05T15:40:38-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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 = ""…
creator: britta.mey
date: 2007-12-05T15:57:23-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.")
creator: David Fanning
date: 2007-12-05T16:06:12-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.")
creator: David Fanning
date: 2007-12-05T16:16:35-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.
creator: Vince Hradil
date: 2007-12-05T16:23:53-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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
creator: britta.mey
date: 2007-12-05T16:25:44-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.")
creator: David Fanning
date: 2007-12-05T17:15:40-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.")
creator: David Fanning
date: 2007-12-05T17:21:11-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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 subs…
creator: britta.mey
date: 2007-12-05T17:47:40-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.")
creator: David Fanning
date: 2007-12-05T17:57:55-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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
creator: Mike[2]
date: 2007-12-06T14:52:01-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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.")
creator: David Fanning
date: 2007-12-06T15:10:45-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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. Che…
creator: britta.mey
date: 2008-01-05T15:27:15-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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. :-…
creator: David Fanning
date: 2008-01-05T15:56:12-00:00

Re: read_ascii for many rows / possible to create automatic names for variables
type: item
description: 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 clea…
creator: britta.mey
date: 2008-01-05T18:00:42-00:00