From 68f96614b997303e04965f6c1b9abe79404347ff Mon Sep 17 00:00:00 2001
From: Francesco Sabatini <francesco.sabatini@idiv.de>
Date: Fri, 14 Feb 2020 15:51:38 +0100
Subject: [PATCH] Minor adjustments to A98 and launched in array

---
 code/A98_PredictorsExtract.R | 4 +++-
 code/submit-A98.sh           | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/code/A98_PredictorsExtract.R b/code/A98_PredictorsExtract.R
index 7b8aad7..4221167 100644
--- a/code/A98_PredictorsExtract.R
+++ b/code/A98_PredictorsExtract.R
@@ -10,6 +10,7 @@ PredExtr <- function(x.shp, myfunction=NA, output,
   require(rgdal) 
  
   print(paste("Loading", typp, "data :", toextract))
+  print(paste("output will be:", output))
   if(typp=="raster"){ mypredictor <- raster(toextract)} else
     mypredictor <- readOGR(toextract)
   header.shp <-readOGR(x.shp)
@@ -45,13 +46,14 @@ PredExtr <- function(x.shp, myfunction=NA, output,
     out <- sp::over(x=header.shp, y=mypredictor) 
     toassign <- header.shp[which(is.na(out[,1])),]
     print(paste(length(toassign), "plots not matched directely - seek for NN"))
-
+  if(length(toassign)>0){
     
     nearest <- foreach(i=1:length(toassign), .packages=c('raster'), .combine=rbind) %dopar% { 
       nearest.tmp <- geosphere::dist2Line(toassign[i,], mypredictor)
       return(nearest.tmp)
       }
     out[which(is.na(out[,1])),] <- mypredictor@data[nearest[,"ID"],]
+   }
     write.csv(out, file=output)
   }
   stopCluster(cl)
diff --git a/code/submit-A98.sh b/code/submit-A98.sh
index 28b7664..25e5c6d 100644
--- a/code/submit-A98.sh
+++ b/code/submit-A98.sh
@@ -3,7 +3,7 @@
 #$ -S /bin/bash
 #$ -N PredictorExtract
 
-#$ -o /work/$USER/$JOB_NAME-$JOB_ID.log
+#$ -o /work/$USER/$JOB_NAME-$JOB_ID-$TASK_ID.log
 #$ -j y
 
 #$ -l h_rt=00:30:00:00
@@ -21,7 +21,7 @@ module load R
 filename="$1"
 shift 
 
-output=/work/$USER/output_pred/$(basename $filename .shp).csv
+output=/data/splot/_data_splot3/output_pred/$(basename $filename .shp)-$SGE_TASK_ID.csv
 
 Rscript \
     cli_A98.r \
-- 
GitLab