-
Notifications
You must be signed in to change notification settings - Fork 136
/
diag_axis.F90
1324 lines (1191 loc) · 55.1 KB
/
diag_axis.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
!***********************************************************************
!* GNU Lesser General Public License
!*
!* This file is part of the GFDL Flexible Modeling System (FMS).
!*
!* FMS is free software: you can redistribute it and/or modify it under
!* the terms of the GNU Lesser General Public License as published by
!* the Free Software Foundation, either version 3 of the License, or (at
!* your option) any later version.
!*
!* FMS is distributed in the hope that it will be useful, but WITHOUT
!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
!* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
!* for more details.
!*
!* You should have received a copy of the GNU Lesser General Public
!* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
!***********************************************************************
!> @defgroup diag_axis_mod diag_axis_mod
!> @ingroup diag_manager
!> @brief An integral part of @ref diag_manager_mod. It helps to create axis IDs
!! that are used in @ref register_diag_field.
!!
!> @author Seth Underwood
!!
!! Users first create axis ID by calling diag_axis_init, then use this axis ID in
!! register_diag_field.
!> @addtogroup diag_axis_mod
!> @{
MODULE diag_axis_mod
use platform_mod
USE mpp_domains_mod, ONLY: domainUG, domain1d, domain2d, mpp_get_compute_domain,&
& mpp_get_domain_components, null_domain1d, null_domain2d, null_domainUG,&
& NORTH, EAST, CENTER, &
& OPERATOR(.NE.), mpp_get_global_domain, mpp_get_domain_name
USE fms_mod, ONLY: error_mesg, write_version_number, lowercase, uppercase,&
& fms_error_handler, FATAL, NOTE
USE diag_data_mod, ONLY: diag_axis_type, max_subaxes, max_axes,&
& max_num_axis_sets, max_axis_attributes, debug_diag_manager,&
& first_send_data_call, diag_atttype, use_modern_diag, TWO_D_DOMAIN
use fms_diag_object_mod, only:fms_diag_object
#ifdef use_netCDF
USE netcdf, ONLY: NF90_INT, NF90_FLOAT, NF90_CHAR
#endif
IMPLICIT NONE
PRIVATE
PUBLIC diag_axis_init, get_diag_axis, get_domain1d, get_domain2d,&
& get_axis_length, get_axis_global_length, diag_subaxes_init,&
& get_diag_axis_cart, get_diag_axis_data, max_axes, get_axis_aux,&
& get_tile_count, get_axes_shift, get_diag_axis_name,&
& get_axis_num, get_diag_axis_domain_name, diag_axis_add_attribute,&
& get_domainUG, axis_compatible_check, axis_is_compressed, &
& get_compressed_axes_ids, get_axis_reqfld, &
& NORTH, EAST, CENTER, diag_axis_type
! Include variable "version" to be written to log file
#include<file_version.h>
!----------
integer(I4_KIND),parameter,public :: DIAG_AXIS_NODOMAIN = 0 !< For unstructured grid support
integer(I4_KIND),parameter,public :: DIAG_AXIS_2DDOMAIN = 1 !< For unstructured grid support
integer(I4_KIND),parameter,public :: DIAG_AXIS_UGDOMAIN = 2 !< For unstructured grid support
!----------
INTEGER, DIMENSION(:), ALLOCATABLE :: num_subaxes !< counter of number of axes defined
INTEGER :: num_def_axes = 0
CHARACTER(len=128), DIMENSION(:), ALLOCATABLE, SAVE :: Axis_sets !< storage for axis set names
INTEGER :: num_axis_sets = 0
TYPE(diag_axis_type), ALLOCATABLE, SAVE :: Axes(:) !< global storage for all defined axes
LOGICAL :: module_is_initialized = .FALSE.
!> @}
!> @brief Add an arbitrary attribute and value to the diagnostic axis.
!!
!> Any number of attributes can be added to a given axis. All attribute addition must
!! be done before first <TT>send_data</TT> call.<br>
!!
!! If a real or integer attribute is already defined, a FATAL error will be called.
!! If a character attribute is already defined, then it will be prepended to the
!! existing attribute value.
!! <br>Example usage:
!! @code{.F90} call diag_axis_add_attribute(diag_axis_id, att_name, att_value) @endcode
!> @ingroup diag_axis_mod
INTERFACE diag_axis_add_attribute
MODULE PROCEDURE diag_axis_add_attribute_scalar_r
MODULE PROCEDURE diag_axis_add_attribute_scalar_i
MODULE PROCEDURE diag_axis_add_attribute_scalar_c
MODULE PROCEDURE diag_axis_add_attribute_r1d
MODULE PROCEDURE diag_axis_add_attribute_i1d
END INTERFACE diag_axis_add_attribute
!> @addtogroup diag_axis_mod
!> @{
CONTAINS
!> @brief Initialize the axis, and return the axis ID.
!!
!> <TT>diag_axis_init</TT> initializes an axis and returns the axis ID that
!! is to be used with <TT>register_diag_field</TT>. This function also
!! increments the axis counter and fills in the axes
!!
!! @return integer axis ID
INTEGER FUNCTION diag_axis_init(name, DATA, units, cart_name, long_name, direction,&
& set_name, edges, Domain, Domain2, DomainU, aux, req, tile_count, domain_position )
CHARACTER(len=*), INTENT(in) :: name !< Short name for axis
CLASS(*), DIMENSION(:), INTENT(in) :: DATA !< Array of coordinate values
CHARACTER(len=*), INTENT(in) :: units !< Units for the axis
CHARACTER(len=*), INTENT(in) :: cart_name !< Cartesian axis ("X", "Y", "Z", "T")
CHARACTER(len=*), INTENT(in), OPTIONAL :: long_name !< Long name for the axis.
CHARACTER(len=*), INTENT(in), OPTIONAL :: set_name
INTEGER, INTENT(in), OPTIONAL :: direction !< Indicates the direction of the axis
INTEGER, INTENT(in), OPTIONAL :: edges !< Axis ID for the previously defined "edges axis"
TYPE(domain1d), INTENT(in), OPTIONAL :: Domain
TYPE(domain2d), INTENT(in), OPTIONAL :: Domain2
TYPE(domainUG), INTENT(in), OPTIONAL :: DomainU
CHARACTER(len=*), INTENT(in), OPTIONAL :: aux !< Auxiliary name, can only be <TT>geolon_t</TT> or <TT>geolat_t</TT>
CHARACTER(len=*), INTENT(in), OPTIONAL :: req !< Required field names.
INTEGER, INTENT(in), OPTIONAL :: tile_count
INTEGER, INTENT(in), OPTIONAL :: domain_position
TYPE(domain1d) :: domain_x, domain_y
INTEGER :: ierr, axlen
INTEGER :: i, set, tile
INTEGER :: isc, iec, isg, ieg
CHARACTER(len=128) :: emsg
IF ( .NOT.module_is_initialized ) THEN
CALL write_version_number("DIAG_AXIS_MOD", version)
ENDIF
if (use_modern_diag) then
!TODO Passing in the axis_length because of a gnu issue where inside fms_diag_axis_init, the size of DATA
!was 2 which was causing the axis_data to not be written correctly...
diag_axis_init = fms_diag_object%fms_diag_axis_init(name, DATA, units, cart_name, size(DATA(:)), &
& long_name=long_name, direction=direction, set_name=set_name, edges=edges, Domain=Domain, Domain2=Domain2, &
& DomainU=DomainU, aux=aux, req=req, tile_count=tile_count, domain_position=domain_position)
return
endif
IF ( PRESENT(tile_count)) THEN
tile = tile_count
ELSE
tile = 1
END IF
! Allocate the axes
IF (.NOT. ALLOCATED(Axis_sets)) ALLOCATE(Axis_sets(max_num_axis_sets))
IF (.NOT. ALLOCATED(Axes)) ALLOCATE(Axes(max_axes))
IF (.NOT. ALLOCATED(num_subaxes)) THEN
ALLOCATE(num_subaxes(max_axes))
num_subaxes = 0
END IF
!---- is there an axis set? ----
IF ( PRESENT(set_name) ) THEN
set = get_axis_set_num (set_name)
!---- add new set name ----
IF (set == 0) THEN
num_axis_sets = num_axis_sets + 1
IF ( num_axis_sets > max_num_axis_sets ) THEN
WRITE (emsg, FMT='("num_axis_sets (",I2,") exceeds max_num_axis_sets (",I2,"). ")')&
& num_axis_sets, max_num_axis_sets
! <ERROR STATUS="FATAL">
! num_axis_sets (<num_axis_sets>) exceeds max_num_axis_sets(<num_axis_sets>).
! Increase max_num_axis_sets via diag_manager_nml.
! </ERROR>
CALL error_mesg('diag_axis_mod::diag_axis_init',&
& TRIM(emsg)//' Increase max_num_axis_sets via diag_manager_nml.', FATAL)
END IF
set = num_axis_sets
Axis_sets(set) = set_name
END IF
ELSE
set = 0
END IF
!---- see if axis already exists --
! if this is time axis, return the ID of a previously defined
! if this is spatial axis, FATAL error
DO i = 1, num_def_axes
IF ( TRIM(name) == Axes(i)%name ) THEN
IF ( TRIM(name) == 'Stations' .OR. TRIM(name) == 'Levels') THEN
diag_axis_init = i
RETURN
ELSE IF ( set == Axes(i)%set ) THEN
IF ( TRIM(lowercase(name)) == 'time' .OR.&
& TRIM(lowercase(cart_name)) == 't' .OR.&
& TRIM(lowercase(name)) == 'nv' .OR.&
& TRIM(lowercase(cart_name)) == 'n' ) THEN
diag_axis_init = i
RETURN
ELSE IF ( (lowercase(cart_name) /= 'x' .AND. lowercase(cart_name) /= 'y')&
& .OR. tile /= Axes(i)%tile_count) THEN
! <ERROR STATUS="FATAL">axis_name <NAME> and axis_set already exist.</ERROR>
CALL error_mesg('diag_axis_mod::diag_axis_init',&
& 'axis_name '//TRIM(name)//' and axis_set already exist.', FATAL)
END IF
END IF
END IF
END DO
!---- register axis ----
num_def_axes = num_def_axes + 1
! <ERROR STATUS="FATAL">max_axes exceeded, increase it via diag_manager_nml</ERROR>
IF (num_def_axes > max_axes) CALL error_mesg ('diag_axis_mod::diag_axis_init',&
& 'max_axes exceeded, increase via diag_manager_nml', FATAL)
diag_axis_init = num_def_axes
!---- check and then save cart_name name ----
IF ( TRIM(uppercase(cart_name)) == 'X' .OR.&
& TRIM(uppercase(cart_name)) == 'Y' .OR.&
& TRIM(uppercase(cart_name)) == 'Z' .OR.&
& TRIM(uppercase(cart_name)) == 'T' .OR.&
& TRIM(uppercase(cart_name)) == 'U' .OR.&
& TRIM(uppercase(cart_name)) == 'N' ) THEN
Axes(diag_axis_init)%cart_name = TRIM(uppercase(cart_name))
ELSE
! <ERROR STATUS="FATAL">Invalid cart_name name.</ERROR>
CALL error_mesg('diag_axis_mod::diag_axis_init', 'Invalid cart_name name. '//TRIM(uppercase(cart_name)), FATAL)
END IF
!---- allocate storage for coordinate values of axis ----
IF ( Axes(diag_axis_init)%cart_name == 'T' ) THEN
axlen = 0
ELSE
axlen = SIZE(DATA(:))
END IF
ALLOCATE ( Axes(diag_axis_init)%data(1:axlen) )
! Initialize Axes(diag_axis_init)
Axes(diag_axis_init)%name = TRIM(name)
SELECT TYPE (DATA)
TYPE IS (real(kind=r4_kind))
Axes(diag_axis_init)%data = DATA(1:axlen)
TYPE IS (real(kind=r8_kind))
Axes(diag_axis_init)%data = real(DATA(1:axlen))
CLASS DEFAULT
CALL error_mesg('diag_axis_mod::diag_axis_init',&
& 'The axis data is not one of the supported types of real(kind=4) or real(kind=8)', FATAL)
END SELECT
Axes(diag_axis_init)%units = units
Axes(diag_axis_init)%length = axlen
Axes(diag_axis_init)%set = set
! start and end are used in subaxes information only
Axes(diag_axis_init)%start = -1
Axes(diag_axis_init)%end = -1
Axes(diag_axis_init)%subaxis_name = ""
Axes(diag_axis_init)%shift = 0
Axes(diag_axis_init)%num_attributes = 0
IF ( PRESENT(long_name) ) THEN
Axes(diag_axis_init)%long_name = long_name
ELSE
Axes(diag_axis_init)%long_name = name
END IF
IF ( PRESENT(aux) ) THEN
Axes(diag_axis_init)%aux = TRIM(aux)
ELSE
Axes(diag_axis_init)%aux = 'none'
END IF
IF ( PRESENT(req) ) THEN
Axes(diag_axis_init)%req = TRIM(req)
ELSE
Axes(diag_axis_init)%req = 'none'
END IF
IF ( PRESENT(domain_position) ) THEN
if (domain_position == NORTH .or. domain_position == EAST .or. domain_position == CENTER) then
Axes(diag_axis_init)%domain_position = domain_position
else
CALL error_mesg('diag_axis_mod::diag_axis_init', "Position must be NORTH, EAST, or CENTER" ,&
FATAL)
endif
ELSE
Axes(diag_axis_init)%domain_position = CENTER
END IF
!---- axis direction (-1, 0, or +1) ----
IF ( PRESENT(direction) )THEN
IF ( ABS(direction) /= 1 .AND. direction /= 0 )&
! <ERROR STATUS="FATAL">direction must be 0, +1, or -1</ERROR>
& CALL error_mesg('diag_axis_mod::diag_axis_init', 'direction must be 0, +1 or -1', FATAL)
Axes(diag_axis_init)%direction = direction
ELSE
Axes(diag_axis_init)%direction = 0
END IF
!---- Handle the DomainU check
IF (present(DomainU) .AND. (PRESENT(Domain2) .OR. PRESENT(Domain)) ) THEN
! <ERROR STATUS="FATAL">Presence of DomainU and another Domain at the same time is prohibited</ERROR>
CALL error_mesg('diag_axis_mod::diag_axis_init',&
& 'Presence of DomainU and another Domain at the same time is prohibited', FATAL)
!---- domain2d type ----
ELSE IF ( PRESENT(Domain2) .AND. PRESENT(Domain)) THEN
! <ERROR STATUS="FATAL">Presence of both Domain and Domain2 at the same time is prohibited</ERROR>
CALL error_mesg('diag_axis_mod::diag_axis_init',&
& 'Presence of both Domain and Domain2 at the same time is prohibited', FATAL)
ELSE IF ( PRESENT(Domain2) .OR. PRESENT(Domain)) THEN
IF ( Axes(diag_axis_init)%cart_name /= 'X' .AND. Axes(diag_axis_init)%cart_name /= 'Y') THEN
! <ERROR STATUS="FATAL">Domain must not be present for an axis which is not in the X or Y direction.</ERROR>
CALL error_mesg('diag_axis_mod::diag_axis_init',&
& 'A Structured Domain must not be present for an axis which is not in the X or Y direction', FATAL)
END IF
ELSE IF (present(DomainU) .AND. Axes(diag_axis_init)%cart_name /= 'U') THEN
CALL error_mesg('diag_axis_mod::diag_axis_init',&
& 'In the unstructured domain, the axis cart_name must be U', FATAL)
END IF
Axes(diag_axis_init)%tile_count = tile
IF ( PRESENT(Domain2) ) THEN
Axes(diag_axis_init)%Domain2 = Domain2
CALL mpp_get_domain_components(Domain2, domain_x, domain_y, tile_count=tile_count)
IF ( Axes(diag_axis_init)%cart_name == 'X' ) Axes(diag_axis_init)%Domain = domain_x
IF ( Axes(diag_axis_init)%cart_name == 'Y' ) Axes(diag_axis_init)%Domain = domain_y
Axes(diag_axis_init)%DomainUG = null_DomainUG
ELSE IF ( PRESENT(Domain)) THEN
!---- domain1d type ----
Axes(diag_axis_init)%Domain2 = null_domain2d ! needed since not 2-D domain
Axes(diag_axis_init)%Domain = Domain
Axes(diag_axis_init)%DomainUG = null_DomainUG
ELSE IF (present(DomainU)) THEN
Axes(diag_axis_init)%Domain2 = null_domain2d
Axes(diag_axis_init)%Domain = null_domain1d
Axes(diag_axis_init)%DomainUG = DomainU
ELSE
Axes(diag_axis_init)%Domain2 = null_domain2d
Axes(diag_axis_init)%Domain = null_domain1d
Axes(diag_axis_init)%DomainUG = null_domainUG
END IF
!--- set up the shift value for x-y axis
IF ( Axes(diag_axis_init)%Domain .NE. null_domain1d ) THEN
CALL mpp_get_compute_domain(Axes(diag_axis_init)%Domain, isc, iec)
CALL mpp_get_global_domain(Axes(diag_axis_init)%Domain, isg, ieg)
IF ( Axes(diag_axis_init)%length == ieg - isg + 2 ) THEN
Axes(diag_axis_init)%shift = 1
END IF
END IF
!---- have axis edges been defined ? ----
Axes(diag_axis_init)%edges = 0
IF (PRESENT(edges) ) THEN
IF ( edges > 0 .AND. edges < num_def_axes ) THEN
ierr=0
IF ( Axes(edges)%cart_name /= Axes(diag_axis_init)%cart_name) ierr=1
IF ( Axes(edges)%length /= Axes(diag_axis_init)%length+1 ) ierr=ierr+2
IF ( Axes(edges)%set /= Axes(diag_axis_init)%set ) ierr=ierr+4
IF ( ierr > 0 ) THEN
! <ERROR STATUS="FATAL">Edges axis does not match axis (code <CODE>).</ERROR>
WRITE (emsg,'("Edges axis does not match axis (code ",I1,").")') ierr
CALL error_mesg('diag_axis_mod::diag_axis_init', emsg, FATAL)
END IF
Axes(diag_axis_init)%edges = edges
ELSE
! <ERROR STATUS="FATAL">Edges axis is not defined.</ERROR>
CALL error_mesg('diag_axis_mod::diag_axis_init', 'Edges axis is not defined', FATAL)
END IF
END IF
! Module is now initialized
module_is_initialized = .TRUE.
END FUNCTION diag_axis_init
!> @brief Create a subaxis on a parent axis.
!!
!> Given the ID of a parent axis, create a subaxis and fill it with data,
!! and return the ID of the corresponding subaxis.
!!
!! The subaxis is defined on the parent axis from <TT>start_indx</TT>
!! to <TT>end_indx</TT>.
!!
!! @return Integer ID of the corresponding subaxis.
INTEGER FUNCTION diag_subaxes_init(axis, subdata, start_indx, end_indx, domain_2d)
INTEGER, INTENT(in) :: axis !< ID of the parent axis
REAL, DIMENSION(:), INTENT(in) :: subdata !< Data of the subaxis
INTEGER, INTENT(in) :: start_indx !< Start index of the subaxis
INTEGER, INTENT(in) :: end_indx !< End index of the subaxis
TYPE(domain2d), INTENT(in), OPTIONAL :: domain_2d
INTEGER :: i, nsub_axis, direction
INTEGER :: xbegin, xend, ybegin, yend
INTEGER :: ad_xbegin, ad_xend, ad_ybegin, ad_yend
CHARACTER(len=128) :: name, nsub_name
CHARACTER(len=128) :: units
CHARACTER(len=128) :: cart_name
CHARACTER(len=128) :: long_name
CHARACTER(len=128) :: emsg
LOGICAL :: subaxis_set, hasDomain
! there may be more than 1 subaxis on a parent axis, check for redundancy
nsub_axis = 0
subaxis_set = .FALSE.
IF ( PRESENT(domain_2d) ) THEN
hasDomain = .TRUE.
CALL mpp_get_compute_domain(domain_2d, xbegin, xend, ybegin, yend)
ELSE
hasDomain = .FALSE.
END IF
sa_search: DO i = 1, num_subaxes(axis)
IF ( start_indx == Axes(axis)%start(i) .AND. end_indx == Axes(axis)%end(i) ) THEN
IF ( hasDomain ) THEN
CALL mpp_get_compute_domain(Axes(axis)%subaxis_domain2(i), ad_xbegin, ad_xend, ad_ybegin, ad_yend)
IF ( .NOT.((xbegin == ad_xbegin .AND. xend == ad_xend) .AND.&
& (ybegin == ad_ybegin .AND. yend == ad_yend)) ) THEN
CYCLE sa_search
END IF
END IF
nsub_axis = i
subaxis_set = .TRUE. !subaxis already exists
name = TRIM(Axes(axis)%subaxis_name(nsub_axis))
EXIT sa_search
END IF
END DO sa_search
IF ( nsub_axis == 0 ) THEN ! create new subaxis
num_subaxes(axis) = num_subaxes(axis) + 1
IF (num_subaxes(axis) > max_subaxes) THEN
! <ERROR STATUS="FATAL">max_subaxes (value <VALUE>) is too small. Consider increasing max_subaxes.</ERROR>
WRITE (emsg,'("max_subaxes (value ",I4,") is too small. Consider increasing max_subaxes.")') max_subaxes
CALL error_mesg('diag_axis_mod::diag_subaxes_init', emsg, FATAL)
END IF
nsub_axis = num_subaxes(axis)
Axes(axis)%start(nsub_axis) = start_indx
Axes(axis)%end(nsub_axis) = end_indx
if ( hasDomain ) Axes(axis)%subaxis_domain2(nsub_axis) = domain_2d
END IF
! Create new name for the subaxis from name of parent axis
! If subaxis already exists, get the index and return
IF(subaxis_set) THEN
IF ( Axes(axis)%set > 0 ) THEN
diag_subaxes_init = get_axis_num(name, set_name=TRIM(Axis_sets(Axes(axis)%set)))
ELSE
diag_subaxes_init = get_axis_num(name)
END IF
ELSE
! get a new index for subaxis
!::sdu:: Need a check to allow larger numbers in the index number.
WRITE (nsub_name,'(I2.2)') nsub_axis
name = TRIM(Axes(axis)%name)//'_sub'//TRIM(nsub_name)
Axes(axis)%subaxis_name(nsub_axis) = name
long_name = TRIM(Axes(axis)%long_name)
units = TRIM(Axes(axis)%units)
cart_name = TRIM(Axes(axis)%cart_name)
direction = Axes(axis)%direction
IF (Axes(axis)%set > 0) THEN
diag_subaxes_init = diag_axis_init (TRIM(name), subdata, TRIM(units), TRIM(cart_name), TRIM(long_name),&
& set_name=TRIM(Axis_sets(Axes(axis)%set)), direction=direction, Domain2=domain_2d)
ELSE
diag_subaxes_init = diag_axis_init (TRIM(name), subdata, TRIM(units), TRIM(cart_name), TRIM(long_name),&
& direction=direction, Domain2=domain_2d)
END IF
END IF
END FUNCTION diag_subaxes_init
!> @brief Return information about the axis with index ID
SUBROUTINE get_diag_axis(id, name, units, long_name, cart_name,&
& direction, edges, Domain, DomainU, DATA, num_attributes, attributes, domain_position)
CHARACTER(len=*), INTENT(out) :: name, units, long_name, cart_name
INTEGER, INTENT(in) :: id !< Axis ID
TYPE(domain1d), INTENT(out) :: Domain
TYPE(domainUG), INTENT(out) :: DomainU
INTEGER, INTENT(out) :: direction !< Direction of data. (See <TT>@ref diag_axis_init</TT> for a description of
!! allowed values)
INTEGER, INTENT(out) :: edges !< Axis ID for the previously defined "edges axis".
CLASS(*), DIMENSION(:), INTENT(out) :: DATA !< Array of coordinate values for this axis.
INTEGER, INTENT(out), OPTIONAL :: num_attributes
TYPE(diag_atttype), ALLOCATABLE, DIMENSION(:), INTENT(out), OPTIONAL :: attributes
INTEGER, INTENT(out), OPTIONAL :: domain_position
INTEGER :: i, j, istat
CALL valid_id_check(id, 'get_diag_axis')
name = Axes(id)%name
units = Axes(id)%units
long_name = Axes(id)%long_name
cart_name = Axes(id)%cart_name
direction = Axes(id)%direction
edges = Axes(id)%edges
Domain = Axes(id)%Domain
DomainU = Axes(id)%DomainUG
if (present(domain_position)) domain_position = Axes(id)%domain_position
IF ( Axes(id)%length > SIZE(DATA(:)) ) THEN
! <ERROR STATUS="FATAL">array data is too small.</ERROR>
CALL error_mesg('diag_axis_mod::get_diag_axis', 'array data is too small', FATAL)
ELSE
SELECT TYPE (DATA)
TYPE IS (real(kind=r4_kind))
DATA(1:Axes(id)%length) = real(Axes(id)%data(1:Axes(id)%length), kind=r4_kind)
TYPE IS (real(kind=r8_kind))
DATA(1:Axes(id)%length) = Axes(id)%data(1:Axes(id)%length)
CLASS DEFAULT
CALL error_mesg('diag_axis_mod::get_diag_axis',&
& 'The axis data is not one of the supported types of real(kind=4) or real(kind=8)', FATAL)
END SELECT
END IF
IF ( PRESENT(num_attributes) ) THEN
num_attributes = Axes(id)%num_attributes
END IF
IF ( PRESENT(attributes) ) THEN
IF ( allocated(Axes(id)%attributes) ) THEN
IF ( ALLOCATED(attributes) ) THEN
! If allocate, make sure attributes is large enough to hold Axis(id)%attributes
IF ( Axes(id)%num_attributes .GT. SIZE(attributes(:)) ) THEN
CALL error_mesg('diag_axis_mod::get_diag_axis', 'array attribute is too small', FATAL)
END IF
ELSE
! Allocate attributes
ALLOCATE(attributes(Axes(id)%num_attributes), STAT=istat)
IF ( istat .NE. 0 ) THEN
CALL error_mesg('diag_axis_mod::get_diag_axis', 'Unable to allocate memory for attribute', FATAL)
END IF
END IF
DO i=1, Axes(id)%num_attributes
! Unallocate all att arrays in preparation for new data
IF ( allocated(attributes(i)%fatt) ) THEN
DEALLOCATE(attributes(i)%fatt)
END IF
IF ( allocated(attributes(i)%iatt) ) THEN
DEALLOCATE(attributes(i)%iatt)
END IF
! Copy in attribute data
attributes(i)%type = Axes(id)%attributes(i)%type
attributes(i)%len = Axes(id)%attributes(i)%len
attributes(i)%name = Axes(id)%attributes(i)%name
attributes(i)%catt = Axes(id)%attributes(i)%catt
! Allocate fatt arrays (if needed), and copy in data
IF ( allocated(Axes(id)%attributes(i)%fatt) ) THEN
ALLOCATE(attributes(i)%fatt(SIZE(Axes(id)%attributes(i)%fatt(:))), STAT=istat)
IF ( istat .NE. 0 ) THEN
CALL error_mesg('diag_axis_mod::get_diag_axis', &
& 'Unable to allocate memory for attribute%fatt', FATAL)
END IF
DO j=1, SIZE(attributes(i)%fatt(:))
attributes(i)%fatt(j) = Axes(id)%attributes(i)%fatt(j)
END DO
END IF
! Allocate iatt arrays (if needed), and copy in data
IF ( allocated(Axes(id)%attributes(i)%iatt) ) THEN
ALLOCATE(attributes(i)%iatt(SIZE(Axes(id)%attributes(i)%iatt(:))), STAT=istat)
IF ( istat .NE. 0 ) THEN
CALL error_mesg('diag_axis_mod::get_diag_axis', &
& 'Unable to allocate memory for attribute%iatt', FATAL)
END IF
DO j=1, SIZE(attributes(i)%iatt(:))
attributes(i)%iatt(j) = Axes(id)%attributes(i)%iatt(j)
END DO
END IF
END DO
END IF
END IF
END SUBROUTINE get_diag_axis
!> @brief Return the axis cartesian.
SUBROUTINE get_diag_axis_cart(id, cart_name)
INTEGER, INTENT(in) :: id !< Axis ID
CHARACTER(len=*), INTENT(out) :: cart_name !< Cartesian axis
CALL valid_id_check(id, 'get_diag_axis_cart')
cart_name = Axes(id)%cart_name
END SUBROUTINE get_diag_axis_cart
!> @brief Return the axis data.
SUBROUTINE get_diag_axis_data(id, DATA)
INTEGER, INTENT(in) :: id !< Axis ID
REAL, DIMENSION(:), INTENT(out) :: DATA !< Axis data
CALL valid_id_check(id, 'get_diag_axis_data')
IF (Axes(id)%length > SIZE(DATA(:))) THEN
! <ERROR STATUS="FATAL">array data is too small</ERROR>
CALL error_mesg('diag_axis_mod::get_diag_axis_data', 'array data is too small', FATAL)
ELSE
DATA(1:Axes(id)%length) = Axes(id)%data
END IF
END SUBROUTINE get_diag_axis_data
!> @brief Return the short name of the axis.
SUBROUTINE get_diag_axis_name(id, axis_name)
INTEGER , INTENT(in) :: id !< Axis ID
CHARACTER(len=*), INTENT(out) :: axis_name !< Axis short name
if (use_modern_diag) then
axis_name = fms_diag_object%fms_get_axis_name_from_id(id)
else
CALL valid_id_check(id, 'get_diag_axis_name')
axis_name = Axes(id)%name
endif
END SUBROUTINE get_diag_axis_name
!> @brief Return the name of the axis' domain
SUBROUTINE get_diag_axis_domain_name(id, name)
INTEGER, INTENT(in) :: id !< Axis ID
CHARACTER(len=*), INTENT(out) :: name !< Axis' domain name
CALL valid_id_check(id, 'get_diag_axis_domain_name')
name = mpp_get_domain_name(Axes(id)%domain2)
END SUBROUTINE get_diag_axis_domain_name
!> @brief Return the length of the axis.
!> @return length of axis as an integer
INTEGER FUNCTION get_axis_length(id)
INTEGER, INTENT(in) :: id !< Axis ID
INTEGER :: length
if (use_modern_diag) then
get_axis_length = fms_diag_object%fms_get_axis_length(id)
else
CALL valid_id_check(id, 'get_axis_length')
IF ( Axes(id)%Domain .NE. null_domain1d ) THEN
CALL mpp_get_compute_domain(Axes(id)%Domain,size=length)
!---one extra point is needed for some case. ( like symmetry domain )
get_axis_length = length + Axes(id)%shift
ELSE
get_axis_length = Axes(id)%length
END IF
endif
END FUNCTION get_axis_length
!> @brief Return the auxiliary name for the axis.
!! @return auxiliary name for the axis
CHARACTER(len=128) FUNCTION get_axis_aux(id)
INTEGER, INTENT(in) :: id !< Axis ID
CALL valid_id_check(id, 'get_axis_aux')
get_axis_aux = Axes(id)%aux
END FUNCTION get_axis_aux
!> @brief Return the required field names for the axis.
!! @return required field names for the axis
CHARACTER(len=128) FUNCTION get_axis_reqfld(id)
INTEGER, INTENT(in) :: id !< Axis ID
CALL valid_id_check(id, 'get_axis_reqfld')
get_axis_reqfld = Axes(id)%req
END FUNCTION get_axis_reqfld
!> @brief Return the global length of the axis.
!! @return global length of the axis
INTEGER FUNCTION get_axis_global_length(id)
INTEGER, INTENT(in) :: id !< Axis ID
CALL valid_id_check(id, 'get_axis_global_length')
get_axis_global_length = Axes(id)%length
END FUNCTION get_axis_global_length
!> @brief Return the tile count for the axis.
!! @return tile count for the axis
INTEGER FUNCTION get_tile_count(ids)
INTEGER, DIMENSION(:), INTENT(in) :: ids !< Axis IDs.
!! Possible dimensions: 1 <= <TT>size(ids(:))</TT> <= 4.
INTEGER :: i, id, flag
IF ( SIZE(ids(:)) < 1 ) THEN
! <ERROR STATUS="FATAL">input argument has incorrect size.</ERROR>
CALL error_mesg('diag_axis_mod::get_tile_count', 'input argument has incorrect size', FATAL)
END IF
get_tile_count = 1
flag = 0
DO i = 1, SIZE(ids(:))
id = ids(i)
CALL valid_id_check(id, 'get_tile_count')
IF ( Axes(id)%cart_name == 'X' .OR. &
Axes(id)%cart_name == 'Y' ) flag = flag + 1
! --- both x/y axes found ---
IF ( flag == 2 ) THEN
get_tile_count = Axes(id)%tile_count
EXIT
END IF
END DO
END FUNCTION get_tile_count
!> @brief Retrun the 1D domain for the axis ID given.
!! @return 1D domain for the axis ID given
TYPE(domain1d) FUNCTION get_domain1d(id)
INTEGER, INTENT(in) :: id !< Axis ID
CALL valid_id_check(id, 'get_domain1d')
IF (Axes(id)%Domain .NE. NULL_DOMAIN1D) THEN
get_domain1d = Axes(id)%Domain
ELSE
get_domain1d = NULL_DOMAIN1D
ENDIF
END FUNCTION get_domain1d
!> @brief Return the 2D domain for the axis IDs given.
!! @return 2D domain for the axis IDs given
TYPE(domain2d) FUNCTION get_domain2d(ids)
INTEGER, DIMENSION(:), INTENT(in) :: ids !< Axis IDs.
!! Possible dimensions: 1 <= <TT>size(ids(:))</TT> <= 4.
INTEGER :: i, id, flag
IF ( SIZE(ids(:)) < 1 ) THEN
! <ERROR STATUS="FATAL">input argument has incorrect size.</ERROR>
CALL error_mesg('diag_axis_mod::get_domain2d', 'input argument has incorrect size', FATAL)
END IF
if (use_modern_diag) then
get_domain2d = fms_diag_object%fms_get_domain2d(ids)
return
endif
get_domain2d = null_domain2d
flag = 0
DO i = 1, SIZE(ids(:))
id = ids(i)
CALL valid_id_check(id, 'get_domain2d')
IF ( Axes(id)%cart_name == 'X' .OR. Axes(id)%cart_name == 'Y' ) flag = flag + 1
! --- both x/y axes found ---
IF ( flag == 2 ) THEN
IF (Axes(id)%Domain2 .NE. NULL_DOMAIN2D) get_domain2d = Axes(id)%Domain2
EXIT
END IF
END DO
END FUNCTION get_domain2d
!> @brief Retrun the 1D domain for the axis ID given.
!! @return 1D domain for the axis ID given
TYPE(domainUG) FUNCTION get_domainUG(id)
INTEGER, INTENT(in) :: id !< Axis ID
CALL valid_id_check(id, 'get_domainUG')
IF (Axes(id)%DomainUG .NE. NULL_DOMAINUG) THEN
get_domainUG = Axes(id)%DomainUG
ELSE
get_domainUG = NULL_DOMAINUG
ENDIF
END FUNCTION get_domainUG
!ug support
!> @brief Checks if the axes are compatible
!! @return integer domain_type
function axis_compatible_check(id,varname) result(domain_type)
!Inputs/Outputs
integer,dimension(:),intent(in) :: id !<The array of axis IDs
character(*),intent(in),optional :: varname !<The name of the variable
integer(I4_KIND) :: domain_type !<DIAG_AXIS_NODOMAIN = no domain.
!<DIAG_AXIS_2DDOMAIN = structured domain.
!<DIAG_AXIS_UGDOMAIN = unstructured domain.
!Local variables
logical :: XorY !<XorY set to true if X or Y is found as a cart_name.
logical :: UG !<UG set to true if U is found as a cart_name.
integer :: n !<Looping index.
logical :: uses_domain2D !<True if an axis is associated with a 2D domain.
logical :: uses_domainUG !<True if an axis is associated with an unstructured domain.
!Initialize flags.
XorY = .false.
UG = .false.
uses_domain2D = .false.
uses_domainUG = .false.
!Make sure that valid set of axes was passed, and determine the domain-type
!associated with the axes.
do n = 1,size(id)
call valid_id_check(id(n), &
"axis_compatible_check")
if (Axes(id(n))%cart_name .eq. "X" .or. &
Axes(id(n))%cart_name .eq. "Y") then
XorY = .true.
elseif (Axes(id(n))%cart_name .eq. "U") then
UG = .true.
endif
if (Axes(id(n))%Domain2 .ne. null_domain2d) then
uses_domain2D = .true.
elseif (Axes(id(n))%DomainUG .ne. null_domainUG) then
uses_domainUG = .true.
endif
enddo
if (UG .and. XorY) then
if (present(varname)) then
call error_mesg("axis_compatible_check", &
"Can not use an unstructured grid with a "// &
"horizontal cartesian coordinate for the field " &
//trim(varname), &
FATAL)
else
call error_mesg("axis_compatible_check", &
"Can not use an unstructured grid with a horizontal "// &
"cartesian coordinate", &
FATAL)
endif
endif
if (uses_domain2D .and. uses_domainUG) then
if (present(varname)) then
call error_mesg("axis_compatible_check", &
"Can not use an unstructured grid with a"// &
"structured grid for the field "//trim(varname), &
FATAL)
else
call error_mesg("axis_compatible_check", &
"Can not use an unstructured grid with a"// &
"structured grid.", &
FATAL)
endif
endif
if (uses_domain2D) then
domain_type = DIAG_AXIS_2DDOMAIN
elseif (uses_domainUG) then
domain_type = DIAG_AXIS_UGDOMAIN
else
domain_type = DIAG_AXIS_NODOMAIN
endif
return
end function axis_compatible_check
!> @brief Return the value of the shift for the axis IDs given.
SUBROUTINE get_axes_shift(ids, ishift, jshift)
INTEGER, DIMENSION(:), INTENT(in) :: ids
INTEGER, INTENT(out) :: ishift !< X shift value.
INTEGER, INTENT(out) :: jshift !< Y shift value.
INTEGER :: i, id
!-- get the value of the shift.
ishift = 0
jshift = 0
DO i = 1, SIZE(ids(:))
id = ids(i)
CALL valid_id_check(id, 'get_axes_shift')
SELECT CASE (Axes(id)%cart_name)
CASE ( 'X' )
ishift = Axes(id)%shift
CASE ( 'Y' )
jshift = Axes(id)%shift
END SELECT
END DO
END SUBROUTINE get_axes_shift
!> @brief Returns index into axis table corresponding to a given axis name.
!! @return Returns index into axis table corresponding to a given axis name.
INTEGER FUNCTION get_axis_num(axis_name, set_name)
CHARACTER(len=*), INTENT(in) :: axis_name !< Axis name
CHARACTER(len=*), INTENT(in), OPTIONAL :: set_name !< Set name
INTEGER :: set, n
IF ( PRESENT(set_name) ) THEN
set = get_axis_set_num (TRIM(set_name))
ELSE
set = 0
END IF
get_axis_num = 0
DO n = 1, num_def_axes
IF ( TRIM(axis_name) == TRIM(Axes(n)%name) .AND. Axes(n)%set == set ) THEN
get_axis_num = n
RETURN
END IF
END DO
END FUNCTION get_axis_num
!> @brief Returns index in axis set table corresponding to a given axis set name
!! @return Returns index in axis set table corresponding to a given axis set name
INTEGER FUNCTION get_axis_set_num (set_name)
CHARACTER(len=*), INTENT(in) :: set_name !< Set name
INTEGER :: iset
get_axis_set_num = 0
DO iset = 1, num_axis_sets
IF ( set_name == Axis_sets(iset) ) THEN
get_axis_set_num = iset
RETURN
END IF
END DO
END FUNCTION get_axis_set_num
!> @brief Check to see if the given axis id is a valid id. If the axis id is invalid,
!! call a FATAL error. If the ID is valid, just return.
SUBROUTINE valid_id_check(id, routine_name)
INTEGER, INTENT(in) :: id !< Axis is to check for validity
CHARACTER(len=*), INTENT(in) :: routine_name !< Name of the subroutine checking for a valid axis id
CHARACTER(len=5) :: emsg
IF ( id < 1 .OR. id > num_def_axes) THEN
! <ERROR STATUS="FATAL">
! Illegal value for axis used (value <VALUE>).
! </ERROR>
WRITE (emsg, '(I2)') id
CALL error_mesg('diag_axis_mod::'//TRIM(routine_name),&
& 'Illegal value for axis_id used (value '//TRIM(emsg)//').', FATAL)
END IF
END SUBROUTINE valid_id_check
SUBROUTINE diag_axis_attribute_init(diag_axis_id, name, type, cval, ival, rval)
INTEGER, INTENT(in) :: diag_axis_id !< input field ID, obtained from diag_axis_mod::diag_axis_init.
CHARACTER(len=*) :: name !< Name of the attribute
INTEGER, INTENT(in) :: type !< NetCDF type (NF_FLOAT, NF_INT, NF_CHAR)
CHARACTER(len=*), INTENT(in), OPTIONAL :: cval !< Character string attribute value
INTEGER, DIMENSION(:), INTENT(in), OPTIONAL :: ival !< Integer attribute value(s)
REAL, DIMENSION(:), INTENT(in), OPTIONAL :: rval !< Real attribute value(s)
INTEGER :: istat, length, i, this_attribute
CHARACTER(len=1024) :: err_msg
IF ( .NOT.first_send_data_call ) THEN
! Call error due to unable to add attribute after send_data called
! <ERROR STATUS="FATAL">
! Attempting to add attribute <name> to axis <axis_name>
! after first send_data call. Too late.
! </ERROR>
CALL error_mesg('diag_manager_mod::diag_axis_add_attribute', 'Attempting to add attribute "'&
&//TRIM(name)//'" to axis after first send_data call. Too late.', FATAL)
END IF
! Simply return if diag_axis_id <= 0 --- not registered
IF ( diag_axis_id .LE. 0 ) THEN
RETURN
ELSE IF ( diag_axis_id .GT. num_def_axes ) THEN
! Call error axis_id greater than num_def_axes. Axis is unknown
! <ERROR STATUS="FATAL">
! Attempting to add attribute <name> to axis ID <axis_ID>, however ID unknown.
! </ERROR>
WRITE(err_msg, '(I5)') diag_axis_id
CALL error_mesg('diag_manager_mod::diag_axis_add_attribute', 'Attempting to add attribute "'&
&//TRIM(name)//'" to axis ID "'//TRIM(err_msg)//'", however ID unknown.', FATAL)
ELSE
! Allocate memory for the attributes
CALL attribute_init_axis(Axes(diag_axis_id))
! Check if attribute already exists
this_attribute = 0
DO i=1, Axes(diag_axis_id)%num_attributes
IF ( TRIM(Axes(diag_axis_id)%attributes(i)%name) .EQ. TRIM(name) ) THEN
this_attribute = i
EXIT
END IF
END DO
IF ( this_attribute.NE.0 .AND. (type.EQ.NF90_INT .OR. type.EQ.NF90_FLOAT) ) THEN
! <ERROR STATUS="FATAL">
! Attribute <name> already defined for axis <axis_name>.
! Contact the developers
! </ERROR>
CALL error_mesg('diag_manager_mod::diag_axis_add_attribute',&
& 'Attribute "'//TRIM(name)//'" already defined for axis "'&
&//TRIM(Axes(diag_axis_id)%name)//'". Contact the developers.', FATAL)
ELSE IF ( this_attribute.NE.0 .AND. type.EQ.NF90_CHAR .AND. debug_diag_manager ) THEN
! <ERROR STATUS="NOTE">
! Attribute <name> already defined for axis <axis_name>.
! Prepending.
! </ERROR>
CALL error_mesg('diag_manager_mod::diag_axis_add_attribute',&
& 'Attribute "'//TRIM(name)//'" already defined for axis"'&
&//TRIM(Axes(diag_axis_id)%name)//'". Prepending.', NOTE)
ELSE
! Defining a new attribute
! Increase the number of field attributes
this_attribute = Axes(diag_axis_id)%num_attributes + 1
! Checking to see if num_attributes == max_axis_attributes, and return error message
IF ( this_attribute .GT. max_axis_attributes ) THEN
! <ERROR STATUS="FATAL">
! Number of attributes exceeds max_axis_attributes for attribute <name> for axis <axis_name>.
! Increase diag_manager_nml:max_axis_attributes.
! </ERROR>
CALL error_mesg('diag_manager_mod::diag_axis_add_attribute',&
& 'Number of attributes exceeds max_axis_attributes for attribute "'&
& //TRIM(name)//'" for axis "'//TRIM(Axes(diag_axis_id)%name)&
& //'". Increase diag_manager_nml:max_axis_attributes.',&
& FATAL)
ELSE
Axes(diag_axis_id)%num_attributes = this_attribute
! Set name and type
Axes(diag_axis_id)%attributes(this_attribute)%name = name
Axes(diag_axis_id)%attributes(this_attribute)%type = type
! Initialize catt to a blank string, as len_trim doesn't always work on an uninitialized string
Axes(diag_axis_id)%attributes(this_attribute)%catt = ''
END IF
END IF
SELECT CASE (type)
CASE (NF90_INT)
IF ( .NOT.PRESENT(ival) ) THEN
! <ERROR STATUS="FATAL">
! Number type claims INTEGER, but ival not present for attribute <name> for axis <axis_name>.
! Contact the developers.
! </ERROR>
CALL error_mesg('diag_manager_mod::diag_axis_add_attribute',&
& 'Attribute type claims INTEGER, but ival not present for attribute "'&
& //TRIM(name)//'" for axis "'//TRIM(Axes(diag_axis_id)%name)&
& //'". Contact the developers.', FATAL)
END IF