function pp_readcube::init,file,special=special
compile_opt idl2,hidden
special=n_elements(special) eq 1 ? special : 0B
self.special=special
ret=0
if (n_elements(file) ne 1) then begin
print,'pp_readcube: Cube name not provided'
return,ret
endif else if (file eq '') then return,ret
header=obj_new('pp_buffered_vector')
history=obj_new('pp_buffered_vector')
error_status=0
if (error_status ne 0) then begin
catch,/cancel
print,'pp_readcube: Cube named "',file,'" could not be read or parsed'
endif else begin
self.file=file
openr,unit,file,/get_lun
line=''
readf,unit,line
if (strpos(line,'CCSD') ne 0) then print,'pp_readcube: "',file,'" does not appear to be a valid cube' else begin
header->append,line
repeat begin
if (not eof(unit)) then readf,unit,line else begin
print,'pp_readcube: "',file,'" does not appear to be a valid cube'
break
endelse
header->append,line
endrep until (strtrim(line,2) eq 'END')
self.labels=ptr_new(header->getdata(/all))
self.tlabels=ptr_new(strtrim(*self.labels,2))
if self->parselabels() then begin
if ((self.info.filerecords-self.info.labelrecords) gt 0) then begin
point_lun,unit,self.info.recordbytes*self.info.historystart
repeat begin
if (not eof(unit)) then readf,unit,line else begin
print,'pp_readcube: "',file,'" does not appear to be a valid cube'
break
endelse
history->append,line
endrep until (strtrim(line,2) eq 'END')
self.history=ptr_new(history->getdata(/all))
self.thistory=ptr_new(strtrim(*self.history,2))
endif
raw=make_array(self.info.dims,type=self.info.datatype,/nozero)
point_lun,unit,self.info.recordbytes*self.info.binarystart
readu,unit,raw
self.raw=ptr_new(raw,/no_copy)
endif else message,'"'+file+'" does not appear to have enough information in its header'
endelse
self->processdata
ret=1
endelse
catch,/cancel
if (n_elements(unit) eq 1) then free_lun,unit
obj_destroy,header
obj_destroy,history
return,ret
end
pro pp_readcube::cleanup
compile_opt idl2,hidden
ptr_free,self.labels,self.tlabels,self.history,self.thistory,self.raw
ptr_free,self.core,self.backplanes,self.sideplanes,self.bottomplanes
ptr_free,self.wavs,self.bnames,self.snames,self.bonames
ptr_free,self.wavs,self.bunits,self.sunits,self.bounits
end
function pp_readcube::parselabels
compile_opt idl2,hidden
theader=*self.tlabels
count=1
self.info.coredims=long(pp_getcubeheadervalue(theader,'CORE_ITEMS',count=tmp)) & count*=tmp
self.info.suffdims=long(pp_getcubeheadervalue(theader,'SUFFIX_ITEMS',count=tmp)) & count*=tmp
self.info.dims=self.info.coredims+self.info.suffdims
self.info.bytes=fix(pp_getcubeheadervalue(theader,'CORE_ITEM_BYTES',count=tmp)) & count*=tmp
self.info.type=pp_getcubeheadervalue(theader,'CORE_ITEM_TYPE',count=tmp) & count*=tmp
if (strpos(self.info.type,'REAL') ne -1) then begin
case self.info.bytes of
8 : self.info.datatype=5
else : self.info.datatype=4
endcase
endif else begin
case self.info.bytes of
1 : self.info.datatype=1
2 : self.info.datatype=2
8 : self.info.datatype=14
else : self.info.datatype=3
endcase
endelse
self.info.littleendian=(strpos(self.info.type,'PC') ne -1)
self.info.recordbytes=long(pp_getcubeheadervalue(theader,'RECORD_BYTES',count=tmp)) & count*=tmp
self.info.historystart=long(pp_getcubeheadervalue(theader,'\^HISTORY',count=tmp))-1L & count*=tmp
self.info.binarystart=long(pp_getcubeheadervalue(theader,'\^QUBE',count=tmp))-1L & count*=tmp
self.info.filerecords=long(pp_getcubeheadervalue(theader,'FILE_RECORDS',count=tmp))-1L & count*=tmp
self.info.labelrecords=long(pp_getcubeheadervalue(theader,'LABEL_RECORDS',count=tmp))-1L & count*=tmp
self.info.historyrecords=self.info.filerecords-self.info.labelrecords
self.info.binaryrecords=self.info.filerecords-self.info.binarystart-1
wavs=double(pp_getcubeheadervalue(theader,'BAND_BIN_CENTER',count=tmp))
wavs=tmp gt 0 ? wavs : replicate('UNKNOWN',self.info.coredims[2])
self.wavs=ptr_new(wavs,/no_copy)
units=pp_getcubeheadervalue(theader,'BAND_BIN_UNIT',count=tmp)
self.units=tmp gt 0 ? units : ''
if (self.info.suffdims[2] gt 0) then begin
bnames=pp_getcubeheadervalue(theader,'BAND_SUFFIX_NAME',count=tmp)
bnames=tmp gt 0 ? bnames : 'UNKNOWN_'+strtrim(sindgen(self.info.suffdims[2]),2)
self.bnames=ptr_new(bnames,/no_copy)
bunits=pp_getcubeheadervalue(theader,'BAND_SUFFIX_UNIT',count=tmp)
bunits=tmp gt 0 ? bunits : replicate('UNKNOWN',self.info.suffdims[2])
self.bunits=ptr_new(bunits,/no_copy)
endif
if (self.info.suffdims[0] gt 0) then begin
snames=pp_getcubeheadervalue(theader,'SAMPLE_SUFFIX_NAME',count=tmp)
snames=tmp gt 0 ? snames : 'UNKNOWN_'+strtrim(sindgen(self.info.suffdims[0]),2)
self.snames=ptr_new(snames,/no_copy)
sunits=pp_getcubeheadervalue(theader,'SAMPLE_SUFFIX_UNIT',count=tmp)
sunits=tmp gt 0 ? sunits : replicate('UNKNOWN',self.info.suffdims[0])
self.sunits=ptr_new(sunits,/no_copy)
endif
if (self.info.suffdims[1] gt 0) then begin
bonames=pp_getcubeheadervalue(theader,'LINE_SUFFIX_NAME',count=tmp)
bonames=tmp gt 0 ? bonames : 'UNKNOWN_'+strtrim(sindgen(self.info.suffdims[1]),2)
self.bonames=ptr_new(bonames,/no_copy)
bounits=pp_getcubeheadervalue(theader,'LINE_SUFFIX_UNIT',count=tmp)
bounits=tmp gt 0 ? bounits : replicate('UNKNOWN',self.info.suffdims[1])
self.bounits=ptr_new(bounits,/no_copy)
endif
return,(count ne 0)
end
pro pp_readcube::processdata
compile_opt idl2,hidden
cdims=self.info.coredims
sdims=self.info.suffdims
core=(*self.raw)[0:cdims[0]-1,0:cdims[1]-1,0:cdims[2]-1]
back=(sdims[2] gt 0)
side=(sdims[0] gt 0)
bottom=(sdims[1] gt 0)
if back then backplanes=(*self.raw)[0:cdims[0]-1,0:cdims[1]-1,cdims[2]:cdims[2]+sdims[2]-1]
if side then sideplanes=(*self.raw)[cdims[0]:cdims[0]+sdims[0]-1,0:cdims[1]-1,0:cdims[2]-1]
if bottom then bottomplanes=(*self.raw)[0:cdims[0]-1,cdims[1]:cdims[1]+sdims[1]-1,0:cdims[2]-1]
l_e=self.info.littleendian
b_e=~l_e
byteorder,core,swap_if_big_endian=l_e,swap_if_little_endian=b_e
if back then byteorder,backplanes,swap_if_big_endian=l_e,swap_if_little_endian=b_e
if side then byteorder,sideplanes,swap_if_big_endian=l_e,swap_if_little_endian=b_e
if bottom then byteorder,bottomplanes,swap_if_big_endian=l_e,swap_if_little_endian=b_e
if (self.special eq 0) || (self.special eq 1) then begin
special=self->getspecialvalues()
core=pp_readcube_specialreplace(core,special)
if back then backplanes=pp_readcube_specialreplace(backplanes,special)
if side then sideplanes=pp_readcube_specialreplace(sideplanes,special)
if bottom then bottomplanes=pp_readcube_specialreplace(bottomplanes,special)
endif
self.core=ptr_new(core,/no_copy)
if back then self.backplanes=ptr_new(backplanes,/no_copy)
if side then self.sideplanes=ptr_new(sideplanes,/no_copy)
if bottom then self.bottomplanes=ptr_new(bottomplanes,/no_copy)
end
function pp_readcube::getspecialvalues,default=default
compile_opt idl2
default=n_elements(default) eq 1 ? default : 0
special_8={VALID_MIN:'FEFFFFFFFFFFFFA'xull,$
NULL:'FFEFFFFFFFFFFFFB'xull,$
LOW_REPR_SAT:'FFEFFFFFFFFFFFFC'xull,$
LOW_INSTR_SAT:'FFEFFFFFFFFFFFFD'xull,$
HIGH_INSTR_SAT:'FFEFFFFFFFFFFFFE'xull,$
HIGH_REPR_SAT:'FFEFFFFFFFFFFFFF'xull}
special_4={VALID_MIN:'FF7FFFFA'xul,$
NULL:'FF7FFFFB'xul,$
LOW_REPR_SAT:'FF7FFFFC'xul,$
LOW_INSTR_SAT:'FF7FFFFD'xul,$
HIGH_INSTR_SAT:'FF7FFFFE'xul,$
HIGH_REPR_SAT:'FF7FFFFF'xul}
special_2={VALID_MIN:-32752S,$
NULL:fix(-32768),$
LOW_REPR_SAT:-32767S,$
LOW_INSTR_SAT:-32766S,$
HIGH_INSTR_SAT:-32765S,$
HIGH_REPR_SAT:-32764S,$
VALID_MAX:32767S}
special_1={VALID_MIN:1B,$
NULL:0B,$
LOW_REPR_SAT:0B,$
LOW_INSTR_SAT:0B,$
HIGH_INSTR_SAT:255B,$
HIGH_REPR_SAT:255B,$
VALID_MAX:254B}
sel=default ? 0 : self.special
switch sel of
1 : begin
theader=*self.theader
count=1
vmin=pp_getcubeheadervalue(theader,'CORE_VALID_MINIMUM',count=tmp) & count*=tmp
null=pp_getcubeheadervalue(theader,'CORE_NULL',count=tmp) & count*=tmp
lrs=pp_getcubeheadervalue(theader,'CORE_LOW_REPR_SATURATION',count=tmp) & count*=tmp
lis=pp_getcubeheadervalue(theader,'CORE_LOW_INSTR_SATURATION',count=tmp) & count*=tmp
hrs=pp_getcubeheadervalue(theader,'CORE_HIGH_REPR_SATURATION',count=tmp) & count*=tmp
his=pp_getcubeheadervalue(theader,'CORE_HIGH_INSTR_SATURATION',count=tmp) & count*=tmp
if (count ne 0) then begin
if (self.info.bytes ge 4) then begin
tmp=self.info.bytes eq 8 ? 0ULL : 0UL
reads,vmin,ltmp,format='(3X,Z,1X)' & vmin=ltmp
reads,null,ltmp,format='(3X,Z,1X)' & null=ltmp
reads,lrs,ltmp,format='(3X,Z,1X)' & lrs=ltmp
reads,lis,ltmp,format='(3X,Z,1X)' & lis=ltmp
reads,hrs,ltmp,format='(3X,Z,1X)' & hrs=ltmp
reads,his,ltmp,format='(3X,Z,1X)' & his=ltmp
endif
case self.info.bytes of
1 : special={VALID_MIN:byte(vmin),NULL:byte(null),LOW_REPR_SAT:byte(lrs),$
LOW_INSTR_SAT:byte(lis),HIGH_INSTR_SAT:byte(his),HIGH_REPR_SAT:byte(hrs)}
2 : special={VALID_MIN:fix(vmin),NULL:fix(null),LOW_REPR_SAT:fix(lrs),$
LOW_INSTR_SAT:fix(lis),HIGH_INSTR_SAT:fix(his),HIGH_REPR_SAT:fix(hrs)}
8 : special={VALID_MIN:vmin,NULL:null,LOW_REPR_SAT:lrs,$
LOW_INSTR_SAT:lis,HIGH_INSTR_SAT:his,HIGH_REPR_SAT:hrs}
else : special={VALID_MIN:vmin,NULL:null,LOW_REPR_SAT:lrs,$
LOW_INSTR_SAT:lis,HIGH_INSTR_SAT:his,HIGH_REPR_SAT:hrs}
endcase
break
endif else print,'pp_readcube: Warning: Cube header does not have all special values, using default values'
end
else : begin
case self.info.bytes of
1 : special=special_1
2 : special=special_2
8 : special=special_8
else : special=special_4
endcase
self.special=0
end
endswitch
return,special
end
function pp_readcube_specialreplace,data,special
compile_opt idl2,hidden
datatype=size(data,/type)
case datatype of
4 : begin
rep=!values.f_nan
w=where(data lt float(special.valid_min,0),count)
if (count gt 0) then data[w]=rep
sel=(data eq float(special.null,0))
sel=sel or (data eq float(special.low_repr_sat,0))
sel=sel or (data eq float(special.low_instr_sat,0))
sel=sel or (data eq float(special.high_instr_sat,0))
sel=sel or (data eq float(special.high_repr_sat,0))
w=where(sel,count)
if (count gt 0) then data[w]=rep
end
5 : begin
rep=!values.d_nan
w=where(data lt double(special.valid_min,0),count)
if (count gt 0) then data[w]=rep
sel=(data eq double(special.null,0))
sel=sel or (data eq double(special.low_repr_sat,0))
sel=sel or (data eq double(special.low_instr_sat,0))
sel=sel or (data eq double(special.high_instr_sat,0))
sel=sel or (data eq double(special.high_repr_sat,0))
w=where(sel,count)
if (count gt 0) then data[w]=rep
end
else : begin
rep=special.null
w=where(data lt special.valid_min,count)
if (count gt 0) then data[w]=rep
sel=(data eq special.null)
sel=sel or (data eq special.low_repr_sat)
sel=sel or (data eq special.low_instr_sat)
sel=sel or (data eq special.high_instr_sat)
sel=sel or (data eq special.high_repr_sat)
w=where(sel,count)
if (count gt 0) then data[w]=rep
end
endcase
return,data
end
function pp_readcube::getexerpt
compile_opt idl2,logical_predicate
nx=self.info.coredims[0]
nz=self.info.coredims[1]
npixels=nx*nz
ret=replicate({x:0,z:0,lats:dblarr(4)+!values.d_nan,lons:dblarr(4)+!values.d_nan,lat:!values.d_nan,$
lon:!values.d_nan,emissions:dblarr(4)+!values.d_nan,phases:dblarr(4)+!values.d_nan,incidences:$
dblarr(4)+!values.d_nan,az_difs:dblarr(4)+!values.d_nan,emission:!values.d_nan,phase:!values.d_nan,$
incidence:!values.d_nan,az_dif:!values.d_nan},npixels)
lats=reform(self.getsuffixbyname('LAT_'+strtrim(indgen(5),2)),npixels,5)
lons=reform(self.getsuffixbyname('LON_'+strtrim(indgen(5),2)),npixels,5)
emissions=reform(self.getsuffixbyname('EMISSION_'+strtrim(indgen(5),2)),npixels,5)
phases=reform(self.getsuffixbyname('PHASE_'+strtrim(indgen(5),2)),npixels,5)
incidences=reform(self.getsuffixbyname('INCIDENCE_'+strtrim(indgen(5),2)),npixels,5)
az_difs=reform(self.getsuffixbyname('AZ_DIF_'+strtrim(indgen(5),2)),npixels,5)
x=(indgen(nx)+1)#replicate(1,nz)
z=replicate(1,nx)#(indgen(nz)+1)
x=reform(x,npixels)
z=reform(z,npixels)
ret.x=x & ret.z=z
ret.lat=lats[*,0]
ret.lon=lons[*,0]
ret.incidence=incidences[*,0]
ret.phase=phases[*,0]
ret.emission=emissions[*,0]
ret.az_dif=az_difs[*,0]
ret.lats=transpose(lats[*,1:4])
ret.lons=transpose(lons[*,1:4])
ret.incidences=transpose(incidences[*,1:4])
ret.phases=transpose(phases[*,1:4])
ret.emissions=transpose(emissions[*,1:4])
ret.az_difs=transpose(az_difs[*,1:4])
return,ret
end
pro pp_readcube::getproperty,all=all,file=file,special=special,labels=labels,history=history,$
core=core,backplanes=backplanes,sideplanes=sideplanes,bottomplanes=bottomplanes,$
info=info,lines=lines,bands=bands,samples=samples,nback=nback,nside=nside,nbottom=nbottom,$
rawdata=raw,wavelengths=wavs,backnames=bnames,sidenames=snames,bottomnames=bonames,$
units=wunits,backunits=bunits,sideunits=sunits,bottomunits=bounits,struct_backplanes=struct_backplanes,$
npixels=npixels,lats=lats,lons=lons
compile_opt idl2
all=arg_present(all)
if (all || arg_present(file)) then file=self.file
if (all || arg_present(special)) then special=self.special
if (all || arg_present(labels)) then labels=*self.labels
if (all || arg_present(history)) then history=*self.history
if (all || arg_present(core)) then core=*self.core
if (all || arg_present(backplanes)) then backplanes=ptr_valid(self.backplanes) ? *self.backplanes : self.backplanes
if (all || arg_present(sideplanes)) then sideplanes=ptr_valid(self.sideplanes) ? *self.sideplanes : self.sideplanes
if (all || arg_present(bottomplanes)) then bottomplanes=ptr_valid(self.bottomplanes) ? *self.bottomplanes : self.bottomplanes
if (all || arg_present(info)) then info=self.info
if (all || arg_present(lines)) then lines=self.info.coredims[1]
if (all || arg_present(samples)) then samples=self.info.coredims[0]
if (all || arg_present(npixels)) then npixels=self.info.coredims[0]*self.info.coredims[1]
if (all || arg_present(bands)) then bands=self.info.coredims[2]
if (all || arg_present(nback)) then nback=self.info.suffdims[2]
if (all || arg_present(nside)) then nside=self.info.suffdims[0]
if (all || arg_present(nbottom)) then nbottom=self.info.suffdims[1]
if (all || arg_present(raw)) then raw=*self.raw
if (all || arg_present(wavs)) then wavs=*self.wavs
if (all || arg_present(bnames)) then bnames=ptr_valid(self.bnames) ? *self.bnames : self.bnames
if (all || arg_present(snames)) then snames=ptr_valid(self.snames) ? *self.snames : self.snames
if (all || arg_present(bonames)) then bonames=ptr_valid(self.bonames) ? *self.bonames : self.bonames
if (all || arg_present(wunits)) then wunits=self.units
if (all || arg_present(bunits)) then bunits=ptr_valid(self.bunits) ? *self.bunits : self.bunits
if (all || arg_present(sunits)) then sunits=ptr_valid(self.sunits) ? *self.sunits : self.sunits
if (all || arg_present(bounits)) then bounits=ptr_valid(self.bounits) ? self.bounits : self.bounits
if (all || arg_present(struct_backplanes)) then begin
if (ptr_valid(self.bnames)) then begin
nt=n_elements(*self.bnames)
tmp=create_struct((*self.bnames)[0],0d0)
for i=1,nt-1 do tmp=create_struct(tmp,(*self.bnames)[i],0d0)
struct_backplanes=replicate(tmp,self.info.coredims[0],self.info.coredims[1],self.info.suffdims[2])
for i=0,nt-1 do struct_backplanes[*,*].(i)=(*self.backplanes)[*,*,i]
endif else struct_backplanes=ptr_new()
endif
if arg_present(lats) then begin
lats=self[['lat_1','lat_2','lat_3','lat_4']]
self.getproperty,npixels=np
lats=reform(lats,np,4)
lats=transpose(lats)
endif
if arg_present(lons) then begin
lons=self[['lon_1','lon_2','lon_3','lon_4']]
self.getproperty,npixels=np
lons=reform(lons,np,4)
lons=transpose(lons)
endif
if all then all={file:file,special:special,labels:labels,history:history,core:core,$
backplanes:backplanes,sideplanes:sideplanes,bottomplanes:bottomplanes,$
info:info,lines:lines,samples:samples,bands:bands,$
nback:nback,nside:nside,nbottom:nbottom,$
raw:raw,wavelengths:wavs,backnames:bnames,sidenames:snames,bottomnames:bonames,$
units:wunits,backunits:bunits,sideunits:sunits,bottomunits:bounits,struct_backplanes:struct_backplanes}
end
function pp_readcube::getproperty,all=all,file=file,special=special,labels=labels,history=history,$
core=core,backplanes=backplanes,sideplanes=sideplanes,bottomplanes=bottomplanes,$
info=info,lines=lines,bands=bands,samples=samples,nback=nback,nside=nside,nbottom=nbottom,$
rawdata=raw,wavelengths=wavs,backnames=bnames,sidenames=snames,bottomnames=bonames,$
units=wunits,backunits=bunits,sideunits=sunits,bottomunits=bounits
compile_opt idl2
if keyword_set(all) then self->getproperty,all=ret
if keyword_set(file) then self->getproperty,file=ret
if keyword_set(special) then self->getproperty,special=ret
if keyword_set(labels) then self->getproperty,labels=ret
if keyword_set(history) then self->getproperty,history=ret
if keyword_set(core) then self->getproperty,core=ret
if keyword_set(backplanes) then self->getproperty,backplanes=ret
if keyword_set(sideplanes) then self->getproperty,sideplanes=ret
if keyword_set(bottomplanes) then self->getproperty,bottomplanes=ret
if keyword_set(info) then self->getproperty,info=ret
if keyword_set(lines) then self->getproperty,lines=ret
if keyword_set(bands) then self->getproperty,bands=ret
if keyword_set(samples) then self->getproperty,samples=ret
if keyword_set(nback) then self->getproperty,nback=ret
if keyword_set(nside) then self->getproperty,nside=ret
if keyword_set(nbottom) then self->getproperty,nbottom=ret
if keyword_set(raw) then self->getproperty,rawdata=ret
if keyword_set(wavs) then self->getproperty,wavelengths=ret
if keyword_set(bnames) then self->getproperty,backnames=ret
if keyword_set(snames) then self->getproperty,sidenames=ret
if keyword_set(bonames) then self->getproperty,bottomnames=ret
if keyword_set(wunits) then self->getproperty,units=ret
if keyword_set(bunits) then self->getproperty,backunits=ret
if keyword_set(sunits) then self->getproperty,sideunits=ret
if keyword_set(bounits) then self->getproperty,bottomunits=ret
if keyword_set(all) then self->getproperty,all=ret
return,ret
end
function pp_readcube::getsuffixbyname,names,found=found,case_sensitive=cases,side=side,bottom=bottom,back=back,index=index
compile_opt idl2
cases=n_elements(cases) eq 1 ? cases : 0
back=n_elements(back) eq 1 ? back : 1
side=n_elements(side) eq 1 ? side : 0
bottom=n_elements(bottom) eq 1 ? bottom : 0
nnames=n_elements(names)
if (nnames eq 0) then message,'Names for the suffix planes were not provided'
type=back ? 2 : (side ? 0 : (bottom ? 1 : 2))
case type of
2 : ret=make_array(type=self.info.datatype,[self.info.coredims[[0,1]],nnames],/nozero)
0 : ret=make_array(type=self.info.datatype,[self.info.coredims[[1,2]],nnames],/nozero)
1 : ret=make_array(type=self.info.datatype,[self.info.coredims[[0,2]],nnames],/nozero)
endcase
special=self->getspecialvalues()
ret[*]=self.info.datatype eq 4 ? !values.f_nan : (self.info.datatype eq 5 ? !values.d_nan : special.null)
found=intarr(nnames)
index=intarr(nnames)
sufnames=type eq 2 ? self.bnames : (type eq 0 ? self.snames : self.bonames)
sufvals=type eq 2 ? self.backplanes : (type eq 0 ? self.sideplanes : self.bottomplanes)
if ptr_valid(sufnames) then begin
csufnames=cases ? *sufnames : strupcase(*sufnames)
cnames=cases ? names : strupcase(names)
for i=0,nnames-1 do begin
if (cnames[i] eq 'X') or (cnames[i] eq 'Z') then begin
if (cnames[i] eq 'X') then tmp=indgen(self.info.coredims[[0,1]]) mod self.info.coredims[0]
if (cnames[i] eq 'Z') then tmp=reverse(floor(indgen(self.info.coredims[[0,1]]) / self.info.coredims[0]),2)
ret[0,0,i]=tmp+1
endif else begin
w=where((strpos(csufnames,cnames[i]) ne -1),nw)
found[i]=nw
index[i]=w[0]
if (nw gt 0) then ret[0,0,i]=(*sufvals)[*,*,w[0]]
endelse
endfor
endif
return,ret
end
function pp_readcube::getbandbywavelength,wavs,index=inds,wavelengths=sdwavs
compile_opt idl2
nwavs=n_elements(wavs)
if (nwavs eq 0) then message,'Wavelengths were not provided'
catch,error_status
if (error_status ne 0) then begin
catch,/cancel
message,'Cube does not contain valid wavelengths'
endif else dwavs=double(*self.wavs)
ndwavs=n_elements(dwavs)
tmp0=rebin(reform(wavs,1,nwavs),ndwavs,nwavs)
tmp1=rebin(dwavs,ndwavs,nwavs)
void=min(tmp0-tmp1,inds,/abs,dim=1,/nan)
inds=reform((array_indices(tmp0,inds))[0,*])
ret=(*self.core)[*,*,inds]
sdwavs=dwavs[inds]
return,ret
end
function pp_readcube::getbandbyindex,index,wavelengths=sdwavs
compile_opt idl2
ninds=n_elements(index)
if (ninds eq 0) then message,'Indexes were not provided'
catch,error_status
if (error_status ne 0) then begin
catch,/cancel
message,'Cube does not contain given band'
endif else dwavs=double(*self.wavs)
ret=(*self.core)[*,*,index]
sdwavs=dwavs[index]
return,ret
end
function pp_readcube::getfromheader,key,history=hist,$
count=count,fold_case=fold_case,lines=lines,unquote=unquote,sel=sel,cont=cont
compile_opt idl2
hist=n_elements(hist) eq 1 ? hist : 0
tmp=hist ? *self.thistory : *self.tlabels
ret=pp_getcubeheadervalue(tmp,key,count=count,fold_case=fold_case,lines=lines,unquote=unquote,sel=sel,cont=cont)
return,ret
end
function pp_readcube::_overloadBracketsRightSide, isRange, sub1, $
sub2, sub3, sub4, sub5, sub6, sub7, sub8
compile_opt idl2,logical_predicate
if (n_elements(isrange) ne 1) then return,!null
if (isrange[0]) then begin
core=self.getproperty(/core)
ret=core[*,*,sub1[0]:sub1[1]:sub1[2]]
return,ret
endif
case 1 of
isa(sub1,'string') : ret=self.getsuffixbyname(sub1)
isa(sub1,'double') : ret=self.getbandbywavelength(sub1)
isa(sub1,'float') : !null=self.getbandbywavelength(sub1,wavelengths=ret)
isa(sub1,'int') || isa(sub1,'uint') || isa(sub1,'long') || isa(sub1,'ulong') || $
isa(sub1,'long64') || isa(sub1,'ulong64') : ret=self.getbandbyindex(sub1)
else: ret=!null
endcase
return,ret
end
pro pp_readcube__define
compile_opt idl2
void={pp_readcube,$
file:'',$
special:0B,$
labels:ptr_new(),tlabels:ptr_new(),$
history:ptr_new(),thistory:ptr_new(),$
raw:ptr_new(),$
info:{pp_readcube_info,datatype:0,littleendian:1B,$
recordbytes:0L,filerecords:0L,labelrecords:0L,historyrecords:0L,binaryrecords:0L,$
historystart:0L,binarystart:0L,$
bytes:0B,type:'',$
dims:lonarr(3),coredims:lonarr(3),suffdims:lonarr(3)},$
core:ptr_new(),backplanes:ptr_new(),sideplanes:ptr_new(),bottomplanes:ptr_new(),$
wavs:ptr_new(),units:'UNKNOWN',$
bnames:ptr_new(),snames:ptr_new(),bonames:ptr_new(),$
bunits:ptr_new(),sunits:ptr_new(),bounits:ptr_new(),$
dwavs:ptr_new(),idwavs:ptr_new(),$
inherits IDL_Object}
return
end