Skip to content

Commit

Permalink
Add dry run flag. Also add a debug print for checking time was recogn…
Browse files Browse the repository at this point in the history
…ised appropriately
  • Loading branch information
adrfantini committed Feb 26, 2019
1 parent 2b4678f commit fd32552
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ncspellR.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ option_list = list( make_option(c("-n", "--nthreads"),
help="Activate netCDF compression (with deflate level 1) for the main variable"),
make_option("--debug",
action="store_true",
help="Print additional debug output. This flag is also useful if you want to check that the options were correctly understood")
help="Print additional debug output. This flag is also useful if you want to check that the options were correctly understood"),
make_option("--dryrun",
action="store_true",
help="Perform a dry run, do not compute nor write anything to file")
)
parser = OptionParser(
usage = "%prog [options] INPUT OUTPUT",
Expand Down Expand Up @@ -123,6 +126,8 @@ if (!is.null(logfile)) {
if (file.exists(logfile)) flog.debug('Appending output to logfile %s', logfile)
}

dryrun = isTRUE(opt$dryrun)

flog.info(glue(' ### Starting {program_name} version {version} from {author} ({contact}) ### '))

progress = isTRUE(opt$progress)
Expand Down Expand Up @@ -187,6 +192,8 @@ time_units = nc_in %>% ncatt_get(time_var, 'units')
if (!time_units$hasatt) flog.fatal('Cannot find time units!')
flog.debug('Time units: %s', time_units$value)
time_units = strsplit(time_units$value, " ")[[1]]
flog.debug('Time unit parsed as:', data.frame(WHAT = c('unit', 'since', 'date', 'time', 'timezone'), VALUE = c(time_units, rep(NA, 5 - length(time_units)))), capture=TRUE)

time_cal = nc_in %>% ncatt_get(time_var, 'calendar')
if (!time_cal$hasatt) {
flog.info('No input calendar, assuming standard')
Expand Down Expand Up @@ -255,6 +262,11 @@ spi_in = nc_in %>% ncvar_get(var_in)

#============= COMPUTE =============

if (dryrun) {
flog.info('Quitting, this was just a dry run')
quit()
}

spi_spell = function(v, yrs, eventstart = -1, eventend = 0) {
stopifnot( length(v) == length(yrs) )
# Define what the labels mean, for clarity
Expand Down

0 comments on commit fd32552

Please sign in to comment.