OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
main_interpnav.f
Go to the documentation of this file.
1  program interp_nav
2 c
3 c
4 c Purpose: This is the main routine for a program which extracts navigation
5 c for a LAC scene from the GAC file covering the same time period. The
6 c attitude angles from the GAC data are interpolated to the LAC scan times
7 c and used to replace the attitude-dependent fields in the LAC file
8 c
9 c Command-line Arguments:
10 c
11 c Name Type Description
12 c -------- ---- -----------
13 c lacfile char LAC file name
14 c gacfile char GAC file name
15 c
16 c By: Frederick S. Patt, SAIC GSC, 24 Sep. 98
17 c
18 c Notes: Linear interpolation is used for the attitude angles.
19 c The ECEF-to-orbital transformation matrices for the LAC scan lines are
20 c extracted from the original sensor transformation matrices using the
21 c tilt angle, sensor alignment matrix and original attitude angles.
22 c The tilt angle and orbit position are assumed to be correct and are
23 c re-used from the LAC data.
24 c
25 c Modification History:
26 c
27 c Modified to stop processing and return error code if LAC data is out of
28 c range of the GAC file provided. F. S. Patt, SAIC GSC, April 19, 1999.
29 c
30 c Modified to check for GAC file start time on previous day.
31 c F. S. Patt, SAIC GSC, April 22, 1999.
32 c
33 c Modified to exit with non-zero return codes for all error conditions.
34 c F. S. Patt, SAIC GSC, May 11, 1999.
35 c
36 c Modified to return number of extrapolated frames > 3 as exit code.
37 c F. S. Patt, SAIC GSC, April 27, 2000.
38 c
39 c Fixed bug which caused the same tilt angle to be used for all scan lines.
40 c F. S. Patt, SAIC GSC, June 6, 2000.
41 c
42 c Added check for orbit data consistency between LAC and GAC.
43 c F. S. Patt, SAIC, September 13, 2002.
44 c
45 c Changed data type for data start day from 2 to 4 bytes, to allow use of
46 c Julian day.
47 c F. S. Patt, SAIC, November 5, 2002.
48 
49 
50  implicit none
51 c
52 #include "nav_cnst.fin"
53 #include "navctl_s.fin"
54  type(navctl_struct) :: navctl
55 c
56  integer*4 nling, nlinl, iret, amode, prod_id, sfend, i
57  integer*4 msecg(maxlin), msecl(maxlin), msecday, maxret
58  integer*4 igday, ilday
59  real*4 posg(3,maxlin), posl(3,maxlin), tilt(maxlin)
60  real*4 attg(3,maxlin), attl(3,maxlin), coef(6,maxlin)
61  real*4 attxfm(3,3), smat(3,3,maxlin)
62  character*80 lacfile, gacfile
63  data msecday/86400000/
64 
65 c Initialize navigation constants
66  call cdata
67 
68 c Read control parameter file
69  call readctl(navctl, iret)
70 
71  if (iret.ne.0) then
72  write (*,*) 'Error reading navctl.dat'
73  go to 999
74  end if
75 
76 c Get LAC file name
77  call getarg(1,lacfile)
78  write( 6, 300 ) lacfile
79  300 format( ' interp_nav.f: LAC file =',/,a,/ )
80 
81 c Get GAC file name
82  call getarg(2,gacfile)
83  write( 6, 301 ) gacfile
84  301 format( ' interp_nav.f: GAC file =',/,a,/ )
85 
86 c Open GAC file
87  amode = 1
88  call get_l1a_open( gacfile, amode, prod_id, igday, nling, iret )
89 
90  if (iret.ne.0) then
91  write(*,*) 'Error opening GAC file'
92  go to 999
93  end if
94 
95 c Read GAC data
96  call get_l1a_data( prod_id, nling, msecg, posg, smat, attg,
97  * tilt, iret )
98 
99  if (iret.ne.0) then
100  write(*,*) 'Error reading GAC'
101  go to 999
102  end if
103 
104 c Close GAC file
105  iret = sfend(prod_id)
106 
107 c Open LAC file
108  amode = 3
109  call get_l1a_open( lacfile, amode, prod_id, ilday, nlinl, iret )
110 
111  if (iret.ne.0) then
112  write(*,*) 'Error opening LAC file'
113  go to 999
114  end if
115 
116 c Read LAC data
117  call get_l1a_data( prod_id, nlinl, msecl, posl, smat, attl,
118  * tilt, iret )
119 
120  if (iret.ne.0) then
121  write(*,*) 'Error reading LAC file'
122  go to 999
123  end if
124 
125 c Check for GAC file starting on previous day
126  if ( (ilday-igday) .eq. 1 ) then
127  do i=1,nlinl
128  msecl(i) = msecl(i) + msecday
129  end do
130  end if
131 
132 c Check for inconsistency between LAC and GAC orbit data
133  call checkorb( msecl, posl, msecg, posg, nlinl, nling, iret)
134  if (iret.ne.0) then
135  write(*,*) 'Orbit data differences in LAC and GAC data'
136  go to 999
137  end if
138 
139 
140  maxret = 0
141 
142 c Do for each LAC scan line
143  do i=1,nlinl
144 
145 c Extract the ECEF-to-orbital transformation matrix
146  call get_xfm( smat(1,1,i), navctl, tilt(i), attl(1,i),
147  * attxfm)
148 
149 c Interpolate the GAC attitude angles to the LAC scan line time
150  call interp_att(msecl(i), nling, msecg, attg, attl(1,i), iret)
151 
152  if (iret.ne.0) then
153  if (maxret.lt.iret) maxret = iret
154 c write(*,*) 'Error interpolating attitude at time',msecl(i)
155 c go to 999
156  end if
157 
158 c Recompute the sensor transformation matrix and the ellipse coefficients
159  call ellxfm( attxfm, attl(1,i), tilt(i), posl(1,i), navctl,
160  * smat(1,1,i), coef(1,i))
161 
162  end do
163  write(*,*) maxret, ' LAC lines extrapolated'
164 
165 c Write recomputed data to LAC file
166 
167  call put_l1a_data( prod_id, nlinl, smat, attl, coef, iret)
168  if (iret.ne.0) then
169  write(*,*) 'Error writing data to LAC file'
170  end if
171 
172 c Write recomputed metadata to LAC file
173 
174  call put_l1a_metadata( prod_id, nlinl, posl, smat, coef, iret)
175  if (iret.ne.0) then
176  write(*,*) 'Error writing metadata to LAC file'
177  end if
178 
179 c Close LAC file
180 
181  iret = sfend(prod_id)
182  stop
183 
184  999 iret = sfend(prod_id)
185  write(*,*) 'interp_nav exiting with error'
186  call exit(1)
187 
188  end
189 
190 
191 
192 
193 
194 
subroutine put_l1a_data(prod_ID, nlin, smat, att, coef, iret)
Definition: put_l1a_data.f:2
subroutine interp_att(msecl, nlin, msecg, attg, attl, iret)
Definition: interp_att.f:2
subroutine readctl(navctl, ierr)
Definition: readctl.f:2
subroutine get_l1a_data(prod_ID, nlin, msec, pos, smat, att, tilt, iret)
Definition: get_l1a_data.f:3
#define real
Definition: DbAlgOcean.cpp:26
subroutine put_l1a_metadata(prod_ID, nlin, pos, smat, coef, iret)
subroutine get_xfm(smat, navctl, tilt, att, attxfm)
Definition: get_xfm.f:2
subroutine cdata
Definition: cdata.f:2
subroutine ellxfm(attxfm, att_ang, tilt, p, navctl, smat, coef)
Definition: ellxfm.f:2
program interp_nav
Definition: main_interpnav.f:1
subroutine get_l1a_open(infile, amode, prod_ID, isday, nlin, iret)
Definition: get_l1a_open.f:3
subroutine checkorb(msecl, posl, msecg, posg, nlinl, nling, iret)
Definition: checkorb.f:2