opus-data/OpusData.R

42 lines
1.2 KiB
R
Raw Normal View History

#!/usr/bin/env Rscript
2021-01-19 11:09:12 +01:00
# Package installation, execute once
#if (!require("remotes")) install.packages("remotes")
#remotes::install_github("philipp-baumann/simplerspec")
2021-01-19 11:09:12 +01:00
# Attach package to workspace, execute with every new session
library("simplerspec")
2021-01-19 14:26:16 +01:00
# Determine file path
path <- paste(getwd(), "\\OPUS\\", sep = "")
2021-01-15 15:39:19 +01:00
file_name <- "Rng02_Rng2630_01.0"
2021-01-19 14:26:16 +01:00
file_path <- paste(path, file_name, sep = "")
2021-01-19 14:26:16 +01:00
# 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 = 4, stop = nchar(file_path))
2021-01-19 14:26:16 +01:00
# Extract data
data_x_values <- data[[file_path]]$wavenumbers
data_y_values <- as.numeric(data[[file_path]]$spc[1,])
2021-01-19 14:26:16 +01:00
# Set working directory to path where the result file should appear
setwd(paste(path, "..\\DPT", sep = ""))
2021-01-15 15:39:19 +01:00
2021-01-19 14:26:16 +01:00
# Convert data into dataframe
data <- data.frame(data_x_values, data_y_values, row.names = NULL)
2021-01-15 15:39:19 +01:00
2021-01-19 11:09:12 +01:00
# 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=",")
2021-01-15 15:39:19 +01:00
2021-01-19 14:26:16 +01:00