diff --git a/src/tropolink/templates/connectivity-computation.R b/src/tropolink/templates/connectivity-computation.R old mode 100755 new mode 100644 index 99369df6f6392470c855aabe8c541195ca55091b..9b75606777eb34a1b63a2cce931ae0f3e3b8cb24 --- a/src/tropolink/templates/connectivity-computation.R +++ b/src/tropolink/templates/connectivity-computation.R @@ -3,14 +3,14 @@ ########## Computation of connectivity between geographic locations from air mass trajectories ########## R code embedded in the tropolink web application - https://tropolink.fr/ ########## Authors: Samuel SOUBEYRAND, Hervé RICHARD, Davide MARTINETTI -########## v1.0 (2022-10-30) +########## v1.1 (2022-12-13) ########## License: Creative Commons Attribution 4.0 International ## Initialization of running time time.init=proc.time() -cat("Connectivity code - Version 1.0 \nLast update: 2022-10-30 \nInitialization \n") +cat("Connectivity code - Version 1.1 \nLast update: 2022-12-13 \nInitialization \n") ################################################################################ ## LOAD COMMAND LINE ARGUMENTS provided when the R session was invoked @@ -91,9 +91,6 @@ input.C=read_json(connectivity.specs.filename) ################################################################################ ## SET VARIABLES -## Number of locations in the trajectory study -nlocations.T=length(input.T$locations) - ## Data frame of locations in the trajectory study locations.T=as.data.frame(lapply(input.T$locations,function(u) strsplit(u$value," ")[[1]])) names(locations.T)=locations.T[1,] @@ -120,9 +117,6 @@ tdump.filenames=paste(tdumpfiles.directory,"tdump_",dates,sep="") ## Duration of trajectories in the trajectory file (in hours, absolute value) runtime=input.T$runtime -## Number of trajectory-points in tdump files -ninputrows=nlocations.T*(abs(runtime)+1) - ## Type of buffer, buffer (Circular buffer) or geographic_buffer (Geographic buffer) buffer.type=input.C$parameters$config$method @@ -194,15 +188,13 @@ CONNECT=0 ## Loop over all dates considered in the connectivity study for(k in 1:length(tdump.filenames)){ - ## Number of lines in the tdump file - nlines=as.numeric(system(paste("wc -l < ",tdump.filenames[k],sep=""),inter=TRUE)) - - ## Load trajectory data - TD=matrix(scan(tdump.filenames[k],skip=nlines-ninputrows,quiet=TRUE),nrow=ninputrows,byrow=TRUE) - colnames(TD)=c("TRAJ_NB","MET_GRID_NB","YEAR","MONTH","DAY","HOUR","MINUTE","FORECAST_HOUR","AGE", - "LATITUDE","LONGITUDE","ALTITUDE","PRESSURE","THETA","AIR_TEMP","RAINFALL","MIXDEPTH", - "RELHUMID","SPCHUMID","H2OMIXRA","TERR_MSL", "SUN_FLUX") - TD=as.data.frame(TD) + ## Load trajectory data + TDraw=scan(tdump.filenames[k],quiet=TRUE,what="character") + TD=matrix(as.numeric(TDraw[(which(TDraw=="SUN_FLUX")+1):length(TDraw)]),ncol=22,byrow=TRUE) + colnames(TD)=c("TRAJ_NB","MET_GRID_NB","YEAR","MONTH","DAY","HOUR","MINUTE","FORECAST_HOUR", + "AGE","LATITUDE","LONGITUDE","ALTITUDE","PRESSURE","THETA","AIR_TEMP","RAINFALL", + "MIXDEPTH","RELHUMID","SPCHUMID","H2OMIXRA","TERR_MSL", "SUN_FLUX") + TD=as.data.frame(TD) ## Extract relevant trajectory subsets for every node considered in the connectivity study traj=sapply(locations.indices,function(u){ @@ -231,8 +223,10 @@ for(k in 1:length(tdump.filenames)){ ## Increment connectivity CONNECT=CONNECT+connect1 - ## Display information about the progression of the computation - cat(" Percent complete:",round(k/length(tdump.filenames)*100,digits=1),"\n") + ## Display information about the progression of the computation + if(length(tdump.filenames)<20 | k/20==round(k/20) | k==length(tdump.filenames)){ + cat(" Percent complete:",round(k/length(tdump.filenames)*100,digits=1),"\n") + } }