; Comments added by Erik Johnson 7/6/07
; write_maccs.pro, compiles and runs with idl
; called by igloolik_despike.pro (which creates despiked .s2 files)
; called by five_sec_avg.pro (which creates 5 second average .5s files)
; called by sec_to_min.pro (which creates 1 minute average .1m files)
; writes 5 different types of maccs data files: .1m (1 minute files), .1mg (1 month of 1 min files merged together in one file), .5sg (rotated 5 second files), .5s (5 second files), .s2 (cleaned files)
; uses the type parameter to specify what type of file to write, Ex: type="1m"
; all parameters are required
pro write_maccs,filename,bx,by,bz,bx2=bx2,by2=by2,bz2=bz2,tf1=tf1,type=type
case type of
'1m':begin
new_data=bytarr(14,1440)
for j=0,1439 do begin
hr=floor(j*60./3600.)
mi=floor((j*60.-hr*3600.)/60.)
; writeu,unit2,byte(hr),byte(mi),long(bx(j)*1000),long(by(j)*1000),long(bz(j)*1000)
new_data(*,j)=byte([byte(hr),byte(mi),$
reform(byte(long(bx(j)*1000),0,1,4)),$
reform(byte(long(by(j)*1000),0,1,4)),$
reform(byte(long(bz(j)*1000),0,1,4))],0,1,14)
endfor
openw,unit2,filename,/get_lun
writeu,unit2,new_data
free_lun,unit2
end
'1mg':begin
new_data=bytarr(14,1440)
for j=0,1439 do begin
hr=floor(j*60./3600.)
mi=floor((j*60.-hr*3600.)/60.)
; writeu,unit2,byte(hr),byte(mi),long(bx(j)*1000),long(by(j)*1000),long(bz(j)*1000)
new_data(*,j)=byte([byte(hr),byte(mi),$
reform(byte(long(bx(j)*1000),0,1,4)),$
reform(byte(long(by(j)*1000),0,1,4)),$
reform(byte(long(bz(j)*1000),0,1,4))],0,1,14)
endfor
openw,unit2,filename,/get_lun
writeu,unit2,new_data
free_lun,unit2
end
'5sg':begin
openw,unit2,filename,/get_lun
for j=0,17279 do begin
hr=floor(j*5./3600.)
mi=floor((j*5.-hr*3600.)/60.)
se=j*5.-(hr*3600.+mi*60.)
writeu,unit2,byte(hr),byte(mi),byte(se),long(bx(j)*1000),long(by(j)*1000),long(bz(j)*1000)
endfor
free_lun,unit2
end
'5s':begin
openw,unit2,filename,/get_lun
for j=0,17279 do begin
hr=floor(j*5./3600.)
mi=floor((j*5.-hr*3600.)/60.)
se=j*5-(hr*3600.+mi*60.)
writeu,unit2,byte(hr),byte(mi),byte(se),long(bx(j)*1000),long(by(j)*1000),long(bz(j)*1000)
endfor
free_lun,unit2
end
's2':begin
openw,unit2,filename,/get_lun
for j=0L,86399L do begin
hr=floor(j/3600.)
mi=floor((j-hr*3600.)/60.)
se=j-(hr*3600.+mi*60.)
writeu,unit2,byte(tf1(j)),byte(hr),byte(mi),byte(se),$
long(bx(j)*1000),long(bx2(j)*1000),$
long(by(j)*1000),long(by2(j)*1000),$
long(bz(j)*1000),long(bz2(j)*1000)
;if j eq 86399L then begin
; print, bx(j),long(bx(j)),tf1(j),byte(tf1(j)),byte(hr),byte(mi),byte(se)
; help, bx, tf1, hr, mi, se
;endif
endfor
free_lun,unit2
end
endcase
print,'done writing'
end

