PRO wid_draw_event, ev
WIDGET_CONTROL, ev.top, GET_UVALUE = ev_var
WIDGET_CONTROL, ev.id, GET_UVALUE = uval
CASE uval OF
'DRAW' : begin
IF ((*ev_var).mouse((*ev_var).component) eq 0 AND ev.type eq 0) THEN BEGIN ;If draw lines is selected this loop begins
n = (*ev_var).n + 1 ;which takes the coordinates of your mouse location and
(*ev_var).n = n ;takes the coordinates of where you LAST clicked,
(*ev_var).x(0) = 0 ;and draws a line connecting the two points
location = convert_coord(ev.x, ev.y, /device, /to_data)
(*ev_var).x(n) = location(0)
(*ev_var).y(n) = location(1)
IF ((*ev_var).x(n) gt 365) THEN BEGIN
(*ev_var).x(n) = 365.
(*ev_var).y(n) = (*ev_var).y(n-1)
ENDIF
PLOTS,[(*ev_var).x(n-1),(*ev_var).x(n)],[(*ev_var).y(n-1), (*ev_var).y(n)], COLOR = 25
delx = (*ev_var).x(n) - (*ev_var).x(n-1) ;The slope and y-intercept of the drawn line is found and every day
dely = (*ev_var).y(n) - (*ev_var).y(n-1) ;that is in between the endpoints of the line
m = dely / delx ;is assigned the line's slope and y-intercept
b = (*ev_var).y(n) - (m * (*ev_var).x(n))
FOR i = FLOOR((*ev_var).x(n-1)) + 1, FLOOR((*ev_var).x(n)) DO BEGIN
(*ev_var).slope[i] = m
(*ev_var).yintercept[i] = b
ENDFOR
print, 'Size of '
help, (*ev_var).y_val_all3
FOR j = 1, 365 DO BEGIN ;From the slope and y-intercept of everyday
(*ev_var).y_val_all3[j,(*ev_var).component] = j * (*ev_var).slope[j]$ ;a yvalue is found for that day and stored in
+ (*ev_var).yintercept[j] ;the state pointer array y_val_all3 (capable of storing
ENDFOR
PRINT, (*ev_var).y_val_all3[365,0]
Print, (*ev_var).y_val_all3[365,1]
Print, (*ev_var).y_val_all3[365,2] ;yvalues for every day for each component of a station)
ENDIF
IF ((*ev_var).mouse((*ev_var).component) eq 1) THEN BEGIN ;if fix lines is selected: when the mouse is
;DEPRESSED, a state pointer variable called 'motion'
IF (ev.type eq 0) THEN BEGIN ;is set to 1, a counter state pointer variable, m, which counts
(*ev_var).motion = 1 ;motion events is reset to zero, and two state pointer arrays which
(*ev_var).m = 0 ;contain the x and y data coordinates of where the
FOR i = 0, 99 DO BEGIN ;mouse is generating motion events, are reset to zero
(*ev_var).x2(i) = 0
(*ev_var).y2(i) = 0
ENDFOR
ENDIF
IF (ev.type eq 1) THEN (*ev_var).motion = 0 ;when the mouse button is RELEASED, the state
;pointer variable 'motion' set back to zero
IF ((*ev_var).motion eq 1 AND ev.type eq 2) THEN BEGIN ;this if-loop thus implies that
m = (*ev_var).m + 1 ;if the mouse button is being
(*ev_var).m = m ;held down and motion is occurring
local = convert_coord(ev.x, ev.y, /device, /to_data) ;then with each different pixel
(*ev_var).x2(m) = local(0) ;location the device coordinates
(*ev_var).y2(m) = local(1) ;will be converted to data coordinates
IF ((*ev_var).x2(m) lt 0 AND (*ev_var).x2(m) gt -.5) THEN BEGIN
(*ev_var).y_val_all3[0,(*ev_var).component] = (*ev_var).y2(m)
PLOT_IT, ev_var
ENDIF ELSE BEGIN
IF (ABS(((*ev_var).x2(m) MOD 1)-((*ev_var).x2(m-1) MOD 1)) ge .5) THEN BEGIN
day = FLOOR((*ev_var).x2(m) + .5) ;this embedded if loop finds when an
(*ev_var).y_val_all3[day,(*ev_var).component] = (*ev_var).y2(m) ;integer day is passed and changes the
(*ev_var).y_val_all3[day,(*ev_var).component] = (*ev_var).y2(m) ;yvalue at that day to the converted
PLOT_IT, ev_var ;device y-coordinate of where the motion
ENDIF ;event occurred.
ENDELSE
ENDIF
ENDIF ;The data and yvalues are then replotted
end ;with this new yvalue using the procedure PLOT_IT
;so that AS the user creates motion events with the
'DONE' : WIDGET_CONTROL, ev.top, /DESTROY ;this button exits the program ;mouse button pressed, these new yvalues
;are constantly integrated into the graph that the
'FILE' : GET_THE_FILE, ev_var ;Calls procedure GET_THE_FILE which gets the file ;user is looking at
'REPLOT': begin
; basex = [ 9450, 6150, 0, 6900, 4240, 6050, 4220, 3870, 0, 2850, 0, 0 ] ;The REPLOT button finds the rotation angles necessary and fixes
basex = [ 9450, 6150, 0, 6900, 4240, 7280, 4220, 3870, 0, 2850, 0, 0 ] ;The REPLOT button finds the rotation angles necessary and fixes
index = where ((*ev_var).y_val_all3(*,*) eq 0) ;the baseline that the user drew which is represented by the yvalues
PRINT, 'REPLOT ',index(0)
help, index
IF (index(0) eq -1) THEN BEGIN
FOR j = 0, 365 DO BEGIN
alpha = atan((*ev_var).y_val_all3[j,1],(*ev_var).y_val_all3[j,2]) ;these are the functions for finding
zvalp = ((*ev_var).y_val_all3[j,1] * (sin(alpha)) + ((*ev_var).y_val_all3[j,2] * cos(alpha))) ;the rotation angles
beta = FindBeta(zvalp, basex[(*ev_var).basex_index], (*ev_var).y_val_all3[j,0])
s = MAX([0,j*24-11]) ;the MAX and MIN functions ensure that negative
e = MIN([365*24,j*24+12]) ;subscripts and subscripts greater than 365 are not accessed
FOR x = 0, 2 DO (*ev_var).yval_hours(x,s:e) = (*ev_var).y_val_all3[j,x]
(*ev_var).lalpha(s:e) = LONG(alpha * 10000.0)
(*ev_var).lbeta(s:e) = LONG(beta * 10000.0)
(*ev_var).lx_yval(s:e) = LONG((*ev_var).y_val_all3(j,0) * 10000.0)
(*ev_var).ly_yval(s:e) = LONG((*ev_var).y_val_all3(j,1) * 10000.0)
(*ev_var).lz_yval(s:e) = LONG((*ev_var).y_val_all3(j,2) * 10000.0)
index0 = where((*ev_var).data(0,s:e) eq 32767)
index1 = where((*ev_var).data(1,s:e) eq 32767)
index2 = where((*ev_var).data(2,s:e) eq 32767)
pre_z = ((*ev_var).data(2,s:e) * cos(alpha)) + ((*ev_var).data(1,s:e) * sin(alpha)) ;these statements assign the corrected,
(*ev_var).data(1,s:e) = ((*ev_var).data(1,s:e) * cos(alpha)) - ((*ev_var).data(2,s:e) * sin(alpha)) ;rotated yvalues to the data array,
(*ev_var).data(0,s:e) = ((*ev_var).data(0,s:e) * cos(beta)) + (pre_z * sin(beta)) ;replacing the actual data
(*ev_var).data(2,s:e) = (pre_z * cos(beta)) - ((*ev_var).data(0,s:e) * sin(beta))
IF (index0(0) ne -1) THEN (*ev_var).data(0,index0+s) = 32767
IF (index1(0) ne -1) THEN (*ev_var).data(1,index1+s) = 32767
IF (index2(0) ne -1) THEN (*ev_var).data(2,index2+s) = 32767
ENDFOR
WIDGET_CONTROL, (*ev_var).mouse_select_ID, SENSITIVE = 0
(*ev_var).mouse(*) = 2
ENDIF ELSE BEGIN
errmess = DIALOG_MESSAGE(['In order to proceed with rotation corrections, the x, y, AND z components must have baseline values.',$
'The year and station that you have selected do not have complete baselines for all three coordinates.'],$
/ERROR, DIALOG_PARENT = draw) ;this error message box appears if the user tries to replot without
(*ev_var).disp_err = errmess ;having created baselines for all three coordinate axis
ENDELSE
PLOT_IT, ev_var
end
'PRINT': begin
Months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']
Days_in_month = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
IF ((*ev_var).year MOD 4 eq 0) THEN Days_in_month(2) = 29
basex = [ 9450, 6150, 0, 6900, 4240, 6050, 4220, 3870, 0, 2850, 0, 0 ]
FOR month = 0, 11 DO BEGIN
s = total(Days_in_month(0:month)) * 24
e = total(Days_in_month(0:month+1)) * 24 - 1
;openw, x,"/magneto3/maccs/maccsidl/sarah13/" + $
openw, x,"/raid/2004/rotated/cor/" + $
STRUPCASE((*ev_var).station) + $
strmid((*ev_var).year,2,2) + $
Months(month) + '.cor', /get_lun
FOR hour = s, e DO BEGIN
writeu,x,long(basex[(*ev_var).basex_index]*10000.), $
long((*ev_var).yval_hours(0,hour)*10000.), $
long((*ev_var).yval_hours(1,hour)*10000.), $
long((*ev_var).yval_hours(2,hour)*10000.), $
long((*ev_var).lalpha(hour)), $
long((*ev_var).lbeta(hour))
; print,hour,long(basex[(*ev_var).basex_index]*10000.), $
; long((*ev_var).yval_hours(0,hour)*10000.), $
; long((*ev_var).yval_hours(1,hour)*10000.), $
; long((*ev_var).yval_hours(2,hour)*10000.), $
; long((*ev_var).lalpha(hour)), $
; long((*ev_var).lbeta(hour))
ENDFOR
close, x
free_lun, x
ENDFOR
PLOT_IT, ev_var
end
'SLIDER1': begin
(*ev_var).start_day = ev.value
PLOT_IT, ev_var
end
'SLIDER2': begin
(*ev_var).stop_day = ev.value
PLOT_IT, ev_var
end
'MOUSE_SELECT': begin
print, (*ev_var).mouse(*)
(*ev_var).mouse((*ev_var).component) = ev.value
print, (*ev_var).mouse(*)
IF ((*ev_var).mouse((*ev_var).component) eq 1) THEN BEGIN
errmessage = DIALOG_MESSAGE('You cannot draw'$
+'anymore lines' $
+'once you have started fixing them!'$
+'Are you sure you are done drawing lines?', TITLE = 'CAUTION!',$
DIALOG_PARENT = draw, /QUESTION)
(*ev_var).disp_err = errmessage
IF (errmessage eq 'No') THEN BEGIN
(*ev_var).mouse((*ev_var).component) = 0
WIDGET_CONTROL, (*ev_var).mouse_select_ID, SET_VALUE = 0
ENDIF
IF (errmessage eq 'Yes') THEN BEGIN
(*ev_var).mouse((*ev_var).component) = 1
PLOT_IT, ev_var
ENDIF
ENDIF
end
'STATION': begin
(*ev_var).basex_index = ev.index
abbrev = ['pg','cy','iq','cd','ig','ch','rb','pb','bl','gh','cb','re']
(*ev_var).station = abbrev(ev.index)
end
'YEAR': begin
years = ['1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004','2005','2006','2007']
(*ev_var).year = years(ev.index)
end
'COMPONENT': begin
(*ev_var).component = ev.value
IF ((*ev_var).y_val_all3(360,(*ev_var).component) ne 0) THEN BEGIN
PLOT_IT, ev_var
IF ((*ev_var).mouse((*ev_var).component) eq 0) THEN WIDGET_CONTROL, (*ev_var).mouse_select_ID, SENSITIVE = 13, SET_VALUE = 0
IF ((*ev_var).mouse((*ev_var).component) eq 1 OR (*ev_var).component eq 2) THEN WIDGET_CONTROL, (*ev_var).mouse_select_ID, SENSITIVE = 0
ENDIF ELSE BEGIN
(*ev_var).n = 0
FOR p = 0, 99 DO (*ev_var).x(p) = 0
FOR m = 0, 99 DO (*ev_var).y(m) = 0
FOR r = 0, 365 DO (*ev_var).slope(r) = 0
FOR l = 0, 365 DO (*ev_var).yintercept(l) = 0
PLOT_IT, ev_var
index = where((*ev_var).data((*ev_var).component,*) ne 32767)
(*ev_var).y(0) = (*ev_var).data((*ev_var).component,index(0))
(*ev_var).y_val_all3(0,(*ev_var).component) = (*ev_var).data((*ev_var).component,index(0))
WIDGET_CONTROL, (*ev_var).mouse_select_ID, SENSITIVE = 13, SET_VALUE = 0
(*ev_var).mouse((*ev_var).component) = 0
ENDELSE
end
'RANGE': begin
(*ev_var).range = ev.value
t = findgen(8760)
s = (*ev_var).start_day * 24
e = (*ev_var).stop_day * 24 - 1
index = where ((*ev_var).data((*ev_var).component,s:e) ne 32767)
(*ev_var).ave_val = MEDIAN((*ev_var).data((*ev_var).component,index+s))
PLOT, t(s:e)/24, FLAG((*ev_var).data((*ev_var).component,s:e)),$
MAX_VAL = 100000, YSTYLE = 1,$
YRANGE = [(*ev_var).ave_val-(*ev_var).range, (*ev_var).ave_val+(*ev_var).range],$
XRANGE = [(*ev_var).start_day, (*ev_var).stop_day], XSTYLE = 1
OPLOT, findgen(366), (*ev_var).y_val_all3(0:365,(*ev_var).component), PSYM = -5, COLOR = 25
end
ENDCASE
END
PRO wid_draw
LOADCT, 12
base = WIDGET_BASE(xoffset = 100)
draw = WIDGET_DRAW(base, XOFFSET = 0, YOFFSET = 130, XSIZE = 800, YSIZE = 500,$
UVALUE = 'DRAW', /BUTTON_EVENTS, /MOTION_EVENTS)
button = WIDGET_BUTTON(base, value = 'Done', uvalue = 'DONE',$
scr_xsize = 100, XOFFSET = 442, YOFFSET = 92)
file_button = WIDGET_BUTTON(base, value = 'Get file', uvalue = 'FILE',$
scr_xsize = 100, scr_ysize = 38, XOFFSET = 180, YOFFSET = 53)
replot_button = WIDGET_BUTTON(base, value = 'Replot', uvalue = 'REPLOT',$
scr_xsize = 100, XOFFSET = 442, YOFFSET = 15)
print_button = WIDGET_BUTTON(base, value = 'Creat File', uvalue = 'PRINT',$
scr_xsize = 100, XOFFSET = 442, YOFFSET = 53)
slider1 = WIDGET_SLIDER(base, value = 0, title = 'Start day',$
uvalue = 'SLIDER1', XOFFSET = 565, YOFFSET = 65, maximum = 365,$
scr_xsize = 100)
slider2 = WIDGET_SLIDER(base, value = 365, title = 'Stop day',$
uvalue = 'SLIDER2', XOFFSET = 685, YOFFSET = 65, maximum = 365,$
scr_xsize = 100)
mouse_select_ID = CW_BGROUP(base, ['draw lines', 'fix lines'], SET_VALUE = 0,$
XOFFSET = 45, YOFFSET = 93, UVALUE = 'MOUSE_SELECT', /ROW,$
/EXCLUSIVE)
station = WIDGET_DROPLIST(base, FRAME = 5, TITLE = 'MACCS Stations',$
UVALUE = 'STATION', VALUE = ['Pangnirtung', 'Clyde River', 'Iqaluit',$
'Cape Dorset', 'Igloolik', 'Coral Harbour', 'Repulse Bay', 'Pelly Bay',$
'Baker Lake', 'Gjoa Haven', 'Cambridge Bay', 'Resolute Bay', 'Nain'],$
scr_xsize = 100, XOFFSET = 15, YOFFSET = 10)
year_select = WIDGET_DROPLIST(base, FRAME = 5, TITLE = 'Select Year',$
UVALUE = 'YEAR', VALUE = ['1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004','2005','2006','2007'],$
scr_xsize = 100, XOFFSET = 15, YOFFSET = 50)
component_select = CW_BGROUP(base, ['x component', 'y component', 'z component'],$
SET_VALUE = 0, UVALUE = 'COMPONENT', XOFFSET = 295, YOFFSET = 15,$
/COLUMN, /EXCLUSIVE, /NO_RELEASE)
y_range = WIDGET_SLIDER(base, value = 0, TITLE = 'y range(+/-)', UVALUE='RANGE',$
maximum = 1000, XOFFSET = 625, YOFFSET = 10, scr_xsize = 100)
ev_var = ptr_new({n:0,x:fltarr(100),y:fltarr(100),$
slope: fltarr(366),$
yintercept: fltarr(366),$
start_day: 0.,$
stop_day: 365.,$
data: fltarr(3,24*366),$
station: 'Pangnirtung',$
basex_index: 0,$
year: '2001',$
component: 0.,$
mouse_select_ID: mouse_select_ID,$
mouse: intarr(3),$
hour: 0.,$
day: 0.,$
range: 0.,$
ave_val: 0.,$
disp_err: " ",$
motion: 0,$
lx_yval: fltarr(24*366),$
ly_yval: fltarr(24*366),$
lz_yval: fltarr(24*366),$
lalpha: fltarr(24*366),$
lbeta: fltarr(24*366),$
yval_hours: fltarr(3,24*366),$
y_val_all3: fltarr(366,3),$
m:0, x2:fltarr(1000), y2:fltarr(1000)})
WIDGET_CONTROL, base, SET_UVALUE = ev_var
WIDGET_CONTROL, /REALIZE, base
WIDGET_CONTROL, draw, GET_VALUE = index
WSET, index
XMANAGER, 'Wid_draw', base
ptr_free, ev_var
END
PRO PLOT_IT, ev_var
t = findgen(8760)
s = (*ev_var).start_day * 24
e = (*ev_var).stop_day * 24 - 1
IF (s GE e) THEN print, 'Invalid start and end day' ELSE BEGIN
index = where ((*ev_var).data((*ev_var).component,s:e) ne 32767)
IF (index(0) ne -1) THEN BEGIN
IF ((*ev_var).range eq 0) THEN BEGIN
PLOT, t(s:e)/24, FLAG((*ev_var).data((*ev_var).component,s:e)),$
MAX_VAL = 100000, /YSTYLE,$
XRANGE = [(*ev_var).start_day, (*ev_var).stop_day], XSTYLE = 1
OPLOT, findgen(366), (*ev_var).y_val_all3(0:365,(*ev_var).component), PSYM = -5, COLOR = 25
ENDIF ELSE BEGIN
(*ev_var).ave_val = MEDIAN((*ev_var).data((*ev_var).component,index+s))
PLOT, t(s:e)/24, FLAG((*ev_var).data((*ev_var).component, s:e)),$
MAX_VAL = 100000, YSTYLE = 1,$
XRANGE = [(*ev_var).start_day, (*ev_var).stop_day], XSTYLE = 1,$
YRANGE = [(*ev_var).ave_val-(*ev_var).range, (*ev_var).ave_val+(*ev_var).range]
OPLOT, findgen(366), (*ev_var).y_val_all3(0:365,(*ev_var).component), PSYM = -5, COLOR = 25
ENDELSE
ENDIF ELSE BEGIN
print, 'No data in range: ', 'Day ', BYTE((*ev_var).start_day),$
' to Day ', BYTE((*ev_var).stop_day)
ENDELSE
ENDELSE
IF ((*ev_var).mouse((*ev_var).component) eq 1) THEN WIDGET_CONTROL, (*ev_var).mouse_select_ID, SENSITIVE = 0
END
PRO GET_THE_FILE, ev_var
(*ev_var).n = 0
(*ev_var).x(*) = 0
(*ev_var).y(*) = 0
(*ev_var).slope(*) = 0
(*ev_var).yintercept(*) = 0
(*ev_var).y_val_all3(*,*) = 0
(*ev_var).data(*,*) = 0
(*ev_var).lx_yval(*) = 0
(*ev_var).ly_yval(*) = 0
(*ev_var).lz_yval(*) = 0
(*ev_var).lalpha(*) = 0
(*ev_var).lbeta(*) = 0
IF ((*ev_var).station eq 'Pangnirtung') THEN (*ev_var).station = 'pg'
hour_read, code = STRUPCASE((*ev_var).station), year = (*ev_var).year, temp_data
(*ev_var).data=temp_data
t = findgen(8760)
s = (*ev_var).start_day * 24
e = (*ev_var).stop_day * 24 - 1
i = where ((*ev_var).data((*ev_var).component,s:e) ne 32767)
IF (i(0) eq -1) THEN BEGIN
errmessage = DIALOG_MESSAGE(['There is no data for this station in the year you selected.',$
'Please select a different file.'], DIALOG_PARENT = DRAW, /ERROR)
(*ev_var).disp_err = errmessage
ENDIF ELSE BEGIN
(*ev_var).ave_val = MEDIAN((*ev_var).data((*ev_var).component,i+s))
IF ((*ev_var).range eq 0) THEN BEGIN
PLOT, t((*ev_var).start_day * 24:(*ev_var).stop_day * 24 - 1)/24,$
FLAG((*ev_var).data((*ev_var).component,*)), MAX_VAL=100000, /YSTYLE,$
XRANGE = [(*ev_var).start_day, (*ev_var).stop_day], XSTYLE = 1
PLOTS, t(0)/365., FLAG((*ev_var).data((*ev_var).component,0))
ENDIF ELSE BEGIN
PLOT, t((*ev_var).start_day * 24:(*ev_var).stop_day * 24 - 1)/24,$
FLAG((*ev_var).data((*ev_var).component,*)), MAX_VAL=100000, YSTYLE = 1,$
XRANGE = [(*ev_var).start_day, (*ev_var).stop_day], XSTYLE = 1,$
YRANGE = [(*ev_var).ave_val-(*ev_var).range, (*ev_var).ave_val+(*ev_var).range]
PLOTS, t(0)/365., FLAG((*ev_var).data((*ev_var).component,0))
ENDELSE
ENDELSE
index = where((*ev_var).data((*ev_var).component,*) ne 32767)
(*ev_var).y(0) = (*ev_var).data((*ev_var).component,index(0))
(*ev_var).y_val_all3(0,(*ev_var).component) = (*ev_var).data((*ev_var).component,index(0))
WIDGET_CONTROL, (*ev_var).mouse_select_ID, SENSITIVE = 13, SET_VALUE = 0
(*ev_var).mouse = 0
END

