Skip to content

Commit

Permalink
more prints
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasia-popova committed Apr 5, 2024
1 parent 5cb42a6 commit 29590fe
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Regridder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -648,28 +648,23 @@ function truncate_dataset(
comms_ctx::ClimaComms.AbstractCommsContext,
)
if ClimaComms.iamroot(comms_ctx)
println("got dates")
date_start = date0 + Dates.Second(time_start)
date_end = date0 + Dates.Second(time_start + time_end)

println("got ds")
ds = NCDataset(datafile, "r")
dates = ds["time"][:]

# if the simulation start date is before our first date in the dataset
# leave the beginning of the truncated dataset to be first date available
if date_start < dates[1]
println("start too early")
start_id = 1
# if the simulation start date is after the last date in the dataset
# start the truncated dataset at its last possible date
elseif date_start > last(dates)
println("start too late")
start_id = length(dates)
# if the simulation start date falls within the range of the dataset
# find the closest date to the start date and truncate there
else
println("good start")
(~, start_id) = findmin(x -> abs(x - date_start), dates)
# if the closest date is after the start date, add one more date before
if dates[start_id] > date_start
Expand All @@ -680,25 +675,26 @@ function truncate_dataset(
# if the simulation end date is before our first date in the dataset
# truncate the end of the dataset to be the first date
if date_end < dates[1]
println("end too early")
end_id = 1
# if the simulation end date is after the last date in the dataset
# leave the end of the dataset as is
elseif date_end > last(dates)
println("end too late")
end_id = length(dates)
# if the simulation end date falls within the range of the dataset
# find the closest date to the end date and truncate there
else
println("end good")
(~, end_id) = findmin(x -> abs(x - date_end), dates)
# if the closest date is before the end date, add one more date after
if dates[end_id] < date_end
end_id = end_id + 1
end
end

println("------------------------------")
println(start_id)
println(end_id)
println("set start and end id")
println("----------------------------")

file_name = string(name, "_truncated_data_", string(date_start), string(date_end), ".nc")
datafile_truncated = joinpath(datapath, file_name)
Expand Down

0 comments on commit 29590fe

Please sign in to comment.