OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
put_l1a_metadata.f
Go to the documentation of this file.
1  subroutine put_l1a_metadata( prod_ID, nlin, pos, smat, coef, iret)
2 
3 c put_l1a_metadata( prod_ID, nlin, pos, smat, coef, iret)
4 c
5 c Purpose: computes the granule-level and scan-line geographic metadata
6 c fields and writes them to a SeaWiFS L1A file
7 c
8 c Calling Arguments:
9 c
10 c Name Type I/O Description
11 c -------- ---- --- -----------
12 c prod_ID I*4 I HDF file ID for open file
13 c nlin I*4 I number of scan lines in the L1A file
14 c pos(3,*) R*4 I size 3 x nlin array of orbit vectors
15 c smat(3,3,*) R*4 I size 3 x 3 x nlin array of sensor matrices
16 c coef(6,*) R*4 I size 3 x nlin array of ellipse coefficients
17 c iret I*4 O return code
18 c =0, success
19 c =-1, failure
20 c
21 c By: F. S. Patt, SAIC GSC, 5 Feb 99
22 c
23 c Notes:
24 c
25 c Modification History:
26 c
27 
28 #include "nav_cnst.fin"
29 
30  real*4 smat(3,3,*), pos(3,*), coef(6,*)
31  real*4 xlon(maxlin,3), xlat(maxlin,3), xla(3)
32  real*4 xlo(3), solz(3), sola(3), senz(3), sena(3)
33  real*4 csolz(maxlin), sunr(3,maxlin)
34  integer*4 prod_ID, iret
35  integer*4 sr_id, sl_id, at_id, ind, dfflt
36  integer*4 istart(3), istr(3), idims(3)
37  integer*4 nflag(maxlin)
38  integer sfn2index, sfselect, sfwdata, sfrdata, sfendacc
39  integer sfsattr
40  logical cross
41  data istart/3*0/, istr/3*1/, dfflt/5/
42 
43  iret = 0
44 
45 c First read Sun reference vectors from file
46  ind = sfn2index(prod_id, 'sun_ref')
47  if (ind.eq.-1) then
48  iret = -1
49  write(*,*) 'Error getting index for sun_ref'
50  return
51  end if
52  sr_id = sfselect(prod_id, ind)
53  if (sr_id.eq.-1) then
54  iret = -1
55  write(*,*) 'Error selecting sun_ref'
56  return
57  end if
58  idims(1) = 3
59  idims(2) = nlin
60  iret = sfrdata(sr_id, istart, istr, idims, sunr)
61  if (iret.eq.-1) then
62  write(*,*) 'Error reading sun_ref'
63  return
64  end if
65  iret = sfendacc(sr_id)
66 
67 
68 c Next compute scan line end and center coordinates for each line
69 c Also find min and max coordinates
70 
71  nsta = 1
72  ninc = 642
73  npix = 3
74  cross = .false.
75 
76  do ilin = 1, nlin
77  call geonav( pos(1,ilin), smat(1,1,ilin), coef(1,ilin),
78  1 sunr(1,ilin), nsta, ninc, npix, xla, xlo,
79  2 solz, sola, senz, sena )
80  csolz(ilin) = solz(2)
81  do j=1,3
82  xlon(ilin,j) = xlo(j)
83  xlat(ilin,j) = xla(j)
84  end do
85 
86 
87 c Check for date line crossing
88  if ( xlo(1) .gt. xlo(3) ) cross = .true.
89 
90  end do
91 
92 c Find coordinate extrema
93 c Not worried about exceptional cases here
94  xlanth = max(xlat(1,1),xlat(1,2))
95  xlasth = min(xlat(nlin,2),xlat(nlin,3) )
96  xlowst = xlon(nlin,1)
97  xloest = xlon(1,3)
98  icntr = nlin/2
99  xlactr = xlat(icntr,2)
100  xloctr = xlon(icntr,2)
101  solzct = csolz(icntr)
102 
103 c Write scan line metadata
104 
105 c Scan start latitude
106  call put_scan_metadata (prod_id, 'slat', nlin, xlat(1,1),
107  1 iret )
108  if (iret.eq.-1) then
109  write(*,*) 'Error writing slat'
110  return
111  end if
112 
113 c Scan center latitude
114  call put_scan_metadata (prod_id, 'clat', nlin, xlat(1,2),
115  1 iret )
116  if (iret.eq.-1) then
117  write(*,*) 'Error writing clat'
118  return
119  end if
120 
121 c Scan end latitude
122  call put_scan_metadata (prod_id, 'elat', nlin, xlat(1,3),
123  1 iret )
124  if (iret.eq.-1) then
125  write(*,*) 'Error writing elat'
126  return
127  end if
128 
129 c Scan start longitude
130  call put_scan_metadata (prod_id, 'slon', nlin, xlon(1,1),
131  1 iret )
132  if (iret.eq.-1) then
133  write(*,*) 'Error writing slon'
134  return
135  end if
136 
137 c Scan center longitude
138  call put_scan_metadata (prod_id, 'clon', nlin, xlon(1,2),
139  1 iret )
140  if (iret.eq.-1) then
141  write(*,*) 'Error writing clon'
142  return
143  end if
144 
145 c Scan end longitude
146  call put_scan_metadata (prod_id, 'elon', nlin, xlon(1,3),
147  1 iret )
148  if (iret.eq.-1) then
149  write(*,*) 'Error writing elon'
150  return
151  end if
152 
153 c Scan center solar zenith
154  call put_scan_metadata (prod_id, 'csol_z', nlin, csolz,
155  1 iret )
156  if (iret.eq.-1) then
157  write(*,*) 'Error writing csol_z'
158  return
159  end if
160 
161 c End of writing scan line metadat
162 
163 c Write scene coordinate metadata
164 
165  iret = sfsattr(prod_id, 'Scene Center Solar Zenith', dfflt,
166  1 1, solzct )
167  if (iret.eq.-1) then
168  write(*,*)'Error writing Scene Center Solar Zenith'
169  return
170  endif
171 
172  iret = sfsattr(prod_id, 'Scene Center Latitude', dfflt,
173  1 1, xlactr)
174  if (iret.eq.-1) then
175  write(*,*)'Error writing Scene Center Latitude'
176  return
177  endif
178 
179  iret = sfsattr(prod_id, 'Scene Center Longitude', dfflt,
180  1 1, xloctr)
181  if (iret.eq.-1) then
182  write(*,*)'Error writing Scene Center Longitude'
183  return
184  endif
185 
186  iret = sfsattr(prod_id, 'Upper Right Latitude', dfflt,
187  1 1, xlat(1,3))
188  if (iret.eq.-1) then
189  write(*,*)'Error writing Upper Right Latitude'
190  return
191  endif
192 
193  iret = sfsattr(prod_id, 'Upper Right Longitude', dfflt,
194  1 1, xlon(1,3))
195  if (iret.eq.-1) then
196  write(*,*)'Error writing Upper Right Longitude'
197  return
198  endif
199 
200  iret = sfsattr(prod_id, 'Upper Left Latitude', dfflt,
201  1 1, xlat(1,1))
202  if (iret.eq.-1) then
203  write(*,*)'Error writing Upper Left Latitude'
204  return
205  endif
206 
207  iret = sfsattr(prod_id, 'Upper Left Longitude', dfflt,
208  1 1, xlon(1,1))
209  if (iret.eq.-1) then
210  write(*,*)'Error writing Upper Left Longitude'
211  return
212  endif
213 
214  iret = sfsattr(prod_id, 'Lower Left Latitude', dfflt,
215  1 1, xlat(nlin,1))
216  if (iret.eq.-1) then
217  write(*,*)'Error writing Lower Left Latitude'
218  return
219  endif
220 
221  iret = sfsattr(prod_id, 'Lower Left Longitude', dfflt,
222  1 1, xlon(nlin,1))
223  if (iret.eq.-1) then
224  write(*,*)'Error writing Lower Left Longitude'
225  return
226  endif
227 
228  iret = sfsattr(prod_id, 'Lower Right Latitude', dfflt,
229  1 1, xlat(nlin,3))
230  if (iret.eq.-1) then
231  write(*,*)'Error writing Lower Right Latitude'
232  return
233  endif
234 
235  iret = sfsattr(prod_id, 'Lower Right Longitude', dfflt,
236  1 1, xlon(nlin,3))
237  if (iret.eq.-1) then
238  write(*,*)'Error writing Lower Right Longitude'
239  return
240  endif
241 
242  iret = sfsattr(prod_id, 'Start Center Latitude', dfflt,
243  1 1, xlat(1,2))
244  if (iret.eq.-1) then
245  write(*,*)'Error writing Start Center Latitude'
246  return
247  endif
248 
249  iret = sfsattr(prod_id, 'Start Center Longitude', dfflt,
250  1 1, xlon(1,2))
251  if (iret.eq.-1) then
252  write(*,*)'Error writing Start Center Longitude'
253  return
254  endif
255 
256  iret = sfsattr(prod_id, 'End Center Latitude', dfflt,
257  1 1, xlat(nlin,2))
258  if (iret.eq.-1) then
259  write(*,*)'Error writing End Center Latitude'
260  return
261  endif
262 
263  iret = sfsattr(prod_id, 'End Center Longitude', dfflt,
264  1 1, xlon(nlin,2))
265  if (iret.eq.-1) then
266  write(*,*)'Error writing End Center Longitude'
267  return
268  endif
269 
270  iret = sfsattr(prod_id, 'Northernmost Latitude', dfflt,
271  1 1, xlanth)
272  if (iret.eq.-1) then
273  write(*,*)'Error writing Northernmost Latitude'
274  return
275  endif
276 
277  iret = sfsattr(prod_id, 'Southernmost Latitude', dfflt,
278  1 1, xlasth)
279  if (iret.eq.-1) then
280  write(*,*)'Error writing Southernmost Latitude'
281  return
282  endif
283 
284  iret = sfsattr(prod_id, 'Westernmost Longitude', dfflt,
285  1 1, xlowst)
286  if (iret.eq.-1) then
287  write(*,*)'Error writing Westernmost Longitude'
288  return
289  endif
290 
291  at_id = sfsattr(prod_id, 'Easternmost Longitude', dfflt,
292  1 1, xloest)
293  if (iret.eq.-1) then
294  write(*,*)'Error writing Easternmost Longitude'
295  return
296  endif
297 
298  return
299  end
300 
301  subroutine put_scan_metadata (prod_ID, sdname, idim, sddata,
302  1 iret )
303 
304  real*4 sddata(*)
305  integer*4 prod_ID, idim, iret
306  integer*4 istart(2), istr(2), idims(2), ind, sd_id
307  integer sfn2index, sfselect, sfwdata, sfendacc
308  character*(*) sdname
309  data istart/2*0/, istr/2*1/
310 
311  ind = sfn2index(prod_id, sdname)
312  if (ind.eq.-1) then
313  iret = -1
314  write(*,*) 'Error getting sds index'
315  return
316  end if
317 
318  sd_id = sfselect(prod_id, ind)
319  if (sd_id.eq.-1) then
320  iret = -1
321  write(*,*) 'Error selecting sds'
322  return
323  end if
324 
325  idims(1) = idim
326  iret = sfwdata(sd_id, istart, istr, idims, sddata)
327  if (iret.eq.-1) then
328  write(*,*) 'Error writing sds'
329  return
330  end if
331 
332  iret = sfendacc(sd_id)
333 
334  return
335  end
#define real
Definition: DbAlgOcean.cpp:26
subroutine put_l1a_metadata(prod_ID, nlin, pos, smat, coef, iret)
#define max(A, B)
Definition: main_biosmap.c:61
subroutine put_scan_metadata(prod_ID, sdname, idim, sddata, iret)
#define min(A, B)
Definition: main_biosmap.c:62