pro ogrid_log, xtick=xt, ytick=yt, xpminor = xm, ypminor = ym, xdot= xd, $
          ydot = yd
; NAME:
;    OGRID_LOG
;
; PURPOSE:
;    To draw the grid over the plot on log-log plot 
;
; CALLING SEQUENCE:
;    ogrid_log,/xtick, /ytick, /xpminor, /ypminor, /xdot, /ydot
;    use any of keyword parameter(or none parameter)
;
; INPUT:
;    Input keywords xtick, ytick, xpminor, ypminor, xdot and ydot
;    xtick  - if xtick keyword set to 1 then draw X axis tick lines
;    ytick  - if ytick keyword set to 1 then draw Y axis tick lines
;    xpminor - if xpminor keyword set to 1 then draw minor tick mark(X)
;    ypminor - if ypminor keyword set to 1 then draw minor tick mark(Y)
;    xdot   - if xdot keyword set to 1 then draw "dot" line on X axis
;    ydot   - if ydot keyword set to 1 then draw "dot" line on Y axis
;
;    default value is set both xtick, ytick = 1(draw both X and Y axis)
;    draw major on X and Y axis, and the line style is "dash"
;
; OUTPUT:
;    plot the grid line on existing plot
;
; COMMON BLOCK:
;    None
;
; RESTRICTIONS:
;    over plot on log-log plot only
;
; PROCEDURE:
;    Find the min. and max. value of X, Y axis from !X.crange and
;    !Y.crange.
;    get keyword value from input parameter, then set all the flag.
;    Determine this grid line is for X axis or Y axis, plot major tick
;    mark or minor tick mark(for both X and Y axis). Also determine
;    use dot line or dash line.
;    Determine the tick mark position, and draw line between each 
;    tickmark pare one by one.
;    default value(no any input parameter) is draw both X and Y axis on
;    major tick mark only and using "dash" linestyle.
;
; SUBROUTINE CALLED:
;    oplot
;
; MODIFICATION HISTORY:
;    Written May, 1991
;
;
;  determin xmin, xmax, ymin, ymax from !X, !Y
;
xmin = 10. ^ !X.crange(0)
xmax = 10. ^ !X.crange(1) 
ymin = 10. ^ !Y.crange(0)
ymax = 10. ^ !Y.crange(1) 
;
;  check the keyword parameter
;  set the proper keyword value
;
;
;  default value of tickmark is to mark on both x and y axis
;
xflag = KEYWORD_SET(xt) 
yflag = KEYWORD_SET(yt)
if((xflag eq 0) and (yflag eq 0)) then begin
   xflag = 1
   yflag = 1
endif              
;  defult value of linestyle is dash
xlinestyle_v = 2     &   ylinestyle_v = 2   ; default linestyle is dash
if KEYWORD_SET(xd) then xlinestyle_v = 1  ; dot on X axis
if KEYWORD_SET(yd) then ylinestyle_v = 1  ; dot on Y axis
;
if( xflag eq 1) then begin
   cycle = alog10(xmax) - alog10(xmin)
   if(KEYWORD_SET(xm)) then begin   ; tick minor tickmark
      npt = 9 * cycle 
      x = indgen(10)
      xdata = xmin * x(1:9)
      for i = 1, cycle - 1 do begin
        xdata= [xdata, (10. ^ i) * xmin*x(1:9)]
      endfor
   endif else begin                 ; tick major tickmark(default)
      npt = cycle 
      xdata = fltarr(npt)
      for i = 0, npt - 1 do begin
         xdata(i) = xmin * (10. ^ i )
      endfor
   endelse
;
   datax=fltarr(2)
   datay=fltarr(2)
   datay(0) = ymin
   datay(1) = ymax
   for i = 1, npt-1 do begin
     datax(0) = xdata(i)
     datax(1) = datax(0)
     oplot,datax,datay, linestyle=xlinestyle_v
   endfor
endif
; Y_axis grid
;
if( yflag eq 1) then begin
   cycle = alog10(ymax) - alog10(ymin)
   if(KEYWORD_SET(ym)) then begin   ; tick minor tickmark
      npt = 9 * cycle 
      y = indgen(10)
      ydata = ymin * y(1:9)
      for i = 1, cycle - 1 do begin
        ydata= [ydata, (10. ^ i) * ymin*y(1:9)]
      endfor
   endif else begin                ; tick major tickmark(default)
      npt = cycle 
      ydata = fltarr(npt)
      for i = 0, npt - 1 do begin
         ydata(i) = ymin * (10. ^ i )
      endfor
   endelse
;
   datax=fltarr(2)
   datay=fltarr(2)
   datax(0) = xmin
   datax(1) = xmax
   for i = 1, npt-1 do begin
     datay(0) = ydata(i)
     datay(1) = datay(0)
     oplot,datax,datay, linestyle=ylinestyle_v
   endfor
endif
return
end
