Re: Question regarding HDF file [message #55138] |
Mon, 06 August 2007 08:05  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
None wrote:
> Hi. I have a problem rewriting the data to the original hdf file
> (i.e., to the same dataset which i had read from, earlier) I am
> getting negetive data values. Also I am getting the same negetive data
> values if i put a dummy array instead of the data in the
The fact that you are getting negative values suggests that you may
have a type conversion problem. What is the HDF data type for the SDS
you're trying to overwrite? What is the IDL type of the rowp array
that you're writing down below?
> HDF_SD_ADDDATA command. I got correct values when I output the result
> to a tiff file, but not able to get the correct values if I write it
> back to the original file. I have posted my code bellow. Can anybody
> please help me with a solution
>
> sdFileID2 = HDF_SD_Start(fname, /RdWr)
> sdsIDsm = HDF_SD_Select(sdFileID2,im[j]); im[j] are different bands
> HDF_SD_ADDDATA, sdsIDsm, rowp, start=[0,0], count=[x[j],y[j]]
> ; rowp is the dataset and is of type float
> ; x,y are the array dimensions
> HDF_SD_EndAccess, sdsIDsm
I just performed a test, and I had no problems overwriting data using
code similar to yours. The one important thing that seems to be
missing from your code is a call to HDF_SD_End, but what you've
written is obviously a code fragment, rather than a complete program,
so I'm not sure whether that procedure call is really missing.
|
|
|
Re: Question regarding HDF file [message #55231 is a reply to message #55138] |
Mon, 06 August 2007 13:55  |
None[1]
Messages: 13 Registered: August 2007
|
Junior Member |
|
|
On Aug 6, 11:05 am, kuyper <kuy...@wizard.net> wrote:
> I just performed a test, and I had no problems overwriting data using
> code similar to yours. The one important thing that seems to be
> missing from your code is a call to HDF_SD_End, but what you've
> written is obviously a code fragment, rather than a complete program,
> so I'm not sure whether that procedure call is really missing.
Thanks for replying. No I have not missed that command. This is what I
am doing. I am reading the dataset into a text file. the text file
contains 3 columns seperated by spaces. I read the text file line by
line to get the 3 values (D,A and G). use it in the formula to get the
results and write it back to the HDF file. I get the correct results
if I output the results to tiff file. But I am not able to get the
same results when I write it back to the HDF file. this is what my
code looks like
sdFileID2 = HDF_SD_Start(fname, /RdWr)
sdsIDsm = HDF_SD_Select(sdFileID2,im[j]) ; Image data
sdsIDsm2 = HDF_SD_Select(sdFileID2,bd[j]) ; recorrection data
HDF_SD_GETDATA, sdsIDsm, rr, start=[0,0], count=[x[j],y[j]],
stride=[0,0]
HDF_SD_GETDATA, sdsIDsm2, r2
; Writing it into a text file
openw, lun, out_path+'Step1\'+strcompress(fn[3],/remove_all)
+'-'+strcompress(j,/remove_all)+'.txt', /get_lun
printf, lun, r2
close, lun
free_lun, lun
results=fltarr(x[j],y[j])
rowp=fltarr(x[j],y[j])
openr, lun1, out_path+'Step1\'+strcompress(fn[3],/remove_all)
+'-'+strcompress(j,/remove_all)+'.txt', /get_lun
; Reading line by line to D, A, G values
while ((~eof(lun1)) && (n lt x[j])) do begin
readf, lun1, temp1
sr = strsplit(temp1,' ', /Extract)
d=float(sr[0])
a=float(sr[1])
g=float(sr[2])
print, d, a, g
results[n,*]=(float(a)*(rr[(n),*])/float(g))+float(d)
rowp[n,*]=(3.14159*results[n,*]*sd*sd)/(esun[j]*COS((90-
theta)*3.14159/180))
n=n+1
endwhile
HDF_SD_ADDDATA, sdsIDsm, rowp, start=[0,0], count=[x[j],y[j]],
stride=[0,0]
HDF_SD_EndAccess, sdsIDsm
HDF_SD_END, sdFileID2
Thanks
Rajesh
|
|
|