elscntplot.pro 4.38 KB
;==========================================================
;                DD DDMARS/DDVEX
;                 elscntplot.pro
;    
;-----------------------------------------------------------

pro elscntplot, Mission, anodStart, anodStop, enMin, enMax

common VexELS, VexELS, VexElsPlus
common MexELS, MexELS, MexElsPlus
common GraphC, Graph,GraphN, Item
common request, List, StartTime, TimeInt
   
   cmd = 'ElsPlus = ' + Mission + 'ElsPlus'
   R = execute(cmd);  
   
 ; Expand DeltaT a little : Get Energy Calibration
 
  StD = call_external(!DDLIB+'DD_idl.so','GetDTime', StartTime, /D_VALUE)
  DtD = call_external(!DDLIB+'DD_idl.so','GetDTime', TimeInt, /D_VALUE)
  StD = StD - 100.0D0
  DtD = DtD + 200.0D0
  stloc = call_external(!DDLIB+'DD_idl.so','GetTime',StD, /S_VALUE)
  dtloc = call_external(!DDLIB+'DD_idl.so','GetTime',DtD, /S_VALUE)
  Size = Long(DtD/4. + 2)
  Nen = 128;
  Energy = fltarr(Nen, Size)
  Tm = dblarr(Size)
  ID = -1L;
  
  err = call_external(!PROJLIB + 'libplanetcom.so','SetMission_idl', Mission);
  RetSize = call_external(!PROJLIB + 'els_idl.so','GetRef',   $
                                                 ID,    $
                                                 stloc, $
                                                 dtloc, $
                                                 Size,  $
                                                 Tm,    $
                                                 Energy)
  if (err GE 0) then Tm  -= Graph[GraphN].TimeBase
  err = call_external(!DDLIB +'DD_idl.so','CloseID',ID)

; data 
 
   Time = (*Graph[GraphN].Time[0]); 
   N_Time = N_elements(Time);

   Val = (*Graph[GraphN].Val[0]);
   Val = temporary(reform(Val, 16, Nen, N_Time)); 
   
   num = where(abs(Tm - Time[N_Time/2]) EQ min(abs(Tm - Time[N_Time/2])));

   E = Energy[*,num[0]]*ElsPlus.Sens[7];
 
   if ((enmin eq enmax) and (enmin eq 0)) then begin      
            enmax = E[0];
            enmin = E[126];       
   endif
       
   Data =  anodStop GT anodStart ? total(Val[anodStart:anodStop,*,*],1) : reform(Val[anodStart,*,*], 128, N_Time);

; if reduced Energy Table  

   reducedEnergy = E[0] LT 1000.0 ? 1 : 0; 
  ; if reduced Energy Table expand time
     if (reducedEnergy) then begin
	Nen = 32;
	enMax = enMax < 158.0; 
        newTime = dblarr(N_Time*4);
        for i = 0, N_Time-1 do for j = 0, 3 do newTime[i*4+j] = Time[i] + double(j);
        Time = newTime; 
        Data = reform(Data, Nen, N_Time*4);
        N_Time *= 4;    
        E = E(0:Nen-1);                   
     endif  
     
    E[Nen-1] = E[Nen-2]; 
    EBounds = fltarr(Nen+1);
    EBounds[0] = E[0];
    EBounds[Nen] = E[Nen-1]; 
    for ie = 1, Nen-1 do EBounds(ie) = sqrt(E(ie-1)*E(ie)); 
   
    num0 = where(EBounds ge enMin, Index0);
    num1 = where(EBounds ge enMax, Index1);
 
    if (Index1 eq Nen+1) then begin
	  nodatafortimeinterval
	  return
    endif

    if (Index1 eq 0)  then numStop = 0 else  numStop = num1[Index1-1];

    if (Index0 eq Nen+1) then numStart = 31 else numStart = num0[Index0-1];

    Data =  numStart ne numStop ? total(Data[numStop:numStart,*],1) : reform(Data[numStart,*], N_Time);
 ;   Data = IndexE gt 1 ? total(Data[numE,*],1) : reform(Data[numE[0],*], N_Time);

  ;  if (avEnergy) then Data /= IndexE;
  ;  if (avAngle) then Data /= (anodStop-anodStart+1); 
  
    numMinMax = where(finite(Data), IndexMinMax)
 
  ;--------------------- No DATA - just axes -----------------------
 
  if (IndexMinMax LE 0) then begin
        nodatafortimeinterval  
        return
  endif

  if (Time[0] GT Graph[GraphN].TotalTime) then begin
        nodatafortimeinterval
        return
  endif
 ;-------------------------------------------------------------------
  
  ;TODO test mode   if E(1) EQ E(126) then begin ; The test mode, just plot everything???         
    MinVal = min(Data[numMinMax]);   
    MaxVal = max(Data[numMinMax]);
   
    if Graph[GraphN].Ly.range[0] eq Graph[GraphN].Ly.range[1] then begin
                Graph[GraphN].Ly.range = Graph[GraphN].AxisF eq 'logaxis' ? [MinVal, MaxVal] : [0.0, MaxVal]
                Graph[GraphN].Ly.style = 0
    endif else Graph[GraphN].Ly.style = 1
    
    !y = Graph[GraphN].Ly;
    
     
    if (execute(Graph[GraphN].AxisF) NE 1) then plot, Time, Data, MAX_VALUE=MaxValue,  color = !dnc-1, /NODATA, /NOERASE 
    oplot, Time, Data,  MAX_VALUE=MaxValue, color = !dnc-1 

        
return
end  
;--------------------------------------------------------------------