Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Find names and total number of REEs in file "pmo.dat"
- con = file("pmo.dat", "r")
- pat <- "ASSOCIACAO ENTRE REEs E SUBSISTEMAS"
- while ( TRUE ) {
- line = readLines(con, n = 1)
- # print(line)
- if ( length(line) == 0 ) break
- if(grepl(pattern = pat, line) == TRUE) {
- print(line)
- break
- }
- }
- line = readLines(con, n = 6)
- # Save REEs names and total number
- NameREE <- list()
- while (TRUE) {
- line <- readLines(con, n = 1)
- aa <- strsplit(line, split="\\s+")
- if (substring(line, 5, 7) != "---"){
- NameREE <- c(NameREE, aa[[1]][3])
- }
- else {
- print("NameREE", str(NameREE))
- break
- }
- }
- totREE <- length(NameREE)
- #
- # ***********************************************************************************************
- # Get initial and final years for EAF historical data in file pmo.dat
- # Caveat: here we take for granted that all inflows have the same common period of data
- pat <- "CONFIGURACAO DOS REEs"
- while ( TRUE ) {
- line = readLines(con, n = 1)
- # print(line)
- if ( length(line) == 0 ) break
- if(grepl(pattern = pat, line) == TRUE) {
- print(line)
- break
- }
- }
- line <- readLines(con, n = 4)
- line <- readLines(con, n = 1)
- aa <- strsplit(line, split="\\s+")
- anoFim <- as.numeric(aa[[1]][11])
- anoIni <- as.numeric(aa[[1]][10])
- totYears <- anoFim - anoIni + 1
- close(con)
- #
- # ***********************************************************************************************
- # Read energy inflows in file parp.dat for all REEs, for configuration No. 1
- EAFh = array(0, dim=c(totREE,totYears,13))
- rownames(EAFh) <- NameREE
- con <- file("parp.dat", "r")
- nREE <- 0
- # for (nREE in 1:length(NameREE)) {
- # for (nREE in 1:9) {
- while (nREE <= totREE) {
- line = readLines(con, n = 1)
- # print(line)
- if ( length(line) == 0 ) break
- if(grepl(pattern = "CONFIGURACAO No. 1", line) == TRUE) {
- # print(line)
- aa <- strsplit(line, split="\\s+")
- line = readLines(con, n = 4)
- nREE <- nREE + 1
- print(paste0("nREE = ", nREE, " name = ", aa[[1]][7]))
- EAFh[nREE,,] <- as.matrix(read.table(con, nrows = totYears))
- }
- }
- names_REE <- unlist(NameREE)
- REE_lt <- setNames(NameREE, names_REE)
- # print(" fim de leitura de dados ")
- # bla <- readEAF("CONFIGURACAO No. 1")
- # ***********************************************************************************************
- readEAF <- function(confNumber){
- # ***********************************************************************************************
- # read energy inflow for configuration confNumber
- # ***********************************************************************************************
- # Find names and total number of REEs in file "pmo.dat"
- con = file("pmo.dat", "r")
- pat <- "ASSOCIACAO ENTRE REEs E SUBSISTEMAS"
- while ( TRUE ) {
- line = readLines(con, n = 1)
- # print(line)
- if ( length(line) == 0 ) break
- if(grepl(pattern = pat, line) == TRUE) {
- print(line)
- break
- }
- }
- line = readLines(con, n = 6)
- # Save REEs names and total number
- NameREE <- list()
- while (TRUE) {
- line <- readLines(con, n = 1)
- aa <- strsplit(line, split="\\s+")
- if (substring(line, 5, 7) != "---"){
- NameREE <- c(NameREE, aa[[1]][3])
- }
- else {
- print("NameREE", str(NameREE))
- break
- }
- }
- totREE <- length(NameREE)
- #
- # ***********************************************************************************************
- # Get initial and final years for EAF historical data in file pmo.dat
- # Caveat: here we take for granted that all inflows have the same common period of data
- pat <- "CONFIGURACAO DOS REEs"
- while ( TRUE ) {
- line = readLines(con, n = 1)
- # print(line)
- if ( length(line) == 0 ) break
- if(grepl(pattern = pat, line) == TRUE) {
- print(line)
- break
- }
- }
- line <- readLines(con, n = 4)
- line <- readLines(con, n = 1)
- aa <- strsplit(line, split="\\s+")
- anoFim <- as.numeric(aa[[1]][11])
- anoIni <- as.numeric(aa[[1]][10])
- totYears <- anoFim - anoIni + 1
- close(con)
- #
- # ***********************************************************************************************
- # Read energy inflows in file parp.dat for all REEs, for configuration No. 1
- EAFh = array(0, dim=c(totREE,totYears,13))
- rownames(EAFh) <- NameREE
- con <- file("parp.dat", "r")
- nREE <- 0
- # for (nREE in 1:length(NameREE)) {
- # for (nREE in 1:9) {
- while (nREE <= totREE) {
- line = readLines(con, n = 1)
- # print(line)
- if ( length(line) == 0 ) break
- if(grepl(pattern = "CONFIGURACAO No. 1", line) == TRUE) {
- # print(line)
- aa <- strsplit(line, split="\\s+")
- line = readLines(con, n = 4)
- nREE <- nREE + 1
- print(paste0("nREE = ", nREE, " name = ", aa[[1]][7]))
- EAFh[nREE,,] <- as.matrix(read.table(con, nrows = totYears))
- }
- }
- names_REE <- unlist(NameREE)
- REE_lt <- setNames(NameREE, names_REE)
- # print(" fim de leitura de dados ")
- return(list(EAFh = EAFh, REE_lt = REE_lt))
- }
Advertisement
Add Comment
Please, Sign In to add comment