OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
atrem_app_refl_plus_gas_removal_l2.f90
Go to the documentation of this file.
1 !------------------------------------------------------------------------------|
2 ! 2015 - Modifications for l2gen including speed enhancements by R. Healy |
3 ! (richard.healy@nasa.gov) |
4 ! The September 2012 version of atrem code, 'atrem_for_PRISM.f' (atrem for JPL |
5 ! PRISM Imaging Spectrometer, was obtained through modifying a 2011 |
6 ! version of 'atrem_f90_cubeio.f'. |
7 ! The March 2013 version of atrem code, 'atrem_for_PRISM_2013.f', was updated |
8 ! from the September 2012 version of atrem code. The upgrades include: |
9 ! a) replacing the MODTRAN 3.5 solar irradiance curve with a new solar curve|
10 ! constructed from the solar irradiance curve of Thuillier et al. 2004 |
11 ! ATLAS 3 (<=644.7 nm) and that of Kurucz 2005 (> 644.7 nm) built in |
12 ! MODTRAN 5.2. This newly contructed solar curve is more suited for |
13 ! modeling imaging imaging spectrometer data below 450 nm and with a |
14 ! spectral resolution finer than 5 nm; |
15 ! b) replacing high spectral resolution gas absorption tables with new |
16 ! tables calculated with the HITRAN2008+ line database and a fast |
17 ! line-by-line code originally developed by Bill Ridgway. After such |
18 ! upgrades, the retrieved surface reflectances near 1.45 and 1.95 micron |
19 ! are improved significantly; |
20 ! c) modifying volume mixing ratios of atmospheric carbon dioxide; |
21 ! d) applying a scaling factor for improved modeling of atmospheric |
22 ! oxygen band absorption centered near 1.265 micron. |
23 !------------------------------------------------------------------------------|
24 ! The 2001 version of ATREM code uses the new 'cubeio.f90' for I/O operations. |
25 ! The output data cubes have no headers, unlike the previous generations |
26 ! of ATREM codes containing 512 bytes of headers in output data cubes. |
27 !------------------------------------------------------------------------------|
28 !********************************************************************************
29 !* *
30 !* Name: atrem_app_refl_plus_gas_removal_2013 April, 2013 *
31 !* (ATmosphere REMoval Program) *
32 !* *
33 !* Author: Bo-Cai Gao, Remote Sensing Division, Code 7230, *
34 !* Naval Research Laboratory, Washington, DC 20375 USA *
35 !* *
36 !* Purpose: To derive surface reflectances from spectral imaging data collected *
37 !* by the Airborne Visible Infrared Imaging Spectrometer (AVIRIS), *
38 !* HYDICE, HSI, PHILLS, HICO, NIS, PRISM, and possibly other *
39 !* airborne and spaceborne imaging spectrometers, and to derive a *
40 !* column water vapor image for each scene. *
41 !* *
42 !* General Principles: In order to derive surface reflectances from image data *
43 !* cube, a thorough compensation for the atmospheric absorption and *
44 !* scattering is required. The spatial and temporal variations of *
45 !* atmospheric water vapor amounts pose difficulties in removing *
46 !* water vapor absorption features in data cube using standard *
47 !* atmospheric models. In this algorithm, the amount of water vapor *
48 !* on a pixel-by-pixel basis is derived from data cube themselves *
49 !* using the 0.94- and the 1.14-um water vapor bands and a *
50 !* three-channel ratioing technique. The derived water vapor *
51 !* values are then used for modeling water vapor absorption effects *
52 !* in the entire 0.4-2.5 um region. The absorption effects of *
53 !* well mixed atmospheric gases, such as CO2, N2O, CH4, and O2, *
54 !* are modeled using standard atmospheric models. A line-by-line *
55 !* code developed by W. Ridgway at NASA Goddard Space Flight Center *
56 !* is used to generate a database of gaseous absorption *
57 !* coefficients at high spectral resolution. This database and *
58 !* ozone cross sections and NO2 cross sections are used in *
59 !* calculating transmittances of eight atmospheric gases (H2O, CO2 *
60 !* O3, N2O, CO, CH4, O2, and NO2). The scattering effect is modeled *
61 !* using a modified version of 6S code (Vermote et al. 1996). *
62 !* *
63 !* Algorithm: 1. An input parameter file is read in and global data are *
64 !* initialized. *
65 !* 2. The solar zenith angle is derived based on the flight time *
66 !* and latitude and longitude of the scene. *
67 !* 3. A table consisting of transmittance spectra at the solar *
68 !* and observational geometry but with varying amounts of water *
69 !* vapor is created. *
70 !* The transmittance spectra for water vapor (H2O), carbon *
71 !* dioxide (CO2), ozone (O3), nitrous oxide (N2O), carbon *
72 !* monoxide (CO), methane (CH4), oxygen (O2), and nitrogen *
73 !* dioxide (NO2) in the 0.4-2.5 micron region are calculated. *
74 !* 4. Aerosol and molecular scattering terms are calculated using *
75 !* a modified version of the 6S code. *
76 !* 5. The image data cube (2D spatial and 1D spectral) are accessed *
77 !* one spectral slice at a time from an image file in any storage*
78 !* order, Band SeQuential (BSQ), Band Interleaved by Pixel (BIP),*
79 !* and Band Interleaved by Line (BIL). Each measured radiance *
80 !* spectrum is divided by the solar irradiance curve above the *
81 !* atmosphere to get apparent reflectances. *
82 !* 6. The integrated water vapor amount for each apparent *
83 !* reflectance spectrum is derived from the 0.94- and the 1.14-um*
84 !* water vapor absorption bands using a 3-channel ratioing *
85 !* technique and a look-up table procedure. *
86 !* 7. The surface reflectances are derived using another look-up *
87 !* table procedure. Routines written in C language are used to *
88 !* perform all the input/output operations. *
89 !* *
90 !* Limitations: *
91 !* 1. This algorithm works best for areas where the surface elevation *
92 !* does not vary by more than 1 km. *
93 !* 2. The algorithm works well only for measurements taken on clear *
94 !* days. For hazy days with large aerosol optical depths, the *
95 !* algorithm does not work nearly as well. *
96 !* 3. The algorithm does not work well over dark areas such as rivers *
97 !* and lakes. It does not perform corrections for "atmospheric *
98 !* adjacency" effects. *
99 !* 4. The algorithm assumes horizontal surfaces having Lambertian *
100 !* reflectances. *
101 !* 5. Additional work is needed to port this algorithm to different *
102 !* computing systems. This algorithm was developed on an SGI *
103 !* workstation and used FORTRAN statements to read several binary *
104 !* files. The binary file format on different computers can be *
105 !* different. The record lengths defined on an SGI machine are *
106 !* different from most other computers. Some of the Dec Alpha *
107 !* workstations use 8 bytes (64 bits) to store a C-pointer, instead *
108 !* of 4 bytes (32 bits). All these factors need to be taken into *
109 !* considerations when porting this algorithm to other computers. *
110 !* *
111 !* User Input: *
112 !* 1. Name - Imaging spectrometer name, e.g., AVIRIS, HYDICE, HSI, PHYLLS. *
113 !* 2. Plane altitude in km, above the sea level. *
114 !* 3. Date - The month, day, and year that the data were collected. *
115 !* 4. Time - The hour, minute, second (GMT) that the data were *
116 !* collected. *
117 !* 5. Latitude - The mean latitude of the measurement area in degrees, *
118 !* minutes, seconds, and hemisphere. *
119 !* 6. Longitude - The mean longitude of the measurement area in *
120 !* degrees, minutes, seconds, and hemisphere. *
121 !* 7. View zenith angle - the angle in degrees, minutes, and seconds *
122 !* between the viewing direction and nadir *
123 !* 8. View azimuth angle in degree, minutes and seconds. The view azimuth *
124 !* angle is defined as the angle between local North *
125 !* the view direction projected on the ground *
126 !* (clockwise count). This angle can vary from 0 *
127 !* to 360 deg. Ths definition here is consistent with*
128 !* navigator's convention, but not consistent with *
129 !* astronomer's convention. Here is an example: for *
130 !* a downward looking instrument pointed off-nadir *
131 !* to the West, the view azimuthal angle is 90 deg. *
132 !* Conversely, if the instrument is pointed toward *
133 !* East, the view azimuthal angle is 270 deg. *
134 !* *
135 !* 9. Resolution of input spectra in nm (~ 10 nm for AVIRIS) or "0" *
136 !* if the FWHM values (in micron) are present in the wavelength file *
137 !* 10. Filename of spectrometer wavelength table - 2 or 3 column ASCII data. *
138 !* The first column is the channel number, the second column is *
139 !* the wavelength and the optional third column is the FWHM value for *
140 !* each channel. *
141 !* 11. Channel ratio parameters - Center positions and widths of window and *
142 !* water vapor channels used in channel ratios for deriving *
143 !* the amount of water vapor from imaging data. Each of the window *
144 !* and water vapor channels typically consists of several narrow *
145 !* imaging spectrometer channels. *
146 !* 12. Atmospheric model - Temperature, pressure, water vapor volume mixing *
147 !* ratio profiles. The model can be either a predefined model or a *
148 !* user defined model. *
149 !* 13. Gases - An indication of which of the 8 gases (H2O, CO2, O3, *
150 !* N2O, CO, CH4, O2, and NO2) should be included in the spectral *
151 !* calculations. *
152 !* 14. Ozone - Column amount of O3 - changes with season and *
153 !* latitude. Typical value is .34 atm-cm. *
154 !* 15. Aerosol model number and visibility when measurements were taken. *
155 !* 16. Aerosol optical depth at 550 nm (Optional, only if visibility V *
156 !* is set to 0) *
157 !* 17. Surface elevation - The average surface elevation of an imaging scene *
158 !* in km. *
159 !* 18. Filename of input image file *
160 !* 19. Dimensions of input image. *
161 !* 20. Filename of output image file in same storage order as input file *
162 !* 21. Resolution of output surface reflectance spectra in micron *
163 !* 22. Scale factor for output reflectance values *
164 !* 23. Filename of output water vapor image. *
165 !* 24. Filename of output atmospheric transmittance look-up table *
166 !* *
167 !* Output: *
168 !* a. Output to user specified files: *
169 !* 1. Surface reflectance cube data - retrieved from the image data cube *
170 !* 2. Water vapor image - an image of the derived column water vapor *
171 !* amounts at each pixel. *
172 !* 3. Transmittance Look-up table - consisting of channel ratio values *
173 !* for the .94- and 1.14-um channels corresponding to 60 water vapor *
174 !* amounts, and the associated atmospheric transmittance spectra. *
175 !* b. Output to standard output: *
176 !* 1. Debugging information - if the source is compiled with the *
177 !* debug flag set (-d_lines for the ULTRIX compiler), *
178 !* then debug information is written out. *
179 !* 2. Error messages - if any of the user input is invalid, or there is *
180 !* an I/O error, a message is written out, and the program halts. *
181 !* 3. Progress indicator - a message, which shows the number of the *
182 !* spectral slices that have been processed, to give the user an *
183 !* indication of the progress of the program execution. *
184 !* *
185 !* Special Considerations: *
186 !* a. Make sure that the imaging spectrometer's channel positions specified *
187 !* in the input wavelength table are correct. The incorrect channel *
188 !* positions will introduce sharp features in derived surface *
189 !* reflectance spectra. *
190 !* b. The output reflectance cube file has the same size as the input *
191 !* data cube file. Make sure there is enough space in the file *
192 !* system for the output cube before running this program. *
193 !* *
194 !* Change History: *
195 !* ATREM 1.2 - uses full-width half-max values to smooth solar irradiance *
196 !* curve and a new scaling factor for methane *
197 !* ATREM 1.3 - used new solar irradiance curve *
198 !* - supports 1992 AVIRIS data *
199 !* ATREM 1.3.1 - allows 0 and above for output resolution *
200 !* ATREM 2.0 - allows variable scale factors for each spectrometer *
201 !* (code submitted by Roger Clark, USGS) *
202 !* - user can input output scale factor for reflectance values *
203 !* - user can input radiance file header size in bytes *
204 !* - new solar irradiance curve (Neckel and Labs plus ATMOS) *
205 !* used (Green and Gao, 1993). *
206 !* ATREM 3.0 - replaced the 5S code by the 6S code for modeling atmospheric *
207 !* scattering effects and for modeling measurements from *
208 !* low-altitude aircrafts. ATREM 3.0, like previous versions *
209 !* of ATREM, only models nadir viewing geometry. *
210 !* - changed algorithms for calculating atmospheric gaseous *
211 !* transmittances for the upward surface-sensor path *
212 !* - users need to specify aircraft altitude (km) in input file *
213 !* ATREM 4.0 - replaced the band model by a line-by-line-based algorithm *
214 !* for calculating atmospheric gaseous transmittances. This *
215 !* allows the modeling of imaging spectrometer data at *
216 !* spectral resolutions better than 10 nm. *
217 !* - increased the buffer size to 1024x1024 in order to handle *
218 !* images larger than the AVIRIS' size (614x512). *
219 !* - modified the algorithm to allow off-nadir pointing geometry. *
220 !* - users need to specify view zenith angle and view azimuth *
221 !* angle. The view azimuth angle is defined as the angle *
222 !* between local North and the view direction projected on the *
223 !* ground (clockwise count). This angle can vary from 0 to *
224 !* 360 deg. *
225 !* - replaced the solar irradiance curve (Neckel and Labs plus *
226 !* ATMOS) by the high spectral resolution solar irradiance *
227 !* curve from MODTRAN 3.5 released in December of 1996. *
228 !* ATREM 4.1 - included atmospheric NO2 in transmittance calculations. *
229 !* *
230 !* Acknowledgments: *
231 !* This work was partially supported over several years by grants *
232 !* from NASA Jet Propulsion Laboratory, California Institute of *
233 !* Technology, from NASA Headquarters, and from the Office of Naval *
234 !* Research. Special thanks goes to Kathy Heidebrecht at the Center *
235 !* for the Study of Earth from Space, University of Colorado at *
236 !* Boulder, Colorado, for supporting the development of the earlier *
237 !* versions of ATREM codes. Special thanks also goes to William L. *
238 !* Ridgway for providing the line-by-line gaseous absorption database *
239 !* used in the present version of ATREM. *
240 !* *
241 !* References: *
242 !* Gao, B.-C., K. Heidebrecht, and A. F. H. Goetz, Derivation of scaled *
243 !* surface reflectances from AVIRIS data, Remote Sens. Env., 44, *
244 !* 165-178, 1993. *
245 !* Gao, B.-C., and C. O. Davis, Development of an operational algorithm *
246 !* for removing atmospheric effects from HYDICE and HSI data, *
247 !* in SPIE'96 Conference Proceedings, Vol. 2819, 45-55, 1996. *
248 !* Gao, B.-C., and A. F. H. Goetz, Column atmospheric water vapor and *
249 !* vegetation liquid water retrievals from airborne imaging *
250 !* spectrometer data, J. Geophys. Res., 95, 3549-3564, 1990. *
251 !* Goetz, A. F. H., and M. Herring, The high resolution imaging *
252 !* spectrometer (HIRIS) for Eos, IEEE Trans. Geosci. Remote Sens., 27,*
253 !* 136-144, 1989. *
254 !* Goetz, A. F. H., G. Vane, J. Solomon, and B. N. Rock, Imaging *
255 !* spectrometry for Earth remote sensing, Science, 228, 1147-1153,1985*
256 !* Green, R. O., and B.-C. Gao, A Proposed Update to the Solar Irradiance*
257 !* Spectrum used in LOWTRAN and MODTRAN, in Summaries of the Fourth *
258 !* Annual JPL Airborne Geoscience Workshop, October 25-29, (Editor, *
259 !* R. O. Green), JPL Publ. 93-26, Vol. 1, pp. 81-84, Jet Propul. Lab, *
260 !* Pasadena, Calif., 1993. *
261 !* Kneizys, F. X., E. P. Shettle, L. W. Abreu, J. H. Chetwynd, G. P. *
262 !* Anderson, W. O. Gallery, J. E. A. Selby, and S. A. Clough, Users *
263 !* guide to LOWTRAN7, AFGL-TR-8-0177, Air Force Geophys. Lab., *
264 !* Bedford, Mass., 1988. *
265 !* Iqbal, M., An Introduction To Solar Radiation, Academic, San Diego, *
266 !* Calif., 1983. *
267 !* Malkmus, W., Random Lorentz band model with exponential-tailed S line *
268 !* intensity distribution function, J. Opt. Soc. Am., 57, 323-329,1967*
269 !* Press, W. H., B. P. Flannery, S. A. Teukolsky, and W. T. Vetterling, *
270 !* Numerical Recipes-The ART of Scientific Computing, Cambridge *
271 !* University Press, 1986. *
272 !* Rothman, L. S., et al., The HITRAN 2008 molecular spectroscopic *
273 !* database, JQSRT, 110, 533-572, 2009. *
274 !* Solomon, S., R. W. Portmann, R. W. Sanders, J. S. Daniel, W. Madsen, *
275 !* B. Bartram, and E. G. Dutton, On the role of nitrogen dioxide in *
276 !* the absorption of solar radiation, J. Geophys. Res., 104, *
277 !* 12047-12058, 1999. *
278 !* Tanre, D., C. Deroo, P. Duhaut, M. Herman, J. J. Morcrette, J. Perbos,*
279 !* and P. Y. Deschamps, Description of a computer code to simulate *
280 !* the satellite signal in the solar spectrum: the 5S code, Int. *
281 !* J. Remote Sens., 11, 659-668, 1990. *
282 !* Tanre, D., C. Deroo, P. Duhaut, M. Herman, J. J. Morcrette, J. Perbos,*
283 !* and P. Y. Deschamps, Simulation of the satellite signal in the *
284 !* solar spectrum (5S), Users' Guide (U. S. T. De Lille, 59655 *
285 !* Villeneu d'Ascq, France: Laboratoire d'Optique Atmospherique), *
286 !* 1986. *
287 !* Thuillier, G., et al., Solar irradiance reference spectra for two *
288 !* solar active levels, Adv. Space Res., 34, 256-261, 2004. *
289 !* Vane, G., R. O. Green, T. G. Chrien, H. T. Enmark, E. G. Hansen, and *
290 !* W. M. Porter, The Airborne Visible/Infrared Imaging Spectrometer, *
291 !* Remote Sens. Env., 44, 127-143, 1993. *
292 !* Vane, G. (Ed), Airborne visible/infrared imaging spectrometer *
293 !* (AVIRIS), JPL Publ. 87-38, Jet Propul. Lab, Pasadena, Calif., 1987.*
294 !* Vermote, E., D. Tanre, J. L. Deuze, M. Herman, and J. J. Morcrette, *
295 !* Second simulation of the satellite signal in the solar spectrum *
296 !* (6S), 6S User's Guide Version 1, NASA-GSFC, Greenbelt, Maryland, *
297 !* 134 pages, 1994. *
298 !* *
299 !********************************************************************************
300 !
301 !
302 !********************************************************************************
303 !* *
304 !* Name: GET_INPUT *
305 !* Purpose: Reads and verifies all user provided input. *
306 !* Parameters: none *
307 !* Algorithm: Data is read in from standard input. The user is not prompted *
308 !* interactively, so data should be redirected from an input file. *
309 !* The data is validated after it is read in. If the data is *
310 !* invalid, a message is printed and the program stops. *
311 !* Globals used: TPVMR - two dimensional array containing 6 predefined *
312 !* atmospheric models. The models contain values for *
313 !* the number of atmospheric layer boundaries, altitude,*
314 !* temperature, pressure, and water vapor volume mixing *
315 !* ratio. *
316 !* Global output: IH2OVP, ICO2, IO3, IN2O, ICO, ICH4, IO2 - set to 0 to *
317 !* indicate that the gas should NOT be used in the *
318 !* calculations, and set to 1 if the gas should be used *
319 !* H(), T(), P(), VMR(), NB, NL, MODEL - altitude (km), *
320 !* temperature (K), pressure (atm), water vapor volume *
321 !* mixing ratio (ppm), number of atmospheric layer *
322 !* boundaries, number of atmospheric layers (NB-1), *
323 !* and model number for the selected atmospheric model. *
324 !* VRTO3 - column amount of O3. *
325 !* WAVOBS() - wavelengths for all channels. *
326 !* FWHM() - resolutions for each channel. *
327 !* NOBS - number of AVIRIS wavelengths. *
328 !* HSURF - the mean surface elevation of the imaging scene *
329 !* DLT, DLT2 - resolution, in units of nm, of input *
330 !* spectra and resolution of output surface reflectance *
331 !* spectra. If DLT2>DLT, output spectra are smoothed *
332 !* using a gaussian function. *
333 !* WNDOW1, WNDOW2, WP94C - center wavelength positions of two *
334 !* broad window channels and one broad .94-um water *
335 !* vapor channel. *
336 !* WNDOW3, WNDOW4, W1P14C - center wavelength positions of two *
337 !* broad window channels and one broad 1.14-um water *
338 !* vapor channel. *
339 !* NB1, NB2, NBP94, NB3, NB4, NB1P14 - number of individual *
340 !* narrow channels that form the corresponding broad *
341 !* window and water vapor absorption channels. *
342 !* IMN, IDY, IYR, IH, IM, IS - month, day, year, hour, minute, *
343 !* and second of measurement. *
344 !* XLATD, XLATM, XLATS, LATHEM - degrees, minutes, seconds, and*
345 !* hemisphere of latitude of measured area. *
346 !* XLONGD, XLONGM, XLONGS, LNGHEM - degrees, minutes, seconds, *
347 !* and hemisphere of latitude of measured area. *
348 !* NAME_INSTRU: Imaging spectrometer name, e.g., AVIRIS, HYDICE*
349 !* XPSS: = HSURF, an interface for using 6S. *
350 !* XPPP: plane height (km, above the sea level). *
351 !* *
352 !* Return Codes: none *
353 !* Special Considerations: None *
354 !* *
355 !********************************************************************************
356 
357 !INTERFACE
358 ! SUBROUTINE ecdf(xcdf, ycdf, nbin, xs, nsamp) BIND(C)
359 ! USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT, C_FLOAT
360 ! IMPLICIT NONE
361 ! FLOAT(C_FLOAT) :: xcdf,ycdf,xs
362 ! INTEGER(C_INT) :: nsamp,nbin
363 ! END SUBROUTINE addnums
364 !END INTERFACE
365 
366  SUBROUTINE get_input
367 
368 ! use cubeio
369 
370  include 'COMMONS_INC.f'
371 
372  INTEGER LUN_IN, LUN_OUT, LUN_VAP, I_RET
373  COMMON /inout_units/ lun_in, lun_out, lun_vap
374 
375 
376 !C Common variables
377  dimension h(25), t(25), p(25), vmr(25)
378  dimension wavobs(nobs_max),fwhm(nobs_max)
379  dimension tpvmr(7,81)
380  CHARACTER*1 LATHEM, LNGHEM
381 
382  CHARACTER (LEN = 1000) :: FINAV,FOCUB,FOH2O
383  INTEGER SORDER,HDREC
384 
385 !C Local variables
386  INTEGER ANS
387  CHARACTER (LEN = 1000) :: FINPWV,FTPVMR
388  LOGICAL GOOD_DATA
389  CHARACTER (LEN = 1000) :: FOUT1
390  INTEGER DIMS(4)
391  INTEGER ST_ORDER
392 
393  COMMON /getinput1/ ih2ovp,ico2,io3,in2o,ico,ich4,io2,ino2
394  COMMON /getinput3/ h,t,p,vmr,nb,nl,model,iaer,v,taer55,vrto3,sno2
395  COMMON /getinput4/ wavobs,fwhm
396  COMMON /getinput5/ nobs,ifullcalc,hsurf,dlt,dlt2
397  COMMON /getinput6/ wndow1,wndow2,wp94c,wndow3,wndow4,w1p14c
398  COMMON /getinput7/ nb1,nb2,nbp94,nb3,nb4,nb1p14
399  COMMON /getinput8/ imn,idy,iyr,ih,im,is
400  COMMON /getinput9/ xlatd,xlatm,xlats,lathem
401  COMMON /getinput10/xlongd,xlongm,xlongs,lnghem
402  COMMON /getinput11/hdrec,nsamps,nlines,nbands,sorder
403  COMMON /getinput12/scalef
404  COMMON /tpvmr_init1/ tpvmr
405 
406 !C Commons for use with the C programs for cube I/O
407  COMMON /outcube/ focub
408  COMMON /incube/ finav
409  COMMON /outh2ovap/ foh2o
410 
411 !C Parameters for names of imaging spectrometers
412  CHARACTER (LEN = 80) :: NAME_INSTRU, NAMES(10)
413  COMMON /getinput13/ name_instru, names
414 
415  REAL XPSS, XPPP
416  COMMON /getinput14/ xpss, xppp
417 
418  REAL XVIEWD, XVIEWM, XVIEWS
419  REAL XAZMUD, XAZMUM, XAZMUS
420  COMMON /getinput15/ xviewd,xviewm,xviews, xazmud,xazmum,xazmus
421 
422  good_data = .true. ! initialize flag for good data
423 
424  627 FORMAT(a10)
425 !C
426 !C
427 !C***Temp code for assigning names of imaging spectrometers. Based on these
428 !C names, different scale factors should be used for different instrument
429 !C when converting measured radiances to standard radiance units.
430 !C*** The coding here may need to be moved to the file "COMMONS_INC"
431  names(1) = 'AVIRIS'
432  names(2) = 'HYDICE'
433  names(3) = 'HSI'
434  names(4) = 'TRWIS-III'
435  names(5) = 'PHYLLS'
436  names(6) = 'Hyperion'
437  names(7) = 'HICO'
438  names(8) = 'NIS'
439  names(9) = 'PRISM'
440  names(10)= 'OTHERS?'
441 !C***End of temp coding ------------
442 
443  85 FORMAT(a1000)
444 
445 !C ELSE
446 
447 !C Initialize default atmospheric window and water vapor absorption regions
448 !C for 3-channel ratioing calculations.
449 !C WNDOW1 = 0.865
450 !C NB1 = 3
451 !C WNDOW2 = 1.030
452 !C NB2 = 3
453 !C WP94C = 0.940
454 !C NBP94 = 5
455 !C WNDOW3 = 1.050
456 !C NB3 = 3
457 !C WNDOW4 = 1.235
458 !C NB4 = 3
459 !C W1P14C = 1.1375
460 !C NB1P14 = 7
461 !C ENDIF
462 !C ENDIF
463 
464 !C Determine which atmospheric model to use
465 !C 1 = tropical
466 !C 2 = mid latitude summer
467 !C 3 = mid latitude winter
468 !C 4 = subarctic summer
469 !C 5 = subarctic winter
470 !C 6 = US standard 1962
471 !C 7 = user defined model
472  model = 1
473 !C Initialize NB, H, P, T, VMR from predefined atmospheric model array
474  nb = tpvmr(model,1)
475  DO 120 i=1,nb
476  h(i) = tpvmr(model,2+(4*(i-1)))
477  !Convert the atmospheric pressure from "mb" to "atm.":
478  p(i) = tpvmr(model,3+(4*(i-1))) / 1013.
479  t(i) = tpvmr(model,4+(4*(i-1)))
480  !Convert the VMR from the ppm unit in the model to absolute unit
481  vmr(i) = tpvmr(model,5+(4*(i-1)))*1.0e-06
482  120 CONTINUE
483  nl=nb-1
484 
485  DO i = nb+1, 25
486  h(i) = 1000.
487  p(i) = 0.0
488  t(i) = 300.
489  vmr(i) = 0.0
490  END DO
491 !
492 !C Determine if various gases should be included in the calculations. Format:
493 !C 1=yes or 0=no. The order should be:
494 !C 1. water vapor
495 !C 2. carbon dioxide
496 !C 3. ozone
497 !C 4. nitrous oxide
498 !C 5. carbon monoxide
499 !C 6. methane
500 !C 7. oxygen
501 !C 8. nitrogen dioxide
502 
503 !C READ(*,*)IH2OVP, ICO2, IO3, IN2O, ICO, ICH4, IO2, INO2
504 
505  ih2ovp = 1
506  ico2 = 0
507  io3 = 0
508  in2o = 0
509  ico = 0
510  ich4 = 0
511  io2 = 0
512  ino2 = 0
513 
514  RETURN
515  END
516 
517 !********************************************************************************
518 !* *
519 !* Name: MODEL_ADJ *
520 !* Purpose: resets the bottom boundary of the input model if the surface *
521 !* elevation is greater than 0, and calculate the column water vapor *
522 !* amount in the selected model. *
523 !* Parameters: none *
524 !* Algorithm: If the surface elevation > 0, the bottom layer temperature and *
525 !* water vapor volume mixing ratio are obtained through linear *
526 !* interpolation, while the bottom layer pressure is obtained *
527 !* through exponential interpolation. *
528 !* Globals used: H, T, P, VMR, NB, NL, HSURF - these values are adjusted if *
529 !* HSURF > 0 *
530 !* Global output: CLMVAP - Column water vapor amount in unit of cm. *
531 !* Q - Number of molecules above the surface at one *
532 !* atmosphere in units of molecules/cm**2 *
533 !* Return Codes: none *
534 !* Special Considerations: none *
535 !* *
536 !********************************************************************************
537  SUBROUTINE model_adj
538 
539  include 'COMMONS_INC.f'
540 
541 !C Common variables
542  dimension h(25), t(25), p(25), vmr(25)
543 
544  COMMON /getinput3/ h,t,p,vmr,nb,nl,model,iaer,v,taer55,vrto3,sno2
545  COMMON /getinput5/ nobs,ifullcalc,hsurf,dlt,dlt2
546  COMMON /model_adj1/ clmvap,q
547 
548  dimension hp(25), tp(25), pp(25), vmrp(25)
549  COMMON /model_adj2/ hp, tp, pp, vmrp
550  COMMON /model_adj3/ k_plane, dvap_plane, dvap_layer, &
551  dp_plane, dp_layer, clmvapp
552  COMMON /model_adj4/ k_surf
553 
554  REAL XPSS, XPPP
555  COMMON /getinput14/ xpss, xppp
556 
557 !C H = Layer boundary height, SL=Slant path length, DSLODH=DSL/DH
558 
559  re=6380.0
560 !C Q=# of molecules above the surface at one atmosphere (molecules/cm**2)
561  q=2.152e25
562 
563 !C-- print*, 'original model atmosphere ...'
564 !C-- DO I = 1, 25
565 !C-- print*, 'H,T,P,VMR = ', H(I), T(I), P(I), VMR(I)
566 !C-- END DO
567 
568 !C--- Convert the atmospheric pressure from "mb" to "atm.":
569 ! Moved this conversion to GET_INPUT and init_tpvmr - rjh 1/8/2016
570 ! DO I = 1, NB
571 ! P(I) = P(I) / 1013.
572 ! END DO
573 !C--- End of conversion
574 
575 !C Convert the VMR from the ppm unit in the model to absolute unit.
576 ! Moved this conversion to GET_INPUT and init_tpvmr - rjh 1/8/2016
577 ! DO 310 I=1,NB
578 ! 310 VMR(I)=VMR(I)*1.0E-06
579 
580 !C Do special processing if surface altitude is greater than 0
581 !C--- IF(HSURF.NE.0.0) THEN
582 !C Reset H(I) to a smaller value if HSURF.EQ.H(I) to avoid possible
583 !C problems in table searching using LOCATE
584  DO 7455 i=1,nb
585  7455 IF(hsurf.EQ.h(i)) hsurf=h(i)+0.0001
586 
587 !C Determine index of H() such that H(index) < HSURF < H(index+1)
588  CALL locate(h,nb,hsurf,k)
589 !C
590 !C K_SURF is an index relative to the original model atmosphere (0 - 100 km)
591  k_surf = k
592 !C print*, 'K_SURF = ', K_SURF
593 !C
594  IF(k.EQ.0) THEN
595  WRITE(6,5237)
596  5237 FORMAT(2x,'***WARNING: Surface elevation smaller then lowest boundary of the model atmosphere.')
597 
598  k_surf = 1
599  GOTO 5255
600  ENDIF
601 
602  IF(k.GT.0) THEN
603  dhk=h(k+1)-h(k)
604  dhs=hsurf -h(k)
605 
606 !C linear interpolation for surface temperature (TSURF) and VMR ( VMRS)
607  tsurf=t(k)+(dhs/dhk)*(t(k+1)-t(k))
608  vmrs =vmr(k)+(dhs/dhk)*(vmr(k+1)-vmr(k))
609 
610 !C exponential interpolation for surface pressure (PSURF)
611  psurf=p(k)*exp(-alog(p(k)/p(k+1))*dhs/dhk)
612  h(1)=hsurf
613  p(1)=psurf
614  t(1)=tsurf
615  vmr(1)=vmrs
616 
617  nb=nb-k+1
618  nl=nb-1
619 !C--- print*,'NL = ', NL, ' NB = ', NB, 'in Model_Adj'
620 !C
621  DO 5240 i=2,nb
622  h(i)=h(i+k-1)
623  p(i)=p(i+k-1)
624  t(i)=t(i+k-1)
625  vmr(i)=vmr(i+k-1)
626  5240 CONTINUE
627 !C Zero out pressures and VMRS of top atmospheric layers.
628  DO 5245 i=nb+1,25
629  h(i)=1000.
630  p(i)=0.0
631  t(i)=300.
632  vmr(i)=0.0
633  5245 CONTINUE
634  ENDIF
635 !C--- ENDIF
636 
637  5255 CONTINUE
638 
639  amtvrt=0.0
640 
641  DO 350 i=1,nl
642  damtvt=q*(p(i)-p(i+1))*(vmr(i)+vmr(i+1))/2.0
643  amtvrt=amtvrt+damtvt
644  350 CONTINUE
645 
646  clmvap=amtvrt/3.34e+22
647 
648  WRITE(91,*)'Column vapor amount in model atmosphere from ground'
649  WRITE(91,*)' to space = ', clmvap, ' cm'
650 
651 !C--- WRITE(*,*)'In MODEL_ADJ, NB = ',NB,' NL = ',NL
652 !C--- print*, 'After adjusting for elevated surface ...'
653 !C--- DO I = 1, 25
654 !C--- print*, 'H,T,P,VMR = ', H(I), T(I), P(I), VMR(I)
655 !C--- END DO
656 !
657 !C
658 !C
659 !C Setting the upward atmospheric path's T, P, and VMR profiles:
660 !C
661 !C 1st duplicate the entire atmospheric profiles from the downward path
662 !C to the upward path
663 !C
664  DO i = 1, 25
665  hp(i) = h(i)
666  tp(i) = t(i)
667  pp(i) = p(i)
668  vmrp(i) = vmr(i)
669  END DO
670 
671 
672  hplane = xppp
673 !C Set the highest plane altitude to the upper bound of model atmosphere
674 !C--- IF(HPLANE.GT.100.0) HPLANE = 100. - 0.0001
675  IF(hplane.GE.100.0) hplane = 100. - 0.0001
676 !C
677 !C Do special processing if the plane height (HPLANE) is greater than HP(1)
678  IF(hplane.GT.hp(1)) THEN
679 !C Reset Plane altitude HPLANE (= XPPP) to a larger value if
680 !C HPLANE.EQ.HP(I) to avoid possible problems in table
681 !C searching using LOCATE
682  DO 7456 i=1,25
683  7456 IF(hplane.EQ.hp(i)) hplane=hp(i)-0.0001
684 
685 !C Determine index of HP() such that HP(index) < HPLANE < H(index+1)
686  CALL locate(hp,nb,hplane,kk)
687 
688  IF(kk.EQ.0) THEN
689  WRITE(6,5239)
690  5239 FORMAT(2x,'***WARNING: Plane altitude less then lowest boundary of the model atmosphere.')
691  GOTO 5256
692  ENDIF
693 
694  IF(kk.GT.0) THEN
695  dhkk = hp(kk+1) - hp(kk)
696  dhss = hplane - hp(kk)
697 
698 !C linear interpolation for plane temperature (TPLANE) and VMR ( VMRSP)
699  tplane = tp(kk) + (dhss/dhkk)*(tp(kk+1)-tp(kk))
700  vmrsp = vmrp(kk) + (dhss/dhkk)*(vmrp(kk+1)-vmrp(kk))
701 
702 !C exponential interpolation for plane pressure (PPLANE)
703  pplane = pp(kk)*exp(-alog(pp(kk)/pp(kk+1))*dhss/dhkk)
704  hp(kk+1) = hplane
705  pp(kk+1) = pplane
706  tp(kk+1) = tplane
707  vmrp(kk+1) = vmrsp
708 
709 !C Zero out pressures and VMRP of top atmospheric layers.
710  IF(kk.LT.24) THEN
711  DO i=kk+2,25
712  hp(i)=1000.
713  pp(i)=0.0
714  tp(i)=300.
715  vmrp(i)=0.0
716  END DO
717  END IF
718 
719  ENDIF
720  ENDIF
721 
722  5256 CONTINUE
723 
724  amtvrtp=0.0
725 
726  DO 357 i=1,kk
727  damtvtp=q*(pp(i)-pp(i+1))*(vmrp(i)+vmrp(i+1))/2.0
728  amtvrtp=amtvrtp+damtvtp
729  357 CONTINUE
730 
731  clmvapp=amtvrtp/3.34e+22
732 
733  WRITE(91,*)'Column vapor below plane (CLMVAPP) = ', &
734  clmvapp, ' cm'
735 
736 !C--- WRITE(*,*)'In MODEL_ADJ, NB = ',NB,' KK = ', KK
737 !C--- print*, 'After further adjusting for plane height ...'
738 !C--- DO I = 1, 25
739 !C--- print*, 'HP,TP,PP,VMRP = ', HP(I), TP(I), PP(I), VMRP(I)
740 !C--- END DO
741 
742 !C--- Indices and parameters for the plane layer
743  k_plane = kk
744 
745  dvap_plane = q*(pp(k_plane) - pp(k_plane+1))* &
746  (vmrp(k_plane) + vmrp(k_plane+1))/2.0 / 3.34e+22
747 
748  dvap_layer = q*(p(k_plane) - p(k_plane+1))* &
749  (vmr(k_plane) + vmr(k_plane+1))/2.0 / 3.34e+22
750 
751  dp_plane = pp(k_plane) - pp(k_plane+1)
752  dp_layer = p(k_plane) - p(k_plane+1)
753 
754 !C--- print*, 'K_PLANE, DVAP_PLANE, DVAP_LAYER = ',
755 !C--- & K_PLANE, DVAP_PLANE, DVAP_LAYER
756 !C--- print*, 'DP_PLANE, DP_LAYER = ', DP_PLANE, DP_LAYER
757 
758 
759  RETURN
760  END
761 !********************************************************************************
762 !* *
763 !* Name: GEOMETRY *
764 !* Purpose: Calculates the solar and the observational geometric factors. *
765 !* Parameters: none *
766 !* Algorithm: The solar geometry was obtained based on the latitude, longitude,*
767 !* GMT time using programs written by W. Mankin at National Center *
768 !* for Atmospheric Research in Boulder, Colorado. The *
769 !* geometric factors for CO2, O3, N2O, CO, CH4, and O2 are based *
770 !* only on the solar and observational angles. Sixty artificial *
771 !* geometric factors for H2O are set up to produce a transmittance *
772 !* table for different atmospheric water vapor amounts. *
773 !* Globals used: VRTO3 - Column O3 amount in units of atm-cm *
774 !* IMN,IDY,IYR,IH,IM,IS - time and date of data measurements *
775 !* XLATD,XLATM,XLATS,LATHEM - Latitude of measured area *
776 !* XLONGD,XLONGM,XLONGS,LNGHEM - Longitude of measured area *
777 !* CLMVAP - Column water vapor in unit of cm in the model atmosphere *
778 !* Global output: *
779 !* SOLZNI,SOLAZ,OBSZNI,OBSPHI,IDAY - Solar zenith angle, solar azimuth *
780 !* angle, observational zenith angle, observational azimuth angle, *
781 !* and the day number in the year *
782 !* GCO2,GO3,GN2O,GCO,GCH4,GO2,SSH2O,GGEOM,TOTLO3 - Geometric factors for *
783 !* different gases, and total O3 amount in the sun-surface ray path. *
784 !* The geometric factor is defined as: if the vertical column amount *
785 !* of the gas is equal 1, then GGAS is equal to the total amount of *
786 !* the gas in the combined Sun-surface-sensor ray path. *
787 !* Return Codes: none *
788 !* Special Considerations: none *
789 !* *
790 !********************************************************************************
791 
792  SUBROUTINE geometry
793 
794  include 'COMMONS_INC.f'
795 
796  dimension vapvrt(nh2o_max), vap_slant(nh2o_max)
797  dimension md(12)
798  dimension ssh2o(nh2o_max)
799  dimension h(25), t(25), p(25), vmr(25)
800  CHARACTER*1 LATHEM,LNGHEM
801 
802 !C The VAPVRT array contains 60 column water vapor values used for generating
803 !C a table of transmittance spectra with different amount of water vapor.
804 !C The values in VAPVRT is designed so that there is approximately 2% change
805 !C in the .94-um H2O channel ratio for column water vapor in the range .4-6 cm.
806 
807  DATA vapvrt/.00, .02, .06, .11, .16, .21, .26, .31, .36, .40, &
808  .43, .46, .50, .54, .58, .62, .66, .70, .75, .80, &
809  .86, .92, .98, 1.06,1.14, 1.22, 1.3, 1.4, 1.5, 1.6, &
810  1.7, 1.8, 1.9, 2.05, 2.2, 2.35, 2.55, 2.75, 2.95, 3.2, &
811  3.5, 3.8, 4.1, 4.4, 4.7, 5.0, 5.3, 5.6, 6.0, 6.4, &
812  7.0, 7.7, 8.5, 9.4,10.4, 11.6, 13.0, 15.0, 25.0, 50./
813 
814  DATA md/0,31,59,90,120,151,181,212,243,273,304,334/
815 
816  COMMON /getinput3/ h,t,p,vmr,nb,nl,model,iaer,v,taer55,vrto3,sno2
817 
818  COMMON /getinput8/ imn,idy,iyr,ih,im,is
819  COMMON /getinput9/ xlatd,xlatm,xlats,lathem
820  COMMON /getinput10/xlongd,xlongm,xlongs,lnghem
821  COMMON /model_adj1/ clmvap,q
822  COMMON /geometry1/ solzni,solaz,obszni,obsphi,iday
823  COMMON /geometry2/ gco2,go3,gn2o,gco,gch4,go2,ssh2o,totlo3,ggeom
824  COMMON /model_adj3/ k_plane, dvap_plane, dvap_layer, &
825  dp_plane, dp_layer, clmvapp
826 
827  dimension g_vap(25), g_other(25)
828  COMMON /geometry3/ g_vap, g_other, g_vap_equiv
829  COMMON /geometry4/vap_slant_mdl
830  REAL MU,MU0, SSH2O_S(NH2O_MAX,2)
831  COMMON /geometry5/mu,mu0,ssh2o_s
832  REAL XPSS, XPPP
833  COMMON /getinput14/ xpss, xppp
834 
835  REAL XVIEWD, XVIEWM, XVIEWS
836  REAL XAZMUD, XAZMUM, XAZMUS
837  COMMON /getinput15/ xviewd,xviewm,xviews, xazmud,xazmum,xazmus
838 
839  hplane = xppp
840 !C
841 !C VAP_SLANT is a new array for containing two-way total vapor amounts
842 !C Here the number "2" can be changed to other numbers, e.g., 2.5,
843 !C without any major effects in derived water vapor values from
844 !C imaging spectrometer data.
845 !C
846 
847  DO i = 1, nh2o_max
848  vap_slant(i) = vapvrt(i) * 2.0
849  END DO
850 
851  obszni = senzn_l2
852  obsphi = senaz_l2
853  solzni = solzn_l2
854 
855  obszni = obszni / radeg
856  obsphi = obsphi / radeg
857 
858  solzni = solzni/radeg
859 
860 ! write(91,*) 'KPLANE=',k_plane
861 
862  mu0 = 1./cos(solzni)
863  mu = 1./cos(obszni)
864  ggeom = mu0 + mu
865  write(91,*) 'GGEOM =',ggeom,' OBSZNI = ',obszni, ' OBSPHI = ',obsphi, &
866  'solzni=',solzni,' degrees :: MU0, MU = ',mu0, mu
867  write(91,*) 'f1a,f2a,f1b,f2b=',f1a,f2a,f1b,f2b
868  gco2 = ggeom
869 
870  go3 = ggeom
871  IF(hplane.LT.27.) go3 = ggeom - 1./cos(obszni)
872 
873  gn2o = ggeom
874  gco = ggeom
875  gch4 = ggeom
876  go2 = ggeom
877 
878 ! write(91,*) 'GGEOM, GCO2, GO3, GN2O, GCO, GCH4, GO2 = '
879 ! write(91,*) GGEOM, GCO2, GO3, GN2O, GCO, GCH4, GO2
880 
881  totlo3 = go3 * vrto3
882 
883  WRITE(91,*) 'TOTLO3 = ', totlo3, vrto3
884 
885 !C Initialize newly created geometrical factors for each atmospheric
886 !C layers (here G_VAP and G_OTHER are true geometrical factors that
887 !C account for the actual Sun-surface-plane path lengths in the
888 !C model atmosphere):
889 !C
890 !C---For layers below the plane layer---
891  DO i = 1, k_plane - 1
892  g_vap(i) = ggeom
893  g_other(i) = ggeom
894  END DO
895 !C
896 !C---For layers above the plane layer
897  DO i = k_plane + 1, 25
898  g_vap(i) = ggeom - 1./cos(obszni)
899  g_other(i) = ggeom - 1./cos(obszni)
900  END DO
901 !C
902 !C---Special treatment for the plane layer to take account the
903 !C "shorter" upward path length
904  g_vap(k_plane) = ggeom - 1./cos(obszni) &
905  + dvap_plane/dvap_layer/cos(obszni)
906  g_other(k_plane) = ggeom - 1./cos(obszni) &
907  + dp_plane/dp_layer/cos(obszni)
908 
909 ! write(91,*) ' G_VAP, G_OTHER, I ='
910 ! DO I = 1, 25
911 ! write(91,*) G_VAP(I), G_OTHER(I), I
912 ! END DO
913 
914 !C Calculate the water vapor SCALING factor relative to the total amount
915 !C of water vapor in the model atmosphere in the L-shaped
916 !C Sun-surface-plane ray path.
917 !C
918  vap_slant_mdl = clmvap/cos(solzni) + clmvapp/cos(obszni)
919  vap_sol = clmvapp*mu0
920  vap_sen = clmvapp*mu
921 ! write(91,*) 'VAP_SLANT_MDL =', VAP_SLANT_MDL, ' cm ', SLANT_MDL
922 !C
923 !C The "equivalent" geometrical factor corresponding to the total
924 !C slant vapor amount of VAP_SLANT_MDL':
925 !C
926  g_vap_equiv = vap_slant_mdl / clmvap
927  write(91,*) 'G_VAP_EQUIV = ', g_vap_equiv, vap_slant_mdl, clmvap
928  write(91,*) 'VAP_SOL,VAP_SEN = ', vap_sol, vap_sen, wtrvpr
929 
930  DO 310 i=1,nh2o_max
931  ssh2o(i) = vap_slant(i) / vap_slant_mdl
932  write(91,*) 'SSH2O(I), I = ', ssh2o(i), i, vap_slant_mdl, wtrvpr, isplitp
933  if (wtrvpr.gt.0) THEN
934  ssh2o_s(i,1) = vapvrt(i) / vap_sol
935  ssh2o_s(i,2) = vapvrt(i) / vap_sen
936  write(91,*) 'SSH2O_S(I,1), I = ', ssh2o_s(i,1), i, solzni*radeg
937  write(91,*) 'SSH2O_S(I,2), I = ', ssh2o_s(i,2), i, obszni*radeg
938  else
939  if (isplitp.ne.0) then
940  write(6,*) 'ATREM: Split paths is not working because WaterVapor is 0'
941  stop 0
942  end if
943  end if
944  310 CONTINUE
945 
946 !C Calculate the number of days that have passed in this year. Take leap year
947 !C into account.
948  iday = md(imn) + idy
949  lpyr = iyr - (4 * (iyr/4))
950  IF((lpyr.EQ.0).AND.(iday.GT.59).AND.(imn.NE.2)) iday = iday + 1
951 
952 !C--D WRITE(*,*)'SOLZNI=',SOLZNI,' SOLAZ=',SOLAZ,' OBSZNI=',OBSZNI
953 !C--D WRITE(*,*)'OBSPHI=',OBSPHI,' IDAY = ',IDAY
954 !C--D WRITE(*,*)'GCO2=',GCO2,' GO3=',GO3,' GN2O=',GN2O,' GCO=',GCO
955 !C--D WRITE(*,*)'GCH4=',GCH4,' GO2=',GO2,' TOTLO3=',TOTLO3
956 !C--D WRITE(*,*)'GGEOM=',GGEOM
957 !C--D DO 311 I=1,60
958 !C--D 311 WRITE(*,*)'I=',I,' SSH2O(I)',SSH2O(I)
959 
960  RETURN
961  END
962 
963 !********************************************************************************
964 !* *
965 !* Name: INIT_SPECCAL *
966 !* Purpose: initialize global data for spectrum calculations. *
967 !* Parameters: none *
968 !* Algorithm: initialize data. *
969 !* Globals used: AH2O, APH2O, BH2O, BPH2O, SODLT, SOGAM, O3CF - Band model *
970 !* parameters for spectral calculations. *
971 !* WNDOW1, WNDOW2, WP94C, WNDOW3, WNDOW4, W1P14C - Center *
972 !* positions of window and water vapor absorption *
973 !* channels used in 3-channel ratio calculations. *
974 !* NB1, NB2, NBP94, NB3, NB4, NB1P14 - Number of narrow channels *
975 !* to form broader window and absorption channels. *
976 !* Global output: *
977 !* IH2OLQ,RLQAMT,NGASTT,NH2O,VSTART,VEND - Flag for including liquid *
978 !* water, liquid water amount (cm), total number of gases *
979 !* (typically 8), number of water vapor values, starting *
980 !* and ending wavelengths in internal calculations. *
981 !* NO3PT,NCV,NCVHAF,NCVTOT,VMIN,ISTART,IEND - Number of O3 abs. coef. *
982 !* points, parameters for gaussian function and spectral *
983 !* calculations. *
984 !* ISTCAL,IEDCAL,DP,PM,TM,VMRM - Parameters for spectral calculations *
985 !* IST1,IED1,IST2,IED2,ISTP94,IEDP94 - 3-channel ratioing parameters for *
986 !* the 0.94-um water vapor band. *
987 !* IST3,IED3,IST4,IED4,IST1P14,IED1P14 - 3-channel ratioing parameters for *
988 !* the 1.14-um water vapor band. *
989 !* WT1,WT2,WT3,WT4,JA - Relative weights for the four window channels *
990 !* used in channel-ratioing calculations. JA is a *
991 !* output parameter from a table searching routine. *
992 !* NCV2,NCVHF2,NCVTT2,ISTRT2,IEND2,FINST2 - Parameters for smoothing *
993 !* output reflectance spectra. *
994 !* NATOT,NBTOT,NCTOT,NDTOT - Number of channels for the four AVIRIS' *
995 !* grating spectrometers (A, B, C, and D). *
996 !* Return Codes: None. *
997 !* Special Considerations: Some parameters may need to be fine-tuned. *
998 !* *
999 !********************************************************************************
1000 !* Notes about water vapor VMRS and related quantities: *
1001 !* *
1002 !* VAPVRT(60) - a table containing 60 column vapor values (in unit of cm) *
1003 !* *
1004 !* VAP_SLANT(I) = VAPVRT(I) * 2.0, VAP_SLANT is a new table for containing *
1005 !* two-way total vapor amounts. Here the number "2" can be *
1006 !* changed to other numbers, e.g., 2.5, without major *
1007 !* effects on retrieved water vapor values. *
1008 !* *
1009 !* G_VAP(I = 1,..., NL) = true vapor geometric factor for each layer in *
1010 !* the model atmosphere (after adjusting for the elevated *
1011 !* surface. *
1012 !* *
1013 !* VMRM(I) = VMRM(I)*G_VAP(I). The VMRS are multiplied by the geometrical *
1014 !* factor. We can calculate the vapor transmittance on the *
1015 !* Sun-surface-sensor path by assuming a vertical path in *
1016 !* the model atmosphere with geometric-factor-adjusted VMRS. *
1017 !* *
1018 !* CLMVAP = vertical column amount from ground to space in model atmosphere*
1019 !* CLMVAPP = vertical column amount from ground to aircraft or satellite *
1020 !* sensor in model atmosphere *
1021 !* Q = 2.152E25 = # of molecules above the surface at one atmosphere *
1022 !* (in unit of molecules/cm**2) *
1023 !* *
1024 !* VAP_SLANT_MDL= CLMVAP/COS(SOLZNI) + CLMVAPP/COS(OBSZNI) = total amount *
1025 !* of water vapor in the model atmosphere in the L-shaped *
1026 !* Sun-surface-plane ray path. *
1027 !* *
1028 !* G_VAP_EQUIV = VAP_SLANT_MDL / CLMVAP = the "equivalent" geometrical *
1029 !* factor corresponding to the total slant vapor amount *
1030 !* VAP_SLANT_MDL and the column vapor amount CLMVAP. *
1031 !* *
1032 !* SSH2O(I) (I = 1, ..., 60) - a pure scaling factor relative to the total *
1033 !* slant vapor amount of VAP_SLANT_MDL, and *
1034 !* SSH2O(I) = VAP_SLANT(I) / VAP_SLANT_MDL *
1035 !* *
1036 !* SH2O = one value of SSH2O(I). SH2O is used during generation of the *
1037 !* look-up table. *
1038 !* *
1039 !* VAPTT = VAP_SLANT_MDL*SH2O, is the absolute total vapor amount on the *
1040 !* L-shaped path corresponding to a spectrum stored in the *
1041 !* look-up table. *
1042 !* *
1043 !* CLMWVP = 0.5*(VAPTTA+VAPTTB)/G_VAP_EQUIV, is the retrieved column water *
1044 !* vapor amount from imaging spectrometer data. *
1045 !********************************************************************************
1046  SUBROUTINE init_speccal
1047 
1048  include 'COMMONS_INC.f'
1049 
1050 !C Common variables
1051  dimension h(25), t(25), p(25), vmr(25)
1052  dimension ssh2o(nh2o_max)
1053  dimension wavobs(nobs_max),fwhm(nobs_max)
1054  dimension dp(25), pm(25), tm(25), vmrm(25)
1055  dimension finst2(100)
1056  dimension sumcf(np_hi)
1057 
1058 !C Local variables
1059 
1060  COMMON /getinput1/ ih2ovp,ico2,io3,in2o,ico,ich4,io2,ino2
1061  COMMON /getinput3/ h,t,p,vmr,nb,nl,model,iaer,v,taer55,vrto3,sno2
1062  COMMON /getinput4/ wavobs,fwhm
1063  COMMON /getinput5/ nobs,ifullcalc,hsurf,dlt,dlt2
1064  COMMON /getinput6/ wndow1,wndow2,wp94c,wndow3,wndow4,w1p14c
1065  COMMON /getinput7/ nb1,nb2,nbp94,nb3,nb4,nb1p14
1066  COMMON /geometry2/ gco2,go3,gn2o,gco,gch4,go2,ssh2o,totlo3,ggeom
1067 
1068  COMMON /model_adj1/ clmvap,q
1069 
1070  COMMON /init_speccal3/ nh2o
1071  COMMON /init_speccal5/ dp,pm,tm,vmrm
1072  COMMON /init_speccal6/ ist1,ied1,ist2,ied2,istp94,iedp94
1073  COMMON /init_speccal7/ ist3,ied3,ist4,ied4,ist1p14,ied1p14
1074  COMMON /init_speccal8/ wt1,wt2,wt3,wt4,ja
1075 
1076  COMMON /init_speccal10/ ncv2,ncvhf2,ncvtt2,istrt2,iend2,finst2
1077  COMMON /init_speccal11/ natot,nbtot,nctot,ndtot
1078 
1079  REAL, ALLOCATABLE :: ABSCF_CO2(:,:),ABSCF_O2(:,:),ABSCF_N2O(:,:),ABSCF_CH4(:,:),ABSCF_CO(:,:)
1080  dimension g_vap(25), g_other(25)
1081  COMMON /geometry3/ g_vap, g_other, g_vap_equiv
1082  COMMON /geometry4/vap_slant_mdl
1083 
1084  dimension o3cf(no3pt)
1085  COMMON /o3cf_init1/ o3cf
1086 
1087  dimension tran_o3_std(no3pt)
1088  COMMON /init_speccal16/ tran_o3_std
1089 
1090  dimension rno2cf(no3pt)
1091  COMMON /no2cf_init1/ rno2cf
1092 
1093  dimension tran_no2_std(no3pt)
1094  COMMON /init_speccal17/ tran_no2_std
1095 
1096  COMMON /model_adj4/ k_surf
1097  INTEGER start(2)/1,1/
1098  INTEGER cnt(2)/NP_HI,19/
1099  CHARACTER(len=4096) :: filename
1100  INTEGER FINDMATCH
1101  external findMatch
1102  INTEGER FIRST/1/
1103  SAVE first,abscf_co2,abscf_o2,abscf_n2o,abscf_ch4,abscf_co
1104 
1105  IF (first.eq.1) THEN
1106 
1107 ! CALL get_environment_variable("OCDATAROOT", datadir)
1108 ! WRITE (*,*) 'OCDATAROOT='//TRIM(homedir)
1109 
1110  nh2o = nh2o_max !Number of column water vapor values
1111 !C
1112 !C Initialization for high resolution spectral calculations -
1113 !C First initialize arrays to smooth high resolution spectra (0.05 cm-1) to
1114 !C medium resolution spectra (0.2 nm):
1115 !C
1116 !C*** Note: The array WAVNO_HI is not used in actual computing, the array
1117 !C* should be removed from COMMONS_INC and the following DO LOOP
1118 !C* of this program, the purpose of keeping WAVNO_HI now is to
1119 !C* check array indices and make sure the correctness of the
1120 !C* indices ****************************************************
1121 ! DO I = 1, NP_HI
1122 ! WAVNO_HI(I) = 3000. + FLOAT(I-1)*DWAVNO ! Wavenumber (cm-1)of high
1123 ! ! resolution spectrum,
1124 ! TRAN_HI(I) = 1.0 ! 3000 - 18000 cm-1
1125 ! END DO
1126 
1127 ! TRAN_HI(:,:) = 1.0
1128 
1129 !C--- print*,'WAVNO_HI ,1, 10000,NP_HI = ',WAVNO_HI(1),
1130 !C--- & WAVNO_HI(10000), WAVNO_HI(NP_HI)
1131 !C
1132 !C
1133  DO i = 1, np_med
1134  wavln_med(i) = vstart + float(i-1)*dwavln ! Wavelength of medium
1135  ! resolution spectrum,
1136 !C TRAN_MED(I,:) = 1.0 ! FWHM=.2 nm, .56-3.1 um.
1137  END DO
1138 !C-----
1139 !C--- print*,'WAVLN_MED ,1, 10000,NP_MED = ',WAVLN_MED(1),
1140 !C--- & WAVLN_MED(10000), WAVLN_MED(NP_MED)
1141 !C-----
1142 !C
1143 !C NOTE: WAVLN_STD starts from 0.3 um, instead of 0.56 um
1144  DO i = 1, np_std
1145  wavln_std(i) = 0.3 + float(i-1)*dwavln ! Wavelength of medium
1146  ! resolution spectrum,
1147 !C TRAN_STD(I,:) = 1.0 ! FWHM=.2 nm, .3-3.1 um.
1148  END DO
1149 !C-----
1150 !C--- print*,'WAVLN_STD ,1, 10000,NP_STD = ',WAVLN_STD(1),
1151 !C--- & WAVLN_STD(10000), WAVLN_STD(NP_STD)
1152 !C-----
1153 !C
1154 !C Note: The grids of WAVNO_HI do not match the grids of 10000./WAVLN_MED.
1155 !C INDEX_MED is a specially designed index for finding close matches
1156 !C between the two kinds of grids.
1157 !C
1158  DO i = 1, np_med
1159  index_med(i) = ( (10000./wavln_med(i) - 3000.)/dwavno + 1.)
1160  END DO
1161 !C-----
1162 !C--- print*,'INDEX_MED ,1, 10000,NP_MED = ',INDEX_MED(1),
1163 !C--- & INDEX_MED(10000), INDEX_MED(NP_MED)
1164 !C-----
1165 !C
1166 !C Note: WAVLN_MED_INDEX(I) is very close to WAVLN_MED(I),
1167 !C and WAVLN_MED_INDEX(I) >= WAVLN_MED(I)
1168 !C
1169  DO i = 1, np_med
1170  wavln_med_index(i) = 10000. /(float(index_med(i)-1)*dwavno &
1171  + 3000.)
1172  END DO
1173 !C-----
1174 !C--- print*,'WAVLN_MED_INDEX ,1, 10000,NP_MED = ',WAVLN_MED_INDEX(1),
1175 !C--- & WAVLN_MED_INDEX(10000), WAVLN_MED_INDEX(NP_MED)
1176 !C-----
1177 
1178 
1179  DO i = 1, np_med
1180  fwhm_wavno(i) = 10000.*dlt_med &
1181  /(wavln_med_index(i)*wavln_med_index(i))
1182  END DO
1183 !C-----
1184 !C--- print*,'FWHM_WAVNO ,1, 10000,NP_MED = ',FWHM_WAVNO(1),
1185 !C--- & FWHM_WAVNO(10000), FWHM_WAVNO(NP_MED)
1186 !C-----
1187 !C
1188 
1189  DO i = 1, np_med
1190  ncvhf_wavno(i) = ( facdlt * fwhm_wavno(i) / dwavno + 1.)
1191  END DO
1192 !C-----
1193 !C--- print*,'NCVHF_WAVNO ,1, 10000,NP_MED = ',NCVHF_WAVNO(1),
1194 !C--- & NCVHF_WAVNO(10000), NCVHF_WAVNO(NP_MED)
1195 !C-----
1196 
1197 !C Initialize arrays for smoothing medium resolution spectrum (DLT_MED = 0.2 nm,
1198 !C and point spacing DWAVLN = 0.0001 micron) to coarser spectral
1199 !C resolution data from imaging spectrometers.
1200 
1201  DO i = 1, nobs
1202  ncvhf(i) = ( facdlt * fwhm(i) / dwavln + 1.)
1203  END DO
1204 !C
1205 !C parameters and arrays to smooth output surface reflectance spectrum
1206  wavcv2=facdlt*dlt2
1207 
1208 !C Find the largest value in the FWHM array, and use this value in calculation
1209 !C of indices for smoothing output reflectance spectra. This smoothing
1210 !C algorithm should work well with grating spectrometers having nearly
1211 !C constant spectral resolutions, but not so well for prism spectrometers
1212 !C having variable spectral resolution.
1213  dwvavr = fwhm(1)
1214 
1215  DO i = 2, nobs
1216  IF(dwvavr.LT.fwhm(i)) dwvavr = fwhm(i)
1217  END DO
1218 
1219  rncv2=wavcv2/dwvavr
1220  ncv2=rncv2
1221  ncvhf2=ncv2+1
1222  ncvtt2=2*ncv2+1
1223 
1224  cons2=dlt2*sqrt(3.1415926/const1)
1225 
1226  IF (dlt2 .NE. 0.0) THEN
1227  sumins=0.0
1228  DO 585 i=ncvhf2,ncvtt2
1229  finst2(i)=exp(-const1*(float(i-ncvhf2)*dwvavr/dlt2)**2)
1230  sumins=sumins+finst2(i)
1231  585 CONTINUE
1232 
1233  DO 590 i=1,ncvhf2-1
1234  finst2(i)=finst2(ncvtt2-i+1)
1235  sumins=sumins+finst2(i)
1236  590 CONTINUE
1237 
1238  sumins=sumins*dwvavr
1239 
1240  DO 595 i=1,ncvtt2
1241  finst2(i)=finst2(i)*dwvavr/sumins
1242  595 CONTINUE
1243  END IF
1244 
1245  istrt2=ncvhf2
1246  iend2=nobs-ncvhf2
1247 
1248 !C number of channels of the four AVIRIS spectrometers. These are used
1249 !C in removing null AVIRIS radiance values in the overlap portions of two
1250 !C adjacent spectrometers.
1251  nchnla=32
1252  nchnlb=64
1253  nchnlc=64
1254  nchnld=64
1255 
1256  natot=nchnla
1257  nbtot=nchnla+nchnlb
1258  nctot=nchnla+nchnlb+nchnlc
1259  ndtot=nchnla+nchnlb+nchnlc+nchnld
1260 
1261 !C Resetting window wavelength positions and calculating weights for
1262 !C window and absorption channels used in 3-channel ratioing.
1263  iwndw1=findmatch(wavobs,nobs,wndow1)
1264  iwndw1c = findmatch(wavobs,nobs,wndow1)
1265  write(91,*) 'IWNDW1=',iwndw1,iwndw1c,' list[0]=',wavobs(1)
1266  iwndw2=findmatch(wavobs,nobs,wndow2)
1267 
1268  wndow1=wavobs(iwndw1)
1269  wndow2=wavobs(iwndw2)
1270 
1271  jj=mod(nb1,2)
1272  IF(jj.EQ.0) nb1=nb1+1
1273  kk=mod(nb2,2)
1274  IF(kk.EQ.0) nb2=nb2+1
1275  nb1haf=(nb1-1)/2
1276  nb2haf=(nb2-1)/2
1277 
1278  ist1=iwndw1-nb1haf
1279  ied1=iwndw1+nb1haf
1280  ist2=iwndw2-nb2haf
1281  ied2=iwndw2+nb2haf
1282 
1283  iwp94c=findmatch(wavobs,nobs,wp94c)
1284  wp94c=wavobs(iwp94c)
1285 
1286  ll=mod(nbp94,2)
1287  IF(ll.EQ.0) nbp94=nbp94+1
1288  nb3haf=(nbp94-1)/2
1289  istp94=iwp94c-nb3haf
1290  iedp94=iwp94c+nb3haf
1291 
1292  wt1=(wndow2-wp94c)/(wndow2-wndow1)
1293  wt2=(wp94c-wndow1)/(wndow2-wndow1)
1294 
1295  iwndw4=findmatch(wavobs,nobs,wndow3)
1296  iwndw5=findmatch(wavobs,nobs,wndow4)
1297 
1298  wndow3=wavobs(iwndw4)
1299  wndow4=wavobs(iwndw5)
1300 
1301  jj=mod(nb3,2)
1302  IF(jj.EQ.0) nb3=nb3+1
1303  kk=mod(nb4,2)
1304  IF(kk.EQ.0) nb4=nb4+1
1305 
1306  nb4haf=(nb3-1)/2
1307  nb5haf=(nb4-1)/2
1308 
1309  ist3=iwndw4-nb4haf
1310  ied3=iwndw4+nb4haf
1311  ist4=iwndw5-nb5haf
1312  ied4=iwndw5+nb5haf
1313  iw1p14c=findmatch(wavobs,nobs,w1p14c)
1314 
1315  w1p14c=wavobs(iw1p14c)
1316  ll=mod(nb1p14,2)
1317  IF(ll.EQ.0) nb1p14=nb1p14+1
1318  nb6haf=(nb1p14-1)/2
1319  ist1p14=iw1p14c-nb6haf
1320  ied1p14=iw1p14c+nb6haf
1321 
1322  wt3=(wndow4-w1p14c)/(wndow4-wndow3)
1323  wt4=(w1p14c-wndow3)/(wndow4-wndow3)
1324 
1325  ALLOCATE ( abscf_co2(np_hi,19) )
1326  ALLOCATE ( abscf_n2o(np_hi,19) )
1327  ALLOCATE ( abscf_co(np_hi,19) )
1328  ALLOCATE ( abscf_ch4(np_hi,19) )
1329  ALLOCATE ( abscf_o2(np_hi,19) )
1330 
1331  write(filename(1:dln),'(a)') datpath(1:dln)
1332  write(filename(dln+1:),'(a)') 'abscf_gas.nc'
1333  ncid = ncopn(filename,ncnowrit,ircode)
1334 
1335  nrhid = ncvid(ncid, 'abscf_co2', ircode)
1336  CALL ncvgt (ncid, nrhid, start, cnt, abscf_co2, ircode)
1337  if (ircode .ne.0) then
1338  write(*,*) 'Error reading abscf_gas.nc: abscf_co2: rcode=',ircode
1339  stop 0
1340  end if
1341 
1342  nrhid = ncvid(ncid, 'abscf_n2o', ircode)
1343  CALL ncvgt (ncid, nrhid, start, cnt, abscf_n2o, ircode)
1344  if (ircode .ne.0) then
1345  write(*,*) 'Error reading abscf_gas.nc: abscf_n2o: rcode=',ircode
1346  stop 0
1347  end if
1348 
1349  nrhid = ncvid(ncid, 'abscf_co', ircode)
1350  CALL ncvgt (ncid, nrhid, start, cnt, abscf_co, ircode)
1351  if (ircode .ne.0) then
1352  write(*,*) 'Error reading abscf_gas.nc: abscf_co: rcode=',ircode
1353  stop 0
1354  end if
1355 
1356  nrhid = ncvid(ncid, 'abscf_ch4', ircode)
1357  CALL ncvgt (ncid, nrhid, start, cnt, abscf_ch4, ircode)
1358  if (ircode .ne.0) then
1359  write(*,*) 'Error reading abscf_gas.nc: abscf_ch4: rcode=',ircode
1360  stop 0
1361  end if
1362 
1363  nrhid = ncvid(ncid, 'abscf_o2', ircode)
1364  CALL ncvgt (ncid, nrhid, start, cnt, abscf_o2, ircode)
1365  if (ircode .ne.0) then
1366  write(*,*) 'Error reading abscf_gas.nc: abscf_o2: rcode=',ircode
1367  stop 0
1368  end if
1369 
1370  CALL ncclos(ncid, rcode)
1371 
1372  END IF ! IFIRST = 1
1373 !C Initialization for searching water vapor table (TRNTBL)
1374  ja = 30
1375 !C
1376 !C
1377 !C Calculate medium resolution O3 transmittances (0.2 nm, 2-way) with
1378 !C a point spacing of 0.1 nm between 0.3 and 0.8 micron.
1379 !C
1380  IF(io3.EQ.1) THEN
1381  DO i=1,no3pt
1382  tran_o3_std(i) = exp(-totlo3*o3cf(i))
1383  END DO
1384  END IF
1385 
1386 !C
1387 !C If O3 is not intended to be included in total atmospheric gaseous
1388 !C transmittance calculations, assigning TRAN_O3_STD = 1.0:
1389 !C
1390  IF(io3.NE.1) THEN
1391  DO i=1,no3pt
1392  tran_o3_std(i) = 1.0
1393  END DO
1394  END IF
1395 !C
1396 !C Calculate medium resolution NO2 transmittances (0.2 nm, 2-way) with
1397 !C a point spacing of 0.1 nm between 0.3 and 0.8 micron.
1398 !C
1399  no2pt = no3pt
1400  vrtno2 = 5.0e+15
1401  vrtno2 = sno2 * vrtno2
1402 
1403  gno2 = go3
1404  totno2 = gno2 * vrtno2
1405 
1406  IF(ino2.EQ.1) THEN
1407  DO i=1,no2pt
1408  tran_no2_std(i) = exp(-totno2*rno2cf(i))
1409  END DO
1410  END IF
1411 
1412 !C---Temp Code:
1413 !C--- OPEN(57,file='zzzzzz_tst_NO2_trn',status='unknown')
1414 !C--- DO I = 1, NO2PT
1415 !C--- write(57,*)WAVLN_STD(I), TRAN_NO2_STD(I)
1416 !C--- END DO
1417 !C--- CLOSE(57)
1418 !C---End of Temp Code
1419 !
1420 !C--- print*,' TOTNO2 = ', TOTNO2
1421 !C--- print*,'VRTNO2, SNO2, GNO2 = ', VRTNO2, SNO2, GNO2
1422 
1423 !C
1424 !C If NO2 is not intended to be included in total atmospheric gaseous
1425 !C transmittance calculations, assigning TRAN_NO2_STD = 1.0:
1426 !C
1427  IF(ino2.NE.1) THEN
1428  DO i=1,no2pt
1429  tran_no2_std(i) = 1.0
1430  END DO
1431  END IF
1432 
1433 
1434 !C
1435 !C Initial arrays for mean layer pressure and temperatures
1436 
1437  DO 320 i=1,nl
1438  dp(i)=p(i)-p(i+1)
1439  pm(i)=(p(i)+p(i+1))/2.0
1440  tm(i)=(t(i)+t(i+1))/2.0
1441  320 CONTINUE
1442 
1443 !C
1444 !C Calculate high resolution transmittances (0.05 cm-1) of CO2, N2O, CO,
1445 !C CH4, and O2 in the 0.56 - 3.1 micron range, and save values for
1446 !C calculating total atmospheric transmittances later.
1447 !C Because water vapor amounts are allowed to vary,
1448 !C the high resolution water vapor transmittances are calculated
1449 !C in subroutines TRAN_TABLE and TRANCAL. TRAN_TABLE provides variable
1450 !C water vapor amounts, and calls TRANCAL for the calculation of
1451 !C corresponding vapor transmittance spectrum.
1452 !C
1453 !C*** Note: The array WAVNO_HI is not used in actual computing, the array
1454 !C* should be removed from COMMONS_INC and the following DO LOOP
1455 !C* of this program, the purpose of keeping WAVNO_HI now is to
1456 !C* check array indices and make sure the correctness of the
1457 !C* indices.
1458 !C*
1459 !C Initialize the TRAN_HI_OTHERS array for high resolution spectrum:
1460 
1461  tran_hi_others(:) = 1.0
1462 
1463 
1464 !C---------------------------------------
1465 !C For CO2 transmittance calculation -
1466  IF(ico2.EQ.1) THEN
1467 !C---- SCLCO2=1.0
1468 !C---- On 2/7/2013 B.-C. Gao made the modification - Increased SCLCO2 i
1469 !C---- from 1.0 to 1.1 to reflect the fact that the CO2 VMR reached the
1470 !C---- 2012 level of 390 ppmv.
1471 !C----
1472  sclco2=1.1
1473 
1474  DO 322 i=1,nl
1475  vmrm(i)=sclco2*355.0*1.0e-06
1476 !C Scale the VMRM by the two-way path geometrical factors. The geometric
1477 !C factors, G_OTHER, varies with atmospheric layer number for
1478 !C aircraft observational geometries.
1479  vmrm(i)= vmrm(i)*g_other(i)
1480  322 CONTINUE
1481 
1482  sumcf(:) = 0.0
1483  DO j = k_surf, 19
1484  sumcf(:) = sumcf(:) - abscf_co2(:,j)*dp(j-k_surf+1)*vmrm(j-k_surf+1)
1485  END DO
1486 
1487  tran_hi_others(:) = tran_hi_others(:)*exp(sumcf(:)*q* 28.966 / &
1488  6.0225e+23 / 1.0e-06)
1489  END IF
1490 
1491 !C--------------------------------------------
1492 !C For N2O transmittance calculation.
1493 
1494  IF(in2o.EQ.1) THEN
1495 ! if (first.eq.1) print*,"Doing N2O..."
1496  DO 324 i=1,nl
1497  vmrm(i)=0.3*1.0e-06
1498  vmrm(i)= vmrm(i)*g_other(i)
1499  324 CONTINUE
1500 
1501 
1502  sumcf(:) = 0
1503  DO j = k_surf, 19
1504  sumcf(:) = sumcf(:) - abscf_n2o(:,j)*dp(j-k_surf+1)*vmrm(j-k_surf+1)
1505  END DO
1506 
1507  tran_hi_others(:) = tran_hi_others(:)*exp(sumcf(:)*q* 28.966 / &
1508  6.0225e+23 / 1.0e-06)
1509 ! if (first.eq.1) then
1510 ! do i=1,NP_HI
1511 ! print*,i," Tran_hi_others=",TRAN_HI_OTHERS(i)
1512 ! end do
1513 ! endif
1514  END IF
1515 
1516 !C--------------------------------------------
1517 !C For CO transmittance calculation.
1518  IF(ico.EQ.1) THEN
1519 ! if (first.eq.1) print*,"Doing CO..."
1520  DO 325 i=1,nl
1521  vmrm(i)=0.1*1.0e-06
1522  vmrm(i)= vmrm(i)*g_other(i)
1523  325 CONTINUE
1524 
1525  sumcf(:) = 0.0
1526  DO j = k_surf, 19
1527  sumcf(:) = sumcf(:) - abscf_co(:,j)*dp(j-k_surf+1)*vmrm(j-k_surf+1)
1528  END DO
1529  tran_hi_others(:) = tran_hi_others(:)*exp(sumcf(:)*q* 28.966 / &
1530  6.0225e+23 / 1.0e-06)
1531 ! if (first.eq.1) then
1532 ! do i=1,NP_HI
1533 ! print*,i," Tran_hi_others=",TRAN_HI_OTHERS(i)
1534 ! end do
1535 ! endif
1536  END IF
1537 
1538 !C--------------------------------------------
1539 !C For CH4 transmittance calculation.
1540 !C For assigning CH4 VMRM
1541 !C NOTE: The scaling factor of 0.8 for the CH4 VMRS was obtained by comparing
1542 !C transmittance spectra calculated using our program, which is based on
1543 !C the Malkmus narrow band spectral model, with a ratioed spectrum
1544 !C provided by G. C. Toon at Jet Propulsion Laboratory (JPL). The JPL
1545 !C ratio spectrum was obtained by ratioing a high resolution (0.005 cm-1)
1546 !C solar spectrum measured at ground level against a solar spectrum
1547 !C measured at an altitude of approximately 35 km with the same Fourier
1548 !C Transform spectrometer. The high resolution ratio spectrum was
1549 !C degraded to a resolution of 10 nm during our derivation of the
1550 !C scaling factor for the CH4 VMRS.
1551 
1552  IF(ich4.EQ.1) THEN
1553 !C*** SCLCH4=0.8
1554  sclch4=1.0
1555  DO 326 i=1,nl
1556  vmrm(i)=sclch4*1.6*1.0e-06
1557  vmrm(i)= vmrm(i)*g_other(i)
1558  326 CONTINUE
1559 
1560 
1561  sumcf(:) = 0.0
1562  DO j = k_surf, 19
1563  sumcf(:) = sumcf(:) - abscf_ch4(:,j)*dp(j-k_surf+1)*vmrm(j-k_surf+1)
1564  END DO
1565 
1566  tran_hi_others(:) = tran_hi_others(:)*exp(sumcf(:)*q* 28.966 / &
1567  6.0225e+23 / 1.0e-06)
1568 
1569  END IF
1570 
1571 !C--------------------------------------------
1572 !C For O2 transmittance calculation.
1573  IF(io2.EQ.1) THEN
1574  sumcf(:) = 0
1575 !C***Modified by Bo-Cai Gao on 2/7/2013 to increase O2 absorption
1576 !C--- coefficients by the factor SCL_O2 for wavelengths > 1.2 micron
1577 !C--- in order to model properly the atmospheric O2 band centered
1578 !C--- near 1.265 micron.
1579 
1580  scl_o2 = 2.60
1581 
1582  DO 327 i=1,nl
1583  vmrm(i)=0.21
1584  vmrm(i)= vmrm(i)*g_other(i)
1585  327 CONTINUE
1586 
1587 
1588 !C***Modified by Bo-Cai Gao on 2/7/2013 to increase O2 absorption
1589 !C--- coefficients by the factor SCL_O2 for wavelengths > 1.2 micron
1590 !C--- i& < 1.3333 micron in order to model properly the atmospheric
1591 !C--- O2 band centered near 1.265 micron.
1592  DO j = k_surf, 19
1593  sumcf(:) = sumcf(:) - abscf_o2(:,j)*dp(j-k_surf+1)*vmrm(j-k_surf+1)
1594 
1595  END DO
1596  tran_hi_others(1:9000) = tran_hi_others(1:9000) * exp(sumcf(1:9000)*q* 28.966 / &
1597  6.0225e+23 / 1.0e-06)
1598  tran_hi_others(9001:106600) = tran_hi_others(9001:106600) * exp(sumcf(9001:106600)*q*scl_o2* 28.966 / &
1599  6.0225e+23 / 1.0e-06)
1600  tran_hi_others(106601:np_hi) = tran_hi_others(106601:np_hi) * exp(sumcf(106601:np_hi)*q* 28.966 / &
1601  6.0225e+23 / 1.0e-06)
1602 
1603  END IF
1604 
1605 
1606 !C--------------------------------------------
1607 !C End of calculation of high resolution transmittances for CO2, N2O, CO,
1608 !C CH4, and O2.
1609 !C--------------------------------------------
1610 !C--------------------------------------------
1611 !C
1612 !C--D WRITE(*,*)'NPSHIF=',NPSHIF,' DWAVLN=',DWAVLN
1613 !C--D WRITE(*,*)'NO3PT=',NO3PT,' VMIN=',VMIN,' ISTART=',ISTART
1614 !C--D WRITE(*,*)'IH2OLQ=',IH2OLQ,' RLQAMT=',RLQAMT,' NGASTT=',NGASTT
1615 !C--D WRITE(*,*)'NH2O=',NH2O,' VSTART=',VSTART,' VEND=',VEND
1616 !C--D WRITE(*,*)'IEND=',IEND
1617 !C--D WRITE(*,*)'ISTCAL=',ISTCAL,' IEDCAL=',IEDCAL
1618 !C--D DO 545 I=1,NL
1619 !C--D 545 WRITE(*,*)I,DP(I),PM(I),TM(I),VMRM(I)
1620 !C--D WRITE(*,*)'IST1=',IST1,' IED1=',IED1,' IST2=',IST2,' IED2=',IED2
1621 !C--D WRITE(*,*)'ISTP94=',ISTP94,' IEDP94=',IEDP94
1622 !C--D WRITE(*,*)'IST3=',IST3,' IED3=',IED3,' IST4=',IST4,' IED4=',IED4
1623 !C--D WRITE(*,*)'IST1P14=',IST1P14,' IED1P14=',IED1P14
1624 !C--D WRITE(*,*)'WT1=',WT1,' WT2=',WT2,' WT3=',WT3,' WT4=',WT4,' JA=',JA
1625 !C--D WRITE(*,*)'NCV2=',NCV2,' NCVHF2=',NCVHF2,' NCVTT2=',NCVTT2,
1626 !C--D &' ISTRT2=',ISTRT2,' IEND2=',IEND2
1627 !C--D DO 544 I=1,30
1628 !C--D 544 WRITE(*,*)'I=',I,' FINST2(I)=',FINST2(I)
1629 !C--D WRITE(*,*)'NATOT=',NATOT,' NBTOT=',NBTOT
1630 !C--D WRITE(*,*)'NCTOT=',NCTOT,' NDTOT=',NDTOT
1631 
1632  first = 0
1633  RETURN
1634  END
1635 
1636 !********************************************************************************
1637 !* *
1638 !* Name: TRAN_TABLE *
1639 !* Purpose: This subroutine generates a table consisting of 60 atmospheric *
1640 !* transmittance spectra at the solar and observational *
1641 !* geometry and with 60 column water vapor values. The table also *
1642 !* includes the total amounts of column water vapor used in the *
1643 !* calculations, and the 3-channel ratios calculated from the window *
1644 !* and absorption channels in and around the 0.94- and 1.14-um water *
1645 !* vapor bands. *
1646 !* Parameters: none *
1647 !* Algorithm: For each of the 60 water vapor amounts, calculate the *
1648 !* atmospheric transmittance, and save *
1649 !* Globals Used: NH2O - number of column water vapor values *
1650 !* VAPTT - geometrically adjusted water vapor total *
1651 !* R094 - channel ratio for .94 um region *
1652 !* R114 - channel ratio for 1.14 um region *
1653 !* TRNCAL - atmospheric transmittance spectra *
1654 !* Global Output: VAPTOT() - array containing geometrically adjusted water *
1655 !* vapor values *
1656 !* ROP94() - array containing channel ratios for .94 um region *
1657 !* R1P14() - array containing channel ratios for 1.14 um region*
1658 !* TRNTBL() - 2 dimensional array containing one transmittance *
1659 !* spectrum for each column water vapor amount *
1660 !* Return Codes: none *
1661 !* Special Considerations: none *
1662 !* *
1663 !********************************************************************************
1664 !********************************************************************************
1665 !* TRANCAL combined with TRAN_TABLE by R. Healy 4/28/2015 *
1666 !* Name: TRANCAL *
1667 !* Purpose: This program calculates combined transmittances of H2O, CO2, O3, *
1668 !* N2O, CO, CH4, and O2. *
1669 !* Parameters: none. *
1670 !* Algorithm: The calculations were based on the line-by-line absorption *
1671 !* parameters supplied by William R. Ridgway of NASA/GSFC. *
1672 !* Global output:VAPTT - geometrically adjusted water vapor total. *
1673 !* R094 - channel ratio for 0.94 um region. *
1674 !* R114 - channel ratio for 1.14 um region. *
1675 !* TRNCAL - total transmittances of all gases that match the *
1676 !* resolutions of imaging spectrometers. *
1677 !* Return Codes: none. *
1678 !* Special Considerations: The high resolution (0.05 cm-1) line-by-line *
1679 !* absorption parameters cover the 0.555 - 3.33 micron spectral range *
1680 !* (3000 - 18000 cm-1). The medium resolution ozone absorption *
1681 !* coefficients covers the 0.3-0.8 um spectral range. The line-by-line *
1682 !* high resolution spectra were first smoothed to medium resolution *
1683 !* spectra (resolution = 0.2 nm, wavelength spacing = 0.1 nm) covering *
1684 !* the 0.56 - 3.1 micron spectral region. The medium resolution spectra *
1685 !* of O3 and other gases are combined (in SUBROUTINE TRAN_SMOOTH) to form *
1686 !* a single medium resolution spectrum from 0.3 to 3.1 micron. This *
1687 !* combined spectrum (medium resolution) is then smoothed to lower *
1688 !* resolutions to match the resolutions of imaging spectrometers. The *
1689 !* smoothing is also done in SUBROUTINE TRAN_SMOOTH. *
1690 !* *
1691 !********************************************************************************
1692 
1693 
1694  SUBROUTINE tran_table
1695 
1696  include 'COMMONS_INC.f'
1697 
1698 !C Common variables
1699  dimension dp(25), pm(25), tm(25), vmrm(25), g_vap(25),g_other(25)
1700  dimension h(25), t(25), p(25), vmr(25)
1701  dimension wavobs(nobs_max),fwhm(nobs_max)
1702  COMMON /getinput1/ ih2ovp,ico2,io3,in2o,ico,ich4,io2,ino2
1703  COMMON /getinput3/ h,t,p,vmr,nb,nl,model,iaer,v,taer55,vrto3,sno2
1704  COMMON /getinput4/ wavobs,fwhm
1705  COMMON /getinput5/ nobs,ifullcalc,hsurf,dlt,dlt2
1706  COMMON /init_speccal3/ nh2o
1707  COMMON /init_speccal5/ dp,pm,tm,vmrm
1708  COMMON /model_adj1/ clmvap,q
1709  COMMON /model_adj4/ k_surf
1710  COMMON /model_adj3/ k_plane, dvap_plane, dvap_layer, &
1711  dp_plane, dp_layer, clmvapp
1712 
1713  dimension ssh2o(nh2o_max)
1714  dimension vaptot(nh2o_max), r0p94(nh2o_max), r1p14(nh2o_max), trntbl(nobs_max,nh2o_max), &
1715  tran_kd(nobs_max,nh2o_max), diff_tran(nobs_max,nh2o_max),trh2(nobs_max,nh2o_max), &
1716  trntblo(nobs_max)
1717  COMMON /tran_table1/ sh2o,vaptot,r0p94,r1p14,trntbl,tran_kd, diff_tran,trntblo
1718  ! Split path transmittance
1719  ! Just need the values for the four table entries calculated on call to get_atrem
1720  ! rjh - 1/11/2016
1721  REAL TRAN_HI_SA(NP_HI,2),TRAN_HI_SAP1(NP_HI,2),TRAN_HI_SB(NP_HI,2),TRAN_HI_SBP1(NP_HI,2), &
1722  trntbl_s(nobs_max,2),trntbl_so(nobs_max,2)
1723  COMMON /tran_tables/tran_hi_sa,tran_hi_sap1,tran_hi_sb,tran_hi_sbp1
1724  COMMON /tran_table_l2gen/trntbl_s,trntbl_so
1725  !COMMON /TRANCAL1/ VAPTT
1726 
1727  REAL MU,MU0,SSH2O_S(NH2O_MAX,2),VMRM_S(25,2)
1728  COMMON /geometry5/mu,mu0,ssh2o_s
1729 
1730  COMMON /geometry2/ gco2,go3,gn2o,gco,gch4,go2,ssh2o,totlo3,ggeom
1731  COMMON /geometry3/ g_vap, g_other, g_vap_equiv
1732  COMMON /geometry4/vap_slant_mdl
1733 
1734  INTEGER start(3)
1735  INTEGER cnt(3)
1736  CHARACTER(len=4096) :: filename
1737  dimension sumcf(np_hi), sumcf_s(np_hi,2)
1738  REAL ABSCF_H2O(NP_HI,19)
1739 
1740  REAL, ALLOCATABLE :: TG(:), TKCDF(:,:,:),DIFFT(:,:),SUM_KD(:),F1(:),F2(:),TKCDFC(:,:,:)
1741  REAL, ALLOCATABLE :: WAVNO_HI(:)
1742  CHARACTER*31 GNAM, BNAM,LNAM
1743 
1744  REAL, ALLOCATABLE :: TDP(:),TVMRM(:), TRAN_HI(:,:)
1745  SAVE tdp, tvmrm
1746 
1747  INTEGER FIRST/1/,IDOSMOOTH/0/
1748  REAL WV/4.1294627/
1749  LOGICAL DOINLINEKD/.TRUE./
1750  SAVE first, abscf_h2o, tg, tkcdf, difft,n_g, wv, idosmooth, doinlinekd
1751  data nl/19/,ng/7/
1752 
1753  ALLOCATE( tran_hi(np_hi,nh2o_max) )
1754  ALLOCATE( wavno_hi(np_hi) )
1755 
1756  if (first.eq.1) then
1757 
1758  if (ifullcalc.eq.1) then
1759  print*,'ATREM: **WARNING** Full_calc is on. Processing will be extremely slow...'
1760  else
1761  print*,'ATREM: Full_calc is off. Processing using k-distribution method...'
1762  endif
1763 
1764  idosmooth = ico2 + in2o + ico + ich4 + io2 + io3 + ino2
1765 
1766  write(filename(1:dln),'(a)') datpath(1:dln)
1767  write(filename(dln+1:),'(a)') 'abscf_gas.nc'
1768 
1769  start(1) = 1
1770  start(2) = 1
1771  start(3) = 1
1772  cnt(1) = np_hi
1773  cnt(2) = 19
1774  cnt(3) = 0
1775  ncid = ncopn(filename,ncnowrit,ircode)
1776  nrhid = ncvid(ncid, 'abscf_h2o', ircode)
1777  CALL ncvgt (ncid, nrhid, start, cnt, abscf_h2o, ircode)
1778  if (ircode .ne.0) then
1779  write(*,*) 'Error reading abscf_gas.nc: abscf_h2o: rcode=',ircode
1780  stop 0
1781  end if
1782  cnt(2) = 1
1783  nrhid = ncvid(ncid, 'waveno', ircode)
1784  CALL ncvgt (ncid, nrhid, start, cnt, wavno_hi, ircode)
1785  if (ircode .ne.0) then
1786  write(*,*) 'Error reading abscf_gas.nc: waveno: rcode=',ircode
1787  stop 0
1788  end if
1789 
1790  CALL ncclos(ncid, rcode)
1791 
1792  if (.not.doinlinekd) then
1793  write(filename(1:dln),'(a)') datpath(1:dln)
1794  write(filename(dln+1:),'(a)') 'hico_atrem_h2o_coef7.nc'
1795 
1796  ncid = ncopn(filename,ncnowrit,ircode)
1797 
1798  CALL ncinq(ncid,ndims,nvars,natts,irecdim,ircode)
1799 
1800  if (ndims.NE.3) then
1801  write(*,*) 'Error Wrong number of dims in file'//trim(filename)// &
1802  'Expected 4, but got ',ndims
1803  stop 0
1804  end if
1805 
1806  CALL ncdinq(ncid, 1, gnam, n_g, ircode)
1807 
1808  CALL ncdinq(ncid, 2, bnam, n_b, ircode)
1809 
1810  CALL ncdinq(ncid, 3, lnam, n_l, ircode)
1811 
1812  !CALL NCDINQ(NCID, 4, LNAM, N_H, IRCODE)
1813 
1814  if (n_b.NE.nobs) then
1815  write(*,*) ' Bands expected (',nobs,') do not match number of bands in file'// &
1816  '(',n_b,') for file='//filename
1817  stop 0
1818  end if
1819 
1820  ! if (N_H.NE.NH2O) then
1821  ! write(*,*) ' NH2O expected (',NH2O,') do not match NH2O in file'// &
1822  ! '(',N_H,') for file='//filename
1823  ! stop 0
1824  ! end if
1825  else
1826  n_g = 7
1827  n_l = 19
1828  n_b = nobs
1829  endif ! doinlinekd
1830 
1831  ALLOCATE( tg(n_g) )
1832  ALLOCATE( tkcdf(n_l,n_b,n_g) )
1833  !ALLOCATE( DIFFT(N_B,N_H) )
1834  ALLOCATE( f1(n_b) )
1835  ALLOCATE( f2(n_b) )
1836  ALLOCATE( sum_kd(n_b))
1837 
1838  ALLOCATE( tvmrm(n_l) )
1839  ALLOCATE( tdp(n_l) )
1840 
1841  if (doinlinekd) then
1842  tg(1:7) = (/ 0.0, 0.379, 0.5106, 0.81, 0.9548, 0.9933, 1.0/)
1843  else
1844 
1845  start(1) = 1
1846  start(2) = 1
1847  start(3) = 1
1848  cnt(1) = n_g
1849  cnt(2) = 0
1850  cnt(3) = 0
1851 
1852  nrhid = ncvid(ncid, 'g', ircode)
1853  CALL ncvgt (ncid, nrhid, start, cnt, tg, ircode)
1854  if (ircode .ne.0) then
1855  write(*,*) 'Error reading '//filename//': rcode=',ircode
1856  stop 0
1857  end if
1858 
1859  start(1) = 1
1860  start(2) = 1
1861  start(3) = 1
1862  cnt(1) = n_l
1863  cnt(2) = n_b
1864  cnt(3) = n_g
1865 
1866  nrhid = ncvid(ncid, 'k_h2o', ircode)
1867  CALL ncvgt (ncid, nrhid, start, cnt, tkcdf, ircode)
1868  if (ircode .ne.0) then
1869  write(*,*) 'Error reading '//filename//': rcode=',ircode
1870  stop 0
1871  end if
1872 
1873  ! start(1) = 1
1874  ! start(2) = 1
1875  ! start(3) = 1
1876  ! cnt(1) = N_B
1877  ! cnt(2) = N_H
1878  ! cnt(3) = 0
1879 
1880  ! NRHID = NCVID (NCID, 'diffT', IRCODE)
1881  ! CALL NCVGT (NCID, NRHID, START, CNT, DIFFT, IRCODE)
1882  ! if (ircode .ne.0) then
1883  ! write(*,*) 'Error reading '//filename//': rcode=',ircode
1884  ! stop 0
1885  ! end if
1886 
1887  endif
1888 
1889 
1890  endif
1891 
1892 ! Moved from INIT_SPECAL because it seems more logical here. - rjh 01/04/2016
1893 !C Initial water vapor VMRs for repeated use in other subroutines and
1894 !C adjust layered water vapor VMRM with geometrical factors.
1895  DO i = 1, nl
1896  vmrm(i) = (vmr(i)+vmr(i+1))/2.0
1897 !C Scale the VMRM by the two-way path geometrical factors. The geometric
1898 !C factors, G_VAP, varies with atmospheric layer number for
1899 !C aircraft observational geometries.
1900  if (isplitp.ne.0) then ! perform the split path calculations
1901  vmrm_s(i,1) = vmrm(i)*mu0
1902  if (i.lt.k_plane) THEN
1903  vmrm_s(i,2) = vmrm(i)*mu
1904  else
1905  if (i.eq.k_plane) THEN
1906  vmrm_s(i,2) = vmrm(i)*mu*dvap_plane/dvap_layer
1907  else
1908  vmrm_s(i,2) = 0
1909  end if
1910  END IF
1911  WRITE(91,*) i,' VMRM SOL, OBS=',vmrm_s(i,1),vmrm_s(i,2)
1912  end if
1913  vmrm(i) = vmrm(i)*g_vap(i)
1914  WRITE(91,*) 'VMRM=',vmrm(i)
1915  END DO
1916 
1917  if (ifullcalc.ne.0.or.first.eq.1) then
1918 
1919  !C For each water vapor amount, calculate the geometrically adjusted water
1920  !C vapor amount, the channel ratios, and the transmittance spectrum.
1921  sumcf(:) = 0
1922  IF (isplitp.NE.0) THEN
1923  sumcf_s(:,1) = 0
1924  sumcf_s(:,2) = 0
1925  END IF
1926  DO j = k_surf, 19
1927  sumcf(:) = sumcf(:) - abscf_h2o(:,j)*dp(j-k_surf+1)*vmrm(j-k_surf+1)
1928  IF (isplitp.NE.0) THEN
1929  sumcf_s(:,1) = sumcf_s(:,1) - abscf_h2o(:,j)*dp(j-k_surf+1)*vmrm_s(j-k_surf+1,1)
1930  sumcf_s(:,2) = sumcf_s(:,2) - abscf_h2o(:,j)*dp(j-k_surf+1)*vmrm_s(j-k_surf+1,2)
1931  END IF
1932  END DO
1933 
1934  DO i=1,nh2o
1935  !C Calculate water vapor transmittances with different scaling factors:
1936  !C
1937  !C Multiplying the high resolution water vapor transmittance with combined
1938  !C transmittances of CO2, N2O, CO, CH4, and O2:
1939  !C
1940 
1941  tran_hi(:,i) = exp(sumcf(:)*ssh2o(i) * q * 28.966 / &
1942  6.0225e+23 / 1.0e-06) ! *TRAN_HI_OTHERS(:) - Done in TRAN_SMOOTH_OTHERS
1943  !C Total amount of water vapor (in unit of cm) corresponding to the spectrum.
1944  vaptot(i)= vap_slant_mdl * ssh2o(i)
1945 ! write(91,*) 'VAPTT=',VAPTOT(I),SSH2O(I),VAP_SLANT_MDL
1946 
1947  END DO
1948 
1949  if (isplitp.ne.0) then ! perform the split path calculations
1950  DO j=1,2
1951  tran_hi_sa(:,j) = exp(sumcf_s(:,j) *ssh2o_s(ja_l2,j) * q * 28.966 / &
1952  6.0225e+23 / 1.0e-06)
1953  tran_hi_sap1(:,j) = exp(sumcf_s(:,j)*ssh2o_s(ja_l2+1,j) * q * 28.966 / &
1954  6.0225e+23 / 1.0e-06)
1955 
1956  tran_hi_sb(:,j) = exp(sumcf_s(:,j) *ssh2o_s(jb_l2,j) * q * 28.966 / &
1957  6.0225e+23 / 1.0e-06)
1958  tran_hi_sbp1(:,j) = exp(sumcf_s(:,j)*ssh2o_s(jb_l2+1,j) * q * 28.966 / &
1959  6.0225e+23 / 1.0e-06)
1960  END DO
1961 ! write(91,*) 'SPLIT: JA,JB=',JA_L2,JB_L2,'TRAN_HI=',TRAN_HI(1,JA_L2), &
1962 ! ' TRAN_HI_SA:',TRAN_HI_SA(1,1),TRAN_HI_SA(1,2), &
1963 ! TRAN_HI_SAP1(1,1),TRAN_HI_SAP1(1,2),TRAN_HI_SB(1,1),TRAN_HI_SB(1,2), &
1964 ! TRAN_HI_SBP1(1,1),TRAN_HI_SBP1(1,2)
1965 ! write(91,*) 'SSH2O JAJB:',SSH2O_S(JA_L2,1),SSH2O_S(JA_L2,2),SSH2O_S(JB_L2,1),SSH2O_S(JB_L2,2), ' SOL=', &
1966 ! SUMCF_S(1,1), SSH2O_S(JA_L2,1), SUMCF_S(1,1) *SSH2O_S(JA_L2,1) * Q * 28.966 / 6.0225E+23 / 1.0E-06,' SEN=', &
1967 ! SUMCF_S(1,2), SSH2O_S(JA_L2,2), SUMCF_S(1,2) *SSH2O_S(JA_L2,2) * Q * 28.966 / 6.0225E+23 / 1.0E-06,' SOL=', &
1968 ! exp(SUMCF_S(1,1) *SSH2O_S(JA_L2,1) * Q * 28.966 / 6.0225E+23 / 1.0E-06),' SEN=', &
1969 ! exp(SUMCF_S(1,2) *SSH2O_S(JA_L2,2) * Q * 28.966 / 6.0225E+23 / 1.0E-06)
1970 
1971  endif
1972 
1973  endif
1974  if (ifullcalc.eq.0) then
1975 ! The following code calculates the k-distrubition coefficients
1976 ! as opposed to reading them in from a netcdf file.
1977 ! -rjh 9/23/2015
1978  if (first.eq.1.AND.doinlinekd) then
1979  ALLOCATE( tkcdfc(n_l,n_b,n_g) )
1980  call kdist_gas_abs(tkcdfc,abscf_h2o,np_hi,wavno_hi,wavobs,n_b)
1981  tkcdf = tkcdfc
1982  end if
1983  ! Perform the k-distribution calculation Trapezoidal integral for transmittance over the NOBS(NBANDS) bands
1984  DO i=1,nh2o
1985  tran_kd(:,i) = 1.0
1986 
1987  DO j = k_surf, 19
1988 
1989  sum_kd(:) = 0.0
1990 
1991  f1(:) = exp(-tkcdf(j,:,1) *dp(j-k_surf+1)*vmrm(j-k_surf+1)*ssh2o(i))
1992 
1993  DO k = 1, n_g-1
1994  f2(:) = exp(-tkcdf(j,:,k+1)*dp(j-k_surf+1)*vmrm(j-k_surf+1)*ssh2o(i))
1995  sum_kd(:) = sum_kd(:)+(f1(:) + f2(:))*(tg(k+1) - tg(k))/2.0
1996  f1(:) = f2(:)
1997  END DO
1998 
1999  tran_kd(:,i) = tran_kd(:,i)*sum_kd(:)
2000 
2001  END DO
2002 
2003  !C Total amount of water vapor (in unit of cm) corresponding to the spectrum.
2004  vaptot(i)= vap_slant_mdl * ssh2o(i)
2005  END DO
2006 
2007  endif
2008 
2009  if (ifullcalc.ne.0.or.first.eq.1) then
2010 
2011 !C
2012 !C Smooth the high resolution spectra to resolutions of measured spectrum
2013 !C
2014 
2015  CALL tran_smooth(tran_hi)
2016 
2017  if (first.eq.1) then
2018  DO i=1,nh2o
2019  trh2(:,i) = trntbl(:,i)
2020  ! DO J=1,NOBS
2021  ! write(6,*) 'RJH: TRH2: ',TRH2(J,I)
2022  ! END DO
2023  END DO
2024  endif
2025 
2026  endif
2027 
2028  trntblo(:) = 1.0
2029  trntbl_so(:,:) = 1.0
2030  ! Only call the TRAN_SMOOTH_OTHERS if the other trace gases were selected
2031  IF (idosmooth.GT.0) THEN
2032  CALL tran_smooth_others
2033  ENDIF
2034 
2035  if (ifullcalc.eq.0) then
2036 
2037  if (first.eq.1) then
2038 ! do k=1,NOBS
2039 ! print*,K," FAST)TRNTBL=",TRAN_KD(k,60)*DIFF_TRAN(k,1),TRNTBLO(k)
2040 ! end do
2041  end if
2042  DO i=1,nh2o
2043  trntbl(:,i) = tran_kd(:,i)*diff_tran(:,i)*trntblo(:)
2044 
2045 ! if (first.eq.1) then
2046 ! DO J=1,NOBS
2047 ! write(6,*) 'RJH: DIFF_TRAN: ',I,J,TRNTBL(J,I),TRH2(J,I),TRAN_KD(J,I),DIFF_TRAN(J,I)
2048 ! END DO
2049 ! endif
2050  END DO
2051 
2052  ELSE
2053  if (first.eq.1) then
2054  do k=1,nobs
2055  print*,k," SLOW)TRNTBL=",trntbl(k,60),trntblo(k)
2056  end do
2057  end if
2058 
2059  DO i=1,nh2o
2060  trntbl(:,i) = trntbl(:,i)*trntblo(:)
2061  END DO
2062 
2063  trntbl_s(:,:) = trntbl_s(:,:)*trntbl_so(:,:)
2064 
2065  endif
2066 
2067 !C Calculate 3-channel ratio values, R094 and R114, from simulated spectra.
2068  CALL chnlratio
2069 
2070  first=0
2071  DEALLOCATE(tran_hi,wavno_hi)
2072  RETURN
2073  END
2074 
2075  subroutine linterp(x,y,n,xi,yi)
2076  real*4 x(n),y(n),xi,yi
2077  integer n
2078 
2079  klo=1
2080  khi=n
2081  k=0
2082  do while (khi-klo.gt.1)
2083  k=(khi+klo)/2
2084  if(x(k).gt.xi)then
2085  khi=k
2086  else
2087  klo=k
2088  endif
2089  end do
2090 
2091  if (khi.eq.klo) then !extrapolate
2092  klo = klo - 1
2093  if (klo.le.0) then
2094  !print*,"Ooops..."
2095  klo=1
2096  !stop 0
2097  endif
2098  yi = y(khi) + (xi-x(khi))/(x(khi)-x(klo))*(y(khi)-y(klo))
2099  else
2100  yi = y(klo) + (xi-x(klo))/(x(khi)-x(klo))*(y(khi)-y(klo))
2101  endif
2102 
2103  end
2104 
2105  SUBROUTINE kdist_gas_abs(kcdf,abscf,np_hi,waveno,wavobs,nwave)
2106 
2107  ! R. Healy 9/2015
2108  ! Reconstruct Transmittances from the k coefficients (from Amir Ibrahim's Matlab Code)
2109 
2110  real*4 :: abscf(np_hi,19),waveno(np_hi),wavobs(nwave),kcdf(19,nwave,7)
2111  real*4 alayers(np_hi,19)
2112  REAL, ALLOCATABLE :: diflam(:),UV_lam(:),IR_lam(:),uv_dlam(:),ir_dlam(:),lam(:), &
2113  dwave(:),dwn(:),wn(:),g_i(:),k_i(:),g(:),kg(:),logk(:),kint(:,:), &
2114  k7(:,:,:),kk(:)
2115  INTEGER, ALLOCATABLE :: wavel_window(:,:)
2116  INTEGER binnum(19)
2117  real*4 g7(7)/ 0, 0.379, 0.6, 0.81, 0.9548, 0.9933, 1/
2118  character*1 x /''/
2119  integer*1 inul
2120  equivalence(inul,x)
2121 
2122  data q/2.15199993e+25/ ! Q=# of molecules above the surface at one atmosphere (molecules/cm**2)
2123 
2124  do i=1,19
2125 
2126  alayers(:,i) = abscf(:,i)*q*28.966/ &
2127  6.0225e+23 / 1.0e-06
2128  end do
2129 ! wavobs - array of center wavelengths of instrument
2130 ! DLAM_cent - delta center wavelengths
2131 
2132  ALLOCATE( diflam(nwave) )
2133 
2134  dlam = 9999
2135  wmin = 9999
2136  wmax = -9999
2137  do i=1,nwave-1
2138  diflam(i) = wavobs(i+1) - wavobs(i)
2139  if (dlam.gt.diflam(i)) dlam = diflam(i)
2140  if (wmin.gt.wavobs(i)) wmin = wavobs(i)
2141  if (wmax.lt.wavobs(i)) wmax = wavobs(i)
2142  end do
2143 
2144  diflam(nwave) = diflam(nwave-1)
2145 
2146  if (wmin.gt.wavobs(nwave)) wmin = wavobs(nwave)
2147  if (wmax.lt.wavobs(nwave)) wmax = wavobs(nwave)
2148 
2149  ndxwuv = (wmin-0.0001 - 0.3)/dlam + 1
2150  ndxwir = (3.1- (wmax+0.0001))/diflam(nwave) + 1
2151  ndxtot = nwave+ndxwuv+ndxwir
2152 
2153  ALLOCATE( uv_lam(ndxwuv) )
2154  ALLOCATE( ir_lam(ndxwir) )
2155  ALLOCATE( uv_dlam(ndxwuv) )
2156  ALLOCATE( ir_dlam(ndxwir) )
2157  ALLOCATE( lam(ndxtot) )
2158  ALLOCATE( dwave(ndxtot) )
2159  ALLOCATE( dwn(ndxtot) )
2160  ALLOCATE( wn(ndxtot) )
2161  ALLOCATE( wavel_window(ndxtot,2) )
2162 
2163  k = ndxtot
2164  swav = 0.3
2165 
2166  do i=1,ndxwuv
2167  uv_lam(i) = swav
2168  uv_dlam(i) = diflam(1)
2169  swav = swav + dlam
2170  lam(k) = uv_lam(i)
2171  dwn(k) = 10000.*dlam/(lam(k)**2)
2172  wn(k) = 10000./lam(k)
2173  k = k - 1
2174  end do
2175  swav = wmin
2176  ks=k
2177  do i=1,nwave
2178  lam(k) = swav
2179  dwn(k) = 10000.*diflam(i)/(lam(k)**2)
2180  wn(k) = 10000./lam(k)
2181  swav = swav + diflam(i)
2182  k = k - 1
2183  end do
2184 
2185  swav = wmax+0.0001
2186 
2187  do i=1,ndxwir
2188  ir_lam(i) = swav
2189  ir_dlam(i) = diflam(nwave)
2190  swav = swav + diflam(nwave)
2191  lam(k) = ir_lam(i)
2192  dwn(k) = 10000.*diflam(nwave)/(lam(k)**2)
2193  wn(k) = 10000./lam(k)
2194  k = k - 1
2195  end do
2196 
2197  ALLOCATE( kint(ndxtot,7) )
2198  ALLOCATE( k7(19,ndxtot,7) )
2199 
2200  iw = nwave ! index for wavelngths for output array kcdf
2201 
2202  do i=ndxwir+1,ndxtot-ndxwuv
2203 
2204  kwavdn = -999
2205  kwavup = -999
2206 
2207  do k=1,np_hi
2208  if (kwavdn.lt.0.and.waveno(k).gt.(wn(i)-dwn(i)/2.0)) kwavdn = k
2209  if (kwavup.lt.0.and.waveno(k).gt.(wn(i)+dwn(i)/2.0)) kwavup = k
2210  end do
2211 
2212  wavel_window(i,1) = kwavdn
2213  wavel_window(i,2) = kwavup
2214 
2215  if (kwavup.lt.1.or.kwavdn.lt.1) then
2216  nsamp = 1
2217  else
2218  nsamp = kwavup - kwavdn + 1
2219  end if
2220 
2221  nbins = nsamp
2222  ALLOCATE( g_i(nbins+1) )
2223  ALLOCATE( k_i(nbins+1) )
2224  ALLOCATE( kk(nsamp+1) )
2225 
2226  do k=1,19
2227  if (kwavdn.lt.1.or.kwavup.lt.1) then
2228  kk(:) = 0
2229  else
2230  kk(1:nsamp) = alayers(kwavdn:kwavup,k)
2231  end if
2232 
2233  binnum(k) = nbins
2234  call ecdf(k_i,g_i,binnum(k),kk,nsamp)
2235 
2236  ALLOCATE( logk(nbins+1) )
2237  logk(:) = log10(k_i(:))
2238 
2239  do l=1,7
2240 
2241 
2242  call linterp(g_i,logk,binnum(k),g7(l),kint(i,l))
2243  k7(k,i,l) = 10**kint(i,l)
2244 
2245  if (i.gt.ndxwir.and.i.le.ndxtot-ndxwuv) then
2246  if (isnan(k7(k,i,l))) then
2247  k7(k,i,l) = 0
2248  endif
2249  kcdf(k,iw,l) = k7(k,i,l)
2250  end if
2251  end do
2252 
2253  DEALLOCATE(logk)
2254 
2255  end do
2256  DEALLOCATE (g_i, stat=ialloerr)
2257  DEALLOCATE (k_i)
2258  DEALLOCATE (kk)
2259 
2260  if (i.gt.ndxwir.and.i.le.ndxtot-ndxwuv) iw = iw - 1
2261  end do
2262 
2263  DEALLOCATE (k7)
2264  DEALLOCATE (kint)
2265  DEALLOCATE( uv_lam )
2266  DEALLOCATE( ir_lam )
2267  DEALLOCATE( uv_dlam )
2268  DEALLOCATE( ir_dlam )
2269  DEALLOCATE( lam )
2270  DEALLOCATE( dwave )
2271  DEALLOCATE( dwn )
2272  DEALLOCATE( wn )
2273  DEALLOCATE( wavel_window )
2274 
2275  END
2276 
2277 !********************************************************************************
2278 !* *
2279 !* Name: TRAN_SMOOTH *
2280 !* Purpose: This program is to smooth the line-by-line high resolution *
2281 !* spectrum to lower resolution spectrum that matches the resolutions *
2282 !* of imaging spectrometer data. *
2283 !* Parameters: none. *
2284 !* Algorithm: The smoothing is done in two stages. The 1st stage is to smooth *
2285 !* the high resolution spectrum to medium resolution spectrum at a *
2286 !* constant FWHM (0.2 nm) and a constant wavelength interval *
2287 !* (0.1 nm). The 2nd stage smoothing is to smooth the medium *
2288 !* resolution spectrum to resolutions of input imaging spectrometer *
2289 !* data. *
2290 !* Globals used: The global variables used are contained in the file *
2291 !* "COMMONS_INC" *
2292 !* Global output: TRNCAL - total transmittances of all gases that match the *
2293 !* resolutions of imaging spectrometers. *
2294 !* Return Codes: none. *
2295 !* *
2296 !********************************************************************************
2297 
2298  SUBROUTINE tran_smooth(TRAN_HI)
2299 
2300  include 'COMMONS_INC.f'
2301 
2302  REAL :: TRAN_HI(NP_HI,NH2O_MAX)
2303  dimension wavobs(nobs_max),fwhm(nobs_max)
2304  COMMON /getinput4/ wavobs,fwhm
2305 
2306  dimension vaptot(nh2o_max), r0p94(nh2o_max), r1p14(nh2o_max), trntbl(nobs_max,nh2o_max), &
2307  tran_kd(nobs_max,nh2o_max), diff_tran(nobs_max,nh2o_max),trntblo(nobs_max)
2308  COMMON /tran_table1/ sh2o,vaptot,r0p94,r1p14,trntbl,tran_kd, diff_tran,trntblo
2309 
2310  dimension tran_ia(nh2o_max),tran_iap1(nh2o_max)
2311 
2312  COMMON /getinput5/ nobs,ifullcalc,hsurf,dlt,dlt2
2313  REAL, ALLOCATABLE :: TRAN_STD(:,:),TRAN_MED(:,:)
2314 
2315  REAL TRAN_HI_SA(NP_HI,2),TRAN_HI_SAP1(NP_HI,2),TRAN_HI_SB(NP_HI,2),TRAN_HI_SBP1(NP_HI,2), &
2316  trntbl_s(nobs_max,2),trntbl_so(nobs_max,2)
2317  COMMON /tran_tables/tran_hi_sa,tran_hi_sap1,tran_hi_sb,tran_hi_sbp1
2318  COMMON /tran_table_l2gen/trntbl_s,trntbl_so
2319  REAL TRAN_MED_INDEX_SA(NP_MED,2),TRAN_MED_INDEX_SB(NP_MED,2), &
2320  tran_med_index_sap1(np_med,2),tran_med_index_sbp1(np_med,2), &
2321  tran_med_sa(np_med,2),tran_med_sap1(np_med,2),tran_med_sb(np_med,2),tran_med_sbp1(np_med,2), &
2322  tran_std_sa(np_std,2),tran_std_sap1(np_std,2),tran_std_sb(np_std,2),tran_std_sbp1(np_std,2), &
2323  tran_ia_sa(2),tran_ia_sap1(2),tran_ia_sb(2),tran_ia_sbp1(2), &
2324  tran_iap1_sa(2),tran_iap1_sap1(2),tran_iap1_sb(2),tran_iap1_sbp1(2), &
2325  trntblsa(2),trntblsap1(2),trntblsb(2),trntblsbp1(2)
2326  COMMON /tran_tables1/tran_med_index_sa,tran_med_index_sap1,tran_med_index_sb,tran_med_index_sbp1, &
2327  tran_med_sa,tran_med_sap1,tran_med_sb,tran_med_sbp1, &
2328  tran_std_sa,tran_std_sap1,tran_std_sb,tran_std_sbp1
2329 
2330  INTEGER FIRST/1/,IA(NOBS_MAX)
2331  SAVE first, ia
2332 
2333 !C First stage of smoothing - smooth line-by-line high resolution spectrum with
2334 !C over 300,000 points (point spacing of 0.05 cm-1) to medium resolution
2335 !C spectrum (resolution of 0.2 nm and point spacing of 0.1 nm) with about
2336 !C 25,000 points.
2337 !C
2338 !C The smoothing of line-by-line spectrum is done in wavenumber domain. For
2339 !C a spectrum with a constant 0.2 nm resolution in wavelength domain, it has
2340 !C variable resolution in wavenumber domain. This effect is properly taken
2341 !C care of in the design of smoothing functions.
2342 !C
2343 !C Because the high resolution spectrum is in wavenumber units (cm-1), while
2344 !C the medium resolution spectrum is in wavelength units, the two kinds of
2345 !C grids do not automatically match. In order to match the grids, arrays
2346 !C of INDEX_MED and TRAN_MED_INDEX are specially designed. The desired
2347 !C medium resolution spectrum, TRAN_MED, at constant 0.1 nm point spacing
2348 !C and 0.2 nm resolution is obtained through linear interpolation of
2349 !C TRAN_MED_INDEX array.
2350 !C
2351  IF (first.eq.1) THEN !RJH
2352  DO 466 j =1, np_med
2353 
2354  ncvtot_wavno = 2 * ncvhf_wavno(j) - 1
2355 
2356  sumins = 0.0
2357 
2358  DO 560 i = ncvhf_wavno(j), ncvtot_wavno
2359  finstr_wavno(i,j) = &
2360  exp( -const1*(float(i-ncvhf_wavno(j))*dwavno &
2361  /fwhm_wavno(j))**2)
2362  sumins = sumins + finstr_wavno(i,j)
2363  560 CONTINUE
2364 
2365  DO 565 i = 1, ncvhf_wavno(j)-1
2366  finstr_wavno(i,j) = finstr_wavno(ncvtot_wavno-i+1,j)
2367  sumins = sumins + finstr_wavno(i,j)
2368  565 CONTINUE
2369 
2370  sumins = sumins * dwavno
2371 
2372  DO 570 i = 1, ncvtot_wavno
2373  finstr_wavno(i,j) = finstr_wavno(i,j)*dwavno/sumins
2374  570 CONTINUE
2375 
2376 
2377  466 CONTINUE
2378 
2379 
2380 !C Index searching...
2381 !C
2382  DO j=1,nobs
2383  !C Calculate instrumental response functions...
2384 
2385  sumins = 0.0
2386 
2387  ncvtot = 2 * ncvhf(j) - 1
2388 
2389  DO 1560 i = ncvhf(j), ncvtot
2390  finstr(i,j) = &
2391  exp( -const1*(float(i-ncvhf(j))*dwavln &
2392  /fwhm(j))**2)
2393  sumins = sumins + finstr(i,j)
2394 1560 CONTINUE
2395 
2396  DO 1565 i = 1, ncvhf(j)-1
2397  finstr(i,j) = finstr(ncvtot-i+1,j)
2398  sumins = sumins + finstr(i,j)
2399 1565 CONTINUE
2400 
2401  sumins = sumins * dwavln
2402 
2403  DO 1570 i = 1, ncvtot
2404  finstr(i,j) = finstr(i,j)*dwavln/sumins
2405 1570 CONTINUE
2406 
2407 
2408  CALL hunt(wavln_std, np_std, wavobs(j), ia(j))
2409  END DO
2410 
2411  first = 0
2412  END IF
2413 
2414  ALLOCATE(tran_std(np_std,nh2o_max))
2415  ALLOCATE(tran_med(np_med,nh2o_max))
2416 !C*** !!!High resolution transmittances of CO2, N2O, CO, CH4, and O2 should
2417 !C also be calculated somewhere else (wavelength start = 0.56 micron).
2418 !C*** Here assuming TCO2*TN2O*TCO*TCH4*TO2 is already calculated previously,
2419 !C i.e., TRANS(I) = TRAN_CO2(I)*TRAN_N2O(I)*TRAN_CO(I)*TRAN_CH4(I)*TRAN_O2(I)
2420 !C and TRAN_HI(I) = TRAN_HI_H2O(I) * TRANS(I), and TRAN_HI_H2O for varying
2421 !C water vapor amounts is calculated in this subroutine.
2422 
2423  tran_med_index(:,:) = 0.0
2424  IF(isplitp.NE.0) THEN
2425  tran_med_index_sa(:,:) = 0.0
2426  tran_med_index_sap1(:,:) = 0.0
2427  tran_med_index_sb(:,:) = 0.0
2428  tran_med_index_sbp1(:,:) = 0.0
2429  END IF
2430 
2431 
2432  DO j =1, np_med
2433 
2434  ndx1 = index_med(j)-(ncvhf_wavno(j)-1)
2435  ndx2 = index_med(j)+ ncvhf_wavno(j)-1
2436  DO 491 k = ndx1,ndx2
2437  tran_med_index(j,:) = tran_med_index(j,:) + tran_hi(k,:)* &
2438  finstr_wavno(k-index_med(j)+ncvhf_wavno(j),j)
2439  IF(isplitp.NE.0) THEN
2440  tran_med_index_sa(j,:) = tran_med_index_sa(j,:) + tran_hi_sa(k,:)* &
2441  finstr_wavno(k-index_med(j)+ncvhf_wavno(j),j)
2442  tran_med_index_sap1(j,:) = tran_med_index_sap1(j,:) + tran_hi_sap1(k,:)* &
2443  finstr_wavno(k-index_med(j)+ncvhf_wavno(j),j)
2444  tran_med_index_sb(j,:) = tran_med_index_sb(j,:) + tran_hi_sb(k,:)* &
2445  finstr_wavno(k-index_med(j)+ncvhf_wavno(j),j)
2446  tran_med_index_sbp1(j,:) = tran_med_index_sbp1(j,:) + tran_hi_sbp1(k,:)* &
2447  finstr_wavno(k-index_med(j)+ncvhf_wavno(j),j)
2448  END IF
2449  491 CONTINUE
2450  END DO
2451 
2452 !C
2453 !C Linear interpolation to get TRAN_MED from TRAN_MED_INDEX:
2454 !C (Note that WAVLN_MED_INDEX(J) >= WAVLN_MED(J) )
2455 !C
2456  tran_med(1,:) = tran_med_index(1,:)
2457  tran_med(np_med,:) = tran_med_index(np_med,:)
2458  IF(isplitp.NE.0) THEN
2459  tran_med_sa(1,:) = tran_med_index_sa(1,:)
2460  tran_med_sa(np_med,:) = tran_med_index_sa(np_med,:)
2461  tran_med_sap1(1,:) = tran_med_index_sap1(1,:)
2462  tran_med_sap1(np_med,:) = tran_med_index_sap1(np_med,:)
2463  tran_med_sb(1,:) = tran_med_index_sb(1,:)
2464  tran_med_sb(np_med,:) = tran_med_index_sb(np_med,:)
2465  tran_med_sbp1(1,:) = tran_med_index_sbp1(1,:)
2466  tran_med_sbp1(np_med,:) = tran_med_index_sbp1(np_med,:)
2467  ENDIF
2468 
2469  DO j = 2, np_med-1
2470  IF(wavln_med_index(j).LE.wavln_med(j)) THEN
2471  tran_med(j,:) = tran_med_index(j,:)
2472  IF(isplitp.NE.0) THEN
2473  tran_med_sa(j,:) = tran_med_index_sa(j,:)
2474  tran_med_sap1(j,:) = tran_med_index_sap1(j,:)
2475  tran_med_sb(j,:) = tran_med_index_sb(j,:)
2476  tran_med_sbp1(j,:) = tran_med_index_sbp1(j,:)
2477  ENDIF
2478  ELSE
2479  dlt = wavln_med_index(j) - wavln_med_index(j-1)
2480  fjm1 = (wavln_med_index(j) - wavln_med(j)) /dlt
2481  fj = (wavln_med(j) - wavln_med_index(j-1))/dlt
2482  tran_med(j,:) = fjm1*tran_med_index(j-1,:) + fj*tran_med_index(j,:)
2483  IF(isplitp.NE.0) THEN
2484  tran_med_sa(j,:) = fjm1*tran_med_index_sa(j-1,:) + fj*tran_med_index_sa(j,:)
2485  tran_med_sap1(j,:) = fjm1*tran_med_index_sap1(j-1,:) + fj*tran_med_index_sap1(j,:)
2486  tran_med_sb(j,:) = fjm1*tran_med_index_sb(j-1,:) + fj*tran_med_index_sb(j,:)
2487  tran_med_sbp1(j,:) = fjm1*tran_med_index_sbp1(j-1,:) + fj*tran_med_index_sbp1(j,:)
2488 ! write(91,*) J,' TRAN_MED_SAP1=',TRAN_MED_INDEX(J,JA_L2),FJM1,FJ,TRAN_MED_INDEX(J-1,JA_L2), &
2489 ! TRAN_MED_INDEX_SAP1(J,JA_L2)
2490 ! write(91,*) J,' TRAN_MED_SAP1_SOL=',TRAN_MED_SAP1(J,1),FJM1,FJ,TRAN_MED_INDEX_SAP1(J-1,1), &
2491 ! TRAN_MED_INDEX_SAP1(J,1)
2492  ENDIF
2493 !C---
2494 !C--- print*,j,fjm1,fj
2495 !C---
2496  END IF
2497  END DO
2498 
2499 !C
2500 !C--- Here multiplying O3 and NO2 spectra and other spectrum at medium resolution:
2501 !C
2502  DO i = 1, np_std
2503  tran_std(i,:) = 1.
2504  END DO
2505 
2506  DO i = npshif+1, np_std
2507  tran_std(i,:) = tran_std(i,:)*tran_med(i-npshif,:)
2508  END DO
2509 
2510  IF(isplitp.NE.0) THEN
2511  DO i = 1, np_std
2512  tran_std_sa(i,:) = 1.
2513  tran_std_sap1(i,:) = 1.
2514  tran_std_sb(i,:) = 1.
2515  tran_std_sbp1(i,:) = 1.
2516  END DO
2517  DO i = npshif+1, np_std
2518  tran_std_sa(i,:) = tran_std_sa(i,:) *tran_med_sa(i-npshif,:)
2519  tran_std_sap1(i,:) = tran_std_sap1(i,:)*tran_med_sap1(i-npshif,:)
2520  tran_std_sb(i,:) = tran_std_sb(i,:) *tran_med_sb(i-npshif,:)
2521  tran_std_sbp1(i,:) = tran_std_sbp1(i,:)*tran_med_sbp1(i-npshif,:)
2522  END DO
2523 ! DO I = 1,NP_STD
2524 ! write(91,*) I,' TRAN_STD_SA_SOL=',TRAN_STD_SA(I,1)
2525 ! write(91,*) I,' TRAN_STD_SAP1_SOL=',TRAN_STD_SAP1(I,1)
2526 ! END DO
2527  ENDIF
2528 
2529 
2530 
2531 !C The 2nd stage of smoothing - smooth the medium resolution spectrum (resolution
2532 !C of 0.2 nm and point spacing of 0.1 nm) with about 25,000 points to match
2533 !C the coarser and variable resolution spectrum from imaging spectrometers.
2534 !C
2535 !C Initialize some index parameters:
2536 !C
2537  DO 1466 j =1, nobs
2538 
2539  trntbl(j,:) = 0.0
2540  tran_ia(:) = 0.0
2541  tran_iap1(:) = 0.0
2542 
2543  IF(isplitp.NE.0) THEN
2544  trntbl_s(j,:) = 0.0
2545  tran_ia_sa(:) = 0.0
2546  tran_iap1_sa(:) = 0.0
2547  tran_ia_sap1(:) = 0.0
2548  tran_iap1_sap1(:) = 0.0
2549  tran_ia_sb(:) = 0.0
2550  tran_iap1_sb(:) = 0.0
2551  tran_ia_sbp1(:) = 0.0
2552  tran_iap1_sbp1(:) = 0.0
2553  ENDIF
2554 !C---
2555 !C--- print*,'J= ',j, 'NCVHF =', NCVHF(J), 'NCVTOT=',NCVTOT
2556 
2557 !C--- IF(j.eq.87) then
2558 !C--- print*, ' J = 87 =', J
2559 !C--- do i = 1, NCVTOT
2560 !C--- print*,i, FINSTR(i)
2561 !C--- end do
2562 !C--- end if
2563 
2564 !C
2565 !C--- print*,'J =', J, ' IA =', IA
2566 
2567 !
2568 !C Smoothing...
2569 !C
2570  DO 1491 k = ia(j)-(ncvhf(j)-1), ia(j)+ncvhf(j)-1
2571  tran_ia(:) = tran_ia(:) + tran_std(k,:)* &
2572  finstr(k-ia(j)+ncvhf(j),j)
2573  IF(isplitp.NE.0) THEN
2574  tran_ia_sa(:) = tran_ia_sa(:) + tran_std_sa(k,:)* &
2575  finstr(k-ia(j)+ncvhf(j),j)
2576  tran_ia_sap1(:) = tran_ia_sap1(:) + tran_std_sap1(k,:)* &
2577  finstr(k-ia(j)+ncvhf(j),j)
2578  tran_ia_sb(:) = tran_ia_sb(:) + tran_std_sb(k,:)* &
2579  finstr(k-ia(j)+ncvhf(j),j)
2580  tran_ia_sbp1(:) = tran_ia_sbp1(:) + tran_std_sbp1(k,:)* &
2581  finstr(k-ia(j)+ncvhf(j),j)
2582 ! write(91,*) K,' TRAN_IA=',TRAN_IA(JA_L2),TRAN_STD(K,JA_L2),FINSTR(K-IA(J)+NCVHF(J),J)
2583 ! write(91,*) K,' TRAN_IA_SA_SOL=',TRAN_IA_SA(1),TRAN_STD_SA(K,1),FINSTR(K-IA(J)+NCVHF(J),J)
2584 ! write(91,*) K,' TRAN_IA_SAP1_SOL=',TRAN_IA_SAP1(1),TRAN_STD_SAP1(K,1),FINSTR(K-IA(J)+NCVHF(J),J)
2585  ENDIF
2586 
2587 !C--- IF(J.eq.1) then
2588 !C--- print*,'j =', j, 'K = ',K, ' IA= ',IA,
2589 !C--- & K-IA+NCVHF(J),
2590 !C--- & FINSTR(K-IA+NCVHF(J))
2591 !C--- End IF
2592 
2593 1491 CONTINUE
2594 
2595  ia_p1 = ia(j) + 1
2596  DO 1492 k = ia_p1-(ncvhf(j)-1), ia_p1+ncvhf(j)-1
2597  tran_iap1(:) = tran_iap1(:) + tran_std(k,:)* &
2598  finstr(k-ia_p1+ncvhf(j),j)
2599  IF(isplitp.NE.0) THEN
2600  tran_iap1_sa(:) = tran_iap1_sa(:) + tran_std_sa(k,:)* &
2601  finstr(k-ia_p1+ncvhf(j),j)
2602  tran_iap1_sap1(:) = tran_iap1_sap1(:) + tran_std_sap1(k,:)* &
2603  finstr(k-ia_p1+ncvhf(j),j)
2604  tran_iap1_sb(:) = tran_iap1_sb(:) + tran_std_sb(k,:)* &
2605  finstr(k-ia_p1+ncvhf(j),j)
2606  tran_iap1_sbp1(:) = tran_iap1_sbp1(:) + tran_std_sbp1(k,:)* &
2607  finstr(k-ia_p1+ncvhf(j),j)
2608  ENDIF
2609 1492 CONTINUE
2610 !C
2611 !C Linear interpolation to get TRNCAL from TRAN_IA and TRAN_IAP1:
2612 !C
2613  dlt_ia = wavln_std(ia_p1) - wavln_std(ia(j))
2614  fia = (wavln_std(ia_p1) - wavobs(j)) /dlt_ia
2615 !C FIA_P1 = (WAVOBS(J) - WAVLN_STD(IA))/DLT_IA
2616  fia_p1 = 1. - fia
2617  trntbl(j,:) = fia*tran_ia(:) + fia_p1*tran_iap1(:)
2618  IF(isplitp.NE.0) THEN
2619  trntblsa(:) = fia*tran_ia_sa(:) + fia_p1*tran_iap1_sa(:)
2620  trntblsap1(:) = fia*tran_ia_sap1(:) + fia_p1*tran_iap1_sap1(:)
2621  trntblsb(:) = fia*tran_ia_sb(:) + fia_p1*tran_iap1_sb(:)
2622  trntblsbp1(:) = fia*tran_ia_sbp1(:) + fia_p1*tran_iap1_sbp1(:)
2623  trntbl_s(j,:) = 0.5*(f1a*trntblsa(:) + f2a*trntblsap1(:) + &
2624  f1b*trntblsb(:) + f2b*trntblsbp1(:) )
2625 ! write(91,*) J,' TRNTBL_TOT=',TRNTBL(J,JA_L2),FIA,FIA_P1,TRAN_IA(JA_L2),TRAN_IAP1(JA_L2)
2626 ! write(91,*) J,' TRNTBL_SOL_SA=',TRNTBLSA(1),TRNTBLSAP1(1),F1A,F2A,F1B,F2B,TRAN_IA_SA(1), &
2627 ! TRAN_IAP1_SA(1),TRAN_IA_SAP1(1),TRAN_IAP1_SAP1(1)
2628 ! write(91,*) J,JA_L2,JB_L2,' TRNTBL_SOL=',TRNTBL_S(J,1),TRNTBL(J,1),F1A,F2A,F1B,F2B,TRNTBLSA(1),TRNTBLSAP1(1), &
2629 ! TRNTBLSB(1),TRNTBLSBP1(1)
2630 ! write(91,*) J,JA_L2,JB_L2,' TRNTBL_SEN=',TRNTBL_S(J,2),TRNTBL(J,2),F1A,F2A,F1B,F2B,TRNTBLSA(2),TRNTBLSAP1(2), &
2631 ! TRNTBLSB(2),TRNTBLSBP1(2)
2632  ENDIF
2633  IF (ifullcalc.eq.0) THEN
2634  do k=1,nh2o_max
2635  !! TRAN_KD(J,K) = TRAN_KD(J,K)*DIFF_TRAN(J,K)
2636  diff_tran(j,k) = (trntbl(j,k)-tran_kd(j,k))/tran_kd(j,k) + 1
2637  !!DTT = (TRAN_KD(J,K)-TRNTBL(J,K))/TRNTBL(J,K)
2638  !write(*,*) 'RJH: TRAN2: ',J, K, TRAN_KD(J,K),TRNTBL(J,K),DIFF_TRAN(J,K) !!,100*DTT
2639  end do
2640 
2641  end if
2642 !C---
2643 !C--- print*,'j=',j,'IA =',IA,'FIA =',FIA,'FIA_P1=',FIA_P1,DLT_IA
2644 !C---
2645 !C
2646 1466 CONTINUE
2647 
2648 
2649  DEALLOCATE(tran_std,tran_med)
2650  RETURN
2651  END
2652 
2653 !********************************************************************************
2654 !* *
2655 !* Name: TRAN_SMOOTH_OTHERS *
2656 !* Purpose: This program is to smooth the line-by-line high resolution *
2657 !* spectrum to lower resolution spectrum that matches the resolutions *
2658 !* of imaging spectrometer data. *
2659 !* Parameters: none. *
2660 !* Algorithm: The smoothing is done in two stages. The 1st stage is to smooth *
2661 !* the high resolution spectrum to medium resolution spectrum at a *
2662 !* constant FWHM (0.2 nm) and a constant wavelength interval *
2663 !* (0.1 nm). The 2nd stage smoothing is to smooth the medium *
2664 !* resolution spectrum to resolutions of input imaging spectrometer *
2665 !* data. *
2666 !* Globals used: The global variables used are contained in the file *
2667 !* "COMMONS_INC" *
2668 !* Global output: TRNCAL - total transmittances of all gases that match the *
2669 !* resolutions of imaging spectrometers. *
2670 !* Return Codes: none. *
2671 !* *
2672 !* Added by R. Healy (richard.healy@nasa.gov) 9/29/2015 *
2673 !* *
2674 !* This version smooths the other gases, not H2O *
2675 !********************************************************************************
2676 
2677  SUBROUTINE tran_smooth_others
2678 
2679  include 'COMMONS_INC.f'
2680 
2681  dimension tran_o3_std(no3pt)
2682  COMMON /init_speccal16/ tran_o3_std
2683 
2684  dimension tran_no2_std(no3pt)
2685  COMMON /init_speccal17/ tran_no2_std
2686 
2687  dimension wavobs(nobs_max),fwhm(nobs_max)
2688  COMMON /getinput4/ wavobs,fwhm
2689 
2690  dimension vaptot(nh2o_max), r0p94(nh2o_max), r1p14(nh2o_max), trntbl(nobs_max,nh2o_max), &
2691  tran_kd(nobs_max,nh2o_max), diff_tran(nobs_max,nh2o_max),trntblo(nobs_max)
2692  COMMON /tran_table1/ sh2o,vaptot,r0p94,r1p14,trntbl,tran_kd, diff_tran,trntblo
2693  REAL TRAN_HI_SA(NP_HI,2),TRAN_HI_SAP1(NP_HI,2),TRAN_HI_SB(NP_HI,2),TRAN_HI_SBP1(NP_HI,2), &
2694  trntbl_s(nobs_max,2),trntbl_so(nobs_max,2)
2695  COMMON /tran_tables/tran_hi_sa,tran_hi_sap1,tran_hi_sb,tran_hi_sbp1
2696  COMMON /tran_table_l2gen/trntbl_s,trntbl_so
2697  REAL MU,MU0, SSH2O_S(NH2O_MAX,2)
2698  COMMON /geometry5/mu,mu0,ssh2o_s
2699 
2700  real*4 tran_ia,tran_iap1, tran_std_o(np_std),tran_std_os(np_std,2),am(np_std),tran_ias(2),tran_iap1s(2)
2701 
2702  COMMON /getinput5/ nobs,ifullcalc,hsurf,dlt,dlt2
2703  REAL TRAN_MED_O(NP_MED),TRAN_MED_INDEX_O(NP_MED) !Transmittance of medium resolution data
2704  REAL TRAN_MED_OS(NP_MED,2),TRAN_MED_INDEX_OS(NP_MED,2)
2705  INTEGER FIRST/1/,IA(NOBS_MAX)
2706  SAVE first, ia
2707 
2708 !C First stage of smoothing - smooth line-by-line high resolution spectrum with
2709 !C over 300,000 points (point spacing of 0.05 cm-1) to medium resolution
2710 !C spectrum (resolution of 0.2 nm and point spacing of 0.1 nm) with about
2711 !C 25,000 points.
2712 !C
2713 !C The smoothing of line-by-line spectrum is done in wavenumber domain. For
2714 !C a spectrum with a constant 0.2 nm resolution in wavelength domain, it has
2715 !C variable resolution in wavenumber domain. This effect is properly taken
2716 !C care of in the design of smoothing functions.
2717 !C
2718 !C Because the high resolution spectrum is in wavenumber units (cm-1), while
2719 !C the medium resolution spectrum is in wavelength units, the two kinds of
2720 !C grids do not automatically match. In order to match the grids, arrays
2721 !C of INDEX_MED and TRAN_MED_INDEX are specially designed. The desired
2722 !C medium resolution spectrum, TRAN_MED, at constant 0.1 nm point spacing
2723 !C and 0.2 nm resolution is obtained through linear interpolation of
2724 !C TRAN_MED_INDEX array.
2725 !C
2726  IF (first.eq.1) THEN !RJH
2727  DO 466 j =1, np_med
2728 
2729  ncvtot_wavno = 2 * ncvhf_wavno(j) - 1
2730 
2731  sumins = 0.0
2732 
2733  DO 560 i = ncvhf_wavno(j), ncvtot_wavno
2734  finstr_wavno(i,j) = &
2735  exp( -const1*(float(i-ncvhf_wavno(j))*dwavno &
2736  /fwhm_wavno(j))**2)
2737  sumins = sumins + finstr_wavno(i,j)
2738  560 CONTINUE
2739 
2740  DO 565 i = 1, ncvhf_wavno(j)-1
2741  finstr_wavno(i,j) = finstr_wavno(ncvtot_wavno-i+1,j)
2742  sumins = sumins + finstr_wavno(i,j)
2743  565 CONTINUE
2744 
2745  sumins = sumins * dwavno
2746 
2747  DO 570 i = 1, ncvtot_wavno
2748  finstr_wavno(i,j) = finstr_wavno(i,j)*dwavno/sumins
2749  570 CONTINUE
2750 
2751 
2752  466 CONTINUE
2753 
2754 
2755  tran_med_o(:) = 1.0 ! FWHM=.2 nm, .56-3.1 um.
2756 
2757 
2758 !C Index searching...
2759 !C
2760  DO j=1,nobs
2761  !C Calculate instrumental response functions...
2762 
2763  sumins = 0.0
2764 
2765  ncvtot = 2 * ncvhf(j) - 1
2766 
2767  DO 1560 i = ncvhf(j), ncvtot
2768  finstr(i,j) = &
2769  exp( -const1*(float(i-ncvhf(j))*dwavln &
2770  /fwhm(j))**2)
2771  sumins = sumins + finstr(i,j)
2772 1560 CONTINUE
2773 
2774  DO 1565 i = 1, ncvhf(j)-1
2775  finstr(i,j) = finstr(ncvtot-i+1,j)
2776  sumins = sumins + finstr(i,j)
2777 1565 CONTINUE
2778 
2779  sumins = sumins * dwavln
2780 
2781  DO 1570 i = 1, ncvtot
2782  finstr(i,j) = finstr(i,j)*dwavln/sumins
2783 1570 CONTINUE
2784 
2785 
2786  CALL hunt(wavln_std, np_std, wavobs(j), ia(j))
2787  END DO
2788 
2789  END IF ! IFIRST = 0
2790 
2791  airmass = 1.0/mu0 + 1.0/mu;
2792 
2793 !C*** !!!High resolution transmittances for CO2, N2O, CO, CH4, and O2 should
2794 !C also be calculated for wavelength start = 0.56 micron.
2795 
2796  tran_med_index_o(:) = 0.0
2797  IF(isplitp.NE.0) tran_med_index_os(:,:) = 0.0
2798 
2799  DO j =1, np_med
2800 
2801  ndx1 = index_med(j)-(ncvhf_wavno(j)-1)
2802  ndx2 = index_med(j)+ ncvhf_wavno(j)-1
2803  DO 491 k = ndx1,ndx2
2804  tran_med_index_o(j) = tran_med_index_o(j) + tran_hi_others(k)* &
2805  finstr_wavno(k-index_med(j)+ncvhf_wavno(j),j)
2806 
2807  IF(isplitp.NE.0) THEN
2808  airm = -log(tran_hi_others(k))/airmass
2809  tran_hi_others_sol = exp(-airm/mu0)
2810  tran_hi_others_sen = exp(-airm/mu)
2811 
2812  tran_med_index_os(j,1) = tran_med_index_os(j,1) + tran_hi_others_sol* &
2813  finstr_wavno(k-index_med(j)+ncvhf_wavno(j),j)
2814  tran_med_index_os(j,2) = tran_med_index_os(j,2) + tran_hi_others_sen* &
2815  finstr_wavno(k-index_med(j)+ncvhf_wavno(j),j)
2816 
2817  ENDIF
2818 !C if (FIRST.eq.1) print*,j," tran_med_index:", TRAN_MED_INDEX_O(J)
2819  491 CONTINUE
2820  END DO
2821 
2822 !C
2823 !C Linear interpolation to get TRAN_MED from TRAN_MED_INDEX_O:
2824 !C (Note that WAVLN_MED_INDEX(J) >= WAVLN_MED(J) )
2825 !C
2826  tran_med_o(1) = tran_med_index_o(1)
2827  tran_med_o(np_med) = tran_med_index_o(np_med)
2828  IF(isplitp.NE.0) THEN
2829  tran_med_os(1,:) = tran_med_index_os(1,:)
2830  tran_med_os(np_med,:) = tran_med_index_os(np_med,:)
2831  END IF
2832 
2833  DO j = 2, np_med-1
2834  IF(wavln_med_index(j).LE.wavln_med(j)) THEN
2835  tran_med_o(j) = tran_med_index_o(j)
2836  IF(isplitp.NE.0) tran_med_os(j,:) = tran_med_index_os(j,:)
2837  ELSE
2838  dlt = wavln_med_index(j) - wavln_med_index(j-1)
2839  fjm1 = (wavln_med_index(j) - wavln_med(j)) /dlt
2840  fj = (wavln_med(j) - wavln_med_index(j-1))/dlt
2841  tran_med_o(j) = fjm1*tran_med_index_o(j-1) + fj*tran_med_index_o(j)
2842  IF(isplitp.NE.0) &
2843  tran_med_os(j,:) = fjm1*tran_med_index_os(j-1,:) + fj*tran_med_index_os(j,:)
2844 
2845  END IF
2846  END DO
2847 
2848 !C
2849 !C--- Here multiplying O3 and NO2 spectra and other spectrum at medium resolution:
2850 !C
2851  tran_std_o(:) = 1.
2852  IF(isplitp.NE.0) tran_std_os(:,:) = 1.
2853 
2854  tran_std_o(1:no3pt) = tran_o3_std(1:no3pt) * tran_no2_std(1:no3pt)
2855  IF(isplitp.NE.0) THEN
2856  am(1:no3pt) = -log(tran_std_o(1:no3pt))/airmass
2857  tran_std_os(1:no3pt,1) = exp(-am(1:no3pt)/mu0)
2858  tran_std_os(1:no3pt,2) = exp(-am(1:no3pt)/mu)
2859  END IF
2860 
2861  tran_std_o(npshif+1:np_std) = tran_std_o(npshif+1:np_std)*tran_med_o(1:np_std-npshif)
2862  IF(isplitp.NE.0) THEN
2863  tran_std_os(npshif+1:np_std,:) = tran_std_os(npshif+1:np_std,:)*tran_med_os(1:np_std-npshif,:)
2864 ! do j=NPSHIF+1,NP_STD
2865 ! write(91,*) j, ' TRAN_STD_OS_SOL=',TRAN_STD_OS(j,1),TRAN_MED_OS(j-NPSHIF,1),TRAN_STD_O(j),TRAN_MED_O(J)
2866 ! write(91,*) j, ' TRAN_STD_OS_SEN=',TRAN_STD_OS(j,2),TRAN_MED_OS(j-NPSHIF,2),TRAN_STD_O(j),TRAN_MED_O(J)
2867 ! end do
2868  ENDIF
2869 !C The 2nd stage of smoothing - smooth the medium resolution spectrum (resolution
2870 !C of 0.2 nm and point spacing of 0.1 nm) with about 25,000 points to match
2871 !C the coarser and variable resolution spectrum from imaging spectrometers.
2872 !C
2873 !C Initialize some index parameters:
2874 !C
2875  DO 1466 j =1, nobs
2876 
2877  tran_ia = 0.0
2878  tran_iap1 = 0.0
2879  tran_ias(:) = 0.0
2880  tran_iap1s(:) = 0.0
2881 
2882 !
2883 !C Smoothing...
2884 !C
2885  DO 1491 k = ia(j)-(ncvhf(j)-1), ia(j)+ncvhf(j)-1
2886  tran_ia = tran_ia + tran_std_o(k)* &
2887  finstr(k-ia(j)+ncvhf(j),j)
2888  IF(isplitp.NE.0) &
2889  tran_ias(:) = tran_ias(:) + tran_std_os(k,:)* &
2890  finstr(k-ia(j)+ncvhf(j),j)
2891 
2892 
2893 1491 CONTINUE
2894 
2895  ia_p1 = ia(j) + 1
2896  DO 1492 k = ia_p1-(ncvhf(j)-1), ia_p1+ncvhf(j)-1
2897  tran_iap1 = tran_iap1 + tran_std_o(k)* &
2898  finstr(k-ia_p1+ncvhf(j),j)
2899  IF(isplitp.NE.0) &
2900  tran_iap1s(:) = tran_iap1s(:) + tran_std_os(k,:)* &
2901  finstr(k-ia_p1+ncvhf(j),j)
2902  1492 CONTINUE
2903 !C
2904 !C Linear interpolation to get TRNCAL from TRAN_IA and TRAN_IAP1:
2905 !C
2906  dlt_ia = wavln_std(ia_p1) - wavln_std(ia(j))
2907  fia = (wavln_std(ia_p1) - wavobs(j)) /dlt_ia
2908 !C FIA_P1 = (WAVOBS(J) - WAVLN_STD(IA))/DLT_IA
2909  fia_p1 = 1. - fia
2910  trntblo(j) = fia*tran_ia + fia_p1*tran_iap1
2911  IF(isplitp.NE.0) THEN
2912  trntbl_so(j,:) = fia*tran_ias(:) + fia_p1*tran_iap1s(:)
2913 ! write(91,*) 'TRNTBL_SO:',TRNTBL_SO(J,1),TRNTBL_SO(J,2),TRAN_IAS(1), &
2914 ! TRAN_IAS(2),TRAN_IAP1S(1),TRAN_IAP1S(2)
2915  ENDIF
2916 
2917 !C---
2918 !C--- print*,'j=',j,'IA =',IA,'FIA =',FIA,'FIA_P1=',FIA_P1,DLT_IA
2919 !C---
2920 !C
2921 1466 CONTINUE
2922 
2923 
2924  first = 0
2925 
2926  RETURN
2927  END
2928 
2929 
2930 !********************************************************************************
2931 !* *
2932 !* Name: CHNLRATIO *
2933 !* Purpose: Calculate 3-channel ratios. *
2934 !* Parameters: none *
2935 !* Algorithm: The 0.94-um water vapor absorption channel is ratioed against *
2936 !* the linear combination of two window channels near 0.86 and *
2937 !* 1.03 um to obtain one channel ratio for the 0.94-um band. *
2938 !* Similar calculation is done for the 1.14-um water vapor band. *
2939 !* Globals used: NB1,NB2,NBP94,NB3,NB4,NB1P14 - number of points used in *
2940 !* channel ratios for both the .94- and 1.14-um regions*
2941 !* IST1,IED1,IST2,IED2,ISTP94,IEDP94 - 3-channel ratioing *
2942 !* parameters for the 0.94-um water vapor band *
2943 !* IST3,IED3,IST4,IED4,IST1P14,IED1P14 - 3-channel ratioing *
2944 !* parameters for the 1.14-um water vapor band. *
2945 !* WT1,WT2,WT3,WT4,JA - Relative weights for the four window *
2946 !* channels used in channel-ratioing calculations. JA *
2947 !* is an output parameter from a table searching *
2948 !* routine. *
2949 !* TRNCAL - Atmospheric transmittance spectra. *
2950 !* Global output:R094,R114 - 3-channel ratio values for the 0.94- and 1.14-um *
2951 !* water vapor bands. *
2952 !* Return Codes: none *
2953 !* Special Considerations: none *
2954 !* *
2955 !********************************************************************************
2956 
2957  SUBROUTINE chnlratio
2958  parameter(nobs_max=1024,nh2o_max=60)
2959 
2960 !C Common variables
2961  dimension const1(nh2o_max),const2(nh2o_max),const3(nh2o_max)
2962  dimension const4(nh2o_max),const5(nh2o_max),const6(nh2o_max)
2963 
2964  COMMON /getinput7/ nb1,nb2,nbp94,nb3,nb4,nb1p14
2965  COMMON /init_speccal6/ ist1,ied1,ist2,ied2,istp94,iedp94
2966  COMMON /init_speccal7/ ist3,ied3,ist4,ied4,ist1p14,ied1p14
2967  COMMON /init_speccal8/ wt1,wt2,wt3,wt4,ja
2968  dimension vaptot(nh2o_max), r0p94(nh2o_max), r1p14(nh2o_max),trntbl(nobs_max,nh2o_max), &
2969  tran_kd(nobs_max,nh2o_max), diff_tran(nobs_max,nh2o_max),trntblo(nobs_max)
2970  COMMON /tran_table1/ sh2o,vaptot,r0p94,r1p14,trntbl, tran_kd, diff_tran,trntblo
2971 
2972 !C Calculate average of spectra over window and water vapor absorption regions.
2973  const1(:)=0.0
2974  DO 560 i=ist1,ied1
2975  const1(:)=const1(:)+trntbl(i,:)
2976  560 CONTINUE
2977  const1(:)=const1(:)/float(nb1)
2978 
2979  const2=0.0
2980  DO 570 i=ist2,ied2
2981  const2(:)=const2(:)+trntbl(i,:)
2982  570 CONTINUE
2983  const2(:)=const2(:)/float(nb2)
2984 
2985  const3(:)=0.0
2986  DO 575 i=istp94,iedp94
2987  const3(:)=const3(:)+trntbl(i,:)
2988  575 CONTINUE
2989  const3(:)=const3(:)/float(nbp94)
2990 
2991  r0p94(:)=const3(:)/((wt1*const1(:)) + (wt2*const2(:)))
2992 
2993  const4(:)=0.0
2994  DO 580 i=ist3,ied3
2995  const4(:)=const4(:)+trntbl(i,:)
2996  580 CONTINUE
2997  const4(:)=const4(:)/float(nb3)
2998 
2999  const5(:)=0.0
3000  DO 590 i=ist4,ied4
3001  const5(:)=const5(:)+trntbl(i,:)
3002  590 CONTINUE
3003  const5(:)=const5(:)/float(nb4)
3004 
3005  const6(:)=0.0
3006  DO 595 i=ist1p14,ied1p14
3007  const6(:)=const6(:)+trntbl(i,:)
3008  595 CONTINUE
3009  const6(:)=const6(:)/float(nb1p14)
3010 
3011  r1p14(:)=const6(:)/((wt3*const4(:)) + (wt4*const5(:)))
3012 
3013  RETURN
3014  END
3015 
3016 
3017 !********************************************************************************
3018 !* *
3019 !* Name: LOCATE *
3020 !* Purpose: given an array XX of length N, and given a value X, returns a value*
3021 !* J such that X is between XX(J) and XX(J+1). XX must be monotonic, *
3022 !* Parameters: XX - monotonic array of values *
3023 !* N - number of elements in XX *
3024 !* X - value that will be matched to the XX array *
3025 !* J - index into the XX array where XX(J) <= X <= XX(J+1) *
3026 !* Algorithm: bisectional table searching, copied from Numerical Recipes. *
3027 !* Globals used: none *
3028 !* Global output: none *
3029 !* Return Codes: J=0 or J=N is returned to indicate that X is out of range *
3030 !* Special Considerations: none *
3031 !* *
3032 !********************************************************************************
3033  SUBROUTINE locate(xx,n,x,j)
3034  INTEGER j,n
3035  REAL x,xx(n)
3036  INTEGER jl,jm,ju
3037  jl=0
3038  ju=n+1
3039 10 if(ju-jl.gt.1)then
3040  jm=(ju+jl)/2
3041  if((xx(n).ge.xx(1)).eqv.(x.ge.xx(jm)))then
3042  jl=jm
3043  else
3044  ju=jm
3045  endif
3046  goto 10
3047  endif
3048  if(x.eq.xx(1))then
3049  j=1
3050  else if(x.eq.xx(n))then
3051  j=n-1
3052  else
3053  j=jl
3054  endif
3055  return
3056  END
3057 
3058 !********************************************************************************
3059 !* *
3060 !* Name: CUBSPLN *
3061 !* Purpose: an interface for performing cubic spline interpolations. *
3062 !* Parameters: N - number of elements in XORGN, YORGN *
3063 !* XORGN - original x values *
3064 !* YORGN - original y values *
3065 !* XINT - interpolated x values *
3066 !* YINT - interpolated y values *
3067 !* Algorithm: Straight forward calculations *
3068 !* Globals used: NOBS - number of spectral points. *
3069 !* Global output: none *
3070 !* Return Codes: none *
3071 !* Special Considerations: none *
3072 !* *
3073 !********************************************************************************
3074 
3075  SUBROUTINE cubspln(N,XORGN,YORGN,XINT,YINT)
3076  parameter(nobs_max=1024)
3077 
3078  dimension xorgn(1050),yorgn(1050),y2(1050)
3079  dimension xint(nobs_max),yint(nobs_max)
3080  INTEGER N !number of elements in XORGN,YORGN
3081 
3082  COMMON /getinput5/ nobs,ifullcalc,hsurf,dlt,dlt2
3083 !C
3084 !C YP1 and YP2 are two parameters specifying the values of 2nd derivatives at
3085 !C XORGN(1) and XORGN(N) and were used in cubic spline interpolations. The
3086 !C setting of both YP1 and YP2 to 2.0E30 is equivalent to set the 2nd
3087 !C derivatives at the two boundaries as zero, according to Numeric Recipes.
3088  yp1=2.0e30
3089  ypn=2.0e30
3090 
3091  CALL spline(xorgn,yorgn,n,yp1,ypn,y2)
3092 
3093  DO 320 i=1,nobs
3094  x=xint(i)
3095  CALL splint(xorgn,yorgn,y2,n,x,y)
3096  IF(y.LT.0.0) y=0.0
3097  yint(i)=y
3098 
3099  320 CONTINUE
3100 
3101  RETURN
3102  END
3103 !
3104 !********************************************************************************
3105 !* *
3106 !* Name: SPLINE *
3107 !* Purpose: program for cubic spline interpolation --- copyed from Numerical *
3108 !* Recipes, p.88-89 *
3109 !* Parameters: X - x-values *
3110 !* Y - y-values *
3111 !* N - length of X *
3112 !* YP1 - 2nd derivative at X(1) *
3113 !* YPN - 2nd derivative at X(N) *
3114 !* Y2 - 2nd derivatives at all X positions *
3115 !* Algorithm: Given arrays X and Y of length N containing a tabulated function,*
3116 !* i.e.,Yj=f(Xj), with X1 < X2...<XN, and given values YP1 and YPN for *
3117 !* the first derivative of the interpolating function at points 1 *
3118 !* and N, respectively, this routine returns an array Y2 of length N *
3119 !* which contains the second derivatives of the interpolating function *
3120 !* at the tabulated points Xj. If YP1 and/or YPN are equal to 1.0E30 or *
3121 !* larger, the routine is signalled to set the corresponding boundary *
3122 !* condition for a natural spline, with zero second derivative on *
3123 !* that boundary. *
3124 !* Globals used: none *
3125 !* Global output: none *
3126 !* Return Codes: none *
3127 !* Special Considerations: none *
3128 !* *
3129 !********************************************************************************
3130 
3131  subroutine spline(x,y,n,yp1,ypn,y2)
3132  parameter(nmax=1050)
3133  integer n,i,k
3134  real x(n),y(n),y2(n),u(nmax)
3135  real yp1,ypn,sig,p,qn,un
3136  if (yp1.gt..99e30) then
3137  y2(1)=0.
3138  u(1)=0.
3139  else
3140  y2(1)=-0.5
3141  u(1)=(3./(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)
3142  endif
3143  do 11 i=2,n-1
3144  sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))
3145  p=sig*y2(i-1)+2.
3146  y2(i)=(sig-1.)/p
3147  u(i)=(6.*((y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1)) &
3148  /(x(i)-x(i-1)))/(x(i+1)-x(i-1))-sig*u(i-1))/p
3149 11 continue
3150  if (ypn.gt..99e30) then
3151  qn=0.
3152  un=0.
3153  else
3154  qn=0.5
3155  un=(3./(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))
3156  endif
3157  y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.)
3158  do 12 k=n-1,1,-1
3159  y2(k)=y2(k)*y2(k+1)+u(k)
3160 12 continue
3161  return
3162  end
3163 
3164 !********************************************************************************
3165 !* *
3166 !* Name: SPLINT *
3167 !* Purpose: calculate a cubic-spline interpolated Y value, -- copied from *
3168 !* Numerical Recipes. *
3169 !* Parameters: XA - original X array *
3170 !* YA - original Y array *
3171 !* Y2A - 2nd derivative array from SUBROUTINE SPLINE *
3172 !* N - number of X elements *
3173 !* X - an X position at which interpolation should be made *
3174 !* Y - interpolated y value at position X *
3175 !* Algorithm: Given the arrays XA and YA of length N, which tabulate a function*
3176 !* (with the XAj's in order), and given the array Y2A, which is the output *
3177 !* from SPLINE above, and given a value of X, this routine returns a *
3178 !* cubic-spline interpolated value Y. *
3179 !* Globals used: none *
3180 !* Global output: none *
3181 !* Return Codes: none *
3182 !* Special Considerations: SPLINE is called only once to process an entire *
3183 !* tabulated function in arrays Xi and Yi. Once this has been done, values *
3184 !* of the interpolated function for any value of X are obtained by calls *
3185 !* (as many as desired) to a separate routine SPLINT (for cubic spline *
3186 !* interpolation") *
3187 !* *
3188 !********************************************************************************
3189 
3190  subroutine splint(xa,ya,y2a,n,x,y)
3191  integer n,klo,khi,k
3192  real xa(n),ya(n),y2a(n)
3193  real x,y,h,a,b
3194  klo=1
3195  khi=n
3196 1 if (khi-klo.gt.1) then
3197  k=(khi+klo)/2
3198  if(xa(k).gt.x)then
3199  khi=k
3200  else
3201  klo=k
3202  endif
3203  goto 1
3204  endif
3205  h=xa(khi)-xa(klo)
3206  if (h.eq.0.) stop 'bad xa input.'
3207  a=(xa(khi)-x)/h
3208  b=(x-xa(klo))/h
3209  y=a*ya(klo)+b*ya(khi)+ &
3210  ((a**3-a)*y2a(klo)+(b**3-b)*y2a(khi))*(h**2)/6.
3211  return
3212  end
3213 
3214 !********************************************************************************
3215 !* *
3216 !* Name: HUNT *
3217 !* Purpose: finds the element in array XX that is closest to value X. Array AA*
3218 !* must be monotonic, either increasing or decreasing. *
3219 !* Parameters: XX - array to search *
3220 !* N - number of elements in the array *
3221 !* X - element to search for closest match *
3222 !* JLO - index of the closest matching element *
3223 !* Algorithm: this subroutine was copied from Numerical Recipes *
3224 !* Globals used: none *
3225 !* Global output: none *
3226 !* Return Codes: none *
3227 !* Special Considerations: none *
3228 !* *
3229 !********************************************************************************
3230 
3231  SUBROUTINE hunt(xx,n,x,jlo)
3232  INTEGER jlo,n
3233  REAL x,xx(n)
3234  INTEGER inc,jhi,jm
3235  LOGICAL ascnd
3236  ascnd=xx(n).ge.xx(1)
3237  if(jlo.le.0.or.jlo.gt.n)then
3238  jlo=0
3239  jhi=n+1
3240  goto 3
3241  endif
3242  inc=1
3243  if(x.ge.xx(jlo).eqv.ascnd)then
3244 1 jhi=jlo+inc
3245  if(jhi.gt.n)then
3246  jhi=n+1
3247  else if(x.ge.xx(jhi).eqv.ascnd)then
3248  jlo=jhi
3249  inc=inc+inc
3250  goto 1
3251  endif
3252  else
3253  jhi=jlo
3254 2 jlo=jhi-inc
3255  if(jlo.lt.1)then
3256  jlo=0
3257  else if(x.lt.xx(jlo).eqv.ascnd)then
3258  jhi=jlo
3259  inc=inc+inc
3260  goto 2
3261  endif
3262  endif
3263 3 if(jhi-jlo.eq.1)then
3264  if(x.eq.xx(n))jlo=n-1
3265  if(x.eq.xx(1))jlo=1
3266  return
3267  endif
3268  jm=(jhi+jlo)/2
3269  if(x.ge.xx(jm).eqv.ascnd)then
3270  jlo=jm
3271  else
3272  jhi=jm
3273  endif
3274  goto 3
3275  END
3276 
3277 
3278 !********************************************************************************
3279 !* *
3280 !* Name: FINDMATCH *
3281 !* Purpose: finds the closest match for ELEM in LIST *
3282 !* Parameters: LIST - array of values to match ELEM to. Elements is array *
3283 !* should increase in value. *
3284 !* Algorithm: linearly compare ELEM to each element. When ELEM is smaller *
3285 !* than the LIST(I), then it is assumed to be closest to LIST(I-1) *
3286 !* or LIST(I). The one that has the smallest absolute difference *
3287 !* to ELEM is returned as the closest match. *
3288 !* Globals used: none *
3289 !* Global output: none *
3290 !* Return Codes: the closest matching element index *
3291 !* Special Considerations: none *
3292 !* *
3293 !********************************************************************************
3294 
3295  INTEGER FUNCTION findmatch(LIST,NOBS,ELEM)
3296  parameter(nobs_max=1024)
3297  dimension list(nobs_max)
3298  INTEGER NOBS
3299  REAL ELEM,LIST
3300 
3301  DO 460 i=1,nobs
3302  IF(list(i).GT.elem) GOTO 470
3303  460 CONTINUE
3304  470 CONTINUE
3305  diff1=abs(list(i-1)-elem)
3306  diff2=abs(list(i)-elem)
3307  IF (diff1.LT.diff2) THEN
3308  findmatch=i-1
3309  ELSE
3310  findmatch=i
3311  ENDIF
3312  RETURN
3313  END
3314 !C--------1---------2---------3---------4---------5---------6---------7--
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 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)
#define real
Definition: DbAlgOcean.cpp:26
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
float linterp(float xin[], float yin[], int32_t nin, float xout)
Definition: lspline.c:59
#define re
Definition: l1_czcs_hdf.c:701
function findmatch(LIST, NOBS, ELEM)
subroutine chnlratio
string & trim(string &s, const string &delimiters)
Definition: EnvsatUtil.cpp:29
subroutine tran_smooth
subroutine locate(xx, n, x, j)
Definition: names.f90:1
subroutine geometry
subroutine splint(xa, ya, y2a, n, x, y)
#define abs(a)
Definition: misc.h:90
void tran_smooth_others()