gettxtvar.pro 1.42 KB
function getTxtVar, files,  paramName, dims, StartDouble, IntDouble, Time, Data
 
 Size = N_elements(Time);
  
 startIndex = 0L;
 i_start = long(paramName);
 i_stop = i_start + dims - 1;
 
 datapath = getenv("USER_DATA_PATH") eq '' ?  '../DATA/' : getenv("USER_DATA_PATH");
 for i = 0, n_elements(files) - 1 do begin
 ; print,  i, "FILENEME", files[i]
     openr, LUN, datapath+files[i], err = err, /GET_LUN ;
     temp = " ";
    
     while not EOF(LUN) do begin
        readf, LUN, temp
        arr = strsplit(temp, " ", /EXTRACT);
        Time1 = N_Elements(Time1) eq 0 ? double(arr[0]) : [Time1,double(arr[0])];   
        Data1 = N_Elements(Data1) eq 0 ? float(arr[i_start:i_stop]) : [Data1, float(arr[i_start:i_stop])]        
    endwhile

    close,LUN
    free_lun,LUN  
  endfor 

   num = where(Time1 GE StartDouble AND Time1 LT StartDouble+IntDouble, Index);
 ;  print, "INDEX ",Index, " SIZE ", Size, " INDEX+ ", startIndex + 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];
        if (dims eq 1) then  Data[startIndex:startIndex+Index-1] = reform(Data1[num])  $
        else begin 
                Data1 = reform(Data1,dims,N_elements(Time1))
                Data[*, startIndex:startIndex+Index-1] = Data1[*, num]
        endelse      
   endif
  startIndex += Index; 
 return, startIndex;
end