Re: open and read a file [message #45861] |
Mon, 10 October 2005 16:09 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
ChiChiRuiz@gmail.com writes:
> Hi there, I know this is a very easy task to do, but for some reason I
> can't get it to work. I have a .img file into the IDL code folder
> (where I save all the source code), then I run the following lines:
>
> openr, 1, filepath('filename.img')
> image = fltarr(xsize, ysize, zsize)
> readu, 1, image
> close, 1
>
> but I keep getting error message that the system cannot find the file
> specified.
> I thought as long as the .img file is located in the source code
> folder, i don't need to list the full address. What did I do wrong?
You forgot to use PROGRAMROOTDIR. :-)
OpenR, lun, Filepath(Root_Dir=ProgramRootDir(), 'filename.img'), /Get
You can find it here:
http://www.dfanning.com/programs/programrootdir.pro
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: open and read a file [message #45863 is a reply to message #45861] |
Mon, 10 October 2005 14:35  |
Michael Wallace
Messages: 409 Registered: December 2003
|
Senior Member |
|
|
The file needs to be relative to your working directory in order for
this to work. Even if you have your file in the same directory as the
the source code, paths are resolved according to your working directory.
You can see your current working directory with
IDL> cd, CURRENT=current
IDL> print, current
It is this directory that's being added to the front of the filename.
For example, if the current directory were "/my/current/directory", the
file that you're attempting to open is actually
"/my/current/directory/filename.img" and probably not what you want.
HTH,
-Mike
ChiChiRuiz@gmail.com wrote:
> Hi there, I know this is a very easy task to do, but for some reason I
> can't get it to work. I have a .img file into the IDL code folder
> (where I save all the source code), then I run the following lines:
>
> openr, 1, filepath('filename.img')
> image = fltarr(xsize, ysize, zsize)
> readu, 1, image
> close, 1
>
> but I keep getting error message that the system cannot find the file
> specified.
> I thought as long as the .img file is located in the source code
> folder, i don't need to list the full address. What did I do wrong?
>
|
|
|