From adfbaf64b5132b1be97bb3155ef6058451c11762 Mon Sep 17 00:00:00 2001
From: Karl-Hermann Wieners <karl-hermann.wieners@mpimet.mpg.de>
Date: Fri, 28 May 2021 18:10:31 +0200
Subject: [PATCH] Global: added file tags for 'output_nml' groups in
 'namelist2config'

---
 CHANGES.txt     |  1 +
 namelist2config | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/CHANGES.txt b/CHANGES.txt
index 685a570..c08e856 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -17,6 +17,7 @@ Global
 * Added 'files2config' tool to extract input file info from logs and scripts
 * Added variable replacement beta options to the '...2config' tools
 * Added output of file name in -d mode of 'namelist2config'
+* Added file tags for 'output_nml' groups in 'namelist2config'
 
 Configuration
 -------------
diff --git a/namelist2config b/namelist2config
index 4c8c31a..3385a12 100755
--- a/namelist2config
+++ b/namelist2config
@@ -190,6 +190,17 @@ unless($direct) {
     for my $file (sort keys %namelists) {
         print("  [[$file]]\n");
         $namelist_file = $namelists{$file};
+
+        # Replace TODO markers for output_nml by output_filename info
+        for my $group (grep(/^output_nml/, keys %$namelist_file)) {
+            $namelist_group = $namelist_file->{$group};
+            my $key = subst_value($namelist_group->{output_filename}->[0]);
+            $key =~ s/^\$\{EXP_ID\}_//;
+            $key = 'output_nml '.$key;
+            $namelist_file->{$key} = $namelist_group;
+            delete $namelist_file->{$group};
+        }
+
         for my $group (sort keys %$namelist_file) {
             print("    [[[$group]]]\n");
             $namelist_group = $namelist_file->{$group};
-- 
GitLab