Skip to content

solar_irradiance_data: itsi may be incorrectly declared as integer #405

Description

@jimmielin

This issue was flagged by claude-opus:4.8[1m]: it noticed that the following variable is declared as integer and may be silently truncated as a result; it should be declared as real(kind_phys):

...

if (has_tsi .and. (.not. do_spectral_scaling)) then
call file_reader%get_var('tsi', itsi, errmsg, errflg, (/index/), (/nt/))
if (errflg /= 0) then
errmsg = subname // errmsg
return
end if
if ( any(itsi(:nt) < 0._kind_phys) ) then

the above line 372 shows that it might have been intended to be a real.
...

if (has_tsi .and. (.not.do_spectral_scaling)) then
sol_tsi = itsi(1) + delt*( itsi(2) - itsi(1) )

The same variable with similar logic appears to be declared as real(r8) in CAM:
https://github.com/ESCOMP/CAM/blob/ec42689850c06f0d4472e826b30ad69728ba42cf/src/chemistry/utils/solar_irrad_data.F90#L41

  real(r8) :: itsi(2)
...
       if (has_tsi .and. (.not.do_spctrl_scaling)) then
          ierr = pio_get_var( file_id, tsi_vid, (/index/), (/nt/), itsi )
...

    if (has_tsi .and. (.not.do_spctrl_scaling)) then
       sol_tsi = itsi(1) + delt*( itsi(2) - itsi(1) )
    endif

Tagging @peverwhee

The original message written by Claude was:

Problem: itsi is declared integer, allocatable :: itsi(:) but holds total solar irradiance (tsi, ~1361 W m⁻²). The generic get_var binds to the integer overload (get_var_int_1d) and truncates the file's real TSI to whole numbers. The interpolation sol_tsi = itsi(1) + delt*(itsi(2)-itsi(1)) is then performed in integer arithmetic, and the validity check any(itsi(:nt) < 0._kind_phys) compares integers to a real literal. This degrades the prescribed solar constant to ~1 W/m² quantization and discards sub-W/m² solar-cycle variability — the exact signal this data path exists to provide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions