getcefvar.pro 1.47 KB
function getCefVar, files,  paramName, dims, StartDouble, IntDouble, Time, Data
 ; CEF_UNDEF, CEF_INT, CEF_FLOAT, CEF_DOUBLE, CEF_CHAR, CEF_ISO_TIME, CEF_ISO_TIME_RANGE,
  
 Size = N_elements(Time);
 TIMESHIFT =  378691200.D0 ; secs 1970 - 1958
 
 startIndex = 0L;

 datapath = getenv("USER_DATA_PATH") eq '' ?  '../DATA/' : getenv("USER_DATA_PATH");

 for i = 0, n_elements(files) - 1 do begin
   
     fileName = datapath + files[i];
     nrec = CEF_READ(fileName);
     if (nrec LE 0) then continue;

     if (i EQ 0) then begin
	dataType = "UNKNOWN"
	timeId = 0L;
        vars = CEF_VARNAMES();
	while (dataType ne "ISO_TIME") do begin
	      dataType = CEF_VATTR(vars[timeId],"VALUE_TYPE"); 
	      timeId += 1L;
	endwhile
	timeId -= 1L;
     endif

      Time1 = CEF_VAR(vars[timeId])/1000.D0 -  TIMESHIFT;
       
      num = where(Time1 GE StartDouble AND Time1 LT StartDouble+IntDouble, Index);
 
      if ((Index eq 0 AND startIndex eq 0) OR (startIndex + Index gt Size))  then return, 0
        
      if (Index gt 0) then begin
            Time[startIndex:startIndex+Index-1] = Time1[num];
        
            Data1 = CEF_VAR(paramName);
           ; dims = CEF_VATTR(paramName, "SIZES")
            dims = n_elements(Data1)/n_elements(Time1);
            if (dims eq 1) then  Data[startIndex:startIndex+Index-1] = Data1[num]  $
            else Data[*, startIndex:startIndex+Index-1] = Data1[*, num]
      endif
      CEF_CLOSE
      startIndex += Index;     
  endfor 
  
 return,startIndex;
end