ASCII import [message #48004] |
Sun, 26 March 2006 11:56  |
none
Messages: 6 Registered: March 2006
|
Junior Member |
|
|
Hi, i have to import a number of ASCII .txt files and save them as ENVI
standard images, but I can not found any IDL script able to do this; do
you know which is the code ENVI uses to to open generic format-ASCII
data ?
thanks
m
|
|
|
|
Re: ASCII import [message #48096 is a reply to message #48004] |
Tue, 28 March 2006 16:12   |
Jeff N.
Messages: 120 Registered: April 2005
|
Senior Member |
|
|
Ok, so now I think we're getting somewhere. What are the dimensions of
the final image though? Is it supposed to be a one column image as
well - so that the single column of ASCII input becomes a single column
image on output? If not, how do you know how to fill the output image?
Assuming that the first number in the text file is the value for pixel
[0,0], is the second number in the file for pixel [0,1], or is it for
[1,0], etc? You have to be able to describe all of this, which is why
it's impossible to just have one function that reads any ASCII file :)
Jeff
none wrote:
> hi jeff, thanks for replying; well, the txt file just consist of 1
> column of numbers, without semicolumns or commas separating them, and
> it should yield a one-band image, double precision data type.
> it looks like something like this..
> 0.3798
> -0.0277
> -0.0357
> -0.0287
> -0.0550
> -0.0415
> -0.0666
> -0.0868
> -0.0823
> -0.1248
>
> thanks
> marco
|
|
|
|
|
|
|
Re: ASCII import [message #48186 is a reply to message #48095] |
Wed, 29 March 2006 07:16  |
lbusett@yahoo.it
Messages: 30 Registered: February 2006
|
Member |
|
|
Hi Marco,
What about something like this ?
pro multiple_conversion
; Define image dimensions
n_col = 2400L
n_row = 2400L
arr_dim = n_col*n_row
tmp_array = fltarr (arr_dim)
; Select Input Files
file_list = dialog_pickfile ( title = 'Select files to convert',
/multiple_files)
; Begin the for loop to convert each file
for file = 0, n_elements(file_list-1) do begin
openr, in_lun, file_list [file], /get_lun ; Open the file
readf, in_lun, tmp_array ; Store data in a temporary array
;"Create" a square image from tmp_array
tmp_image = reform (tmp_array, n_col,n_row)
out_filename = file_list[file] + '_envi' ; Define output file
; Write envi output file
ENVI_WRITE_ENVI_FILE, tmp_image, out_name=out_filename free_lun,
in_lun
endfor
end
I didn't test it, so it's possible that it doesn't work, but I think
that this is a possible approach: Just select the files that you need
to convert, then read one file at a time with a simple READF
instruction, "reform" the data into a square matrix and write an output
with the ENVI dedicated write function (ENVI_WRITE_ENVI_FILE). You just
have to be sure that there is no header in your .txt files: otherwise,
you have to skip the header lines before you read "tmp_array".
Hope this helps,
Lorenzo
none wrote:
> well jeff, thanks for your patience...
> the file is made of 5,760,000 numbers, resulting in an image of 2400
> columns * 2400 rows. the second number should be the pixel [0,1] and so
> on, till the number #2401 that becomes the pixel [1,1].
> thanks
> marco
|
|
|