Skip to content

Commit 25d528f

Browse files
committed
Argument 'file.name' to getField() now used for Format GUESS.
1 parent 43e4a30 commit 25d528f

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

R/Format-GUESS.R

+31-33
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ getField_GUESS <- function(source,
2424
verbose,
2525
...) {
2626

27-
# Give warning if file.name is used because it is currently being ignored
28-
if(!is.null(file.name)) warning(paste0("Argument file.name (currently set to ", file.name, ") is being ignored."))
29-
3027
# First check if quantity is for FireMIP, if so call a special function with the extra processing required
3128
if("FireMIP" %in% quant@format) {
3229
return(openLPJOutputFile_FireMIP(source, quant, target.sta = target.STAInfo, file.name = file.name, verbose = verbose, ...))
@@ -38,7 +35,7 @@ getField_GUESS <- function(source,
3835
return(getStandardQuantity_LPJ(source, quant, target.sta = target.STAInfo, file.name = file.name, verbose = verbose, ...))
3936
}
4037
else{
41-
stop("Unrecognised Quantity in 'quant' argument to getField_GUESS()")
38+
stop("Unrecognised Format of Quantity in 'quant' argument to getField_GUESS()")
4239
}
4340

4441

@@ -94,7 +91,8 @@ openLPJOutputFile <- function(run,
9491

9592

9693
# Make the filename and check for the file, gunzip if necessary, fail if not present
97-
file.string = file.path(run@dir, paste(variable, ".out", sep=""))
94+
if(is.null(file.name)) file.string <- file.path(run@dir, paste(variable, ".out", sep=""))
95+
else file.string <- file.path(run@dir, file.name)
9896
re.zip <- FALSE
9997
if(file.exists(file.string)){
10098
if(verbose) message(paste("Found and opening file", file.string, sep = " "))
@@ -326,13 +324,13 @@ openLPJOutputFile_FireMIP <- function(run,
326324
############# PER PFT VARIABLES
327325

328326
if(variable == "lai") {
329-
dt <- openLPJOutputFile(run, "lai", data.table.only = TRUE, target.sta = target.sta, verbose = verbose)
327+
dt <- openLPJOutputFile(run, "lai", data.table.only = TRUE, target.sta = target.sta, file.name = file.name, verbose = verbose)
330328
}
331329
if(variable == "landCoverFrac") {
332-
dt <- openLPJOutputFile(run, "fpc", data.table.only = TRUE, target.sta = target.sta, verbose = verbose)
330+
dt <- openLPJOutputFile(run, "fpc", data.table.only = TRUE, target.sta = target.sta, file.name = file.name, verbose = verbose)
333331
}
334332
if(variable == "theightpft") {
335-
dt <- openLPJOutputFile(run, "speciesheights", data.table.only = TRUE, target.sta = target.sta, verbose = verbose)
333+
dt <- openLPJOutputFile(run, "speciesheights", data.table.only = TRUE, target.sta = target.sta, file.name = file.name, verbose = verbose)
336334
}
337335

338336

@@ -476,7 +474,7 @@ openLPJOutputFile_FireMIP <- function(run,
476474
# Now calculate these bad boys
477475
if(monthly.to.second || monthly.to.percent || monthly){
478476

479-
dt <- openLPJOutputFile(run, guess.var, target.sta, verbose, data.table.only = TRUE)
477+
dt <- openLPJOutputFile(run, guess.var, target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
480478
setnames(dt, guess.var, variable)
481479
if(monthly.to.second){
482480
#suppressWarnings(dt[, Seconds := seconds.in.month[Month]])
@@ -499,7 +497,7 @@ openLPJOutputFile_FireMIP <- function(run,
499497
### Special monthly variables
500498
if(variable == "meanFire") {
501499
guess.var <- "real_fire_size"
502-
dt <- openLPJOutputFile(run, guess.var, target.sta, verbose, data.table.only = TRUE)
500+
dt <- openLPJOutputFile(run, guess.var, target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
503501
setnames(dt, guess.var, variable)
504502
dt[, (variable) := get(variable) * 10000]
505503
}
@@ -522,10 +520,10 @@ openLPJOutputFile_FireMIP <- function(run,
522520
dt_cap[, Capacity := wcap[Code]]
523521
dt_cap[, Code := NULL]
524522

525-
dt_upper <- openLPJOutputFile(run, "mwcont_upper", target.sta, verbose, data.table.only = TRUE)
523+
dt_upper <- openLPJOutputFile(run, "mwcont_upper", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
526524
setKeyDGVM(dt_upper)
527525

528-
dt_lower <- openLPJOutputFile(run, "mwcont_lower", target.sta, verbose, data.table.only = TRUE)
526+
dt_lower <- openLPJOutputFile(run, "mwcont_lower", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
529527
setKeyDGVM(dt_lower)
530528
dt <- dt_upper[dt_lower]
531529

@@ -557,7 +555,7 @@ openLPJOutputFile_FireMIP <- function(run,
557555
dt_cap[, Capacity := wcap[Code]]
558556
dt_cap[, Code := NULL]
559557

560-
dt <- openLPJOutputFile(run, "mwcont_upper", target.sta, verbose, data.table.only = TRUE)
558+
dt <- openLPJOutputFile(run, "mwcont_upper", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
561559
setKeyDGVM(dt)
562560

563561
dt <- dt[dt_cap]
@@ -575,16 +573,16 @@ openLPJOutputFile_FireMIP <- function(run,
575573
if(variable == "evapotrans") {
576574

577575
# firstly combine transpiration and evaporation
578-
dt_trans <- openLPJOutputFile(run, "maet", target.sta, verbose, data.table.only = TRUE)
579-
dt_evap <- openLPJOutputFile(run, "mevap", target.sta, verbose, data.table.only = TRUE)
576+
dt_trans <- openLPJOutputFile(run, "maet", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
577+
dt_evap <- openLPJOutputFile(run, "mevap", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
580578
setKeyDGVM(dt_trans)
581579
setKeyDGVM(dt_evap)
582580
dt_trans <- dt_evap[dt_trans]
583581
rm(dt_evap)
584582
gc()
585583

586584
# now add interception
587-
dt_intercep <- openLPJOutputFile(run, "mintercep", target.sta, verbose, data.table.only = TRUE)
585+
dt_intercep <- openLPJOutputFile(run, "mintercep", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
588586
setKeyDGVM(dt_intercep)
589587
dt_trans <- dt_trans[dt_intercep]
590588
rm(dt_intercep)
@@ -604,19 +602,19 @@ openLPJOutputFile_FireMIP <- function(run,
604602
### ANNUAL C POOLS FROM cpool.out FILE
605603

606604
if(variable == "cVeg") {
607-
dt <- openLPJOutputFile(run, "cpool", target.sta, verbose, data.table.only = TRUE)
605+
dt <- openLPJOutputFile(run, "cpool", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
608606
target.cols <- append(getDimInfo(dt), "VegC")
609607
dt <- dt[,target.cols,with=FALSE]
610608
setnames(dt, "VegC", "cVeg")
611609
}
612610
if(variable == "cLitter") {
613-
dt <- openLPJOutputFile(run, "cpool", target.sta, verbose, data.table.only = TRUE)
611+
dt <- openLPJOutputFile(run, "cpool", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
614612
target.cols <- append(getDimInfo(dt), "LittC")
615613
dt <- dt[,target.cols,with=FALSE]
616614
setnames(dt, "LittC", "cLitter")
617615
}
618616
if(variable == "cSoil") {
619-
dt <- openLPJOutputFile(run, "cpool", target.sta, verbose, data.table.only = TRUE)
617+
dt <- openLPJOutputFile(run, "cpool", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
620618
target.cols <- append(unlist(getDimInfo(dt)), c("SoilfC", "SoilsC"))
621619
dt <- dt[,target.cols,with=FALSE]
622620
dt[, "cSoil" := SoilfC + SoilsC]
@@ -627,15 +625,15 @@ openLPJOutputFile_FireMIP <- function(run,
627625
### LAND USE FLUX AND STORE FROM luflux.out FILE
628626

629627
if(variable == "cProduct") {
630-
dt <- openLPJOutputFile(run, "luflux", target.sta, verbose, data.table.only = TRUE)
628+
dt <- openLPJOutputFile(run, "luflux", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
631629
target.cols <- append(getDimInfo(dt), "Products_Pool")
632630
dt <- dt[,target.cols, with = FALSE]
633631
setnames(dt, "Products_Pool", "cProduct")
634632
}
635633

636634
if(variable == "fLuc") {
637635

638-
dt <- openLPJOutputFile(run, "luflux", target.sta, verbose, data.table.only = TRUE)
636+
dt <- openLPJOutputFile(run, "luflux", target.sta, file.name = file.name, verbose = verbose, data.table.only = TRUE)
639637
target.cols <- append(getDimInfo(dt), "Deforest_Flux")
640638
dt <- dt[,target.cols, with = FALSE]
641639
setnames(dt, "Deforest_Flux", "fLuc")
@@ -726,7 +724,7 @@ getStandardQuantity_LPJ <- function(run,
726724
if(quant@id == "vegcover_std") {
727725

728726
# vegcover.out provides the right quantity here (note this is not standard LPJ-GUESS)
729-
data.list <- openLPJOutputFile(run, lookupQuantity("vegcover", GUESS), target.sta, verbose = verbose)
727+
data.list <- openLPJOutputFile(run, lookupQuantity("vegcover", GUESS), target.sta, file.name = file.name, verbose = verbose)
730728

731729
# But we need to scale it to %
732730
if(verbose) message("Multiplying fractional areal vegetation cover by 100 to get percentage areal cover")
@@ -742,23 +740,23 @@ getStandardQuantity_LPJ <- function(run,
742740
else if(quant@id == "vegC_std") {
743741

744742
# cmass provides the right quantity here - so done
745-
this.Field <- openLPJOutputFile(run, lookupQuantity("cmass", GUESS), target.sta, verbose = verbose)
743+
this.Field <- openLPJOutputFile(run, lookupQuantity("cmass", GUESS), target.sta, file.name = file.name, verbose = verbose)
746744

747745
}
748746

749747
# LAI_std
750748
else if(quant@id == "LAI_std") {
751749

752750
# lai provides the right quantity here - so done
753-
this.Field <- openLPJOutputFile(run, lookupQuantity("lai", GUESS), target.sta, verbose = verbose)
751+
this.Field <- openLPJOutputFile(run, lookupQuantity("lai", GUESS), target.sta, file.name = file.name, verbose = verbose)
754752

755753
}
756754

757755
# FPAR_std
758756
else if(quant@id == "FPAR_std") {
759757

760758
# lai provides the right quantity here - so done
761-
this.Field <- openLPJOutputFile(run, lookupQuantity("fpc", GUESS), target.sta, verbose = verbose)
759+
this.Field <- openLPJOutputFile(run, lookupQuantity("fpc", GUESS), target.sta, file.name = file.name, verbose = verbose)
762760
all.layers <- layers(this.Field)
763761
drop.layers <- all.layers [! all.layers %in% c("Total")]
764762
this.Field@data[, (drop.layers) := NULL]
@@ -772,10 +770,10 @@ getStandardQuantity_LPJ <- function(run,
772770
# in older version of LPJ-GUESS, the mgpp file must be aggregated to annual
773771
# newer versions have the agpp output variable which has the per PFT version
774772
if(file.exists(file.path(run@dir, "agpp.out")) || file.exists(file.path(run@dir, "agpp.out.gz"))){
775-
this.Field <- openLPJOutputFile(run, lookupQuantity("agpp", GUESS), target.sta, verbose = verbose)
773+
this.Field <- openLPJOutputFile(run, lookupQuantity("agpp", GUESS), target.sta, file.name = file.name, verbose = verbose)
776774
}
777775
else {
778-
this.Field <- openLPJOutputFile(run, lookupQuantity("mgpp", GUESS), target.sta, verbose = verbose)
776+
this.Field <- openLPJOutputFile(run, lookupQuantity("mgpp", GUESS), target.sta, file.name = file.name, verbose = verbose)
779777
this.Field <- aggregateSubannual(this.Field, method = "sum", target = "Year")
780778
}
781779

@@ -789,10 +787,10 @@ getStandardQuantity_LPJ <- function(run,
789787
# newer versions have the agpp output variable which has the per PFT version
790788

791789
if(file.exists(file.path(run@dir, "anpp.out")) || file.exists(file.path(run@dir, "anpp.out.gz"))){
792-
this.Field <- openLPJOutputFile(run, lookupQuantity("anpp", GUESS), target.sta, verbose = verbose)
790+
this.Field <- openLPJOutputFile(run, lookupQuantity("anpp", GUESS), target.sta, file.name = file.name, verbose = verbose)
793791
}
794792
else{
795-
this.Field <- openLPJOutputFile(run, lookupQuantity("mnpp", GUESS), target.sta, verbose = verbose)
793+
this.Field <- openLPJOutputFile(run, lookupQuantity("mnpp", GUESS), target.sta, file.name = file.name, verbose = verbose)
796794
this.Field <- aggregateSubannual(this.Field , method = "sum", target = "Year")
797795
}
798796

@@ -801,7 +799,7 @@ getStandardQuantity_LPJ <- function(run,
801799
# mNPP_std
802800
else if(quant@id == "aNEE_std") {
803801

804-
this.Field <- openLPJOutputFile(run, lookupQuantity("cflux", GUESS), target.sta, verbose = verbose)
802+
this.Field <- openLPJOutputFile(run, lookupQuantity("cflux", GUESS), target.sta, file.name = file.name, verbose = verbose)
805803

806804
# take NEE and ditch the rest
807805
all.layers <- layers(this.Field)
@@ -814,7 +812,7 @@ getStandardQuantity_LPJ <- function(run,
814812
else if(quant@id == "canopyheight_std") {
815813

816814
# The canopyheight output fromth e benchmarkoutput output module is designed to be exactly this quantity
817-
this.Field <- openLPJOutputFile(run, lookupQuantity("canopyheight", GUESS), target.sta, verbose = verbose)
815+
this.Field <- openLPJOutputFile(run, lookupQuantity("canopyheight", GUESS), target.sta, file.name = file.name, verbose = verbose)
818816
renameLayers(this.Field, "CanHght", "CanopyHeight")
819817

820818
}
@@ -824,15 +822,15 @@ getStandardQuantity_LPJ <- function(run,
824822

825823
# if mfirefrac is present the open it and use it
826824
if("mfirefrac" %in% availableQuantities_GUESS(run, names=TRUE)){
827-
this.Field <- openLPJOutputFile(run, lookupQuantity("mfirefrac", GUESS), target.sta, verbose = verbose)
825+
this.Field <- openLPJOutputFile(run, lookupQuantity("mfirefrac", GUESS), target.sta, file.name = file.name, verbose = verbose)
828826
this.Field <- aggregateSubannual(this.Field, method = "sum")
829827
renameLayers(this.Field, "mfirefrac", quant@id)
830828

831829
}
832830

833831
# otherwise open firert to get GlobFIRM fire return interval and invert it
834832
else {
835-
this.Field <- openLPJOutputFile(run, lookupQuantity("firert", GUESS), target.sta, verbose = verbose)
833+
this.Field <- openLPJOutputFile(run, lookupQuantity("firert", GUESS), target.sta, file.name = file.name, verbose = verbose)
836834
this.Field@data[, "burntfraction_std" := 1 / FireRT]
837835
this.Field@data[, FireRT := NULL]
838836
}

0 commit comments

Comments
 (0)