;+ ; NAME: ; LOAD_CDF ; ; PURPOSE: ; The purpose of this programme is to extract from a CDF ; file a variable whose name is known. ; ; CATEGORY: ; I/O routine ; ; CALLING SEQUENCE: ; load_cdf,CDF_file,CDF_var,x,REC_COUNT=rcnt,REC_START=rstr ; ; INPUTS: ; CDF_file: Name of the CDF file to be opened. CDF_name ; is a string. ; CDF_var: Name of the variable to be read. CDF_name is a ; string. ; ; OPTIONAL INPUTS: ; REC_COUNT: Number of record to be read. If rec_count is too ; large, the file is read to the last record. ; REC_START: First record to be read. If not specified, reading ; starts at record=0. ; ; KEYWORD PARAMETERS: ; None. ; ; OUTPUTS: ; x: Variable read from the CDF file. The first dimension ; is the number of record read. x=-1 if occurs an I/O ; error. ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; None. ; ; EXAMPLE: ; To read the Number of 32-spectra in each pixel of the ; NS_V001.cdf file: ; ; load_cdf,'NS_V001.cdf','Nspectra',x ; ; x is an an array of 1790 values. The name of the variable ; to be read is found in the document 'NS_V001-info.txt' ; ; MODIFICATION HISTORY: ; ; Included to the release of Lunar Prospector data ; on Wed Sep 30, 1998, by Sylvestre Maurice ; ;- pro load_cdf,CDF_file,CDF_var,x,REC_COUNT=rcnt,REC_START=rstr ON_IOERROR,BAD ; Open CDF file id = -1 id = cdf_open(CDF_file) ; Get file CDF structure information inq = cdf_inquire(id) ; Get variable structure information vinq = cdf_varinq(id,CDF_var) ; Check to see if REC_START keyword is used IF KEYWORD_SET(rstr) EQ 0 THEN rstr = 0 ; Check to see if variable requested is a Z variable case 1 of (vinq.is_zvar eq 0): begin ; NOT Z var dims = total(vinq.dimvar) dimc = vinq.dimvar * inq.dim dimw = where(dimc eq 0) if (dimw(0) ne -1) then dimc(dimw) = 1 IF KEYWORD_SET(rcnt) EQ 0 THEN rcnt = inq.maxrec+1 if (vinq.recvar eq 'NOVARY') then rcnt = 1 if ((rstr+rcnt) gt inq.maxrec+1) then rcnt = inq.maxrec+1 - rstr CDF_varget,id,CDF_var,x,COUNT=dimc,REC_COUNT=rcnt,REC_START=rstr end else: begin ; IS Z var dims = total(vinq.dimvar) dimc = vinq.dimvar * vinq.dim dimw = where(dimc eq 0) if (dimw(0) ne -1) then dimc(dimw) = 1 !QUIET = 1 CDF_control,id,variable=CDF_var,/zvariable,get_var_info=vinfo !QUIET = 0 IF KEYWORD_SET(rcnt) EQ 0 THEN rcnt = vinfo.maxrec+1 if (vinq.recvar eq 'NOVARY') then rcnt = 1 if ((rstr+rcnt) gt vinfo.maxrec+1) then rcnt = vinfo.maxrec+1 - rstr CDF_varget,id,CDF_var,x,COUNT=dimc,REC_COUNT=rcnt,REC_START=rstr,/zvariable end endcase sa = size(x) sa = sa(1:sa(0)) if (vinq.recvar eq 'VARY' and dims ne 0 and rcnt gt 1) then begin dummy=sa(0:(n_elements(sa)-2)) aa = long(dummy(0)) for i = 1,n_elements(dummy)-1 do aa = aa*dummy(i) x = reform(x,[aa,sa(n_elements(sa)-1)]) x = transpose(x) sa = shift(sa,1) x = reform(x,sa) endif saw = where(sa ne 1) x = reform(x,sa(saw)) goto, DONE BAD: x = -1 DONE: if (id ne -1) then CDF_close,id return end