Skip to content

Commit e75b59a

Browse files
committed
add volg to init.nc and add a new stream property gattr_update to turn on/off the update of global attributes (#12)
* add volg into the scalars for init_atmosphere * add a new property 'gattr_update' to MPAS streams * Only update the 'output_interval' global attribute when gattr_update=yes * fine tune * only do 'mpas_writeStreamAtt' if stream%gattr_update=yes * remove the redundant 'if (stream % gattr_update == MPAS_STREAM_GATTR_UPDATE_YES) then'
1 parent deee49b commit e75b59a

5 files changed

Lines changed: 90 additions & 11 deletions

File tree

src/core_init_atmosphere/Registry.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,10 @@
12581258
<var name="nwfa" array_group="number" units="nb kg^{-1}"
12591259
description="Gocart water-friendly aerosol number concentration"
12601260
packages="mp_thompson_aers_in;tempo_aerosolaware_in"/>
1261+
1262+
<var name="volg" array_group="volume" units="m^{3} kg^{-1}"
1263+
description="Graupel particle volume"
1264+
packages="mp_thompson_aers_in;tempo_aerosolaware_in"/>
12611265
</var_array>
12621266
12631267
<!-- Climatology for ocean mixed-layer depth -->

src/framework/mpas_stream_list_types.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
integer :: nRecords
2323
integer :: precision = MPAS_IO_NATIVE_PRECISION
2424
integer :: clobber_mode
25+
integer :: gattr_update = 1
2526
integer :: io_type
2627
type (MPAS_TimeInterval_type), pointer :: recordInterval => null()
2728
type (MPAS_stream_list_type), pointer :: alarmList_in => null()

src/framework/mpas_stream_manager.F

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ end subroutine MPAS_stream_mgr_finalize!}}}
315315
!-----------------------------------------------------------------------
316316
subroutine MPAS_stream_mgr_create_stream(manager, streamID, direction, filename, &
317317
filenameInterval, referenceTime, recordInterval, &
318-
realPrecision, clobberMode, ioType, ierr) !{{{
318+
realPrecision, clobberMode, gattrUpdate, ioType, ierr) !{{{
319319

320320
use mpas_io, only : MPAS_IO_PNETCDF
321321

@@ -332,6 +332,7 @@ subroutine MPAS_stream_mgr_create_stream(manager, streamID, direction, filename,
332332
type (MPAS_TimeInterval_type), intent(in), optional :: recordInterval
333333
integer, intent(in), optional :: realPrecision
334334
integer, intent(in), optional :: clobberMode
335+
integer, intent(in), optional :: gattrUpdate
335336
integer, intent(in), optional :: ioType
336337
integer, intent(out), optional :: ierr
337338

@@ -379,6 +380,11 @@ subroutine MPAS_stream_mgr_create_stream(manager, streamID, direction, filename,
379380
else
380381
new_stream % clobber_mode = MPAS_STREAM_CLOBBER_NEVER
381382
end if
383+
if (present(gattrUpdate)) then
384+
new_stream % gattr_update = gattrUpdate
385+
else
386+
new_stream % gattr_update = MPAS_STREAM_GATTR_UPDATE_YES
387+
end if
382388
if (present(ioType)) then
383389
new_stream % io_type = ioType
384390
else
@@ -1772,6 +1778,9 @@ subroutine MPAS_stream_mgr_set_property_int(manager, streamID, propertyName, pro
17721778
case (MPAS_STREAM_PROPERTY_CLOBBER)
17731779
stream_cursor % clobber_mode = propertyValue
17741780

1781+
case (MPAS_STREAM_PROPERTY_GATTR_UPDATE)
1782+
stream_cursor % gattr_update = propertyValue
1783+
17751784
case (MPAS_STREAM_PROPERTY_IOTYPE)
17761785
stream_cursor % io_type = propertyValue
17771786

@@ -2005,6 +2014,9 @@ subroutine MPAS_stream_mgr_get_property_int(manager, streamID, propertyName, pro
20052014
case (MPAS_STREAM_PROPERTY_CLOBBER)
20062015
propertyValue = stream_cursor % clobber_mode
20072016

2017+
case (MPAS_STREAM_PROPERTY_GATTR_UPDATE)
2018+
propertyValue = stream_cursor % gattr_update
2019+
20082020
case (MPAS_STREAM_PROPERTY_IOTYPE)
20092021
propertyValue = stream_cursor % io_type
20102022

@@ -4244,7 +4256,7 @@ end subroutine gen_random
42444256
integer :: output_interval
42454257
type (MPAS_timeInterval_type) :: filename_interval
42464258

4247-
if (direction == MPAS_STREAM_OUTPUT) then
4259+
if (direction == MPAS_STREAM_OUTPUT .and. stream % gattr_update == MPAS_STREAM_GATTR_UPDATE_YES) then
42484260

42494261
!
42504262
! Write attributes to stream
@@ -5712,7 +5724,7 @@ end subroutine MPAS_stream_mgr_begin_iteration !}}}
57125724
logical function MPAS_stream_mgr_get_next_stream(manager, streamID, directionProperty, activeProperty, & !{{{
57135725
immutableProperty, filenameTemplateProperty, &
57145726
referenceTimeProperty, recordIntervalProperty, precisionProperty, &
5715-
filenameIntervalProperty, clobberProperty) result(validStream)
5727+
filenameIntervalProperty, clobberProperty, gattrUpdateProperty) result(validStream)
57165728
57175729
implicit none
57185730
@@ -5727,6 +5739,7 @@ logical function MPAS_stream_mgr_get_next_stream(manager, streamID, directionPro
57275739
integer, intent(out), optional :: precisionProperty !< Output: Integer describing the precision of the stream
57285740
character (len=StrKIND), intent(out), optional :: filenameIntervalProperty !< Output: String containing the filename interval for the stream
57295741
integer, intent(out), optional :: clobberProperty !< Output: Interger describing the clobber mode of the stream
5742+
integer, intent(out), optional :: gattrUpdateProperty !< Output: Interger describing whether to update global attributes
57305743
57315744
integer :: threadNum
57325745
@@ -5794,6 +5807,10 @@ logical function MPAS_stream_mgr_get_next_stream(manager, streamID, directionPro
57945807
clobberProperty = manager % currentStream % clobber_mode
57955808
end if
57965809
5810+
if ( present(gattrUpdateProperty) ) then
5811+
gattrUpdateProperty = manager % currentStream % gattr_update
5812+
end if
5813+
57975814
end function MPAS_stream_mgr_get_next_stream !}}}
57985815
57995816
@@ -5916,7 +5933,7 @@ end module mpas_stream_manager
59165933
59175934
59185935
subroutine stream_mgr_create_stream_c(manager_c, streamID_c, direction_c, filename_c, filename_intv_c, ref_time_c, rec_intv_c, &
5919-
immutable_c, precision_c, clobber_c, iotype_c, ierr_c) bind(c) !{{{
5936+
immutable_c, precision_c, clobber_c, gattr_update_c, iotype_c, ierr_c) bind(c) !{{{
59205937
59215938
use mpas_c_interfacing, only : mpas_c_to_f_string
59225939
use iso_c_binding, only : c_char, c_int, c_ptr, c_f_pointer
@@ -5925,7 +5942,8 @@ subroutine stream_mgr_create_stream_c(manager_c, streamID_c, direction_c, filena
59255942
MPAS_STREAM_PROPERTY_FILENAME_INTV, MPAS_STREAM_PROPERTY_REF_TIME, &
59265943
MPAS_STREAM_PROPERTY_RECORD_INTV, MPAS_STREAM_PROPERTY_PRECISION, &
59275944
MPAS_STREAM_PROPERTY_CLOBBER, MPAS_STREAM_CLOBBER_NEVER, MPAS_STREAM_CLOBBER_APPEND, &
5928-
MPAS_STREAM_CLOBBER_TRUNCATE, MPAS_STREAM_CLOBBER_OVERWRITE, MPAS_STREAM_PROPERTY_IOTYPE
5945+
MPAS_STREAM_CLOBBER_TRUNCATE, MPAS_STREAM_CLOBBER_OVERWRITE, MPAS_STREAM_PROPERTY_IOTYPE, &
5946+
MPAS_STREAM_PROPERTY_GATTR_UPDATE, MPAS_STREAM_GATTR_UPDATE_YES, MPAS_STREAM_GATTR_UPDATE_NO
59295947
use mpas_stream_manager, only : MPAS_stream_mgr_create_stream, MPAS_stream_mgr_set_property
59305948
use mpas_kind_types, only : StrKIND
59315949
use mpas_derived_types, only : MPAS_LOG_ERR
@@ -5945,13 +5963,14 @@ subroutine stream_mgr_create_stream_c(manager_c, streamID_c, direction_c, filena
59455963
integer(kind=c_int) :: immutable_c
59465964
integer(kind=c_int) :: precision_c
59475965
integer(kind=c_int) :: clobber_c
5966+
integer(kind=c_int) :: gattr_update_c
59485967
integer(kind=c_int) :: iotype_c
59495968
integer(kind=c_int) :: ierr_c
59505969
59515970
type (MPAS_streamManager_type), pointer :: manager
59525971
character(len=StrKIND) :: streamID, filename, filename_interval, reference_time, record_interval
59535972
integer :: direction, immutable, prec, ierr
5954-
integer :: clobber_mode, iotype
5973+
integer :: clobber_mode, iotype, gattr_update
59555974
59565975
call c_f_pointer(manager_c, manager)
59575976
call mpas_c_to_f_string(streamID_c, streamID)
@@ -5982,6 +6001,12 @@ subroutine stream_mgr_create_stream_c(manager_c, streamID_c, direction_c, filena
59826001
clobber_mode = MPAS_STREAM_CLOBBER_NEVER
59836002
end if
59846003
6004+
if (gattr_update_c == 0) then
6005+
gattr_update = MPAS_STREAM_GATTR_UPDATE_NO
6006+
else
6007+
gattr_update = MPAS_STREAM_GATTR_UPDATE_YES
6008+
end if
6009+
59856010
if (iotype_c == 0) then
59866011
iotype = MPAS_IO_PNETCDF
59876012
else if (iotype_c == 1) then
@@ -6017,10 +6042,11 @@ subroutine stream_mgr_create_stream_c(manager_c, streamID_c, direction_c, filena
60176042
end if
60186043
call MPAS_stream_mgr_set_property(manager, streamID, MPAS_STREAM_PROPERTY_PRECISION, prec, ierr=ierr)
60196044
call MPAS_stream_mgr_set_property(manager, streamID, MPAS_STREAM_PROPERTY_CLOBBER, clobber_mode, ierr=ierr)
6045+
call MPAS_stream_mgr_set_property(manager, streamID, MPAS_STREAM_PROPERTY_GATTR_UPDATE, gattr_update, ierr=ierr)
60206046
call MPAS_stream_mgr_set_property(manager, streamID, MPAS_STREAM_PROPERTY_IOTYPE, iotype, ierr=ierr)
60216047
else
60226048
call MPAS_stream_mgr_create_stream(manager, streamID, direction, filename, realPrecision=prec, &
6023-
clobberMode=clobber_mode, ioType=iotype, ierr=ierr)
6049+
clobberMode=clobber_mode, gattrUpdate=gattr_update, ioType=iotype, ierr=ierr)
60246050
end if
60256051
60266052
if (reference_time /= 'initial_time') then

src/framework/mpas_stream_manager_types.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
MPAS_STREAM_PROPERTY_PRECISION = 10, &
2121
MPAS_STREAM_PROPERTY_FILENAME_INTV = 11, &
2222
MPAS_STREAM_PROPERTY_CLOBBER = 12, &
23-
MPAS_STREAM_PROPERTY_IOTYPE = 13
23+
MPAS_STREAM_PROPERTY_IOTYPE = 13, &
24+
MPAS_STREAM_PROPERTY_GATTR_UPDATE = 14
2425

2526
integer, public, parameter :: MPAS_STREAM_CLOBBER_NEVER = 100, &
2627
MPAS_STREAM_CLOBBER_APPEND = 101, &
2728
MPAS_STREAM_CLOBBER_TRUNCATE = 102, &
2829
MPAS_STREAM_CLOBBER_OVERWRITE = 103
2930

31+
integer, public, parameter :: MPAS_STREAM_GATTR_UPDATE_YES = 201, &
32+
MPAS_STREAM_GATTR_UPDATE_NO = 200
33+
3034
type MPAS_streamManager_type
3135

3236
integer :: numStreams = 0

src/framework/xml_stream_parser.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/*
2626
* Interface routines for building streams at run-time; defined in mpas_stream_manager.F
2727
*/
28-
void stream_mgr_create_stream_c(void *, const char *, int *, const char *, const char *, const char *, const char *, int *, int *, int *, int *, int *);
28+
void stream_mgr_create_stream_c(void *, const char *, int *, const char *, const char *, const char *, const char *, int *, int *, int *, int *, int *, int *);
2929
void stream_mgr_add_field_c(void *, const char *, const char *, const char *, int *);
3030
void stream_mgr_add_immutable_stream_fields_c(void *, const char *, const char *, const char *, int *);
3131
void stream_mgr_add_pool_c(void *, const char *, const char *, const char *, int *);
@@ -1053,6 +1053,7 @@ void xml_stream_parser(char *fname, void *manager, int *mpi_comm, int *status)
10531053
const char *streamID, *filename_template, *filename_interval, *direction, *varfile, *fieldname_const, *reference_time, *record_interval, *streamname_const, *precision;
10541054
const char *interval_in, *interval_out, *packagelist;
10551055
const char *clobber;
1056+
const char *gattr_update;
10561057
const char *iotype;
10571058
const char *streamID2, *interval_in2, *interval_out2;
10581059
char interval_name[256];
@@ -1068,6 +1069,7 @@ void xml_stream_parser(char *fname, void *manager, int *mpi_comm, int *status)
10681069
char msgbuf[MSGSIZE];
10691070
int itype;
10701071
int iclobber;
1072+
int igattr_update;
10711073
int i_iotype;
10721074
int iprec;
10731075
int immutable;
@@ -1114,6 +1116,7 @@ void xml_stream_parser(char *fname, void *manager, int *mpi_comm, int *status)
11141116
precision = ezxml_attr(stream_xml, "precision");
11151117
packagelist = ezxml_attr(stream_xml, "packages");
11161118
clobber = ezxml_attr(stream_xml, "clobber_mode");
1119+
gattr_update = ezxml_attr(stream_xml, "gattr_update");
11171120
iotype = ezxml_attr(stream_xml, "io_type");
11181121

11191122
/* Extract the input interval, if it refer to other streams */
@@ -1236,6 +1239,26 @@ void xml_stream_parser(char *fname, void *manager, int *mpi_comm, int *status)
12361239
}
12371240
}
12381241

1242+
/* NB: These gattr_update constants must match those in the mpas_stream_manager module! */
1243+
igattr_update = 1;
1244+
if (gattr_update != NULL) {
1245+
if (strstr(gattr_update, "yes") != NULL) {
1246+
igattr_update = 1;
1247+
snprintf(msgbuf, MSGSIZE, " %-20s%s", "gattr_update:", "yes");
1248+
mpas_log_write_c(msgbuf, "MPAS_LOG_OUT");
1249+
}
1250+
else if (strstr(gattr_update, "no") != NULL) {
1251+
igattr_update = 0;
1252+
snprintf(msgbuf, MSGSIZE, " %-20s%s", "gattr_update:", "no");
1253+
mpas_log_write_c(msgbuf, "MPAS_LOG_OUT");
1254+
}
1255+
else {
1256+
igattr_update = 1;
1257+
snprintf(msgbuf, MSGSIZE, " *** unrecognized gattr_update specification; global attributes will be updated by default");
1258+
mpas_log_write_c(msgbuf, "MPAS_LOG_OUT");
1259+
}
1260+
}
1261+
12391262
/* NB: These io_type constants must match those in the mpas_stream_manager module! */
12401263
i_iotype = 0;
12411264
if (iotype != NULL) {
@@ -1337,7 +1360,7 @@ void xml_stream_parser(char *fname, void *manager, int *mpi_comm, int *status)
13371360
}
13381361

13391362
stream_mgr_create_stream_c(manager, streamID, &itype, filename_template, filename_interval_string, ref_time_local, rec_intv_local,
1340-
&immutable, &iprec, &iclobber, &i_iotype, &err);
1363+
&immutable, &iprec, &iclobber, &igattr_update, &i_iotype, &err);
13411364
if (err != 0) {
13421365
*status = 1;
13431366
return;
@@ -1423,6 +1446,7 @@ void xml_stream_parser(char *fname, void *manager, int *mpi_comm, int *status)
14231446
precision = ezxml_attr(stream_xml, "precision");
14241447
packagelist = ezxml_attr(stream_xml, "packages");
14251448
clobber = ezxml_attr(stream_xml, "clobber_mode");
1449+
gattr_update = ezxml_attr(stream_xml, "gattr_update");
14261450
iotype = ezxml_attr(stream_xml, "io_type");
14271451

14281452
/* Extract the input interval, if it refer to other streams */
@@ -1545,6 +1569,26 @@ void xml_stream_parser(char *fname, void *manager, int *mpi_comm, int *status)
15451569
}
15461570
}
15471571

1572+
/* NB: These gattr_update constants must match those in the mpas_stream_manager module! */
1573+
igattr_update = 1;
1574+
if (gattr_update != NULL) {
1575+
if (strstr(gattr_update, "yes") != NULL) {
1576+
igattr_update = 1;
1577+
snprintf(msgbuf, MSGSIZE, " %-20s%s", "gattr_update:", "yes");
1578+
mpas_log_write_c(msgbuf, "MPAS_LOG_OUT");
1579+
}
1580+
else if (strstr(gattr_update, "no") != NULL) {
1581+
igattr_update = 0;
1582+
snprintf(msgbuf, MSGSIZE, " %-20s%s", "gattr_update:", "no");
1583+
mpas_log_write_c(msgbuf, "MPAS_LOG_OUT");
1584+
}
1585+
else {
1586+
igattr_update = 1;
1587+
snprintf(msgbuf, MSGSIZE, " *** unrecognized gattr_update specification; global attributes will be updated by default");
1588+
mpas_log_write_c(msgbuf, "MPAS_LOG_OUT");
1589+
}
1590+
}
1591+
15481592
/* NB: These io_type constants must match those in the mpas_stream_manager module! */
15491593
i_iotype = 0;
15501594
if (iotype != NULL) {
@@ -1646,7 +1690,7 @@ void xml_stream_parser(char *fname, void *manager, int *mpi_comm, int *status)
16461690
}
16471691

16481692
stream_mgr_create_stream_c(manager, streamID, &itype, filename_template, filename_interval_string, ref_time_local, rec_intv_local,
1649-
&immutable, &iprec, &iclobber, &i_iotype, &err);
1693+
&immutable, &iprec, &iclobber, &igattr_update, &i_iotype, &err);
16501694
if (err != 0) {
16511695
*status = 1;
16521696
return;

0 commit comments

Comments
 (0)