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

Home » Public Forums » archive » Re: ENVI header files in IDL
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
Re: ENVI header files in IDL [message #58947] Wed, 27 February 2008 09:36 Go to next message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
Raghu wrote:
> Hi,
>
> In IDL, i'm using filesearch function to read through files of certain
> types.
> Since an envi file has no specific extension, i'm not able to figure
> out how to sort out the files.
> Here's an example:
>
> Say i have 2 images in ENVI format. It would look like IMAGE1,
> IMAGE1.hdr,IMAGE2, IMAGE2.hdr.
> As you can see, its only the header file which has the extension. When
> i use the filesearch(image*), i am not
> able to ignore the header files. These header files are not to be
> processed.
>
> Any ideas of how to choose only the images and not the header files,
> as in this case ?
> I guess i could convert the files to IMG so that they have an
> extension, but there must be an easier way.
>
> Thanks,
>
> Raghu

Hi,
you can do a filesearch on the headers only
filesToOpen = filesearch('image*.hdr') --> all that start with 'image'
and ends with '.hdr')
then remove the last 4 characters from the strings. Test if the file
exists. If yes, open it. If not, try to add the common extensions (.dat,
then .img etc). Of course, sort the order of the extensions (nothing,
.dat etc) so that most images to process have the first extension (or
lack of extension).


here is a slightly different code that I use. The user select a file. If
there is no extension in that file, it is open. Otherwise, the code
looks for the file with the possible extensions.

fileToOpen = dialog_pickFile(path = searchFolder, GET_PATH =
searchFolder, /must_exist, title = title)

;If the user selected a .hdr, remove the extension and find the correct
one.
if (STRLOWCASE(strmid(fileToOpen,3, /REVERSE_OFFSET)) eq '.hdr') or
(STRLOWCASE(strmid(fileToOpen,3, /REVERSE_OFFSET)) eq '.aux') then begin
fileToOpen= strmid(fileToOpen, 0,strlen(fileToOpen)-4)

extensionNotFound = 1B
currentExtension = 0
tmpFileToOpen = fileToOpen
commonExtensions = ['.dat','.img']
while extensionNotFound and currentExtension lt
n_elements(commonExtensions) do begin
if FILE_TEST(tmpFileToOpen) eq 0 then begin
tmpFileToOpen = fileToOpen + commonExtensions[currentExtension]
currentExtension +=1
endif else begin
extensionNotFound = 0B
fileToOpen = tmpFileToOpen
endelse
endwhile

endif


