-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmisGet_mod.f90
1742 lines (1508 loc) · 76.5 KB
/
EmisGet_mod.f90
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module EmisGet_mod
use CheckStop_mod, only: CheckStop, StopAll, check=>CheckNC
use ChemDims_mod, only: NSPEC_ADV, NSPEC_TOT, NEMIS_File, NEMIS_Specs
use ChemSpecs_mod, only: species
use Config_module, only: NPROC, MasterProc,USES,&
KMAX_MID,KMAX_BND, Pref,&
SEAFIX_GEA_NEEDED, & ! only if emission problems over sea
IIFULLDOM,JJFULLDOM, SECTORS_NAME, &
SplitSpecialsFile,SplitDefaultFile,EmisHeightsFile,femisFile,&
startdate
use Country_mod, only: NLAND, IC_NAT, IC_VUL, IC_NOA, Country, &
! NMR-NH3 specific variables (hb NH3Emis)
IC_NMR,IC_DUMMY
use Debug_module, only: DEBUG
use EmisDef_mod, only: NSECTORS, ANTROP_SECTORS, NCMAX, &
N_HFAC,N_SPLIT, EMIS_FILE, &
VOLCANOES_LL, &
! NMR-NH3 specific variables (for FUTURE )
NH3EMIS_VAR,dknh3_agr,ISNAP_AGR,ISNAP_TRAF, &
NROADDUST, &
gnfr2snap,snap2gnfr&
,cdfemis,sumcdfemis,nGridEmisCodes,GridEmisCodes&
,GridEmis,gridrcemis, Emis_mask, MASK_LIMIT&
,landcode,nlandcode,MAXFEMISLONLAT,N_femis_lonlat &
,femis_lonlat_internal & !DSHK
,Emis_field, NEmis_id, Emis_id, NEmis_sources&
,EmisFiles, NEmisFile_sources, Emis_source &
,NEmis_sourcesMAX
use GridAllocate_mod, only: GridAllocate
use GridValues_mod, only: debug_proc,debug_li,debug_lj,i_fdom,j_fdom,i_local
use GridValues_mod, only: glon, glat, A_bnd, B_bnd,j_local
!DSHK use Io_mod, only: open_file,IO_LOG, NO_FILE, ios, IO_EMIS, &
use Io_mod, only: open_file, NO_FILE, ios, IO_EMIS, &
Read_Headers, read_line, PrintLog
use Io_Progs_mod, only: datewrite
use KeyValueTypes, only: KeyVal
use MPI_Groups_mod , only : MPI_BYTE, MPI_REAL8, MPI_DOUBLE_PRECISION, MPI_SUM&
, MPI_INTEGER, MPI_COMM_CALC, IERROR
use NetCDF_mod, only : ReadField_CDF, check_lon_lat, ReadTimeCDF, &
GetCDF_modelgrid, make_gridresolution
use OwnDataTypes_mod, only: TXTLEN_NAME, TXTLEN_FILE, Emis_id_type, &
EmisFile_id_type, Emis_sourceFile_id_type
use Par_mod, only: LIMAX, LJMAX, limax, ljmax, me
use SmallUtils_mod, only: wordsplit, find_index, key2str
use netcdf, only: NF90_OPEN,NF90_NOERR,NF90_NOWRITE,&
NF90_INQUIRE,NF90_INQUIRE_VARIABLE,NF90_CLOSE,&
nf90_global,nf90_get_var,nf90_get_att
use PhysicalConstants_mod, only : PI, EARTH_RADIUS
use TimeDate_mod, only : date
use TimeDate_ExtraUtil_mod, only : nctime2date,date2nctime, date2string
use Timefactors_mod, only: fac_ehh24x7
implicit none
private
! subroutines:
public :: Emis_init_GetCdf ! define constant parameters
public :: Emis_GetCdf ! new formats
public :: EmisGetCdf ! cdfemis
public :: EmisGetASCII !new version of "EmisGet" which does not use fulldomain arrays
public :: EmisSplit ! => emisfrac, speciation of voc, pm25, etc.
public :: EmisHeights ! => nemis_kprofile, emis_kprofile
! vertical emissions profile
public :: RoadDustGet ! Collects road dust emission potentials
public :: femis ! Sets emissions control factors
public :: make_iland_for_time !make land indices for timefactors
private :: CountEmisSpecs !
!logical, private, save :: my_first_call = .true.
logical, private, save :: my_first_road = .true.
! e_fact is the emission control factor (increase/decrease/switch-off)
! e_fact is read in from the femis file and applied within EmisGet
real, public, save, allocatable, &
! dimension(NSECTORS,NLAND,NEMIS_FILE) :: e_fact
dimension(:,:,:) :: e_fact
! e_fact_lonlat is read in from the femis file and applied within EmisGet using lat lon format
real, public, save, allocatable, &
! dimension(NSECTORS,MAXFEMISLONLAT,NEMIS_FILE) :: e_fact_lonlat
dimension(:,:,:) :: e_fact_lonlat
real, public, save, dimension(MAXFEMISLONLAT) :: femis_latmin,femis_latmax,femis_lonmin,femis_lonmax,femis_lonlat_ic
! emisfrac is used at each time-step of the model run to split
! emissions such as VOC, PM into species.
integer, public, parameter :: NMAX = NSPEC_ADV
integer, public, save :: nrcemis, nrcsplit
integer, public, dimension(NEMIS_FILE) , save :: emis_nsplit
real, public,allocatable, dimension(:,:,:), save :: emisfrac
integer, public,allocatable, dimension(:), save :: iqrc2itot
integer, public,allocatable, dimension(:), save :: iqrc2iem
integer, public, dimension(NSPEC_TOT), save :: itot2iqrc
integer, public, dimension(NSPEC_TOT,NEMIS_FILE) :: iemsplit2itot !maps from split and iem to itot
integer, public, dimension(NEMIS_FILE), save :: Emis_MolWt
real, public,allocatable, dimension(:), save :: emis_masscorr
real, public,allocatable, dimension(:), save :: roaddust_masscorr
! vertical profiles for SNAP emis, read from EmisHeightsFile
integer, public, save :: nemis_kprofile
real, public,allocatable, dimension(:,:), save :: emis_kprofile
real, public,allocatable, dimension(:,:), save :: emis_hprofile
! some common variables
character(len=TXTLEN_FILE), private :: fname ! File name
character(len=80), private :: errmsg
! Import list of the emitted species we need to find in the
! emissplit files.
include 'CM_EmisSpecs.inc'
logical, dimension(NEMIS_SPECS) :: EmisSpecFound = .false.
integer, private ::i_femis_lonlat
contains
! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
subroutine Emis_GetCdf(EmisFile, Emis_source, Emis_XD, date_wanted)
type(Emis_id_type),intent(inout) :: Emis_source
type(EmisFile_id_type),intent(inout) :: EmisFile
real, intent(out), dimension(*) :: Emis_XD
type(date), intent(in) :: date_wanted
real :: date_wanted_in_days, TimesInDays(1)
integer :: record
logical, save :: dbg= .false., first_call = .true. ! DS
character(len=*), parameter :: dtxt = 'Emis_GetCdf:'
if ( first_call ) then ! DS
dbg = ( MasterProc .and. DEBUG%GETEMIS )
first_call = .false.
end if
fname = date2string(EmisFile%filename,date_wanted,mode='YMDH')
if(EmisFile%periodicity == 'yearly')then
!assumes only one record to read
record = 1
else if(EmisFile%periodicity == 'monthly')then
!assumes 12 records, one for each month
record = date_wanted%month
else
!the correct time must be written in the file
call date2nctime(date_wanted,date_wanted_in_days)
call ReadTimeCDF(fname,TimesInDays,record,date_wanted_in_days)
call nctime2date(EmisFile%end_of_validity_date, TimesInDays(1))
if(me==0)write(*,*)record,'ENDOFVAL ', EmisFile%end_of_validity_date
endif
if( dbg ) write(*,*) dtxt//'Reading '//trim(fname)
if(trim(EmisFile%projection) == 'native')then
if(me==0)write(*,*)'reading new '//trim(Emis_source%varname)//' from native grid, record ',record
if(Emis_source%is3D)then
call GetCDF_modelgrid(Emis_source%varname,fname,Emis_XD,&
Emis_source%kstart, Emis_source%kend,record,1,&
i_start=Emis_source%istart,j_start=Emis_source%jstart,&
reverse_k=Emis_source%reversek,needed=.true.)
else
call GetCDF_modelgrid(Emis_source%varname,fname,Emis_XD,1,1,record,1,&
i_start=Emis_source%istart,j_start=Emis_source%jstart,&
needed=.true.)
endif
else
if(me==0)write(*,*)trim(Emis_source%varname)//' reading new emis from '//trim(fname)//', record ',record
if(Emis_source%units(1:9) == 'tonnes/m2' &
.or. Emis_source%units(1:5) == 'kg/m2' &
.or. Emis_source%units(1:4) == 'g/m2' &
.or. Emis_source%units(1:5) == 'mg/m2')then
!per area units
call ReadField_CDF(fname,Emis_source%varname,Emis_XD,record,&
known_projection=trim(EmisFile%projection),&
interpol='conservative',&
Grid_resolution_in = EmisFile%grid_resolution,&
needed=.true.,UnDef=0.0,&
debug_flag=.false.)
else if(Emis_source%units == 'tonnes' .or. Emis_source%units == 'tonnes/s' &
.or.Emis_source%units == 'tonnes/month' .or. Emis_source%units == 'tonnes/year' &
.or. Emis_source%units == 'kg' .or. Emis_source%units == 'kg/s' &
.or. Emis_source%units == 'kg/month' .or. Emis_source%units == 'kg/year' &
.or. Emis_source%units == 'g' .or. Emis_source%units == 'g/s' &
.or. Emis_source%units == 'g/month' .or. Emis_source%units == 'g/year' &
.or. Emis_source%units == 'mg' .or. Emis_source%units == 'mg/s' &
.or. Emis_source%units == 'mg/month' .or. Emis_source%units == 'mg/year' &
.or. Emis_source%units == 'g/h' .or. Emis_source%units == 'mg/h')then
!per gridcell unit
if(me==0)write(*,*)'reading emis '//trim(Emis_source%varname)//' from '//trim(fname)//', proj ',trim(EmisFile%projection),', res ',EmisFile%grid_resolution
call ReadField_CDF(fname,Emis_source%varname,Emis_XD,record,&
known_projection=trim(EmisFile%projection),&
interpol='mass_conservative',&
Grid_resolution_in = EmisFile%grid_resolution,&
needed=.true.,UnDef=0.0,&
debug_flag=.false.)
else
call StopAll("EmisGet: Unit for emissions not recognized: "//trim(Emis_source%units)//' '//trim(Emis_source%varname))
endif
endif
end subroutine Emis_GetCdf
! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
subroutine EmisGetCdf(iem, fname, sumemis_local, &
Emis, EmisCodes, nEmisCodes, nstart,&
incl, nin, excl, nex, use_lonlat_femis, &
set_mask,use_mask, fractionformat, type)
!read in emissions in fraction format and add results into
!Emis, nEmisCodes and nEmisCodes
!NB: landcode and nlandcode arrays are local
implicit none
integer, intent(in) ::iem, nin, nex,nstart
character(len=*),intent(in) :: fname, incl(*),excl(*),type
real,intent(inout) ::Emis(NSECTORS,LIMAX,LJMAX,NCMAX,NEMIS_FILE)
integer,intent(inout) ::nEmisCodes(LIMAX,LJMAX)
integer,intent(inout) ::EmisCodes(LIMAX,LJMAX,NCMAX)
! Sum of emissions per country
real,intent(inout), dimension(NLAND,NEMIS_FILE) :: sumemis_local
logical, intent(in) :: use_lonlat_femis,set_mask,use_mask
logical, intent(in) :: fractionformat
real :: fractions(LIMAX,LJMAX,NCMAX),Reduc(NLAND)
integer :: landcode(LIMAX,LJMAX,NCMAX),nlandcode(LIMAX,LJMAX)
real :: lonlat_fac, fac, file_fac
integer ::i,j,n,ic,i_cc,found, isec, sec_ix
logical :: Cexist
integer :: nwords, err, status
integer :: ncFileID, nDimensions,nVariables,nAttributes,timeDimID,varid,xtype,ndims
character(len=100) :: code, ewords(10), varname, cdfvarname, specname
logical :: mappingGNFR2SNAP = .false., foundEmis_id
integer :: iem_used, ix_Emis
if(.not. fractionformat)then
!not fraction format
!loop over all variables
status=nf90_open(path = trim(fName), mode = nf90_nowrite, ncid = ncFileID)
if( status /= nf90_noerr ) then
if( MasterProc )write(*,*) "ERROR: EmisGetCdf - couldn't open "//trim(fName)
CALL MPI_FINALIZE(IERROR)
stop
end if
call check(nf90_Inquire(ncFileID,nDimensions,nVariables,nAttributes,timeDimID))
nlandcode=1
fractions=1.0
if(SECTORS_NAME=='GNFR'.and.type == "SNAPsectors")then
call CheckStop('GNFR sector cannot mix with SNAP sectors for this format')
else if(SECTORS_NAME=='SNAP'.and.type == "GNFRsectors")then
call CheckStop('SNAP sector cannot mix with GNFR sectors for this format')
else
!only case implemented for not fractions
endif
else
nVariables = NSECTORS*NEMIS_FILE !in fraction format we loop over all species and sectors
endif
mappingGNFR2SNAP = .false.
do varid=1,nVariables
sec_ix = 1
762 continue !if several GNFR counterparts to one SNAP
iem_used = iem !default
file_fac = 1.0 !default
foundEmis_id = .false.
if(.not. fractionformat)then
call check(nf90_Inquire_Variable(ncFileID,varid,cdfvarname,xtype,ndims))
ewords=''
if( index(cdfvarname, "Emis:") >0 )then
! Emission terms look like, e.g. Emis:FR:snap:7
! or Emis:FR:snap:7:spec:sox:fac:1.0
call wordsplit(cdfvarname,8,ewords,nwords,err,separator=":")
if( ewords(3) /= "snap" ) cycle ! ONLY SNAP coded for now
read(ewords(4),"(I6)") isec
code = ewords(2) ! Country ISO
if( ewords(5) == "spec" )then !optional
iem_used = find_index(ewords(6),EMIS_FILE(:))
if(iem_used<0)then
iem_used = find_index(ewords(6),species(:)%name)
if(iem_used<0)then
if(MasterProc)write(*,*)trim(ewords(6))//' NOT FOUND'
cycle
else
if(MasterProc)write(*,*)'found '//species(iem_used)%name//' for '//trim(ewords(6))
!see if case has been found before
!should search only among NEmis_id first!
ix_Emis = find_index(ewords(6),Emis_id%species(:))
if(ix_Emis>0)then
if(MasterProc)write(*,*)trim(ewords(6))//' already defined'
else
if(MasterProc)write(*,*)NEmis_id,' defining new id '//trim(ewords(6))
NEmis_id = NEmis_id + 1
ix_Emis = NEmis_id
Emis_id(ix_Emis)%species = trim(ewords(6))
endif
iem_used = 1
foundEmis_id = .true.
endif
endif
!could add case for any species
endif
if( ewords(7) == "fac" )then !optional, but "spec" must be used if "fac" is set
file_fac=-999.9
read(ewords(8),*)file_fac
if(abs(file_fac+999.9)<0.1)then !not good test
if(MasterProc)write(*,*)trim(ewords(8))//' NOT UNDERSTOOD AS REAL'
cycle
endif
endif
cdfemis = 0.0 ! safety, shouldn't be needed though
call ReadField_CDF(fname,cdfvarname,cdfemis,nstart=nstart,&
interpol='mass_conservative',&
needed=.false.,UnDef=0.0,&
debug_flag=.false.,ncFileID_given=ncFileID)
if( maxval(cdfemis ) < 1.0e-10 ) cycle ! Likely no emiss in domain
else
!other allowed cases to be implemented
cycle
endif
else
!fraction format
isec=mod((varid-1),NSECTORS)+1
iem_used=(varid-1)/NSECTORS+1
if(SECTORS_NAME=='GNFR'.and.type == "SNAPsectors")then
if(gnfr2snap(isec)<=0)cycle
write(varname,"(A,I2.2)")trim(EMIS_FILE(iem_used))//'_sec',gnfr2snap(isec)
if(me==0.and.iem_used==1)write(*,*)'WARNING, mapping snap sector ',gnfr2snap(isec),'onto gnfr',isec
else if(SECTORS_NAME=='SNAP'.and.type == "GNFRsectors")then
mappingGNFR2SNAP = .true.
if(snap2gnfr(isec,sec_ix)<=0)cycle
if(me==0.and.iem_used==1)write(*,*)'WARNING, mapping gnfr sector ',snap2gnfr(isec,sec_ix),'onto snap',isec
write(varname,"(A,I2.2)")trim(EMIS_FILE(iem_used))//'_sec',snap2gnfr(isec,sec_ix)
else
write(varname,"(A,I2.2)")trim(EMIS_FILE(iem_used))//'_sec',isec
endif
Reduc=e_fact(isec,:,iem_used)
call ReadField_CDF(trim(fname),varname,cdfemis(1,1),nstart=nstart,&
interpol='mass_conservative',fractions_out=fractions,&
CC_out=landcode,Ncc_out=nlandcode,Reduc=Reduc,needed=.false.,debug_flag=.false.,&
Undef=0.0)
endif
!end reading of data
!apply mask and femis_lonlat (femis "not lonlat" is already applied)
do j=1,ljmax
do i=1,limax
if(foundEmis_id)then
!for now no reductions applied
Emis_field(i,j,ix_Emis) = Emis_field(i,j,ix_Emis) +&
cdfemis(i,j) * file_fac
else
if(use_mask)then
if(Emis_mask(i,j))cdfemis(i,j)=0.0
endif
if(set_mask)then
if(cdfemis(i,j)>MASK_LIMIT)Emis_mask(i,j)=.true.
endif
if(cdfemis(i,j)<100.0*MASK_LIMIT)cycle !important, because otherwise get too many countries per gridcell!
if(nlandcode(i,j)>NCMAX)then
write(*,*)"GetCdfFrac: Too many emitter countries in one gridcell: ",&
me,i,j,nlandcode(i,j),trim(fname),trim(varname)
call StopAll("To many countries in one gridcell ")
end if
do n=1,nlandcode(i,j)
if(fractionformat)then
ic=find_index(landcode(i,j,n),Country(:)%icode)
else
ic=find_index(code,Country(:)%code)
landcode(i,j,n) = Country(ic)%icode
endif
if(ic>NLAND .or. ic<1)then
write(*,*)"COUNTRY CODE NOT RECOGNIZED OR UNDEFINED: ",ic,landcode(i,j,n)
call StopAll("COUNTRY CODE NOT RECOGNIZED ")
end if
!exclude or include countries
!could easily be optimized, by defining a country mask
if(nin>0)then
!1) check that country is in include list
found=find_index(Country(ic)%code ,incl(1:nin),first_only=.true.)
if(found<=0)cycle!do not include
end if
if(nex>0)then
!1) check that country is not in exclude list
found=find_index(Country(ic)%code ,excl(1:nex),first_only=.true.)
if(found>0)cycle!exclude
end if
lonlat_fac=1.0
if(N_femis_lonlat>0 .and. use_lonlat_femis)then
do i_femis_lonlat=1,N_femis_lonlat
if(glat(i,j)>femis_latmin(i_femis_lonlat).and.&
glat(i,j)<femis_latmax(i_femis_lonlat).and.&
glon(i,j)>femis_lonmin(i_femis_lonlat).and.&
glon(i,j)<femis_lonmax(i_femis_lonlat).and.&
(femis_lonlat_ic(i_femis_lonlat)==0 .or. &
femis_lonlat_ic(i_femis_lonlat)==landcode(i,j,n)) )then
!DSHK IN BOX:
if ( femis_lonlat_internal(i_femis_lonlat) ) & !DSHK
lonlat_fac=lonlat_fac*e_fact_lonlat(isec,i_femis_lonlat,iem_used)
else if ( femis_lonlat_internal(i_femis_lonlat ) .eqv. .false. ) then !DSHK
! DSHK - apply functions outside box
!print *, 'DSHK here A ', me, N_femis_lonlat, i_femis_lonlat, femis_lonlat_ic(i_femis_lonlat)
lonlat_fac=lonlat_fac*e_fact_lonlat(isec,i_femis_lonlat,iem_used) !DSHK
end if
end do
end if
fac = file_fac*lonlat_fac
if(.not. fractionformat) fac = fac*e_fact(isec,ic,iem_used)
!merge into existing emissions
Cexist=.false.
do i_cc=1,nEmisCodes(i,j)
if(EmisCodes(i,j,i_cc)==landcode(i,j,n))then
Emis(isec,i,j,i_cc,iem_used)=Emis(isec,i,j,i_cc,iem_used)&
+fractions(i,j,n)*cdfemis(i,j) * fac
Cexist=.true.
exit
end if
end do
if(.not.Cexist)then
!country not included yet. define it now:
nEmisCodes(i,j)=nEmisCodes(i,j)+1
if(nEmisCodes(i,j)>NCMAX)then
write(*,*)"Too many emitter Countries in one emiscell: ",&
me,i,j,nEmisCodes(i,j),trim(fname),trim(varname),(EmisCodes(i,j,i_cc),i_cc=1,nEmisCodes(i,j)-1)
call StopAll("To many countries in one emiscell ")
end if
i_cc=nEmisCodes(i,j)
EmisCodes(i,j,i_cc)=landcode(i,j,n)
Emis(isec,i,j,i_cc,iem_used)=fractions(i,j,n)*cdfemis(i,j)*fac
end if
sumemis_local(ic,iem_used)=sumemis_local(ic,iem_used)&
+0.001*fractions(i,j,n)*cdfemis(i,j)*fac !for diagnostics, mass balance
end do
endif
end do
end do
if(mappingGNFR2SNAP)then
!some SNAP sectors have several GNFR counterparts. Must take all of them
if(sec_ix<3)then
if(snap2gnfr(isec,sec_ix+1)>0)then
sec_ix = sec_ix + 1
goto 762
endif
endif
endif
enddo
if(.not.fractionformat) call check(nf90_close(ncFileID))
end subroutine EmisGetCdf
! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
subroutine Emis_init_GetCdf(EmisFile_in, EmisFile, names_in, nnames)
!read in emissions from one file and set parameters
implicit none
character(len=*),intent(in) :: names_in(*)
type(Emis_sourceFile_id_type),intent(in) :: EmisFile_in
type(EmisFile_id_type),intent(inout) :: EmisFile
integer,intent(in) :: nnames
character(len=100) :: projection, default_projection, name, cdfvarname, cdfspecies
real :: factor, default_factor
character(len= TXTLEN_FILE) :: fname
character(len=30) :: lon_name, lat_name
integer :: n, nn, i, ix, varid, status, sector, iem, isec, iqrc, itot, f
integer :: nDimensions, nVariables, nAttributes, xtype, ndims
real :: x, resolution, default_resolution, Rlat(2)
integer :: ncFileID, nemis_old, lonVarID, latVarID, dimids(10),dims(10)
real, allocatable ::Rlat2D(:,:)
character(len=*), parameter :: dtxt='Em_inicdf:'
integer :: countrycode
logical :: apply_femis
fname=trim(date2string(EmisFile_in%filename,startdate,mode='YMDH'))
status=nf90_open(path = trim(fname), mode = nf90_nowrite, ncid = ncFileID)
if( status /= nf90_noerr ) then
if( MasterProc )write(*,*)"ERROR: EmisGetCdf - couldn't open "//trim(fname)
CALL MPI_FINALIZE(IERROR)
stop
end if
!-------------
associate ( debugm0 => ( DEBUG%GETEMIS .and. MasterProc ) )
!-------------
if ( debugm0 ) write(*,*) dtxt//'Start File:',trim(fname)
if(EmisFile_in%projection /= 'native')then
default_projection = 'Unknown'
status = nf90_get_att(ncFileID, nf90_global,"projection", projection)
if(status==nf90_noerr)then
default_projection = trim(projection)
endif
default_resolution = 0.0
status = nf90_get_att(ncFileID, nf90_global,"Grid_resolution", resolution)
if(status==nf90_noerr)then
default_resolution = resolution
else
call make_gridresolution(ncFileID, default_resolution)
endif
endif
default_factor = 1.0
status = nf90_get_att(ncFileID, nf90_global,"factor", factor)
if(status==nf90_noerr)then
default_factor = factor
endif
nemis_old = NEmis_sources
!loop over all variables
call check(nf90_Inquire(ncFileID,nDimensions,nVariables,nAttributes))
do varid=1,nVariables
call check(nf90_Inquire_Variable(ncFileID,varid,cdfvarname,xtype,ndims))
status = nf90_get_att(ncFileID,varid,"species",cdfspecies)
nn = 0
do i = 1,size(EmisFile_in%source)
!if ( debugm0 ) write(*,*) dtxt//'source:',trim(EmisFile_in%source(i)%varname)
if(EmisFile_in%source(i)%varname == cdfvarname)then
nn = nn + 1
call CheckStop(NEmis_sources+nn > NEmis_sourcesMAX,"NEmis_sourcesMAX exceeded (A)")
Emis_source(NEmis_sources+nn)%ix_in=i
if ( debugm0 ) write(*,*) dtxt//'var add:',trim(cdfvarname)
endif
enddo
if((status==nf90_noerr .and. ndims>=2) .or. nn>0 )then
!can be that one source must be taken several times (for instance
! into different vertical levels)
do i = 1,max(1,nn)
!we define a new emission source
call CheckStop(NEmis_sources+1 > NEmis_sourcesMAX,"NEmis_sourcesMAX exceeded (B)")
NEmis_sources = NEmis_sources + 1
Emis_source(NEmis_sources)%varname = trim(cdfvarname)
Emis_source(NEmis_sources)%species = trim(cdfspecies)
if ( debugm0 ) write(*,*) dtxt//'source add:',&
trim(cdfvarname)//'->'// trim(cdfspecies),EmisFile_in%apply_femis
status = nf90_get_att(ncFileID,varid,"units", name)
if(status==nf90_noerr)Emis_source(NEmis_sources)%units = trim(name)
status = nf90_get_att(ncFileID,varid,"sector", sector)
if(status==nf90_noerr)Emis_source(NEmis_sources)%sector = sector
status = nf90_get_att(ncFileID,varid,"factor", x)
if(status==nf90_noerr)Emis_source(NEmis_sources)%factor = x
status = nf90_get_att(ncFileID,varid,"country", countrycode)
if(status==nf90_noerr)then
ix = find_index(countrycode, Country(:)%icode)
if(ix<0)then
if(me==0)write(*,*)dtxt//'WARNING: country '//trim(name)//&
' not defined. file'//trim(fname)//&
' variable '//trim(cdfvarname)
else
Emis_source(NEmis_sources)%country_ISO = trim(name)
Emis_source(NEmis_sources)%country_ix = ix
if ( debugm0 ) write(*,*) dtxt//'ISO add:',ix,trim(name)
endif
else
status = nf90_get_att(ncFileID,varid,"country_ISO", name)
if(status==nf90_noerr)Emis_source(NEmis_sources)%country_ISO = trim(name)
ix = find_index(trim(name) ,Country(:)%code, first_only=.true.)
if(ix<0)then
if(me==0)write(*,*)dtxt//'WARNING: country_ISO '//trim(name)//&
' not defined. file'//trim(fname)//&
' variable '//trim(cdfvarname)
else
Emis_source(NEmis_sources)%country_ix = ix
if ( debugm0 ) write(*,*) dtxt//'country_ISO add: ',ix,trim(name)
endif
endif
enddo
endif
enddo
if(nemis_old /= NEmis_sources)then
!at least one valid source found in the file
NEmisFile_sources = NEmisFile_sources + 1
EmisFile%filename = EmisFile_in%filename
EmisFile%projection = default_projection
EmisFile%grid_resolution = default_resolution
EmisFile%factor = default_factor
if ( debugm0 ) write(*,*) dtxt//'valid File:',&
trim(EmisFile_in%filename),trim(default_projection), default_resolution
status = nf90_get_att(ncFileID,nf90_global,"periodicity", name)
if(status==nf90_noerr)EmisFile%periodicity = trim(name)
!default values for sources
status = nf90_get_att(ncFileID,varid,"species",cdfspecies)
if(status==nf90_noerr)EmisFile%species = trim(cdfspecies)
status = nf90_get_att(ncFileID,nf90_global,"units", name)
if(status==nf90_noerr)EmisFile%units = trim(name)
status = nf90_get_att(ncFileID,nf90_global,"sector", sector)
if(status==nf90_noerr)EmisFile%sector = sector
status = nf90_get_att(ncFileID,nf90_global,"country_ISO", name)
if(status==nf90_noerr)EmisFile%country_ISO = trim(name)
endif
call check(nf90_close(ncFileID))
if ( debugm0 ) write(*,*) dtxt//'Finished File',trim(fname)
!-------------
end associate
!-------------
end subroutine Emis_init_GetCdf
! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
subroutine EmisGetASCII(iem, fname, emisname, sumemis_local, incl, nin, excl, nex, &
use_lonlat_femis)
implicit none
integer, intent(in) ::iem, nin, nex
character(len=*),intent(in) :: fname, emisname, incl(*),excl(*)
real,intent(inout), dimension(NLAND,NEMIS_FILE) &
:: sumemis_local ! Sum of emissions per country
logical, intent(in) :: use_lonlat_femis
integer ::i,j,ic,CC,isec,i_gridemis,found
character(len=*), parameter :: sub = 'EmisGetASCII:'
logical :: Cexist
real :: tmpsec(NSECTORS),duml,dumh
real ::lonlat_fac(NSECTORS)
character(len=len(fname)+10) :: newfname !need some extra characters if the new name gets longer
character(len=*),parameter :: dtxt = 'Em_getAsc:'
call open_file(IO_EMIS, "r", fname, needed=.false., iostat=ios)
if(ios/=0)then
22 format(5A)
if(MasterProc)write(*,22)dtxt//'did not find ',trim(fname)
!try to write pollutant with capital letters
newfname=trim(fname)
newfname=key2str(newfname,'gridsox','gridSOx')
newfname=key2str(newfname,'gridnox','gridNOx')
newfname=key2str(newfname,'gridco','gridCO')
newfname=key2str(newfname,'gridvoc','gridNMVOC')
newfname=key2str(newfname,'gridnh3','gridNH3')
newfname=key2str(newfname,'gridpm25','gridPM25')
newfname=key2str(newfname,'gridpmco','gridPMco')
newfname=key2str(newfname,'gridpm10','gridPM10')
if(MasterProc)write(*,22)'trying: ',trim(newfname)
call open_file(IO_EMIS,"r",newfname,needed=.true.)
end if
READEMIS: do ! ************* Loop over emislist files *******************
read(unit=IO_EMIS,fmt=*,iostat=ios) CC,i,j, duml,dumh, &
(tmpsec(isec),isec=1,NSECTORS)
if ( ios < 0 ) exit READEMIS ! End of file
call CheckStop(ios > 0,"EmisGetASCII: ios error in emission file")
do ic=1,NLAND
if((Country(ic)%icode==CC))&
goto 543
end do
write(unit=errmsg,fmt=*) &
"COUNTRY CODE NOT RECOGNIZED OR UNDEFINED ", CC
call CheckStop(errmsg)
ic=0
543 continue
if ( i <= 0 .or. i > IIFULLDOM .or. &
j <= 0 .or. j > JJFULLDOM) cycle READEMIS
i = i_local(i) ! for SUB domain
j = j_local(j) ! for SUB domain
if ( i <= 0 .or. i > LIMAX .or. &
j <= 0 .or. j > LJMAX .or. &
ic <= 0 .or. ic > NLAND .or. &
ic == IC_NAT .or. & ! Excludes DMS
(ic == IC_VUL .and. VOLCANOES_LL) )&! Excludes Volcanoes
! from gridSOx. Read from
! VolcanoesLL.dat instead
cycle READEMIS
if ( trim ( emisname ) == "voc" ) tmpsec(11:11) = 0.0
!exclude or include countries
!could easily be optimized, by defining a country mask
if(nin>0)then
!1) check that country is in include list
found=find_index(Country(ic)%code ,incl(1:nin),first_only=.true.)
if(found<=0)cycle READEMIS!do not include
end if
if(nex>0)then
!1) check that country is not in exclude list
found=find_index(Country(ic)%code ,excl(1:nex),first_only=.true.)
if(found>0)cycle READEMIS!exclude
end if
lonlat_fac=1.0
if(N_femis_lonlat>0 .and. use_lonlat_femis)then
do i_femis_lonlat=1,N_femis_lonlat
if(glat(i,j)>femis_latmin(i_femis_lonlat).and.&
glat(i,j)<femis_latmax(i_femis_lonlat).and.&
glon(i,j)>femis_lonmin(i_femis_lonlat).and.&
glon(i,j)<femis_lonmax(i_femis_lonlat).and.&
(femis_lonlat_ic(i_femis_lonlat)==0 .or. &
femis_lonlat_ic(i_femis_lonlat)==CC) )then
!DSHK IN BOX
if ( femis_lonlat_internal(i_femis_lonlat) ) &
lonlat_fac(:)=lonlat_fac(:)*e_fact_lonlat(:,i_femis_lonlat,iem)
!DSHK OUTSIDE BOX
else if ( femis_lonlat_internal(i_femis_lonlat) .eqv. .false. ) then
lonlat_fac(:)=lonlat_fac(:)*e_fact_lonlat(:,i_femis_lonlat,iem)
end if
end do
end if
!merge into existing emissions
Cexist=.false.
do i_gridemis=1,nGridEmisCodes(i,j)
if(GridEmisCodes(i,j,i_gridemis)==CC)then
GridEmis(:,i,j,i_gridemis,iem)=&
GridEmis(:,i,j,i_gridemis,iem)&
+e_fact(:,ic,iem) * tmpsec(:) *lonlat_fac(:)
Cexist=.true.
exit
end if
end do
if(.not.Cexist)then
!country not included yet. define it now:
nGridEmisCodes(i,j)=nGridEmisCodes(i,j)+1
if(nGridEmisCodes(i,j)>NCMAX)then
write(*,*) sub// &
" Too many emitter countries in one gridemiscell: ",&
me,i,j,CC,&
(GridEmisCodes(i,j,i_gridemis),i_gridemis=1,NCMAX)
call StopAll("To many countries in one gridemiscell ")
end if
i_gridemis=nGridEmisCodes(i,j)
GridEmisCodes(i,j,i_gridemis)=CC
GridEmis(:,i,j,i_gridemis,iem)=e_fact(:,ic,iem) * tmpsec(:)*lonlat_fac(:)
end if
!for diagnostics, mass balance:
sumemis_local(ic,iem)=sumemis_local(ic,iem)&
+0.001*sum(e_fact(:,ic,iem)*tmpsec(:)*lonlat_fac(:))
end do READEMIS
close(IO_EMIS)
ios = 0
end subroutine EmisGetASCII
!-----------------------------------------------------------------------------
subroutine femis()
!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
!-------------------------------------------------------------------------
! Read emission control factors for the emissions from (optional) file femis.
! Emission factors are applied EITHER to specified country and/or
! emission sector, e.g. the femis file with input:
! Code 5 co sox nox nh3 voc
! 27 6 1.0 0.5 1.0 1.0 1.0
! will reduce SO2 emissions from sector 6 by a factor 0.5 for the UK
! (country 27);
! OR to all countries/sectors: a zero for country or sector means to
! apply factors to all countries and/or sectors.
! The number following the first text on line 1 (number 5 above) gives
! the number of pollutants treated in the file (ncols below).
! Note: ncols can be greater than the number of emitted species we actually
! have, and the species can be specified in any order, as given on the
! top line.
!-------------------------------------------------------------------------
!*** local variables ***
integer :: ie, iq, ic, iland1, iland2 & ! loop variables
,inland & ! Country read from femis
,isec, isec1 , isec2 & ! loop vars: emis sectors
,nwords,ncols, n, oldn ! No. cols. in "femis"
integer, parameter :: NCOLS_MAX = 20 ! Max. no. cols. in "femis"
integer, dimension(NEMIS_FILE) :: qc ! index for sorting femis columns
real, dimension(NCOLS_MAX):: e_f ! factors read from femis
real, dimension(NCOLS_MAX):: e_f_lonlat ! factors read from femis in lonlat format
character(len=200) :: txt ! For read-in
character(len=30), dimension(NCOLS_MAX):: txtinwords ! to read lines
character(len=*), parameter :: dtxt = 'femis:' !DS
!--------------------------------------------------------
e_fact(:,:,:) = 1.0 !**** default value = 1 ****
e_fact_lonlat(:,:,:) = 1.0 !**** default value = 1 ****
associate ( debugm0 => ( DEBUG%GETEMIS .and. MasterProc ) )
if( debugm0 ) write(*,*) dtxt//" Enters femis", me, trim(femisFile)
call open_file(IO_EMIS,"r",femisFile,needed=.false.)
if ( ios == NO_FILE ) then
ios = 0
write( *,*) "WARNING: NO FEMIS FILE"
return !*** if no femis file, e_fact=1 as default ***
end if
call CheckStop( ios < 0 ,"EmisGet:ios error in "//trim(femisFile))
! Reads in the header line, e.g. name sec sox nox voc.
! Pollutant names wil be checked against those defined in My_Emis_mod
read(unit=IO_EMIS,fmt="(a200)") txt
!D if(debugm0)write(unit=6,fmt=*) "In femis, header0 is: ", trim(txt)
call wordsplit(txt,NCOLS_MAX,txtinwords,ncols,ios)
if(debugm0) then
write(unit=6,fmt=*) "In femis, header is: ", txt
write(unit=6,fmt=*) "In femis, file has ", ncols, " columns (-2)"
end if
call CheckStop( ncols > NCOLS_MAX , "EmisGet:femisncols ncols > NCOLS_MAX" )
if(ios>0)return
! we allow the femis file to give factors in any order, and
! for pollutants not needed, so we need to work out the indices
! for each column. Remember also that ncols includes the 1st
! 2 columns (country_code and sector), which are not e_factors
ncols = ncols - 2
call CheckStop( ncols > NCOLS_MAX , "EmisGet:femisncols ncols > NCOLS_MAX" )
call CheckStop( ncols < 1 , "EmisGet:femisncols ncols < 1" )
n = 0
COLS: do ic=1,ncols
oldn = n
EMLOOP: do ie=1, NEMIS_FILE
if ( txtinwords(ic+2) == trim ( EMIS_FILE(ie) ) ) then
qc(ie) = ic
n = n + 1
if(debugm0)write(unit=6,fmt=*) "In femis: ", &
txtinwords(ic+2), " assigned to ", ie, EMIS_FILE(ie)
exit EMLOOP
end if
end do EMLOOP ! ie
if (oldn == n .and.debugm0) &
write(unit=6,fmt=*) "femis: ",txtinwords(ic+2)," NOT assigned"
end do COLS ! ic
if ( n < NEMIS_FILE ) then
print *, "FEMIS me n NEMIS_FILE", me, n, NEMIS_FILE, trim(femisFile)
call CheckStop( n < NEMIS_FILE , "EmisGet: too few femis items" )
end if
n = 0
N_femis_lonlat=0
!if(me==0)write(IO_LOG,55)'femis reductions:'
if(MasterProc) call PrintLog(dtxt//' reductions:')
READFILE: do ! ************ read lines of femis ***************
read(unit=IO_EMIS,fmt="(a200)",iostat=ios) txt
if( debugm0 ) write(*,*) dtxt//' input:'//trim(txt), ios
if ( ios < 0 ) exit READFILE ! End of file
call CheckStop( ios > 0 , "EmisGet: read error in femis" )
!DSHK: Allow comments in femis files:
if( txt(1:1) == '#' ) CYCLE ! Comments allowed DSHK
call wordsplit(txt,NCOLS_MAX,txtinwords,nwords,ios)
if ( nwords<3 ) cycle READFILE ! End of file
if(MasterProc) call PrintLog(txt) ! DSHK
!lonlat box. reductions defined with coordinates
!DSHK if(txtinwords(1)=='lonlat')then xlonlat applies reductions outside
if(txtinwords(1)=='lonlat' .or. txtinwords(1)=='xlonlat')then
if(debugm0) write(*,*) dtxt//' LONLAT'//trim(txtinwords(1) ), &
nwords, ncols !DSHK DEBUG
if(nwords<ncols+6)then
if(me==0)write(*,*)trim(femisFile)//' not understood ',nwords,ncols+5,txt
call CheckStop( nwords<ncols+5 , "EmisGet: read error in femis lonlat" )
end if
!latmin,latmax,lonmin,lonmax
N_femis_lonlat=N_femis_lonlat+1
femis_lonlat_internal(N_femis_lonlat) = .true.
call CheckStop( N_femis_lonlat>MAXFEMISLONLAT, "EmisGet: increase MAXFEMISLONLAT" )
!DSHK apply reductions area external to box:
if( txtinwords(1) == 'xlonlat' ) then
femis_lonlat_internal(N_femis_lonlat) = .false.
if( debugm0 ) write(*,*) dtxt//' exclude outside:'//trim(txt)
else
if( debugm0 ) write(*,*) dtxt//' exclude inside:'//trim(txt)
end if
inland = 0!default
if(nwords>ncols+6)then
! 76 format(A,4F,2I,20F)
read(txt,*)txtinwords(1),&
femis_lonmin(N_femis_lonlat),&
femis_lonmax(N_femis_lonlat),&
femis_latmin(N_femis_lonlat),&
femis_latmax(N_femis_lonlat),&
inland, isec, & !country code and sector
(e_f_lonlat(ic),ic=1,ncols)!reductions
else
!old format without country code
! 77 format(A,4F,I,20F)
if(me==0)write(*,*)'WARNING: USING OLD FORMAT for femis.&
Please, add country code (zero for all countries)'
read(txt,*)txtinwords(1),&
femis_lonmin(N_femis_lonlat),&
femis_lonmax(N_femis_lonlat),&
femis_latmin(N_femis_lonlat),&
femis_latmax(N_femis_lonlat)&
,isec,(e_f_lonlat(ic),ic=1,ncols)
endif
femis_lonlat_ic(N_femis_lonlat) = inland !country code to reduce (or reduce all for 0)
!It is rather easy to get coordinates which are equals.
!In order to avoid random decisions when this happens, we increase slightly the bounds:
femis_lonmin(N_femis_lonlat)=femis_lonmin(N_femis_lonlat)-1.0E-10
femis_lonmax(N_femis_lonlat)=femis_lonmax(N_femis_lonlat)+1.0E-10
femis_latmin(N_femis_lonlat)=femis_latmin(N_femis_lonlat)-1.0E-10
femis_latmax(N_femis_lonlat)=femis_latmax(N_femis_lonlat)+1.0E-10
!"normalize" longitudes to the interval -180,180
if(femis_lonmin(N_femis_lonlat)>180.0)femis_lonmin(N_femis_lonlat)=femis_lonmin(N_femis_lonlat)-360.0
if(femis_lonmin(N_femis_lonlat)<-180.0)femis_lonmin(N_femis_lonlat)=femis_lonmin(N_femis_lonlat)+360.0
if(femis_lonmax(N_femis_lonlat)>180.0)femis_lonmax(N_femis_lonlat)=femis_lonmax(N_femis_lonlat)-360.0
if(femis_lonmax(N_femis_lonlat)<-180.0)femis_lonmax(N_femis_lonlat)=femis_lonmax(N_femis_lonlat)+360.0
!There will still be problem when trying to "cross" the 180 degree longitude, therefore we put a test here:
call CheckStop(femis_lonmin(N_femis_lonlat)>femis_lonmax(N_femis_lonlat),&
"femislonlat: crossing 180 degrees longitude not allowed")
else
! read(unit=IO_EMIS,fmt=*,iostat=ios) inland, isec, (e_f(ic),ic=1,ncols)
! if ( ios < 0 ) exit READFILE ! End of file
! call CheckStop( ios > 0 , "EmisGet: read error in femis" )
read(txt,fmt=*,iostat=ios) inland, isec, (e_f(ic),ic=1,ncols)
n = n + 1
if(debugm0) then
!DSwrite(unit=6,fmt=*) dtxt//"FEMIS READ", inland, &
write(unit=6,fmt='(a,2i5,99f9.4)') dtxt//"FEMIS READ", inland, &
isec, (e_f(ic),ic=1,ncols)
write(unit=6,fmt="(2a,I3,a,i3,a)") &
dtxt//" Emission factors from femis.dat, ",&
"landcode =", inland, ", sector code =",isec, &
" (sector 0 applies to all sectors) :"
write(unit=6,fmt="(a,14(a,a,F8.2,a))") " ", &
(trim(txtinwords(qc(ie)+2)),&
" =",e_f(qc(ie)), ", ", ie=1,NEMIS_FILE-1), &
(trim(txtinwords(qc(ie)+2))," =",e_f(qc(ie))," ", &
ie=NEMIS_FILE,NEMIS_FILE)
end if
if (inland == 0 ) then ! Apply factors to all countries
iland1 = 1
iland2 = NLAND
else ! Apply factors to country "inland"
! find country number corresponding to index as written in emisfile
do iland1=1,NLAND
if(Country(iland1)%icode==inland ) then
if (debugm0 .and. inland==6) write(*,*)'DKLAND',inland,iland1
goto 544
end if
end do
if(MasterProc) write(*,*)'COUNTRY CODE NOT RECOGNIZED',inland
iland1 = 0
iland2 =-1
544 continue
if(iland1/=0) iland2 = iland1
end if
end if
if (isec == 0 ) then ! All sectors
isec1 = 1
isec2 = NSECTORS
elseif (isec==100) then ! Anthropogenic scenario
!if you need this option, then just uncomment and check that
!ANTROP_SECTORS is set according to your categories (10 for SNAP)
call CheckStop(SECTORS_NAME/='SNAP',&
"Anthropogenic not compatible with non-SNAP")
isec1 = 1
isec2 = ANTROP_SECTORS
else ! one sector: isec
isec1 = isec
isec2 = isec
end if
if(debugm0) write(*,'(a,4i5)') dtxt//" SECS", inland, isec, isec1, isec2, trim(txtinwords(1))
do ie = 1,NEMIS_FILE
if(txtinwords(1)=='lonlat')then
do isec = isec1, isec2
e_fact_lonlat(isec,N_femis_lonlat,ie) = &
e_fact_lonlat(isec,N_femis_lonlat,ie) * e_f_lonlat( qc(ie) )
end do !isec