C+ C NAME: C set_flatfields C PURPOSE: C To set the flatfields - note the flatfield values are normally read in from a table C This particular version allows only one camera to be analyzed at a time C Entire-orbit SMEI analysis will likely require combining data from three cameras C CATEGORY: C Data processing C CALLING SEQUENCE: C call set_flatfields(ic,framessff,framelsff,framelsffu) C INPUTS: C ic integer Camera 0,1,2,3 or 4 C OUTPUTS: C framessff (1280,600) real small scale flat field adjustments that are not included on spacecraft C framelsff (1280,600) real large scale flat field - the best available from ground-based analyses C framelsffu(1280,600) real differentially updated large scale flat field: modified during operation C CALLS: C none C PROCEDURE: C Flatfields are initialized to unity. ***Here, they are all put into RAL format.*** C The flatfield(s) appropriate for the selected camera are read from grid data file(s) C The standard coordinate frame here is the 1280 x 600 RAL. Flight flatfields are padded out to this. C For historical reasons the UCSD large scale flatfield grid to be read is 320 x 130 (4x4 binned), C while the flight camera flatfields are 1280 x 301. C The UCSD large scale flatfield skips the 1st 13 rows, flight lsff's skip the 1st 49. C Small scale flatfields are "add one and multiply", while large scale flatfields are "divide by". C C Cameras 1 --> 4 lsff's each have some "hot pixel" blanks. Roughly one to two dozen entries C (i.e. blocks of sixteen) within each camera's table are zeroed. Some of these are possibly C remedied by the substitution values for onboard ssff's sent Mark Cooke on 6-13-02, but C flight data should be examined before altering the table's lsff values. The best bet now C is to fill these entries with a nearest-neighbor average, but we'll need C to pay special attention since neighbor's average here is just a guess. C C Note also that these flatfields only occupy roughly the middle 2/3 of the actual telemetered ROI. C Outside of this band, using 1.00 flatfield values may be best,although extrapolating c a columns average out to the edge may have some merit. Inflight data will dictate change... C c The RAL format is offset relative to flight data, being shifted by +1 pixel c along the rows, and by skipping the first {65, 59, 61, 51} rows for cameras {1,2,3,4} c respectively. Flight data have only 256 rows. C C MODIFICATION HISTORY: C Dec, 2002 B. Jackson (UCSD)l, Jan, 2003 A. Buffington (UCSD/CASS) C- subroutine set_flatfields(ic,framessff,framelsff,framelsffu) c real*4 framessff(1280,600), & framelsff(1280,600), & framelsffu(1280,600) real*4 temp(1280,301) integer*4 ic,i,j,ii,jj,icount,isum character head(20,5) C C Flat field parameters all initialized to unity (can be reset at a later time) C do j=1,600 do i=1,1280 framessff(i,j)=1.0 framelsff(i,j)=1.0 framelsffu(i,j)=1.0 end do end do C C Camera 0: Read both ssff and lsff. the latter must be padded out C if(ic.eq.0) then open(10,file='ucsdssff.grd',form='formatted',readonly) read(10,1)head 1 format(20a1) read(10,2)((framessff(i,j),i=1,1280),j=1,600) 2 format(20f10.5) close(10) c c Here add one to the ssff: note in "ssff.f" this divides the uncorrected value c do j=1,600 do i=1,1280 framessff(i,j)=1.0+framessff(i,j) enddo enddo c open(11,file='ucsdflt2.grd',form='formatted',readonly) read(11,1)head read(11,2)((temp(ii,jj),ii=1,320),jj=1,130) close(11) do j=14,534 jj=1+(j-14)/4 do i=1,1280 ii=1+(i-2)/4 framelsff(i,j)=temp(ii,jj) enddo enddo end if C C Camera 1 C if(ic.eq.1) then open(10,file='newfltgrd1.grd',form='formatted',readonly) read(10,1)head read(10,2)((temp(i,j),i=1,1280),j=1,301) close(10) do j=50,350 do i=1,1280 framelsff(i,j)=temp(i,j-49) enddo enddo end if C C Camera 2 C if(ic.eq.2) then open(10,file='newfltgrd2.grd',form='formatted',readonly) read(10,1)head read(10,2)((temp(i,j),i=1,1280),j=1,301) close(10) do j=50,350 do i=1,1280 framelsff(i,j)=temp(i,j-49) enddo enddo end if C C Camera 3 C if(ic.eq.3) then open(10,file='newfltgrd3.grd',form='formatted',readonly) read(10,1)head read(10,2)((temp(i,j),i=1,1280),j=1,301) close(10) do j=50,350 do i=1,1280 framelsff(i,j)=temp(i,j-49) enddo enddo end if C C Camera 4 C if(ic.eq.4) then open(10,file='newfltgrd4.grd',form='formatted',readonly) read(10,1)head read(10,2)((temp(i,j),i=1,1280),j=1,301) close(10) do j=50,350 do i=1,1280 framelsff(i,j)=temp(i,j-49) enddo enddo end if C C Here replace enclosed zeroes with a "neighbors average" (needs revisiting w/flight data). C icount=0 do j=5,595 do i=5,1275 if(framelsff(i,j).eq.0.)then isum=0 if(framelsff(i-4,j).ne.0.)isum=isum+1 if(framelsff(i+4,j).ne.0.)isum=isum+1 if(framelsff(i,j-4).ne.0.)isum=isum+1 if(framelsff(i,j+4).ne.0.)isum=isum+1 if(isum.eq.4)then icount=icount+1 framelsff(i,j)=(framelsff(i-4,j)+framelsff(i+4,j)+framelsff(i,j-4)+framelsff(i,j+4))/4. endif endif enddo enddo if(icount.gt.0)print *,icount/16,' Hot pixels replaced with neighbors average' C return end