Jean
Re: ENVI header files in IDL [message #58948 is a reply to message #58947] Wed, 27 February 2008 09:29 Go to previous messageGo to next message
Bob[3] is currently offline  Bob[3]
Messages: 60
Registered: December 2006
Member
On Feb 27, 10:39 am, David Fanning <n...@dfanning.com> wrote:
> Raghu writes:
>> In IDL, i'm using filesearch function to read through files of certain
>> types.
>> Since an envi file has no specific extension, i'm not able to figure
>> out how to sort out the files.
>> Here's an example:
>
>> Say i have 2 images in ENVI format. It would look like IMAGE1,
>> IMAGE1.hdr,IMAGE2, IMAGE2.hdr.
>> As you can see, its only the header file which has the extension. When
>> i use the filesearch(image*), i am not
>> able to ignore the header files. These header files are not to be
>> processed.
>
>> Any ideas of how to choose only the images and not the header files,
>> as in this case ?
>> I guess i could convert the files to IMG so that they have an
>> extension, but there must be an easier way.
>
> Are you feeling confident this morning? Charged up?
> If so, you may want to try to wrap your head around
> regular expressions. Here is where I would go for a
> start:
>
>   http://www.ittvis.com/codebank/search.asp?FID=311
>
> This points you to Mike Galloy's excellent article on
> the subject. I've been studying the damn things for years
> without making the slightest bit of progress, but maybe
> you will have more luck.
>
> Failing that, I think a WHERE statement to locate the
> parts of the file search array you want to keep
> (or eliminate) wouldn't be totally out of place. :-)
>
> 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.")- Hide quoted text -
>
> - Show quoted text -

Or, if you know you only have at max image0 thru image9:
result = FILE_SEARCH('image?')

Or if your known max is image99:
result = FILE_SEARCH('{image?,image??}')

(that is if you're not feeling up to regular expressions)
Re: ENVI header files in IDL [message #58952 is a reply to message #58948] Wed, 27 February 2008 07:39 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Raghu writes:

> In IDL, i'm using filesearch function to read through files of certain
> types.
> Since an envi file has no specific extension, i'm not able to figure
> out how to sort out the files.
> Here's an example:
>
> Say i have 2 images in ENVI format. It would look like IMAGE1,
> IMAGE1.hdr,IMAGE2, IMAGE2.hdr.
> As you can see, its only the header file which has the extension. When
> i use the filesearch(image*), i am not
> able to ignore the header files. These header files are not to be
> processed.
>
> Any ideas of how to choose only the images and not the header files,
> as in this case ?
> I guess i could convert the files to IMG so that they have an
> extension, but there must be an easier way.

Are you feeling confident this morning? Charged up?
If so, you may want to try to wrap your head around
regular expressions. Here is where I would go for a
start:

http://www.ittvis.com/codebank/search.asp?FID=311

This points you to Mike Galloy's excellent article on
the subject. I've been studying the damn things for years
without making the slightest bit of progress, but maybe
you will have more luck.

Failing that, I think a WHERE statement to locate the
parts of the file search array you want to keep
(or eliminate) wouldn't be totally out of place. :-)

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.")
Re: ENVI header files in IDL [message #59156 is a reply to message #58947] Mon, 10 March 2008 19:30 Go to previous message
raghuram is currently offline  raghuram
Messages: 32
Registered: February 2008
Member
On Feb 27, 10:36 am, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> Raghu wrote:
>> Hi,
>
>> In IDL, i'm using filesearch function to read through files of certain
>> types.
>> Since an envi file has no specific extension, i'm not able to figure
>> out how to sort out the files.
>> Here's an example:
>
>> Say i have 2 images in ENVI format. It would look like IMAGE1,
>> IMAGE1.hdr,IMAGE2, IMAGE2.hdr.
>> As you can see, its only the header file which has the extension. When
>> i use the filesearch(image*), i am not
>> able to ignore the header files. These header files are not to be
>> processed.
>
>> Any ideas of how to choose only the images and not the header files,
>> as in this case ?
>> I guess i could convert the files to IMG so that they have an
>> extension, but there must be an easier way.
>
>> Thanks,
>
>> Raghu
>
> Hi,
> you can do a filesearch on the headers only
> filesToOpen = filesearch('image*.hdr')   --> all that start with 'image'
> and ends with '.hdr')
> then remove the last 4 characters from the strings. Test if the file
> exists. If yes, open it. If not, try to add the common extensions (.dat,
> then .img etc). Of course, sort the order of the extensions (nothing,
> .dat etc) so that most images to process have the first extension (or
> lack of extension).
>
> here is a slightly different code that I use. The user select a file. If
> there is no extension in that file, it is open. Otherwise, the code
> looks for the file with the possible extensions.
>
>         fileToOpen = dialog_pickFile(path = searchFolder, GET_PATH =
> searchFolder, /must_exist, title = title)
>
>         ;If the user selected a .hdr, remove the extension and find the correct
> one.
>         if (STRLOWCASE(strmid(fileToOpen,3, /REVERSE_OFFSET)) eq '.hdr') or
> (STRLOWCASE(strmid(fileToOpen,3, /REVERSE_OFFSET)) eq '.aux') then begin
>                 fileToOpen= strmid(fileToOpen, 0,strlen(fileToOpen)-4)
>
>                 extensionNotFound = 1B
>                 currentExtension = 0
>                 tmpFileToOpen = fileToOpen
>                 commonExtensions = ['.dat','.img']
>                 while extensionNotFound and currentExtension lt
> n_elements(commonExtensions) do begin
>                         if FILE_TEST(tmpFileToOpen) eq 0 then begin
>                                 tmpFileToOpen = fileToOpen + commonExtensions[currentExtension]
>                                 currentExtension +=1
>                         endif else begin
>                                 extensionNotFound = 0B
>                                 fileToOpen = tmpFileToOpen
>                         endelse
>                 endwhile
>
>         endif
>
> Jean- Hide quoted text -
>
> - Show quoted text -

Hi,

I got a very simple answer to my question from James Jones on the
ITTVIS usergroup.

Here it is:

images=FILE_SEARCH('*[^\.{hdr}]', /QUOTE)

In this case, the file_search function ignores the hdr files and reads
in only whats left.
Credit to James Jones for this.

Thanks,
Raghu
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Is it possible to export graphics objects and direct graphics in the same file?
Next Topic: IDL batch indexing

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

Current Time: Wed Oct 08 19:30:34 PDT 2025

Total time taken to generate the page: 0.00430 seconds