Skip to content

Commit 55683c8

Browse files
K20shoresclaude
andcommitted
Fix nvhpc string corruption in dose_rates array concatenation
Replace Fortran array concatenation `[ handles_, key ]` with explicit temporary + reallocation for both handles_ and spectral_weights_ arrays. nvhpc 25.7 doesn't deep-copy allocatable character components in string_t during array concatenation, causing garbled variable names when writing dose_rates.nc. This matches the pattern already used in photolysis_rates.F90. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1c3a37a commit 55683c8

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/dose_rates.F90

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ function constructor( config, grid_warehouse, profile_warehouse ) &
8888
type(string_t) :: required_keys(1), optional_keys(1)
8989
type(string_t) :: rate_required_keys(2), rate_optional_keys(0)
9090
type(config_t) :: rate_config
91+
type(string_t), allocatable :: temp_handles(:)
92+
type(spectral_weight_ptr), allocatable :: temp_weights(:)
93+
integer :: i_elem
9194

9295
required_keys(1) = "rates"
9396
optional_keys(1) = "enable diagnostics"
@@ -131,14 +134,33 @@ function constructor( config, grid_warehouse, profile_warehouse ) &
131134
call wght_config%get( "weights", spectral_weight_config, Iam )
132135
call wght_config%get( "name", wght_key, Iam )
133136

134-
rates%handles_ = [ rates%handles_, wght_key ]
137+
temp_handles = rates%handles_
138+
deallocate( rates%handles_ )
139+
allocate( rates%handles_( size( temp_handles ) + 1 ) )
140+
rates%handles_( 1:size( temp_handles ) ) = temp_handles(:)
141+
rates%handles_( size( rates%handles_ ) ) = wght_key
142+
deallocate( temp_handles )
143+
135144
call config%get( iter, wght_config, Iam )
136145

137146
spectral_weight%val_ => &
138147
spectral_weight_builder( spectral_weight_config, grid_warehouse, &
139148
profile_warehouse )
140-
rates%spectral_weights_ = [ rates%spectral_weights_, &
141-
spectral_weight ]
149+
allocate( temp_weights( size( rates%spectral_weights_ ) ) )
150+
do i_elem = 1, size( temp_weights )
151+
temp_weights( i_elem )%val_ => rates%spectral_weights_( i_elem )%val_
152+
nullify( rates%spectral_weights_( i_elem )%val_ )
153+
end do
154+
deallocate( rates%spectral_weights_ )
155+
allocate( rates%spectral_weights_( size( temp_weights ) + 1 ) )
156+
do i_elem = 1, size( temp_weights )
157+
rates%spectral_weights_( i_elem )%val_ => temp_weights( i_elem )%val_
158+
nullify( temp_weights( i_elem )%val_ )
159+
end do
160+
rates%spectral_weights_( size( rates%spectral_weights_ ) )%val_ => &
161+
spectral_weight%val_
162+
nullify( spectral_weight%val_ )
163+
deallocate( temp_weights )
142164
end do
143165
deallocate( iter )
144166

0 commit comments

Comments
 (0)