; Comments added by Erik Johnson 7/16/07
; five_sec_avg.pro, compiles and runs with idl
; it is used in the 1/2 sec to 5 sec avg step
; needs five_sec_avg_fast_avg.pro, read_maccs.pro & write_maccs.pro to run
; input must be clean maccs files (.s2 files)
; output is 5 second average files (.5s files)
; example file names: input: CD04024.s2 output: CD04024.5s
; to compile & run: five_sec_avg, files="/path_to_input_file(s)/name_of_input_file(s)", out_dir="/path_to_output_directory/" (you can use * and ?)
; Example: five_sec_avg, files="/Volumes/physics_data/Ftp/MACCS_DATA/Clean/CD/2005/*.s2", out_dir="/Volumes/physics_data/Ftp/MACCS_DATA/Unrotated/5sec/CD/2005/"
pro five_sec_avg, files=files, out_dir=out_dir
if (not keyword_set(files)) and (not keyword_set(out_dir)) then begin
print,'Enter files=search string and out_dir=output directory'
print,'Also, you must compile first with .r five_sec_avg'
stop
endif
; This program makes 5 sec averages from 1/2 sec MACCS data 04/26/00
print,'running five_sec_avg ver 1.0'
data_files = findfile(files,count=count)
if count eq 0 then begin
print,'No files found in '+in_dir+' with '+files
stop
endif
for i = 0, count-1 do begin
read_maccs,data_files(i),time,bx1,by1,bz1,type,$
bx2=bx2,by2=by2,bz2=bz2,/nt
if type eq 2 then begin
; bad_bx1=where(bx1 eq 32767,count)
; bx2(bad_bx1) = 32767
bx_avg = five_sec_avg_fast_avg(bx1,bx2)
by_avg = five_sec_avg_fast_avg(by1,by2)
bz_avg = five_sec_avg_fast_avg(bz1,bz2)
;PRINT, 'The min and max of bx are ', MIN(bx_avg), ' and ', MAX(bx_avg)
;PRINT, 'The min and max of by are ', MIN(by_avg), ' and ', MAX(by_avg)
;PRINT, 'The min and max of bz are ', MIN(bz_avg), ' and ', MAX(bz_avg)
endif else begin
print,'GSC file'
bx2=bx1 & by2=by1 & bz2=bz1
bx_avg = five_sec_avg_fast_avg(bx1,bx2)
by_avg = five_sec_avg_fast_avg(by1,by2)
bz_avg = five_sec_avg_fast_avg(bz1,bz2)
endelse
; plot,bx_avg,max_val=30000,/ystyle
new_file = out_dir+$
strmid(data_files(i),strlen(data_files(i))-10,8)+'5s'
write_maccs,new_file,[32767,bx_avg,32767],$
[32767,by_avg,32767],$
[32767,bz_avg,32767],type='5sg'
endfor
end

