Skip to content

Commit 6b34353

Browse files
committed
EAMxx: alias only outputs, fix docs
1 parent c87cb8d commit 6b34353

File tree

5 files changed

+24
-62
lines changed

5 files changed

+24
-62
lines changed

components/eamxx/docs/user/io_aliases.md

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ alias_name:=internal_field_name
2626
### Basic Usage
2727

2828
```yaml
29-
field_names:
30-
- "LWP:=LiqWaterPath" # Alias LWP for LiqWaterPath
31-
- "SWP:=SolidWaterPath" # Alias SWP for SolidWaterPath
32-
- "T:=T_mid" # Alias T for T_mid
33-
- "qv" # Regular field name (no alias)
29+
field_names:
30+
- "LWP:=LiqWaterPath" # Alias LWP for LiqWaterPath
31+
- "SWP:=SolidWaterPath" # Alias SWP for SolidWaterPath
32+
- "T:=T_mid" # Alias T for T_mid
33+
- "qv" # Regular field name (no alias)
3434
```
3535
3636
### Mixed Usage
@@ -39,9 +39,9 @@ You can mix aliased and non-aliased fields in the same configuration:
3939
4040
```yaml
4141
field_names:
42-
- "T_mid" # Regular field name
42+
- "T_mid" # Regular field name
4343
- "LWP:=LiqWaterPath" # Aliased field
44-
- "ps" # Regular field name
44+
- "p_mid" # Regular field name
4545
- "RH:=RelativeHumidity" # Aliased field
4646
```
4747
@@ -64,30 +64,13 @@ original field names
6464
- Memory management uses original field structures
6565

6666
3. **Metadata**: Variable attributes (units, long_name, etc.)
67-
are preserved from the original fields
68-
69-
## Input Reading
70-
71-
The same alias syntax works for reading input files:
72-
73-
```yaml
74-
input_streams:
75-
initial_conditions:
76-
filename: ic_file.nc
77-
field_names:
78-
- "LWP:=LiqWaterPath" # Read variable LWP from file into field LiqWaterPath
79-
- "T:=T_mid" # Read variable T from file into field T_mid
80-
```
81-
82-
## Error Handling
83-
84-
The system provides comprehensive error checking:
67+
are preserved from the original fields, and `eamxx_name`
68+
is added to the netcdf files to document aliasing
8569

86-
- **Duplicate Aliases**: Each alias must be unique within a field list
87-
- **Malformed Syntax**: Proper error messages for invalid alias specifications
88-
- **Empty Names**: Both alias and field names must be non-empty
70+
## Caveats
8971

90-
Example error cases:
72+
Currently, a field can be requested only once in a single stream,
73+
and either the original name or the alias name counts.
9174

