OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
atrem_app_refl_plus_gas_removal_for_l2gen3.f90
Go to the documentation of this file.
1 !------------------------------------------------------------------------------|
2 ! The September 2012 version of atrem code, 'atrem_for_PRISM.f' (atrem for JPL |
3 ! PRISM Imaging Spectrometer, was obtained through modifying a 2011 |
4 ! version of 'atrem_f90_cubeio.f'. |
5 ! The March 2013 version of atrem code, 'atrem_for_PRISM_2013.f', was updated |
6 ! from the September 2012 version of atrem code. The upgrades include: |
7 ! a) replacing the MODTRAN 3.5 solar irradiance curve with a new solar curve|
8 ! constructed from the solar irradiance curve of Thuillier et al. 2004 |
9 ! ATLAS 3 (<=644.7 nm) and that of Kurucz 2005 (> 644.7 nm) built in |
10 ! MODTRAN 5.2. This newly contructed solar curve is more suited for |
11 ! modeling imaging imaging spectrometer data below 450 nm and with a |
12 ! spectral resolution finer than 5 nm; |
13 ! b) replacing high spectral resolution gas absorption tables with new |
14 ! tables calculated with the HITRAN2008+ line database and a fast |
15 ! line-by-line code originally developed by Bill Ridgway. After such |
16 ! upgrades, the retrieved surface reflectances near 1.45 and 1.95 micron |
17 ! are improved significantly; |
18 ! c) modifying volume mixing ratios of atmospheric carbon dioxide; |
19 ! d) applying a scaling factor for improved modeling of atmospheric |
20 ! oxygen band absorption centered near 1.265 micron. |
21 !------------------------------------------------------------------------------|
22 ! The 2001 version of ATREM code uses the new 'cubeio.f90' for I/O operations. |
23 ! The output data cubes have no headers, unlike the previous generations |
24 ! of ATREM codes containing 512 bytes of headers in output data cubes. |
25 !------------------------------------------------------------------------------|
26 !********************************************************************************
27 !* *
28 !* Name: atrem_app_refl_plus_gas_removal_2013 April, 2013 *
29 !* (ATmosphere REMoval Program) *
30 !* *
31 !* Author: Bo-Cai Gao, Remote Sensing Division, Code 7230, *
32 !* Naval Research Laboratory, Washington, DC 20375 USA *
33 !* *
34 !* Purpose: To derive surface reflectances from spectral imaging data collected *
35 !* by the Airborne Visible Infrared Imaging Spectrometer (AVIRIS), *
36 !* HYDICE, HSI, PHILLS, HICO, NIS, PRISM, and possibly other *
37 !* airborne and spaceborne imaging spectrometers, and to derive a *
38 !* column water vapor image for each scene. *
39 !* *
40 !* General Principles: In order to derive surface reflectances from image data *
41 !* cube, a thorough compensation for the atmospheric absorption and *
42 !* scattering is required. The spatial and temporal variations of *
43 !* atmospheric water vapor amounts pose difficulties in removing *
44 !* water vapor absorption features in data cube using standard *
45 !* atmospheric models. In this algorithm, the amount of water vapor *
46 !* on a pixel-by-pixel basis is derived from data cube themselves *
47 !* using the 0.94- and the 1.14-um water vapor bands and a *
48 !* three-channel ratioing technique. The derived water vapor *
49 !* values are then used for modeling water vapor absorption effects *
50 !* in the entire 0.4-2.5 um region. The absorption effects of *
51 !* well mixed atmospheric gases, such as CO2, N2O, CH4, and O2, *
52 !* are modeled using standard atmospheric models. A line-by-line *
53 !* code developed by W. Ridgway at NASA Goddard Space Flight Center *
54 !* is used to generate a database of gaseous absorption *
55 !* coefficients at high spectral resolution. This database and *
56 !* ozone cross sections and NO2 cross sections are used in *
57 !* calculating transmittances of eight atmospheric gases (H2O, CO2 *
58 !* O3, N2O, CO, CH4, O2, and NO2). The scattering effect is modeled *
59 !* using a modified version of 6S code (Vermote et al. 1996). *
60 !* *
61 !* Algorithm: 1. An input parameter file is read in and global data are *
62 !* initialized. *
63 !* 2. The solar zenith angle is derived based on the flight time *
64 !* and latitude and longitude of the scene. *
65 !* 3. A table consisting of transmittance spectra at the solar *
66 !* and observational geometry but with varying amounts of water *
67 !* vapor is created. *
68 !* The transmittance spectra for water vapor (H2O), carbon *
69 !* dioxide (CO2), ozone (O3), nitrous oxide (N2O), carbon *
70 !* monoxide (CO), methane (CH4), oxygen (O2), and nitrogen *
71 !* dioxide (NO2) in the 0.4-2.5 micron region are calculated. *
72 !* 4. Aerosol and molecular scattering terms are calculated using *
73 !* a modified version of the 6S code. *
74 !* 5. The image data cube (2D spatial and 1D spectral) are accessed *
75 !* one spectral slice at a time from an image file in any storage*
76 !* order, Band SeQuential (BSQ), Band Interleaved by Pixel (BIP),*
77 !* and Band Interleaved by Line (BIL). Each measured radiance *
78 !* spectrum is divided by the solar irradiance curve above the *
79 !* atmosphere to get apparent reflectances. *
80 !* 6. The integrated water vapor amount for each apparent *
81 !* reflectance spectrum is derived from the 0.94- and the 1.14-um*
82 !* water vapor absorption bands using a 3-channel ratioing *
83 !* technique and a look-up table procedure. *
84 !* 7. The surface reflectances are derived using another look-up *
85 !* table procedure. Routines written in C language are used to *
86 !* perform all the input/output operations. *
87 !* *
88 !* Limitations: *
89 !* 1. This algorithm works best for areas where the surface elevation *
90 !* does not vary by more than 1 km. *
91 !* 2. The algorithm works well only for measurements taken on clear *
92 !* days. For hazy days with large aerosol optical depths, the *
93 !* algorithm does not work nearly as well. *
94 !* 3. The algorithm does not work well over dark areas such as rivers *
95 !* and lakes. It does not perform corrections for "atmospheric *
96 !* adjacency" effects. *
97 !* 4. The algorithm assumes horizontal surfaces having Lambertian *
98 !* reflectances. *
99 !* 5. Additional work is needed to port this algorithm to different *
100 !* computing systems. This algorithm was developed on an SGI *
101 !* workstation and used FORTRAN statements to read several binary *
102 !* files. The binary file format on different computers can be *
103 !* different. The record lengths defined on an SGI machine are *
104 !* different from most other computers. Some of the Dec Alpha *
105 !* workstations use 8 bytes (64 bits) to store a C-pointer, instead *
106 !* of 4 bytes (32 bits). All these factors need to be taken into *
107 !* considerations when porting this algorithm to other computers. *
108 !* *
109 !* User Input: *
110 !* 1. Name - Imaging spectrometer name, e.g., AVIRIS, HYDICE, HSI, PHYLLS. *
111 !* 2. Plane altitude in km, above the sea level. *
112 !* 3. Date - The month, day, and year that the data were collected. *
113 !* 4. Time - The hour, minute, second (GMT) that the data were *
114 !* collected. *
115 !* 5. Latitude - The mean latitude of the measurement area in degrees, *
116 !* minutes, seconds, and hemisphere. *
117 !* 6. Longitude - The mean longitude of the measurement area in *
118 !* degrees, minutes, seconds, and hemisphere. *
119 !* 7. View zenith angle - the angle in degrees, minutes, and seconds *
120 !* between the viewing direction and nadir *
121 !* 8. View azimuth angle in degree, minutes and seconds. The view azimuth *
122 !* angle is defined as the angle between local North *
123 !* the view direction projected on the ground *
124 !* (clockwise count). This angle can vary from 0 *
125 !* to 360 deg. Ths definition here is consistent with*
126 !* navigator's convention, but not consistent with *
127 !* astronomer's convention. Here is an example: for *
128 !* a downward looking instrument pointed off-nadir *
129 !* to the West, the view azimuthal angle is 90 deg. *
130 !* Conversely, if the instrument is pointed toward *
131 !* East, the view azimuthal angle is 270 deg. *
132 !* *
133 !* 9. Resolution of input spectra in nm (~ 10 nm for AVIRIS) or "0" *
134 !* if the FWHM values (in micron) are present in the wavelength file *
135 !* 10. Filename of spectrometer wavelength table - 2 or 3 column ASCII data. *
136 !* The first column is the channel number, the second column is *
137 !* the wavelength and the optional third column is the FWHM value for *
138 !* each channel. *
139 !* 11. Channel ratio parameters - Center positions and widths of window and *
140 !* water vapor channels used in channel ratios for deriving *
141 !* the amount of water vapor from imaging data. Each of the window *
142 !* and water vapor channels typically consists of several narrow *
143 !* imaging spectrometer channels. *
144 !* 12. Atmospheric model - Temperature, pressure, water vapor volume mixing *
145 !* ratio profiles. The model can be either a predefined model or a *
146 !* user defined model. *
147 !* 13. Gases - An indication of which of the 8 gases (H2O, CO2, O3, *
148 !* N2O, CO, CH4, O2, and NO2) should be included in the spectral *
149 !* calculations. *
150 !* 14. Ozone - Column amount of O3 - changes with season and *
151 !* latitude. Typical value is .34 atm-cm. *
152 !* 15. Aerosol model number and visibility when measurements were taken. *
153 !* 16. Aerosol optical depth at 550 nm (Optional, only if visibility V *
154 !* is set to 0) *
155 !* 17. Surface elevation - The average surface elevation of an imaging scene *
156 !* in km. *
157 !* 18. Filename of input image file *
158 !* 19. Dimensions of input image. *
159 !* 20. Filename of output image file in same storage order as input file *
160 !* 21. Resolution of output surface reflectance spectra in micron *
161 !* 22. Scale factor for output reflectance values *
162 !* 23. Filename of output water vapor image. *
163 !* 24. Filename of output atmospheric transmittance look-up table *
164 !* *
165 !* Output: *
166 !* a. Output to user specified files: *
167 !* 1. Surface reflectance cube data - retrieved from the image data cube *
168 !* 2. Water vapor image - an image of the derived column water vapor *
169 !* amounts at each pixel. *
170 !* 3. Transmittance Look-up table - consisting of channel ratio values *
171 !* for the .94- and 1.14-um channels corresponding to 60 water vapor *
172 !* amounts, and the associated atmospheric transmittance spectra. *
173 !* b. Output to standard output: *
174 !* 1. Debugging information - if the source is compiled with the *
175 !* debug flag set (-d_lines for the ULTRIX compiler), *
176 !* then debug information is written out. *
177 !* 2. Error messages - if any of the user input is invalid, or there is *
178 !* an I/O error, a message is written out, and the program halts. *
179 !* 3. Progress indicator - a message, which shows the number of the *
180 !* spectral slices that have been processed, to give the user an *
181 !* indication of the progress of the program execution. *
182 !* *
183 !* Special Considerations: *
184 !* a. Make sure that the imaging spectrometer's channel positions specified *
185 !* in the input wavelength table are correct. The incorrect channel *
186 !* positions will introduce sharp features in derived surface *
187 !* reflectance spectra. *
188 !* b. The output reflectance cube file has the same size as the input *
189 !* data cube file. Make sure there is enough space in the file *
190 !* system for the output cube before running this program. *
191 !* *
192 !* Change History: *
193 !* ATREM 1.2 - uses full-width half-max values to smooth solar irradiance *
194 !* curve and a new scaling factor for methane *
195 !* ATREM 1.3 - used new solar irradiance curve *
196 !* - supports 1992 AVIRIS data *
197 !* ATREM 1.3.1 - allows 0 and above for output resolution *
198 !* ATREM 2.0 - allows variable scale factors for each spectrometer *
199 !* (code submitted by Roger Clark, USGS) *
200 !* - user can input output scale factor for reflectance values *
201 !* - user can input radiance file header size in bytes *
202 !* - new solar irradiance curve (Neckel and Labs plus ATMOS) *
203 !* used (Green and Gao, 1993). *
204 !* ATREM 3.0 - replaced the 5S code by the 6S code for modeling atmospheric *
205 !* scattering effects and for modeling measurements from *
206 !* low-altitude aircrafts. ATREM 3.0, like previous versions *
207 !* of ATREM, only models nadir viewing geometry. *
208 !* - changed algorithms for calculating atmospheric gaseous *
209 !* transmittances for the upward surface-sensor path *
210 !* - users need to specify aircraft altitude (km) in input file *
211 !* ATREM 4.0 - replaced the band model by a line-by-line-based algorithm *
212 !* for calculating atmospheric gaseous transmittances. This *
213 !* allows the modeling of imaging spectrometer data at *
214 !* spectral resolutions better than 10 nm. *
215 !* - increased the buffer size to 1024x1024 in order to handle *
216 !* images larger than the AVIRIS' size (614x512). *
217 !* - modified the algorithm to allow off-nadir pointing geometry. *
218 !* - users need to specify view zenith angle and view azimuth *
219 !* angle. The view azimuth angle is defined as the angle *
220 !* between local North and the view direction projected on the *
221 !* ground (clockwise count). This angle can vary from 0 to *
222 !* 360 deg. *
223 !* - replaced the solar irradiance curve (Neckel and Labs plus *
224 !* ATMOS) by the high spectral resolution solar irradiance *
225 !* curve from MODTRAN 3.5 released in December of 1996. *
226 !* ATREM 4.1 - included atmospheric NO2 in transmittance calculations. *
227 !* *
228 !* Acknowledgments: *
229 !* This work was partially supported over several years by grants *
230 !* from NASA Jet Propulsion Laboratory, California Institute of *
231 !* Technology, from NASA Headquarters, and from the Office of Naval *
232 !* Research. Special thanks goes to Kathy Heidebrecht at the Center *
233 !* for the Study of Earth from Space, University of Colorado at *
234 !* Boulder, Colorado, for supporting the development of the earlier *
235 !* versions of ATREM codes. Special thanks also goes to William L. *
236 !* Ridgway for providing the line-by-line gaseous absorption database *
237 !* used in the present version of ATREM. *
238 !* *
239 !* References: *
240 !* Gao, B.-C., K. Heidebrecht, and A. F. H. Goetz, Derivation of scaled *
241 !* surface reflectances from AVIRIS data, Remote Sens. Env., 44, *
242 !* 165-178, 1993. *
243 !* Gao, B.-C., and C. O. Davis, Development of an operational algorithm *
244 !* for removing atmospheric effects from HYDICE and HSI data, *
245 !* in SPIE'96 Conference Proceedings, Vol. 2819, 45-55, 1996. *
246 !* Gao, B.-C., and A. F. H. Goetz, Column atmospheric water vapor and *
247 !* vegetation liquid water retrievals from airborne imaging *
248 !* spectrometer data, J. Geophys. Res., 95, 3549-3564, 1990. *
249 !* Goetz, A. F. H., and M. Herring, The high resolution imaging *
250 !* spectrometer (HIRIS) for Eos, IEEE Trans. Geosci. Remote Sens., 27,*
251 !* 136-144, 1989. *
252 !* Goetz, A. F. H., G. Vane, J. Solomon, and B. N. Rock, Imaging *
253 !* spectrometry for Earth remote sensing, Science, 228, 1147-1153,1985*
254 !* Green, R. O., and B.-C. Gao, A Proposed Update to the Solar Irradiance*
255 !* Spectrum used in LOWTRAN and MODTRAN, in Summaries of the Fourth *
256 !* Annual JPL Airborne Geoscience Workshop, October 25-29, (Editor, *
257 !* R. O. Green), JPL Publ. 93-26, Vol. 1, pp. 81-84, Jet Propul. Lab, *
258 !* Pasadena, Calif., 1993. *
259 !* Kneizys, F. X., E. P. Shettle, L. W. Abreu, J. H. Chetwynd, G. P. *
260 !* Anderson, W. O. Gallery, J. E. A. Selby, and S. A. Clough, Users *
261 !* guide to LOWTRAN7, AFGL-TR-8-0177, Air Force Geophys. Lab., *
262 !* Bedford, Mass., 1988. *
263 !* Iqbal, M., An Introduction To Solar Radiation, Academic, San Diego, *
264 !* Calif., 1983. *
265 !* Malkmus, W., Random Lorentz band model with exponential-tailed S line *
266 !* intensity distribution function, J. Opt. Soc. Am., 57, 323-329,1967*
267 !* Press, W. H., B. P. Flannery, S. A. Teukolsky, and W. T. Vetterling, *
268 !* Numerical Recipes-The ART of Scientific Computing, Cambridge *
269 !* University Press, 1986. *
270 !* Rothman, L. S., et al., The HITRAN 2008 molecular spectroscopic *
271 !* database, JQSRT, 110, 533-572, 2009. *
272 !* Solomon, S., R. W. Portmann, R. W. Sanders, J. S. Daniel, W. Madsen, *
273 !* B. Bartram, and E. G. Dutton, On the role of nitrogen dioxide in *
274 !* the absorption of solar radiation, J. Geophys. Res., 104, *
275 !* 12047-12058, 1999. *
276 !* Tanre, D., C. Deroo, P. Duhaut, M. Herman, J. J. Morcrette, J. Perbos,*
277 !* and P. Y. Deschamps, Description of a computer code to simulate *
278 !* the satellite signal in the solar spectrum: the 5S code, Int. *
279 !* J. Remote Sens., 11, 659-668, 1990. *
280 !* Tanre, D., C. Deroo, P. Duhaut, M. Herman, J. J. Morcrette, J. Perbos,*
281 !* and P. Y. Deschamps, Simulation of the satellite signal in the *
282 !* solar spectrum (5S), Users' Guide (U. S. T. De Lille, 59655 *
283 !* Villeneu d'Ascq, France: Laboratoire d'Optique Atmospherique), *
284 !* 1986. *
285 !* Thuillier, G., et al., Solar irradiance reference spectra for two *
286 !* solar active levels, Adv. Space Res., 34, 256-261, 2004. *
287 !* Vane, G., R. O. Green, T. G. Chrien, H. T. Enmark, E. G. Hansen, and *
288 !* W. M. Porter, The Airborne Visible/Infrared Imaging Spectrometer, *
289 !* Remote Sens. Env., 44, 127-143, 1993. *
290 !* Vane, G. (Ed), Airborne visible/infrared imaging spectrometer *
291 !* (AVIRIS), JPL Publ. 87-38, Jet Propul. Lab, Pasadena, Calif., 1987.*
292 !* Vermote, E., D. Tanre, J. L. Deuze, M. Herman, and J. J. Morcrette, *
293 !* Second simulation of the satellite signal in the solar spectrum *
294 !* (6S), 6S User's Guide Version 1, NASA-GSFC, Greenbelt, Maryland, *
295 !* 134 pages, 1994. *
296 !* *
297 !********************************************************************************
298 !
299 !
300 !********************************************************************************
301 !* *
302 !* Name: GET_INPUT *
303 !* Purpose: Reads and verifies all user provided input. *
304 !* Parameters: none *
305 !* Algorithm: Data is read in from standard input. The user is not prompted *
306 !* interactively, so data should be redirected from an input file. *
307 !* The data is validated after it is read in. If the data is *
308 !* invalid, a message is printed and the program stops. *
309 !* Globals used: TPVMR - two dimensional array containing 6 predefined *
310 !* atmospheric models. The models contain values for *
311 !* the number of atmospheric layer boundaries, altitude,*
312 !* temperature, pressure, and water vapor volume mixing *
313 !* ratio. *
314 !* Global output: IH2OVP, ICO2, IO3, IN2O, ICO, ICH4, IO2 - set to 0 to *
315 !* indicate that the gas should NOT be used in the *
316 !* calculations, and set to 1 if the gas should be used *
317 !* H(), T(), P(), VMR(), NB, NL, MODEL - altitude (km), *
318 !* temperature (K), pressure (atm), water vapor volume *
319 !* mixing ratio (ppm), number of atmospheric layer *
320 !* boundaries, number of atmospheric layers (NB-1), *
321 !* and model number for the selected atmospheric model. *
322 !* VRTO3 - column amount of O3. *
323 !* WAVOBS() - wavelengths for all channels. *
324 !* FWHM() - resolutions for each channel. *
325 !* NOBS - number of AVIRIS wavelengths. *
326 !* HSURF - the mean surface elevation of the imaging scene *
327 !* DLT, DLT2 - resolution, in units of nm, of input *
328 !* spectra and resolution of output surface reflectance *
329 !* spectra. If DLT2>DLT, output spectra are smoothed *
330 !* using a gaussian function. *
331 !* WNDOW1, WNDOW2, WP94C - center wavelength positions of two *
332 !* broad window channels and one broad .94-um water *
333 !* vapor channel. *
334 !* WNDOW3, WNDOW4, W1P14C - center wavelength positions of two *
335 !* broad window channels and one broad 1.14-um water *
336 !* vapor channel. *
337 !* NB1, NB2, NBP94, NB3, NB4, NB1P14 - number of individual *
338 !* narrow channels that form the corresponding broad *
339 !* window and water vapor absorption channels. *
340 !* IMN, IDY, IYR, IH, IM, IS - month, day, year, hour, minute, *
341 !* and second of measurement. *
342 !* XLATD, XLATM, XLATS, LATHEM - degrees, minutes, seconds, and*
343 !* hemisphere of latitude of measured area. *
344 !* XLONGD, XLONGM, XLONGS, LNGHEM - degrees, minutes, seconds, *
345 !* and hemisphere of latitude of measured area. *
346 !* NAME_INSTRU: Imaging spectrometer name, e.g., AVIRIS, HYDICE*
347 !* XPSS: = HSURF, an interface for using 6S. *
348 !* XPPP: plane height (km, above the sea level). *
349 !* *
350 !* Return Codes: none *
351 !* Special Considerations: None *
352 !* *
353 !********************************************************************************
354 
355  SUBROUTINE get_input
356 
357  use cubeio
358 
359  include 'COMMONS_INC.f'
360 
361  INTEGER LUN_IN, LUN_OUT, LUN_VAP, I_RET
362  COMMON /inout_units/ lun_in, lun_out, lun_vap
363 
364 
365 !C Common variables
366  dimension h(25), t(25), p(25), vmr(25)
367  dimension wavobs(1024),fwhm(1024)
368  dimension tpvmr(7,81)
369  CHARACTER*1 LATHEM, LNGHEM
370 
371  CHARACTER (LEN = 1000) :: FINAV,FOCUB,FOH2O
372  INTEGER SORDER,HDREC
373 
374 !C Local variables
375  INTEGER ANS
376  CHARACTER (LEN = 1000) :: FINPWV,FTPVMR
377  LOGICAL GOOD_DATA
378  CHARACTER (LEN = 1000) :: FOUT1
379  INTEGER DIMS(4)
380  INTEGER ST_ORDER
381 
382  COMMON /getinput1/ ih2ovp,ico2,io3,in2o,ico,ich4,io2,ino2
383  COMMON /getinput3/ h,t,p,vmr,nb,nl,model,iaer,v,taer55,vrto3,sno2
384  COMMON /getinput4/ wavobs,fwhm
385  COMMON /getinput5/ nobs,hsurf,dlt,dlt2
386  COMMON /getinput6/ wndow1,wndow2,wp94c,wndow3,wndow4,w1p14c
387  COMMON /getinput7/ nb1,nb2,nbp94,nb3,nb4,nb1p14
388  COMMON /getinput8/ imn,idy,iyr,ih,im,is
389  COMMON /getinput9/ xlatd,xlatm,xlats,lathem
390  COMMON /getinput10/xlongd,xlongm,xlongs,lnghem
391  COMMON /getinput11/hdrec,nsamps,nlines,nbands,sorder
392  COMMON /getinput12/scalef
393  COMMON /tpvmr_init1/ tpvmr
394 
395 !C Commons for use with the C programs for cube I/O
396  COMMON /outcube/ focub
397  COMMON /incube/ finav
398  COMMON /outh2ovap/ foh2o
399 
400 !C Parameters for names of imaging spectrometers
401  CHARACTER (LEN = 80) :: NAME_INSTRU, NAMES(10)
402  COMMON /getinput13/ name_instru, names
403 
404  REAL XPSS, XPPP
405  COMMON /getinput14/ xpss, xppp
406 
407  REAL XVIEWD, XVIEWM, XVIEWS
408  REAL XAZMUD, XAZMUM, XAZMUS
409  COMMON /getinput15/ xviewd,xviewm,xviews, xazmud,xazmum,xazmus
410 
411  good_data = .true. ! initialize flag for good data
412 
413 !C Get the name of imaging spectrometer, e.g., AVIRIS, HYDICE
414  READ(5,627) name_instru
415  627 FORMAT(a10)
416 !C
417 !C
418 !C***Temp code for assigning names of imaging spectrometers. Based on these
419 !C names, different scale factors should be used for different instrument
420 !C when converting measured radiances to standard radiance units.
421 !C*** The coding here may need to be moved to the file "COMMONS_INC"
422  names(1) = 'AVIRIS'
423  names(2) = 'HYDICE'
424  names(3) = 'HSI'
425  names(4) = 'TRWIS-III'
426  names(5) = 'PHYLLS'
427  names(6) = 'Hyperion'
428  names(7) = 'HICO'
429  names(8) = 'NIS'
430  names(9) = 'PRISM'
431  names(10)= 'OTHERS?'
432 !C***End of temp coding ------------
433 
434  print*, 'Instrument Name: ', name_instru
435 
436 !C Get the plane altitude (in km, above sea level). Must > HSURF.
437  READ(*,*) xppp
438 
439 !C-- print*, 'XPPP = ', XPPP
440 
441 !C Get date and time of measurements. Format: MM DD YYYY HH MM SS
442  READ (5,*) imn,idy,iyr,ih,im,is
443  IF((imn.LT.1).OR.(imn.GT.12).OR.(idy.LT.1).OR.(idy.GT.31).OR. &
444  (iyr.LT.1987).OR.(iyr.GT.2020)) THEN
445  WRITE(*,*)'Invalid date:',imn,idy,iyr
446  WRITE(*,*)'Format is MM DD YYYY where 0<MM<12, 0<DD<32, &
447  YYYY>1986.'
448  good_data = .false.
449  ENDIF
450  IF((ih.LT.0).OR.(ih.GT.24).OR.(im.LT.0).OR.(im.GT.60).OR. &
451  (is.LT.0).OR.(is.GT.60)) THEN
452  WRITE(*,*)'Invalid time:',ih,im,is
453  WRITE(*,*)'Format is HH MM SS where 0<HH<24, 0<MM<60, SS<60.'
454  good_data = .false.
455  ENDIF
456 
457 !C Get latitude of measurements. Format: degrees minutes seconds
458  READ (5,*) xlatd,xlatm,xlats
459  IF((xlatd.GT.90).OR.(xlatm.GT.60).OR.(xlats.GT.60)) THEN
460  WRITE(*,*)'Invalid latitude:',xlatd,xlatm,xlats
461  WRITE(*,*)'Format: degrees minutes seconds'
462  WRITE(*,*)'Valid values are degrees < 90, minutes < 60, &
463  seconds<60.'
464  good_data = .false.
465  ENDIF
466 
467 !C Get hemisphere of latitude. Format: "N" or "S"
468  READ (5,127) lathem
469  127 FORMAT(a1)
470  IF((lathem.NE.'N').AND.(lathem.NE.'S')) THEN
471  WRITE(*,*)'Invalid hemisphere value:',lathem
472  WRITE(*,*)'Valid values are "N" or "S".'
473  good_data = .false.
474  ENDIF
475 
476 !C Get longitude of measurements. Format: degrees minutes seconds
477  READ (5,*) xlongd,xlongm,xlongs
478  IF((xlongd.GT.180).OR.(xlongm.GT.60).OR.(xlongs.GT.60)) THEN
479  WRITE(*,*)'Invalid longitude:',xlongd,xlongm,xlongs
480  WRITE(*,*)'Format: degrees minutes seconds'
481  WRITE(*,*)'Valid values are degrees < 180 minutes < 60, &
482  seconds<60.'
483  good_data = .false.
484  ENDIF
485 
486 !C Get hemisphere of longitude. Format: "E" or "W"
487  READ (5,127) lnghem
488  IF((lnghem.NE.'E').AND.(lnghem.NE.'W')) THEN
489  WRITE(*,*)'Invalid hemisphere:',lnghem
490  WRITE(*,*)'Valid values are "E" or "W".'
491  good_data = .false.
492  ENDIF
493 
494 !C Get view zenith angle. Format: degrees minutes seconds
495  READ (5,*) xviewd,xviewm,xviews
496  IF((xviewd.GT.90).OR.(xviewm.GT.60).OR.(xviews.GT.60)) THEN
497  WRITE(*,*)'Invalid latitude:',xviewd,xviewm,xviews
498  WRITE(*,*)'Format: degrees minutes seconds'
499  WRITE(*,*)'Valid values are degrees < 90, minutes < 60 & seconds<60.'
500  good_data = .false.
501  ENDIF
502 
503 !C Get relative azimuth angle between the solar ray and view direction with
504 !C both projected on the ground. Format: degrees minutes seconds
505  READ (5,*) xazmud,xazmum,xazmus
506  IF((xazmud.GT.360.).OR.(xazmum.GT.60).OR.(xazmus.GT.60)) THEN
507  WRITE(*,*)'Invalid view azimuth ang.:',xazmud,xazmum,xazmus
508  WRITE(*,*)'Format: degrees minutes seconds'
509  WRITE(*,*)'Valid values are degrees < 360, minutes < 60, & seconds<60.'
510  good_data = .false.
511  ENDIF
512 
513 !C Get spectral resolutions (FWHM) in micron. If the value is 0, that means
514 !C read the FWHM data from the wavelength file. Otherwise, a non-zero value
515 !C will be used as a the constant FWHM value.
516  READ(*,*)dlt
517  IF (dlt.GT.0.0) THEN
518  IF((dlt.LT.0.0005).OR.(dlt.GT.0.1)) THEN
519  WRITE(*,*)'Invalid spectral resolution value:',dlt
520  WRITE(*,*)'Valid values are 0.0005-0.1 micron.'
521  good_data = .false.
522  ELSE
523 !C Initialize the FWHM array
524 !C*** DLTNEW=DLT/1000.
525  DO 521 i=1,1024
526  fwhm(i)=dlt
527  521 CONTINUE
528  ENDIF
529  ENDIF
530 
531 !C Get imaging spectrometer wavelength file name
532  READ(*,85) finpwv
533  85 FORMAT(a1000)
534  OPEN(11,file=finpwv,status='OLD',iostat=istat)
535  IF(istat.NE.0) THEN
536  WRITE(*,*)'wavelength file did not open successfully:',finpwv
537  good_data = .false.
538  ELSE
539 
540 !C Read wavelength data. For 1991 and before, the file contains the channel
541 !C number and the wavelength for each channel. For 1992, the file also contains
542 !C a third column with the resolution (FWHM) in micron for each channel.
543 
544  nobs = 1024 !initially set to max allowable # of observations
545  DO 510 i=1,nobs
546  IF (dlt.GT.0.) THEN
547  READ(11,*,END=520) X,WAVOBS(I)
548  ELSE
549  READ(11,*,END=520) X,WAVOBS(I), FWHM(I)
550  ENDIF
551  510 CONTINUE
552  520 nobs=i-1 !set to actual # of observations in input file
553  CLOSE(11)
554  ENDIF
555 
556 !C Determine if channel ratio parameters should be read. Format: 0=no 1=yes
557  READ(*,*) ans
558  IF((ans.NE.0).AND.(ans.NE.1)) THEN
559  WRITE(*,*)'Invalid value to indicate whether the channel ratio parameters should be read:',ans
560  WRITE(*,*)'Valid values: 0=no 1=yes.'
561  good_data = .false.
562  ELSE
563  IF (ans .EQ. 1) THEN
564 !C Get ranges on curve for the two atmospheric windows surrounding the .94-um
565 !C water vapor absorption feature and the center point of the .94-um water
566 !C vapor absorption feature. Enter:
567 !C 1. the midpoint of first window (0.6-2.5)
568 !C 2. number of points to average for first window (1-10)
569 !C 3. the midpoint of second window (0.6-2.5)
570 !C 4. number of points to average for second window (1-10)
571 !C 5. the midpoint of water vapor absorption feature (0.6-2.5)
572 !C 6. the number of points to average absorption feature (1-30)
573 
574  114 READ(*,*)wndow1, nb1, wndow2, nb2, wp94c, nbp94
575 
576  IF((wndow1.LT.0.6).OR.(wndow1.GT.2.5)) THEN
577  WRITE(*,*)'Invalid wavelength position for first atmospheric window in the .94-um region:',wndow1
578  WRITE(*,*)'Valid values are 0.6-2.5.'
579  good_data = .false.
580  ENDIF
581 
582  IF((nb1.LT.1).OR.(nb1.GT.50)) THEN
583  WRITE(*,*)'Invalid number of channels for first wavelength position in the .94-um region:',nb1
584  WRITE(*,*)'Valid values are 1-50.'
585  good_data = .false.
586  ENDIF
587 
588  IF((wndow2.LT.0.6).OR.(wndow2.GT.2.5)) THEN
589  WRITE(*,*)'Invalid wavelength position for second atmospheric window in the .94-um region:',wndow2
590  WRITE(*,*)'Valid values are 0.6-2.5.'
591  good_data = .false.
592  ENDIF
593 
594  IF((nb2.LT.1).OR.(nb2.GT.50)) THEN
595  WRITE(*,*)'Invalid number of channels for second wavelength position in the .94-um region:',nb2
596  WRITE(*,*)'Valid values are 1-50.'
597  good_data = .false.
598  ENDIF
599 
600  IF((wp94c.LE.wndow1).OR.(wp94c.GE.wndow2)) THEN
601  WRITE(*,*)'Invalid water vapor wavelength position for the .94-um region:',wp94c
602  WRITE(*,*)'Valid range is:',wndow1,' < value < ',wndow2,'.'
603  good_data = .false.
604  ENDIF
605 
606  IF((nbp94.LT.1).OR.(nbp94.GT.90)) THEN
607  WRITE(*,*)'Invalid number of channels for water vapor wavelength position in the .94-um region:',nbp94
608  WRITE(*,*)'Valid values are 1-90.'
609  good_data = .false.
610  ENDIF
611 
612 !C Get ranges on curve for the two atmospheric windows surrounding the 1.14-um
613 !C water vapor absorption feature and the center point of the 1.14-um water
614 !C vapor absorption feature. Enter:
615 !C 1. the midpoint of third window (0.6-2.5)
616 !C 2. number of points to average for third window (1-10)
617 !C 3. the midpoint of fourth window (0.6-2.5)
618 !C 4. number of points to average for fourth window (1-10)
619 !C 5. the midpoint of 1.14-um absorption feature (0.6-2.5)
620 !C 6. the number of points to average for the absorption feature (1-30)
621 
622 
623  READ(*,*)wndow3, nb3, wndow4, nb4, w1p14c, nb1p14
624 
625  IF((wndow3.LT.0.6).OR.(wndow3.GT.2.5)) THEN
626  WRITE(*,*)'Invalid wavelength position for first atmospheric window in the 1.14-um region:',wndow3
627  WRITE(*,*)'Valid values are 0.6-2.5'
628  good_data = .false.
629  ENDIF
630 
631  IF((nb3.LT.1).OR.(nb3.GT.50)) THEN
632  WRITE(*,*)'Invalid number of channels for first wavelength position in the 1.14-um region:',nb3
633  WRITE(*,*)'Valid values are 1-50.'
634  good_data = .false.
635  ENDIF
636 
637  IF((wndow4.LT.0.6).OR.(wndow4.GT.2.5)) THEN
638  WRITE(*,*)'Invalid wavelength position for second atmospheric window in the 1.14-um region:',wndow4
639  WRITE(*,*)'Valid values are 0.6-2.5'
640  good_data = .false.
641  ENDIF
642 
643  IF((nb4.LT.1).OR.(nb4.GT.50)) THEN
644  WRITE(*,*)'Invalid number of channels for second wavelength position in the 1.14-um region:',nb4
645  WRITE(*,*)'Valid values are 1-50.'
646  good_data = .false.
647  ENDIF
648 
649  IF((w1p14c.LE.wndow3).OR.(w1p14c.GE.wndow4)) THEN
650  WRITE(*,*)'Invalid water vapor wavelength position for 1.14-um:',w1p14c
651  WRITE(*,*)'Valid range is:',wndow3,' < value <', wndow4,'.'
652  good_data = .false.
653  ENDIF
654 
655  IF((nb1p14.LT.1).OR.(nb1p14.GT.110)) THEN
656  WRITE(*,*)'Invalid number of channels for water vapor wavelength position in the 1.14-um region:',nb1p14
657  WRITE(*,*)'Valid values are 1-110.'
658  good_data = .false.
659  ENDIF
660  ELSE
661 
662 !C Initialize default atmospheric window and water vapor absorption regions
663 !C for 3-channel ratioing calculations.
664  wndow1 = 0.865
665  nb1 = 3
666  wndow2 = 1.030
667  nb2 = 3
668  wp94c = 0.940
669  nbp94 = 5
670  wndow3 = 1.050
671  nb3 = 3
672  wndow4 = 1.235
673  nb4 = 3
674  w1p14c = 1.1375
675  nb1p14 = 7
676  ENDIF
677  ENDIF
678 
679 !C Determine which atmospheric model to use
680 !C 1 = tropical
681 !C 2 = mid latitude summer
682 !C 3 = mid latitude winter
683 !C 4 = subarctic summer
684 !C 5 = subarctic winter
685 !C 6 = US standard 1962
686 !C 7 = user defined model
687  READ(*,*)model
688  IF((model.LT.1).OR.(model.GT.7)) THEN
689  WRITE(*,*)'Invalid atmospheric model value:',model
690  WRITE(*,*)'Valid values are 1-7.'
691  good_data = .false.
692  model = 1 ! init model to a valid value for use below
693  ENDIF
694 
695  IF (model.EQ.7) THEN
696 !C Get file name of atmospheric model information
697  READ(*,101) ftpvmr
698  101 FORMAT(a1000)
699  OPEN(20,file=ftpvmr,status='OLD',iostat=istat)
700  IF(istat.NE.0) THEN
701  WRITE(*,*)'Atmospheric model file did not open successfully:',ftpvmr
702  good_data = .false.
703  ELSE
704 !C Read in number of boundaries, temperature (K), pressure (mb), and water
705 !C vapor volume mixing ratio (VMR, in units of parts per million (ppm)) profiles
706  READ(20,*) nb
707  IF((nb.LE.0).OR.(nb.GT.25)) THEN
708  WRITE(*,*)'Invalid number of boundaries:',nb
709  WRITE(*,*)'Valid values are 1-25.'
710  good_data = .false.
711  ELSE
712  DO 300 i=1,nb
713  READ(20,*) h(i),p(i),t(i),vmr(i)
714  300 CONTINUE
715  CLOSE(20,iostat=istat)
716  ENDIF
717  ENDIF
718  ELSE
719 !C Initialize NB, H, P, T, VMR from predefined atmospheric model array
720  nb = tpvmr(model,1)
721  DO 120 i=1,nb
722  h(i) = tpvmr(model,2+(4*(i-1)))
723  p(i) = tpvmr(model,3+(4*(i-1)))
724  t(i) = tpvmr(model,4+(4*(i-1)))
725  vmr(i) = tpvmr(model,5+(4*(i-1)))
726  120 CONTINUE
727  ENDIF
728  nl=nb-1
729 
730  DO i = nb+1, 25
731  h(i) = 1000.
732  p(i) = 0.0
733  t(i) = 300.
734  vmr(i) = 0.0
735  END DO
736 !
737 !C Determine if various gases should be included in the calculations. Format:
738 !C 1=yes or 0=no. The order should be:
739 !C 1. water vapor
740 !C 2. carbon dioxide
741 !C 3. ozone
742 !C 4. nitrous oxide
743 !C 5. carbon monoxide
744 !C 6. methane
745 !C 7. oxygen
746 !C 8. nitrogen dioxide
747 
748  READ(*,*)ih2ovp, ico2, io3, in2o, ico, ich4, io2, ino2
749  IF((ih2ovp.NE.0).AND.(ih2ovp.NE.1)) THEN
750  WRITE(*,*)'Invalid selection for H2O vapor:',ih2ovp
751  WRITE(*,*)'Valid values: 0=no, 1=yes.'
752  good_data = .false.
753  ENDIF
754 
755  IF((ico2.NE.0).AND.(ico2.NE.1)) THEN
756  WRITE(*,*)'Invalid selection for CO2:',ico2
757  WRITE(*,*)'Valid values: 0=no, 1=yes.'
758  good_data = .false.
759  ENDIF
760 
761  IF((io3.NE.0).AND.(io3.NE.1)) THEN
762  WRITE(*,*)'Invalid selection for O3:',io3
763  WRITE(*,*)'Valid values: 0=no, 1=yes.'
764  good_data = .false.
765  ENDIF
766 
767  IF((in2o.NE.0).AND.(in2o.NE.1)) THEN
768  WRITE(*,*)'Invalid selection for N2O:',in2o
769  WRITE(*,*)'Valid values: 0=no, 1=yes.'
770  good_data = .false.
771  ENDIF
772 
773  IF((ico.NE.0).AND.(ico.NE.1)) THEN
774  WRITE(*,*)'Invalid selection for CO:',ico
775  WRITE(*,*)'Valid values: 0=no, 1=yes.'
776  good_data = .false.
777  ENDIF
778 
779  IF((ich4.NE.0).AND.(ich4.NE.1)) THEN
780  WRITE(*,*)'Invalid selection for CH4:',ich4
781  WRITE(*,*)'Valid values: 0=no, 1=yes.'
782  good_data = .false.
783  ENDIF
784 
785  IF((io2.NE.0).AND.(io2.NE.1)) THEN
786  WRITE(*,*)'Invalid selection for O2:',io2
787  WRITE(*,*)'Valid values: 0=no, 1=yes.'
788  good_data = .false.
789  ENDIF
790 
791  IF((ino2.NE.0).AND.(ino2.NE.1)) THEN
792  WRITE(*,*)'Invalid selection for NO2:',ino2
793  WRITE(*,*)'Valid values: 0=no, 1=yes.'
794  good_data = .false.
795  ENDIF
796 
797 !C Read in the column ozone amount and scaling factor for NO2 column amount.
798 !C The typical ozone amount is: 0.28-0.55 (atm-cm). The built-in NO2
799 !C column amount is 5.0E+15 molecules/cm^2.
800  READ(*,*)vrto3, sno2
801  IF((vrto3.LT.0.1).OR.(vrto3.GT.0.6)) THEN
802  WRITE(*,*)'Invalid vertical column amount of ozone:',vrto3
803  WRITE(*,*)'Valid values are 0.1-0.6.'
804  WRITE(*,*)'Reasonable values are 0.28-0.55.'
805  good_data = .false.
806  ENDIF
807 
808 !C Get aerosol model, visibility, or aerosol optical depth at 0.55 um (TAER55)
809 !C for SSSSS(). If V > 0, no TAER55 is needed in the input file. If V = 0,
810 !C TAER55 is needed.
811 !C IAER: 0=no aerosol, set V = -1
812 !C IAER: 1=continental aerosol, 2=maritime aerosol, 3=urban aerosol, set V>5 km.
813 
814  READ(*,*) iaer,v
815  IF((iaer.LT.0).OR.(iaer.GT.6)) THEN
816  WRITE(*,*)'Invalid aerosol model value:',iaer
817  WRITE(*,*)'Valid values are 0-3.'
818  good_data = .false.
819  ENDIF
820 
821  IF(iaer.EQ.0) THEN
822  v = -1
823  taer55=0.0
824  ELSE
825  IF((v.LT.0).OR.(v.GT.300)) THEN
826  WRITE(*,*)'Invalid visibility value:',v
827  WRITE(*,*)'Value must be greater than 0 and less than 300.'
828  good_data = .false.
829  ENDIF
830  ENDIF
831 
832  IF(v.EQ.0) THEN
833  READ(*,*) taer55
834  IF((taer55.GT.10.).OR.(taer55.LE.0)) THEN
835  WRITE(*,*)'Invalid aerosol optical depth at 550 nm: ',taer55
836  WRITE(*,*)'Valid values are between 0 and 10.'
837  good_data = .false.
838  ENDIF
839  ENDIF
840 
841 !C Get the mean surface elevation. Range: 0.0 - H(NB-1) km
842  READ(*,*)hsurf
843 !C--
844  xpss = hsurf
845 !C--
846  IF((hsurf.LT.0).OR.(hsurf.GT.h(nb-1))) THEN
847  WRITE(*,*)'Invalid surface elevation value:',hsurf
848  WRITE(*,*)'Value must be less than the maximum elevation in the atmospheric model.'
849  good_data = .false.
850  ENDIF
851 
852 !C Test to see if plane altitude is greater than bottom surface elevation
853  IF(xppp .LT. hsurf) THEN
854  WRITE(*,*)'Invalid plane altitude:',xppp
855  WRITE(*,*)'Plane altitude must be greater than the bottom surface elevation.'
856  good_data = .false.
857  ENDIF
858 
859 !C Read in file name of data cube and get data dimensions in DIMS, ST_ORDER
860 !C If no SIPS header on data, then default dimensions are header size = 0,
861 !C number of samples = 614, number of lines = 512, number of bands = 224,
862 !C storage order = BIL
863  READ(*,85) finav
864 !C------ CALL OPENINFILE(IRET,DIMS,ST_ORDER)
865  lun_in = 47
866 ! CALL OPENINFILE(LUN_IN, I_RET)
867 
868 ! IF(I_RET.NE.0) THEN
869 ! WRITE(*,*)'Input image file did not open
870 ! & successfully:',FINAV
871 ! GOOD_DATA = .FALSE.
872 ! ENDIF
873 
874 !C Determine if cube dimensions should be read in. If not, the dimensions
875 !C in the image file header will be used.
876  READ(*,*) ans
877  IF((ans.NE.0).AND.(ans.NE.1)) THEN
878  WRITE(*,*)'Invalid value to indicate whether the cube dimensions should be read:',ans
879  WRITE(*,*)'Valid values: 0=no 1=yes.'
880  good_data = .false.
881  ELSE
882  IF (ans .EQ. 1) THEN
883 !C Read the header size in bytes, samples, lines, bands, and
884 !C storage order (0=BSQ, 1=BIP, 2=BIL)'
885  READ(*,*) hdrec, nsamps, nlines, nbands, sorder
886  IF ((hdrec.LT.0).OR.(nsamps.LE.0).OR. (nlines.LE.0).OR.(nbands.LE.0).OR. &
887  (sorder.LE.0).OR.(sorder.GT.2)) THEN
888  WRITE(*,*)'Invalid cube parameters:',hdrec,nsamps,nlines, &
889  nbands,sorder
890  WRITE(*,*)'Values must be greater than or equal to 1 and the storage order must be less than 3.'
891  WRITE(*,*)'Storage Order (0=BSQ, 1=BIP, 2=BIL)'
892  WRITE(*,*)' 0 = BSQ is not supported in this version of ATREM'
893  good_data = .false.
894  ENDIF
895  ELSE
896  hdrec = dims(1)
897  nsamps = dims(2)
898  nlines = dims(3)
899  nbands = dims(4)
900  sorder = st_order
901  ENDIF
902  ENDIF
903 
904 !C Get the output reflectance cube file name. The output cube always has a 512
905 !C byte header record.
906  READ(*,85) focub
907 !C--- CALL OPENOUTFILE(IRET,512,NSAMPS,NLINES,NBANDS,SORDER)
908  lun_out = 48
909 ! CALL OPENOUTFILE(LUN_OUT, I_RET)
910 
911 ! IF(I_RET.NE.0) THEN
912 ! WRITE(*,*)'Output image file did not open
913 ! & successfully:',FOCUB
914 ! GOOD_DATA = .FALSE.
915 ! ENDIF
916 
917 !C Get the resolution of output spectra. Format: 0-100 nm.
918  READ(*,*)dlt2
919  IF((dlt2.LT.0.).OR.(dlt2.GT.100.)) THEN
920  WRITE(*,*)'Invalid output resolution value:',dlt2
921  WRITE(*,*)'Valid values are 0-100 nm.'
922  good_data = .false.
923  ENDIF
924 
925 !C Get the scaling factor for output reflectance values. Range: 1. to 32000.
926  READ(*,*)scalef
927  IF((scalef.LT.1.).OR.(scalef.GT.32000.)) THEN
928  WRITE(*,*)'Invalid output resolution value:',scalef
929  WRITE(*,*)'Valid values are 1-32000 nm.'
930  good_data = .false.
931  ENDIF
932 
933 !C Get the output water vapor file name. The water vapor output has a 512-byte
934 !C header, is always one band, and is in BSQ format (BSQ=0).
935  READ(*,85) foh2o
936 !C--- CALL OPENVAPFILE(IRET,512,NSAMPS,NLINES,1,0)
937  lun_vap = 49
938 ! CALL OPENVAPFILE(LUN_VAP, I_RET)
939 
940 ! IF(I_RET.NE.0) THEN
941 ! WRITE(*,*)'Output water vapor file did not open
942 ! & successfully:',FOH2O
943 ! GOOD_DATA = .FALSE.
944 ! ENDIF
945 
946 !C Get the file name for output table consisting of atmospheric
947 !C transmission spectra at the solar and observational geometry but
948 !C with varying amounts of water vapor.
949 
950 !COMMENTED out RJH
951 ! READ(*,85) FOUT1
952 ! OPEN(35,FILE=FOUT1,STATUS='UNKNOWN',IOSTAT=ISTAT)
953 ! IF(ISTAT.NE.0) THEN
954 ! WRITE(*,*)'Output file did not open successfully:',FOUT1
955 ! GOOD_DATA = .FALSE.
956 ! ENDIF
957 !
958 ! IF(GOOD_DATA .NEQV. .TRUE.) THEN
959 ! WRITE(*,*)'**** ERROR: Invalid input detected. ****'
960 ! STOP
961 ! ENDIF
962 
963 !C--D WRITE(*,*)'IH2OVP=',IH2OVP,' ICO2=',ICO2,' IO3=',IO3,' IN2O=',IN2O
964 !C--D WRITE(*,*)'ICO=',ICO,' ICH4=',ICH4,' IO2=',IO2
965 !C--D WRITE(*,*)'H T P VMR'
966 !C--D DO 998 I=1,25
967 !C--D 998 WRITE(*,*)H(I),' ',T(I),' ',P(I),' ',VMR(I)
968 !C--D WRITE(*,*)'NB=',NB,' NL=',NL,' MODEL=',MODEL
969 !C--D WRITE(*,*)' IAER=',IAER,' V=',V,' VRTO3=',VRTO3
970 !C--D DO 997 I=1,NOBS
971 !C--D 997 WRITE(*,*)'I=',I,' WAVOBS(I)=',WAVOBS(I),' FWHM(I)=',FWHM(I)
972 !C--D WRITE(*,*)'NOBS=',NOBS,' HSURF=',HSURF,' DLT=',DLT,' DLT2=',DLT2
973 !C--D WRITE(*,*)'SCALEF=',SCALEF
974 !C--D WRITE(*,*)'WNDOW1=',WNDOW1,' WNDOW2=',WNDOW2,' WP94C=',WP94C
975 !C--D WRITE(*,*)'WNDOW3=',WNDOW3,' WNDOW4=',WNDOW4,' W1P14C=',W1P14C
976 !C--D WRITE(*,*)'NB1=',NB1,' NB2=',NB2,' NBP94=',NBP94
977 !C--D WRITE(*,*)'NB3=',NB3,' NB4=',NB4,' NB1P14=',NB1P14
978 !C--D WRITE(*,*)'IMN=',IMN,' IDY=',IDY,' IYR=',IYR
979 !C--D WRITE(*,*)'IH=',IH,' IM=',IM,' IS=',IS
980 !C--D WRITE(*,*)'XLATD=',XLATD,' XLATM=',XLATM,' XLATS=',XLATS
981 !C--D WRITE(*,147)LATHEM
982 !C--D 147 FORMAT('LATHEM=',A1)
983 !C--D WRITE(*,*)'XLONGD=',XLONGD,' XLONGM=',XLONGM,' XLONGS=',XLONGS
984 !C--D WRITE(*,148)LNGHEM
985 !C--D 148 FORMAT('LNGHEM=',A1)
986 !C--D WRITE(*,*)'HDREC=',HDREC,' NSAMPS=',NSAMPS,' NLINES=',NLINES
987 !C--D WRITE(*,*)'NBANDS=',NBANDS,' SORDER=',SORDER
988 
989  RETURN
990  END
991 
992 !********************************************************************************
993 !* *
994 !* Name: MODEL_ADJ *
995 !* Purpose: resets the bottom boundary of the input model if the surface *
996 !* elevation is greater than 0, and calculate the column water vapor *
997 !* amount in the selected model. *
998 !* Parameters: none *
999 !* Algorithm: If the surface elevation > 0, the bottom layer temperature and *
1000 !* water vapor volume mixing ratio are obtained through linear *
1001 !* interpolation, while the bottom layer pressure is obtained *
1002 !* through exponential interpolation. *
1003 !* Globals used: H, T, P, VMR, NB, NL, HSURF - these values are adjusted if *
1004 !* HSURF > 0 *
1005 !* Global output: CLMVAP - Column water vapor amount in unit of cm. *
1006 !* Q - Number of molecules above the surface at one *
1007 !* atmosphere in units of molecules/cm**2 *
1008 !* Return Codes: none *
1009 !* Special Considerations: none *
1010 !* *
1011 !********************************************************************************
1012  SUBROUTINE model_adj
1014  include 'COMMONS_INC.f'
1015 
1016 !C Common variables
1017  dimension h(25), t(25), p(25), vmr(25)
1018 
1019  COMMON /getinput3/ h,t,p,vmr,nb,nl,model,iaer,v,taer55,vrto3,sno2
1020  COMMON /getinput5/ nobs,hsurf,dlt,dlt2
1021  COMMON /model_adj1/ clmvap,q
1022 
1023  dimension hp(25), tp(25), pp(25), vmrp(25)
1024  COMMON /model_adj2/ hp, tp, pp, vmrp
1025  COMMON /model_adj3/ k_plane, dvap_plane, dvap_layer, &
1026  dp_plane, dp_layer, clmvapp
1027  COMMON /model_adj4/ k_surf
1028 
1029  REAL XPSS, XPPP
1030  COMMON /getinput14/ xpss, xppp
1031 
1032 !C H = Layer boundary height, SL=Slant path length, DSLODH=DSL/DH
1033 
1034  re=6380.0
1035 !C Q=# of molecules above the surface at one atmosphere (molecules/cm**2)
1036  q=2.152e25
1037 
1038 !C-- print*, 'original model atmosphere ...'
1039 !C-- DO I = 1, 25
1040 !C-- print*, 'H,T,P,VMR = ', H(I), T(I), P(I), VMR(I)
1041 !C-- END DO
1042 
1043 !C--- Convert the atmospheric pressure from "mb" to "atm.":
1044  DO i = 1, nb
1045  p(i) = p(i) / 1013.
1046  END DO
1047 !C--- End of conversion
1048 
1049 !C Convert the VMR from the ppm unit in the model to absolute unit.
1050  DO 310 i=1,nb
1051  310 vmr(i)=vmr(i)*1.0e-06
1052 
1053 !C Do special processing if surface altitude is greater than 0
1054 !C--- IF(HSURF.NE.0.0) THEN
1055 !C Reset H(I) to a smaller value if HSURF.EQ.H(I) to avoid possible
1056 !C problems in table searching using LOCATE
1057  DO 7455 i=1,nb
1058  7455 IF(hsurf.EQ.h(i)) hsurf=h(i)+0.0001
1059 
1060 !C Determine index of H() such that H(index) < HSURF < H(index+1)
1061  CALL locate(h,nb,hsurf,k)
1062 !C
1063 !C K_SURF is an index relative to the original model atmosphere (0 - 100 km)
1064  k_surf = k
1065 !C--- print*, 'K_SURF = ', K_SURF
1066 !C
1067  IF(k.EQ.0) THEN
1068  WRITE(6,5237)
1069  5237 FORMAT(2x,'***WARNING: Surface elevation smaller then lowest boundary of the model atmosphere.')
1070 
1071  k_surf = 1
1072  GOTO 5255
1073  ENDIF
1074 
1075  IF(k.GT.0) THEN
1076  dhk=h(k+1)-h(k)
1077  dhs=hsurf -h(k)
1078 
1079 !C linear interpolation for surface temperature (TSURF) and VMR ( VMRS)
1080  tsurf=t(k)+(dhs/dhk)*(t(k+1)-t(k))
1081  vmrs =vmr(k)+(dhs/dhk)*(vmr(k+1)-vmr(k))
1082 
1083 !C exponential interpolation for surface pressure (PSURF)
1084  psurf=p(k)*exp(-alog(p(k)/p(k+1))*dhs/dhk)
1085  h(1)=hsurf
1086  p(1)=psurf
1087  t(1)=tsurf
1088  vmr(1)=vmrs
1089 
1090  nb=nb-k+1
1091  nl=nb-1
1092 !C--- print*,'NL = ', NL, ' NB = ', NB, 'in Model_Adj'
1093 !C
1094  DO 5240 i=2,nb
1095  h(i)=h(i+k-1)
1096  p(i)=p(i+k-1)
1097  t(i)=t(i+k-1)
1098  vmr(i)=vmr(i+k-1)
1099  5240 CONTINUE
1100 !C Zero out pressures and VMRS of top atmospheric layers.
1101  DO 5245 i=nb+1,25
1102  h(i)=1000.
1103  p(i)=0.0
1104  t(i)=300.
1105  vmr(i)=0.0
1106  5245 CONTINUE
1107  ENDIF
1108 !C--- ENDIF
1109 
1110  5255 CONTINUE
1111 
1112  amtvrt=0.0
1113 
1114  DO 350 i=1,nl
1115  damtvt=q*(p(i)-p(i+1))*(vmr(i)+vmr(i+1))/2.0
1116  amtvrt=amtvrt+damtvt
1117  350 CONTINUE
1118 
1119  clmvap=amtvrt/3.34e+22
1120 
1121  WRITE(*,*)'Column vapor amount in model atmosphere from ground'
1122  WRITE(*,*)' to space = ', clmvap, ' cm'
1123 
1124 !C--- WRITE(*,*)'In MODEL_ADJ, NB = ',NB,' NL = ',NL
1125 !C--- print*, 'After adjusting for elevated surface ...'
1126 !C--- DO I = 1, 25
1127 !C--- print*, 'H,T,P,VMR = ', H(I), T(I), P(I), VMR(I)
1128 !C--- END DO
1129 !
1130 !C
1131 !C
1132 !C Setting the upward atmospheric path's T, P, and VMR profiles:
1133 !C
1134 !C 1st duplicate the entire atmospheric profiles from the downward path
1135 !C to the upward path
1136 !C
1137  DO i = 1, 25
1138  hp(i) = h(i)
1139  tp(i) = t(i)
1140  pp(i) = p(i)
1141  vmrp(i) = vmr(i)
1142  END DO
1143 
1144 
1145  hplane = xppp
1146 !C Set the highest plane altitude to the upper bound of model atmosphere
1147 !C--- IF(HPLANE.GT.100.0) HPLANE = 100. - 0.0001
1148  IF(hplane.GE.100.0) hplane = 100. - 0.0001
1149 !C
1150 !C Do special processing if the plane height (HPLANE) is greater than HP(1)
1151  IF(hplane.GT.hp(1)) THEN
1152 !C Reset Plane altitude HPLANE (= XPPP) to a larger value if
1153 !C HPLANE.EQ.HP(I) to avoid possible problems in table
1154 !C searching using LOCATE
1155  DO 7456 i=1,25
1156  7456 IF(hplane.EQ.hp(i)) hplane=hp(i)-0.0001
1157 
1158 !C Determine index of HP() such that HP(index) < HPLANE < H(index+1)
1159  CALL locate(hp,nb,hplane,kk)
1160 
1161  IF(kk.EQ.0) THEN
1162  WRITE(6,5239)
1163  5239 FORMAT(2x,'***WARNING: Plane altitude less then lowest boundary of the model atmosphere.')
1164  GOTO 5256
1165  ENDIF
1166 
1167  IF(kk.GT.0) THEN
1168  dhkk = hp(kk+1) - hp(kk)
1169  dhss = hplane - hp(kk)
1170 
1171 !C linear interpolation for plane temperature (TPLANE) and VMR ( VMRSP)
1172  tplane = tp(kk) + (dhss/dhkk)*(tp(kk+1)-tp(kk))
1173  vmrsp = vmrp(kk) + (dhss/dhkk)*(vmrp(kk+1)-vmrp(kk))
1174 
1175 !C exponential interpolation for plane pressure (PPLANE)
1176  pplane = pp(kk)*exp(-alog(pp(kk)/pp(kk+1))*dhss/dhkk)
1177  hp(kk+1) = hplane
1178  pp(kk+1) = pplane
1179  tp(kk+1) = tplane
1180  vmrp(kk+1) = vmrsp
1181 
1182 !C Zero out pressures and VMRP of top atmospheric layers.
1183  IF(kk.LT.24) THEN
1184  DO i=kk+2,25
1185  hp(i)=1000.
1186  pp(i)=0.0
1187  tp(i)=300.
1188  vmrp(i)=0.0
1189  END DO
1190  END IF
1191 
1192  ENDIF
1193  ENDIF
1194 
1195  5256 CONTINUE
1196 
1197  amtvrtp=0.0
1198 
1199  DO 357 i=1,kk
1200  damtvtp=q*(pp(i)-pp(i+1))*(vmrp(i)+vmrp(i+1))/2.0
1201  amtvrtp=amtvrtp+damtvtp
1202  357 CONTINUE
1203 
1204  clmvapp=amtvrtp/3.34e+22
1205 
1206  WRITE(*,*)'Column vapor below plane (CLMVAPP) = ', &
1207  clmvapp, ' cm'
1208 
1209 !C--- WRITE(*,*)'In MODEL_ADJ, NB = ',NB,' KK = ', KK
1210 !C--- print*, 'After further adjusting for plane height ...'
1211 !C--- DO I = 1, 25
1212 !C--- print*, 'HP,TP,PP,VMRP = ', HP(I), TP(I), PP(I), VMRP(I)
1213 !C--- END DO
1214 
1215 !C--- Indices and parameters for the plane layer
1216  k_plane = kk
1217 
1218  dvap_plane = q*(pp(k_plane) - pp(k_plane+1))* &
1219  (vmrp(k_plane) + vmrp(k_plane+1))/2.0 / 3.34e+22
1220 
1221  dvap_layer = q*(p(k_plane) - p(k_plane+1))* &
1222  (vmr(k_plane) + vmr(k_plane+1))/2.0 / 3.34e+22
1223 
1224  dp_plane = pp(k_plane) - pp(k_plane+1)
1225  dp_layer = p(k_plane) - p(k_plane+1)
1226 
1227 !C--- print*, 'K_PLANE, DVAP_PLANE, DVAP_LAYER = ',
1228 !C--- & K_PLANE, DVAP_PLANE, DVAP_LAYER
1229 !C--- print*, 'DP_PLANE, DP_LAYER = ', DP_PLANE, DP_LAYER
1230 
1231 
1232  RETURN
1233  END
1234 !********************************************************************************
1235 !* *
1236 !* Name: GEOMETRY *
1237 !* Purpose: Calculates the solar and the observational geometric factors. *
1238 !* Parameters: none *
1239 !* Algorithm: The solar geometry was obtained based on the latitude, longitude,*
1240 !* GMT time using programs written by W. Mankin at National Center *
1241 !* for Atmospheric Research in Boulder, Colorado. The *
1242 !* geometric factors for CO2, O3, N2O, CO, CH4, and O2 are based *
1243 !* only on the solar and observational angles. Sixty artificial *
1244 !* geometric factors for H2O are set up to produce a transmittance *
1245 !* table for different atmospheric water vapor amounts. *
1246 !* Globals used: VRTO3 - Column O3 amount in units of atm-cm *
1247 !* IMN,IDY,IYR,IH,IM,IS - time and date of data measurements *
1248 !* XLATD,XLATM,XLATS,LATHEM - Latitude of measured area *
1249 !* XLONGD,XLONGM,XLONGS,LNGHEM - Longitude of measured area *
1250 !* CLMVAP - Column water vapor in unit of cm in the model atmosphere *
1251 !* Global output: *
1252 !* SOLZNI,SOLAZ,OBSZNI,OBSPHI,IDAY - Solar zenith angle, solar azimuth *
1253 !* angle, observational zenith angle, observational azimuth angle, *
1254 !* and the day number in the year *
1255 !* GCO2,GO3,GN2O,GCO,GCH4,GO2,SSH2O,GGEOM,TOTLO3 - Geometric factors for *
1256 !* different gases, and total O3 amount in the sun-surface ray path. *
1257 !* The geometric factor is defined as: if the vertical column amount *
1258 !* of the gas is equal 1, then GGAS is equal to the total amount of *
1259 !* the gas in the combined Sun-surface-sensor ray path. *
1260 !* Return Codes: none *
1261 !* Special Considerations: none *
1262 !* *
1263 !********************************************************************************
1264 
1265  SUBROUTINE geometry
1266 
1267  include 'COMMONS_INC.f'
1268 
1269  dimension vapvrt(60), vap_slant(60)
1270  dimension md(12)
1271  dimension ssh2o(60)
1272  dimension h(25), t(25), p(25), vmr(25)
1273  CHARACTER*1 LATHEM,LNGHEM
1274 
1275 !C The VAPVRT array contains 60 column water vapor values used for generating
1276 !C a table of transmittance spectra with different amount of water vapor.
1277 !C The values in VAPVRT is designed so that there is approximately 2% change
1278 !C in the .94-um H2O channel ratio for column water vapor in the range .4-6 cm.
1279 
1280  DATA vapvrt/.00, .02, .06, .11, .16, .21, .26, .31, .36, .40, &
1281  .43, .46, .50, .54, .58, .62, .66, .70, .75, .80, &
1282  .86, .92, .98, 1.06,1.14, 1.22, 1.3, 1.4, 1.5, 1.6, &
1283  1.7, 1.8, 1.9, 2.05, 2.2, 2.35, 2.55, 2.75, 2.95, 3.2, &
1284  3.5, 3.8, 4.1, 4.4, 4.7, 5.0, 5.3, 5.6, 6.0, 6.4, &
1285  7.0, 7.7, 8.5, 9.4,10.4, 11.6, 13.0, 15.0, 25.0, 50./
1286 
1287  DATA md/0,31,59,90,120,151,181,212,243,273,304,334/
1288 
1289  COMMON /getinput3/ h,t,p,vmr,nb,nl,model,iaer,v,taer55,vrto3,sno2
1290 
1291  COMMON /getinput8/ imn,idy,iyr,ih,im,is
1292  COMMON /getinput9/ xlatd,xlatm,xlats,lathem
1293  COMMON /getinput10/xlongd,xlongm,xlongs,lnghem
1294  COMMON /model_adj1/ clmvap,q
1295  COMMON /geometry1/ solzni,solaz,obszni,obsphi,iday
1296  COMMON /geometry2/ gco2,go3,gn2o,gco,gch4,go2,ssh2o,totlo3,ggeom
1297 
1298  COMMON /model_adj3/ k_plane, dvap_plane, dvap_layer, &
1299  dp_plane, dp_layer, clmvapp
1300 
1301  dimension g_vap(25), g_other(25)
1302  COMMON /geometry3/ g_vap, g_other, g_vap_equiv, vap_slant_mdl
1303 
1304  REAL XPSS, XPPP
1305  COMMON /getinput14/ xpss, xppp
1306 
1307  REAL XVIEWD, XVIEWM, XVIEWS
1308  REAL XAZMUD, XAZMUM, XAZMUS
1309  COMMON /getinput15/ xviewd,xviewm,xviews, xazmud,xazmum,xazmus
1310 
1311  hplane = xppp
1312 !C
1313 !C VAP_SLANT is a new array for containing two-way total vapor amounts
1314 !C Here the number "2" can be changed to other numbers, e.g., 2.5,
1315 !C without any major effects in derived water vapor values from
1316 !C imaging spectrometer data.
1317 !C
1318 
1319  DO i = 1, 60
1320  vap_slant(i) = vapvrt(i) * 2.0
1321  END DO
1322 
1323  xh=ih
1324  xm=im
1325  xs=is
1326  tt=6.28318*((xh)/24+xm/1440+xs/86400)
1327 
1328  xlat = xlatd + xlatm/60.0 + xlats/3600.0
1329  xlong = xlongd + xlongm/60.0 + xlongs/3600.0
1330 
1331 !C northern hemisphere is positive, and western hemisphere is positive
1332 !C (NOTE: this is not standard, but has been internally coded in this program)
1333  IF(lathem.NE.'N') xlat = -xlat
1334  IF(lnghem.NE.'W') xlong = -xlong
1335 
1336 325 xlatr = xlat/57.2958
1337  xlongr = xlong/57.2958
1338 
1339  CALL suncor(idy,imn,iyr,tt,dec,haz)
1340  CALL hazel(haz+tt-xlongr,dec,solaz,el,xlatr)
1341 !C---Note: DEC, SOLAZ,and EL DEC are in radiant units
1342 
1343  IF (el .LE. 0.) THEN
1344  WRITE(*,*)'ERROR: Sun is below the horizon!!!'
1345  WRITE(*,*)'Check input date, time, latitude and longitude.'
1346  stop
1347  ENDIF
1348 
1349 !C converting observational zenith angle and relative azimuth angle into degrees
1350  obszni = xviewd + xviewm/60.0 + xviews/3600.0
1351  obsphi = xazmud + xazmum/60.0 + xazmus/3600.0
1352 
1353  write(91,*) 'OBSZNI = ',obszni, ' OBSPHI = ',obsphi, ' degrees'
1354 
1355  obszni = obszni / 57.2958
1356  obsphi = obsphi / 57.2958
1357 
1358  solzni = 90.0/57.2958 - el
1359 
1360  write(91,*) 'solzni=',solzni
1361  write(91,*) 'KPLANE=',k_plane
1362 
1363  ggeom = 1./cos(solzni) + 1./cos(obszni)
1364 
1365  gco2 = ggeom
1366 
1367  go3 = ggeom
1368  IF(hplane.LT.27.) go3 = ggeom - 1./cos(obszni)
1369 
1370  gn2o = ggeom
1371  gco = ggeom
1372  gch4 = ggeom
1373  go2 = ggeom
1374 
1375  write(91,*) 'GGEOM, GCO2, GO3, GN2O, GCO, GCH4, GO2 = '
1376  write(91,*) ggeom, gco2, go3, gn2o, gco, gch4, go2
1377 
1378  totlo3 = go3 * vrto3
1379 
1380  WRITE(91,*) 'TOTLO3 = ', totlo3
1381 
1382 !C Initialize newly created geometrical factors for each atmospheric
1383 !C layers (here G_VAP and G_OTHER are true geometrical factors that
1384 !C account for the actual Sun-surface-plane path lengths in the
1385 !C model atmosphere):
1386 !C
1387 !C---For layers below the plane layer---
1388  DO i = 1, k_plane - 1
1389  g_vap(i) = ggeom
1390  g_other(i) = ggeom
1391  END DO
1392 !C
1393 !C---For layers above the plane layer
1394  DO i = k_plane + 1, 25
1395  g_vap(i) = ggeom - 1./cos(obszni)
1396  g_other(i) = ggeom - 1./cos(obszni)
1397  END DO
1398 !C
1399 !C---Special treatment for the plane layer to take account the
1400 !C "shorter" upward path length
1401  g_vap(k_plane) = ggeom - 1./cos(obszni) &
1402  + dvap_plane/dvap_layer/cos(obszni)
1403  g_other(k_plane) = ggeom - 1./cos(obszni) &
1404  + dp_plane/dp_layer/cos(obszni)
1405 
1406  write(91,*) ' G_VAP, G_OTHER, I ='
1407  DO i = 1, 25
1408  write(91,*) g_vap(i), g_other(i), i
1409  END DO
1410 
1411 !C Calculate the water vapor SCALING factor relative to the total amount
1412 !C of water vapor in the model atmosphere in the L-shaped
1413 !C Sun-surface-plane ray path.
1414 !C
1415  vap_slant_mdl = clmvap/cos(solzni) + clmvapp/cos(obszni)
1416  write(91,*) 'VAP_SLANT_MDL =', vap_slant_mdl, ' cm'
1417 !C
1418 !C The "equivalent" geometrical factor corresponding to the total
1419 !C slant vapor amount of VAP_SLANT_MDL':
1420 !C
1421  g_vap_equiv = vap_slant_mdl / clmvap
1422  write(91,*) 'G_VAP_EQUIV = ', g_vap_equiv
1423 
1424  DO 310 i=1,60
1425  ssh2o(i) = vap_slant(i) / vap_slant_mdl
1426  write(91,*) 'SSH2O(I), I = ', ssh2o(i), i
1427  310 CONTINUE
1428 
1429 !C Calculate the number of days that have passed in this year. Take leap year
1430 !C into account.
1431  iday = md(imn) + idy
1432  lpyr = iyr - (4 * (iyr/4))
1433  IF((lpyr.EQ.0).AND.(iday.GT.59).AND.(imn.NE.2)) iday = iday + 1
1434 
1435 !C--D WRITE(*,*)'SOLZNI=',SOLZNI,' SOLAZ=',SOLAZ,' OBSZNI=',OBSZNI
1436 !C--D WRITE(*,*)'OBSPHI=',OBSPHI,' IDAY = ',IDAY
1437 !C--D WRITE(*,*)'GCO2=',GCO2,' GO3=',GO3,' GN2O=',GN2O,' GCO=',GCO
1438 !C--D WRITE(*,*)'GCH4=',GCH4,' GO2=',GO2,' TOTLO3=',TOTLO3
1439 !C--D WRITE(*,*)'GGEOM=',GGEOM
1440 !C--D DO 311 I=1,60
1441 !C--D 311 WRITE(*,*)'I=',I,' SSH2O(I)',SSH2O(I)
1442 
1443  RETURN
1444  END
1445 
1446 !********************************************************************************
1447 !* *
1448 !* Name: INIT_SPECCAL *
1449 !* Purpose: initialize global data for spectrum calculations. *
1450 !* Parameters: none *
1451 !* Algorithm: initialize data. *
1452 !* Globals used: AH2O, APH2O, BH2O, BPH2O, SODLT, SOGAM, O3CF - Band model *
1453 !* parameters for spectral calculations. *
1454 !* WNDOW1, WNDOW2, WP94C, WNDOW3, WNDOW4, W1P14C - Center *
1455 !* positions of window and water vapor absorption *
1456 !* channels used in 3-channel ratio calculations. *
1457 !* NB1, NB2, NBP94, NB3, NB4, NB1P14 - Number of narrow channels *
1458 !* to form broader window and absorption channels. *
1459 !* Global output: *
1460 !* IH2OLQ,RLQAMT,NGASTT,NH2O,VSTART,VEND - Flag for including liquid *
1461 !* water, liquid water amount (cm), total number of gases *
1462 !* (typically 8), number of water vapor values, starting *
1463 !* and ending wavelengths in internal calculations. *
1464 !* NO3PT,NCV,NCVHAF,NCVTOT,VMIN,ISTART,IEND - Number of O3 abs. coef. *
1465 !* points, parameters for gaussian function and spectral *
1466 !* calculations. *
1467 !* ISTCAL,IEDCAL,DP,PM,TM,VMRM - Parameters for spectral calculations *
1468 !* IST1,IED1,IST2,IED2,ISTP94,IEDP94 - 3-channel ratioing parameters for *
1469 !* the 0.94-um water vapor band. *
1470 !* IST3,IED3,IST4,IED4,IST1P14,IED1P14 - 3-channel ratioing parameters for *
1471 !* the 1.14-um water vapor band. *
1472 !* WT1,WT2,WT3,WT4,JA - Relative weights for the four window channels *
1473 !* used in channel-ratioing calculations. JA is a *
1474 !* output parameter from a table searching routine. *
1475 !* NCV2,NCVHF2,NCVTT2,ISTRT2,IEND2,FINST2 - Parameters for smoothing *
1476 !* output reflectance spectra. *
1477 !* NATOT,NBTOT,NCTOT,NDTOT - Number of channels for the four AVIRIS' *
1478 !* grating spectrometers (A, B, C, and D). *
1479 !* Return Codes: None. *
1480 !* Special Considerations: Some parameters may need to be fine-tuned. *
1481 !* *
1482 !********************************************************************************
1483 !* Notes about water vapor VMRS and related quantities: *
1484 !* *
1485 !* VAPVRT(60) - a table containing 60 column vapor values (in unit of cm) *
1486 !* *
1487 !* VAP_SLANT(I) = VAPVRT(I) * 2.0, VAP_SLANT is a new table for containing *
1488 !* two-way total vapor amounts. Here the number "2" can be *
1489 !* changed to other numbers, e.g., 2.5, without major *
1490 !* effects on retrieved water vapor values. *
1491 !* *
1492 !* G_VAP(I = 1,..., NL) = true vapor geometric factor for each layer in *
1493 !* the model atmosphere (after adjusting for the elevated *
1494 !* surface. *
1495 !* *
1496 !* VMRM(I) = VMRM(I)*G_VAP(I). The VMRS are multiplied by the geometrical *
1497 !* factor. We can calculate the vapor transmittance on the *
1498 !* Sun-surface-sensor path by assuming a vertical path in *
1499 !* the model atmosphere with geometric-factor-adjusted VMRS. *
1500 !* *
1501 !* CLMVAP = vertical column amount from ground to space in model atmosphere*
1502 !* CLMVAPP = vertical column amount from ground to aircraft or satellite *
1503 !* sensor in model atmosphere *
1504 !* Q = 2.152E25 = # of molecules above the surface at one atmosphere *
1505 !* (in unit of molecules/cm**2) *
1506 !* *
1507 !* VAP_SLANT_MDL= CLMVAP/COS(SOLZNI) + CLMVAPP/COS(OBSZNI) = total amount *
1508 !* of water vapor in the model atmosphere in the L-shaped *
1509 !* Sun-surface-plane ray path. *
1510 !* *
1511 !* G_VAP_EQUIV = VAP_SLANT_MDL / CLMVAP = the "equivalent" geometrical *
1512 !* factor corresponding to the total slant vapor amount *
1513 !* VAP_SLANT_MDL and the column vapor amount CLMVAP. *
1514 !* *
1515 !* SSH2O(I) (I = 1, ..., 60) - a pure scaling factor relative to the total *
1516 !* slant vapor amount of VAP_SLANT_MDL, and *
1517 !* SSH2O(I) = VAP_SLANT(I) / VAP_SLANT_MDL *
1518 !* *
1519 !* SH2O = one value of SSH2O(I). SH2O is used during generation of the *
1520 !* look-up table. *
1521 !* *
1522 !* VAPTT = VAP_SLANT_MDL*SH2O, is the absolute total vapor amount on the *
1523 !* L-shaped path corresponding to a spectrum stored in the *
1524 !* look-up table. *
1525 !* *
1526 !* CLMWVP = 0.5*(VAPTTA+VAPTTB)/G_VAP_EQUIV, is the retrieved column water *
1527 !* vapor amount from imaging spectrometer data. *
1528 !********************************************************************************
1529  SUBROUTINE init_speccal
1531  include 'COMMONS_INC.f'
1532 
1533 !C Common variables
1534  dimension h(25), t(25), p(25), vmr(25)
1535  dimension ssh2o(60)
1536  dimension wavobs(1024),fwhm(1024)
1537  dimension dp(25), pm(25), tm(25), vmrm(25)
1538  dimension finst2(100)
1539 
1540 !C Local variables
1541 
1542  COMMON /getinput1/ ih2ovp,ico2,io3,in2o,ico,ich4,io2,ino2
1543  COMMON /getinput3/ h,t,p,vmr,nb,nl,model,iaer,v,taer55,vrto3,sno2
1544  COMMON /getinput4/ wavobs,fwhm
1545  COMMON /getinput5/ nobs,hsurf,dlt,dlt2
1546  COMMON /getinput6/ wndow1,wndow2,wp94c,wndow3,wndow4,w1p14c
1547  COMMON /getinput7/ nb1,nb2,nbp94,nb3,nb4,nb1p14
1548  COMMON /geometry2/ gco2,go3,gn2o,gco,gch4,go2,ssh2o,totlo3,ggeom
1549  COMMON /model_adj1/ clmvap,q
1550 
1551  COMMON /init_speccal3/ nh2o
1552  COMMON /init_speccal5/ dp,pm,tm,vmrm
1553  COMMON /init_speccal6/ ist1,ied1,ist2,ied2,istp94,iedp94
1554  COMMON /init_speccal7/ ist3,ied3,ist4,ied4,ist1p14,ied1p14
1555  COMMON /init_speccal8/ wt1,wt2,wt3,wt4,ja
1556 
1557  COMMON /init_speccal10/ ncv2,ncvhf2,ncvtt2,istrt2,iend2,finst2
1558  COMMON /init_speccal11/ natot,nbtot,nctot,ndtot
1559 
1560  dimension g_vap(25), g_other(25)
1561  COMMON /geometry3/ g_vap, g_other, g_vap_equiv, vap_slant_mdl
1562 
1563  dimension o3cf(5001)
1564  COMMON /o3cf_init1/ o3cf
1565 
1566  dimension tran_o3_std(5001)
1567  COMMON /init_speccal16/ tran_o3_std
1568 
1569  dimension rno2cf(5001)
1570  COMMON /no2cf_init1/ rno2cf
1571 
1572  dimension tran_no2_std(5001)
1573  COMMON /init_speccal17/ tran_no2_std
1574 
1575  COMMON /model_adj4/ k_surf
1576  INTEGER start(2)/1,1/
1577  INTEGER cnt(2)/NP_HI,19/
1578 
1579 
1580  nh2o = 60 !Number of column water vapor values
1581 !C
1582 !C Initialization for high resolution spectral calculations -
1583 !C First initialize arrays to smooth high resolution spectra (0.05 cm-1) to
1584 !C medium resolution spectra (0.2 nm):
1585 !C
1586 !C*** Note: The array WAVNO_HI is not used in actual computing, the array
1587 !C* should be removed from COMMONS_INC and the following DO LOOP
1588 !C* of this program, the purpose of keeping WAVNO_HI now is to
1589 !C* check array indices and make sure the correctness of the
1590 !C* indices ****************************************************
1591  DO i = 1, np_hi
1592  wavno_hi(i) = 3000. + float(i-1)*dwavno ! Wavenumber (cm-1)of high
1593  ! resolution spectrum,
1594  tran_hi(i) = 1.0 ! 3000 - 18000 cm-1
1595  END DO
1596 !C--- print*,'WAVNO_HI ,1, 10000,NP_HI = ',WAVNO_HI(1),
1597 !C--- & WAVNO_HI(10000), WAVNO_HI(NP_HI)
1598 !C
1599 !C
1600  DO i = 1, np_med
1601  wavln_med(i) = vstart + float(i-1)*dwavln ! Wavelength of medium
1602  ! resolution spectrum,
1603  tran_med(i) = 1.0 ! FWHM=.2 nm, .56-3.1 um.
1604  END DO
1605 !C-----
1606 !C--- print*,'WAVLN_MED ,1, 10000,NP_MED = ',WAVLN_MED(1),
1607 !C--- & WAVLN_MED(10000), WAVLN_MED(NP_MED)
1608 !C-----
1609 !C
1610 !C NOTE: WAVLN_STD starts from 0.3 um, instead of 0.56 um
1611  DO i = 1, np_std
1612  wavln_std(i) = 0.3 + float(i-1)*dwavln ! Wavelength of medium
1613  ! resolution spectrum,
1614  tran_std(i) = 1.0 ! FWHM=.2 nm, .3-3.1 um.
1615  END DO
1616 !C-----
1617 !C--- print*,'WAVLN_STD ,1, 10000,NP_STD = ',WAVLN_STD(1),
1618 !C--- & WAVLN_STD(10000), WAVLN_STD(NP_STD)
1619 !C-----
1620 !C
1621 !C Note: The grids of WAVNO_HI do not match the grids of 10000./WAVLN_MED.
1622 !C INDEX_MED is a specially designed index for finding close matches
1623 !C between the two kinds of grids.
1624 !C
1625  DO i = 1, np_med
1626  index_med(i) = ( (10000./wavln_med(i) - 3000.)/dwavno + 1.)
1627  END DO
1628 !C-----
1629 !C--- print*,'INDEX_MED ,1, 10000,NP_MED = ',INDEX_MED(1),
1630 !C--- & INDEX_MED(10000), INDEX_MED(NP_MED)
1631 !C-----
1632 !C
1633 !C Note: WAVLN_MED_INDEX(I) is very close to WAVLN_MED(I),
1634 !C and WAVLN_MED_INDEX(I) >= WAVLN_MED(I)
1635 !C
1636  DO i = 1, np_med
1637  wavln_med_index(i) = 10000. /(float(index_med(i)-1)*dwavno &
1638  + 3000.)
1639  END DO
1640 !C-----
1641 !C--- print*,'WAVLN_MED_INDEX ,1, 10000,NP_MED = ',WAVLN_MED_INDEX(1),
1642 !C--- & WAVLN_MED_INDEX(10000), WAVLN_MED_INDEX(NP_MED)
1643 !C-----
1644 
1645 
1646  DO i = 1, np_med
1647  fwhm_wavno(i) = 10000.*dlt_med &
1648  /(wavln_med_index(i)*wavln_med_index(i))
1649  END DO
1650 !C-----
1651 !C--- print*,'FWHM_WAVNO ,1, 10000,NP_MED = ',FWHM_WAVNO(1),
1652 !C--- & FWHM_WAVNO(10000), FWHM_WAVNO(NP_MED)
1653 !C-----
1654 !C
1655 
1656  DO i = 1, np_med
1657  ncvhf_wavno(i) = ( facdlt * fwhm_wavno(i) / dwavno + 1.)
1658  END DO
1659 !C-----
1660 !C--- print*,'NCVHF_WAVNO ,1, 10000,NP_MED = ',NCVHF_WAVNO(1),
1661 !C--- & NCVHF_WAVNO(10000), NCVHF_WAVNO(NP_MED)
1662 !C-----
1663 
1664 !C Initialize arrays for smoothing medium resolution spectrum (DLT_MED = 0.2 nm,
1665 !C and point spacing DWAVLN = 0.0001 micron) to coarser spectral
1666 !C resolution data from imaging spectrometers.
1667 
1668  DO i = 1, nobs
1669  ncvhf(i) = ( facdlt * fwhm(i) / dwavln + 1.)
1670  END DO
1671 !C
1672 !C parameters and arrays to smooth output surface reflectance spectrum
1673  wavcv2=facdlt*dlt2
1674 
1675 !C Find the largest value in the FWHM array, and use this value in calculation
1676 !C of indices for smoothing output reflectance spectra. This smoothing
1677 !C algorithm should work well with grating spectrometers having nearly
1678 !C constant spectral resolutions, but not so well for prism spectrometers
1679 !C having variable spectral resolution.
1680  dwvavr = fwhm(1)
1681 
1682  DO i = 2, nobs
1683  IF(dwvavr.LT.fwhm(i)) dwvavr = fwhm(i)
1684  END DO
1685 
1686  rncv2=wavcv2/dwvavr
1687  ncv2=rncv2
1688  ncvhf2=ncv2+1
1689  ncvtt2=2*ncv2+1
1690 
1691  cons2=dlt2*sqrt(3.1415926/const1)
1692 
1693  IF (dlt2 .NE. 0.0) THEN
1694  sumins=0.0
1695  DO 585 i=ncvhf2,ncvtt2
1696  finst2(i)=exp(-const1*(float(i-ncvhf2)*dwvavr/dlt2)**2.0)
1697  sumins=sumins+finst2(i)
1698  585 CONTINUE
1699 
1700  DO 590 i=1,ncvhf2-1
1701  finst2(i)=finst2(ncvtt2-i+1)
1702  sumins=sumins+finst2(i)
1703  590 CONTINUE
1704 
1705  sumins=sumins*dwvavr
1706 
1707  DO 595 i=1,ncvtt2
1708  finst2(i)=finst2(i)*dwvavr/sumins
1709  595 CONTINUE
1710  ENDIF
1711 
1712  istrt2=ncvhf2
1713  iend2=nobs-ncvhf2
1714 
1715 !C number of channels of the four AVIRIS spectrometers. These are used
1716 !C in removing null AVIRIS radiance values in the overlap portions of two
1717 !C adjacent spectrometers.
1718  nchnla=32
1719  nchnlb=64
1720  nchnlc=64
1721  nchnld=64
1722 
1723  natot=nchnla
1724  nbtot=nchnla+nchnlb
1725  nctot=nchnla+nchnlb+nchnlc
1726  ndtot=nchnla+nchnlb+nchnlc+nchnld
1727 
1728 !C Resetting window wavelength positions and calculating weights for
1729 !C window and absorption channels used in 3-channel ratioing.
1730  iwndw1=findmatch(wavobs,nobs,wndow1)
1731  iwndw2=findmatch(wavobs,nobs,wndow2)
1732 
1733  wndow1=wavobs(iwndw1)
1734  wndow2=wavobs(iwndw2)
1735 
1736  jj=mod(nb1,2)
1737  IF(jj.EQ.0) nb1=nb1+1
1738  kk=mod(nb2,2)
1739  IF(kk.EQ.0) nb2=nb2+1
1740  nb1haf=(nb1-1)/2
1741  nb2haf=(nb2-1)/2
1742 
1743  ist1=iwndw1-nb1haf
1744  ied1=iwndw1+nb1haf
1745  ist2=iwndw2-nb2haf
1746  ied2=iwndw2+nb2haf
1747 
1748  iwp94c=findmatch(wavobs,nobs,wp94c)
1749  wp94c=wavobs(iwp94c)
1750 
1751  ll=mod(nbp94,2)
1752  IF(ll.EQ.0) nbp94=nbp94+1
1753  nb3haf=(nbp94-1)/2
1754  istp94=iwp94c-nb3haf
1755  iedp94=iwp94c+nb3haf
1756 
1757  wt1=(wndow2-wp94c)/(wndow2-wndow1)
1758  wt2=(wp94c-wndow1)/(wndow2-wndow1)
1759 
1760  iwndw4=findmatch(wavobs,nobs,wndow3)
1761  iwndw5=findmatch(wavobs,nobs,wndow4)
1762 
1763  wndow3=wavobs(iwndw4)
1764  wndow4=wavobs(iwndw5)
1765 
1766  jj=mod(nb3,2)
1767  IF(jj.EQ.0) nb3=nb3+1
1768  kk=mod(nb4,2)
1769  IF(kk.EQ.0) nb4=nb4+1
1770 
1771  nb4haf=(nb3-1)/2
1772  nb5haf=(nb4-1)/2
1773 
1774  ist3=iwndw4-nb4haf
1775  ied3=iwndw4+nb4haf
1776  ist4=iwndw5-nb5haf
1777  ied4=iwndw5+nb5haf
1778  iw1p14c=findmatch(wavobs,nobs,w1p14c)
1779 
1780  w1p14c=wavobs(iw1p14c)
1781  ll=mod(nb1p14,2)
1782  IF(ll.EQ.0) nb1p14=nb1p14+1
1783  nb6haf=(nb1p14-1)/2
1784  ist1p14=iw1p14c-nb6haf
1785  ied1p14=iw1p14c+nb6haf
1786 
1787  wt3=(wndow4-w1p14c)/(wndow4-wndow3)
1788  wt4=(w1p14c-wndow3)/(wndow4-wndow3)
1789 
1790 !C Initialization for searching water vapor table (TRNTBL)
1791  ja = 30
1792 !C
1793 !C
1794 !C Calculate medium resolution O3 transmittances (0.2 nm, 2-way) with
1795 !C a point spacing of 0.1 nm between 0.3 and 0.8 micron.
1796 !C
1797  IF(io3.EQ.1) THEN
1798  DO i=1,no3pt
1799  tran_o3_std(i) = exp(-totlo3*o3cf(i))
1800  END DO
1801  END IF
1802 
1803 !C
1804 !C If O3 is not intended to be included in total atmospheric gaseous
1805 !C transmittance calculations, assigning TRAN_O3_STD = 1.0:
1806 !C
1807  IF(io3.NE.1) THEN
1808  DO i=1,no3pt
1809  tran_o3_std(i) = 1.0
1810  END DO
1811  END IF
1812 !C
1813 !C Calculate medium resolution NO2 transmittances (0.2 nm, 2-way) with
1814 !C a point spacing of 0.1 nm between 0.3 and 0.8 micron.
1815 !C
1816  no2pt = no3pt
1817  vrtno2 = 5.0e+15
1818  vrtno2 = sno2 * vrtno2
1819 
1820  gno2 = go3
1821  totno2 = gno2 * vrtno2
1822 
1823  IF(ino2.EQ.1) THEN
1824  DO i=1,no2pt
1825  tran_no2_std(i) = exp(-totno2*rno2cf(i))
1826  END DO
1827  END IF
1828 
1829 !C---Temp Code:
1830 !C--- OPEN(57,file='zzzzzz_tst_NO2_trn',status='unknown')
1831 !C--- DO I = 1, NO2PT
1832 !C--- write(57,*)WAVLN_STD(I), TRAN_NO2_STD(I)
1833 !C--- END DO
1834 !C--- CLOSE(57)
1835 !C---End of Temp Code
1836 !
1837 !C--- print*,' TOTNO2 = ', TOTNO2
1838 !C--- print*,'VRTNO2, SNO2, GNO2 = ', VRTNO2, SNO2, GNO2
1839 
1840 !C
1841 !C If NO2 is not intended to be included in total atmospheric gaseous
1842 !C transmittance calculations, assigning TRAN_NO2_STD = 1.0:
1843 !C
1844  IF(ino2.NE.1) THEN
1845  DO i=1,no2pt
1846  tran_no2_std(i) = 1.0
1847  END DO
1848  END IF
1849 
1850 
1851 !C
1852 !C Initial arrays for mean layer pressure and temperatures
1853 
1854  DO 320 i=1,nl
1855  dp(i)=p(i)-p(i+1)
1856  pm(i)=(p(i)+p(i+1))/2.0
1857  tm(i)=(t(i)+t(i+1))/2.0
1858  320 CONTINUE
1859 
1860 !C
1861 !C Calculate high resolution transmittances (0.05 cm-1) of CO2, N2O, CO,
1862 !C CH4, and O2 in the 0.56 - 3.1 micron range, and save values for
1863 !C calculating total atmospheric transmittances later.
1864 !C Because water vapor amounts are allowed to vary,
1865 !C the high resolution water vapor transmittances are calculated
1866 !C in subroutines TRAN_TABLE and TRANCAL. TRAN_TABLE provides variable
1867 !C water vapor amounts, and calls TRANCAL for the calculation of
1868 !C corresponding vapor transmittance spectrum.
1869 !C
1870 !C*** Note: The array WAVNO_HI is not used in actual computing, the array
1871 !C* should be removed from COMMONS_INC and the following DO LOOP
1872 !C* of this program, the purpose of keeping WAVNO_HI now is to
1873 !C* check array indices and make sure the correctness of the
1874 !C* indices.
1875 !C*
1876 !C Initialize the TRAN_HI_OTHERS array for high resolution spectrum:
1877  DO i = 1, np_hi
1878  tran_hi_others(i) = 1.0
1879  END DO
1880 
1881  ncid = ncopn('abscf_gas.nc',ncnowrit,ircode)
1882 
1883 !C---------------------------------------
1884 !C For CO2 transmittance calculation -
1885  IF(ico2.EQ.1) THEN
1886 !C---- SCLCO2=1.0
1887 !C---- On 2/7/2013 B.-C. Gao made the modification - Increased SCLCO2 i
1888 !C---- from 1.0 to 1.1 to reflect the fact that the CO2 VMR reached the
1889 !C---- 2012 level of 390 ppmv.
1890 !C----
1891  sclco2=1.1
1892 
1893  DO 322 i=1,nl
1894  vmrm(i)=sclco2*355.0*1.0e-06
1895 !C Scale the VMRM by the two-way path geometrical factors. The geometric
1896 !C factors, G_OTHER, varies with atmospheric layer number for
1897 !C aircraft observational geometries.
1898  vmrm(i)= vmrm(i)*g_other(i)
1899  322 CONTINUE
1900 
1901 
1902 
1903 ! NRHID = NCVID (NCID, 'waveno_hi_co2', IRCODE)
1904 ! CALL NCVGT (NCID, NRHID, START(1), CNT(1), WAVNO_HI, IRCODE)
1905 ! if (Ircode .ne.0) then
1906 ! write(*,*) 'Error reading abscf_gas.nc: wavno_hi: rcode=',ircode
1907 ! stop 0
1908 ! end if
1909  nrhid = ncvid(ncid, 'abscf_co2', ircode)
1910  CALL ncvgt (ncid, nrhid, start, cnt, abscf, ircode)
1911  if (ircode .ne.0) then
1912  write(*,*) 'Error reading abscf_gas.nc: abscf_co2: rcode=',ircode
1913  stop 0
1914  end if
1915 
1916 ! OPEN(31,file='abscf_co2_PC',status='old', &
1917 ! form='unformatted',access='direct',recl=4*300000)
1918 
1919 ! READ(31,REC=1) (WAVNO_HI(I), I = 1, 300000)
1920 !
1921  DO j = k_surf, 19
1922 ! READ(31,REC=J+1) (A(I), I = 1, 300000)
1923 !
1924  tran_hi_others(:) = tran_hi_others(:) * exp( - abscf(:,j)*q* &
1925  dp(j-k_surf+1)*vmrm(j-k_surf+1) * 28.966 / &
1926  6.0225e+23 / 1.0e-06)
1927  END DO
1928 !
1929 ! CLOSE(31)
1930  ENDIF
1931 
1932 !C--------------------------------------------
1933 !C For N2O transmittance calculation.
1934 
1935  IF(in2o.EQ.1) THEN
1936  DO 324 i=1,nl
1937  vmrm(i)=0.3*1.0e-06
1938  vmrm(i)= vmrm(i)*g_other(i)
1939  324 CONTINUE
1940 
1941 ! NRHID = NCVID (NCID, 'waveno_hi_n2o', IRCODE)
1942 ! CALL NCVGT (NCID, NRHID, START(1), CNT(1), WAVNO_HI, IRCODE)
1943 ! if (Ircode .ne.0) then
1944 ! write(*,*) 'Error reading abscf_gas.nc: wavno_hi: rcode=',ircode
1945 ! stop 0
1946 ! end if
1947  nrhid = ncvid(ncid, 'abscf_n2o', ircode)
1948  CALL ncvgt (ncid, nrhid, start, cnt, abscf, ircode)
1949  if (ircode .ne.0) then
1950  write(*,*) 'Error reading abscf_gas.nc: abscf_n2o: rcode=',ircode
1951  stop 0
1952  end if
1953 
1954 ! OPEN(31,file='abscf_n2o_PC',status='old', &
1955 ! form='unformatted',access='direct',recl=4*300000)
1956 
1957 ! READ(31,REC=1) (WAVNO_HI(I), I = 1, 300000)
1958 
1959  DO j = k_surf, 19
1960 ! READ(31,REC=J+1) (A(I), I = 1, 300000)
1961 
1962  tran_hi_others(:) = tran_hi_others(:) * exp( - abscf(:,j)*q* &
1963  dp(j-k_surf+1)*vmrm(j-k_surf+1) * 28.966 / &
1964  6.0225e+23 / 1.0e-06)
1965  END DO
1966 
1967 ! CLOSE(31)
1968  ENDIF
1969 
1970 !C--------------------------------------------
1971 !C For CO transmittance calculation.
1972  IF(ico.EQ.1) THEN
1973  DO 325 i=1,nl
1974  vmrm(i)=0.1*1.0e-06
1975  vmrm(i)= vmrm(i)*g_other(i)
1976  325 CONTINUE
1977 
1978 ! NRHID = NCVID (NCID, 'waveno_hi_co', IRCODE)
1979 ! CALL NCVGT (NCID, NRHID, START(1), CNT(1), WAVNO_HI, IRCODE)
1980 ! if (Ircode .ne.0) then
1981 ! write(*,*) 'Error reading abscf_gas.nc: wavno_hi: rcode=',ircode
1982 ! stop 0
1983 ! end if
1984  nrhid = ncvid(ncid, 'abscf_co', ircode)
1985  CALL ncvgt (ncid, nrhid, start, cnt, abscf, ircode)
1986  if (ircode .ne.0) then
1987  write(*,*) 'Error reading abscf_gas.nc: abscf_co: rcode=',ircode
1988  stop 0
1989  end if
1990 
1991 ! OPEN(31,file='abscf_co_PC',status='old', &
1992 ! form='unformatted',access='direct',recl=4*300000)
1993 
1994  ! READ(31,REC=1) (WAVNO_HI(I), I = 1, 300000)
1995 
1996  DO j = k_surf, 19
1997  ! READ(31,REC=J+1) (A(I), I = 1, 300000)
1998 
1999  tran_hi_others(:) = tran_hi_others(:) * exp( - abscf(:,j)*q* &
2000  dp(j-k_surf+1)*vmrm(j-k_surf+1) * 28.966 / &
2001  6.0225e+23 / 1.0e-06)
2002  END DO
2003 
2004  ! CLOSE(31)
2005  ENDIF
2006 
2007 !C--------------------------------------------
2008 !C For CH4 transmittance calculation.
2009 !C For assigning CH4 VMRM
2010 !C NOTE: The scaling factor of 0.8 for the CH4 VMRS was obtained by comparing
2011 !C transmittance spectra calculated using our program, which is based on
2012 !C the Malkmus narrow band spectral model, with a ratioed spectrum
2013 !C provided by G. C. Toon at Jet Propulsion Laboratory (JPL). The JPL
2014 !C ratio spectrum was obtained by ratioing a high resolution (0.005 cm-1)
2015 !C solar spectrum measured at ground level against a solar spectrum
2016 !C measured at an altitude of approximately 35 km with the same Fourier
2017 !C Transform spectrometer. The high resolution ratio spectrum was
2018 !C degraded to a resolution of 10 nm during our derivation of the
2019 !C scaling factor for the CH4 VMRS.
2020 
2021  IF(ich4.EQ.1) THEN
2022 !C*** SCLCH4=0.8
2023  sclch4=1.0
2024  DO 326 i=1,nl
2025  vmrm(i)=sclch4*1.6*1.0e-06
2026  vmrm(i)= vmrm(i)*g_other(i)
2027  326 CONTINUE
2028 
2029 ! NRHID = NCVID (NCID, 'waveno_hi_ch4', IRCODE)
2030 ! CALL NCVGT (NCID, NRHID, START(1), CNT(1), WAVNO_HI, IRCODE)
2031 ! if (Ircode .ne.0) then
2032 ! write(*,*) 'Error reading abscf_gas.nc: wavno_hi: rcode=',ircode
2033 ! stop 0
2034 ! end if
2035  nrhid = ncvid(ncid, 'abscf_ch4', ircode)
2036  CALL ncvgt (ncid, nrhid, start, cnt, abscf, ircode)
2037  if (ircode .ne.0) then
2038  write(*,*) 'Error reading abscf_gas.nc: abscf_ch4: rcode=',ircode
2039  stop 0
2040  end if
2041 
2042 ! OPEN(31,file='abscf_ch4_PC',status='old', &
2043 ! form='unformatted',access='direct',recl=4*300000)
2044 
2045 ! READ(31,REC=1) (WAVNO_HI(I), I = 1, 300000)
2046 
2047  DO j = k_surf, 19
2048 ! READ(31,REC=J+1) (A(I), I = 1, 300000)
2049 
2050  tran_hi_others(:) = tran_hi_others(:) * exp( - abscf(:,j)*q* &
2051  dp(j-k_surf+1)*vmrm(j-k_surf+1) * 28.966 / &
2052  6.0225e+23 / 1.0e-06)
2053  END DO
2054 
2055 ! CLOSE(31)
2056  ENDIF
2057 
2058 !C--------------------------------------------
2059 !C For O2 transmittance calculation.
2060  IF(io2.EQ.1) THEN
2061 
2062 !C***Modified by Bo-Cai Gao on 2/7/2013 to increase O2 absorption
2063 !C--- coefficients by the factor SCL_O2 for wavelengths > 1.2 micron
2064 !C--- in order to model properly the atmospheric O2 band centered
2065 !C--- near 1.265 micron.
2066 
2067  scl_o2 = 2.60
2068 
2069  DO 327 i=1,nl
2070  vmrm(i)=0.21
2071  vmrm(i)= vmrm(i)*g_other(i)
2072  327 CONTINUE
2073 
2074 ! NRHID = NCVID (NCID, 'waveno_hi_o2', IRCODE)
2075 ! CALL NCVGT (NCID, NRHID, START(1), CNT(1), WAVNO_HI, IRCODE)
2076 ! if (Ircode .ne.0) then
2077 ! write(*,*) 'Error reading abscf_gas.nc: wavno_hi: rcode=',ircode
2078 ! stop 0
2079 ! end if
2080  nrhid = ncvid(ncid, 'abscf_o2', ircode)
2081  CALL ncvgt (ncid, nrhid, start, cnt, abscf, ircode)
2082  if (ircode .ne.0) then
2083  write(*,*) 'Error reading abscf_gas.nc: abscf_o2: rcode=',ircode
2084  stop 0
2085  end if
2086 
2087 ! OPEN(31,file='abscf_o2_PC',status='old', &
2088 ! form='unformatted',access='direct',recl=4*300000)
2089 
2090 ! READ(31,REC=1) (WAVNO_HI(I), I = 1, 300000)
2091 
2092  DO j = k_surf, 19
2093 ! READ(31,REC=J+1) (A(I), I = 1, 300000)
2094 
2095 !C***Modified by Bo-Cai Gao on 2/7/2013 to increase O2 absorption
2096 !C--- coefficients by the factor SCL_O2 for wavelengths > 1.2 micron
2097 !C--- i& < 1.3333 micron in order to model properly the atmospheric
2098 !C--- O2 band centered near 1.265 micron.
2099 
2100  tran_hi_others(1:9000) = tran_hi_others(1:9000) * exp( - abscf(1:9000,j)*q* &
2101  dp(j-k_surf+1)*vmrm(j-k_surf+1) * 28.966 / &
2102  6.0225e+23 / 1.0e-06)
2103 
2104  tran_hi_others(9001:106600) = tran_hi_others(9001:106600) * exp( - abscf(9001:106600,j)*q* &
2105  dp(j-k_surf+1)*vmrm(j-k_surf+1)*scl_o2 *28.966/ &
2106  6.0225e+23 / 1.0e-06)
2107 
2108  tran_hi_others(106601:np_hi) = tran_hi_others(106601:np_hi) * exp( - abscf(106601:np_hi,j)*q* &
2109  dp(j-k_surf+1)*vmrm(j-k_surf+1) * 28.966 / &
2110  6.0225e+23 / 1.0e-06)
2111  END DO
2112 
2113  CLOSE(31)
2114  ENDIF
2115 
2116  CALL ncclos(ncid, rcode)
2117 
2118 !C--------------------------------------------
2119 !C End of calculation of high resolution transmittances for CO2, N2O, CO,
2120 !C CH4, and O2.
2121 !C--------------------------------------------
2122 !C Initial water vapor VMRs for repeated use in other subroutines and
2123 !C adjust layered water vapor VMRM with geometrical factors.
2124  DO i = 1, nl
2125  vmrm(i) = (vmr(i)+vmr(i+1))/2.0
2126 !C Scale the VMRM by the two-way path geometrical factors. The geometric
2127 !C factors, G_VAP, varies with atmospheric layer number for
2128 !C aircraft observational geometries.
2129  vmrm(i) = vmrm(i)*g_vap(i)
2130  END DO
2131 !C--------------------------------------------
2132 !C
2133 !C--D WRITE(*,*)'NPSHIF=',NPSHIF,' DWAVLN=',DWAVLN
2134 !C--D WRITE(*,*)'NO3PT=',NO3PT,' VMIN=',VMIN,' ISTART=',ISTART
2135 !C--D WRITE(*,*)'IH2OLQ=',IH2OLQ,' RLQAMT=',RLQAMT,' NGASTT=',NGASTT
2136 !C--D WRITE(*,*)'NH2O=',NH2O,' VSTART=',VSTART,' VEND=',VEND
2137 !C--D WRITE(*,*)'IEND=',IEND
2138 !C--D WRITE(*,*)'ISTCAL=',ISTCAL,' IEDCAL=',IEDCAL
2139 !C--D DO 545 I=1,NL
2140 !C--D 545 WRITE(*,*)I,DP(I),PM(I),TM(I),VMRM(I)
2141 !C--D WRITE(*,*)'IST1=',IST1,' IED1=',IED1,' IST2=',IST2,' IED2=',IED2
2142 !C--D WRITE(*,*)'ISTP94=',ISTP94,' IEDP94=',IEDP94
2143 !C--D WRITE(*,*)'IST3=',IST3,' IED3=',IED3,' IST4=',IST4,' IED4=',IED4
2144 !C--D WRITE(*,*)'IST1P14=',IST1P14,' IED1P14=',IED1P14
2145 !C--D WRITE(*,*)'WT1=',WT1,' WT2=',WT2,' WT3=',WT3,' WT4=',WT4,' JA=',JA
2146 !C--D WRITE(*,*)'NCV2=',NCV2,' NCVHF2=',NCVHF2,' NCVTT2=',NCVTT2,
2147 !C--D &' ISTRT2=',ISTRT2,' IEND2=',IEND2
2148 !C--D DO 544 I=1,30
2149 !C--D 544 WRITE(*,*)'I=',I,' FINST2(I)=',FINST2(I)
2150 !C--D WRITE(*,*)'NATOT=',NATOT,' NBTOT=',NBTOT
2151 !C--D WRITE(*,*)'NCTOT=',NCTOT,' NDTOT=',NDTOT
2152 
2153  RETURN
2154  END
2155 
2156 !********************************************************************************
2157 !* *
2158 !* Name: TRAN_TABLE *
2159 !* Purpose: This subroutine generates a table consisting of 60 atmospheric *
2160 !* transmittance spectra at the solar and observational *
2161 !* geometry and with 60 column water vapor values. The table also *
2162 !* includes the total amounts of column water vapor used in the *
2163 !* calculations, and the 3-channel ratios calculated from the window *
2164 !* and absorption channels in and around the 0.94- and 1.14-um water *
2165 !* vapor bands. *
2166 !* Parameters: none *
2167 !* Algorithm: For each of the 60 water vapor amounts, calculate the *
2168 !* atmospheric transmittance, and save *
2169 !* Globals Used: NH2O - number of column water vapor values *
2170 !* VAPTT - geometrically adjusted water vapor total *
2171 !* R094 - channel ratio for .94 um region *
2172 !* R114 - channel ratio for 1.14 um region *
2173 !* TRNCAL - atmospheric transmittance spectra *
2174 !* Global Output: VAPTOT() - array containing geometrically adjusted water *
2175 !* vapor values *
2176 !* ROP94() - array containing channel ratios for .94 um region *
2177 !* R1P14() - array containing channel ratios for 1.14 um region*
2178 !* TRNTBL() - 2 dimensional array containing one transmittance *
2179 !* spectrum for each column water vapor amount *
2180 !* Return Codes: none *
2181 !* Special Considerations: none *
2182 !* *
2183 !********************************************************************************
2184  SUBROUTINE tran_table
2186  include 'COMMONS_INC.f'
2187 
2188 !C Common variables
2189  dimension trncal(1024)
2190  dimension wavobs(1024),fwhm(1024)
2191  dimension dp(25), pm(25), tm(25), vmrm(25)
2192  dimension ssh2o(60)
2193  dimension vaptot(60), r0p94(60), r1p14(60), trntbl(1024,60)
2194 
2195  dimension o3cf(5001)
2196  COMMON /o3cf_init1/ o3cf
2197 
2198  COMMON /getinput1/ ih2ovp,ico2,io3,in2o,ico,ich4,io2,ino2
2199  COMMON /getinput4/ wavobs,fwhm
2200  COMMON /getinput5/ nobs,hsurf,dlt,dlt2
2201  COMMON /init_speccal3/ nh2o
2202  COMMON /init_speccal5/ dp,pm,tm,vmrm
2203 
2204  COMMON /tran_table1/ sh2o,vaptot,r0p94,r1p14,trntbl
2205  COMMON /trancal1/ trncal,vaptt
2206  COMMON /geometry2/ gco2,go3,gn2o,gco,gch4,go2,ssh2o,totlo3,ggeom
2207  COMMON /chnlratio1/ r094,r114
2208 
2209 !C For each water vapor amount, calculate the geometrically adjusted water
2210 !C vapor amount, the channel ratios, and the transmittance spectrum.
2211  vaptt = 0.
2212 
2213  DO 530 i=1,nh2o
2214  sh2o=ssh2o(i)
2215 
2216  CALL trancal
2217 
2218  vaptot(i)= vaptt
2219  r0p94(i) = r094
2220  r1p14(i) = r114
2221  DO 540 j=1,nobs
2222  trntbl(j,i)=trncal(j)
2223  540 CONTINUE
2224  530 CONTINUE
2225 
2226 !C Write above calculated values to a file.
2227  nj=nh2o
2228  nk=float(nj)/10.
2229  njdiff=nj-nk*10
2230 
2231 !RJH DO 380 KK=1,NK
2232 ! WRITE(35,77) (VAPTOT(I+(KK-1)*10),I=1,10)
2233 ! 77 FORMAT(7X,10(1X,E11.4))
2234 ! WRITE(35,77) ( R0P94(I+(KK-1)*10),I=1,10)
2235 ! WRITE(35,77) ( R1P14(I+(KK-1)*10),I=1,10)
2236 ! DO 385 II=1,NOBS
2237 ! 385 WRITE(35,78) WAVOBS(II),(TRNTBL(II,I+(KK-1)*10),I=1,10)
2238 ! 78 FORMAT(1X,F6.4,10(1X,E11.4))
2239 ! 380 CONTINUE
2240 
2241 ! WRITE(35,77) (VAPTOT(I+NK*10),I=1,NJDIFF)
2242 ! WRITE(35,77) ( R0P94(I+NK*10),I=1,NJDIFF)
2243 ! WRITE(35,77) ( R1P14(I+NK*10),I=1,NJDIFF)
2244 !
2245 ! IF(NJDIFF.GE.1) THEN
2246 ! DO 386 II=1,NOBS
2247 ! 386 WRITE(35,78) WAVOBS(II),(TRNTBL(II,I+NK*10),I=1,NJDIFF)
2248 ! ENDIF
2249 ! CLOSE(35,IOSTAT=ISTAT)
2250 
2251  RETURN
2252  END
2253 
2254 !********************************************************************************
2255 !* *
2256 !* Name: TRANCAL *
2257 !* Purpose: This program calculates combined transmittances of H2O, CO2, O3, *
2258 !* N2O, CO, CH4, and O2. *
2259 !* Parameters: none. *
2260 !* Algorithm: The calculations were based on the line-by-line absorption *
2261 !* parameters supplied by William R. Ridgway of NASA/GSFC. *
2262 !* Global output:VAPTT - geometrically adjusted water vapor total. *
2263 !* R094 - channel ratio for 0.94 um region. *
2264 !* R114 - channel ratio for 1.14 um region. *
2265 !* TRNCAL - total transmittances of all gases that match the *
2266 !* resolutions of imaging spectrometers. *
2267 !* Return Codes: none. *
2268 !* Special Considerations: The high resolution (0.05 cm-1) line-by-line *
2269 !* absorption parameters cover the 0.555 - 3.33 micron spectral range *
2270 !* (3000 - 18000 cm-1). The medium resolution ozone absorption *
2271 !* coefficients covers the 0.3-0.8 um spectral range. The line-by-line *
2272 !* high resolution spectra were first smoothed to medium resolution *
2273 !* spectra (resolution = 0.2 nm, wavelength spacing = 0.1 nm) covering *
2274 !* the 0.56 - 3.1 micron spectral region. The medium resolution spectra *
2275 !* of O3 and other gases are combined (in SUBROUTINE TRAN_SMOOTH) to form *
2276 !* a single medium resolution spectrum from 0.3 to 3.1 micron. This *
2277 !* combined spectrum (medium resolution) is then smoothed to lower *
2278 !* resolutions to match the resolutions of imaging spectrometers. The *
2279 !* smoothing is also done in SUBROUTINE TRAN_SMOOTH. *
2280 !* *
2281 !********************************************************************************
2282 
2283  SUBROUTINE trancal
2285  include 'COMMONS_INC.f'
2286  include 'netcdf.inc'
2287 !C Common variables
2288  dimension trncal(1024)
2289  dimension wavobs(1024),fwhm(1024)
2290  dimension dp(25), pm(25), tm(25), vmrm(25)
2291  dimension vaptot(60), r0p94(60), r1p14(60), trntbl(1024,60)
2292 
2293 !C Local variables
2294  dimension trans(1024)
2295  dimension trncv(1024)
2296  dimension trnstd_sm(1050)
2297  INTEGER INDEX
2298 
2299  COMMON /getinput4/ wavobs,fwhm
2300  COMMON /getinput5/ nobs,hsurf,dlt,dlt2
2301  COMMON /model_adj1/ clmvap,q
2302  COMMON /init_speccal5/ dp,pm,tm,vmrm
2303  COMMON /init_speccal6/ ist1,ied1,ist2,ied2,istp94,iedp94
2304  COMMON /init_speccal7/ ist3,ied3,ist4,ied4,ist1p14,ied1p14
2305  COMMON /tran_table1/ sh2o,vaptot,r0p94,r1p14,trntbl
2306  COMMON /trancal1/ trncal,vaptt
2307 
2308  dimension g_vap(25), g_other(25)
2309  COMMON /geometry3/ g_vap, g_other, g_vap_equiv, vap_slant_mdl
2310 
2311  COMMON /model_adj4/ k_surf
2312  INTEGER FIRST/1/
2313  INTEGER start(2)/1,1/
2314  INTEGER cnt(2)/NP_HI,19/
2315 
2316 ! REAL ABSCF(NP_HI,19)
2317  SAVE first
2318 
2319 !C
2320 !C Calculate water vapor transmittances with different scaling factors:
2321 !C
2322 
2323  DO i = 1, np_hi
2324  tran_hi(i) = 1.0
2325  END DO
2326 
2327  if (first.eq.1) then
2328  ncid = ncopn('abscf_gas.nc',ncnowrit,ircode)
2329 ! NRHID = NCVID (NCID, 'waveno_hi_h2o', IRCODE)
2330 ! CALL NCVGT (NCID, NRHID, START(1), CNT(1), WAVNO_HI, IRCODE)
2331 ! if (Ircode .ne.0) then
2332 ! write(*,*) 'Error reading abscf_gas.nc: wavno_hi: rcode=',ircode
2333 ! stop 0
2334 ! end if
2335  nrhid = ncvid(ncid, 'abscf_h2o', ircode)
2336  CALL ncvgt (ncid, nrhid, start, cnt, abscf, ircode)
2337  if (ircode .ne.0) then
2338  write(*,*) 'Error reading abscf_gas.nc: abscf_h2o: rcode=',ircode
2339  stop 0
2340  end if
2341  CALL ncclos(ncid, rcode)
2342 
2343 ! OPEN(31,file='abscf_h2o_PC',status='old', &
2344 ! form='unformatted',access='direct',recl=4*300000)
2345 
2346 ! READ(31,REC=1) (WAVNO_HI(I), I = 1, 300000)
2347 
2348 ! DO J = 1, 19
2349 ! READ(31,REC=J+1) (ABSCF(I,J), I = 1, 300000)
2350 
2351 ! END DO
2352 
2353 ! CLOSE(31)
2354  first=0
2355  endif
2356 
2357  DO j = k_surf, 19
2358 
2359  tran_hi(:) = tran_hi(:) * exp( - abscf(:,j) * q * &
2360  dp(j-k_surf+1)*vmrm(j-k_surf+1) * sh2o * 28.966 / &
2361  6.0225e+23 / 1.0e-06)
2362 
2363  END DO
2364 
2365 !C Multiplying the high resolution water vapor transmittance with combined
2366 !C transmittances of CO2, N2O, CO, CH4, and O2:
2367 !C
2368  tran_hi(:) = tran_hi(:)*tran_hi_others(:)
2369 ! DO I = 1, NP_HI
2370 ! TRAN_HI(I) = TRAN_HI(I) * TRAN_HI_OTHERS(I)
2371 ! END DO
2372 
2373 !C
2374 !C Smooth the high resolution spectra to resolutions of measured spectrum
2375 !C
2376  CALL tran_smooth
2377 !C
2378 !C--- DO 470 I=1,NOBS
2379 !C--- WRITE(*,*)'I=',I,' TRNCAL(I)=',TRNCAL(I)
2380 !C--- 470 CONTINUE
2381 
2382 !C Calculate 3-channel ratio values, R094 and R114, from simulated spectra.
2383  CALL chnlratio
2384 
2385 !C Total amount of water vapor (in unit of cm) corresponding to the spectrum.
2386  vaptt = vap_slant_mdl * sh2o
2387 !C-- print*, 'VAPTT= ', VAPTT,'VAP_SLANT_MDL= ',VAP_SLANT_MDL
2388 
2389  9999 RETURN
2390  END
2391 
2392 !********************************************************************************
2393 !* *
2394 !* Name: TRAN_SMOOTH *
2395 !* Purpose: This program is to smooth the line-by-line high resolution *
2396 !* spectrum to lower resolution spectrum that matches the resolutions *
2397 !* of imaging spectrometer data. *
2398 !* Parameters: none. *
2399 !* Algorithm: The smoothing is done in two stages. The 1st stage is to smooth *
2400 !* the high resolution spectrum to medium resolution spectrum at a *
2401 !* constant FWHM (0.2 nm) and a constant wavelength interval *
2402 !* (0.1 nm). The 2nd stage smoothing is to smooth the medium *
2403 !* resolution spectrum to resolutions of input imaging spectrometer *
2404 !* data. *
2405 !* Globals used: The global variables used are contained in the file *
2406 !* "COMMONS_INC" *
2407 !* Global output: TRNCAL - total transmittances of all gases that match the *
2408 !* resolutions of imaging spectrometers. *
2409 !* Return Codes: none. *
2410 !* *
2411 !********************************************************************************
2412 
2413  SUBROUTINE tran_smooth
2415  include 'COMMONS_INC.f'
2416 
2417  dimension tran_o3_std(5001)
2418  COMMON /init_speccal16/ tran_o3_std
2419 
2420  dimension tran_no2_std(5001)
2421  COMMON /init_speccal17/ tran_no2_std
2422 
2423  dimension wavobs(1024),fwhm(1024)
2424  COMMON /getinput4/ wavobs,fwhm
2425 
2426  dimension trncal(1024)
2427  COMMON /trancal1/ trncal,vaptt
2428 
2429  COMMON /getinput5/ nobs,hsurf,dlt,dlt2
2430 
2431 !C First stage of smoothing - smooth line-by-line high resolution spectrum with
2432 !C over 300,000 points (point spacing of 0.05 cm-1) to medium resolution
2433 !C spectrum (resolution of 0.2 nm and point spacing of 0.1 nm) with about
2434 !C 25,000 points.
2435 !C
2436 !C The smoothing of line-by-line spectrum is done in wavenumber domain. For
2437 !C a spectrum with a constant 0.2 nm resolution in wavelength domain, it has
2438 !C variable resolution in wavenumber domain. This effect is properly taken
2439 !C care of in the design of smoothing functions.
2440 !C
2441 !C Because the high resolution spectrum is in wavenumber units (cm-1), while
2442 !C the medium resolution spectrum is in wavelength units, the two kinds of
2443 !C grids do not automatically match. In order to match the grids, arrays
2444 !C of INDEX_MED and TRAN_MED_INDEX are specially designed. The desired
2445 !C medium resolution spectrum, TRAN_MED, at constant 0.1 nm point spacing
2446 !C and 0.2 nm resolution is obtained through linear interpolation of
2447 !C TRAN_MED_INDEX array.
2448 !C
2449  DO 466 j =1, np_med
2450 
2451  tran_med_index(j) = 0.0
2452  ncvtot_wavno = 2 * ncvhf_wavno(j) - 1
2453 
2454  sumins = 0.0
2455 
2456  DO 560 i = ncvhf_wavno(j), ncvtot_wavno
2457  finstr_wavno(i) = &
2458  exp( -const1*(float(i-ncvhf_wavno(j))*dwavno &
2459  /fwhm_wavno(j))**2.0)
2460  sumins = sumins + finstr_wavno(i)
2461  560 CONTINUE
2462 
2463  DO 565 i = 1, ncvhf_wavno(j)-1
2464  finstr_wavno(i) = finstr_wavno(ncvtot_wavno-i+1)
2465  sumins = sumins + finstr_wavno(i)
2466  565 CONTINUE
2467 
2468  sumins = sumins * dwavno
2469 
2470  DO 570 i = 1, ncvtot_wavno
2471  finstr_wavno(i) = finstr_wavno(i)*dwavno/sumins
2472  570 CONTINUE
2473 
2474 !C*** !!!High resolution transmittances of CO2, N2O, CO, CH4, and O2 should
2475 !C also be calculated somewhere else (wavelength start = 0.56 micron).
2476 !C*** Here assuming TCO2*TN2O*TCO*TCH4*TO2 is already calculated previously,
2477 !C i.e., TRANS(I) = TRAN_CO2(I)*TRAN_N2O(I)*TRAN_CO(I)*TRAN_CH4(I)*TRAN_O2(I)
2478 !C and TRAN_HI(I) = TRAN_HI_H2O(I) * TRANS(I), and TRAN_HI_H2O for varying
2479 !C water vapor amounts is calculated in this subroutine.
2480 
2481  DO 491 k = index_med(j)-(ncvhf_wavno(j)-1), &
2482  index_med(j)+ncvhf_wavno(j)-1
2483  tran_med_index(j) = tran_med_index(j) + tran_hi(k)* &
2484  finstr_wavno(k-index_med(j)+ncvhf_wavno(j))
2485  491 CONTINUE
2486 
2487  466 CONTINUE
2488 
2489 !C
2490 !C Linear interpolation to get TRAN_MED from TRAN_MED_INDEX:
2491 !C (Note that WAVLN_MED_INDEX(J) >= WAVLN_MED(J) )
2492 !C
2493  tran_med(1) = tran_med_index(1)
2494  tran_med(np_med) = tran_med_index(np_med)
2495 
2496  DO j = 2, np_med-1
2497  IF(wavln_med_index(j).LE.wavln_med(j)) THEN
2498  tran_med(j) = tran_med_index(j)
2499  ELSE
2500  dlt = wavln_med_index(j) - wavln_med_index(j-1)
2501  fjm1 = (wavln_med_index(j) - wavln_med(j)) /dlt
2502  fj = (wavln_med(j) - wavln_med_index(j-1))/dlt
2503  tran_med(j) = fjm1*tran_med_index(j-1) + fj*tran_med_index(j)
2504 !C---
2505 !C--- print*,j,fjm1,fj
2506 !C---
2507  END IF
2508  END DO
2509 !C
2510 !C--- Here multiplying O3 and NO2 spectra and other spectrum at medium resolution:
2511 !C
2512  DO i = 1, np_std
2513  tran_std(i) = 1.
2514  END DO
2515 
2516  DO i = 1, no3pt
2517  tran_std(i) = tran_o3_std(i) * tran_no2_std(i)
2518  END DO
2519 
2520  DO i = npshif+1, np_std
2521  tran_std(i) = tran_std(i)*tran_med(i-npshif)
2522  END DO
2523 
2524 
2525 !C The 2nd stage of smoothing - smooth the medium resolution spectrum (resolution
2526 !C of 0.2 nm and point spacing of 0.1 nm) with about 25,000 points to match
2527 !C the coarser and variable resolution spectrum from imaging spectrometers.
2528 !C
2529 !C Initialize some index parameters:
2530  ia = 1000
2531 !C
2532  DO 1466 j =1, nobs
2533 
2534  trncal(j) = 0.0
2535  tran_ia = 0.0
2536  tran_iap1 = 0.0
2537 
2538  ncvtot = 2 * ncvhf(j) - 1
2539 !C---
2540 !C--- print*,'J= ',j, 'NCVHF =', NCVHF(J), 'NCVTOT=',NCVTOT
2541 
2542 !C Calculate instrumental response functions...
2543  sumins = 0.0
2544 
2545  DO 1560 i = ncvhf(j), ncvtot
2546  finstr(i) = &
2547  exp( -const1*(float(i-ncvhf(j))*dwavln &
2548  /fwhm(j))**2.0)
2549  sumins = sumins + finstr(i)
2550 1560 CONTINUE
2551 
2552  DO 1565 i = 1, ncvhf(j)-1
2553  finstr(i) = finstr(ncvtot-i+1)
2554  sumins = sumins + finstr(i)
2555 1565 CONTINUE
2556 
2557  sumins = sumins * dwavln
2558 
2559  DO 1570 i = 1, ncvtot
2560  finstr(i) = finstr(i)*dwavln/sumins
2561 1570 CONTINUE
2562 
2563 !C--- IF(j.eq.87) then
2564 !C--- print*, ' J = 87 =', J
2565 !C--- do i = 1, NCVTOT
2566 !C--- print*,i, FINSTR(i)
2567 !C--- end do
2568 !C--- end if
2569 
2570 !C Index searching...
2571 !C
2572  CALL hunt(wavln_std, np_std, wavobs(j), ia)
2573 !C
2574 !C--- print*,'J =', J, ' IA =', IA
2575 !
2576 !C Smoothing...
2577 !C
2578  DO 1491 k = ia-(ncvhf(j)-1), ia+ncvhf(j)-1
2579  tran_ia = tran_ia + tran_std(k)* &
2580  finstr(k-ia+ncvhf(j))
2581 
2582 !C--- IF(J.eq.1) then
2583 !C--- print*,'j =', j, 'K = ',K, ' IA= ',IA,
2584 !C--- & K-IA+NCVHF(J),
2585 !C--- & FINSTR(K-IA+NCVHF(J))
2586 !C--- End IF
2587 
2588 1491 CONTINUE
2589 
2590  ia_p1 = ia + 1
2591  DO 1492 k = ia_p1-(ncvhf(j)-1), ia_p1+ncvhf(j)-1
2592  tran_iap1 = tran_iap1 + tran_std(k)* &
2593  finstr(k-ia_p1+ncvhf(j))
2594 1492 CONTINUE
2595 !C
2596 !C Linear interpolation to get TRNCAL from TRAN_IA and TRAN_IAP1:
2597 !C
2598  dlt_ia = wavln_std(ia_p1) - wavln_std(ia)
2599  fia = (wavln_std(ia_p1) - wavobs(j)) /dlt_ia
2600 !C FIA_P1 = (WAVOBS(J) - WAVLN_STD(IA))/DLT_IA
2601  fia_p1 = 1. - fia
2602  trncal(j) = fia*tran_ia + fia_p1*tran_iap1
2603 !C---
2604 !C--- print*,'j=',j,'IA =',IA,'FIA =',FIA,'FIA_P1=',FIA_P1,DLT_IA
2605 !C---
2606 !C
2607 1466 CONTINUE
2608 
2609 
2610 
2611  RETURN
2612  END
2613 !********************************************************************************
2614 !* *
2615 !* Name: CHNLRATIO *
2616 !* Purpose: Calculate 3-channel ratios. *
2617 !* Parameters: none *
2618 !* Algorithm: The 0.94-um water vapor absorption channel is ratioed against *
2619 !* the linear combination of two window channels near 0.86 and *
2620 !* 1.03 um to obtain one channel ratio for the 0.94-um band. *
2621 !* Similar calculation is done for the 1.14-um water vapor band. *
2622 !* Globals used: NB1,NB2,NBP94,NB3,NB4,NB1P14 - number of points used in *
2623 !* channel ratios for both the .94- and 1.14-um regions*
2624 !* IST1,IED1,IST2,IED2,ISTP94,IEDP94 - 3-channel ratioing *
2625 !* parameters for the 0.94-um water vapor band *
2626 !* IST3,IED3,IST4,IED4,IST1P14,IED1P14 - 3-channel ratioing *
2627 !* parameters for the 1.14-um water vapor band. *
2628 !* WT1,WT2,WT3,WT4,JA - Relative weights for the four window *
2629 !* channels used in channel-ratioing calculations. JA *
2630 !* is an output parameter from a table searching *
2631 !* routine. *
2632 !* TRNCAL - Atmospheric transmittance spectra. *
2633 !* Global output:R094,R114 - 3-channel ratio values for the 0.94- and 1.14-um *
2634 !* water vapor bands. *
2635 !* Return Codes: none *
2636 !* Special Considerations: none *
2637 !* *
2638 !********************************************************************************
2639 
2640  SUBROUTINE chnlratio
2642 !C Common variables
2643  dimension trncal(1024)
2644 
2645  COMMON /getinput7/ nb1,nb2,nbp94,nb3,nb4,nb1p14
2646  COMMON /init_speccal6/ ist1,ied1,ist2,ied2,istp94,iedp94
2647  COMMON /init_speccal7/ ist3,ied3,ist4,ied4,ist1p14,ied1p14
2648  COMMON /init_speccal8/ wt1,wt2,wt3,wt4,ja
2649  COMMON /trancal1/ trncal,vaptt
2650  COMMON /chnlratio1/ r094,r114
2651 
2652 !C Calculate average of spectra over window and water vapor absorption regions.
2653  const1=0.0
2654  DO 560 i=ist1,ied1
2655  const1=const1+trncal(i)
2656  560 CONTINUE
2657  const1=const1/float(nb1)
2658 
2659  const2=0.0
2660  DO 570 i=ist2,ied2
2661  const2=const2+trncal(i)
2662  570 CONTINUE
2663  const2=const2/float(nb2)
2664 
2665  const3=0.0
2666  DO 575 i=istp94,iedp94
2667  const3=const3+trncal(i)
2668  575 CONTINUE
2669  const3=const3/float(nbp94)
2670 
2671  r094=const3/((wt1*const1) + (wt2*const2))
2672 
2673  const4=0.0
2674  DO 580 i=ist3,ied3
2675  const4=const4+trncal(i)
2676  580 CONTINUE
2677  const4=const4/float(nb3)
2678 
2679  const5=0.0
2680  DO 590 i=ist4,ied4
2681  const5=const5+trncal(i)
2682  590 CONTINUE
2683  const5=const5/float(nb4)
2684 
2685  const6=0.0
2686  DO 595 i=ist1p14,ied1p14
2687  const6=const6+trncal(i)
2688  595 CONTINUE
2689  const6=const6/float(nb1p14)
2690 
2691  r114=const6/((wt3*const4) + (wt4*const5))
2692 
2693  RETURN
2694  END
2695 
2696 !********************************************************************************
2697 !* *
2698 !* Name: PROCESS_CUBE *
2699 !* Purpose: Processes an input cube one spectral slice at a time to derive *
2700 !* surface reflectance for each spectrum and calculate the column *
2701 !* water vapor amount for each pixel. The derived surface reflectance*
2702 !* values are written to an output image file with the same dimensions*
2703 !* as the input image, and the column water vapor amounts are written *
2704 !* to a separate file as a single channel image. *
2705 !* Parameters: none *
2706 !* Algorithm: C programs are used to perform all of the file I/O. A spectral *
2707 !* slice is read from the input file. Each spectrum in the slice *
2708 !* is divided by the solar irradiance curve, then the water vapor *
2709 !* ratio is calculated. The corresponding ratio and associated *
2710 !* transmission spectrum is used to derive the surface reflectance *
2711 !* values. *
2712 !* *
2713 !* The output is an image file in the same storage order format as *
2714 !* the input image file. It has a 512-byte SIPS header. The values*
2715 !* are surface reflectance values multiplied by an input scale *
2716 !* factor to make them integer*2 data. *
2717 !* *
2718 !* The output water vapor file is in BSQ format. It has a 512-byte *
2719 !* SIPS header. It contains 1 channel with each pixel value *
2720 !* representing the column water vapor amount in units of cm *
2721 !* multiplied by a scale factor of 1000 to make the values *
2722 !* integer*2. *
2723 !* *
2724 !* Globals used: NSAMPS,NLINES,NBANDS - Input image dimensions used in I/O and *
2725 !* cube processing. *
2726 !* FPIN - File pointer for input cube passed to rdslice() *
2727 !* FPOCUB - File pointer for output cube passed to wtslice() *
2728 !* FPOH2O - File pointer for water vapor image passed to wtslice() *
2729 !* SPATIAL,ST_SAMPLE,ST_ROW,SAMPLES_TODO,ROWS_TODO,ISLICE,DIMS - Cube *
2730 !* dimensions used in rdslice() and wtslice(). *
2731 !* BUFFER - Holds the slice of data read by rdslice() and written by *
2732 !* wtslice(). *
2733 !* H2OBUF - Holds the water vapor image. *
2734 !* Global output: None. *
2735 !* Return Codes: None. *
2736 !* Special Considerations: None. *
2737 !* *
2738 !********************************************************************************
2739  SUBROUTINE process_cube
2741  use cubeio
2742 
2743  INTEGER LUN_IN, LUN_OUT, LUN_VAP, I_RET
2744  COMMON /inout_units/ lun_in, lun_out, lun_vap
2745 
2746 !C Common variables
2747  dimension yy(1024) ! Observed radiances
2748 
2749 !C parameters for cube I/O
2750  CHARACTER (LEN = 1000) :: FINAV,FOCUB,FOH2O
2751  INTEGER*2 BUFFER(8388608)
2752  INTEGER*2 H2OBUF(8388608)
2753  INTEGER SORDER,HDREC
2754 
2755  INTEGER I_Sample, J_Line
2756 
2757 !C Local variables
2758  REAL TBUF(1024)
2759  INTEGER OFFSET
2760 
2761  INTEGER J, ISAMP, IBAND
2762  real*4 scalef,clmwvp
2763 
2764  dimension yirr(1024)
2765  COMMON /solar_irr1/yirr !RJH
2766  DATA pi/3.1415926535897/ !RJH
2767 !C Putting these large arrays in global memory forces memory allocation at
2768 !C program initialization. Otherwise, the program chokes on the first
2769 !C call to PROCESS_CUBE.
2770 !C--- COMMON /DUMMYGLOB/ BUFFER,H2OBUF
2771 
2772  COMMON /proccube1/ yy
2773  COMMON /getinput11/hdrec,nsamps,nlines,nbands,sorder
2774  COMMON /getinput12/scalef
2775 
2776 !C Commons for use with the C programs for cube I/O
2777  COMMON /outcube/ focub
2778  COMMON /incube/ finav
2779  COMMON /outh2ovap/ foh2o
2780  COMMON /rjhdebug/ const1,const2,const3,const4,const5,const6, &
2781  r094co, r114co, jb
2782  COMMON /init_speccal8/ wt1,wt2,wt3,wt4,ja
2783  COMMON /init_speccal6/ ist1,ied1,ist2,ied2,istp94,iedp94
2784  open(90,file='atrem_yy_pix512line2000_before.txt',form='formatted')
2785  open(91,file='atrem_yy_pix512line2000_after.txt',form='formatted')
2786 
2787 !C Read input cube one slice at a time into the array BUFFER.
2788 !C BUFFER contains a spectral slice of data. The first NBANDS elements are
2789 !C the first spectrum, the second NBANDS elements are the second spectrum, etc
2790 !C Process each spectrum, then write to output file one slice at a time.
2791  DO 11 j=1,nlines
2792 
2793 !C Let us know the progress of program.
2794 ! WRITE(*,*)'LINE=',J
2795 
2796 !C-Note: BUFFER is now passed in through COMMON /DUMMYGLOB/ BUFFER,H2OBUF
2797 !C for reducing the required total computer memory
2798 !C--- CALL RD_SPECTRAL_SLICE(J,HDREC,NSAMPS,NLINES,NBANDS,
2799 !C--- & SORDER)
2800 ! CALL RD_SLICE(LUN_IN,NSAMPS,NBANDS,SORDER,BUFFER)
2801 
2802 !C For each spectrum in the slice, assign it to the YY array, and use it in
2803 !C REFLDRV to create a surface reflectance spectrum.
2804  DO 46 isamp= 1,nsamps
2805  offset = (isamp-1) * nbands
2806  DO 45 iband=1,nbands ! fill YY array with this spectrum
2807  yy(iband) = buffer(offset + iband)
2808  45 CONTINUE
2809 
2810 !C Write out sample input spectrum.
2811  IF((isamp.EQ.512).AND.(j.EQ.2000)) THEN
2812 !C WRITE(90,*)'Islice=3, Isamp=2, Spectrum before REFLDRV'
2813  DO 49 i=1,nbands
2814  49 WRITE(90,*) i,isamp,j,pi*yy(i)/(50*yirr(i)) !HICO CORRECTION
2815 
2816  ENDIF
2817 
2818  CALL app_refl_with_gas_removal_drv(clmwvp)
2819 !C IF((ISAMP.EQ.512).AND.(J.EQ.2000)) THEN
2820 !C WRITE(91,*)'Islice=3, Isamp=2, Spectrum before REFLDRV'
2821  DO i=1,nbands
2822  WRITE(91,'(3i5,9F9.4,4I5)') i,isamp,j,yy(i), &
2823  r094co,r114co,const1,const2,const3, &
2824  const4,const5,const6,ja,jb,ist2,ied2
2825  end do
2826 !C ENDIF
2827 !C--- CALL REFLDRV(CLMWVP)
2828 
2829 !C The YY array now contains true surface reflectance values. Multiply
2830 !C by input scale factor to convert values to integer*2 format.
2831  DO 55 iband=1,nbands
2832  tbuf(iband)=scalef*yy(iband)
2833  buffer(offset + iband) = nint(tbuf(iband))
2834  55 CONTINUE
2835 
2836 !C Save the water vapor amount (also scaled by 1000 to convert to integer*2).
2837 !C Later, H2OBUF will be written to the water vapor output file.
2838 
2839  h2obuf(isamp) = nint(1000.*clmwvp)
2840 
2841 !C Write out sample processed spectrum.
2842 !C--D IF((ISAMP.EQ.2).AND.(J.EQ.3)) THEN
2843 !C--D WRITE(*,*)'Islice=3, Isamp=2, Spectrum after App_Refl_DRV'
2844 !C--D DO 48 I=1,NBANDS
2845 !C--D WRITE(*,*)'I=',I,' YY(I)=',YY(I)
2846 !C--D 48 WRITE(*,*)'I=',I,' TBUF(I)=',TBUF(I)
2847 !C--D ENDIF
2848 
2849  46 CONTINUE
2850 
2851 !C Write slice BUFFER to output file. The output file is the same storage order
2852 !C as the input file, and it always has a header that is one record (512 bytes).
2853 !C-Note: BUFFER is now passed through COMMON /DUMMYGLOB/ BUFFER,H2OBUF
2854 !C--- CALL WT_SPECTRAL_SLICE(FPOCUB,J,512,NSAMPS,NLINES,NBANDS,
2855 !C--- & SORDER)
2856 
2857 ! CALL WT_SLICE(LUN_OUT,NSAMPS,NBANDS,SORDER,BUFFER)
2858 !
2859 ! CALL WT_LINE(LUN_VAP,NSAMPS,H2OBUF)
2860 
2861  11 CONTINUE
2862 
2863 !C Write the water vapor image to a file. The file is one spatial image
2864 !C with one header record (512 bytes).
2865 !C-Note: H2OBUF is now passed through COMMON /DUMMYGLOB/ BUFFER,H2OBUF
2866 !C--- CALL WT_SPATIAL_SLICE(FPOH2O,1,512,NSAMPS,NLINES,NBANDS,0)
2867 
2868 ! CALL CLOSEINFILE(LUN_IN)
2869 ! CALL CLOSEOUTFILE(LUN_OUT)
2870 ! CALL CLOSEVAPFILE(LUN_VAP)
2871 
2872 ! close(90)
2873 ! close(91)
2874  RETURN
2875  END
2876 
2877 !********************************************************************************
2878 !* *
2879 !* Name: App_Refl_With_Gas_Removal_DRV *
2880 !* Purpose: To derive column water vapor amount and apparent reflectance curve *
2881 !* with atmospheric gaseous absorption effect removed from an input *
2882 !* spectrum using a 3-channel ratioing technique. *
2883 !* Parameters: none *
2884 !* Algorithm: the algorithm includes following procedures: *
2885 !* 1. An input radiance spectrum is divided by a solar radiance curve above *
2886 !* the atmosphere to derive 'APPARENT REFLECTANCE SPECTRUM T(Lambda)'*
2887 !* 2. Two 3-channel ratios: T(0.94 um)/(WT1*T(0.86)+WT2*T(1.02)) *
2888 !* and T(1.14 um)/(WT3*T(1.05)+WT4*T(1.23)), are calculated from *
2889 !* the observed spectrum T(Lambda). *
2890 !* 3. Based on the two ratios using look-up table procedures plus linear *
2891 !* interpolation techniques, the column water vapor values and the *
2892 !* atmospheric transmittance spectrum are derived. *
2893 !* 4. The apparent reflectance spectrum is divided by the calculated *
2894 !* transmittance spectrum to remove atmospheric gaseous absorption *
2895 !* features. *
2896 !* 5. The output apprent reflectance spectrum with atmospheric gaseous *
2897 !* absorption effect is smoothed if desired. *
2898 !* Globals used: *
2899 !* Global output: *
2900 !* Return Codes: none *
2901 !* Special Considerations: None *
2902 !* *
2903 !********************************************************************************
2904 
2905  SUBROUTINE app_refl_with_gas_removal_drv(CLMWVP)
2906 
2907 !C Common variables
2908  dimension vaptot(60), r0p94(60), r1p14(60), trntbl(1024,60)
2909  dimension yirr(1024)
2910  dimension yy(1024)
2911  dimension rr(1024)
2912  dimension rotot(1050), ttot(1050), stot(1050)
2913  dimension finst2(100)
2914  dimension ssh2o(60)
2915  dimension trncal(1024)
2916 
2917 !C Local variables
2918  dimension trncv(1024)
2919 
2920  COMMON /getinput5/ nobs,hsurf,dlt,dlt2
2921  COMMON /getinput7/ nb1,nb2,nbp94,nb3,nb4,nb1p14
2922  COMMON /getinput8/ imn,idy,iyr,ih,im,is
2923  COMMON /geometry2/ gco2,go3,gn2o,gco,gch4,go2,ssh2o,totlo3,ggeom
2924  COMMON /init_speccal3/ nh2o
2925  COMMON /init_speccal6/ ist1,ied1,ist2,ied2,istp94,iedp94
2926  COMMON /init_speccal7/ ist3,ied3,ist4,ied4,ist1p14,ied1p14
2927  COMMON /init_speccal8/ wt1,wt2,wt3,wt4,ja
2928  COMMON /init_speccal10/ ncv2,ncvhf2,ncvtt2,istrt2,iend2,finst2
2929  COMMON /init_speccal11/ natot,nbtot,nctot,ndtot
2930  COMMON /tran_table1/ sh2o,vaptot,r0p94,r1p14,trntbl
2931  COMMON /trancal1/ trncal,vaptt
2932  COMMON /solar_irr1/yirr
2933  COMMON /proccube1/ yy
2934  COMMON /sixs1/ rotot, ttot, stot
2935  COMMON /rjhdebug/ const1,const2,const3,const4,const5,const6, &
2936  r094co, r114co, jb
2937  dimension g_vap(25), g_other(25)
2938  COMMON /geometry3/ g_vap, g_other, g_vap_equiv, vap_slant_mdl
2939 
2940 !C Parameters for plane observations:
2941  CHARACTER (LEN = 80) :: NAME_INSTRU, NAMES(10)
2942  COMMON /getinput13/ name_instru, names
2943 
2944 !C Arrays related to look-up table:
2945 !C VAPTOT: TOTAL SUN-SURFACE-SENSOR PATH WATER VAPOR IN UNITS OF CM
2946 !C R0P94 : Tc(0.94 um)/(WT1*Tc(0.86)+WT2*Tc(1.02))
2947 !C R1P14 : Tc(1.14 um)/(WT3*Tc(1.05)+WT4*Tc(1.23))
2948 
2949  dimension speca(1024),specb(1024),specav(1024)
2950 
2951  integer*4 itmp1
2952  real*4 xfa
2953  real*4 xfb
2954  real*4 xfc
2955  real*4 xfd
2956 
2957  DATA pi,dtorad /3.1415926,0.0174533/
2958 
2959 !C
2960 !C Loops for processing image data cube ...
2961  IF((name_instru.EQ.names(1)).AND.(iyr.LE.2009)) THEN
2962 
2963 !C Ratioing observed spectrum against solar irradiance curve.
2964 !C The radiance data from each year is scaled by a different constant.
2965 !C XFA = factor for A spectrometer
2966 !C XFB = factor for B spectrometer
2967 !C XFC = factor for C spectrometer
2968 !C XFD = factor for D spectrometer
2969 !C
2970 !C rewritten to handle each spectrometer differently
2971 !C 9/14/1995 Roger N. Clark, U.S.G.S.
2972 
2973  IF(iyr.LE.1989) THEN
2974  xfa = 10.0
2975  xfb = 10.0
2976  xfc = 10.0
2977  xfd = 10.0
2978  ENDIF
2979 
2980  IF((iyr.GE.1990).AND.(iyr.LE.1991)) THEN
2981  xfa = 20.0
2982  xfb = 20.0
2983  xfc = 20.0
2984  xfd = 20.0
2985  ENDIF
2986 
2987  IF((iyr.GE.1992).AND.(iyr.LE.1994)) THEN
2988  xfa = 50.0
2989  xfb = 50.0
2990  xfc = 50.0
2991  xfd = 50.0
2992  ENDIF
2993 
2994  IF((iyr.GE.1995).AND.(iyr.LE.2009)) THEN
2995  xfa = 50.0
2996  xfb = 50.0
2997  xfc = 50.0
2998  xfd = 100.0
2999  ENDIF
3000 
3001 !C AVIRIS A Spectrometer (ch = 1-32)
3002 
3003  IF(nobs.GE.32) THEN
3004  itmp1 = 32
3005  ELSE
3006  itmp1 = nobs
3007  ENDIF
3008 
3009  DO 551 i=1,itmp1
3010  yy(i)=pi*yy(i)/(xfa*yirr(i))
3011  551 CONTINUE
3012 
3013 !C AVIRIS B Spectrometer (ch = 33-96)
3014 
3015  IF(nobs.GE.96) THEN
3016  itmp1 = 96
3017  ELSE if ((nobs.GE.33).and.(nobs.LT.96)) THEN
3018  itmp1 = nobs
3019  ELSE
3020  go to 559
3021  ENDIF
3022 
3023  DO 552 i=33,itmp1
3024  yy(i)=pi*yy(i)/(xfb*yirr(i))
3025  552 CONTINUE
3026 
3027 !C AVIRIS C Spectrometer (ch = 97-160)
3028 
3029  IF(nobs.GE.160) THEN
3030  itmp1 = 160
3031  ELSE if ((nobs.GE.97).and.(nobs.LT.160)) THEN
3032  itmp1 = nobs
3033  ELSE
3034  go to 559
3035  ENDIF
3036 
3037  DO 553 i=97,itmp1
3038  yy(i)=pi*yy(i)/(xfc*yirr(i))
3039  553 CONTINUE
3040 
3041 !C AVIRIS D Spectrometer (ch = 161-224)
3042 
3043  IF(nobs.GE.161) THEN
3044  itmp1 = nobs
3045  ELSE
3046  go to 559
3047  ENDIF
3048 
3049  DO 554 i=161,itmp1
3050  yy(i)=pi*yy(i)/(xfd*yirr(i))
3051  554 CONTINUE
3052 
3053 !C branch point in case not all spectrometers are being done.
3054  559 CONTINUE
3055 
3056 !C End of R. Clark contribution
3057  END IF
3058 !C
3059 !C Loops for processing AVIRIS data starting from year 2010---
3060  IF((name_instru.EQ.names(1)).AND.(iyr.GE.2010)) THEN
3061 
3062  f_av_1 = 30.
3063  f_av_2 = 60.
3064  f_av_3 = 120.
3065 
3066  DO i = 1, 110
3067  yy(i) = pi*yy(i) / (f_av_1 * yirr(i))
3068  END DO
3069 
3070  DO i = 111, 160
3071  yy(i) = pi*yy(i) / (f_av_2 * yirr(i))
3072  END DO
3073 
3074  DO i = 161, 224
3075  yy(i) = pi*yy(i) / (f_av_3 * yirr(i))
3076  END DO
3077 
3078  END IF
3079 
3080 !C Loops for processing HYDICE data ...
3081 !C
3082  IF(name_instru.EQ.names(2)) THEN
3083 
3084  f_hydice = 75.
3085 
3086  DO i = 1, nobs
3087  yy(i) = pi*yy(i) / (f_hydice * yirr(i))
3088  END DO
3089 
3090  END IF
3091 
3092 
3093 !C Loops for processing HSI data ...
3094 !C
3095  IF(name_instru.EQ.names(3)) THEN
3096 
3097  f_hsi = 100.
3098 
3099  DO i = 1, nobs
3100  yy(i) = pi*yy(i) / (f_hsi * yirr(i))
3101  END DO
3102 
3103  END IF
3104 
3105 
3106 !C Loops for processing TRWIS-III data ...
3107 !C
3108  IF(name_instru.EQ.names(4)) THEN
3109 
3110  f_trwis = 100.
3111 
3112  DO i = 1, nobs
3113  yy(i) = pi*yy(i) / (f_trwis * yirr(i))
3114  END DO
3115 
3116  END IF
3117 
3118 !C Loops for processing EO-1 Hyperion data ...
3119 !C
3120  IF(name_instru.EQ.names(6)) THEN
3121 
3122  f_hyperion_a = 40.
3123  f_hyperion_b = 80.
3124 
3125  DO i = 1, 70
3126  yy(i) = pi*yy(i) / (f_hyperion_a * yirr(i))
3127  END DO
3128 
3129  DO i = 71, nobs
3130  yy(i) = pi*yy(i) / (f_hyperion_b * yirr(i))
3131  END DO
3132 
3133  END IF
3134 
3135 !C Loops for processing HICO data ...
3136 !C
3137  IF(name_instru.EQ.names(7)) THEN
3138 
3139 !C--- F_HICO = 50./1.32
3140  f_hico = 50.
3141 
3142  DO i = 1, nobs
3143  yy(i) = pi*yy(i) / (f_hico * yirr(i))
3144  END DO
3145 
3146  END IF
3147 
3148 !C Loops for processing NIS (NEON Imaging Spectrometer) data ...
3149 !C
3150  IF(name_instru.EQ.names(8)) THEN
3151 
3152  f_nis = 100.
3153 
3154  DO i = 1, nobs
3155  yy(i) = pi*yy(i) / (f_nis * yirr(i))
3156  END DO
3157 
3158  END IF
3159 
3160 !C Loops for processing PRISM Imaging Spectrometer data ...
3161 !C
3162  IF(name_instru.EQ.names(9)) THEN
3163 
3164  f_prism = 100.
3165 
3166  DO i = 1, nobs
3167  yy(i) = pi*yy(i) / (f_prism * yirr(i))
3168  END DO
3169 
3170  END IF
3171 
3172 !C
3173 !C Calculating 3-channel ratios from an observed spectrum, using a
3174 !C look-up table procedure to derive the column amount of water vapor
3175 !C and to find the associated simulated transmittance spectrum.
3176  const1=0.0
3177  DO 560 i=ist1,ied1
3178  const1=const1+yy(i)
3179  560 CONTINUE
3180  const1=const1/float(nb1)
3181 
3182  const2=0.0
3183  DO 570 i=ist2,ied2
3184  const2=const2+yy(i)
3185  570 CONTINUE
3186  const2=const2/float(nb2)
3187 
3188  const3=0.0
3189  DO 575 i=istp94,iedp94
3190  const3=const3+yy(i)
3191  575 CONTINUE
3192  const3=const3/float(nbp94)
3193 
3194  r094co=const3/((wt1*const1) + (wt2*const2))
3195  r094c =r094co
3196 
3197  IF(r094co.GT.1.0) THEN
3198  const1=0.0
3199  DO 561 i=ist1,ied1
3200  const1=const1+1.0/yy(i)
3201  561 CONTINUE
3202  const1=const1/float(nb1)
3203 
3204  const2=0.0
3205  DO 571 i=ist2,ied2
3206  const2=const2+1.0/yy(i)
3207  571 CONTINUE
3208  const2=const2/float(nb2)
3209 
3210  const3=0.0
3211  DO 576 i=istp94,iedp94
3212  const3=const3+1.0/yy(i)
3213  576 CONTINUE
3214  const3=const3/float(nbp94)
3215 
3216  r094c=const3/((wt1*const1) + (wt2*const2))
3217  ENDIF
3218 
3219  const4=0.0
3220  DO 580 i=ist3,ied3
3221  const4=const4+yy(i)
3222  580 CONTINUE
3223  const4=const4/float(nb3)
3224 
3225  const5=0.0
3226  DO 590 i=ist4,ied4
3227  const5=const5+yy(i)
3228  590 CONTINUE
3229  const5=const5/float(nb4)
3230 
3231  const6=0.0
3232  DO 595 i=ist1p14,ied1p14
3233  const6=const6+yy(i)
3234  595 CONTINUE
3235  const6=const6/float(nb1p14)
3236 
3237  r114co=const6/((wt3*const4) + (wt4*const5))
3238  r114c =r114co
3239 
3240  IF(r114co.GT.1.0) THEN
3241  const4=0.0
3242  DO 581 i=ist3,ied3
3243  const4=const4+1.0/yy(i)
3244  581 CONTINUE
3245  const4=const4/float(nb3)
3246 
3247  const5=0.0
3248  DO 591 i=ist4,ied4
3249  const5=const5+1.0/yy(i)
3250  591 CONTINUE
3251  const5=const5/float(nb4)
3252 
3253  const6=0.0
3254  DO 596 i=ist1p14,ied1p14
3255  const6=const6+1.0/yy(i)
3256  596 CONTINUE
3257  const6=const6/float(nb1p14)
3258 
3259  r114c=const6/((wt3*const4) + (wt4*const5))
3260  ENDIF
3261 
3262  CALL hunt(r0p94,nh2o,r094c,ja)
3263  IF (ja.GT.0.AND.ja.LT.60) THEN
3264  dlta =r0p94(ja+1)-r0p94(ja)
3265  fja =(r0p94(ja+1)-r094c)/dlta
3266  fjap1 =(r094c-r0p94(ja))/dlta
3267 
3268  vaptta=fja*vaptot(ja)+fjap1*vaptot(ja+1)
3269  IF(r094co.GT.1.) vaptta=-vaptta
3270  ELSE
3271  IF(ja.LE.0) vaptta = vaptot(ja+1)
3272  IF(ja.GE.60) vaptta = vaptot(ja)
3273  ENDIF
3274 
3275  IF(r094co.LE.1.)THEN
3276  DO 900 i=1,nobs
3277  IF (ja.GT.0.AND.ja.LT.60) THEN
3278  speca(i)=fja*trntbl(i,ja)+fjap1*trntbl(i,ja+1)
3279  ELSE
3280  IF(ja.LE.0) speca(i)=trntbl(i,ja+1)
3281  IF(ja.GE.60) speca(i)=trntbl(i,ja)
3282  ENDIF
3283  900 CONTINUE
3284  ENDIF
3285 
3286  IF(r094co.GT.1.)THEN
3287  DO 901 i=1,nobs
3288  IF (ja.GT.0.AND.ja.LT.60) THEN
3289  speca(i)=1.0/(fja*trntbl(i,ja)+fjap1*trntbl(i,ja+1))
3290  ELSE
3291  IF(ja.LE.0) speca(i)=1.0/trntbl(i,ja+1)
3292  IF(ja.GE.60) speca(i)=1.0/trntbl(i,ja)
3293  ENDIF
3294  901 CONTINUE
3295  ENDIF
3296 
3297  jb = ja
3298  CALL hunt(r1p14,nh2o,r114c,jb)
3299  IF (jb.GT.0.AND.jb.LT.60) THEN
3300  dltb =r1p14(jb+1)-r1p14(jb)
3301  fjb =(r1p14(jb+1)-r114c)/dltb
3302  fjbp1 =(r114c-r1p14(jb))/dltb
3303 
3304  vapttb=fjb*vaptot(jb)+fjbp1*vaptot(jb+1)
3305  IF(r114co.GT.1.) vapttb=-vapttb
3306  ELSE
3307  IF(jb.LE.0) vapttb = vaptot(jb+1)
3308  IF(jb.GE.60) vapttb = vaptot(jb)
3309  ENDIF
3310 
3311  IF(r114co.LE.1.)THEN
3312  DO 910 i=1,nobs
3313  IF (jb.GT.0.AND.jb.LT.60) THEN
3314  specb(i)=fjb*trntbl(i,jb)+fjbp1*trntbl(i,jb+1)
3315  ELSE
3316  IF(jb.LE.0) specb(i)=trntbl(i,jb+1)
3317  IF(jb.GE.60) specb(i)=trntbl(i,jb)
3318  ENDIF
3319  910 CONTINUE
3320  ENDIF
3321 
3322  IF(r114co.GT.1.)THEN
3323  DO 911 i=1,nobs
3324  IF (jb.GT.0.AND.jb.LT.60) THEN
3325  specb(i)=1.0/(fjb*trntbl(i,jb)+fjbp1*trntbl(i,jb+1))
3326  ELSE
3327  IF(jb.LE.0) specb(i)=1.0/trntbl(i,jb+1)
3328  IF(jb.GE.60) specb(i)=1.0/trntbl(i,jb)
3329  ENDIF
3330  911 CONTINUE
3331  ENDIF
3332 
3333 !C--- CLMWVP=0.5*(VAPTTA+VAPTTB)/GGEOM
3334  clmwvp=0.5*(vaptta+vapttb)/g_vap_equiv
3335 !C
3336 !C Derivation of surface reflectances
3337  DO 915 i=1,nobs
3338  specav(i)=0.5*(speca(i)+specb(i))
3339 !C--- TRNTMP=(YY(I)/SPECAV(I))-ROTOT(I)
3340 !C--- YY(I)=TRNTMP/(TTOT(I)+(STOT(I)*TRNTMP))
3341  yy(i) = yy(i) / specav(i)
3342  915 CONTINUE
3343 !C
3344 !C-- print*, 'i, rotot(i), ttot(i), stot(i)'
3345 !C-- DO I = 1, NOBS
3346 !C-- print*, i, rotot(i), ttot(i), stot(i)
3347 !C-- END DO
3348 
3349 !C
3350 !C Smooth the derived surface reflectance spectra
3351 
3352  IF(dlt2.GT.dlt) THEN
3353 !C
3354 !C First, replace radiances <= 0 near the spectral overlapping parts of the
3355 !C four AVIRIS spectrometers by radiances in the nearby AVIRIS' channels.
3356  DO 920 i=natot-2,natot+2
3357  IF(yy(i).LE.0.0) yy(i)=yy(i-1)
3358  920 CONTINUE
3359 
3360  DO 921 i=nbtot-2,nbtot+2
3361  IF(yy(i).LE.0.0) yy(i)=yy(i-1)
3362  921 CONTINUE
3363 
3364  DO 922 i=nctot-4,nctot+4
3365  IF(yy(i).LE.0.0) yy(i)=yy(i-1)
3366  922 CONTINUE
3367 
3368  DO 923 i=ndtot-7,nobs
3369  IF(yy(i).LE.0.0) yy(i)=yy(i-1)
3370  923 CONTINUE
3371 
3372  DO 3480 i=istrt2,iend2
3373  trncv(i)=0.0
3374  ii=i-ncv2
3375  DO 3490 j=i-ncv2,i+ncv2
3376  trncv(i)=trncv(i)+yy(j)*finst2(j-ii+1)
3377  3490 CONTINUE
3378  3480 CONTINUE
3379  DO 3495 i=istrt2,iend2
3380  yy(i)=trncv(i)
3381  3495 CONTINUE
3382  ENDIF
3383 
3384  RETURN
3385  END
3386 
3387 !********************************************************************************
3388 !* *
3389 !* Name: LOCATE *
3390 !* Purpose: given an array XX of length N, and given a value X, returns a value*
3391 !* J such that X is between XX(J) and XX(J+1). XX must be monotonic, *
3392 !* Parameters: XX - monotonic array of values *
3393 !* N - number of elements in XX *
3394 !* X - value that will be matched to the XX array *
3395 !* J - index into the XX array where XX(J) <= X <= XX(J+1) *
3396 !* Algorithm: bisectional table searching, copied from Numerical Recipes. *
3397 !* Globals used: none *
3398 !* Global output: none *
3399 !* Return Codes: J=0 or J=N is returned to indicate that X is out of range *
3400 !* Special Considerations: none *
3401 !* *
3402 !********************************************************************************
3403  SUBROUTINE locate(xx,n,x,j)
3404  INTEGER j,n
3405  REAL x,xx(n)
3406  INTEGER jl,jm,ju
3407  jl=0
3408  ju=n+1
3409 10 if(ju-jl.gt.1)then
3410  jm=(ju+jl)/2
3411  if((xx(n).ge.xx(1)).eqv.(x.ge.xx(jm)))then
3412  jl=jm
3413  else
3414  ju=jm
3415  endif
3416  goto 10
3417  endif
3418  if(x.eq.xx(1))then
3419  j=1
3420  else if(x.eq.xx(n))then
3421  j=n-1
3422  else
3423  j=jl
3424  endif
3425  return
3426  END
3427 
3428 !********************************************************************************
3429 !* *
3430 !* Name: CUBSPLN *
3431 !* Purpose: an interface for performing cubic spline interpolations. *
3432 !* Parameters: N - number of elements in XORGN, YORGN *
3433 !* XORGN - original x values *
3434 !* YORGN - original y values *
3435 !* XINT - interpolated x values *
3436 !* YINT - interpolated y values *
3437 !* Algorithm: Straight forward calculations *
3438 !* Globals used: NOBS - number of spectral points. *
3439 !* Global output: none *
3440 !* Return Codes: none *
3441 !* Special Considerations: none *
3442 !* *
3443 !********************************************************************************
3444 
3445  SUBROUTINE cubspln(N,XORGN,YORGN,XINT,YINT)
3447  dimension xorgn(1050),yorgn(1050),y2(1050)
3448  dimension xint(1024),yint(1024)
3449  INTEGER N !number of elements in XORGN,YORGN
3450 
3451  COMMON /getinput5/ nobs,hsurf,dlt,dlt2
3452 !C
3453 !C YP1 and YP2 are two parameters specifying the values of 2nd derivatives at
3454 !C XORGN(1) and XORGN(N) and were used in cubic spline interpolations. The
3455 !C setting of both YP1 and YP2 to 2.0E30 is equivalent to set the 2nd
3456 !C derivatives at the two boundaries as zero, according to Numeric Recipes.
3457  yp1=2.0e30
3458  ypn=2.0e30
3459 
3460  CALL spline(xorgn,yorgn,n,yp1,ypn,y2)
3461 
3462  DO 320 i=1,nobs
3463  x=xint(i)
3464  CALL splint(xorgn,yorgn,y2,n,x,y)
3465  IF(y.LT.0.0) y=0.0
3466  yint(i)=y
3467 
3468  320 CONTINUE
3469 
3470  RETURN
3471  END
3472 !
3473 !********************************************************************************
3474 !* *
3475 !* Name: SPLINE *
3476 !* Purpose: program for cubic spline interpolation --- copyed from Numerical *
3477 !* Recipes, p.88-89 *
3478 !* Parameters: X - x-values *
3479 !* Y - y-values *
3480 !* N - length of X *
3481 !* YP1 - 2nd derivative at X(1) *
3482 !* YPN - 2nd derivative at X(N) *
3483 !* Y2 - 2nd derivatives at all X positions *
3484 !* Algorithm: Given arrays X and Y of length N containing a tabulated function,*
3485 !* i.e.,Yj=f(Xj), with X1 < X2...<XN, and given values YP1 and YPN for *
3486 !* the first derivative of the interpolating function at points 1 *
3487 !* and N, respectively, this routine returns an array Y2 of length N *
3488 !* which contains the second derivatives of the interpolating function *
3489 !* at the tabulated points Xj. If YP1 and/or YPN are equal to 1.0E30 or *
3490 !* larger, the routine is signalled to set the corresponding boundary *
3491 !* condition for a natural spline, with zero second derivative on *
3492 !* that boundary. *
3493 !* Globals used: none *
3494 !* Global output: none *
3495 !* Return Codes: none *
3496 !* Special Considerations: none *
3497 !* *
3498 !********************************************************************************
3499 
3500  subroutine spline(x,y,n,yp1,ypn,y2)
3501  parameter(nmax=1050)
3502  integer n,i,k
3503  real x(n),y(n),y2(n),u(nmax)
3504  real yp1,ypn,sig,p,qn,un
3505  if (yp1.gt..99e30) then
3506  y2(1)=0.
3507  u(1)=0.
3508  else
3509  y2(1)=-0.5
3510  u(1)=(3./(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)
3511  endif
3512  do 11 i=2,n-1
3513  sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))
3514  p=sig*y2(i-1)+2.
3515  y2(i)=(sig-1.)/p
3516  u(i)=(6.*((y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1)) &
3517  /(x(i)-x(i-1)))/(x(i+1)-x(i-1))-sig*u(i-1))/p
3518 11 continue
3519  if (ypn.gt..99e30) then
3520  qn=0.
3521  un=0.
3522  else
3523  qn=0.5
3524  un=(3./(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))
3525  endif
3526  y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.)
3527  do 12 k=n-1,1,-1
3528  y2(k)=y2(k)*y2(k+1)+u(k)
3529 12 continue
3530  return
3531  end
3532 
3533 !********************************************************************************
3534 !* *
3535 !* Name: SPLINT *
3536 !* Purpose: calculate a cubic-spline interpolated Y value, -- copied from *
3537 !* Numerical Recipes. *
3538 !* Parameters: XA - original X array *
3539 !* YA - original Y array *
3540 !* Y2A - 2nd derivative array from SUBROUTINE SPLINE *
3541 !* N - number of X elements *
3542 !* X - an X position at which interpolation should be made *
3543 !* Y - interpolated y value at position X *
3544 !* Algorithm: Given the arrays XA and YA of length N, which tabulate a function*
3545 !* (with the XAj's in order), and given the array Y2A, which is the output *
3546 !* from SPLINE above, and given a value of X, this routine returns a *
3547 !* cubic-spline interpolated value Y. *
3548 !* Globals used: none *
3549 !* Global output: none *
3550 !* Return Codes: none *
3551 !* Special Considerations: SPLINE is called only once to process an entire *
3552 !* tabulated function in arrays Xi and Yi. Once this has been done, values *
3553 !* of the interpolated function for any value of X are obtained by calls *
3554 !* (as many as desired) to a separate routine SPLINT (for cubic spline *
3555 !* interpolation") *
3556 !* *
3557 !********************************************************************************
3558 
3559  subroutine splint(xa,ya,y2a,n,x,y)
3560  integer n,klo,khi,k
3561  real xa(n),ya(n),y2a(n)
3562  real x,y,h,a,b
3563  klo=1
3564  khi=n
3565 1 if (khi-klo.gt.1) then
3566  k=(khi+klo)/2
3567  if(xa(k).gt.x)then
3568  khi=k
3569  else
3570  klo=k
3571  endif
3572  goto 1
3573  endif
3574  h=xa(khi)-xa(klo)
3575  if (h.eq.0.) stop 'bad xa input.'
3576  a=(xa(khi)-x)/h
3577  b=(x-xa(klo))/h
3578  y=a*ya(klo)+b*ya(khi)+ &
3579  ((a**3-a)*y2a(klo)+(b**3-b)*y2a(khi))*(h**2)/6.
3580  return
3581  end
3582 
3583 !********************************************************************************
3584 !* *
3585 !* Name: HUNT *
3586 !* Purpose: finds the element in array XX that is closest to value X. Array AA*
3587 !* must be monotonic, either increasing or decreasing. *
3588 !* Parameters: XX - array to search *
3589 !* N - number of elements in the array *
3590 !* X - element to search for closest match *
3591 !* JLO - index of the closest matching element *
3592 !* Algorithm: this subroutine was copied from Numerical Recipes *
3593 !* Globals used: none *
3594 !* Global output: none *
3595 !* Return Codes: none *
3596 !* Special Considerations: none *
3597 !* *
3598 !********************************************************************************
3599 
3600  SUBROUTINE hunt(xx,n,x,jlo)
3601  INTEGER jlo,n
3602  REAL x,xx(n)
3603  INTEGER inc,jhi,jm
3604  LOGICAL ascnd
3605  ascnd=xx(n).ge.xx(1)
3606  if(jlo.le.0.or.jlo.gt.n)then
3607  jlo=0
3608  jhi=n+1
3609  goto 3
3610  endif
3611  inc=1
3612  if(x.ge.xx(jlo).eqv.ascnd)then
3613 1 jhi=jlo+inc
3614  if(jhi.gt.n)then
3615  jhi=n+1
3616  else if(x.ge.xx(jhi).eqv.ascnd)then
3617  jlo=jhi
3618  inc=inc+inc
3619  goto 1
3620  endif
3621  else
3622  jhi=jlo
3623 2 jlo=jhi-inc
3624  if(jlo.lt.1)then
3625  jlo=0
3626  else if(x.lt.xx(jlo).eqv.ascnd)then
3627  jhi=jlo
3628  inc=inc+inc
3629  goto 2
3630  endif
3631  endif
3632 3 if(jhi-jlo.eq.1)then
3633  if(x.eq.xx(n))jlo=n-1
3634  if(x.eq.xx(1))jlo=1
3635  return
3636  endif
3637  jm=(jhi+jlo)/2
3638  if(x.ge.xx(jm).eqv.ascnd)then
3639  jlo=jm
3640  else
3641  jhi=jm
3642  endif
3643  goto 3
3644  END
3645 
3646 !********************************************************************************
3647 !* *
3648 !* Name: SUNCOR *
3649 !* Purpose: computes at some reference time TZ the declination of the sun and *
3650 !* the hour angle-TZ. *
3651 !* Algorithm: At any time T, the local solar hour angle is HAZ+T(GMT)-XLONG, *
3652 !* where XLONG is the longitude measured positive west of Greenwich. *
3653 !* Both time and angles are in radians. To compute azimuth and *
3654 !* elevation at latitude XLAT, longitude XLONG, and time T, call *
3655 !* HAZEL(HAZ+T-XLONG,DEC,AZ,EL,XLAT). This routine was copied *
3656 !* from W. Mankin at NCAR, Boulder, CO. *
3657 !* Globals used: none *
3658 !* Global output: none *
3659 !* Return Codes: none *
3660 !* Special Considerations: none *
3661 !* *
3662 !********************************************************************************
3663 
3664  SUBROUTINE suncor(IDAY,MONTH,IYR,TZ,DEC,HAZ)
3666  jd=julian(iday,month,iyr)
3667  fjd=0.5+tz/6.283185307
3668  CALL solcor(jd,fjd,ras,dec,gsdt,bzero,pzero,solong)
3669  haz=gsdt-ras-tz
3670 
3671  RETURN
3672  END
3673 
3674 !********************************************************************************
3675 !* Name: SOLCOR *
3676 !* Purpose: A routine for solar geometry calculations --- copied from *
3677 !* W. Mankin at NCAR. *
3678 !* Parameters: none *
3679 !* Algorithm: This routine was supplied by W. Mankin at NCAR, Boulder, CO *
3680 !* Globals used: *
3681 !* Global output: *
3682 !* Return Codes: none *
3683 !* Special Considerations: none *
3684 !* *
3685 !********************************************************************************
3686  SUBROUTINE solcor(JD,FJD,RAS,DECS,GSDT,BZRO,P,SOLONG)
3688  pi=3.141592654
3689  d=(jd-2415020)+fjd
3690  iyr=d/365.25
3691  g=-.026601523+.01720196977*d-1.95e-15*d*d -2.*pi*iyr
3692  xlms=4.881627938+.017202791266*d+3.95e-15*d*d-2.*pi*iyr
3693  obl=.409319747-6.2179e-9*d
3694  ecc=.01675104-1.1444e-9*d
3695  f=d-365.25*iyr
3696  gsdt=1.739935476+2.*pi*f/365.25+1.342027e-4*d/365.25
3697  gsdt=gsdt+6.2831853*(fjd-0.5)
3698  xlts=xlms+2.*ecc*sin(g)+1.25*ecc*ecc*sin(2.*g)
3699  sndc=sin(xlts)*sin(obl)
3700  decs=asin(sndc)
3701  csra=cos(xlts)/cos(decs)
3702  ras=acos(csra)
3703  IF(sin(xlts).LT.0.) ras=2.*pi-ras
3704  omega=1.297906+6.66992e-7*d
3705  thetac=xlts-omega
3706  bzro=asin(.126199*sin(thetac))
3707  p=-atan(cos(xlts)*tan(obl))-atan(.127216*cos(thetac))
3708  xlmm=atan2(.992005*sin(thetac),cos(thetac))
3709  jdr=jd-2398220
3710  irot=(jdr+fjd)/25.38
3711  frot=(jdr+fjd)/25.38-irot
3712  solong=xlmm-2.*pi*frot+pi-3.e-4
3713  IF(solong.LT.0.) solong=solong+2.*pi
3714  IF(solong.GT.(2.*pi)) solong=solong-2.*pi
3715 
3716  RETURN
3717  END
3718 
3719 
3720 !********************************************************************************
3721 !* *
3722 !* Name: JULIAN *
3723 !* Purpose: computes the julian day *
3724 !* Parameters: IDAY - day of the year *
3725 !* MONTH - day of the year *
3726 !* Algorithm: This routine was supplied by William Mankin at NCAR, Boulder, CO *
3727 !* Globals used: none *
3728 !* Global output: none *
3729 !* Return Codes: none *
3730 !* Special Considerations: none *
3731 !* *
3732 !********************************************************************************
3733 
3734  FUNCTION julian(IDAY,MONTH,IYR)
3736 !C Local variables
3737  dimension md(12)
3738 
3739  DATA md/0,31,59,90,120,151,181,212,243,273,304,334/
3740 
3741  IF(iyr.LT.100) iyr=iyr+1900
3742  jyr=iyr-1600
3743  i1=jyr/400
3744  i2=(jyr-400*i1)/100
3745  i3=(jyr-400*i1-100*i2)/4
3746  julian=2305447+365*jyr+97*i1+24*i2+i3
3747  leap=0
3748  IF(mod(jyr,4).EQ.0) leap=1
3749  IF(mod(jyr,100).EQ.0) leap=0
3750  IF(mod(jyr,400).EQ.0) leap=1
3751 
3752 !C LEAP=1 if iyr is a leap year
3753  julian=julian+md(month)+iday
3754  IF(month.LE.2) julian=julian-leap
3755 
3756  RETURN
3757  END
3758 
3759 !********************************************************************************
3760 !* *
3761 !* Name: HAZEL *
3762 !* Purpose: Calculates azimuth and elevation *
3763 !* Parameters: none *
3764 !* Algorithm: This routine was supplied by William Mankin at NCAR, Boulder, CO *
3765 !* Globals used: None. *
3766 !* Global output: None. *
3767 !* Return Codes: None *
3768 !* Special Considerations: None. *
3769 !* *
3770 !********************************************************************************
3771  SUBROUTINE hazel (H,D,A,E,XLAT)
3773 !C H = HOUR ANGLE
3774 !C D = DECLINATION
3775 !C A = AZIMUTH
3776 !C E = ELEVATION
3777 !C XLAT = LATITUDE
3778 !C ALL ANGLES IN RADIANS
3779 
3780  pi = 3.14159265
3781  sne = sin(d)*sin(xlat)+cos(d)*cos(xlat)*cos(h)
3782  e=asin(sne)
3783  sna = cos(d)*sin(h)
3784  csa=(sin(xlat)*cos(h)*cos(d)-sin(d)*cos(xlat))
3785  a=atan2(sna,csa)+pi
3786  END
3787 
3788 !********************************************************************************
3789 !* *
3790 !* Name: FINDMATCH *
3791 !* Purpose: finds the closest match for ELEM in LIST *
3792 !* Parameters: LIST - array of values to match ELEM to. Elements is array *
3793 !* should increase in value. *
3794 !* Algorithm: linearly compare ELEM to each element. When ELEM is smaller *
3795 !* than the LIST(I), then it is assumed to be closest to LIST(I-1) *
3796 !* or LIST(I). The one that has the smallest absolute difference *
3797 !* to ELEM is returned as the closest match. *
3798 !* Globals used: none *
3799 !* Global output: none *
3800 !* Return Codes: the closest matching element index *
3801 !* Special Considerations: none *
3802 !* *
3803 !********************************************************************************
3804 
3805  FUNCTION findmatch(LIST,NOBS,ELEM)
3807  dimension list(1024)
3808  INTEGER nobs
3809  REAL elem,list
3810 
3811  DO 460 i=1,nobs
3812  IF(list(i).GT.elem) GOTO 470
3813  460 CONTINUE
3814  470 CONTINUE
3815  diff1=abs(list(i-1)-elem)
3816  diff2=abs(list(i)-elem)
3817  IF (diff1.LT.diff2) THEN
3818  findmatch=i-1
3819  ELSE
3820  findmatch=i
3821  ENDIF
3822 
3823  RETURN
3824  END
3825 !C--------1---------2---------3---------4---------5---------6---------7--
subroutine app_refl_with_gas_removal_drv(CLMWVP)
list(APPEND LIBS ${PGSTK_LIBRARIES}) add_executable(atteph_info_modis atteph_info_modis.c) target_link_libraries(atteph_info_modis $
Definition: CMakeLists.txt:7
subroutine suncor(IDAY, MONTH, IYR, TZ, DEC, HAZ)
subroutine tran_table
subroutine model_adj
int32_t hunt(double *xx, int32_t n, double x, int32_t jlo)
subroutine spline(s, x, y, n, in, t, il, iu, vl, vu, e, u)
Definition: phs.f:1348
subroutine get_input
subroutine cubspln(N, XORGN, YORGN, XINT, YINT)
subroutine process_cube
#define real
Definition: DbAlgOcean.cpp:26
void bzero()
subroutine trancal
README for MOD_PR03(V6.1.0) 2. POINTS OF CONTACT it can be either SDP Toolkit or MODIS Packet for Terra input files The orbit validation configuration parameter(LUN 600281) must be either "TRUE" or "FALSE". It needs to be "FALSE" when running in Near Real Time mode
subroutine init_speccal
#define re
Definition: l1_czcs_hdf.c:701
function findmatch(LIST, NOBS, ELEM)
subroutine chnlratio
Definition: jd.py:1
subroutine tt(NMAX, NCHECK)
Definition: ampld.lp.f:1852
subroutine tran_smooth
subroutine locate(xx, n, x, j)
Definition: cubeio.f90:1
Definition: names.f90:1
subroutine geometry
subroutine splint(xa, ya, y2a, n, x, y)
subroutine hazel(H, D, A, E, XLAT)
#define f
Definition: l1_czcs_hdf.c:702
logical function leap(YEAR)
Definition: leap.f:10
integer function julian(DAY, MONTH, YEAR)
Definition: julian.f:2
#define abs(a)
Definition: misc.h:90
subroutine solcor(JD, FJD, RAS, DECS, GSDT, BZRO, P, SOLONG)