FUNCTION linearza,headbytes,image,halfwidth=halfwidth COMMON sampling,oyear,omonth,oday,obin,col0,row0,col1,row1 ; Show the documentation? IF N_PARAMS() LT 2 THEN BEGIN doc_library,'linearza' RETURN,-1 ENDIF ; Determine the scale of the output linearized image. IF N_ELEMENTS(halfwidth) GT 0 THEN npix=halfwidth ELSE npix=165 ; Get the dope on the image supplied. h=gethd(headbytes) year=h.misc.dt.year month=h.misc.dt.month day=h.misc.dt.day cam=FIX(h.misc.cam) bin=MAX([h.exp.sbin,h.exp.pbin]) ; Ensure these variables are not UNDEFINED IF N_ELEMENTS(oyear) EQ 0 THEN oyear=0 IF N_ELEMENTS(omonth) EQ 0 THEN omonth=0 IF N_ELEMENTS(oday) EQ 0 THEN oday=0 IF N_ELEMENTS(obin) EQ 0 THEN obin=0 ; Do we need to build the sampling arrays? newday=((year NE oyear) OR (month NE omonth) OR (day NE oday) $ OR (bin NE obin)) IF cam EQ 0 $ THEN newcam=((N_ELEMENTS(col0) EQ 0) OR (N_ELEMENTS(row0) EQ 0)) $ ELSE newcam=((N_ELEMENTS(col1) EQ 0) OR (N_ELEMENTS(row1) EQ 0)) IF newday OR newcam THEN BEGIN ; Get the required transformation parameters rdmnparm,year,month,day,cam,ccol,crow,stretch,warp,camaz ; Build the needed arrays za=!RADEG*(SHIFT(dist(2*npix+1),npix,npix)/stretch)/warp xx=REBIN(INDGEN(2*npix+1)-npix,2*npix+1,2*npix+1,/SAMPLE) yy=TRANSPOSE(xx) az=ATAN(xx,yy)*!RADEG ; Generate the sampling arrays to go into 'col' and 'row' az2cr,year,month,day,cam,2,az,za,col,row,/degrees,bin=bin ; Reject pixels pointing outside the image crej=WHERE((col LE 0) OR (255 LE col),ncrej) rrej=WHERE((row LE 0) OR (255 LE row),nrrej) IF ncrej GT 0 THEN BEGIN col(crej)=0 row(crej)=0 ENDIF IF nrrej GT 0 THEN BEGIN col(rrej)=0 row(rrej)=0 ENDIF ; Update image parameters. oyear=year omonth=month oday=day obin=bin ENDIF ; Return supplied image, sampled onto linear zenith angle space. image(0,0)=0 RETURN,image(col,row) END