function tickslog, range, MIN=mind, MAX=maxd, NMIN=nmin
if (n_elements(nmin) eq 0) then nmin = 3
if (n_elements(mind) gt 0) then begin
mind = mind[0]
if (n_elements(maxd) eq 0) then maxd = mind*1000.
endif
if (n_elements(maxd) gt 0) then begin
maxd = maxd[0]
if (n_elements(mind) eq 0) then mind = maxd*0.001
endif
if (n_elements(mind) eq 0) then begin
mind = 0.1
maxd = 100.
endif
if (n_elements(range) eq 0) then range = [ mind,maxd ]
if (n_elements(range) eq 1) then range = [ range*0.001, range ]
thisrange = double(range) > 1.D-100
thisrange = thisrange(sort(thisrange))
if (thisrange[0] lt 1.D-36) then thisrange[0] = thisrange[1]/1000.
lrange = alog10(thisrange)
mode = 0
if ((lrange[1]-lrange[0]) lt nmin) then mode = 1
if (thisrange[0] lt 1.D-15 OR thisrange[1] gt 5.D16) then mode = 0
if (mode) then begin
dl = alog10(1D + 1d-7)
lrange[0] -= dl
lrange[1] += dl
deca = floor(min(double(lrange)))
lrange -= deca
labels = [ 1.D+00, 2.D+00, 5.D+00] # [1d, 10d, 100d, 1000d, 10000d]
llabels = alog10(labels)
ind = where(llabels ge lrange[0] AND llabels le lrange[1], cnt)
if cnt lt nmin then begin
lr = lrange +alog10(5d)
labels /= 5d
ind = where(llabels ge lr[0] AND llabels le lr[1], cnt)
endif
if cnt lt nmin then begin
labels = [1D, 1.5D, 2D, 3D, 5D, 7D, 10D, 14D, 20D, 30D, 40D]
llabels = alog10(labels)
ind = where(llabels ge lrange[0] AND llabels le lrange[1], cnt)
endif
if cnt lt nmin then begin
labels = [ 1D, 1.2D, 1.5D, 2D, 3D, 4D, 5D, 6D, 7D, 8D, 10D, 12D, 15D, 20D, 25D, 30D, 40D]
llabels = alog10(labels)
ind = where(llabels ge lrange[0] AND llabels le lrange[1], cnt)
endif
if cnt lt nmin and nmin gt 5 then begin
labels = [ 1D, 1.1D, 1.2D, 1.3D, 1.6D, 2D, 2.5D, 3D, 3.5D, 4D, 5D, 6D, $
7D, 8D, 9D, 10D, 11D, 13D, 15D, 18D, 21D, 25D, 30D, 35D, 40D]
llabels = alog10(labels)
ind = where(llabels ge lrange[0] AND llabels le lrange[1], cnt)
endif
factor = 1d
while cnt lt nmin do begin
if cnt lt nmin then begin
labels = 1D + dindgen(20*factor) / factor
llabels = alog10(labels)
ind = where(llabels ge lrange[0] AND llabels le lrange[1], cnt)
endif
if cnt lt nmin then begin
labels = 1D + dindgen(20*factor)/2d / factor
llabels = alog10(labels)
ind = where(llabels ge lrange[0] AND llabels le lrange[1], cnt)
endif
if cnt lt nmin then begin
labels = 1D + dindgen(50*factor) / 5d / factor
llabels = alog10(labels)
ind = where(llabels ge lrange[0] AND llabels le lrange[1], cnt)
endif
factor *= 10
if factor gt 1d25 then break
endwhile
if (cnt eq 0) then return,range
if (range[0] gt range[1]) then $
return,reverse(labels[min(ind):max(ind)]) *10d^deca $
else $
return,labels[min(ind):max(ind)] *10d^deca
endif else begin
if (lrange[0] lt 0.) then lrange[0] = lrange[0] - 1.0D-6
if (lrange[1] lt 0.) then lrange[1] = lrange[1] - 1.0D-6
maxtick = max([2*nmin, 8])
lfactor = 1d
while lrange[1]-lrange[0] gt maxtick do begin
lrange *= lfactor/(lfactor+1)
lfactor ++
endwhile
drange = fix(lrange)
if (lrange[1] lt 0.) then drange[1] = drange[1] - 1
exponent = (drange[0]+indgen(drange[1]-drange[0]+1)) * lfactor
if (range[0] gt range[1]) then $
return,reverse(10.D0^exponent) $
else $
return,10.D0^exponent
endelse
end
Part of