pro jd2mdays, jd1, jd2, mjds, mjde, approx_maj=amaj, $
major_v=majv, minor_v=minv, format=frm, help=hlp
if (n_params(0) lt 2) or keyword_set(hlp) then begin
print,' Convert a range of Julian Days to month start and end JDs.'
print,' jd2mdays, jd1, jd2, mjds, mjde'
print,' jd1, jd2 = first and last Julian day of a time range. in'
print,' mjds = array of Julian days for the first of each out'
print,' month covered by the range.'
print,' mjde = array of Julian days for the end of each out'
print,' month covered by the range.'
print,' Keywords:'
print,' APPROX_MAJOR=amaj Approximate number of days between'
print,' major tick marks. Used to derive actual # days.'
print,' MAJOR_V=majv Array of labeled tick mark values in'
print,' Julian Days.'
print,' MINOR_V=majv Array of minor tick mark values in'
print,' Julian Days.'
print,' FORMAT=frm Returned suggested format for time labels.'
print,' Notes: intended for time axes involving month labels.'
print,' Ex: if jd1 is for 29-Jan-1992 and jd2 is for 13-Jun-1993'
print,' then mjds and mjde each have 18 elements giving the'
print,' Julian day numbers for the start and end of each of the'
print,' 18 months from Jan 1992 to Jun 1993 inclusive.'
return
endif
jd2ymd, jd1, y, m, d
mjds = [ymd2jd(y,m,1)]
mjde = [ymd2jd(y,m,monthdays(y,m))]
loop: m = m + 1
if m gt 12 then begin
y = y + 1
m = 1
endif
jd = ymd2jd(y,m,1)
if jd gt jd2 then goto, next
mjds = [mjds,jd]
mjde = [mjde,ymd2jd(y,m,monthdays(y,m))]
goto, loop
next: if n_elements(amaj) eq 0 then return
if amaj lt 1. then amaj = 1.
dx = 720
dx2 = 360
frm = 'y$'
if amaj lt 1800 then begin dx=360 & dx2=180 & frm = 'n$ y$' & end
if amaj lt 255 then begin dx=180 & dx2=90 & frm = 'n$ y$' & end
if amaj lt 147 then begin dx=120 & dx2=60 & frm = 'n$ y$' & end
if amaj lt 104 then begin dx=90 & dx2=30 & frm = 'n$ y$' & end
if amaj lt 73.48 then begin dx=60 & dx2=30 & frm = 'n$ y$' & end
if amaj lt 42.43 then begin dx=30 & dx2=10 & frm = 'd$ n$ y$' & end
if amaj lt 21.21 then begin dx=15 & dx2=5 & frm = 'd$ n$ y$' & end
if amaj lt 12.25 then begin dx=10 & dx2=5 & frm = 'd$ n$ y$' & end
if amaj lt 7.07 then begin dx=5 & dx2=1 & frm = 'd$ n$ y$' & end
if amaj lt 3.16 then begin dx=2 & dx2=1 & frm = 'd$ n$' & end
if amaj lt 1.41 then begin dx=1 & dx2=1 & frm = 'd$ n$' & end
if dx le 30 then begin
majv = [0L]
minv = [0L]
for i = 0, n_elements(mjds)-1 do begin
lo = mjds[i]-1+dx
hi=mjde[i]-(dx<2)
if dx le 2 then hi=mjde[i]
if lo lt hi then begin
majv = [majv, mjds[i],makei(lo,hi,dx)]
endif else begin
majv = [majv, mjds[i]]
endelse
lo = mjds[i]-1+dx2
hi = mjde[i]
if lo lt hi then begin
minv = [minv, mjds[i],makei(lo,hi,dx2)]
endif else begin
minv = [minv, mjds[i]]
endelse
endfor
endif else begin
minv = mjds
if dx eq 60 then begin
majv = jdselect(mjds,['jan','mar','may','jul','sep','nov'],/mon)
endif
if dx eq 90 then begin
majv = jdselect(mjds,['jan','apr','jul','oct'],/mon)
endif
if dx eq 180 then begin
majv = jdselect(mjds,['jan','jul'],/mon)
minv = jdselect(mjds,['apr','oct'],/mon)
endif
if dx eq 360 then begin
majv = jdselect(mjds,['jan'],/mon)
minv = jdselect(mjds,['apr','jul','oct'],/mon)
endif
if dx eq 720 then begin
majv = jdselect(mjds,['jan'],/mon)
minv = jdselect(mjds,['jul'],/mon)
endif
endelse
w = where((jd1 le majv) and (jd2 ge majv), c)
if c gt 0 then majv = majv[w]
w = where((jd1 le minv) and (jd2 ge minv), c)
if c gt 0 then minv = minv[w]
end