Skip to content

Commit

Permalink
rev2
Browse files Browse the repository at this point in the history
  • Loading branch information
LenkaNovak committed Jan 31, 2024
1 parent c06719e commit 48804a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DocStringExtensions = "0.8, 0.9"
Insolation = "0.8"
JLD2 = "0.4"
NCDatasets = "0.11, 0.12, 0.13"
Plots = "=1.39.0"
Plots = "1.39.0"
SciMLBase = "1, 2"
StaticArrays = "1"
Statistics = "1"
Expand Down
11 changes: 5 additions & 6 deletions src/BCReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ function update_midmonth_data!(date, bcf_info::BCFileInfo{FT}) where {FT}
segment_idx = bcf_info.segment_idx[1] # index of the current date in the file. [segment_idx, segment_idx+1] indexes the current segment between which we interpolate
segment_idx0 = bcf_info.segment_idx0[1] # reference index (first segment_idx - 1)

# upon initialization (segment_idx == segment_idx0) and not initialized after final file date
# upon initialization (segment_idx == segment_idx0) and initialized before the final file date
if (segment_idx == segment_idx0) && !((date - all_dates[end]).value >= 0)
# case 1: model date is before the first segment read from file
if (date - all_dates[segment_idx]).value < 0
@warn "this time period is before BC data - using file from $(all_dates[segment_idx0])"
if (date - all_dates[segment_idx0]).value < 0
@warn "This time period is before BC data - using file from $(all_dates[segment_idx0])"
bcf_info.monthly_fields[1] .= scaling_function(
Regridder.read_from_hdf5(bcfile_dir, hd_outfile_root, all_dates[Int(segment_idx0)], varname, comms_ctx),
bcf_info,
Expand All @@ -213,7 +213,7 @@ function update_midmonth_data!(date, bcf_info::BCFileInfo{FT}) where {FT}
update_midmonth_data!(date, bcf_info)

# case 3: model date is within the first segment read from file
elseif (date - all_dates[segment_idx]).value >= 0
elseif (date - all_dates[segment_idx0]).value >= 0
@warn "On $date updating file data reads: file dates = [ $(all_dates[segment_idx]) , $(all_dates[segment_idx+1]) ]"
bcf_info.segment_length .= (all_dates[segment_idx + 1] - all_dates[segment_idx]).value
bcf_info.monthly_fields[1] .= scaling_function(
Expand All @@ -229,7 +229,7 @@ function update_midmonth_data!(date, bcf_info::BCFileInfo{FT}) where {FT}

# case 4: date is at or after the last date in file
elseif (date - all_dates[end]).value >= 0
@warn "this time period is after BC data - using file from $(all_dates[end])"
@warn "This time period is after BC data - using file from $(all_dates[end])"
bcf_info.monthly_fields[1] .= scaling_function(
Regridder.read_from_hdf5(
bcfile_dir,
Expand All @@ -247,7 +247,6 @@ function update_midmonth_data!(date, bcf_info::BCFileInfo{FT}) where {FT}
elseif (date - all_dates[Int(segment_idx) + 1]).value >= 0
segment_idx = bcf_info.segment_idx[1] += Int(1)

@warn "On $date updating file data reads: file dates = [ $(all_dates[Int(segment_idx)]) , $(all_dates[Int(segment_idx+1)]) ]"
bcf_info.segment_length .= (all_dates[Int(segment_idx + 1)] - all_dates[Int(segment_idx)]).value

bcf_info.monthly_fields[1] .= scaling_function(
Expand Down

0 comments on commit 48804a3

Please sign in to comment.