-
Notifications
You must be signed in to change notification settings - Fork 14
/
write_data.F90
1615 lines (1434 loc) · 92.3 KB
/
write_data.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 write_data
use utils_mod
use program_setup, only: output_file
use datetime_module, only: datetime, timedelta, clock
use misc_definitions_module, only: PROJ_LC, PROJ_CASSINI
private
public :: write_to_file
contains
!> Write data on the target grid
!!
!!
!! @param[in] localpet ESMF local persistent execution thread
!! @author Larissa Reames CIWRO/NOAA/NSSL
subroutine write_to_file(localpet)
use esmf
use netcdf
use mpi
use program_setup, only: interp_diag, interp_hist, &
wrf_mod_vars, truelat1, truelat2, &
stand_lon, proj_code, map_proj_char, &
i_target, j_target, dx, &
ref_lat, ref_lon, pole_lat, &
pole_lon, missing_value
use model_grid, only: target_grid, &
ip1_target, jp1_target, &
nz_input, nzp1_input, &
nsoil_input, &
start_time, &
config_dt, &
strlen, valid_time, &
lsm_scheme, mp_scheme, &
conv_scheme, &
longitude_target_grid, &
latitude_target_grid, &
longitude_u_target_grid, &
latitude_u_target_grid, &
longitude_v_target_grid, &
latitude_v_target_grid, &
mapfac_m_target_grid, &
mapfac_u_target_grid, &
mapfac_v_target_grid, &
sina_target_grid, &
cosa_target_grid, &
zs_target_grid, &
hgt_target_grid, &
u_target_grid, &
v_target_grid, &
target_diag_bundle, &
n_diag_fields, &
target_hist_bundle_2d_patch, &
target_hist_bundle_2d_cons, &
target_hist_bundle_2d_nstd, &
target_hist_bundle_3d_nz, &
target_hist_bundle_3d_nzp1, &
target_hist_bundle_3d_vert, &
target_hist_bundle_soil, &
n_hist_fields_2d_patch, &
n_hist_fields_2d_cons, &
n_hist_fields_2d_nstd, &
n_hist_fields_3d_nz, &
n_hist_fields_3d_nzp1, &
n_hist_fields_3d_vert, &
n_hist_fields_soil, &
target_diag_units, &
target_hist_units_2d_cons, &
target_hist_units_2d_nstd, &
target_hist_units_2d_patch, &
target_hist_units_3d_nzp1, &
target_hist_units_3d_nz, &
target_hist_units_3d_vert, &
target_hist_units_soil, &
target_diag_longname, &
target_hist_longname_2d_cons, &
target_hist_longname_2d_nstd, &
target_hist_longname_2d_patch, &
target_hist_longname_3d_nzp1, &
target_hist_longname_3d_nz, &
target_hist_longname_3d_vert, &
target_hist_longname_soil, &
diag_out_interval, &
do_u_interp, &
do_v_interp
implicit none
integer, intent(in) :: localpet
character(len=128) :: outfile
character(len=50) :: varname
character(len=20) :: tempstr(1, 19)
integer, parameter :: Datestrlen = 19
integer :: error, ncid, n, rc, i, j, k, m
integer :: header_buffer_val = 16384
integer :: dim_time, dim_lon, dim_lat, dim_z, dim_zp1, dim_soil
integer :: dim_lonp, dim_latp, dim_str, dim_lon_stag, dim_lat_stag
integer :: id_lat, id_lon, id_z, id_zs, id_times, id_xtime, id_itime
integer :: id_latu, id_latv, id_lonu, id_lonv, id_ph, id_mu, id_hgt, id_ptop
integer :: id_mfm, id_mfu, id_mfv, id_sina, id_cosa
integer :: id_u, id_v
integer :: n2d, n3d, ndims
integer :: sy, sm, sd, sh, smi, ss, vy, vm, vd, vh, vmi, vs
integer, allocatable :: id_vars2(:), id_vars3_nz(:), id_vars3_nzp1(:), &
id_vars_soil(:), id_vars3_vert(:)
integer :: maxinds(2), mininds(2)
integer :: id_dummy3d_p, id_dummy3d_pb
real(esmf_kind_r8), allocatable :: dum2d(:, :), dum2dt(:, :, :), &
dum2du(:, :), dum2dtu(:, :, :), &
dum2dv(:, :), dum2dtv(:, :, :), &
dum3d(:, :, :), dum3dt(:, :, :, :), &
dum3dp1(:, :, :), dum3dp1t(:, :, :, :), &
dumsoil(:, :, :), dumsoilt(:, :, :, :), &
dumsmall(:, :), dum3dtmp(:, :, :), dum1d(:)
type(esmf_field), allocatable :: fields(:), field_write_2d(:), field_extra3(:)
type(timedelta) :: xtime_dt
integer :: clb(2), cub(2), clbu(2), cubu(2), clbv(2), cubv(2), clbvert(2), cubvert(2)
integer :: count1, count2, count1u, count2u, count1v, count2v , count1vert, count2vert
real :: start,finish
real(esmf_kind_r8), pointer :: dum2dptr(:,:), dum3dptr(:,:,:)
n2d = n_diag_fields + n_hist_fields_2d_patch + n_hist_fields_2d_nstd + n_hist_fields_2d_cons
allocate (field_write_2d(n2d), id_vars2(n2d))
allocate (field_extra3(n2d)) !allocate large incase all diag fields are 3d
allocate (id_vars3_nz(n_hist_fields_3d_nz + 1))
allocate (id_vars3_nzp1(n_hist_fields_3d_nzp1))
allocate (id_vars3_vert(n_hist_fields_3d_vert))
allocate (id_vars_soil(n_hist_fields_soil))
allocate (dumsmall(nsoil_input, 1))
allocate (dum3d(i_target, j_target, nz_input))
allocate (dum1d(1))
!--- open the file
error = nf90_create_par(output_file, NF90_NETCDF4, &
MPI_COMM_WORLD, &
MPI_INFO_NULL, &
ncid)
call netcdf_err(error, 'CREATING FILE '//trim(output_file))
!if (localpet==0 ) then
!--- define dimension
error = nf90_def_dim(ncid, 'Time', NF90_UNLIMITED, dim_time)
call netcdf_err(error, 'DEFINING Time DIMENSION')
error = nf90_def_dim(ncid, 'west_east', i_target, dim_lon)
call netcdf_err(error, 'DEFINING LON DIMENSION')
error = nf90_def_dim(ncid, 'west_east_stag', i_target + 1, dim_lon_stag)
call netcdf_err(error, 'DEFINING STAGGERED LON DIMENSION')
error = nf90_def_dim(ncid, 'south_north', j_target, dim_lat)
call netcdf_err(error, 'DEFINING LAT DIMENSION')
error = nf90_def_dim(ncid, 'south_north_stag', j_target + 1, dim_lat_stag)
call netcdf_err(error, 'DEFINING STAGGERED LAT DIMENSION')
error = nf90_def_dim(ncid, 'bottom_top', nz_input, dim_z)
call netcdf_err(error, 'DEFINING VERTICAL DIMENSION')
error = nf90_def_dim(ncid, 'bottom_top_stag', nzp1_input, dim_zp1)
call netcdf_err(error, 'DEFINING VERTICALP1 DIMENSION')
error = nf90_def_dim(ncid, 'soil_layers_stag', nsoil_input, dim_soil)
call netcdf_err(error, 'DEFINING VERTICALP1 DIMENSION')
error = nf90_def_dim(ncid, 'StrLen', Datestrlen, dim_str)
call netcdf_err(error, 'DEFINING STRLEN DIMENSION')
!--- define global attributes
error = nf90_put_att(ncid, NF90_GLOBAL, 'WEST-EAST_GRID_DIMENSION', i_target + 1)
call netcdf_err(error, 'DEFINING WEST-EAST GRID DIMENSION GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'SOUTH-NORTH_GRID_DIMENSION', j_target + 1)
call netcdf_err(error, 'DEFINING NORTH-SOUTH GRID DIMENSION GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'BOTTOM-TOP_GRID_DIMENSION', nz_input + 1)
call netcdf_err(error, 'DEFINING BOTTOM-TOP GRID DIMENSION GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'SIMULATION_START_DATE', start_time)
call netcdf_err(error, 'DEFINING SUMLATION START DATE GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'START_DATE', start_time)
call netcdf_err(error, 'DEFINING START DATE GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'DX', dx)
call netcdf_err(error, 'DEFINING DX GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'DY', dx)
call netcdf_err(error, 'DEFINING DY GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'DT', config_dt)
call netcdf_err(error, 'DEFINING DT GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'SF_SURFACE_PHYSICS', lsm_scheme)
call netcdf_err(error, 'DEFINING SF SURFACE PHYSICS GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'MP_PHYSICS', mp_scheme)
call netcdf_err(error, 'DEFINING MP PHYSICS GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'CU_PHYSICS', conv_scheme)
call netcdf_err(error, 'DEFINING CU PHYSICS GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'CEN_LAT', ref_lat)
call netcdf_err(error, 'DEFINING CEN_LAT GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'CEN_LON', ref_lon)
call netcdf_err(error, 'DEFINING CEN_LON GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'TRUELAT1', truelat1)
call netcdf_err(error, 'DEFINING TRUELAT1 GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'TRUELAT2', truelat2)
call netcdf_err(error, 'DEFINING TRUELAT2 GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'MOAD_CEN_LAT', ref_lat)
call netcdf_err(error, 'DEFINING MOAD_CEN_LAT GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'STAND_LON', stand_lon)
call netcdf_err(error, 'DEFINING STAND_LON GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'POLE_LAT', pole_lat)
call netcdf_err(error, 'DEFINING POLELAT GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'POLE_LON', pole_lon)
call netcdf_err(error, 'DEFINING POLE_LON GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'POL_ELAT', pole_lat)
call netcdf_err(error, 'DEFINING POLE_LAT GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'MAP_PROJ', proj_code)
call netcdf_err(error, 'DEFINING MAP_PROJ GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'MAP_PROJ_CHAR', map_proj_char)
call netcdf_err(error, 'DEFINING MAP_PROJ_CHAR GLOBAL ATTRIBUTE')
if (interp_diag) then
error = nf90_put_att(ncid, NF90_GLOBAL, 'PREC_ACC_DT', diag_out_interval)
call netcdf_err(error, 'DEFINING PREC_ACC_DT GLOBAL ATTRIBUTE')
end if
error = nf90_put_att(ncid, NF90_GLOBAL, 'I_PARENT_START', 1)
call netcdf_err(error, 'DEFINING I_PARENT_START GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'J_PARENT_START', 1)
call netcdf_err(error, 'DEFINING J_PARENT_START GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'WEST-EAST_PATCH_START_UNSTAG', 1)
call netcdf_err(error, 'DEFINING WEST-EAST_PATCH_START_UNSTAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'WEST-EAST_PATCH_START_STAG', 1)
call netcdf_err(error, 'DEFINING WEST-EAST_PATCH_START_STAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'SOUTH-NORTH_PATCH_START_UNSTAG', 1)
call netcdf_err(error, 'DEFINING SOUTH-NORTH_PATCH_START_UNSTAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'SOUTH-NORTH_PATCH_START_STAG', 1)
call netcdf_err(error, 'DEFINING SOUTH-NORTH_PATCH_START_STAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'BOTTOM-TOP_PATCH_START_UNSTAG', 1)
call netcdf_err(error, 'DEFINING BOTTOM-TOP_PATCH_START_UNSTAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'BOTTOM-TOP_PATCH_START_STAG', 1)
call netcdf_err(error, 'DEFINING BOTTOM-TOP_PATCH_START_STAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'WEST-EAST_PATCH_END_UNSTAG', i_target)
call netcdf_err(error, 'DEFINING WEST-EAST_PATCH_END_UNSTAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'WEST-EAST_PATCH_END_STAG', i_target + 1)
call netcdf_err(error, 'DEFINING WEST-EAST_PATCH_END_STAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'SOUTH-NORTH_PATCH_END_UNSTAG', j_target)
call netcdf_err(error, 'DEFINING SOUTH-NORTH_PATCH_END_UNSTAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'SOUTH-NORTH_PATCH_END_STAG', j_target + 1)
call netcdf_err(error, 'DEFINING SOUTH-NORTH_PATCH_END_STAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'BOTTOM-TOP_PATCH_END_UNSTAG', nz_input)
call netcdf_err(error, 'DEFINING BOTTOM-TOP_PATCH_END_UNSTAG GLOBAL ATTRIBUTE')
error = nf90_put_att(ncid, NF90_GLOBAL, 'BOTTOM-TOP_PATCH_END_STAG', nz_input + 1)
call netcdf_err(error, 'DEFINING BOTTOM-TOP_PATCH_END_STAG GLOBAL ATTRIBUTE')
!--- define fields
error = nf90_def_var(ncid, 'XLONG', NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_lon)
call netcdf_err(error, 'DEFINING GEOLON FIELD')
error = nf90_put_att(ncid, id_lon, "description", "LONGITUDE, WEST IS NEGATIVE")
call netcdf_err(error, 'DEFINING GEOLON NAME')
error = nf90_put_att(ncid, id_lon, "units", "degree_east")
call netcdf_err(error, 'DEFINING GEOLON UNITS')
error = nf90_put_att(ncid, id_lon, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_lon, "coordinates", "XLONG XLAT")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_lon, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_lon, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_lon, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'XLONG_U', NF90_FLOAT, (/dim_lon_stag, dim_lat, dim_time/), id_lonu)
call netcdf_err(error, 'DEFINING GEOLON FIELD')
error = nf90_put_att(ncid, id_lonu, "description", "LONGITUDE, WEST IS NEGATIVE")
call netcdf_err(error, 'DEFINING GEOLON NAME')
error = nf90_put_att(ncid, id_lonu, "units", "degree_east")
call netcdf_err(error, 'DEFINING GEOLON UNITS')
error = nf90_put_att(ncid, id_lonu, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_lonu, "coordinates", "XLONG_U XLAT_U")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_lonu, "stagger", "X")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_lonu, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_lonu, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'XLONG_V', NF90_FLOAT, (/dim_lon, dim_lat_stag, dim_time/), id_lonv)
call netcdf_err(error, 'DEFINING GEOLON FIELD')
error = nf90_put_att(ncid, id_lonv, "description", "LONGITUDE, WEST IS NEGATIVE")
call netcdf_err(error, 'DEFINING GEOLON NAME')
error = nf90_put_att(ncid, id_lonv, "units", "degree_east")
call netcdf_err(error, 'DEFINING GEOLON UNITS')
error = nf90_put_att(ncid, id_lonv, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_lonv, "coordinates", "XLONG_V XLAT_V")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_lonv, "stagger", "Y")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_lonv, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_lonv, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'XLAT', NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_lat)
call netcdf_err(error, 'DEFINING GEOLAT FIELD')
error = nf90_put_att(ncid, id_lat, "description", "LATITUDE, SOUTH IS NEGATIVE")
call netcdf_err(error, 'DEFINING GEOLAT NAME')
error = nf90_put_att(ncid, id_lat, "units", "degree_north")
call netcdf_err(error, 'DEFINING GEOLAT UNITS')
error = nf90_put_att(ncid, id_lat, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_lat, "coordinates", "XLONG XLAT")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_lat, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_lat, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_lat, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'XLAT_U', NF90_FLOAT, (/dim_lon_stag, dim_lat, dim_time/), id_latu)
call netcdf_err(error, 'DEFINING GEOLAT FIELD')
error = nf90_put_att(ncid, id_latu, "description", "LATITUDE, SOUTH IS NEGATIVE")
call netcdf_err(error, 'DEFINING GEOLAT NAME')
error = nf90_put_att(ncid, id_latu, "units", "degree_north")
call netcdf_err(error, 'DEFINING GEOLAT UNITS')
error = nf90_put_att(ncid, id_latu, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_latu, "coordinates", "XLONG_U XLAT_U")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_latu, "stagger", "X")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_latu, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_latu, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'XLAT_V', NF90_FLOAT, (/dim_lon, dim_lat_stag, dim_time/), id_latv)
call netcdf_err(error, 'DEFINING GEOLAT FIELD')
error = nf90_put_att(ncid, id_latv, "description", "LATITUDE, SOUTH IS NEGATIVE")
call netcdf_err(error, 'DEFINING GEOLAT NAME')
error = nf90_put_att(ncid, id_latv, "units", "degree_north")
call netcdf_err(error, 'DEFINING GEOLAT UNITS')
error = nf90_put_att(ncid, id_latv, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_latv, "coordinates", "XLONG_V XLAT_V")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_latv, "stagger", "Y")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_latv, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_latv, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'MAPFAC_M', NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_mfm)
call netcdf_err(error, 'DEFINING MAPFAC_M FIELD')
error = nf90_put_att(ncid, id_mfm, "description", "LATITUDE, SOUTH IS NEGATIVE")
call netcdf_err(error, 'DEFINING MAPFAC_M NAME')
error = nf90_put_att(ncid, id_mfm, "units", "degree_north")
call netcdf_err(error, 'DEFINING MAPFAC_M UNITS')
error = nf90_put_att(ncid, id_mfm, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_mfm, "coordinates", "XLONG XLAT")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_mfm, "stagger", " ")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_mfm, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_mfm, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'MAPFAC_U', NF90_FLOAT, (/dim_lon_stag, dim_lat, dim_time/), id_mfu)
call netcdf_err(error, 'DEFINING MAPFAC_U FIELD')
error = nf90_put_att(ncid, id_mfu, "description", "LATITUDE, SOUTH IS NEGATIVE")
call netcdf_err(error, 'DEFINING MAPFAC_U NAME')
error = nf90_put_att(ncid, id_mfu, "units", "degree_north")
call netcdf_err(error, 'DEFINING MAPFAC_U UNITS')
error = nf90_put_att(ncid, id_mfu, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_mfu, "coordinates", "XLONG_U XLAT_U")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_mfu, "stagger", "X")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_mfu, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_mfu, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'MAPFAC_V', NF90_FLOAT, (/dim_lon, dim_lat_stag, dim_time/), id_mfv)
call netcdf_err(error, 'DEFINING MAPFAC_V FIELD')
error = nf90_put_att(ncid, id_mfv, "description", "LATITUDE, SOUTH IS NEGATIVE")
call netcdf_err(error, 'DEFINING MAPFAC_V NAME')
error = nf90_put_att(ncid, id_mfv, "units", "degree_north")
call netcdf_err(error, 'DEFINING MAPFAC_V UNITS')
error = nf90_put_att(ncid, id_mfv, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_mfv, "coordinates", "XLONG_V XLAT_V")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_mfv, "stagger", "Y")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_mfv, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_mfv, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
if (PROJ_CODE==PROJ_LC) then
error = nf90_def_var(ncid, 'SINALPHA', NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_sina)
call netcdf_err(error, 'DEFINING SINALPHA FIELD')
error = nf90_put_att(ncid, id_sina, "description", "SINE OF GRID ROTATION ANGLE ALPHA")
call netcdf_err(error, 'DEFINING SINALPHA NAME')
error = nf90_put_att(ncid, id_sina, "units", " ")
call netcdf_err(error, 'DEFINING MAPFAC_M UNITS')
error = nf90_put_att(ncid, id_sina, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_sina, "coordinates", "XLONG XLAT")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_sina, "stagger", " ")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_sina, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_sina, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'COSALPHA', NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_cosa)
call netcdf_err(error, 'DEFINING COAALPHA FIELD')
error = nf90_put_att(ncid, id_cosa, "description", "COSINE OF GRID ROTATION ANGLE ALPHA")
error = nf90_put_att(ncid, id_cosa, "coordinates", "XLONG XLAT")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_cosa, "stagger", " ")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_cosa, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_cosa, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
endif
error = nf90_def_var(ncid, 'Z_C', NF90_FLOAT, (/dim_lon, dim_lat, dim_zp1, dim_time/), id_z)
call netcdf_err(error, 'DEFINING Z_C FIELD')
error = nf90_put_att(ncid, id_z, "description", "Layer center height above mean sea level")
call netcdf_err(error, 'DEFINING Z_C NAME')
error = nf90_put_att(ncid, id_z, "units", "m AMSL")
call netcdf_err(error, 'DEFINING Z_C UNITS')
error = nf90_put_att(ncid, id_z, "MemoryOrder", "XYZ ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_z, "coordinates", "XLAT XLONG Z_C")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_z, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_z, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_z, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'ZS', NF90_FLOAT, (/dim_soil, dim_time/), id_zs)
call netcdf_err(error, 'DEFINING ZS FIELD')
error = nf90_put_att(ncid, id_zs, "description", "DEPTHS OF CENTERS OF SOIL LAYERS")
call netcdf_err(error, 'DEFINING ZS NAME')
error = nf90_put_att(ncid, id_zs, "units", "m")
call netcdf_err(error, 'DEFINING ZS UNITS')
error = nf90_put_att(ncid, id_zs, "MemoryOrder", "X")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_zs, "coordinates", "ZS XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_zs, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_zs, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_zs, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'HGT', NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_hgt)
call netcdf_err(error, 'DEFINING HGT FIELD')
error = nf90_put_att(ncid, id_hgt, "description", "TERRAIN HEIGHT ")
call netcdf_err(error, 'DEFINING HGT NAME')
error = nf90_put_att(ncid, id_hgt, "units", "m AMSL")
call netcdf_err(error, 'DEFINING HGT UNITS')
error = nf90_put_att(ncid, id_hgt, "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_hgt, "coordinates", "XLAT XLONG ")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_hgt, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_hgt, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_hgt, "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_hgt, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'Times', NF90_CHAR, (/dim_str, dim_time/), id_times)
call netcdf_err(error, 'DEFINING Times FIELD')
error = nf90_put_att(ncid, id_times, "description", "Times")
call netcdf_err(error, 'DEFINING Times NAME')
error = nf90_put_att(ncid, id_times, "units", "m")
call netcdf_err(error, 'DEFINING Times UNITS')
error = nf90_put_att(ncid, id_times, "coordinates", "Time")
call netcdf_err(error, 'DEFINING Times COORD')
error = nf90_put_att(ncid, id_times, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_times, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_var_par_access(ncid, id_times, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'ITIMESTEP', NF90_INT, (/dim_time/), id_itime)
call netcdf_err(error, 'DEFINING ITIMESTEP FIELD')
error = nf90_put_att(ncid, id_itime, "description", "")
call netcdf_err(error, 'DEFINING ITIMESTEP NAME')
error = nf90_put_att(ncid, id_itime, "units", "")
call netcdf_err(error, 'DEFINING ITIMESTEP UNITS')
error = nf90_put_att(ncid, id_itime, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_itime, "FieldType", 106)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_itime, "MemoryOrder", "O ")
call netcdf_err(error, 'DEFINING MemoryOrder')
error = nf90_var_par_access(ncid, id_itime, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
error = nf90_def_var(ncid, 'XTIME', NF90_FLOAT, (/dim_time/), id_xtime)
call netcdf_err(error, 'DEFINING XTIME FIELD')
error = nf90_put_att(ncid, id_xtime, "description", "minutes since "//start_time)
call netcdf_err(error, 'DEFINING XTIME NAME')
error = nf90_put_att(ncid, id_xtime, "units", "minutes since "//start_time)
call netcdf_err(error, 'DEFINING XTIME UNITS')
error = nf90_put_att(ncid, id_xtime, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_xtime, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_xtime, "MemoryOrder", "O ")
call netcdf_err(error, 'DEFINING MemoryOrder')
error = nf90_var_par_access(ncid, id_xtime, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
!end if
k = 0
m = 0
if (interp_diag .and. n_diag_fields > 0) then
allocate (fields(n_diag_fields))
call ESMF_FieldBundleGet(target_diag_bundle, fieldList=fields, &
itemorderflag=ESMF_ITEMORDER_ADDORDER, &
rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldBundleGet", error)
do i = 1, n_diag_fields
call ESMF_FieldGet(fields(i), name=varname, rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldGet", error)
call ESMF_FieldGet(fields(i), dimCount=ndims, rc=rc)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldGet", error)
if (ndims == 2) then
k = k + 1
field_write_2d(k) = fields(i)
if (localpet == 0) print *, "- DEFINE 2d diag ON FILE TARGET GRID ", varname
error = nf90_def_var(ncid, varname, NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_vars2(k))
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_vars2(k), "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_vars2(k), "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_vars2(k), "units", target_diag_units(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars2(k), "description", target_diag_longname(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_vars2(k), "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_vars2(k), "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_vars2(k), "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_vars2(k), NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
else
m = m + 1
field_extra3(m) = fields(i)
if (localpet == 0) print *, "- DEFINE 3d diag ON FILE TARGET GRID ", varname
error = nf90_def_var(ncid, varname, NF90_FLOAT, (/dim_lon, dim_lat, dim_z, dim_time/), id_vars3_nz(m))
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_vars3_nz(m), "MemoryOrder", "XYZ ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_vars3_nz(m), "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_vars3_nz(m), "units", target_diag_units(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars3_nz(m), "description", target_diag_longname(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_vars3_nz(m), "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_vars3_nz(m), "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_vars3_nz(m), "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_vars3_nz(m), NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
end if
end do
deallocate (fields)
end if
n3d = m
!print*, "Writing ", n3d, "3-d variables"
if (interp_hist) then
if (n_hist_fields_2d_cons > 0) then
allocate (fields(n_hist_fields_2d_cons))
call ESMF_FieldBundleGet(target_hist_bundle_2d_cons, fieldList=fields, &
itemorderflag=ESMF_ITEMORDER_ADDORDER, &
rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldBundleGet", error)
do i = 1, n_hist_fields_2d_cons
k = k + 1
call ESMF_FieldGet(fields(i), name=varname, rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldGet", error)
if (localpet == 0) print *, "- DEFINE ON FILE TARGET GRID ", varname
field_write_2d(k) = fields(i)
!if (localpet == 0) then
error = nf90_def_var(ncid, varname, NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_vars2(k))
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_vars2(k), "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_vars2(k), "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_vars2(k), "units", target_hist_units_2d_cons(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars2(k), "description", target_hist_longname_2d_cons(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_vars2(k), "stagger", "")
call netcdf_err(error, 'DEFINING STAGGE')
error = nf90_put_att(ncid, id_vars2(k), "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_vars2(k), "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_vars2(k), NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
!end if
end do
deallocate (fields)
end if
if (n_hist_fields_2d_patch > 0) then
allocate (fields(n_hist_fields_2d_patch))
call ESMF_FieldBundleGet(target_hist_bundle_2d_patch, fieldList=fields, &
itemorderflag=ESMF_ITEMORDER_ADDORDER, &
rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldBundleGet", error)
do i = 1, n_hist_fields_2d_patch
k = k + 1
call ESMF_FieldGet(fields(i), name=varname, rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldGet", error)
if (localpet == 0) print *, "- DEFINE ON FILE TARGET GRID ", varname
field_write_2d(k) = fields(i)
error = nf90_def_var(ncid, varname, NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_vars2(k))
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_vars2(k), "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_vars2(k), "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_vars2(k), "units", target_hist_units_2d_patch(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars2(k), "description", target_hist_longname_2d_patch(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_vars2(k), "stagger", "")
call netcdf_err(error, 'DEFINING STAGGE')
error = nf90_put_att(ncid, id_vars2(k), "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_vars2(k), "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_vars2(k), NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
end do
deallocate (fields)
end if
if (n_hist_fields_2d_nstd > 0) then
allocate (fields(n_hist_fields_2d_nstd))
call ESMF_FieldBundleGet(target_hist_bundle_2d_nstd, fieldList=fields, &
itemorderflag=ESMF_ITEMORDER_ADDORDER, &
rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldBundleGet", error)
do i = 1, n_hist_fields_2d_nstd
k = k + 1
call ESMF_FieldGet(fields(i), name=varname, rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldGet", error)
field_write_2d(k) = fields(i)
if (localpet == 0) print *, "- DEFINE ON FILE TARGET GRID ", varname
error = nf90_def_var(ncid, varname, NF90_FLOAT, (/dim_lon, dim_lat, dim_time/), id_vars2(k))
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_vars2(k), "MemoryOrder", "XY ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_vars2(k), "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_vars2(k), "units", target_hist_units_2d_nstd(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars2(k), "description", target_hist_longname_2d_nstd(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_vars2(k), "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_vars2(k), "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_vars2(k), "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_vars2(k), NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
end do
deallocate (fields)
end if
if (n_hist_fields_soil > 0) then
allocate (fields(n_hist_fields_soil))
call ESMF_FieldBundleGet(target_hist_bundle_soil, fieldList=fields, &
itemorderflag=ESMF_ITEMORDER_ADDORDER, &
rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldBundleGet", error)
do i = 1, n_hist_fields_soil
call ESMF_FieldGet(fields(i), name=varname, rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldGet", error)
if (localpet == 0) print *, "- DEFINE ON FILE TARGET GRID ", varname
error = nf90_def_var(ncid, varname, NF90_FLOAT, (/dim_lon, dim_lat, dim_soil, dim_time/), id_vars_soil(i))
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_vars_soil(i), "MemoryOrder", "XYZ ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_vars_soil(i), "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_vars_soil(i), "units", target_hist_units_soil(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars_soil(i), "description", target_hist_longname_soil(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_vars_soil(i), "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_vars_soil(i), "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_vars_soil(i), "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_vars_soil(i), NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
end do
deallocate (fields)
end if
n2d = k
if (n_hist_fields_3d_nz > 0) then
allocate (fields(n_hist_fields_3d_nz))
call ESMF_FieldBundleGet(target_hist_bundle_3d_nz, fieldList=fields, &
itemorderflag=ESMF_ITEMORDER_ADDORDER, &
rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldBundleGet", error)
do i = 1, n_hist_fields_3d_nz
call ESMF_FieldGet(fields(i), name=varname, rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldGet", error)
if (localpet == 0) print *, "- DEFINE ON FILE TARGET GRID ", varname
error = nf90_def_var(ncid, varname, NF90_FLOAT, (/dim_lon, dim_lat, dim_z, dim_time/), id_vars3_nz(i + n3d))
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_vars3_nz(i + n3d), "MemoryOrder", "XYZ ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_vars3_nz(i + n3d), "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_vars3_nz(i + n3d), "units", target_hist_units_3d_nz(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars3_nz(i + n3d), "description", target_hist_longname_3d_nz(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_vars3_nz(i + n3d), "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_vars3_nz(i + n3d), "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_vars3_nz(i + n3d), "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_vars3_nz(i + n3d), NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
if (wrf_mod_vars .and. trim(varname) == 'MUB') then
if (localpet == 0) print *, "- DEFINE ON FILE STAGGERED TARGET GRID MU"
error = nf90_def_var(ncid, 'MU', NF90_FLOAT, (/dim_lon, dim_lat, dim_z, dim_time/), id_mu)
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_mu, "MemoryOrder", "XYZ ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_mu, "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_mu, "units", target_hist_units_3d_nz(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_mu, "description", 'Perturbation '//target_hist_longname_3d_nz(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_mu, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_mu, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_mu, "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_mu, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
end if
if (wrf_mod_vars .and. trim(varname) == 'P_HYD') then
if (localpet == 0) print *, "- DEFINE ON FILE STAGGERED TARGET GRID P_TOP"
error = nf90_def_var(ncid, 'P_TOP', NF90_FLOAT, (/dim_time/), id_ptop)
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_ptop, "MemoryOrder", "0 ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_ptop, "units", target_hist_units_3d_nz(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_ptop, "description", 'PRESSURE TOP OF THE MODEL')
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_ptop, "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_ptop, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_ptop, "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_ptop, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
end if
end do
deallocate (fields)
end if
if (do_u_interp==1) then
if (localpet == 0) print *, "- DEFINE ON FILE STAGGERED TARGET GRID U"
error = nf90_def_var(ncid, "U", NF90_FLOAT, (/dim_lon_stag, dim_lat, dim_z, dim_time/),id_u)
call netcdf_err(error, 'DEFINING VAR U')
error = nf90_put_att(ncid, id_u, "MemoryOrder", "XYZ ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_u, "coordinates", "XLONG_U XLAT_U XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_u, "units", "m s^{-1}")
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_u, "description", "")
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_u, "stagger", "X")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_u, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_u, "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_u, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
endif
if (do_v_interp==1) then
if (localpet == 0) print *, "- DEFINE ON FILE STAGGERED TARGET GRID v"
error = nf90_def_var(ncid, "V", NF90_FLOAT, (/dim_lon, dim_lat_stag, dim_z, dim_time/),id_v)
call netcdf_err(error, 'DEFINING VAR V')
error = nf90_put_att(ncid, id_v, "MemoryOrder", "XYZ ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_v, "coordinates", "XLONG_V XLAT_V XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_v, "units", "m s^{-1}")
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_v, "description", "")
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_v, "stagger", "Y")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_v, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_v, "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_v, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
endif
if (n_hist_fields_3d_nzp1 > 0) then
allocate (fields(n_hist_fields_3d_nzp1))
call ESMF_FieldBundleGet(target_hist_bundle_3d_nzp1, fieldList=fields, &
itemorderflag=ESMF_ITEMORDER_ADDORDER, &
rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldBundleGet", error)
do i = 1, n_hist_fields_3d_nzp1
call ESMF_FieldGet(fields(i), name=varname, rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldGet", error)
if (localpet == 0) print *, "- DEFINE ON FILE TARGET GRID ", varname
error = nf90_def_var(ncid, varname, NF90_FLOAT, (/dim_lon, dim_lat, dim_zp1, dim_time/), id_vars3_nzp1(i))
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_vars3_nzp1(i), "MemoryOrder", "XYZ ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_vars3_nzp1(i), "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
if (wrf_mod_vars .and. trim(varname) == 'PHB') then
error = nf90_put_att(ncid, id_vars3_nzp1(i), "units", "gpm")
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars3_nzp1(i), "description", "Base Geopotential Height")
call netcdf_err(error, 'DEFINING LONG_NAME')
else
error = nf90_put_att(ncid, id_vars3_nzp1(i), "units", target_hist_units_3d_nzp1(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars3_nzp1(i), "description", target_hist_longname_3d_nzp1(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
end if
error = nf90_put_att(ncid, id_vars3_nzp1(i), "stagger", "Z")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_vars3_nzp1(i), "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_vars3_nzp1(i), "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_vars3_nzp1(i), NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
if (wrf_mod_vars .and. trim(varname) == 'PHB') then
if (localpet == 0) print *, "- DEFINE ON FILE STAGGERED TARGET GRID PH"
error = nf90_def_var(ncid, 'PH', NF90_FLOAT, (/dim_lon, dim_lat, dim_zp1, dim_time/), id_ph)
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_ph, "MemoryOrder", "XYZ ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_ph, "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_ph, "units", "gpm")
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_ph, "description", 'Perturbation Geopotential Height')
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_ph, "stagger", "Z")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_ph, "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_ph, "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_ph, NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
end if
end do
deallocate (fields)
end if
if (n_hist_fields_3d_vert > 0) then
allocate (fields(n_hist_fields_3d_vert))
call ESMF_FieldBundleGet(target_hist_bundle_3d_vert, fieldList=fields, &
itemorderflag=ESMF_ITEMORDER_ADDORDER, &
rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldBundleGet", error)
do i = 1, n_hist_fields_3d_vert
call ESMF_FieldGet(fields(i), name=varname, rc=error)
if (ESMF_logFoundError(rcToCheck=error, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) &
call error_handler("IN FieldGet", error)
if (localpet == 0) print *, "- DEFINE ON FILE TARGET GRID ", varname
error = nf90_def_var(ncid, varname, NF90_FLOAT, (/dim_lon, dim_lat, dim_z, dim_time/), id_vars3_vert(i))
call netcdf_err(error, 'DEFINING VAR')
error = nf90_put_att(ncid, id_vars3_vert(i), "MemoryOrder", "XYZ")
call netcdf_err(error, 'DEFINING MEMORYORDER')
error = nf90_put_att(ncid, id_vars3_vert(i), "coordinates", "XLONG XLAT XTIME")
call netcdf_err(error, 'DEFINING COORD')
error = nf90_put_att(ncid, id_vars3_vert(i), "units", target_hist_units_3d_vert(i))
call netcdf_err(error, 'DEFINING UNITS')
error = nf90_put_att(ncid, id_vars3_vert(i), "description", target_hist_longname_3d_vert(i))
call netcdf_err(error, 'DEFINING LONG_NAME')
error = nf90_put_att(ncid, id_vars3_vert(i), "stagger", "")
call netcdf_err(error, 'DEFINING STAGGER')
error = nf90_put_att(ncid, id_vars3_vert(i), "FieldType", 104)
call netcdf_err(error, 'DEFINING FieldType')
error = nf90_put_att(ncid, id_vars3_vert(i), "_FillValue", missing_value)
call netcdf_err(error, 'DEFINING _FillValue')
error = nf90_var_par_access(ncid, id_vars3_vert(i), NF90_COLLECTIVE)
call netcdf_err(error ,'SETTING COLLECTIVE ACCESS')
end do
deallocate (fields)
end if