Re: HDF_SD_GETACCESS: No content in variable, error [message #71782] |
Wed, 21 July 2010 23:54  |
d.poreh
Messages: 406 Registered: October 2007
|
Senior Member |
|
|
On Jul 21, 9:38 am, David Fanning <n...@dfanning.com> wrote:
> aa8533 writes:
>> Hi - I'm trying to make a program which automatically runs through
>> 100s of images (MODIS Fire data) and extracts data at a particular
>> point. The program works fine where there is data to extract (in the
>> case below, when there is data in FP_Sample) but halts for an image
>> where there is none with message "Array dimensions must be greater
>> than 0".
>
>> Extract of code is:
>
>> sd=hdf_sd_start(fileName)
>> index=hdf_sd_nametoindex(sd,'FP_sample')
>> sds=hdf_sd_select(sd,index)
>> hdf_sd_getdata,sds,sample <------------------ Halts with message
>> here
>
>> Is there a way to test the size of the variable (in this case Sample)
>> and if, say it's -1 (no data) then skip the last line of this code?
>
> I opened each of the two files you sent me up in my
> NCDF_Browser program and I could immediately see that
> FP_sample in the file that causes the problem has
> a dimension of 0. Obviously, nothing is there, even
> though the variable has been defined in the file!
>
> To look for this possibility (I have modified my own
> code in ncdf_data__define.pro and it will be on my
> web page shortly) you will have to check for a zero
> length dimension:
>
> sd=hdf_sd_start(fileName)
> index=hdf_sd_nametoindex(sd,'FP_sample')
> sds=hdf_sd_select(sd,index)
> HDF_SD_GetInfo, sds, DIMS=dims
> IF dims[0] NE 0 THEN BEGIN
> hdf_sd_getdata,sds,sample
> ENDIF
>
> I notice that every variable in that particular data file
> has a dimension of 0. That is one very sick puppy! :-)
>
> 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.")
That is a wise solution. You are the man David!
Cheers
Dave
|
|
|
Re: HDF_SD_GETACCESS: No content in variable, error [message #71787 is a reply to message #71782] |
Wed, 21 July 2010 09:38   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
aa8533 writes:
> Hi - I'm trying to make a program which automatically runs through
> 100s of images (MODIS Fire data) and extracts data at a particular
> point. The program works fine where there is data to extract (in the
> case below, when there is data in FP_Sample) but halts for an image
> where there is none with message "Array dimensions must be greater
> than 0".
>
> Extract of code is:
>
> sd=hdf_sd_start(fileName)
> index=hdf_sd_nametoindex(sd,'FP_sample')
> sds=hdf_sd_select(sd,index)
> hdf_sd_getdata,sds,sample <------------------ Halts with message
> here
>
> Is there a way to test the size of the variable (in this case Sample)
> and if, say it's -1 (no data) then skip the last line of this code?
I opened each of the two files you sent me up in my
NCDF_Browser program and I could immediately see that
FP_sample in the file that causes the problem has
a dimension of 0. Obviously, nothing is there, even
though the variable has been defined in the file!
To look for this possibility (I have modified my own
code in ncdf_data__define.pro and it will be on my
web page shortly) you will have to check for a zero
length dimension:
sd=hdf_sd_start(fileName)
index=hdf_sd_nametoindex(sd,'FP_sample')
sds=hdf_sd_select(sd,index)
HDF_SD_GetInfo, sds, DIMS=dims
IF dims[0] NE 0 THEN BEGIN
hdf_sd_getdata,sds,sample
ENDIF
I notice that every variable in that particular data file
has a dimension of 0. That is one very sick puppy! :-)
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: HDF_SD_GETACCESS: No content in variable, error [message #71793 is a reply to message #71792] |
Wed, 21 July 2010 08:48   |
aa8533
Messages: 8 Registered: July 2010
|
Junior Member |
|
|
On Jul 21, 4:33 pm, David Fanning <n...@dfanning.com> wrote:
> aa8533 writes:
>
>> On Jul 21, 4:21 pm, David Fanning <n...@dfanning.com> wrote:
>>> aa8533 writes:
>>>> Sure, no probs at all, let me have an email address and I'll shoot a
>>>> few examples over ... thank you for this!
>
>>> Well, "david" at the usual 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.")
>
>> Sent, thank you again, Matt
>
> Humm. Well, the usual place is "dfanning.com". Is that
> where you sent it? Hasn't arrive here, unfortunately. :-(
>
> 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.")
done (again), missed out the d!
Regards, Matt
|
|
|
Re: HDF_SD_GETACCESS: No content in variable, error [message #71794 is a reply to message #71793] |
Wed, 21 July 2010 08:33   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
aa8533 writes:
>
> On Jul 21, 4:21 pm, David Fanning <n...@dfanning.com> wrote:
>> aa8533 writes:
>>> Sure, no probs at all, let me have an email address and I'll shoot a
>>> few examples over ... thank you for this!
>>
>> Well, "david" at the usual 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.")
>
> Sent, thank you again, Matt
Humm. Well, the usual place is "dfanning.com". Is that
where you sent it? Hasn't arrive here, unfortunately. :-(
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: HDF_SD_GETACCESS: No content in variable, error [message #71795 is a reply to message #71794] |
Wed, 21 July 2010 08:25   |
aa8533
Messages: 8 Registered: July 2010
|
Junior Member |
|
|
On Jul 21, 4:21 pm, David Fanning <n...@dfanning.com> wrote:
> aa8533 writes:
>> Sure, no probs at all, let me have an email address and I'll shoot a
>> few examples over ... thank you for this!
>
> Well, "david" at the usual 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.")
Sent, thank you again, Matt
|
|
|
Re: HDF_SD_GETACCESS: No content in variable, error [message #71796 is a reply to message #71795] |
Wed, 21 July 2010 08:24   |
aa8533
Messages: 8 Registered: July 2010
|
Junior Member |
|
|
On Jul 21, 4:21 pm, David Fanning <n...@dfanning.com> wrote:
> aa8533 writes:
>> Sure, no probs at all, let me have an email address and I'll shoot a
>> few examples over ... thank you for this!
>
> Well, "david" at the usual 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.")
...Sent, thank you again, Matt
|
|
|
|
Re: HDF_SD_GETACCESS: No content in variable, error [message #71799 is a reply to message #71797] |
Wed, 21 July 2010 08:07   |
aa8533
Messages: 8 Registered: July 2010
|
Junior Member |
|
|
On Jul 21, 4:05 pm, David Fanning <n...@dfanning.com> wrote:
> aa8533 writes:
>> Hi - thanks for that David. However, I examined the index values and
>> they are the same (3) both for scenes where there is (and is not)
>> data. So the problem seems to remain.
>
>> What I think I need to do is kind of what you suggested but to check
>> the sample for data (i.e. check that it is not -1) before I get to
>> hdf_sd_getdata,sds,sample - I just don't know how ...!
>
>> Thank you again and if you have any more suggestions, I'd be most
>> grateful.
>
> Well, I'm kind of interested in this topic myself,
> since I have a lot of code that reads scientific
> data sets, and I would like to make the code as
> robust as possible.
>
> Is it possible to get ahold of a file that "works"
> and one that doesn't? I could run some tests.
>
> 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.")
Sure, no probs at all, let me have an email address and I'll shoot a
few examples over ... thank you for this!
|
|
|
Re: HDF_SD_GETACCESS: No content in variable, error [message #71800 is a reply to message #71799] |
Wed, 21 July 2010 08:05   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
aa8533 writes:
> Hi - thanks for that David. However, I examined the index values and
> they are the same (3) both for scenes where there is (and is not)
> data. So the problem seems to remain.
>
> What I think I need to do is kind of what you suggested but to check
> the sample for data (i.e. check that it is not -1) before I get to
> hdf_sd_getdata,sds,sample - I just don't know how ...!
>
> Thank you again and if you have any more suggestions, I'd be most
> grateful.
Well, I'm kind of interested in this topic myself,
since I have a lot of code that reads scientific
data sets, and I would like to make the code as
robust as possible.
Is it possible to get ahold of a file that "works"
and one that doesn't? I could run some tests.
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: HDF_SD_GETACCESS: No content in variable, error [message #71801 is a reply to message #71800] |
Wed, 21 July 2010 07:59   |
aa8533
Messages: 8 Registered: July 2010
|
Junior Member |
|
|
On Jul 21, 1:54 pm, David Fanning <n...@dfanning.com> wrote:
> aa8533 writes:
>> Hi - I'm trying to make a program which automatically runs through
>> 100s of images (MODIS Fire data) and extracts data at a particular
>> point. The program works fine where there is data to extract (in the
>> case below, when there is data in FP_Sample) but halts for an image
>> where there is none with message "Array dimensions must be greater
>> than 0".
>
>> Extract of code is:
>
>> sd=hdf_sd_start(fileName)
>> index=hdf_sd_nametoindex(sd,'FP_sample')
>> sds=hdf_sd_select(sd,index)
>> hdf_sd_getdata,sds,sample <------------------ Halts with message
>> here
>
>> Is there a way to test the size of the variable (in this case Sample)
>> and if, say it's -1 (no data) then skip the last line of this code?
>
> In my code, I check the index number to see if it is
> valid (e.g., something other than -1) before I try
> to read the data. Do you know what the value of the
> index number is when you get this error?
>
> My code looks like this:
>
> ; Get the index of the variable.
> index = HDF_SD_NameToIndex(fileID, theVariable)
> IF index EQ -1 THEN $
> Message, 'Variable (' + theVariable + ') not found.'
>
> ; Select the variable and read it.
> varID = HDF_SD_Select(fileID, index)
> HDF_SD_GetData, varID, data, COUNT=count, $
> START=start, STRIDE=stride
>
> 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.")
Hi - thanks for that David. However, I examined the index values and
they are the same (3) both for scenes where there is (and is not)
data. So the problem seems to remain.
What I think I need to do is kind of what you suggested but to check
the sample for data (i.e. check that it is not -1) before I get to
hdf_sd_getdata,sds,sample - I just don't know how ...!
Thank you again and if you have any more suggestions, I'd be most
grateful.
Regards, Matt
|
|
|
Re: HDF_SD_GETACCESS: No content in variable, error [message #71803 is a reply to message #71801] |
Wed, 21 July 2010 05:54   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
aa8533 writes:
> Hi - I'm trying to make a program which automatically runs through
> 100s of images (MODIS Fire data) and extracts data at a particular
> point. The program works fine where there is data to extract (in the
> case below, when there is data in FP_Sample) but halts for an image
> where there is none with message "Array dimensions must be greater
> than 0".
>
> Extract of code is:
>
> sd=hdf_sd_start(fileName)
> index=hdf_sd_nametoindex(sd,'FP_sample')
> sds=hdf_sd_select(sd,index)
> hdf_sd_getdata,sds,sample <------------------ Halts with message
> here
>
> Is there a way to test the size of the variable (in this case Sample)
> and if, say it's -1 (no data) then skip the last line of this code?
In my code, I check the index number to see if it is
valid (e.g., something other than -1) before I try
to read the data. Do you know what the value of the
index number is when you get this error?
My code looks like this:
; Get the index of the variable.
index = HDF_SD_NameToIndex(fileID, theVariable)
IF index EQ -1 THEN $
Message, 'Variable (' + theVariable + ') not found.'
; Select the variable and read it.
varID = HDF_SD_Select(fileID, index)
HDF_SD_GetData, varID, data, COUNT=count, $
START=start, STRIDE=stride
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: HDF_SD_GETACCESS: No content in variable, error [message #71805 is a reply to message #71803] |
Wed, 21 July 2010 04:42   |
aa8533
Messages: 8 Registered: July 2010
|
Junior Member |
|
|
On Jul 21, 12:32 pm, Dave Poreh <d.po...@gmail.com> wrote:
> On Jul 21, 4:17 am, aa8533 <matthew.blackett.coven...@googlemail.com>
> wrote:
>
>
>
>
>
>> Hi - I'm trying to make a program which automatically runs through
>> 100s of images (MODIS Fire data) and extracts data at a particular
>> point. The program works fine where there is data to extract (in the
>> case below, when there is data in FP_Sample) but halts for an image
>> where there is none with message "Array dimensions must be greater
>> than 0".
>
>> Extract of code is:
>
>> sd=hdf_sd_start(fileName)
>> index=hdf_sd_nametoindex(sd,'FP_sample')
>> sds=hdf_sd_select(sd,index)
>> hdf_sd_getdata,sds,sample <------------------ Halts with message
>> here
>
>> Is there a way to test the size of the variable (in this case Sample)
>> and if, say it's -1 (no data) then skip the last line of this code?
>
>> Would very much appreciate any help.
>
>> Matt
>
> can you post entire code from beginning to see what happen?
SURE, Thank you for getting back so quickly. It is below, the hdf bit
is contained within a for statement. So basically, i need to skip bits
where there is no data but from what I can figure out, it only knows
there is no data when I ask it to get it, hence the array error.
Very thankful - Matt (Dr Matthew Blackett, Coventry University, UK)
pro attemptcorfocusedcov
v=double(0.000003959)
e=double(2.718281828)
h=double(6.6262E-34)
c=double(2.99792458E8)
k=double(1.3807E-23)
Radearth =6378.137
height =705
r = Radearth + height
s = 1.0/height
angle=findgen(1354)
theta=((-1)*(677*s))+(0.5*s)+((angle)*s)
asps=Radearth*s*((cos(theta)/(((Radearth/r)^2)-
sin(theta)^2)^0.5)-1.0)
atps=r*s*(cos(theta)-(((Radearth/r)^2)-(sin(theta)^2))^0.5)
area=(asps)*(atps)
pathName="G:\FTPmod14\"
List = findfile(pathName+"*.hdf")
nosFiles=N_ELEMENTS(List)
for i = 0, nosFiles-1 do begin
fileName = List[i]
sd=hdf_sd_start(fileName)
index=hdf_sd_nametoindex(sd,'FP_sample')
sds=hdf_sd_select(sd,index)
hdf_sd_getdata,sds,sample
hdf_sd_endaccess,sds
index=hdf_sd_nametoindex(sd,'FP_T21')
sds=hdf_sd_select(sd,index)
hdf_sd_getdata,sds,bt21
hdf_sd_endaccess,sds
index=hdf_sd_nametoindex(sd,'FP_MeanT21')
sds=hdf_sd_select(sd,index)
hdf_sd_getdata,sds,btmean21
hdf_sd_endaccess,sds
index=hdf_sd_nametoindex(sd,'FP_latitude')
sds=hdf_sd_select(sd,index)
hdf_sd_getdata,sds,lat
hdf_sd_endaccess,sds
index=hdf_sd_nametoindex(sd,'FP_longitude')
sds=hdf_sd_select(sd,index)
hdf_sd_getdata,sds,longit
hdf_sd_endaccess,sds
index=hdf_sd_nametoindex(sd,'FP_line')
sds=hdf_sd_select(sd,index)
hdf_sd_getdata,sds,horiz
hdf_sd_endaccess,sds
index=hdf_sd_nametoindex(sd,'FP_sample')
sds=hdf_sd_select(sd,index)
hdf_sd_getdata,sds,vertic
hdf_sd_endaccess,sds
hdf_sd_end,sd
radiance=(((2.0*h*c^2)/v^5)*(1/(exp((h*c)/
(v*k*(double(bt21))))-1)))*1e-6
bgradiance=(((2.0*h*c^2)/v^5)*(1/(exp((h*c)/
(v*k*(double(btmean21))))-1)))*1.0e-6
mirpower=((area[vertic,horiz])*20.25)*((1/0.957)*(radiance-
bgradiance))
print, btmean21
results=where(((lat gt 37) and (lat lt 38)) AND ((longit gt 14.5) and
(longit lt 15.5)))
print, "___________________________________________"
print, i
print, results
print, horiz
print, vertic
print, longit
print, lat
PRINT, MIRPOWER
if (results(0) ne -1) then begin
PRINT, 'RESULTS:'
print, mirpower(results)
endif else begin
print, 'no result'
endelse
endfor
end
|
|
|
Re: HDF_SD_GETACCESS: No content in variable, error [message #71806 is a reply to message #71805] |
Wed, 21 July 2010 04:32   |
d.poreh
Messages: 406 Registered: October 2007
|
Senior Member |
|
|
On Jul 21, 4:17 am, aa8533 <matthew.blackett.coven...@googlemail.com>
wrote:
> Hi - I'm trying to make a program which automatically runs through
> 100s of images (MODIS Fire data) and extracts data at a particular
> point. The program works fine where there is data to extract (in the
> case below, when there is data in FP_Sample) but halts for an image
> where there is none with message "Array dimensions must be greater
> than 0".
>
> Extract of code is:
>
> sd=hdf_sd_start(fileName)
> index=hdf_sd_nametoindex(sd,'FP_sample')
> sds=hdf_sd_select(sd,index)
> hdf_sd_getdata,sds,sample <------------------ Halts with message
> here
>
> Is there a way to test the size of the variable (in this case Sample)
> and if, say it's -1 (no data) then skip the last line of this code?
>
> Would very much appreciate any help.
>
> Matt
can you post entire code from beginning to see what happen?
|
|
|
Re: HDF_SD_GETACCESS: No content in variable, error [message #71851 is a reply to message #71782] |
Fri, 23 July 2010 01:11  |
aa8533
Messages: 8 Registered: July 2010
|
Junior Member |
|
|
On Jul 22, 7:54 am, Dave Poreh <d.po...@gmail.com> wrote:
> On Jul 21, 9:38 am, David Fanning <n...@dfanning.com> wrote:
>
>
>
>
>
>> aa8533 writes:
>>> Hi - I'm trying to make a program which automatically runs through
>>> 100s of images (MODIS Fire data) and extracts data at a particular
>>> point. The program works fine where there is data to extract (in the
>>> case below, when there is data in FP_Sample) but halts for an image
>>> where there is none with message "Array dimensions must be greater
>>> than 0".
>
>>> Extract of code is:
>
>>> sd=hdf_sd_start(fileName)
>>> index=hdf_sd_nametoindex(sd,'FP_sample')
>>> sds=hdf_sd_select(sd,index)
>>> hdf_sd_getdata,sds,sample <------------------ Halts with message
>>> here
>
>>> Is there a way to test the size of the variable (in this case Sample)
>>> and if, say it's -1 (no data) then skip the last line of this code?
>
>> I opened each of the two files you sent me up in my
>> NCDF_Browser program and I could immediately see that
>> FP_sample in the file that causes the problem has
>> a dimension of 0. Obviously, nothing is there, even
>> though the variable has been defined in the file!
>
>> To look for this possibility (I have modified my own
>> code in ncdf_data__define.pro and it will be on my
>> web page shortly) you will have to check for a zero
>> length dimension:
>
>> sd=hdf_sd_start(fileName)
>> index=hdf_sd_nametoindex(sd,'FP_sample')
>> sds=hdf_sd_select(sd,index)
>> HDF_SD_GetInfo, sds, DIMS=dims
>> IF dims[0] NE 0 THEN BEGIN
>> hdf_sd_getdata,sds,sample
>> ENDIF
>
>> I notice that every variable in that particular data file
>> has a dimension of 0. That is one very sick puppy! :-)
>
>> 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.")
>
> That is a wise solution. You are the man David!
> Cheers
> Dave
David, thank you so much, that works fine now, saving me hours of
frustration
I appreciate it.
Matt
|
|
|