Below is the code that we have written to pull the data from the Geo-referenced (lat/long based) subset of a full size image using an EVF. It is running, but returning the error message "Type conversion error: Unable to convert given STRING to Float. Detected at: ENVI_DATA_TYPE_WRITE". I'm not sure what I'm doing wrong here - any suggestions?
PRO DrCrkRsz
COMPILE_OPT strictarr
;Restore all the base save files
ENVI, /restore_base_save_files
;Initialize ENVI and send all errors and warnings to the file batch_log
ENVI_BATCH_INIT, log_file='batch_log'
;Change directory to the Folder with Deer Creek
dir='D:\IDLTest\Full_Size_Data' ; for full size files
CD, dir
;Counts the number of available files.
;Open a Base image and associated ROI.
;This is done to convert the ROI in lat/long
;to pixel coords in the target files (loaded below)
BaseFileName='01_BaseImage19850831'
ENVI_OPEN_FILE, BaseFileName, R_FID=Bfid
ENVI_FILE_QUERY, Bfid, dims=Bdims, ns=Bns, nl=Bnl, nb=Bnb
;print, 'these are the base data', Bns, Bnl, Bnb
T_fid=lonarr(Bnb)+Bfid ; array with the band list plus the file id of the base file
pos=lindgen(Bnb) ; array with the band numbers
;
;
; Open the vector file that contains the rectangle that includes Deer Creek
DrcrkRec='DrcrkRec.evf'
DrcrkRec_id=ENVI_EVF_OPEN(DrcrkRec)
;get the vector information from file
ENVI_EVF_INFO, DrcrkRec_id, num_recs=num_recs, data_type=data_type, projection=projection, $
layer_name=layer_name
;Print, 'vecto info', num_recs, data_type, projection, layer_name
; create a variable to contain the records in the vector file (for us this should be 1)
record=ENVI_EVF_READ_RECORD(DrcrkRec_id, 0)
Xmap=record[0,*]
Ymap=record[1,*]
;
;
files=FILE_SEARCH('*Visible.hdr',COUNT=numfiles) ; for full size files
counter=0
WHILE(counter LT numfiles) DO BEGIN
name = files[counter]
namesplit = STRSPLIT(name, '.', /EXTRACT)
namefile = namesplit[0]
;Open the input file
ENVI_OPEN_FILE, namefile, R_FID=fid
IF (fid EQ -1) THEN BEGIN
ENVI_BATCH_EXIT
RETURN
ENDIF
PRINT, namefile ; print name of file
ENVI_FILE_QUERY, fid, DIMS = dims, NB = nb, DATA_TYPE=data_type ; Get the size of the image array.
print, 'datatype = ', data_type
ENVI_CONVERT_FILE_COORDINATES,fid, xf, yf, Xmap, Ymap
dims[0]=-1L ; type of dimensions long float
dims[1]=min(xf)-1 ; lower x corner - 0 based
dims[2]=max(xf)-1 ; uppper x corner - 0 based
dims[3]=min(yf)-1 ; same for y
dims[4]=max(yf)-1 ; again
;Use ENVI write file to save with new file name
outname = namefile +'_' + string(counter,FORMAT='(I2.2)')
print, outname
ENVI_WRITE_ENVI_FILE,namefile, DIMS=dims,OUT_NAME=outname, R_FID=fid, OUT_DT=4
; the following section uses numeric coordinates to
; create an output name for each file with numbers
;pos = LINDGEN(nb)
;outnametxt = 'TestFile_' + string(counter) + '.txt'
;OPENW, 100, 'TestOut.txt'
;ENVI_OUTPUT_TO_EXTERNAL_FORMAT, OUT_NAME=outnametxt, DIMS=dims, /ASCII, FID=fid, POS=pos
CLOSE, fid
counter=counter+1
ENDWHILE
END
|