PRO IridiumMACCS3,filename
;This program is run by ftpsri.sh at :00, :15, :30, and :45 past every hour of every day.
;It creates IAGA2000 format ASCII files from the raw MACCS Iridium data.
;Overhaul Modifications by Michael Murphy Augsut 1, 2007 to begin working for 2 Maccs station
;Modifications by Erik Johnson August 15, 2007 to run on yspace from a script (maccsprocessing.sh)
;Modifications by Erik Johnson August 16, 2007 to comply with the IAGA2000 Data Exchange Format
close, /all
;filename='/Volumes/physics_data/Ftp/MACCS_DATA/Raw/CD/2007ir/*.dat'
;print, filename
openr,unit,filename,error=err,/get_lun
test_array = bytarr(11)
readu,unit,test_array
reclen=test_array(10)+9
free_lun,unit
openr,unit,filename,error=err,/get_lun
file_info = fstat(unit)
file_size = file_info.size/reclen
data_array = bytarr(reclen,file_size)
if (err eq 0) then begin
print,'Now processing ',filename
readu,unit,data_array
free_lun,unit
endif else begin
print,'An error has occurred while trying to read ',filename
stop
endelse
numsamples=(test_array(10)-9)/3/3
xvalue=fltarr(numsamples,file_size)
yvalue=fltarr(numsamples,file_size)
zvalue=fltarr(numsamples,file_size)
timevalue=data_array(4,*)*3600.0+data_array(5,*)*60.0+data_array(6,*)
FOR i=0,numsamples-1 DO BEGIN
xvalue(i,*)=(data_array(18+(i*9),*)*65536l+data_array(19+(i*9),*)*256l+data_array(20+(i*9),*))*0.025
yvalue(i,*)=(data_array(21+(i*9),*)*65536l+data_array(22+(i*9),*)*256l+data_array(23+(i*9),*))*0.025
zvalue(i,*)=(data_array(24+(i*9),*)*65536l+data_array(25+(i*9),*)*256l+data_array(26+(i*9),*))*0.025
ENDFOR
n=findgen(file_size)
nstep=n
n=n*2
bx=fltarr(file_size*2l)
by=bx
bz=bx
bx[n]=xvalue[0,nstep]
bx[n+1]= xvalue[1,nstep]
by[n]=yvalue[0,nstep]
by[n+1]= yvalue[1,nstep]
bz[n]=zvalue[0,nstep]
bz[n+1]= zvalue[1,nstep]
Dtime=dblarr(file_size*2l)
Dtime[n]=timevalue[0,nstep]+ 0.25
Dtime[n+1]= timevalue[0,nstep]+ 0.75
;Section for writing data
lab =
label=strmid(filename,0,2)
labelx=strmid(filename,2,5)
yrday=fix(labelx)
MMDD, YRDAY, MON, DAY
year=strmid(labelx,0,2)
year1=fix(year)
if year1 ge 92 then begin
year=string('19',year)
endif else begin
year=string('20',year)
endelse
;Create The 11 mandatory file header records
line1=' Format | IAGA2000 |'
if label eq 'NA' then begin
line2=' Station | Nain, Canada |'
line3=' IAGA Code | NAN |'
line4=' Geodetic Latitude | 56.4 |'
line5=' Geodetic Longitude | 298.3 |'
line6=' Elevation | 7 |'
endif
if label eq 'CD' then begin
line2=' Station | Cape Dorset, Canada |'
line3=' IAGA Code | CDR |'
line4=' Geodetic Latitude | 64.2 |'
line5=' Geodetic Longitude | 283.4 |'
line6=' Elevation | 50 |'
endif
line7=' Observed | XYZ |'
line8=' Digital Sampling | 0.5 seconds |'
line9=' Data Interval | 0.5 seconds |'
line10=' Data type | Variation |'
line11=' Variables | 9 |'
line12=' # For more information visit
http://space.augsburg.edu |'
line13=' Year| MT| DY| HR| MN| SC| CDRX| CDRY| CDRZ|'
length=size(bx,/n_elements)
newarray = fltarr(4,length)
stringarr = strarr(1,length)
;newarray[0,*]= ' '
newarray[0,*]= Dtime
newarray[1,*] = bx
newarray[2,*] = by
newarray[3,*] = bz
for i=1l, length, 1 do begin
totals = newarray[0,i-1]
hour = fix(totals/3600)
totals = totals - (hour*3600l)
min = fix(totals/60)
sec = fix(totals - (min*60))
data = string(year, mon, day, hour, min, sec, newarray[1,i-1],newarray[2,i-1],newarray[3,i-1], $
format='(" ", a4, "| ", i2, "| ", i2, "| ", i2, "| ", i2, "| ", i2, "|", f10.2, "|", f10.2, "|", f10.2, "|")')
stringarr[0,i-1] = data
endfor
openw, 2,'/Volumes/physics_data/Ftp/MACCS_DATA/IAGA2000/'+label+'/'+year+'ir/'+label+labelx+'.dat',width=107
printf,2,line1
printf,2,line2
printf,2,line3
printf,2,line4
printf,2,line5
printf,2,line6
printf,2,line7
printf,2,line8
printf,2,line9
printf,2,line10
printf,2,line11
printf,2,line12
printf,2,line13
printf,2,stringarr
;printf,2,newarray,format='(f8.2,3f15.3)'
close, 2
print, 'program finished'
END
PRO MMDD,YRDAY,MONTH,MNTHDA,IYR
; 11 NOV 85 S FAVIN
; GIVEN YRDAY LIKE 85199
; RETURNS WITH CHARACTER MONTH AND DAY NUMBER IN MONTH
LEAPYR = [0,0,31,60,91,121,152,182,213,244,274,305,335,366]
NOLEAP = [0,0,31,59,90,120,151,181,212,243,273,304,334,365]
CHARM = [,'1','2','3','4','5','6', $
'7','8','9','10','11','12']
MONTH =
IYEAR = FIX(YRDAY/1000)
IDAY = FIX(YRDAY - IYEAR*1000)
MON= FIX(IDAY/30+1)
IF((IYEAR MOD 100) EQ 0) THEN GOTO, A366
IF((IYEAR MOD 4) EQ 0) THEN GOTO, A366
IF((IDAY-NOLEAP(MON)) LE 0) THEN MON = MON -1
MNTHDA=IDAY-NOLEAP(MON)
A365: MONTH = CHARM(MON)
IYR=IYEAR
RETURN
A366: IF((IDAY-LEAPYR(MON)) LE 0) THEN MON = MON - 1
MNTHDA=IDAY-LEAPYR(MON)
GOTO, A365
END
function xticks, axis, index, value
on_error,1
if keyword_set(help) then begin
helpdir = 'c:\rsi\idl40\help\user'
helpfile = helpdir + '\xticks.txt'
xdisplayfile, helpfile
return, 0
endif
;hour = fix(value+.5)
hour = fix(value)
if hour gt 23 then hour = hour -24
min = fix(value*60. mod 60.)
sec = fix(value*3600. mod 60. + .5)
if sec eq 60 then begin
sec = 0
min = min + 1
if min eq 60 then begin
min = 0
hour = hour+1
endif
endif
if sec eq 0 then begin ;Seconds are not shown on time scale if they are zero.
return, string(format = '(i2.2,":",i2.2)',hour,min)
endif
;min = fix(value*60. mod 60. + .5)
;if min eq 60 then begin
; min = 0
; hour = hour+1
;endif
;sec = fix(value*3600. mod 60. + .5)
;if sec eq 60 then sec = 0
return, string(format = '(i2.2,":",i2.2,":",i2.2)', hour, min, sec)
end

