OB.DAAC Logo
NASA Logo
Ocean Color Science Software

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