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

Home » Public Forums » archive » Error message opening a file in IDL script
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
Error message opening a file in IDL script [message #67954] Thu, 03 September 2009 09:28
Nicolas is currently offline  Nicolas
Messages: 15
Registered: September 2007
Junior Member
Hi everyone,

I have written a code on IDL which allows me to define a projection
for some TIFF data and save then the data in ENVI files.

I have been testing the script which was working. However, since some
time, I get the following error message:

--------------------------------------------
% Attempt to call undefined procedure/function: 'ENVI_READ_TIFF'.
% Execution halted at: ENVI_OPEN_EXTERNAL_FILE
% ENVI_OPEN_DATA_FILE
--------------------------------------------

I think that the problem comes from the compilation of the ENVI
commands but I still haven't find a solution.

After not working on my machine, I have tested the script on another
machine. It has been working a few times but I got then the same error
message.

Does anyone have an idea why?

Here's the full script:


------------------------------------------------------------ ---------------------------------------------

PRO defineprojection

; First restore all the base save files.
envi, /restore_base_save_files
ENVI_BATCH_INIT, LOG_FILE = 'batch.log'

;select the data (.tif files)
file=Dialog_Pickfile(path='D:\04_Jena\10_Enviland2_AP3320_Da ten
\1_Vorprozessierung\Optische_Daten\DOP\4358000_5622000_FARB' , /READ, /
MULTIPLE_FILES, FILTER = '*.tif')
print, 'file', file

;process for each file
for i=0, n_elements(file)-1 DO BEGIN
;define filename without ".tif"
fname = strmid(file[i], 0, strlen(file[i])-4)
inname = fname + '.tif'
print, inname

;open file
ENVI_OPEN_DATA_FILE, inname, r_fid=fid, /TIFF
if (fid eq -1) then begin
print, 'error reading file'
return
endif

;get info from the opened file
ENVI_FILE_QUERY, fid, NS = ns, NL = nl, NB = nb, dims = dims
; print, 'ns', ns
; print, 'nl', nl
; print, 'nb', nb

;get map and projection info
map_info = envi_get_map_info(fid = fid)
proj_info = ENVI_GET_PROJECTION(FID=fid, PIXEL_SIZE=pix_size_info,
UNITS=units_info)
;print, 'map_info', map_info
;print, 'proj_info', proj_info
;print, 'pix_size_info', pix_size_info
;print, 'units_info', units_info

; Set the dimension parameters (not needed here)
;m_dims = [-1L, 0, ns - 1, 0, nl - 1]
;print, 'm_dims', m_dims

; Set the POS parameter (3 bands)
pos = LINDGEN(nb)
bnames = ['R', 'G', 'B']
outname = fname + '_gs'

;set size of the data
xsize = map_info.ps[0]
ysize = map_info.ps[1]
ps = [xsize , ysize]

;set projection parameters
datum = 'WGS-84'
name = 'Gauss-Kruger Zone 4'
units = envi_translate_projection_units('Meters')

;data type
type = 3

;set upper left corner starting values and number of sample and
lines
mc3 = map_info.mc[2]
mc4 = map_info.mc[3]
mc = [0, 0, mc3 , mc4]

;set projection ellipsoïd parameters (Transverse Mercator)
params = [6378137.0, 6356752.3, 0.000000, 12.000000, 4500000.0, 0.0,
1.000000]

;create Projection structure and Map structure
proj = ENVI_PROJ_CREATE(DATUM=datum, TYPE = type, PARAMS = params,
NAME=name, UNITS=units)
map = ENVI_MAP_INFO_CREATE(DATUM=datum, params=params, PROJ=proj,
MC=mc, NAME=name, TYPE=type, UNITS=units, PS=ps)
;print, 'map = ', map
;print, 'proj = ', proj

filetype = ENVI_FILE_TYPE('ENVI Standard')

;initialize data
data=bytarr(ns, nl, nb)
;get data in a variable for each bands
for j=0, nb-1 do begin
inband = envi_get_data (fid=fid,dims=dims,pos=j)
data[*,*,j]=inband
j++
endfor
;help, data

;create envi file + hdr
;To write ENVI file (+ a header file + open data on Available bands)
ENVI_WRITE_ENVI_FILE, data, file_type=filetype, bnames=bnames,
WAVELENGTH_UNIT=6, byte_order=0, out_name=outname, ns=ns, nl=nl,
nb=nb, interleave=0, data_type=1, offset=0, map_info=map, /write, /
open
;NO_OPEN, /NO_WRITE

;to write only a header file
;ENVI_SETUP_HEAD, bnames=bnames, WAVELENGTH_UNIT=6, byte_order=0,
fname=outname, ns=ns, nl=nl, nb=nb, interleave=0,
data_type=1,offset=0, map_info=map, /open
;
;to just open data on Available bands
;ENVI_ENTER_DATA, data, bnames=bnames, file_type=filetype,
WAVELENGTH_UNIT=6, map_info=map

;delete input file from memory
envi_file_mng, id=fid, /remove

;convert to utm32
;ENVI_CONVERT_PROJECTION_COORDINATES

;increments
i++
ENDFOR

end

------------------------------------------------------------ ---------------------------------------------

Cheers,

Nico
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Assigning structure variables
Next Topic: BIL to BSQ in chunks

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

Current Time: Wed Oct 08 19:43:58 PDT 2025

Total time taken to generate the page: 0.00644 seconds