9275
```yaml
9376
field_names:

components/eamxx/src/share/io/scorpio_input.cpp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,7 @@ init (const ekat::ParameterList& params,
8282
"Error! Input class was already inited.\n");
8383

8484
m_params = params;
85-
86-
// Get field specifications and process aliases
87-
std::vector<std::string> field_specs = m_params.get<decltype(field_specs)>("field_names");
88-
auto [alias_to_field_map, alias_names] = process_field_aliases(field_specs);
89-
m_alias_to_field_map = alias_to_field_map;
90-
m_alias_names = alias_names;
91-
92-
// Extract internal field names for field manager operations
93-
m_fields_names.clear();
94-
for (const auto& spec : field_specs) {
95-
auto [alias, field_name] = parse_field_alias(spec);
96-
m_fields_names.push_back(field_name);
97-
}
98-
85+
m_fields_names = m_params.get<decltype(m_fields_names)>("field_names");
9986
m_filename = m_params.get<std::string>("filename");
10087

10188
// Sets the internal field mgr, and possibly sets up the remapper
@@ -212,38 +199,35 @@ void AtmosphereInput::read_variables (const int time_index)
212199
if (m_atm_logger) {
213200
m_atm_logger->info("[EAMxx::scorpio_input] Reading variables from file");
214201
m_atm_logger->info(" file name: " + m_filename);
215-
m_atm_logger->info(" var names: " + ekat::join(m_alias_names,", "));
202+
m_atm_logger->info(" var names: " + ekat::join(m_fields_names,", "));
216203
if (time_index!=-1) {
217204
m_atm_logger->info(" time idx : " + std::to_string(time_index));
218205
}
219206
}
220207
EKAT_REQUIRE_MSG (m_fields_inited and m_scorpio_inited,
221208
"Error! Internal structures not fully inited yet. Did you forget to call 'init(..)'?\n");
222209

223-
for (size_t i = 0; i < m_fields_names.size(); ++i) {
224-
const auto& field_name = m_fields_names[i];
225-
const auto& alias_name = m_alias_names[i];
210+
for (auto const& name : m_fields_names) {
226211

227-
auto f_scorpio = m_fm_for_scorpio->get_field(field_name);
228-
auto f_user = m_fm_from_user->get_field(field_name);
212+
auto f_scorpio = m_fm_for_scorpio->get_field(name);
213+
auto f_user = m_fm_from_user->get_field(name);
229214

230-
// Read the data using alias name for netcdf variable
215+
// Read the data
231216
switch (f_scorpio.data_type()) {
232217
case DataType::DoubleType:
233-
scorpio::read_var(m_filename,alias_name,f_scorpio.get_internal_view_data<double,Host>(),time_index);
218+
scorpio::read_var(m_filename,name,f_scorpio.get_internal_view_data<double,Host>(),time_index);
234219
break;
235220
case DataType::FloatType:
236-
scorpio::read_var(m_filename,alias_name,f_scorpio.get_internal_view_data<float,Host>(),time_index);
221+
scorpio::read_var(m_filename,name,f_scorpio.get_internal_view_data<float,Host>(),time_index);
237222
break;
238223
case DataType::IntType:
239-
scorpio::read_var(m_filename,alias_name,f_scorpio.get_internal_view_data<int,Host>(),time_index);
224+
scorpio::read_var(m_filename,name,f_scorpio.get_internal_view_data<int,Host>(),time_index);
240225
break;
241226
default:
242227
EKAT_ERROR_MSG (
243228
"Error! Unsupported/unrecognized data type while reading field from file.\n"
244229
" - file name : " + m_filename + "\n"
245-
" - field name: " + field_name + "\n"
246-
" - alias name: " + alias_name + "\n");
230+
" - field name: " + name + "\n");
247231
}
248232

249233
f_scorpio.sync_to_dev();

components/eamxx/src/share/io/scorpio_input.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "share/field/field_manager.hpp"
55
#include "share/grid/abstract_grid.hpp"
6-
#include "share/io/eamxx_io_utils.hpp"
76

87
#include "ekat/ekat_parameter_list.hpp"
98
#include "ekat/logging/ekat_logger.hpp"
@@ -123,10 +122,6 @@ class AtmosphereInput
123122
std::string m_filename;
124123
std::vector<std::string> m_fields_names;
125124

126-
// Field aliasing support
127-
std::map<std::string, std::string> m_alias_to_field_map; // Map from alias names to internal field names
128-
std::vector<std::string> m_alias_names; // List of alias names (for netcdf variables)
129-
130125
bool m_fields_inited = false;
131126
bool m_scorpio_inited = false;
132127

components/eamxx/src/share/io/scorpio_output.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,7 @@ register_variables(const std::string& filename,
753753

754754
// Add alias information if variable name differs from field name
755755
if (alias_name != field_name) {
756-
scorpio::set_attribute(filename, alias_name, "eamxx_alias", alias_name);
757-
scorpio::set_attribute(filename, alias_name, "eamxx_field_name", field_name);
756+
scorpio::set_attribute(filename, alias_name, "eamxx_name", field_name);
758757
}
759758
}
760759
}

components/eamxx/src/share/util/eamxx_data_interpolation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ DataInterpolation (const std::shared_ptr<const AbstractGrid>& model_grid,
3333
using namespace ShortFieldTagsNames;
3434
m_input_files_dimnames[COL] = "ncol";
3535
m_input_files_dimnames[LEV] = "lev";
36+
e2str(LEV);
3637
}
3738

3839
void DataInterpolation::run (const util::TimeStamp& ts)

0 commit comments

Comments
 (0)