mareframe / vat

Visualizing Atlantis Tool (vat)
5 stars 9 forks source link

mat_age error if the biol.prm line has more than one number #13

Closed mcgregorv closed 8 years ago

mcgregorv commented 8 years ago

If the biol.prm file contains another number (ie, a recommended value, or a previously used value), the code for mat_age joins them together, so you can get a large age at maturity. I edited this (rather clumsily, but it works) to take just the first number mat_age <- grep("_age_mat", biolprm, value = T) species_ids <- str_split_fixed(mat_age, "_age_mat", n = 2)[,1]

juvenile_age <- as.numeric(gsub("[^\d]+", "", mat_age, perl=TRUE))[which(species_ids %in% vert_names)]

test how many numbers there are. Sometimes there is an example value as well as the actual value,

in which case we only want the first one

get_first_number<-function(x){ yy<-gsub("([^\d])","#",x,perl=TRUE) yyy<-unlist(str_split(yy,"#")) xPos<-grep("[^\d]",yyy)[1] thisNum<-as.numeric(yyy[xPos]) } temp<-lapply(mat_age,FUN=get_first_number) juvenile_age<-as.numeric(unlist(temp))

cddesja commented 8 years ago

Will double-check that with Iceland and Sicily model. If it works, I'll push it to the master branch.