1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
program convert_aura
use types_mod, only : r8 use time_manager_mod, only : time_type, set_calendar_type, GREGORIAN, set_time,& increment_time, get_time, set_date, operator(-), & print_date, operator(+) use utilities_mod, only : initialize_utilities, find_namelist_in_file, & check_namelist_read, nmlfileunit, do_nml_file, & get_next_filename, error_handler, E_ERR, E_MSG, & find_textfile_dims, finalize_utilities, & timestamp,do_nml_term use netcdf_utilities_mod, only : nc_check use location_mod, only : VERTISPRESSURE, set_location use obs_sequence_mod, only : obs_sequence_type, obs_type, read_obs_seq, & static_init_obs_sequence, init_obs, destroy_obs, & write_obs_seq, init_obs_sequence, get_num_obs, & insert_obs_in_seq, destroy_obs_sequence, & set_copy_meta_data, set_qc_meta_data, set_qc, & set_obs_values, set_obs_def, insert_obs_in_seq use obs_def_mod, only : obs_def_type, set_obs_def_time, set_obs_def_type_of_obs, & set_obs_def_error_variance, set_obs_def_location, & set_obs_def_key use obs_utilities_mod, only : create_3d_obs,add_obs_to_seq use obs_kind_mod, only : AURAMLS_TEMPERATURE
use netcdf
implicit none
character(len=256), parameter :: source = & "$URL$" character(len=32 ), parameter :: revision = "$Revision$" character(len=128), parameter :: revdate = "$Date$"
integer, parameter :: num_copies = 1, & num_qc = 1
character (len=130) :: msgstring, next_infile character (len=80) :: name
integer :: iyear,iday,imonth,idoy,ihr,imin,isec,nalt,nevent,ialt,ievent, & nfiles,ncid,varid,filenum,io,iunit,obs_num,num_new_obs,k,osec,oday logical :: file_exist, first_obs, did_obs, from_list = .false.
real(r8) :: qc,oerr,pres_out
real(r8), allocatable :: lat(:), lon(:), pres(:),temp(:,:),qual(:),conv(:),time(:), DAYOFYEAR(:), YEAR(:) real(r8), allocatable :: localsolartime(:)
type(obs_def_type) :: obs_def type(obs_sequence_type) :: obs_seq type(obs_type) :: obs, prev_obs type(time_type) :: time_obs, time_anal, prev_time
character(len=128) :: aura_netcdf_file = 'aura_input.nc' character(len=128) :: aura_netcdf_filelist = 'aura_input_list' character(len=128) :: aura_outfile = 'obs_seq.aura' integer :: aura_yr=2011,aura_doy = 1
namelist /convert_aura_nml/ aura_netcdf_file, aura_netcdf_filelist, & aura_outfile,aura_yr,aura_doy
obs_num = 1 qc = 1.0_r8 first_obs = .true. call set_calendar_type(GREGORIAN)
call initialize_utilities()
call find_namelist_in_file("input.nml", "convert_aura_nml", iunit) read(iunit, nml = convert_aura_nml, iostat = io) call check_namelist_read(iunit, io, "convert_aura_nml")
if (do_nml_file()) write(nmlfileunit, nml=convert_aura_nml) if (do_nml_term()) write( * , nml=convert_aura_nml)
if (aura_netcdf_file /= '' .and. aura_netcdf_filelist /= '') then call error_handler(E_ERR, 'convert_aura_cdf', & 'One of aura_netcdf_file or filelist must be NULL', & source, revision, revdate) endif if (aura_netcdf_filelist /= '') from_list = .true.
if (from_list) then num_new_obs = (400 * 40000) * nfiles else num_new_obs = (400 * 40000 ) endif
print *, 'OUTPUTING FOR YR=',aura_yr,'DOY=',aura_doy
call static_init_obs_sequence() call init_obs(obs, num_copies, num_qc) call init_obs(prev_obs, num_copies, num_qc) inquire(file=aura_outfile, exist=file_exist) if ( file_exist ) then
print *, "found existing obs_seq file, overwriting ", trim(aura_outfile) print *, "max entries = ", num_new_obs call init_obs_sequence(obs_seq, num_copies, num_qc, num_new_obs)
do k = 1, num_copies call set_copy_meta_data(obs_seq, k, 'observation') end do do k = 1, num_qc call set_qc_meta_data(obs_seq, k, 'Data QC') end do
else
print *, "no existing obs_seq file, creating ", trim(aura_outfile) print *, "max entries = ", num_new_obs call init_obs_sequence(obs_seq, num_copies, num_qc, num_new_obs)
do k = 1, num_copies call set_copy_meta_data(obs_seq, k, 'observation') end do do k = 1, num_qc call set_qc_meta_data(obs_seq, k, 'Data QC') end do
end if
did_obs = .false.
filenum = 1
fileloop: do
if (from_list) then next_infile = get_next_filename(aura_netcdf_filelist, filenum) else next_infile = aura_netcdf_file if (filenum > 1) next_infile = '' endif if (next_infile == '') exit fileloop
call nc_check( nf90_open(next_infile, nf90_nowrite, ncid), 'file open', next_infile)
call nc_check( nf90_inq_dimid(ncid,"levels",varid), 'inq dimid altitude') call nc_check( nf90_inquire_dimension(ncid,varid,name,nalt), 'inq dim altitude') call nc_check( nf90_inq_dimid(ncid,"times",varid), 'inq dimid event') call nc_check( nf90_inquire_dimension(ncid,varid,name,nevent), 'inq dim event') print *, 'nalt=',nalt allocate( time(nevent) ) allocate( lat(nevent) ) allocate( lon(nevent) ) allocate( pres(nalt) ) allocate( temp(nalt,nevent) ) allocate( qual(nevent) ) allocate( conv(nevent) ) allocate( localsolartime(nevent) ) allocate( DAYOFYEAR(nevent) ) allocate( YEAR(nevent) )
call nc_check( nf90_inq_varid(ncid, "Latitude", varid) ,'inq varid Lat') call nc_check( nf90_get_var(ncid, varid, lat) ,'get var Lat')
call nc_check( nf90_inq_varid(ncid, "Longitude", varid) ,'inq varid Lon') call nc_check( nf90_get_var(ncid, varid, lon) ,'get var Lon')
call nc_check( nf90_inq_varid(ncid, "Pressure", varid) ,'inq varid pressure') call nc_check( nf90_get_var(ncid, varid, pres) ,'get_var pressure')
call nc_check( nf90_inq_varid(ncid, "Temperature", varid) ,'inq varid ktemp') call nc_check( nf90_get_var(ncid, varid, temp) ,'get_var ktemp') call nc_check( nf90_inq_varid(ncid, "Quality", varid) ,'inq varid quality') call nc_check( nf90_get_var(ncid, varid, qual) ,'get_var quality') call nc_check( nf90_inq_varid(ncid, "Convergence", varid) ,'inq varid conv') call nc_check( nf90_get_var(ncid, varid, conv) ,'get_var conv') call nc_check( nf90_inq_varid(ncid, "LocalSolarTime", varid) ,'inq varid lst') call nc_check( nf90_get_var(ncid, varid, localsolartime) ,'get_var lst')
call nc_check( nf90_inq_varid(ncid, "Time", varid) ,'inq varid time') call nc_check( nf90_get_var(ncid, varid, time) ,'get_var time')
call nc_check( nf90_inq_varid(ncid, "DAYOFYEAR", varid) ,'inq varid DAYOFYEAR') call nc_check( nf90_get_var(ncid, varid, DAYOFYEAR) ,'get_var DAYOFYEAR')
call nc_check( nf90_inq_varid(ncid, "YEAR", varid) ,'inq varid YEAR') call nc_check( nf90_get_var(ncid, varid, YEAR) ,'get_var YEAR')
call nc_check( nf90_close(ncid), 'close file')
do ievent=1,nevent
do ialt=1,nalt
isec = int( (localsolartime(ievent)-(lon(ievent)/15.))/24.*86400. ) if (isec.le.0) isec = isec + 86400 if (isec.ge.86400) isec = isec - 86400
iyear = YEAR(ievent) idoy = DAYOFYEAR(ievent)
call convert_day(iyear,idoy,imonth,iday)
if (temp(ialt,ievent).ne.-999. .and. & qual(ievent).ge.0.65 .and. & conv(ievent).le.1.2 .and. & pres(ialt).ge.0.001 .and. pres(ialt).le.260 .and. & isec .lt.86400 ) then
ihr = int( isec / 3600 ) imin = int( (isec-ihr*3600) / 60 ) isec = int( (isec-ihr*3600)-imin*60 ) time_obs = set_date(iyear,imonth,iday,ihr,imin,isec) call get_time(time_obs,osec,oday)
call saber_error(pres(ialt),oerr)
pres_out = pres(ialt)*100.
if (lon(ievent).le.0) lon(ievent) = lon(ievent)+360.
call create_3d_obs(lat(ievent),lon(ievent),pres_out, & VERTISPRESSURE,temp(ialt,ievent), & AURAMLS_TEMPERATURE,oerr,oday,osec,qc,obs) call add_obs_to_seq(obs_seq,obs,time_obs,prev_obs,prev_time,first_obs)
if(.not. did_obs) did_obs = .true. else
end if end do end do
deallocate( lat,lon,pres,qual,conv,time,temp) filenum = filenum + 1
end do fileloop
if (did_obs) then
if (get_num_obs(obs_seq) > 0) & call write_obs_seq(obs_seq, aura_outfile)
call destroy_obs(obs)
if (get_num_obs(obs_seq) > 0) call destroy_obs_sequence(obs_seq) endif
contains
subroutine convert_day(iyear,idoy,imonth,iday)
integer, intent(in) :: iyear integer, intent(in) :: idoy integer, intent(out) :: imonth integer, intent(out) :: iday
integer :: t
t = 0 if(modulo(iyear, 4) == 0) t = 1
if(modulo(iyear, 400) /= 0 .and. modulo(iyear, 100) == 0) t = 0
iday = idoy if(idoy > 59+t) iday = iday + 2 - t imonth = ((iday+91)*100)/3055 iday = (iday+91) - (imonth*3055)/100 imonth = imonth - 2
if(imonth >= 1 .and. imonth <= 12) return write(unit=*,fmt="(a,i11,a)") & "$$CALEND: DAY OF THE YEAR INPUT =",idoy," IS OUT OF RANGE." stop
end subroutine
subroutine saber_error(pres,err)
real(r8), intent(in) :: pres real(r8), intent(out) :: err
err = 1.6718_r8 - 0.4281_r8*log(pres) + 0.0977_r8*log(pres)**2
end subroutine
end program
|