Skip to content

Commit

Permalink
Clean up linked list code (following review)
Browse files Browse the repository at this point in the history
1. Typo in marbl_interface.F90 -- abort if registered_output is not associated
   (was checking this%output_for_gcm_registry%registered_outputs by accident)
2. Add comment about why create_registry() resets err_message to "" before each
   entry (and clean up errant white-space misalignment)
3. Also, blocks in create_registry() are easier to read if we set err_message
   to "" and then use a continutation line for the if () rather than using
   if-else
4. For adding to the registry linked list, order doesn't matter but the logic
   is simpler (and code is faster) if we prepend entries rather than looping
   through to the end of the list every time
  • Loading branch information
mnlevy1981 committed Feb 23, 2024
1 parent 03fa250 commit c371b6a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/marbl_interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ subroutine add_output_for_GCM(this, num_elements, field_name, output_id, field_s
end do

! Abort if field_name was not registered
if (.not. associated(this%output_for_gcm_registry%registered_outputs)) then
if (.not. associated(registered_output)) then
write(log_message, "(2A)") trim(field_name), " is not a valid output field name for the GCM"
call this%StatusLog%log_error(log_message, subname)
return
Expand Down
92 changes: 39 additions & 53 deletions src/marbl_interface_public_types.F90
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,16 @@ subroutine create_registry(this, conc_flux_units)

character(len=char_len) :: err_message

! NOTE: we want to set err_message = "" prior to every conditional
! so we don't inadvertently pass a non-empty string from a
! previous output variable
! E.g. if lflux_gas_o2 = F but lflux_gas_co2 = T, err_message
! should be blank for CO2 flux (assuming base_bio_on = T)

! Oxygen Flux
if (.not. (base_bio_on .and. lflux_gas_o2)) then
err_message = ""
if (.not. (base_bio_on .and. lflux_gas_o2)) &
err_message = "requires base biotic tracers and lflux_gas_o2"
else
err_message = ""
end if
call this%add_registry_entry(short_name = "flux_o2", &
long_name = "Oxygen Flux", &
units = conc_flux_units, &
Expand All @@ -812,56 +815,48 @@ subroutine create_registry(this, conc_flux_units)
err_message = err_message)

! Carbon Dioxide Flux
if (.not. (base_bio_on .and. lflux_gas_co2)) then
err_message = ""
if (.not. (base_bio_on .and. lflux_gas_co2)) &
err_message = "requires base biotic tracers and lflux_gas_co2"
else
err_message = ""
end if
call this%add_registry_entry(short_name = "flux_co2", &
long_name = "Carbon Dioxide Flux", &
units = conc_flux_units, &
field_source = "surface_flux", &
id = ofg_ind%flux_co2_id, &
err_message = err_message)
long_name = "Carbon Dioxide Flux", &
units = conc_flux_units, &
field_source = "surface_flux", &
id = ofg_ind%flux_co2_id, &
err_message = err_message)

! NHx Surface Emissions
if (.not. (base_bio_on .and. lcompute_nhx_surface_emis)) then
err_message = ""
if (.not. (base_bio_on .and. lcompute_nhx_surface_emis)) &
err_message = "requires base biotic tracers and lcompute_nhx_surface_emis"
else
err_message = ""
end if
call this%add_registry_entry(short_name = "flux_nhx", &
long_name = "NHx Surface Emissions", &
units = conc_flux_units, &
field_source = "surface_flux", &
id = ofg_ind%flux_nhx_id, &
err_message = err_message)
long_name = "NHx Surface Emissions", &
units = conc_flux_units, &
field_source = "surface_flux", &
id = ofg_ind%flux_nhx_id, &
err_message = err_message)

! Surface Chlorophyll
if (.not. base_bio_on) then
err_message = ""
if (.not. base_bio_on) &
err_message = "requires base biotic tracers"
else
err_message = ""
end if
call this%add_registry_entry(short_name = "total_surfChl", &
long_name = "Total Surface Chlorophyll Concentration", &
units = "mg/m^3", &
field_source = "surface_flux", &
id = ofg_ind%total_surfChl_id, &
err_message = err_message)
long_name = "Total Surface Chlorophyll Concentration", &
units = "mg/m^3", &
field_source = "surface_flux", &
id = ofg_ind%total_surfChl_id, &
err_message = err_message)

! Full Depth Chlorophyll
if (.not. base_bio_on) then
err_message = ""
if (.not. base_bio_on) &
err_message = "requires base biotic tracers"
else
err_message = ""
end if
call this%add_registry_entry(short_name = "total_Chl", &
long_name = "Total Chlorophyll Concentration", &
units = "mg/m^3", &
field_source = "interior_tendency", &
id = ofg_ind%total_Chl_id, &
err_message = err_message)
long_name = "Total Chlorophyll Concentration", &
units = "mg/m^3", &
field_source = "interior_tendency", &
id = ofg_ind%total_Chl_id, &
err_message = err_message)

end subroutine create_registry

Expand All @@ -878,19 +873,10 @@ subroutine add_registry_entry(this, short_name, long_name, units, field_source,

type(marbl_output_for_GCM_linked_list_type), pointer :: new_entry

! Find last linked list item
if (associated(this%registered_outputs)) then
new_entry => this%registered_outputs
do while (associated(new_entry%next))
new_entry => new_entry%next
end do
allocate(new_entry%next)
new_entry => new_entry%next
else
! This is first entry in the registry
allocate(new_entry)
this%registered_outputs => new_entry
end if
! Insert new entry at beginning of linked list
allocate(new_entry)
new_entry%next => this%registered_outputs
this%registered_outputs => new_entry

new_entry%short_name = short_name
new_entry%long_name = long_name
Expand Down

0 comments on commit c371b6a

Please sign in to comment.