mex_h_spec_restr_.pro 1.92 KB
function mex_h_spec_restr_, StartTime, TimeInt, Time, RetSize, Sampling, close=close
common GraphC, graph, GraphN
common MEX_H_COM, ID, Energy

FORWARD_FUNCTION gfl

   FillValue =  !Values.F_NAN
   
   if n_elements(ID) EQ 0 then  begin
     ID = -1L
     err = call_external(!PROJLIB + 'libplanetcom.so','SetMission_idl', 'mex');
     err = call_external(!PROJLIB + 'libplanetcom.so','SetRestriction');
     EnNum = 96
     Energy = fltarr(EnNum)
     err = call_external(!PROJLIB + 'imainfo.so','GetImaEner_idl', Energy, 0)
     Energy =  temporary(Energy(where(Energy GT 0)));
   endif
   
   sampling = 192.0;
  
   Size = long(graph[GraphN].DeltaT/sampling)

   Time=dblarr(Size)
   SpectraTot = fltarr(16, 96, 16, 2, Size)
   Product = 'HPSPEC';
   PaccArr = intarr(Size);
   EnergyTab = intarr(Size);

    RetSize = call_external(!PROJLIB + 'libImaExtra.so','GetImaExtra_idl',$
                                ID, StartTime, TimeInt,$
                                Product, Size, $
                                Time, PaccArr, EnergyTab, SpectraTot)
                                
  
   if KEYWORD_SET(CLOSE) then begin
      error = call_external(!DDLIB+'DD_idl.so','CloseID',ID)
      ID = -1L
   endif                              
   
   if (RetSize LE 0) then begin
      Time = 0.D0
      return, replicate(0.0, 96)
   endif
 
   Spectra = fltarr(16, 96, 16, RetSize);
   
         for i = 0, RetSize - 1 do $
            for j = 0, N_elements(Energy) - 1 do begin
               GFeff = gfl(Energy[j], PaccArr[i], 1.0);
               GFeffG = gfl(Energy[j], PaccArr[i], 0.0); Ghost
                 
               coeffH = GFeff GT 0 ? 1.e-5/GFeff : 0.0;
               coeffG = GFeffG GT 0 ? 1.e-5/GFeffG : 0.0;
             
               Spectra[*,j,*,i] = SpectraTot[*,j,*,0,i]*coeffH + SpectraTot[*,j,*,1,i] * coeffG;
         endfor 

   
   SpectraOut = total(total(Spectra,1),2);
   Time=Time[0:Retsize-1]
   
return, SpectraOut
end