; Dec 14, 1994  Alice Lecinski  with help from Joan Burkepile.
;
; This idl procedure can be used to read in and contour
; ANY  MK____.[EW]ib file.
;

psit='y'
dirpath=' '
   roti=' '
   mlmb=' '
  myhei=' '
height='1.74'

print,'Enter in the directory path to the MK????.??ib file'
print,'eg. mk3_synoptic/heightL/ '
    read,dirpath
print,'Enter the rotation, eg.   1845 '
    read,roti
print,'Enter the limb,     eg.   E '
    read,mlmb
print,'Enter the height,   eg.   L  or  M '
    read,myhei  & if(myhei eq 'L')then height='1.36'

if (psit eq 'y') then begin ;{
    !P.MULTI = [ 0, 1 , 1 ]
     
     psfilenm=roti+myhei+mlmb+'.ps'
     set_plot,'ps'
     device,/landscape,/inches,xsize=10.0,ysize=3.75,$
	 xoffset=0.5,yoffset=10.5,filename=psfilenm

endif else begin;}{
    window,0,xsize=360*3+50,ysize=181*3+50
endelse;}

    ahdr=fltarr(8)
    ckey=bytarr(30)
    cpad=bytarr(2)
    histmap=fltarr(30,37)

    bigmap=fltarr(390,181)



;;; /puu/ftpmk3/map/history/mk3_synoptic/heightL/MK1841.LWib

filenm=dirpath+'MK'+roti+'.'+myhei+mlmb+'ib'

    close,1
    openr,1,filenm     & readu,1,ahdr  & readu,1,ckey
					 readu,1,cpad
					 readu,1,histmap
    close,1

    rot = fix(ahdr(0))
    ahdr(1) = ahdr(1) + 1900.




    doy = 0  
             
    for i=0,389,13 do begin ;{   One day is ~13 degrees...

        lat = 0
	spa=12
            bigmap(i:i+spa,0:2) = histmap(doy,lat)
               
        lat = lat + 1
        for j=3,181-4,5 do begin ;{
            bigmap(i:i+spa,j:j+4) = histmap(doy,lat)
            lat = lat + 1
        endfor ;}
 
            bigmap(i:i+spa,178:180) = histmap(doy,lat)

	if (ckey(doy) eq 48 and histmap(doy , 19) le -1000.) then ckey(doy)=0

        doy = doy +1                                  
    endfor ;}

    doy=doy-1
    bigmap(351:359,178:180) = histmap(doy,lat)
 
    if(ahdr(4) eq 2.) then bigmap=rotate(bigmap,7) ; Flip the west limb map.

bigmap=smooth(bigmap,5)


lvl2= [ 1000., 1200., 1400., 1600.]  & lvl2=lvl2/100.
clr2= [120,140,180,220]
lvl= [200.,     400.,  600.,  800.,  1000., 1200., 1400., 1600.]
lvl=lvl/100.
mln= [1,      0,   2,   0,   2,   0,   0,    0]
mln= [1,      0,   0,   0,   0,   0,   0,    0]
thk= [1,      1,   2,   3,   4,  2,  2,   3]

myyticks=6    &   myytickv=findgen(7)*30

fedoy=ahdr(3)  & edoy = fix(fedoy)
fbdoy=ahdr(2)  & bdoy = fix(fbdoy)
    rot='Rotation '+string(fix(ahdr(0)))
    limb='      East Limb'  & if (ahdr(4) eq 2.) then limb='      West Limb'
    bdate='Bdoy '+string(fbdoy)       & bdate=strcompress(bdate)
    edate='Edoy '+string(fedoy)       & edate=strcompress(edate)
    year='Year '+string(fix(ahdr(1))) & year=strcompress(year)
    byr=fix(ahdr(1))
    leap= long((byr mod 4 eq 0) and (byr mod 100 ne 0) or $
				      (byr mod 400 eq 0))

fedoy = fedoy + (365+leap)*(edoy lt bdoy)*1.0
edoy  =  edoy + (365+leap)*(edoy lt bdoy)

numday = edoy-bdoy
myxticks=numday+1
myxtickv=fltarr(numday+2)   
    deltax = 13.
    offset = 0.
myxname=replicate('      X ',numday+2)
for ii=0,myxticks do begin ;{
    if(ckey(ii+0) eq  48) then begin ;{
	myxname(ii) = string(format='(i8)',edoy-ii)
    endif;}
    myxtickv(ii) = offset + ii*deltax
endfor ;}
myyname=replicate(' ',19)
myyname(0)='-90'
myyname(6)=' 90'
myyname(3)='  0'

contour,bigmap,/follow,levels=lvl,$
    c_linestyle=mln,$
    c_thick=thk,$
    xstyle=1,ystyle=1,zstyle=1,charsize=1.0,$
    xcharsize=0.6,$
    xtitle='DOY', ytitle='LATITUDE',$
    title=rot+limb+'       '+year+'      '+bdate+'      '+edate ,$
    subtitle=height, $
    xtickname=myxname,$
    ytickname=myyname,$
    xticks=myxticks,xtickv=myxtickv, $
    yticks=myyticks,ytickv=myytickv, $
    ticklen= -0.015 , xmargin=[10,10] , ymargin=[4,4]

contour,bigmap,/follow,levels=lvl2,c_color=clr2,overplot=1,fill=1

    espot=(edoy*1.0-fedoy)*13. +13.
    oplot,[espot,espot],[0,180],thick=3
	for ii=0,5 do begin ;{
	    espot = espot-0.2
	    oplot,[espot,espot],[0,180],thick=3
	endfor;}
    bspot=(edoy*1.0-fbdoy)*13. +13.
    oplot,[bspot,bspot],[0,180],thick=3
	for ii=0,5 do begin ;{
	    bspot=bspot+0.2
	    oplot,[bspot,bspot],[0,180],thick=3
	endfor;}

if (psit eq 'y') then begin ;{

    device,/close
    set_plot,'x'

endif ;}

end
