-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathgen_surface_forcing.F90
More file actions
3073 lines (2761 loc) · 131 KB
/
gen_surface_forcing.F90
File metadata and controls
3073 lines (2761 loc) · 131 KB
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 g_sbf
!!===========================================================================
!! Ocean forcing:
!!===========================================================================
!! History: 0.1 ! 07/2015 I. Kuznetsov
!!
!! WARNING: in getcoeffld;nc_readTimeGrid
!! module will flip data in infiles for lat from -90 to 90 (NCEP-DOE Reanalysis 2 standart)
!! if you are going to use other coordinates in input files, please rewrite getcoeffld and nc_readTimeGrid functions.
!!! WARNING : for now reading only files were time counts in hours from 1800 year; nc_readTimeGrid ; done FOR NCEP data
!!! WARNING : move time forward for dt/2 , last is a last+dt from last -1 ; nc_readTimeGrid ; done FOR NCEP data
!! Description:
!! read and interpolate atmpospheric forcing on model grid,
!! or use constants from namelist each time step
!!
!! first initialization before first time step
!! model will read namelist, made some checks and prepare first interpolation coeficients
!! during model time steping, each time step sb_do is calling
!! during run model check if there is a time to read new data and construct new interpolation coefients
!! and interpolate data for new time step
!!
!! taux and tuay defined and allocated outside of this module, but will be changed in this module
!! qns - Downward Non Solar heat flux over the ocean defined here and changed here, to use it outside:
!! USE fv_sbc
!! emp - evaporation minus precipitation defined here and changed here, to use it outside:
!! USE fv_sbc
!!
!! Only NetCDF format is supported!
!! we assume that all NetCDF files have identical grid and time variable
!!
!! public:
!! sbc_ini -- initialization atmpospheric forcing
!! sbc_do -- provide a sbc (surface boundary conditions) each time step
!!
USE MOD_MESH
USE MOD_PARTIT
USE MOD_PARSUP
USE o_ARRAYS
USE o_PARAM
USE g_comm_auto
USE g_support
USE g_rotate_grid
USE g_config, only: dummy, ClimateDataPath, dt
USE g_clock, only: timeold, timenew, dayold, daynew, yearold, yearnew, cyearnew
USE g_forcing_arrays, only: runoff, chl
#if defined (__recom)
use recom_config
use recom_declarations
#endif
USE g_read_other_NetCDF, only: read_other_NetCDF, read_2ddata_on_grid_netcdf
USE netcdf
IMPLICIT NONE
include 'netcdf.inc'
public sbc_ini ! routine called before 1st time step (open files, read namelist,...)
public sbc_do ! routine called each time step to provide a sbc fileds (wind,...)
public sbc_end ! routine called after last time step
public RUNOFF_MAPPER
public julday ! get julian day from date
public atmdata
public i_totfl, i_xwind, i_ywind, i_xstre, i_ystre, i_humi, i_qsr, i_qlw, i_tair, i_prec, i_mslp, i_cloud, i_snow
public l_xwind, l_ywind, l_xstre, l_ystre, l_humi, l_qsr, l_qlw, l_tair, l_prec, l_mslp, l_cloud, l_snow
private
integer :: i_totfl = 12 ! total number of fluxes
integer :: i_xwind = 1 ! index of 10m wind velocity (x-component) [m/s]
integer :: i_ywind = 2 ! index of 10m wind velocity (y-component) [m/s]
integer :: i_xstre = 3 ! index of surface wind stress (x-component) [N/m2]
integer :: i_ystre = 4 ! index of surface wind stress (y-component) [N/m2]
integer :: i_humi = 5 ! index of specific humidity [kg/kg]
integer :: i_qsr = 6 ! index of solar heat [W/m2]
integer :: i_qlw = 7 ! index of Long wave [W/m2]
integer :: i_tair = 8 ! index of 2m air temperature [degK]
integer :: i_prec = 9 ! index of total precipitation (rain+snow) [Kg/m^2/s]
integer :: i_mslp = 10 ! index of mean sea level pressure [Pascals]
integer :: i_cloud = 11 ! index of mean sea level pressure [0-1]
integer :: i_snow = 12 ! index of mean sea level pressure [Kg/m^2/s]
logical :: l_totfl = .false.
logical :: l_xwind = .false.
logical :: l_ywind = .false.
logical :: l_xstre = .false.
logical :: l_ystre = .false.
logical :: l_humi = .false.
logical :: l_qsr = .false.
logical :: l_qlw = .false.
logical :: l_tair = .false.
logical :: l_prec = .false.
logical :: l_mslp = .false.
logical :: l_cloud = .false.
logical :: l_snow = .false.
character(10), save :: runoff_data_source ='CORE2'
character(len=MAX_PATH), save :: nm_runoff_file ='runoff.nc'
character(10), save :: sss_data_source ='CORE2'
character(len=MAX_PATH), save :: nm_sss_data_file ='PHC2_salx.nc'
character(10), save :: chl_data_source ='None' ! 'Sweeney' Chlorophyll climatology Sweeney et al. 2005
character(len=MAX_PATH), save :: nm_chl_data_file ='/work/ollie/dsidoren/input/forcing/Sweeney_2005.nc'
real(wp), save :: chl_const = 0.1
#if defined (__recom)
character(10), save :: fe_data_source ='Albani'
character(len=MAX_PATH), save :: nm_fe_data_file ='DustClimMonthlyAlbani.nc'
character(len=MAX_PATH), save :: nm_aen_data_file ='AeolianNitrogenDep.nc '
character(len=MAX_PATH), save :: nm_river_data_file ='River.nc'
character(len=MAX_PATH), save :: nm_erosion_data_file ='Erosion.nc'
character(len=MAX_PATH), save :: nm_co2_data_file ='MonthlyAtmCO2_gcb2021.nc'
character(len=MAX_PATH), save :: nm_sed_data_file ='medusa_flux2fesom.nc'
#endif
logical :: use_runoff_mapper = .false. !runof mapper to be used in the coupled mode with IFS
character(len=MAX_PATH), save :: runoff_basins_file='runoff_basins.nc' ! definition file for runoff basins
real(wp) :: runoff_radius =500000._WP !smoothing radius for runoff mapper (in meters)
type(sparse_matrix) :: RUNOFF_MAPPER
logical :: runoff_climatology =.false.
real(wp), allocatable, save, dimension(:), public :: qns ! downward non solar heat over the ocean [W/m2]
real(wp), allocatable, save, dimension(:), public :: qsr ! downward solar heat over the ocean [W/m2]
real(wp), allocatable, save, dimension(:), public :: emp ! evaporation minus precipitation [kg/m2/s]
real(4), allocatable, dimension(:,:), private, save, target :: sbcdata1_,sbcdata2_
! real(wp), allocatable, save, dimension(:), public :: qns_2 ! downward non solar heat over the ocean [W/m2]
! real(wp), allocatable, save, dimension(:), public :: qsr_2 ! downward solar heat over the ocean [W/m2]
! real(wp), allocatable, save, dimension(:), public :: emp_2 ! evaporation minus precipitation [kg/m2/s]
! real(wp), allocatable, save, dimension(:), public :: taux_node_2 ! wind at 10m [m/s]
! real(wp), allocatable, save, dimension(:), public :: tauy_node_2 ! wind at 10m [m/s]
! windx and windy are defined in fv_var and allocated in main
! real(wp), allocatable, save, dimension(:), public :: windx ! wind at 10m [m/s]
! real(wp), allocatable, save, dimension(:), public :: windy ! wind at 10m [m/s]
! mslp now defined in fv_var and allocated in main module
! real(wp), allocatable, save, dimension(:), public :: mslp ! mean sea level pressure [Pascals]
!
! namelists
integer, save :: nm_sbc_unit = 103 ! unit to open namelist file, skip 100-102 for cray fortran
logical :: ic_cyclic=.true.
!============== namelistatmdata variables ================
character(len=256), save :: nm_xwind_file = 'xwind.dat' ! name of file with winds, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_ywind_file = 'ywind.dat' ! name of file with winds, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_xstre_file = 'xstre.dat' ! name of file with stress, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_ystre_file = 'ystre.dat' ! name of file with stress, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_humi_file = 'humidity.dat' ! name of file with humidity, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_qsr_file = 'qsr.dat' ! name of file with solar heat, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_qlw_file = 'qlw.dat' ! name of file with Long wave, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_tair_file = 'tair.dat' ! name of file with 2m air temperature, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_prec_file = 'prec.dat' ! name of file with total precipitation, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_snow_file = 'snow.dat' ! name of file with snow precipitation, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_mslp_file = 'mslp.dat' ! name of file with mean sea level pressure, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=256), save :: nm_cloud_file = 'cloud.dat' ! name of file with clouds, if netcdf file then provide only name from "nameyyyy.nc" yyyy.nc will be added by model
character(len=34), save :: nm_xwind_var = 'uwnd' ! name of variable in file with wind
character(len=34), save :: nm_ywind_var = 'vwnd' ! name of variable in file with wind
character(len=34), save :: nm_xstre_var = 'xstr' ! name of variable in file with wind stress
character(len=34), save :: nm_ystre_var = 'ystr' ! name of variable in file with wind stress
character(len=34), save :: nm_humi_var = 'shum' ! name of variable in file with humidity
character(len=34), save :: nm_qsr_var = 'dswrf'! name of variable in file with solar heat
character(len=34), save :: nm_qlw_var = 'dlwrf'! name of variable in file with Long wave
character(len=34), save :: nm_tair_var = 'air' ! name of variable in file with 2m air temperature
character(len=34), save :: nm_prec_var = 'prate'! name of variable in file with total precipitation
character(len=34), save :: nm_snow_var = 'snow' ! name of variable in file with snow precipitation
character(len=34), save :: nm_mslp_var = 'mslp' ! name of variable in file with mean sea level pressure
character(len=34), save :: nm_cloud_var = 'cloud'! name of variable in file with clouds
! ========== netCDF time param
integer, save :: nm_nc_iyear = 1948 ! initial year of time axis in netCDF (1948 like CoastDat,1800 NCEP)
integer, save :: nm_nc_imm = 1 ! initial month of time axis in netCDF
integer, save :: nm_nc_idd = 1 ! initial day of time axis in netCDF
real, save :: nm_nc_freq = 86400.0 ! time units coef (86400 CoastDat, 24 NCEP)
integer, save :: nm_nc_tmid = 1 ! 1 if the time stamps are given at the mid points of the netcdf file, 0 otherwise!
logical, save :: y_perpetual=.false.
integer,save :: warn ! warning switch node/element coordinate out of forcing bounds
real(wp), allocatable, save, dimension(:,:) :: coef_b ! time inerp coef. b (x=a*t+b)
real(wp), allocatable, save, dimension(:,:) :: coef_a ! time inerp coef. a (x=a*t+b)
real(wp), allocatable, save, dimension(:,:) :: atmdata ! atmosperic data for current time step
type, public :: flfi_type !flux file informations
character(len = MAX_PATH) :: file_name ! file name
character(len = 34) :: var_name ! variable name in the NetCDF file
character(len = 34) :: calendar ! variable name in the NetCDF file
integer :: year_orig ! year according to original time axis
integer :: year ! year according to filename year!=year_orig in case of linked forcing
integer :: nc_Nlon
integer :: nc_Nlat
integer :: nc_Ntime
real(wp), allocatable, dimension(:) :: nc_lon, nc_lat, nc_time
! time index for NC time array
integer :: t_indx ! now time index in nc_time array
integer :: t_indx_p1 ! now time index +1 in nc_time array
integer read_forcing_rootrank
logical async_netcdf_allowed
real(4), allocatable, dimension(:,:) :: sbcdata_a
integer sbcdata_a_t_index
real(4), allocatable, dimension(:,:) :: sbcdata_b
integer sbcdata_b_t_index
! ========== interpolation coeficients
end type flfi_type
type(flfi_type), allocatable, save, target :: sbc_flfi(:) !array for information about flux files
integer, allocatable, dimension(:,:) :: bilin_indx_i ! indexs i for interpolation
integer, allocatable, dimension(:,:) :: bilin_indx_j ! indexs j for interpolation
!flip latitude from infiles (for example NCEP-DOE Reanalysis 2 standart)
integer, save :: flip_lat ! 1 if we need to flip
!============== NETCDF ==========================================
CONTAINS
SUBROUTINE nc_readTimeGrid(flf, partit)
! Read time array and grid from nc file
IMPLICIT NONE
type(flfi_type),intent(inout) :: flf
type(t_partit), intent(inout), target :: partit
integer :: iost !I/O status
integer :: ncid ! netcdf file id
integer :: i
! ID dimensions and variables:
integer :: id_lon
integer :: id_lat
integer :: id_lond
integer :: id_latd
integer :: id_time
integer :: id_timed
integer :: nf_start(4)
integer :: nf_edges(4)
integer :: ierror ! return error code
character(len=20) :: aux_calendar
integer :: aux_len
integer :: yyyy, mm, dd
!open file
if (partit%mype==0) then
iost = nf90_open(trim(flf%file_name), NF90_NOWRITE, ncid)
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
! get dimensions
if (partit%mype==0) then
iost = nf90_inq_dimid(ncid, "LAT", id_latd)
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_dimid(ncid, "lat", id_latd)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_dimid(ncid, "latitude", id_latd)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_dimid(ncid, "LAT1", id_latd)
end if
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
if (partit%mype==0) then
iost = nf90_inq_dimid(ncid, "LON", id_lond)
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_dimid(ncid, "lon", id_lond)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_dimid(ncid, "longitude", id_lond)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_dimid(ncid, "LON1", id_lond)
end if
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
if (partit%mype==0) then
iost = nf90_inq_dimid(ncid, "TIME", id_timed)
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_dimid(ncid, "time", id_timed)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_dimid(ncid, "TIME1", id_timed)
end if
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
! get variable id
if (partit%mype==0) then
iost = nf90_inq_varid(ncid, "LAT", id_lat)
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_varid(ncid, "lat", id_lat)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_varid(ncid, "latitude", id_lat)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_varid(ncid, "LAT1", id_lat)
end if
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
if (partit%mype==0) then
iost = nf90_inq_varid(ncid, "LON", id_lon)
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_varid(ncid, "longitude", id_lon)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_varid(ncid, "lon", id_lon)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_varid(ncid, "LON1", id_lon)
end if
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
if (partit%mype==0) then
iost = nf90_inq_varid(ncid, "TIME", id_time)
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_varid(ncid, "time", id_time)
end if
if (iost .ne. NF90_NOERR) then
iost = nf90_inq_varid(ncid, "TIME1", id_time)
end if
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
! get dimensions size
if (partit%mype==0) then
iost = nf90_inquire_dimension(ncid, id_latd, len=flf%nc_Nlat)
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
if (partit%mype==0) then
iost = nf90_inquire_dimension(ncid, id_lond, len=flf%nc_Nlon)
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
if (partit%mype==0) then
iost = nf90_inquire_dimension(ncid, id_timed, len=flf%nc_Ntime)
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
flf%nc_Nlon=flf%nc_Nlon+2 !for the halo in case of periodic boundary
call MPI_BCast(flf%nc_Nlon, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call MPI_BCast(flf%nc_Nlat, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call MPI_BCast(flf%nc_Ntime, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
if (.not. allocated(flf%nc_time)) then
allocate( flf%nc_lon(flf%nc_Nlon), flf%nc_lat(flf%nc_Nlat),&
& flf%nc_time(flf%nc_Ntime))
else
! only the temporal axis is allowed to vary between the files
deallocate(flf%nc_time)
allocate(flf%nc_time(flf%nc_Ntime))
end if
!____________________________________________________________________________
!read variables from file
! read lat
if (partit%mype==0) then
iost = nf90_get_var(ncid, id_lat, flf%nc_lat, start=(/1/), count=(/flf%nc_Nlat/))
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
! read lon
if (partit%mype==0) then
iost = nf90_get_var(ncid, id_lon, flf%nc_lon(2:flf%nc_Nlon-1), start=(/1/), count=(/flf%nc_Nlon-2/))
flf%nc_lon(1) =flf%nc_lon(flf%nc_Nlon-1)
flf%nc_lon(flf%nc_Nlon) =flf%nc_lon(2)
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
!____________________________________________________________________________
! read time axis from file
if (partit%mype==0) then
iost = nf90_get_var(ncid, id_time, flf%nc_time, start=(/1/), count=(/flf%nc_Ntime/))
! digg for calendar attribute in time axis variable
end if
call MPI_BCast(flf%nc_time, flf%nc_Ntime, MPI_DOUBLE_PRECISION, 0, partit%MPI_COMM_FESOM, ierror)
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
! digg for calendar attribute in time axis variable
if (partit%mype==0) then
iost = nf90_inquire_attribute(ncid, id_time, 'calendar', len=aux_len)
iost = nf90_get_att(ncid, id_time, 'calendar', aux_calendar)
aux_calendar = aux_calendar(1:aux_len)
if (iost .ne. NF90_NOERR) then
flf%calendar='none'
write(*,*) ' --> could not find/read calendar attribute in the time axis'
write(*,*) ' of the forcing file (Is this right?). I assume there is'
write(*,*) ' none and proceed in CORE2 style without leap years!'
else
flf%calendar=lowercase(aux_calendar)
write(*,*) ' --> found calendar attr. in time axis: |',trim(flf%calendar),'|'
end if
end if ! --> if (partit%mype==0) then
! distribute calender option to other cpus
call MPI_BCast(flf%calendar, len(flf%calendar), MPI_CHARACTER, 0, partit%MPI_COMM_FESOM, ierror)
if (partit%mype==0 .and. use_flpyrcheck) then
! check for calendar and include_fleapyear consistency
if ((trim(flf%calendar).eq.'none') .or. &
(trim(flf%calendar).eq.'noleap') .or. &
(trim(flf%calendar).eq.'365_days')) then
if (include_fleapyear .eqv. .true.) then
print *, achar(27)//'[33m'
write(*,*) '____________________________________________________________'
write(*,*) ' WARNING: It looks like you want to use CORE forcing, Right?'
write(*,*) ' but setted include_fleapyear=.true.. CORE forcing '
write(*,*) ' does not contain any leap years or particular '
write(*,*) ' calender option (julian, gregorian). So if im right,'
write(*,*) ' please go to namelist.config and set '
write(*,*) ' include_fleapyear=.false. otherwise comment this '
write(*,*) ' message block in gen_surface_forcing.F90.'
write(*,*) '____________________________________________________________'
print *, achar(27)//'[0m'
call par_ex(partit%MPI_COMM_FESOM, partit%mype, 0)
end if
elseif ((trim(flf%calendar).eq.'julian') .or. &
(trim(flf%calendar).eq.'gregorian') .or. &
(trim(flf%calendar).eq.'proleptic_gregorian') .or. &
(trim(flf%calendar).eq.'standard')) then
if (include_fleapyear .eqv. .false.) then
print *, achar(27)//'[33m'
write(*,*) '____________________________________________________________'
write(*,*) ' WARNING: It looks like you want to use either JRA55, ERA,'
write(*,*) ' NCEP or a similar forcing, Right?, but setted '
write(*,*) ' include_fleapyear=.false. JRA55, ERA or NCEP contain'
write(*,*) ' all fleapyears and use a specific calendar option '
write(*,*) ' (julian, gregorian). So that the calendars in FESOM2.0'
write(*,*) ' work properly, when using these forcings '
write(*,*) ' include_fleapyear must be true. So if im right, please go'
write(*,*) ' to namelist.config and set include_fleapyear=.true. '
write(*,*) ' otherwise comment this message block in'
write(*,*) ' gen_surface_forcing.F90'
write(*,*) '____________________________________________________________'
print *, achar(27)//'[0m'
call par_ex(partit%MPI_COMM_FESOM, partit%mype, 0)
end if
else
print *, achar(27)//'[31m'
write(*,*) '____________________________________________________________'
write(*,*) ' ERROR: I am not familiar with the found calendar option,'
write(*,*) ' dont know what to do. Either talk to the FESOM2 developers'
write(*,*) ' or add the calendar option by your self in ...'
write(*,*) ' gen_surface_forcing.F90, line:364-367'
write(*,*) ' '
write(*,*) ' elseif ((trim(flf%calendar).eq."julian") .or. &'
write(*,*) ' (trim(flf%calendar).eq."gregorian") .or. &'
write(*,*) ' (trim(flf%calendar).eq."NEW_CALENDAR").or. &'
write(*,*) ' (trim(flf%calendar).eq."standard")) then '
write(*,*) ' '
write(*,*) ' The time axis calendar attribute can be checked for '
write(*,*) ' example with ncdump -h forcing_file.nc '
write(*,*) '____________________________________________________________'
print *, achar(27)//'[0m'
call par_ex(partit%MPI_COMM_FESOM, partit%mype, 0)
end if ! --> if ((trim(flf%calendar).eq.'none') .or. & ...
end if !--> if (partit%mype==0 .and. use_flpyrcheck) then
! transfer time-axis of the forcing files in units of days
flf%nc_time = flf%nc_time / nm_nc_freq
! add the original reference period (1900-01-01(JRA55) to 0000-01-01) of the
! forcing file in units of days --> new reference period 0001-01-01
flf%nc_time = flf%nc_time + julday(nm_nc_iyear, nm_nc_imm, nm_nc_idd, trim(flf%calendar))
! Solve special problem here: Ozgurs wants to repeat only part of the JRA55
! forcing periodically (e.g repeat the period 1958-1967) through re-linking
! of the original forcing files.
!
! 1st problem: This will mess up the leap year cycle of the entire forcing, so
! the model has to run best without leapyear although the calendar
! system of the forcing remains gregorian (so with leapyear)
! This can be solved by makeing the treatment of the time-axes
! depending on the calendar of the forcing files, not alone from
! the include_fleapyear flag
!
! 2nd problem: In the case of a periodically repeated forcing period through
! re-linking of the original files it happens that e.g. the year
! 1968 is linked to the file 1958 in that case time axis of the
! 1968 forcing file remains that of the original 1958 file. So
! axis needs to be resetted properly
call calendar_date(int(flf%nc_time(1)), yyyy, mm, dd, trim(flf%calendar))
! remove the reference period of the original file
flf%year_orig = yyyy
flf%nc_time = flf%nc_time - julday(yyyy , 1, 1, trim(flf%calendar))
! reset the reference period to the proper year it should represent
flf%year = yearnew
flf%nc_time = flf%nc_time + julday(yearnew, 1, 1, trim(flf%calendar))
if (nm_nc_tmid/=1) then
if (flf%nc_Ntime > 1) then
do i = 1, flf%nc_Ntime-1
flf%nc_time(i) = (flf%nc_time(i+1) + flf%nc_time(i))/2.0_WP
end do
flf%nc_time(flf%nc_Ntime) = flf%nc_time(flf%nc_Ntime) + (flf%nc_time(flf%nc_Ntime) - flf%nc_time(flf%nc_Ntime-1))/2.0
end if
end if
call MPI_BCast(flf%nc_lon, flf%nc_Nlon, MPI_DOUBLE_PRECISION, 0, partit%MPI_COMM_FESOM, ierror)
call MPI_BCast(flf%nc_lat, flf%nc_Nlat, MPI_DOUBLE_PRECISION, 0, partit%MPI_COMM_FESOM, ierror)
!___________________________________________________________________________
!flip lat and data in case of lat from -90 to 90
!!!! WARNING this is temporal solution, needs some more checks
flip_lat = 0
if ( flf%nc_Nlat > 1 ) then
if ( flf%nc_lat(1) > flf%nc_lat(flf%nc_Nlat) ) then
flip_lat = 1
flf%nc_lat=flf%nc_lat(flf%nc_Nlat:1:-1)
if (partit%mype==0) write(*,*) "fv_sbc: nc_readTimeGrid: FLIP lat and data while lat from -90 to 90"
endif
endif
if (partit%mype==0) then
iost = nf90_close(ncid)
end if
call MPI_BCast(iost, 1, MPI_INTEGER, 0, partit%MPI_COMM_FESOM, ierror)
call check_nferr(iost,flf%file_name,partit)
if (ic_cyclic) then
flf%nc_lon(1) =flf%nc_lon(1)-360._WP
flf%nc_lon(flf%nc_Nlon)=flf%nc_lon(flf%nc_Nlon)+360._WP
end if
END SUBROUTINE nc_readTimeGrid
SUBROUTINE nc_sbc_ini_fillnames(yyyy)
integer, intent(in) :: yyyy
character(len=4) :: yyear
write(yyear,"(I4)") yyyy
if (y_perpetual) yyear = ''
!! ** Purpose : Fill names of sbc_flfi array (file names and variable names)
!prepare proper nc file (add year and .nc to the end of the file name from namelist
if (l_xwind) write(sbc_flfi(i_xwind)%file_name, *) trim(make_full_path(nm_xwind_file)),trim(yyear),'.nc'
if (l_ywind) write(sbc_flfi(i_ywind)%file_name, *) trim(make_full_path(nm_ywind_file)),trim(yyear),'.nc'
if (l_xstre) write(sbc_flfi(i_xstre)%file_name, *) trim(make_full_path(nm_xstre_file)),trim(yyear),'.nc'
if (l_ystre) write(sbc_flfi(i_ystre)%file_name, *) trim(make_full_path(nm_ystre_file)),trim(yyear),'.nc'
if (l_humi) write(sbc_flfi(i_humi)%file_name, *) trim(make_full_path(nm_humi_file)), trim(yyear),'.nc'
if (l_qsr) write(sbc_flfi(i_qsr)%file_name, *) trim(make_full_path(nm_qsr_file)), trim(yyear),'.nc'
if (l_qlw) write(sbc_flfi(i_qlw)%file_name, *) trim(make_full_path(nm_qlw_file)), trim(yyear),'.nc'
if (l_tair) write(sbc_flfi(i_tair)%file_name, *) trim(make_full_path(nm_tair_file)), trim(yyear),'.nc'
if (l_prec) write(sbc_flfi(i_prec)%file_name, *) trim(make_full_path(nm_prec_file)), trim(yyear),'.nc'
if (l_snow) write(sbc_flfi(i_snow)%file_name, *) trim(make_full_path(nm_snow_file)), trim(yyear),'.nc'
if (l_mslp) write(sbc_flfi(i_mslp)%file_name, *) trim(make_full_path(nm_mslp_file)), trim(yyear),'.nc'
if (l_cloud) write(sbc_flfi(i_cloud)%file_name, *) trim(make_full_path(nm_cloud_file)),trim(yyear),'.nc'
if (l_xwind) sbc_flfi(i_xwind)%file_name=ADJUSTL(trim(sbc_flfi(i_xwind)%file_name))
if (l_ywind) sbc_flfi(i_ywind)%file_name=ADJUSTL(trim(sbc_flfi(i_ywind)%file_name))
if (l_xstre) sbc_flfi(i_xstre)%file_name=ADJUSTL(trim(sbc_flfi(i_xstre)%file_name))
if (l_ystre) sbc_flfi(i_ystre)%file_name=ADJUSTL(trim(sbc_flfi(i_ystre)%file_name))
if (l_humi) sbc_flfi(i_humi)%file_name=ADJUSTL(trim(sbc_flfi(i_humi)%file_name))
if (l_qsr) sbc_flfi(i_qsr)%file_name=ADJUSTL(trim(sbc_flfi(i_qsr)%file_name))
if (l_qlw) sbc_flfi(i_qlw)%file_name=ADJUSTL(trim(sbc_flfi(i_qlw)%file_name))
if (l_tair) sbc_flfi(i_tair)%file_name=ADJUSTL(trim(sbc_flfi(i_tair)%file_name))
if (l_prec) sbc_flfi(i_prec)%file_name=ADJUSTL(trim(sbc_flfi(i_prec)%file_name))
if (l_snow) sbc_flfi(i_snow)%file_name=ADJUSTL(trim(sbc_flfi(i_snow)%file_name))
if (l_mslp) sbc_flfi(i_mslp)%file_name=ADJUSTL(trim(sbc_flfi(i_mslp)%file_name))
if (l_cloud) sbc_flfi(i_cloud)%file_name=ADJUSTL(trim(sbc_flfi(i_cloud)%file_name))
if (l_xwind) sbc_flfi(i_xwind)%var_name=ADJUSTL(trim(nm_xwind_var))
if (l_ywind) sbc_flfi(i_ywind)%var_name=ADJUSTL(trim(nm_ywind_var))
if (l_xstre) sbc_flfi(i_xstre)%var_name=ADJUSTL(trim(nm_xstre_var))
if (l_ystre) sbc_flfi(i_ystre)%var_name=ADJUSTL(trim(nm_ystre_var))
if (l_humi) sbc_flfi(i_humi)%var_name=ADJUSTL(trim(nm_humi_var))
if (l_qsr) sbc_flfi(i_qsr)%var_name=ADJUSTL(trim(nm_qsr_var))
if (l_qlw) sbc_flfi(i_qlw)%var_name=ADJUSTL(trim(nm_qlw_var))
if (l_tair) sbc_flfi(i_tair)%var_name=ADJUSTL(trim(nm_tair_var))
if (l_prec) sbc_flfi(i_prec)%var_name=ADJUSTL(trim(nm_prec_var))
if (l_snow) sbc_flfi(i_snow)%var_name=ADJUSTL(trim(nm_snow_var))
if (l_mslp) sbc_flfi(i_mslp)%var_name=ADJUSTL(trim(nm_mslp_var))
if (l_cloud) sbc_flfi(i_cloud)%var_name=ADJUSTL(trim(nm_cloud_var))
END SUBROUTINE nc_sbc_ini_fillnames
function make_full_path(filename) result(full_path)
character(len=*), intent(in) :: filename
character(len=MAX_PATH) :: full_path
if (len_trim(filename) > 0 .and. filename(1:1) /= '/') then
! Relative path - prepend ClimateDataPath
full_path = trim(ClimateDataPath) // trim(filename)
else
! Absolute path or empty - use as is
full_path = filename
endif
end function make_full_path
SUBROUTINE nc_sbc_ini(partit, mesh)
!!---------------------------------------------------------------------
!! ** Purpose : initialization of ocean forcing from NETCDF file
!!----------------------------------------------------------------------
IMPLICIT NONE
real(wp) :: rdate ! initialization date
integer :: yyyy,mm,dd
integer :: i
integer :: sbc_alloc
logical, save :: lfirst=.true.
integer :: elnodes(4) !4 nodes from one element
integer :: numnodes ! nu,ber of nodes in elem (3 for triangle, 4 for ... )
real(wp) :: x, y ! coordinates of elements
integer :: fld_idx
type(flfi_type), pointer :: flf
type(t_mesh), intent(in), target :: mesh
type(t_partit), intent(inout), target :: partit
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
! used for interpolate on elements
! ALLOCATE( bilin_indx_i(elem2D),bilin_indx_j(elem2D), &
! & qns(elem2D), emp(elem2D), qsr(elem2D), &
! & STAT=sbc_alloc )
! used to inerpolate on nodes
warn = 0
! get ini year; Fill names of sbc_flfi
call nc_sbc_ini_fillnames(yearnew)
! we assume that all NetCDF files have identical grid and time variable
do fld_idx = 1, i_totfl
call nc_readTimeGrid(sbc_flfi(fld_idx), partit)
end do
! compute model rdate at initial moment
rdate = real(julday(yearnew, 1, 1, sbc_flfi(1)%calendar ))
rdate = rdate+real(daynew-1,WP)+timenew/86400._WP
if (lfirst) then
do fld_idx = 1, i_totfl
flf=>sbc_flfi(fld_idx)
! prepare nearest coordinates in INfile , save to bilin_indx_i/j
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i, x, y)
!$OMP DO REDUCTION(max: warn)
do i = 1, myDim_nod2D+eDim_nod2D
x = geo_coord_nod2D(1,i)/rad
if (x < 0) x=x+360._WP
y = geo_coord_nod2D(2,i)/rad
! find nearest
if ( x < flf%nc_lon(flf%nc_Nlon) .and. x >= flf%nc_lon(1) ) then
call binarysearch(flf%nc_Nlon, flf%nc_lon, x, bilin_indx_i(fld_idx, i))
else ! NO extrapolation in space
if ( x < flf%nc_lon(1) ) then
bilin_indx_i(fld_idx, i)=-1
else
bilin_indx_i(fld_idx, i)=0
end if
end if
if ( y < flf%nc_lat(flf%nc_Nlat) .and. y >= flf%nc_lat(1) ) then
call binarysearch(flf%nc_Nlat, flf%nc_lat, y, bilin_indx_j(fld_idx, i))
else ! NO extrapolation in space
if ( y < flf%nc_lat(1) ) then
bilin_indx_j(fld_idx, i)=-1
else
bilin_indx_j(fld_idx, i)=0
end if
end if
if (warn == 0) then
if (bilin_indx_i(fld_idx, i) < 1 .or. bilin_indx_j(fld_idx, i) < 1) then
! WRITE(*,*) ' WARNING: node/element coordinate out of forcing bounds,'
! WRITE(*,*) ' nearest value will be used as a constant field'
warn = 1
end if
end if
end do
!$OMP END DO
!$OMP END PARALLEL
end do
lfirst=.false.
end if
do fld_idx = 1, i_totfl
! get first coefficients for time interpolation on model grid for all data
call getcoeffld(fld_idx, rdate, partit, mesh)
end do
! interpolate in time
!!PS if (partit%mype==0) then
!!PS write(*,*) 'sbc_do --> mstep:',mstep, ' rdate=', rdate
!!PS end if
call data_timeinterp(rdate, partit)
END SUBROUTINE nc_sbc_ini
SUBROUTINE getcoeffld(fld_idx, rdate, partit, mesh)
use forcing_provider_async_module
use io_netcdf_workaround_module
use g_clock
!!---------------------------------------------------------------------
!! *** ROUTINE getcoeffld ***
!!
!! ** Purpose : read fields from files, interpolate on model mesh and prepare interpolation coefficients
!! ** Method :
!! ** Action :
!!----------------------------------------------------------------------
IMPLICIT NONE
type(t_mesh), intent(in), target :: mesh
type(t_partit), intent(inout), target :: partit
integer, intent(in) :: fld_idx
real(wp),intent(in) :: rdate ! initialization date
integer :: iost !I/O status
integer :: ncid ! netcdf file id
! ID dimensions and variables:
integer :: id_data
integer :: nf_start(4)
integer :: nf_edges(4)
! integer :: zero_year,yyyy,mm,dd
! character(len = 256) :: att_string ! attribute
integer :: i,j,ii, ip1, jp1, extrp
integer :: sbc_alloc, itot
real(wp) :: denom, x1, x2, y1, y2, x, y
real(wp) :: now_date
! real(wp), allocatable, dimension(:,:) :: sbcdata1,sbcdata2
real(wp) :: data1,data2
real(wp) :: delta_t ! time(t_indx) - time(t_indx+1)
real(wp) :: rdatep1 ! time(t_indx) - time(t_indx+1)
integer :: elnodes(4) !4 nodes from one element
integer :: numnodes ! nu,ber of nodes in elem (3 for triangle, 4 for ... )
integer :: yyyy, mm, dd, flag_flpyr=0
integer :: ierror ! return error code
integer, pointer :: nc_Ntime, nc_Nlon, nc_Nlat, t_indx, t_indx_p1
character(len=MAX_PATH), pointer :: file_name
character(len=34) , pointer :: var_name
real(wp), pointer :: nc_time(:), nc_lon(:), nc_lat(:)
real(4), dimension(:,:), pointer :: sbcdata1, sbcdata2
logical sbcdata1_from_cache, sbcdata2_from_cache
integer rootrank
#include "associate_part_def.h"
#include "associate_mesh_def.h"
#include "associate_part_ass.h"
#include "associate_mesh_ass.h"
! fld_idx determines which ouf our forcing fields we use here
nc_Ntime =>sbc_flfi(fld_idx)%nc_Ntime
nc_Nlon =>sbc_flfi(fld_idx)%nc_Nlon
nc_Nlat =>sbc_flfi(fld_idx)%nc_Nlat
t_indx =>sbc_flfi(fld_idx)%t_indx
t_indx_p1=>sbc_flfi(fld_idx)%t_indx_p1
file_name=>sbc_flfi(fld_idx)%file_name
var_name =>sbc_flfi(fld_idx)%var_name
nc_time =>sbc_flfi(fld_idx)%nc_time
nc_lon =>sbc_flfi(fld_idx)%nc_lon
nc_lat =>sbc_flfi(fld_idx)%nc_lat
if(.not. allocated(sbc_flfi(fld_idx)%sbcdata_a)) then
allocate(sbc_flfi(fld_idx)%sbcdata_a(nc_Nlon,nc_Nlat))
sbc_flfi(fld_idx)%sbcdata_a_t_index = -1
allocate(sbc_flfi(fld_idx)%sbcdata_b(nc_Nlon,nc_Nlat))
sbc_flfi(fld_idx)%sbcdata_b_t_index = -1
sbc_flfi(fld_idx)%read_forcing_rootrank = next_io_rank(MPI_COMM_FESOM, sbc_flfi(fld_idx)%async_netcdf_allowed, partit)
end if
rootrank = sbc_flfi(fld_idx)%read_forcing_rootrank
! no initialization of sbcdata required, the whole array will be overwritten anyway
! find time index in files
now_date = rdate
call binarysearch(nc_Ntime,nc_time,now_date,t_indx)
if ( (t_indx < nc_Ntime) .and. (t_indx > 0) ) then
t_indx_p1 = t_indx + 1
delta_t = nc_time(t_indx_p1) - nc_time(t_indx)
!_______________________________________________________________________
! if include_fleapyear==.False. and forcing file of year contains a fleap
! year, try to step over the 29.Feb so it is not used for temporal
! interpolation
if ((include_fleapyear .eqv. .False.) .and. &
((trim(sbc_flfi(fld_idx)%calendar).eq.'julian' ) .or. &
(trim(sbc_flfi(fld_idx)%calendar).eq.'gregorian' ) .or. &
(trim(sbc_flfi(fld_idx)%calendar).eq.'proleptic_gregorian') .or. &
(trim(sbc_flfi(fld_idx)%calendar).eq.'standard' ))) then
! Need to know what is the original year of the forcing file. In case of
! ozgures problem where forcing files get re-linked it can happen that
! non-leapyears are represented by a leapyear file thus the indexing
! and counting needs to be adapted
! --> sbc_flfi(fld_idx)%year_orig ... year according to original time axis
! --> sbc_flfi(fld_idx)%year ... year according to filename
call is_fleapyr(sbc_flfi(fld_idx)%year_orig, flag_flpyr)
! here skip the 29.Feb in the counting
! go from 28.Feb directly to 1.Mar for the case the forcing file contains
! a leapyear.
if (flag_flpyr==1) then
! skip the 29. Feb if the model finds one in the forcing data
call calendar_date(int(nc_time(t_indx_p1)), yyyy, mm, dd, sbc_flfi(fld_idx)%calendar )
if (mm==2 .and. dd==29) then
! --> go directly to the first time slice what represents the
! 1. March
rdatep1 = real(julday(yearnew,1,1, sbc_flfi(fld_idx)%calendar ),WP)
rdatep1 = rdatep1+real(60,WP) + delta_t*0.5_WP
call binarysearch(nc_Ntime, nc_time, rdatep1, t_indx_p1)
delta_t = nc_time(t_indx_p1) - nc_time(t_indx)
if (partit%mype==0 .and. fld_idx==1) then
call calendar_date(int(nc_time(t_indx_p1)), yyyy, mm, dd, sbc_flfi(fld_idx)%calendar )
write(*,*) ' --> jump over 29. Feb, now : yy, mm, dd = ', yyyy, mm, dd
end if
end if
end if
end if
elseif (t_indx > 0) then ! NO extrapolation to future
t_indx = nc_Ntime
t_indx_p1 = t_indx
delta_t = 1.0_wp
if (mype==0) then
write(*,*) 'WARNING: no temporal extrapolation into future (nearest neighbour is used): ', trim(var_name), ' !'
write(*,*) trim(file_name)
write(*,*) nc_time(1), nc_time(nc_Ntime), now_date
end if
elseif (t_indx < 1) then ! NO extrapolation back in time
t_indx = 1
t_indx_p1 = t_indx
delta_t = 1.0_wp
if (mype==0) then
write(*,*) 'WARNING: no temporal extrapolation back in time (nearest neighbour is used): ', trim(var_name), ' !'
write(*,*) trim(file_name)
write(*,*) nc_time(1), nc_time(nc_Ntime), now_date
end if
end if
! determine if we can use the broadcast cache
if(yearold == yearnew) then ! todo: simplify if clause
if(sbc_flfi(fld_idx)%sbcdata_a_t_index == t_indx) then
sbcdata1_from_cache = .true.
sbcdata1 => sbc_flfi(fld_idx)%sbcdata_a
sbcdata2 => sbc_flfi(fld_idx)%sbcdata_b
sbc_flfi(fld_idx)%sbcdata_b_t_index = t_indx_p1
else if(sbc_flfi(fld_idx)%sbcdata_b_t_index == t_indx) then
sbcdata1_from_cache = .true.
sbcdata1 => sbc_flfi(fld_idx)%sbcdata_b
sbcdata2 => sbc_flfi(fld_idx)%sbcdata_a !
sbc_flfi(fld_idx)%sbcdata_a_t_index = t_indx_p1
else
sbcdata1_from_cache = .false.
sbcdata1 => sbc_flfi(fld_idx)%sbcdata_a
sbc_flfi(fld_idx)%sbcdata_a_t_index = t_indx
sbcdata2_from_cache = .false.
sbcdata2 => sbc_flfi(fld_idx)%sbcdata_b
sbc_flfi(fld_idx)%sbcdata_b_t_index = t_indx_p1
end if
else
sbcdata1_from_cache = .false.
sbcdata1 => sbc_flfi(fld_idx)%sbcdata_a
sbc_flfi(fld_idx)%sbcdata_a_t_index = t_indx
sbcdata2_from_cache = .false.
sbcdata2 => sbc_flfi(fld_idx)%sbcdata_b
sbc_flfi(fld_idx)%sbcdata_b_t_index = t_indx_p1
end if
sbcdata2_from_cache = .false.
iost = 0
!open file sbc_flfi
if (mype==0) then
!write(*,*) 'check: ', trim(file_name)
end if
!read data from file
if (mype==rootrank) then
nf_start(1)=1
nf_edges(1)=nc_Nlon-2
nf_start(2)=1
nf_edges(2)=nc_Nlat
nf_start(3)=t_indx
nf_edges(3)=1
if(.not. sbcdata1_from_cache) then
call forcing_provider%get_forcingdata(i_totfl, fld_idx, sbc_flfi(fld_idx)%async_netcdf_allowed, trim(file_name), yearnew, trim(var_name), t_indx, sbcdata1(2:nc_Nlon-1,1:nc_Nlat))
end if
iost = 0
end if
if(mype == rootrank) then
if(.not. sbcdata1_from_cache) then
sbcdata1(1, 1:nc_Nlat) = sbcdata1(nc_Nlon-1, 1:nc_Nlat)
sbcdata1(nc_Nlon,1:nc_Nlat) = sbcdata1(2, 1:nc_Nlat)
end if
end if
if(sbcdata1_from_cache) then ! use the cache instead of bcast
else
call MPI_BCast(sbcdata1(1:nc_Nlon,1:nc_Nlat), nc_Nlon*nc_Nlat, MPI_REAL, rootrank, MPI_COMM_FESOM, ierror)
end if
! read next time step in file (check for +1 done before)
if (mype==rootrank) then
nf_start(3)=t_indx_p1
nf_edges(3)=1
if(.not. sbcdata2_from_cache) then
call forcing_provider%get_forcingdata(i_totfl, fld_idx, sbc_flfi(fld_idx)%async_netcdf_allowed, trim(file_name), yearnew, trim(var_name), t_indx_p1, sbcdata2(2:nc_Nlon-1,1:nc_Nlat))
end if
iost = 0
end if
if (mype==rootrank) then
if(.not. sbcdata2_from_cache) then
sbcdata2(1, 1:nc_Nlat) = sbcdata2(nc_Nlon-1, 1:nc_Nlat)
sbcdata2(nc_Nlon, 1:nc_Nlat) = sbcdata2(2, 1:nc_Nlat)
end if
end if
if(sbcdata2_from_cache) then ! use the cache instead of bcast
!
else
call MPI_BCast(sbcdata2(1:nc_Nlon,1:nc_Nlat), nc_Nlon*nc_Nlat, MPI_REAL, rootrank, MPI_COMM_FESOM, ierror)
end if
! !flip data in case of lat from -90 to 90
! !!!! WARNING
! if ( flip_lat == 1 ) then
! sbcdata1=sbcdata1(1:nc_Nlon,nc_Nlat:1:-1)
! sbcdata2=sbcdata2(1:nc_Nlon,nc_Nlat:1:-1)
! end if
! bilinear space interpolation, and time interpolation ,
! data is assumed to be sampled on a regular grid
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(ii, i, j, ip1, jp1, x, y, extrp, x1, x2, y1, y2, denom, data1, data2)
do ii = 1, myDim_nod2D+eDim_nod2D
i = bilin_indx_i(fld_idx, ii)
j = bilin_indx_j(fld_idx, ii)
ip1 = i + 1
jp1 = j + 1
x = geo_coord_nod2D(1,ii)/rad
if (x < 0.0_WP) x=x+360._WP
y = geo_coord_nod2D(2,ii)/rad
extrp = 0
if ( i == 0 ) then
i = nc_Nlon
ip1 = i
extrp = extrp + 1
end if
if ( i == -1 ) then
i = 1
ip1 = i
extrp = extrp + 1
end if
if ( j == 0 ) then
j = nc_Nlat
jp1 = j
extrp = extrp + 2
end if
if ( j == -1 ) then
j = 1
jp1 = j
extrp = extrp + 2
end if
x1 = nc_lon(i)
x2 = nc_lon(ip1)
y1 = nc_lat(j)
y2 = nc_lat(jp1)
if ( extrp == 0 ) then
! if point inside forcing domain
denom = (x2 - x1)*(y2 - y1)
data1 = ( sbcdata1(i,j) * (x2-x)*(y2-y) + sbcdata1(ip1,j) * (x-x1)*(y2-y) + &
sbcdata1(i,jp1) * (x2-x)*(y-y1) + sbcdata1(ip1, jp1) * (x-x1)*(y-y1) ) / denom
data2 = ( sbcdata2(i,j) * (x2-x)*(y2-y) + sbcdata2(ip1,j) * (x-x1)*(y2-y) + &
sbcdata2(i,jp1) * (x2-x)*(y-y1) + sbcdata2(ip1, jp1) * (x-x1)*(y-y1) ) / denom
else if ( extrp == 1 ) then ! "extrapolation" in x direction
denom = (y2 - y1)
data1 = ( sbcdata1(i,j) * (y2-y) + sbcdata1(ip1, jp1) * (y-y1) ) / denom
data2 = ( sbcdata2(i,j) * (y2-y) + sbcdata2(ip1, jp1) * (y-y1) ) / denom
else if ( extrp == 2 ) then ! "extrapolation" in y direction
denom = (x2 - x1)
data1 = ( sbcdata1(i,j) * (x2-x) + sbcdata1(ip1, jp1) * (x-x1) ) / denom
data2 = ( sbcdata2(i,j) * (x2-x) + sbcdata2(ip1, jp1) * (x-x1) ) / denom
else if ( extrp == 3 ) then ! "extrapolation" in x and y direction
data1 = sbcdata1(i,j)
data2 = sbcdata2(i,j)
end if
! calculate new coefficients for interpolations
coef_a(fld_idx, ii) = ( data2 - data1 ) / delta_t !( nc_time(t_indx+1) - nc_time(t_indx) )
coef_b(fld_idx, ii) = data1 - coef_a(fld_idx, ii) * nc_time(t_indx)
end do
!$OMP END PARALLEL DO
END SUBROUTINE getcoeffld
SUBROUTINE data_timeinterp(rdate, partit)