02 Dec 2008 08:10 PM |
|
Hi,
I want to extract data from one ROI, and the data is in one daset of a file (MODIS). and I writes code like this:
///////////////////////// code below
PRO TEST1102,EVENT
NAMESTRING=DIALOG_PICKFILE(TITLE='PLEASE INPUT FILES',FILTER='*.HDF')
IF (N_ELEMENTS(NAMESTRING) EQ -1) THEN RETURN
ENVI_RESTORE_ROIS,'......\ data\ROITEST.ROI'
HDFID=HDF_SD_START(NAMESTRING)
INDEX=HDF_SD_NAMETOINDEX(HDFID,'250m 16 days NDVI')
VARID=HDF_SD_SELECT(HDFID,INDEX1)
ENVI_FILE_QUERY,VARID1,NS=NS,NL=NL,POS=POS
ROIIDS=ENVI_GET_ROI_IDS(NS=NS,NL=NL)
DATA=ENVI_GET_ROI_DATA(ROIIDS[0])
HELP,DATA
PRINT,DATA
PRINT,'THAT IS THE END OF THE PROGRAM'
END
///////////////////////// code above
and got an error like this:
//////////////////////// error info below
ENVI> test1102
Variable is undefined: DATA_TYPE.
Execution halted at: MAGIC_SPEC_ROI
ENVI_GET_ROI_DATA
TEST1102 ..............\test1102.PRO
WIDGET_PROCESS_EVENTS
$MAIN$
///////////////////////////// error info above
the yellow line is the error line. it costs me almost one day, but I can not fix it. can someone help me to find the reason?
I use the dataset ID as FID in function ENVI_FILE_QUERY and ENVI_GET_ROI_IDS, because I only want to extract data from one dataset of the file, not the whole file. Is that the reason?
by the way, if I remove the yellow line and its related PRINT command, It works well !
Thanks!
|
|
|
|
MariM Veteran Member
Posts:2396  
03 Dec 2008 03:02 PM |
|
I can't see in your example how 'VARID' can be passed as a FID. You need to open the file in ENVI to get a FID and you are only opening the file in IDL. What is the result of printing the results of the ENVI_FILE_QUERY? ENVI_GET_ROI_DATA also needs to be passed the FID and POS keywords. Have you tried using ENVI's routines to open the HDF dataset? You could use ENVI_OPEN_DATA_FILE with the /HDF_SD keyword to open the specific HDF dataset you are interested in processing and from this you would get a valid FID.
|
|
|
|
Deleted User New Member
Posts:  
04 Dec 2008 07:53 AM |
|
Hi,mminari, thank you for your reply.
In my example, I use ROIIDS=ENVI_GET_ROI_IDS(NS=NS,NL=NL) to get ROI IDs, the parameters is NS and NL , that is equal to use FID (VARID) as an parameter, yeah? And I use DIALOG_PICKFILE to open files and got their file name strings (which is useful for other part of the program). ENVI_OPEN_DATA_FILE uses a file name as essential param to open a file, and get its FID.
I think the probelm is, the file (say its ID is FID ) includes several datasets ( say their IDs are VARIDs), but I just want to use one dataset of the file, and suppose its id is VARID[i].
when I want to employ ENVI_GET_ROI_DATA, I need to use a file ID as a param, which ID should I use? FID or VARID[i]?
btw, Is there any function in ENVI / IDL that can open file and return both FID and FNAME at once?
thank you.
|
|
|
|
MariM Veteran Member
Posts:2396  
04 Dec 2008 08:17 AM |
|
VARID is not a valid FID in ENVI unless you open it using an ENVI routine which returns a FID. This is why I suggested using ENVI_OPEN_DATA_FILE with the HDF_SD keyword. You can use DIALOG_PICKFILE or ENVI_PICKFILE to get the FNAME and pass this to ENVI_OPEN_DATA_FILE. If you use the HDF routines in IDL to select your file, you will still need to open the file in ENVI to get a FID or use ENVI_SETUP_HEAD to generate an ENVI header file which can return a valid FID. You might look in the ENVI help under Common Keywords to read up about what a FID is and how it is used.
|
|
|
|
Deleted User New Member
Posts:  
04 Dec 2008 09:37 AM |
|
I got it, and now the program can process the data in the roi.Thank you
however, as I want to plot a time series VI (read from the ROI). and I use ENVI_SELECT function to return POS parameter, which will be used in ENVI_GET_ROI_DATA as a perameter, I have to select many times for this, EXCEPT, ENVI_SELECT ,Is there any routines that can return POS without any selection?
THANKS.
|
|
|
|
MariM Veteran Member
Posts:2396  
04 Dec 2008 11:11 AM |
|
If you need to process many data files and you do not want to interactively select them, then you can do something like the following:
;set up path to input and output files
input_path = 'c:\myInputData\'
;change to output directory where I want the processed files to be placed
cd, 'C:\myProcessedData\'
; search for data files in the specified directory to get 'fname'
files = FILE_SEARCH(input_path + '*.hdf', count=count)
IF (count EQ 0) THEN BEGIN
PrintF, 'No files were found to process'
ENDIF
for i=0, count-1 do begin
envi_open_data_file, files[i], r_fid=fid, /HDF_SD
if (fid eq -1) then begin
envi_batch_exit
return
endif
;calculate pos array
envi_file_query, fid, ns=ns, nl=nl, nb=nb
pos=lindgen(nb)
|
|
|
|
Deleted User New Member
Posts:  
04 Dec 2008 11:51 AM |
|
God, You're amazing...
I ?? You ! Man, Thank you.
|
|
|
|