subroutine uEMEP_save_emission_netcdf use uEMEP_definitions implicit none character(256) temp_date_str,temp_compound_str,variable_type,unit_str,temp_name,var_name_temp,title_str logical create_file real scale_factor,valid_min integer i_file,i_pollutant,i_source real, allocatable :: temp_subgrid(:,:,:) logical :: exists integer temp_time_dim integer i,j temp_time_dim=save_emissions_end_index-save_emissions_start_index+1 write(unit_logfile,'(A,3i6)') 'Time dimensions to be saved: ',save_emissions_start_index,save_emissions_end_index,temp_time_dim if (.not.allocated(temp_subgrid)) allocate(temp_subgrid(emission_subgrid_dim(x_dim_index,allsource_index),emission_subgrid_dim(y_dim_index,allsource_index),temp_time_dim)) valid_min=0. unit_str="ug/m3" !variable_type='byte' !variable_type='double' variable_type='float' scale_factor=1. !Save the data !i_file=subgrid_total_file_index(allsource_index) !temp_name=trim(pathname_grid(i_file))//trim(filename_grid(i_file))//'_'//trim(file_tag)//'.nc' if (len(emission_date_str).gt.0) then temp_date_str='_'//trim(emission_date_str) else temp_date_str='' endif !Do not use the actual emission start date for the file name but use the format specified by filename_date_output_grid if (len(filename_date_output_grid).gt.0) then temp_date_str='_'//trim(filename_date_output_grid) else temp_date_str='' endif !Do not write 'all' in file name if all compounds are selected if (pollutant_index.eq.all_nc_index) then temp_compound_str='' else temp_compound_str='_'//trim(var_name_nc(conc_nc_index,compound_index,allsource_index)) endif title_str='uEMEP_emission_'//trim(file_tag)//temp_date_str i_file=subgrid_total_file_index(allsource_index) write(unit_logfile,'(A)') '' write(unit_logfile,'(A)') '================================================================' write(unit_logfile,'(A)') 'Saving emission netcdf data (uEMEP_save_emission_netcdf)' write(unit_logfile,'(A)') '================================================================' exists = check_dir_exist(path=trim(pathname_emissions_for_EMEP)) if (.not.exists) then write(unit_logfile,'(A)')'ERROR: Path to EMEP emission output '//trim(pathname_emissions_for_EMEP)//' does not exist.' stop endif !Save the emissions interpolated to the target grid variable_type='float' unit_str="mg/m2" do i_source=1,n_source_index if (save_emissions_for_EMEP(i_source).and.i_source.ne.allsource_index) then !Create a new file for each source create_file=.true. !temp_name=trim(pathname_emissions_for_EMEP)//'uEMEP_emission_for_EMEP_'//trim(file_tag)//'_'//trim(source_file_str(i_source))//trim(temp_compound_str)//trim(temp_date_str)//'_'//trim(forecast_hour_str)//'.nc' temp_name=trim(pathname_emissions_for_EMEP)//'uEMEP_emission_for_EMEP_'//trim(file_tag)//'_'//trim(source_file_str(i_source))//trim(temp_compound_str)//trim(temp_date_str)//'.nc' write(unit_logfile,'(a,a)') 'Saving netcdf file: ',trim(temp_name) do i_pollutant=1,n_pollutant_loop !if (pollutant_loop_index(i_pollutant).ne.pmex_nc_index.and.pollutant_loop_index(i_pollutant).ne.pm10_sand_nc_index.and.pollutant_loop_index(i_pollutant).ne.pm10_salt_nc_index & ! .and.pollutant_loop_index(i_pollutant).ne.pm25_sand_nc_index.and.pollutant_loop_index(i_pollutant).ne.pm25_salt_nc_index) then if (pollutant_loop_index(i_pollutant).eq.pm10_nc_index.or.pollutant_loop_index(i_pollutant).eq.pm25_nc_index.or.pollutant_loop_index(i_pollutant).eq.nox_nc_index.or.pollutant_loop_index(i_pollutant).eq.nh3_nc_index & .or.(pollutant_loop_index(i_pollutant).eq.pmex_nc_index.and.i_source.eq.traffic_index)) then i_file=emission_file_index(i_source) var_name_temp=trim(var_name_nc(emis_nc_index,pollutant_loop_index(i_pollutant),allsource_index)) !//'_'//trim(filename_grid(i_file)) !Calculate the emissions in the target grid temp_subgrid(:,:,:)=emission_subgrid(:,:,save_emissions_start_index:save_emissions_end_index,i_source,i_pollutant) if (save_traffic_emissions_for_EMEP_as_exhaust_nonexhaust_flag.and.i_source.eq.traffic_index.and.pollutant_loop_index(i_pollutant).eq.pm25_nc_index) then var_name_temp=trim(var_name_nc(emis_nc_index,pm25_nc_index,allsource_index))//'_'//'nonexhaust' temp_subgrid(:,:,:)=emission_subgrid(:,:,save_emissions_start_index:save_emissions_end_index,i_source,pollutant_loop_back_index(pm25_nc_index))-emission_subgrid(:,:,save_emissions_start_index:save_emissions_end_index,i_source,pollutant_loop_back_index(pmex_nc_index)) endif if (save_traffic_emissions_for_EMEP_as_exhaust_nonexhaust_flag.and.i_source.eq.traffic_index.and.pollutant_loop_index(i_pollutant).eq.pmex_nc_index) then var_name_temp=trim(var_name_nc(emis_nc_index,pm25_nc_index,allsource_index))//'_'//'exhaust' temp_subgrid(:,:,:)=emission_subgrid(:,:,save_emissions_start_index:save_emissions_end_index,i_source,pollutant_loop_back_index(pmex_nc_index)) endif !Convert the PM10 to PMco, special case if (pollutant_loop_index(i_pollutant).eq.pm10_nc_index) then var_name_temp=trim(var_name_nc(emis_nc_index,pmco_nc_index,allsource_index)) !//'_'//trim(filename_grid(i_file)) temp_subgrid(:,:,:)=emission_subgrid(:,:,save_emissions_start_index:save_emissions_end_index,i_source,pollutant_loop_back_index(pm10_nc_index))-emission_subgrid(:,:,save_emissions_start_index:save_emissions_end_index,i_source,pollutant_loop_back_index(pm25_nc_index)) if (save_traffic_emissions_for_EMEP_as_exhaust_nonexhaust_flag.and.i_source.eq.traffic_index) then var_name_temp=trim(var_name_nc(emis_nc_index,pmco_nc_index,allsource_index))//'_'//'nonexhaust' temp_subgrid(:,:,:)=emission_subgrid(:,:,save_emissions_start_index:save_emissions_end_index,i_source,pollutant_loop_back_index(pm10_nc_index)) & -emission_subgrid(:,:,save_emissions_start_index:save_emissions_end_index,i_source,pollutant_loop_back_index(pm25_nc_index)) endif endif !Subgrid emissions are in units ug/sec/subgrid. Convert to mg/m2/hour. Acount for the difference in subgrid sizes here if (trim(save_emissions_for_EMEP_projection).eq.'lambert') then temp_subgrid(:,:,:)=1.0e-3*3600.*temp_subgrid(:,:,:)/(emission_subgrid_delta(y_dim_index,i_source)*emission_subgrid_delta(x_dim_index,i_source)) else !Temporary estimate of area of lat lon. Needs to be fixed do j=1,emission_subgrid_dim(y_dim_index,i_source) do i=1,emission_subgrid_dim(x_dim_index,i_source) temp_subgrid(i,j,:)=1.0e-3*3600.*temp_subgrid(i,j,:)/(emission_subgrid_delta(y_dim_index,i_source)*emission_subgrid_delta(x_dim_index,i_source) & *110570.*110570.*cos(3.14159/180.*y_emission_subgrid(i,j,i_source))) enddo enddo endif !write(*,'(4i,a)') i_pollutant,i_file,i_source,pollutant_loop_index(i_pollutant),trim(var_name_temp) if (save_netcdf_file_flag.or.save_netcdf_receptor_flag) then write(unit_logfile,'(a,es12.2)')'Writing netcdf variable: '//trim(var_name_temp),sum(temp_subgrid(:,:,:))/size(temp_subgrid,1)/size(temp_subgrid,2)/size(temp_subgrid,3) call uEMEP_save_for_EMEP_netcdf_file(temp_name,emission_subgrid_dim(x_dim_index,i_source),emission_subgrid_dim(y_dim_index,i_source),temp_time_dim & ,temp_subgrid(:,:,:),x_emission_subgrid(:,:,i_source),y_emission_subgrid(:,:,i_source),lon_emission_subgrid(:,:,i_source),lat_emission_subgrid(:,:,i_source),var_name_temp & ,unit_str,title_str,create_file,valid_min,variable_type,scale_factor) endif !Do not create file after first loop create_file=.false. endif enddo endif enddo end subroutine uEMEP_save_emission_netcdf