pro MAKE_N3G_FILES, aaaajjjd, hd, aaaajjjf, hf, bg_file, fichier=fichier, $
verbose=verbose, nodb=nodb
READ_DATA_BINARY,bg_file,bg,level='bg'
xf=bg.xf & nf=n_elements(xf)
fon5=bg.fon5
restore,getenv('ROOT_RPWS')+'/pro/receiver_backgroundj.idl'
rec_bg=fon5
for i=0,2 do rec_bg(i,*)=10.^(interpol(xrm,fr,xf)/10.)
rec_bg(3,*)=10.^(interpol(xrd,fr,xf)/10.)
fon=(fon5-rec_bg)>1.e-18
restore,getenv('ROOT_RPWS')+'/pro/gal_mod.idl'
sgmod=interpol(sgalmod,fgalmod,xf)>0.
K=[1070.,1070.,1070.,3520.]
print,'% Loading List of Files for the selected period ...'
if not(keyword_set(fichier)) then begin
ptrDataFileList = make_file_list(aaaajjjd, hd, aaaajjjf, hf, level='n2')
if (ptr_valid(ptrDataFileList) eq 0) then begin
nDataFile=0
print,"# Warning ! No N2 data file selected..."
endif else begin
dataFileList=*ptrDataFileList
nDataFile = n_elements(dataFileList)
n3gfiles = strarr(nDataFile)
ptr_free, ptrDataFileList
endelse
endif else begin
dataFileList=[fichier]
nDataFile=1
n3gfiles = strarr(nDataFile)
endelse
for iDataFile = 0,nDataFile-1 do begin
fichier = dataFileList(iDataFile)
str_tmp = strsplit(fichier,'n2/P',/extract,/regex)
print & print,'% fichier : ',fichier
READ_DATA_BINARY,fichier,data_n2,level='n2'
nn = n_elements(data_n2)
fileOut= str_tmp(0)+'n3g/F'+str_tmp(1)
fi=intarr(nn)
for i=0L,nn-1 do fi(i)=where(xf eq data_n2(i).f) >0
data_n3g = replicate({data_n3g},nn)
w=where(data_n2.f le 1000)
if w(0) ne -1 then data_n3g(w).fluxZ=((data_n2(w).autoZ-rec_bg(0,fi(w)))>0)/K(0)
for j=1,3 do begin
w=where(data_n2.f le 1000 and (data_n2.ant mod 10) eq j)
if w(0) ne -1 then data_n3g(w).fluxX=((data_n2(w).autox-rec_bg(j,fi(w)))>0)/K(j)
endfor
w=where(data_n2.f gt 1000 and data_n2.f lt 2000)
if w(0) ne -1 then data_n3g(w).fluxZ=( ((data_n2(w).autoZ-rec_bg(0,fi(w)))>0)/K(0) + sgmod(fi(w))*((data_n2(w).autoZ-rec_bg(0,fi(w)))>0)/fon(0,fi(w)) )/2.
for j=1,3 do begin
w=where(data_n2.f gt 1000 and data_n2.f lt 2000 and (data_n2.ant mod 10) eq j)
if w(0) ne -1 then data_n3g(w).fluxX=( ((data_n2(w).autox-rec_bg(j,fi(w)))>0)/K(j) + sgmod(fi(w))*((data_n2(w).autoX-rec_bg(j,fi(w)))>0)/fon(j,fi(w)) )/2.
endfor
w=where(data_n2.f ge 2000)
if w(0) ne -1 then data_n3g(w).fluxZ=sgmod(fi(w))*((data_n2(w).autoZ-rec_bg(0,fi(w)))>0)/fon(0,fi(w))
for j=1,3 do begin
w=where(data_n2.f ge 2000 and (data_n2.ant mod 10) eq j)
if w(0) ne -1 then data_n3g(w).fluxX=sgmod(fi(w))*((data_n2(w).autoX-rec_bg(j,fi(w)))>0)/fon(j,fi(w))
endfor
data_n3g.ydh=data_n2.ydh
data_n3g.num=data_n2.num
print,'writing ',fileOut,' ...'
WRITE_DATA_BINARY, fileOut, data_n3g
n3gfiles[iDataFile] = fileOut
endfor
if ~keyword_set(nodb) and nDataFile ne 0 then begin
upsert_args = getenv('ROOT_RPWS') + '/pro/kronosdb/upsert.sh'
if keyword_set(verbose) then upsert_args = [upsert_args, '-v']
upsert_args = [upsert_args, '-f', n3gfiles]
spawn, /NOSHELL, upsert_args
end
return
end