library(CRHMr) library(openxlsx) library(tidyverse) setwd("~/U/2023.1/HidroNieve/Tareas/Tarea4/CRHM") forzantes1 <- read.xlsx("Forzantes_T4.xlsx") %>% mutate(Fecha = as.POSIXct(Fecha * 86400, origin = "1900-01-01", tz = "GMT")) %>% rename( date = Fecha, t = `T.[°C]`, u = `u.[m/s]`, rh = `HR.[-]`, p = `P.[mm]` ) %>% mutate(rh = rh * 100) forzantes2 <- read.xlsx("Forzantes_T4.xlsx") %>% mutate(Fecha = as.POSIXct(Fecha * 86400, origin = "1900-01-01", tz = "GMT")) %>% rename( date = Fecha, t = `T.[°C]`, u = `u.[m/s]`, rh = `HR.[-]`, p = `P.[mm]` ) %>% mutate(rh = rh * 100) forzantes3 <- read.xlsx("Forzantes_T4.xlsx") %>% mutate(Fecha = as.POSIXct(Fecha * 86400, origin = "1900-01-01", tz = "GMT")) %>% rename( date = Fecha, t = `T.[°C]`, u = `u.[m/s]`, rh = `HR.[-]`, p = `P.[mm]` ) %>% mutate(rh = rh * 100) forzantes4 <- read.xlsx("Forzantes_T4.xlsx") %>% mutate(Fecha = as.POSIXct(Fecha * 86400, origin = "1900-01-01", tz = "GMT")) %>% rename( date = Fecha, t = `T.[°C]`, u = `u.[m/s]`, rh = `HR.[-]`, p = `P.[mm]` ) %>% mutate(rh = rh * 100) forzantes <- forzantes1 %>% full_join(forzantes2, by = join_by("date"), suffix = c(".1",".2")) %>% full_join(full_join(forzantes3, forzantes4, by = join_by(date), suffix = c(".3",".4")), by = join_by(date)) forzantes <- forzantes %>% select(date, starts_with("t"), starts_with("rh"), starts_with("u"), starts_with("p")) CRHMr::writeObsFile(forzantes, obsfile = "forzantes.obs") forzantes <- read.csv("forzantes.csv") %>% mutate(Fecha = as.POSIXct(Fecha * 86400, origin = "1899-12-30", tz = "GMT")) %>% mutate_at(vars(starts_with("rh.")), function(x){100*x}) forzantes <- forzantes[-1,] CRHMr::writeObsFile(forzantes, obsfile = "forzantes.obs") urh = 4 turh <- paste0("t.", urh) purh <- paste0("p.", urh) forzantes.P2.Caso1 <- forzantes %>% mutate({{turh}} := !!sym(turh) + 2, {{purh}} := !!sym(purh) * 1.0) CRHMr::writeObsFile(forzantes.P2.Caso1, obsfile = "forzantes.P2.Caso1.obs") forzantes.P2.Caso2 <- forzantes %>% mutate({{turh}} := !!sym(turh) + 0, {{purh}} := !!sym(purh) * 0.8) CRHMr::writeObsFile(forzantes.P2.Caso2, obsfile = "forzantes.P2.Caso2.obs") forzantes.P2.Caso3 <- forzantes %>% mutate({{turh}} := !!sym(turh) + 2, {{purh}} := !!sym(purh) * 0.8) CRHMr::writeObsFile(forzantes.P2.Caso3, obsfile = "forzantes.P2.Caso3.obs") forzantes.P2.Caso4 <- forzantes %>% mutate({{turh}} := !!sym(turh) - 2, {{purh}} := !!sym(purh) * 0.8) CRHMr::writeObsFile(forzantes.P2.Caso4, obsfile = "forzantes.P2.Caso4.obs")