Re: a strange loop problem [message #60941] |
Tue, 24 June 2008 06:36 |
bulrushmower
Messages: 19 Registered: February 2008
|
Junior Member |
|
|
On Jun 24, 2:33 am, Anthony <anthonysmit...@gmail.com> wrote:
> On Jun 24, 3:53 am, bulrushmo...@gmail.com wrote:
>
>
>
>
>
>> What is wrong with the loop for the following:
>> i=0
>> Print, 'SDS_NAME'+STRTRIM(string(i+1),2), prints SDS_NAME01
>> But, Band = hdf_sd_nametoindex(file, 'SDS_NAME'+STRTRIM(string(i+1),
>> 2)) is not the same with
>> Band = hdf_sd_nametoindex(file, SDS_NAME01 )
>> ==========================================
>> SDS_NAME01 = "SREFL_CH1"
>> SDS_NAME02 = "SREFL_CH2"
>> SDS_NAME03 = "BT_CH3"
>> SDS_NAME04 = "BT_CH4"
>> SDS_NAME05 = "BT_CH5"
>> SDS_NAME06 = "SREFL_CH3"
>> SDS_NAME07 = "SZEN"
>> SDS_NAME08 = "VZEN"
>> SDS_NAME09 = "RELAZ"
>> SDS_NAME10 = "QA"
>
>> file = hdf_sd_start(fPath_data
>> +"AVH09C1.A1998180.N14.002.2007273131632.hdf")
>
>> for i=0, 9 do begin
>> Band = hdf_sd_nametoindex(file, 'SDS_NAME'+STRTRIM(string(i+1),2))
>> data = hdf_sd_select(file, Band)
>> hdf_sd_getdata, data, getdata
>> hdf_sd_endaccess, data
>
>> endfor
>
> Band = ...(file, 'SDS_NAME01')
> is not the same as
> Band = ...(file, SDS_NAME01)
> Maybe that's the problem?
>
> You could use execute(), e.g.:
> Void = execute('Band = ...(file,' + string(...) + ')')
>
> Or why not put the SDS_NAMEs into an array?
>
> SDS_NAMES = ["SREFL_CH1", "SREFL_CH2", ...]
> ...
> for i = 0, 9 do begin
> Band = hdf_sd_nametoindex(file, SDS_NAMES[i])
> ...
> endfor
>
> Hope that helps!
>
> Cheers,
> Anthony- Hide quoted text -
>
> - Show quoted text -
Thanks for all the help. I tried all, but does not work. But I solved
the problem using other method.
--get bariable names by Gumley's HDF file reader
--then loop the variable namses as a string
It works.
|
|
|
Re: a strange loop problem [message #60943 is a reply to message #60941] |
Tue, 24 June 2008 00:33  |
Anthony[1]
Messages: 20 Registered: December 2006
|
Junior Member |
|
|
On Jun 24, 3:53 am, bulrushmo...@gmail.com wrote:
> What is wrong with the loop for the following:
> i=0
> Print, 'SDS_NAME'+STRTRIM(string(i+1),2), prints SDS_NAME01
> But, Band = hdf_sd_nametoindex(file, 'SDS_NAME'+STRTRIM(string(i+1),
> 2)) is not the same with
> Band = hdf_sd_nametoindex(file, SDS_NAME01 )
> ==========================================
> SDS_NAME01 = "SREFL_CH1"
> SDS_NAME02 = "SREFL_CH2"
> SDS_NAME03 = "BT_CH3"
> SDS_NAME04 = "BT_CH4"
> SDS_NAME05 = "BT_CH5"
> SDS_NAME06 = "SREFL_CH3"
> SDS_NAME07 = "SZEN"
> SDS_NAME08 = "VZEN"
> SDS_NAME09 = "RELAZ"
> SDS_NAME10 = "QA"
>
> file = hdf_sd_start(fPath_data
> +"AVH09C1.A1998180.N14.002.2007273131632.hdf")
>
> for i=0, 9 do begin
> Band = hdf_sd_nametoindex(file, 'SDS_NAME'+STRTRIM(string(i+1),2))
> data = hdf_sd_select(file, Band)
> hdf_sd_getdata, data, getdata
> hdf_sd_endaccess, data
>
> endfor
Band = ...(file, 'SDS_NAME01')
is not the same as
Band = ...(file, SDS_NAME01)
Maybe that's the problem?
You could use execute(), e.g.:
Void = execute('Band = ...(file,' + string(...) + ')')
Or why not put the SDS_NAMEs into an array?
SDS_NAMES = ["SREFL_CH1", "SREFL_CH2", ...]
...
for i = 0, 9 do begin
Band = hdf_sd_nametoindex(file, SDS_NAMES[i])
...
endfor
Hope that helps!
Cheers,
Anthony
|
|
|
Re: a strange loop problem [message #60944 is a reply to message #60943] |
Mon, 23 June 2008 21:26  |
bulrushmower
Messages: 19 Registered: February 2008
|
Junior Member |
|
|
On Jun 23, 10:10 pm, David Fanning <n...@dfanning.com> wrote:
> bulrushmo...@gmail.com writes:
>> What is wrong with the loop for the following:
>> i=0
>> Print, 'SDS_NAME'+STRTRIM(string(i+1),2), prints SDS_NAME01
>
> I don't think so:
>
> IDL> I=0
> IDL> Print, 'SDS_NAME'+STRTRIM(string(I+1),2)
> SDS_NAME1
>
> I think you want this:
>
> IDL> I=0
> IDL> Print, 'SDS_NAME' + String(I+1, FORMAT='(I2.2)')
> SDS_NAME01
>
> 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.")
Thanks David,
But problem is still there.
ENVI> help, band
BAND LONG = -1
It should be: BAND LONG = 0
But IDL> Band = hdf_sd_nametoindex(file,SDS_NAME01) prints:
BAND LONG = 0
Any idea about that? Basically, I am reading an HDF file.
Thanks
|
|
|
Re: a strange loop problem [message #60945 is a reply to message #60944] |
Mon, 23 June 2008 20:10  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
bulrushmower@gmail.com writes:
> What is wrong with the loop for the following:
> i=0
> Print, 'SDS_NAME'+STRTRIM(string(i+1),2), prints SDS_NAME01
I don't think so:
IDL> I=0
IDL> Print, 'SDS_NAME'+STRTRIM(string(I+1),2)
SDS_NAME1
I think you want this:
IDL> I=0
IDL> Print, 'SDS_NAME' + String(I+1, FORMAT='(I2.2)')
SDS_NAME01
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.")
|
|
|