pro read_summermelt_date

;
; This IDL routine reads in the summer-melt-date data files. There are two  
; files (1998 and 1999) each containing the day-of-year of melt onset. There 
; are two grids used in each data file: an interior 10km x 10km grid and a 
; coastal 25km x 25km grid. A data value of 0 means no melt-onset date
; is available for that grid. The data parameters read in are:
;
;   x0    : The minimum x value of the grid (SSMI in kilometers)
;   y0    : The minimum y value of the grid (SSMI in kilometers)
;   x10   : The interior grid spacing in the x direction (km)
;   y10   : The interior grid spacing in the y direction (km)
;   x25   : The coastal grid spacing in the x direction (km)
;   y25   : The coastal grid spacing in the y direction (km)
;   ng10x : The interior grid array size in the x direction
;   ng10y : The interior grid array size in the y direction
;   ng25x : The coastal grid array size in the x direction
;   ng25y : The coastal grid array size in the y direction
;   dategrid10_1998 : The interior grid of melt-onset dates for the year 1998
;   dategrid25_1998 : The interior grid of melt-onset dates for the year 1998
;   dategrid10_1999 : The interior grid of melt-onset dates for the year 1999
;   dategrid25_1999 : The interior grid of melt-onset dates for the year 1999
;

;
; Declare the variable types to be read
;
x0 = 0.
y0 = 0.
x10 = 0.
y10 = 0.
x25 = 0.
y25 = 0.
ng10x = 0
ng10y = 0
ng25x = 0
ng25y = 0

;
; Read in the 1998 summer-melt-date data array
;

openr,unitr,'summermelt_date.1998',/get_lun
readu,unitr,x0,y0,x10,y10,ng10x,ng10y
dategrid10_1998 = fltarr(ng10x,ng10y)
readu,unitr,dategrid10_1998
readu,unitr,x0,y0,x25,y25,ng25x,ng25y
dategrid25_1998 = fltarr(ng25x,ng25y)
readu,unitr,dategrid25_1998
free_lun,unitr

;
; Read in the 1999 summer-melt-date data array
;
openr,unitr,'summermelt_date.1999',/get_lun
readu,unitr,x0,y0,x10,y10,ng10x,ng10y
dategrid10_1999 = fltarr(ng10x,ng10y)
readu,unitr,dategrid10_1999
readu,unitr,x0,y0,x25,y25,ng25x,ng25y
dategrid25_1999 = fltarr(ng25x,ng25y)
readu,unitr,dategrid25_1999
free_lun,unitr

;
; The arrays (xgrid10,ygrid10,xgrid25,ygrid25) containing the centered 
; locations of the grid cells are calculated as follows:
;
xgrid10 = fltarr(ng10x,ng10y)
xline10 = x0 + (findgen(ng10x) + 0.5)*x10
for j=0,ng10y-1 do xgrid10(*,j) = xline10

ygrid10 = fltarr(ng10x,ng10y)
yline10 = y0 + (findgen(ng10y) + 0.5)*y10
for i=0,ng10x-1 do ygrid10(i,*) = yline10

xgrid25 = fltarr(ng25x,ng25y)
xline25 = x0 + (findgen(ng25x) + 0.5)*x25
for j=0,ng25y-1 do xgrid25(*,j) = xline25

ygrid25 = fltarr(ng25x,ng25y)
yline25 = y0 + (findgen(ng25y) + 0.5)*y25
for i=0,ng25x-1 do ygrid25(i,*) = yline25

;
; A simple grayscale plot of the 1998 data is as follows:
;
expand = 2
xplotsz = ng10x*expand
yplotsz = ng10y*expand
window,0,xs=xplotsz,ys=yplotsz,retain=2
plot,[0,0],[0,0],/nodata,xstyle=5,ystyle=5,xrange=[x0,x0+ng10x*x10], $
     yrange=[y0,y0+ng10y*y10],xmargin=[0,0],ymargin=[0,0],color=0,back=255

r = where(dategrid10_1998 gt 0.,count)
for i=0,count-1 do begin
  ri = r(i)
  color = (dategrid10_1998(ri) - 130.)*5
  polyfill,xgrid10(ri)+x10*0.5*[-1,-1,1,1],ygrid10(ri)+y10*0.5*[-1,1,1,-1], $
           color=color,/data
endfor
r = where(dategrid25_1998 gt 0.,count)
for i=0,count-1 do begin
  ri = r(i)
  color = (dategrid25_1998(ri) - 130.)*5
  polyfill,xgrid25(ri)+x25*0.5*[-1,-1,1,1],ygrid25(ri)+y25*0.5*[-1,1,1,-1], $
           color=color,/data
endfor

end