OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
deepblue_initialize.f90
Go to the documentation of this file.
1 !-----------------------------------------------------------------------
2 ! deepblue_initialize()
3 !
4 ! !DESCRIPTION:
5 !
6 ! !INPUT PARAMETERS: none
7 !
8 !-----------------------------------------------------------------------
9 subroutine deepblue_initialize ( config_file, nc4_file, lines, pixels, lat, lon, &
10  year, month, day )
11 
12  use landcover
13 
14  use calendars, only: &
15  gdatetime, &
18 
19  use deepblue_config, only: &
20  viirs_config_type, &
22 
23  use modis_surface, only: &
26  load_brdf, &
27  set_limits, &
28  set_limits6, &
29  load_hdfler, &
30  get_ler412, &
31  get_ler470, &
32  get_ler650, &
37 
38  use viirs_aerosol_luts, only: &
40 
41  use viirs_ler_luts
42 
43  implicit none
44  include 'db.inc'
45  include 'newaottbl90.inc'
46  include 'sfc21tbl90.inc'
47 
48  character(len=255) :: config_file, nc4_file
49  INTEGER, PARAMETER :: VLINES=16*203, vpixels=3200
50  real, dimension(VPIXELS,VLINES):: lat, lon
51 
52  integer, parameter :: R_DBL = kind(1.0d0)
53  type (viirs_config_type) :: config
54  type (gdatetime) :: gdt1
55 
56  real, dimension(:,:), allocatable :: minmax, minmax_ler
57  integer, dimension(:,:), allocatable :: lcld_mask, tmp_mask!,ocld_mask
58  integer, dimension(:,:), allocatable :: lskip_mask
59  integer, dimension(:,:), allocatable :: oskip_mask
60  integer, dimension(:,:), allocatable :: smoke_mask
61  integer, dimension(:,:), allocatable :: smoke_ae_mask
62  integer, dimension(:,:), allocatable :: pyrocb_mask
63  integer, dimension(:,:), allocatable :: high_alt_smoke_mask
64  integer, dimension(:,:), allocatable :: snow_mask, snow_mask2
65  real, dimension(:,:), allocatable :: sr650
66  real, dimension(:,:), allocatable :: sfcstd
67  integer, dimension(:,:), allocatable :: gzflg
68  real, dimension(:,:), allocatable :: wv
69  real, dimension(:,:), allocatable :: oz
70  real, dimension(:,:), allocatable :: windsp
71  real, dimension(:,:), allocatable :: winddir
72  integer, dimension(:,:), allocatable :: lc ! land cover
73  integer, dimension(:,:), allocatable :: bathy ! bathymetry
74  real, dimension(:,:), allocatable :: chl ! log-10 Chl climatology
75 
76  integer, dimension(:,:), allocatable :: n_total_pixels
77  integer :: cell_resolution
78  integer, dimension(2) :: cell_dims
79 
80  real :: ndsi
81  real :: ndvi_lower, ndvi_upper
82  real :: dd
83  integer :: i,j
84  integer :: i1, i2, j1, j2
85  integer :: status
86  integer :: lines, pixels
87  integer :: year, month, day, doy
88  integer :: season
89  integer, dimension(2) :: dims2
90  real, dimension(:,:), allocatable :: to_iof
91  real, parameter :: d2r = 3.14159/180.0 ! convert degrees to radians
92  character(len=255) :: val_fname
93  character(len=255) :: env, out_nc4, dataroot, varroot
94  integer :: nt, nr
95 
96  common /xday/ doy
97 
98  status = -1
99 
100  config = load_viirs_config(config_file, status)
101  if (status /= 0) then
102  print *, "ERROR: Failed to read in VIIRS configuration file: ", status
103  stop
104  end if
105 
106  out_nc4 = trim(config%lut_nc4)
107  if (out_nc4 == "") then
108  out_nc4 = nc4_file
109  endif
110 
111  call get_environment_variable ("OCDATAROOT", dataroot)
112  env = trim('$OCDATAROOT')
113  nt = len_trim(env)
114  nr = len_trim(dataroot)
115  do
116  i = index(out_nc4, env(:nt)) ; IF (i == 0) EXIT
117  out_nc4 = out_nc4(:i-1) // dataroot(:nr) // out_nc4(i+nt:)
118  end do
119 
120  call get_environment_variable ("OCVARROOT", varroot)
121  env = trim('$OCVARROOT')
122  nt = len_trim(env)
123  nr = len_trim(varroot)
124  do
125  i = index(out_nc4, env(:nt)) ; IF (i == 0) EXIT
126  out_nc4 = out_nc4(:i-1) // varroot(:nr) // out_nc4(i+nt:)
127  end do
128 
129  status = load_viirs_aerosol_luts(out_nc4)
130  if (status /= 0) then
131  print *, "ERROR: Failed to load VIIRS aerosol LUTS: ", status
132  stop
133  end if
134 ! print *, 'done.'
135 
136  ! -- LER luts
137  call load_viirs_ler_luts(out_nc4, status)
138  if (status /= 0) then
139  print *, "ERROR: Failed to load VIIRS LER LUTS: ", status
140  stop
141  end if
142 
143  ! -- land cover
144  status = load_landcover(out_nc4)
145  if (status /= 0) then
146  print *, "ERROR: Unable to load land cover input file: ", status
147  stop
148  end if
149 
150  ! -- geo zones
151  gdt1 = gdatetime(year, month, day, 0, 0, 0, 0, 0)
152  doy = doy_from_gregorian(gdt1)
153 
154  season = season_from_doy(2005,doy)
155  print *, "season: ", season
156  status = load_terrainflg_tables(out_nc4,season)
157  if (status /= 0) then
158  print *, "ERROR: Unable to load geozone table: ", status
159  stop
160  end if
161 
162  ! -- seasonal desert data
163  status = load_seasonal_desert(out_nc4)
164  if (status /= 0) then
165  print *, "ERROR: Unable to load seasonal deserts file: ", status
166  end if
167 
168  ! -- 670nm BRDF data
169  status = load_brdf(out_nc4)
170  if (status /= 0) then
171  print *, "ERROR: Unable to load BRDF base input file: ", status
172  stop
173  end if
174 
175  ! -- surface database and BRDF coefficients
176  dims2 = (/pixels, lines/)
177  status = set_limits(dims2, lat, lon)
178  if (status /= 0) then
179  print *, "ERROR: Failure to set limits on surface coefficients table: ", status
180  stop
181  end if
182 
183  status = load_hdfler(out_nc4, season)
184  if (status /= 0) then
185  print *, "ERROR: Unable to load surface BRDF coefficients: ", status
186  stop
187  end if
188 
189  ! -- swir vs. vis surface coeffs
190  dims2 = (/pixels, lines/)
191  status = set_limits6(dims2, lat, lon)
192  if (status /= 0) then
193  print *, "ERROR: Failure to set limits on 2.2 um surface coefficients table: ", status
194  stop
195  end if
196 
197  status = load_swir_coeffs(out_nc4, season)
198  if (status /= 0) then
199  print *, "ERROR: Unable to load swir vs. vis surface coeffs file: ", status
200  end if
201 
202  ! -- vegetated retrieval landcover
203  call get_lut_igbp_land_cover(out_nc4, status)
204  if (status /= 0) then
205  print *, "ERROR: Failed to read in landcover input for vegetated retrieval: ", status
206  stop
207  end if
208 
209  call get_lut_211sfc(out_nc4, status)
210  if (status /= 0) then
211  print *, "ERROR: Failed to read in landcover input for vegetated 2.1um sfc table: ", status
212  stop
213  end if
214 
215  allocate(wv(pixels,lines), oz(pixels,lines), windsp(pixels,lines), &
216  & winddir(pixels,lines), lc(pixels,lines), stat=status)
217  if (status /= 0) then
218  print *, "ERROR: Failed to allocate water vapor, ozone arrays, and wind speed arrays: ", status
219  stop
220  end if
221 
222  return
223 end
224 
225 !-----------------------------------------------------------------------------------------
226 ! -- deepblue_cleanup
227 !-----------------------------------------------------------------------------------------
228 subroutine deepblue_cleanup()
229 
230  use landcover
231 
232  use modis_surface, only: &
234 
235  use viirs_aerosol_luts, only: &
237 
238  integer :: status
239 
240  call unload_landcover(status)
241  if (status /= 0) then
242  print *, "ERROR: Unable to unload landcover data. Continuing: ", status
243  end if
244 
245  call unload_brdf(status)
246  if (status /= 0) then
247  print *, "ERROR: Unable to unload BRDF input file. Continuing: ", status
248  end if
249 
250  call unload_viirs_aerosol_luts(status)
251  if (status /= 0) then
252  print *, "ERROR: Unable to unload VIIRS aerosol LUTS. Continuing: ", status
253  end if
254 
255  return
256 end
257 
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
type(viirs_config_type) function, public load_viirs_config(config_file, status)
subroutine deepblue_initialize(config_file, nc4_file, lines, pixels, lat, lon, year, month, day)
subroutine get_lut_211sfc(lut_file, status)
subroutine deepblue_cleanup()
real function, public get_ler470(latidx, lonidx, NDVI, scatAngle, relaz)
integer function, public season_from_doy(yr, doy)
Definition: calendars.f95:539
integer function, public load_brdf(brdffile)
integer function, public latlon_to_index_ler(lat, lon, ilat, ilon)
integer function, public set_limits6(locedge, lat, long)
integer function, public get_geographic_zone(lat, lon, status)
integer function, public load_landcover(lc_file)
integer function, public doy_from_gregorian(gdt1)
Definition: calendars.f95:483
integer function, public set_limits(locedge, lat, long)
subroutine, public unload_viirs_aerosol_luts(status)
string & trim(string &s, const string &delimiters)
Definition: EnvsatUtil.cpp:29
subroutine, public load_viirs_ler_luts(lut_ler_file, status)
subroutine, public unload_landcover(status)
real function, public get_ler412(latidx, lonidx, NDVI, scatAngle, relaz)
integer function, public load_seasonal_desert(file)
subroutine, public unload_brdf(status)
real function, public get_ler650(latidx, lonidx, NDVI, scatAngle, relaz)
subroutine get_lut_igbp_land_cover(lut_file, status)
integer function, public get_sfc_elev_std(lat, lon, status)
integer function, public load_viirs_aerosol_luts(lut_file)
integer function, public load_swir_coeffs(file, season)
integer function, public load_hdfler(lut_file, season)
integer function, public load_terrainflg_tables(tflg_file, season)