ESCOMP / ESCOMP/atmospheric_physics
solar_irradiance_data: itsi may be incorrectly declared as integer
- Dominant language
- Fortran
- Stars
- 12
- Forks
- 38
- Avg merge
- 11h 16m
- Merged PRs (30d)
- 5
Description
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)`:
https://github.com/ESCOMP/atmospheric_physics/blob/2180f3c4dacd981d50ab81074c73b3db85977060/schemes/radiation_utils/solar_irradiance_data.F90#L324
...
https://github.com/ESCOMP/atmospheric_physics/blob/2180f3c4dacd981d50ab81074c73b3db85977060/schemes/radiation_utils/solar_irradiance_data.F90#L366-L372
the above line 372 shows that it might have been intended to be a real.
...
https://github.com/ESCOMP/atmospheric_physics/blob/2180f3c4dacd981d50ab81074c73b3db85977060/schemes/radiation_utils/solar_irradiance_data.F90#L397-L398
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
```fortran
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.