Skip to content

Commit e6934d2

Browse files
committed
2 parents b2c06a7 + 814b63c commit e6934d2

8 files changed

Lines changed: 230 additions & 89 deletions

File tree

fvsOL/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: fvsOL
22
Title: Forest Vegetation Simulator
3-
Version: 2024.01.01
3+
Version: 2024.04.01
44
Authors@R: c(person("Nicholas", "Crookston", email = "ncrookston.fs@gmail.com",
55
role = c("aut")),
66
person("FVS", "Staff", email = "sm.fs.fvs-support@usda.gov",

fvsOL/R/checkMinColumnDefs.R

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,25 @@ checkMinColumnDefs <- function(dbo, progress = NULL, pn = 0) {
1212

1313
FVS_StandInit = FALSE
1414
valid_table_found = FALSE
15-
for (initnm in c("FVS_StandInit", "FVS_PlotInit",
16-
"FVS_StandInit_Plot", "FVS_PlotInit_Plot", "FVS_StandInit_Cond")) {
15+
FIA_dataset = FALSE
16+
FIA_Tables = c("FVS_StandInit_Plot", "FVS_PlotInit_Plot", "FVS_StandInit_Cond")
17+
for (table in FIA_Tables) {
18+
tryCatch(
19+
# Try to read table from db connection
20+
{
21+
stdInit <- dbReadTable(dbo, table)
22+
FIA_dataset = TRUE
23+
},
24+
25+
# if an error . . .
26+
error = function(e) {
27+
cat(paste0("Table: ", table, " not found in database\n"))
28+
}
29+
)
30+
}
31+
if (FIA_dataset) return(NULL)
32+
33+
for (initnm in c("FVS_StandInit", "FVS_PlotInit")) {
1734
initnm_exists = FALSE
1835
tryCatch(
1936
# Try to read table from db connection
@@ -61,7 +78,7 @@ checkMinColumnDefs <- function(dbo, progress = NULL, pn = 0) {
6178
" NOT REGEXP '[A-Za-z0-9_]' OR ", e, " IS NULL")
6279

6380
if (tolower(e) == 'inv_year'){
64-
q <- paste0("SELECT COUNT (*) FROM ", initnm, " WHERE INV_YEAR <= 0 OR INV_YEAR IS NULL")
81+
q <- paste0("SELECT COUNT (*) FROM ", initnm, " WHERE CAST(INV_YEAR AS INT) <= 0 OR INV_YEAR IS NULL")
6582
}
6683
tryCatch(
6784
{

fvsOL/R/fvsRunUtilities.R

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -961,23 +961,35 @@ moveToPaste <- function(item,globals,fvsRun,atag=NULL)
961961
return(TRUE)
962962
}
963963
}
964-
cntr <- 0
965964
# remove a component from a grp...
966965
if (length(fvsRun$grps)) for (i in length(fvsRun$grps):1)
967966
{
968967
if (length(fvsRun$grps[[i]]$cmps))
969968
{
970969
for (j in length(fvsRun$grps[[i]]$cmps):1)
971970
{
972-
spgtest <- grep("^SpGroup",fvsRun$grps[[i]]$cmps[[j]]$kwds)
973-
if (length(spgtest) && cntr == 0){
974-
globals$GrpNum <- globals$GrpNum[-(length(globals$GrpNum))]
975-
globals$GenGrp<- globals$GenGrp[-(length(globals$GenGrp))]
976-
cntr <- cntr +1
977-
}
978971
if ((!is.null(item) && fvsRun$grps[[i]]$cmps[[j]]$uuid == item) ||
979972
(!is.null(atag) && fvsRun$grps[[i]]$cmps[[j]]$atag == atag))
980973
{
974+
spgtest <- grep("^SpGroup",fvsRun$grps[[i]]$cmps[[j]]$kwds)
975+
if (length(spgtest)){
976+
if(!is.null(fvsRun$grps[[i]]$cmps[[j]]$reopn) && length(fvsRun$grps[[i]]$cmps[[j]]$reopn) > 0){
977+
chkGrp <- trim(fvsRun$grps[[i]]$cmps[[j]]$reopn[[1]])
978+
}
979+
else {
980+
tmpList <- strsplit(fvsRun$grps[[i]]$cmps[[j]]$kwds, split = '[[:space:]]+')
981+
chkGrp <- tmpList[[1]][2]
982+
}
983+
if(length(globals$GenGrp)){
984+
for (k in length(globals$GenGrp):1){
985+
if (chkGrp == globals$GenGrp[[k]]) {
986+
globals$GrpNum <- globals$GrpNum[-length(globals$GrpNum)]
987+
globals$GenGrp<- globals$GenGrp[-k]
988+
break
989+
}
990+
}
991+
}
992+
}
981993
toRm = fvsRun$grps[[i]]$cmps[[j]]
982994
globals$pastelist <- append(globals$pastelist,toRm,after=0)
983995
globals$pastelistShadow <- append(globals$pastelistShadow,toRm$uuid,after=0)
@@ -1593,7 +1605,7 @@ myListTables <- function(db)
15931605
dbGetQuery(db,"select name from sqlite_master where type = 'table';")[,1]
15941606
}
15951607

1596-
mkNameUnique <- function(name,setOfNames=NULL)
1608+
mkNameUnique <- function(name,setOfNames=NULL, spgroup=FALSE)
15971609
{
15981610
if (!name %in% setOfNames) return(name)
15991611
i=1
@@ -1602,6 +1614,7 @@ mkNameUnique <- function(name,setOfNames=NULL)
16021614
{
16031615
sp=unlist(strsplit(name,split=""))
16041616
pl = grep("\\(",sp)
1617+
if(spgroup) pl = grep("#", sp)
16051618
if (length(pl) > 0)
16061619
{
16071620
pl = max(pl)
@@ -1616,13 +1629,25 @@ mkNameUnique <- function(name,setOfNames=NULL)
16161629
nn=i
16171630
kp = length(sp)
16181631
ac = " ("
1619-
} else {
1632+
if (spgroup) ac = "#"
1633+
}
1634+
else {
16201635
kp = pl
16211636
nn=nn+1
16221637
ac = ""
1623-
}
1638+
}
1639+
16241640
sp = sp[1:kp]
16251641
name = paste0(c(sp,ac,as.character(nn),")"),collapse="")
1642+
1643+
if (spgroup) name = paste0(c(sp,ac,as.character(nn)),collapse="")
1644+
1645+
if (spgroup && nchar(name) > 10) {
1646+
suffix = substr(name, nchar(name) - nchar(as.character(nn)) -1, nchar(name))
1647+
prefix = substr(name, 1, 10 - nchar(suffix))
1648+
name = paste0(prefix, suffix)
1649+
}
1650+
16261651
if (!name %in% setOfNames) return(name)
16271652
i = i+1
16281653
}
@@ -1887,4 +1912,26 @@ areFilesIdentical <- function (f1=NULL, f2=NULL)
18871912
f2bin=readBin(f2,what="raw",size=1,n=f2sz)
18881913
identical(f1bin,f2bin)
18891914
}
1915+
1916+
################################################################################
1917+
# DupSpGrpDwdFormat
1918+
#
1919+
# Helper function to properly format keyword spacing when dealing
1920+
# with automatically generated duplicated, sequentially labeled species groups
1921+
#
1922+
# DWagner
1923+
# Last modified: March 06, 2024
1924+
##################################################################################
1925+
1926+
DupSpGrpKwdFormat <- function(orgName, dupName, orgKwd){
1927+
draftKwd <- sub(orgName, dupName, orgKwd)
1928+
draftnewlineIdx <-unlist(gregexpr("\\n", draftKwd))[1]
1929+
difference = if (draftnewlineIdx > 21) difference = draftnewlineIdx - 21 else 0
1930+
1931+
oldnewlineIdx <-unlist(gregexpr("\\n", orgKwd))[1]
1932+
oldStr <- substr(orgKwd, 8, oldnewlineIdx -1)
1933+
newStr <- substr(draftKwd, 8 + difference, draftnewlineIdx - 1)
1934+
replacementkwd <- sub(oldStr, newStr, orgKwd)
18901935

1936+
return(replacementkwd)
1937+
}

fvsOL/R/mkInputElements.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ mkeltList <- function (pkeys,prms,globals,input,output,
4141
else if (funcflag) pkey = paste0("func.",pkey)
4242
cat ("mkeltList title=",title,"\nf=",f," elt=",elt," pkey=",pkey," pmt=",pmt,
4343
"\nglobals$activeVariants[1]=",globals$activeVariants[1]," fpvs=",fpvs,"\n")
44-
4544
elt = switch(elt,
4645
listButton = mkSelectInput (pkey, pmt, choices, fpvs),
4746
longListButton = mkSelectInput (pkey, pmt, choices, fpvs),

0 commit comments

Comments
 (0)