comparison extract_ipm_date_interval.R @ 13:aad04f404793 draft

Uploaded
author greg
date Thu, 09 Aug 2018 10:06:09 -0400
parents 2a438187d051
children
comparison
equal deleted inserted replaced
12:fff2e4833e8f 13:aad04f404793
243 # Calaculate the number of days in the date interval. 243 # Calaculate the number of days in the date interval.
244 start_date = validate_date(start_date); 244 start_date = validate_date(start_date);
245 # Validate end_date. 245 # Validate end_date.
246 end_date = validate_date(end_date); 246 end_date = validate_date(end_date);
247 if (start_date >= end_date) { 247 if (start_date >= end_date) {
248 stop_err("The start date must be between 1 and 50 days before the end date when setting date intervals for plots."); 248 stop_err("The start date must be between 1 and 50 days before the end date.\n");
249 } 249 }
250 # Calculate the number of days in the date interval. 250 # Calculate the number of days in the date interval.
251 num_days = difftime(end_date, start_date, units=c("days")); 251 num_days = difftime(end_date, start_date, units=c("days"));
252 # Add 1 to the number of days to make the dates inclusive. For 252 # Add 1 to the number of days to make the dates inclusive. For
253 # example, if the user enters a date range of 2018-01-01 to 253 # example, if the user enters a date range of 2018-01-01 to
266 for (input_data_file in input_data_files) { 266 for (input_data_file in input_data_files) {
267 file_name = basename(input_data_file); 267 file_name = basename(input_data_file);
268 temperature_data_frame = get_new_temperature_data_frame(input_data_file); 268 temperature_data_frame = get_new_temperature_data_frame(input_data_file);
269 start_date_row = which(temperature_data_frame$DATE==start_date); 269 start_date_row = which(temperature_data_frame$DATE==start_date);
270 end_date_row = which(temperature_data_frame$DATE==end_date); 270 end_date_row = which(temperature_data_frame$DATE==end_date);
271 if (length(start_date_row)==0 | length(end_date_row)==0) {
272 stop_err("Invalid date interval, make sure the start and end dates are both contained within the selected input data files.\n");
273 }
271 # Extract the date interval. 274 # Extract the date interval.
272 temperature_data_frame = temperature_data_frame[start_date_row:end_date_row,]; 275 temperature_data_frame = temperature_data_frame[start_date_row:end_date_row,];
273 # Save the date interval data into an output file 276 # Save the date interval data into an output file
274 # named the same as the input. 277 # named the same as the input.
275 file_path = paste("output_data_dir", file_name, sep="/"); 278 file_path = paste("output_data_dir", file_name, sep="/");