;************************************************* ; Open the file and read in the data. ; The hdf variable is passed back out as "data" ; Add count and start to subset out just a section ;************************************************* pro get_cloudsat,filedir,filename,dataname,data,count_profiles,idx_profiles ;************************************************* ; These come in through the command line ;************************************************* ; HDF file directory ;filedir='/data/mace31/cloudsat/CS_2B-GEOPROF_GRANULE_P_R04/' ;filedir='/uufs/chpc.utah.edu/common/home/mace_grp/data/cloudsat/'+$ ; 'CS_2B-GEOPROF_GRANULE_P_R04/' ; HDF file name ;filename='2007297230603_07931_CS_2B-GEOPROF_GRANULE_P_R04_E02.hdf' ; Variable name ;dataname='Latitude' ;************************************************* ; First try to read the variable as type SD ;************************************************* ; Open HDF file in SD mode file_id=hdf_sd_start(filedir+filename,/read) ; Get SD variable var_id=hdf_sd_nametoindex(file_id,dataname) ; If it is an SD variable then continue if var_id ne -1 then begin ;print,'found sdata ',dataname ; Get the SD variable sds_id=hdf_sd_select(file_id,var_id) ; Gets only a section of data if n_elements(count_profiles) gt 0 then begin ; number of dimensions and their values HDF_SD_GETINFO, sds_id,NDIMS=ndims,DIMS=dims ;PRINT,'numdims',ndims,' dimensions ',dims ; Old way before I found there were 3d arrays as well ;dim_id=hdf_sd_dimgetid(sds_id,0) ;hdf_sd_dimget,dim_id,count=cnt ;hdf_sd_getdata,sds_id,data,count=[cnt,count_profiles],start=[0,idx_profiles[0]] if ndims eq 3 then begin hdf_sd_getdata,sds_id,data,count=[dims[0],count_profiles,dims[2]],start=[0,idx_profiles[0],0] ;help,data endif else if ndims eq 2 then begin hdf_sd_getdata,sds_id,data,count=[dims[0],count_profiles],start=[0,idx_profiles[0]] ;help,data endif else if ndims eq 1 then begin print,'found a 1d sd variable' stop endif endif else begin ; Gets the whole data array hdf_sd_getdata,sds_id,data ;help,data endelse ; Close SD variable hdf_sd_endaccess,sds_id ; Close hdf file hdf_sd_end,file_id ;************************************************* ; If it isn't a SD variable then try to read the ; variable as type VD ;************************************************* endif else begin ; Close hdf file as opened above hdf_sd_end,file_id ; Open the hdf file fid=hdf_open(filedir+filename,/read) ; Locate and attach a VD variable vdref=hdf_vd_find(fid,dataname) vdid=hdf_vd_attach(fid,vdref,/read) ; Gets only a section of data if n_elements(count_profiles) gt 0 then begin hdf_vd_seek,vdid,idx_profiles[0] result=hdf_vd_read(vdid,data,nrecords=count_profiles) ;print,'found vdata ',dataname ;help,data endif else begin ; Get the whole variable result=hdf_vd_read(vdid,data) endelse ; Close hdf file hdf_vd_detach,vdid hdf_close,fid endelse end