Get space weather data for a given Modified Julian Date. Uses direct indexing for daily data and record selection for monthly data
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(sw_data_type), | intent(inout) | :: | me | |||
| real(kind=dp), | intent(in) | :: | mjd |
Modified Julian Date |
||
| type(flux_data_type), | intent(out) | :: | flux_data |
Output flux data structure |
||
| logical, | intent(out) | :: | status |
Output status (true=success, false=not initialized) |
subroutine sw_get_flux_data(me, mjd, flux_data, status) class(sw_data_type), intent(inout) :: me real(dp), intent(in) :: mjd !! Modified Julian Date type(flux_data_type), intent(out) :: flux_data !! Output flux data structure logical, intent(out) :: status !! Output status (true=success, false=not initialized) integer(ip) :: idx, i integer(ip) :: daily_end_idx if (.not. me%initialized) then write(*,'(A)') 'ERROR: Space weather module not initialized' status = .false. return end if status = .true. ! Handle epoch before data starts if (mjd < me%historic_start) then if (me%warn_epoch_before) then write(*,'(A)') 'WARNING: Requested epoch is earlier than space weather data start' write(*,'(A)') ' Using first file entry' me%warn_epoch_before = .false. end if flux_data = me%get_record(1) return end if ! Handle epoch after data ends if (mjd >= me%historic_end) then if (me%warn_epoch_after) then write(*,'(A)') 'WARNING: Requested epoch is later than space weather data end' write(*,'(A)') ' Using last file entry' me%warn_epoch_after = .false. end if flux_data = me%get_record(me%n_records) return end if ! Within data range ! For daily data: direct index calculation (O(1)) ! For monthly data: linear search through monthly section only if (mjd <= me%historic_daily_end) then ! Daily data: use direct index calculation idx = int(mjd - me%historic_start) + 1 ! Bounds check if (idx < 1) idx = 1 if (idx > me%n_records) idx = me%n_records flux_data = me%get_record(idx) else ! Monthly data: search from daily_end to end of array ! Find the index where daily data ends daily_end_idx = int(me%historic_daily_end - me%historic_start) + 1 ! Search monthly data for the record at or before mjd idx = daily_end_idx do i = daily_end_idx, me%n_records if (me%mjd(i) > mjd) exit idx = i end do flux_data = me%get_record(idx) end if end subroutine sw_get_flux_data