opus-data/OpusData.R

42 lines
1.2 KiB
R

#!/usr/bin/env Rscript
# Package installation, execute once
#install.packages("remotes")
#remotes::install_github("philipp-baumann/simplerspec")
# Attach package to workspace, execute with every new session
library("simplerspec")
# Determine file path
path <- paste(getwd(), "/OPUS/", sep = "")
file_name <- commandArgs(trailingOnly = TRUE)[1]
file_path <- paste(path, file_name, sep = "")
# Convert opus binary file into extractable data
data <- read_opus_univ(file_path, extract = "spc",atm_comp_minus4offset = FALSE)
#Cut the beginning (ugly solution)
#file_path <- substr(file_path, start = 10, stop = nchar(file_path))
# Extract data
data_x_values <- data[[file_name]]$wavenumbers
data_y_values <- as.numeric(data[[file_name]]$spc[1,])
# Set working directory to path where the result file should appear
setwd(paste(path, "..\\DPT", sep = ""))
# Convert data into dataframe
data <- data.frame(data_x_values, data_y_values, row.names = NULL)
# Replace last "." with "_", add ".DPT" and create file
file_name <- paste(sub(".([^.]*)$", "_\\1", file_name), ".DPT", sep = "")
file.create(file_name)
# Fill file with dataframe
write.table(data, file_name, row.names = FALSE, col.names = FALSE, sep=",")