From 2da975e00c5b75fc643ff0ed8481335f175e92f3 Mon Sep 17 00:00:00 2001
From: ronesy <rlt@nilu.no>
Date: Wed, 29 Sep 2021 15:22:16 +0200
Subject: [PATCH] Change to read_noaa for averaging flask pairs

---
 prep_flexpart/read_noaa.f90           | 37 +++++++++++++++++----------
 prep_flexpart/run_flexpart.sh         | 10 +++++---
 prep_flexpart/sbatch_prep_flexpart.sh |  2 ++
 3 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/prep_flexpart/read_noaa.f90 b/prep_flexpart/read_noaa.f90
index 40a754a..a375085 100644
--- a/prep_flexpart/read_noaa.f90
+++ b/prep_flexpart/read_noaa.f90
@@ -84,8 +84,6 @@ subroutine read_noaa(settings, jd, nr, nobs, obs)
   call caldate(jd, jjjjmmdd, hhmiss)
   eomday = calceomday(jjjjmmdd/100)
 
-  print*, filelist
-
   ! find file matching receptor name
   do n = 1, nfiles
     do i = 1, len_trim(filelist(n))-2
@@ -136,7 +134,7 @@ subroutine read_noaa(settings, jd, nr, nobs, obs)
       i = i + 1
       read(args(n),*) temp(i)
     end do 
-    n = 27
+    n = 26
     i = i + 2
     read(args(n),*,iostat=ierr) temp(i)
     if ( ierr.ne.0 ) print*, 'WARNING: file does not appear to contain sample height -> using altitude'
@@ -189,19 +187,30 @@ subroutine read_noaa(settings, jd, nr, nobs, obs)
   ! average flask pairs
   i = 1
   j = 0
-  dt = 10./(24.*60.)
+  dt = 10./(24.*60.) ! within 10 min -> consider as pair
   if ( nobs.gt.1 ) then
-    do while( i.lt.nobs )
+    do while( i.le.nobs )
       j = j + 1
-      if ( jdobs(i+1).lt.(jdobs(i) + dt) ) then
-        ! this is a pair
-        dataout(j,1) = jdobs(i)
-        dataout(j,2) = 0.5*(concobs(i) + concobs(i+1))
-        dataout(j,3) = errobs(i)
-        dataout(j,4) = latobs(i)
-        dataout(j,5) = lonobs(i)
-        dataout(j,6) = altobs(i)
-        i = i + 2
+      if ( i.lt.nobs ) then
+        if ( jdobs(i+1).lt.(jdobs(i) + dt) .and. altobs(i+1).eq.altobs(i) ) then
+          ! this is a pair
+          dataout(j,1) = jdobs(i)
+          dataout(j,2) = 0.5*(concobs(i) + concobs(i+1))
+          dataout(j,3) = errobs(i)
+          dataout(j,4) = latobs(i)
+          dataout(j,5) = lonobs(i)
+          dataout(j,6) = altobs(i)
+          i = i + 2
+        else
+          ! not a pair
+          dataout(j,1) = jdobs(i)
+          dataout(j,2) = concobs(i)
+          dataout(j,3) = errobs(i)
+          dataout(j,4) = latobs(i)
+          dataout(j,5) = lonobs(i)
+          dataout(j,6) = altobs(i)
+          i = i + 1
+        endif
       else
         ! not a pair
         dataout(j,1) = jdobs(i)
diff --git a/prep_flexpart/run_flexpart.sh b/prep_flexpart/run_flexpart.sh
index ad6f390..a64469a 100755
--- a/prep_flexpart/run_flexpart.sh
+++ b/prep_flexpart/run_flexpart.sh
@@ -14,9 +14,11 @@
 
 # To run tests reference to current directory
 DIR=$PWD
-LEN=`expr length $DIR - 13`
+LEN=`expr length $DIR - 11`
 ROOTDIR=${DIR:0:$LEN}
 
+echo ${ROOTDIR}
+
 #---------------------------------------------------
 
 # User settings
@@ -26,9 +28,9 @@ TIMELIM=12:00:00
 PARTITION="nilu"
 EXENAME=FP_ecmwf_gfortran
 METEO=ecmwf
-DIRFLEX=/home/rthompson/REPOS/GITHUB/FLEXPART/
-DIROPTIONS=${ROOTDIR}TEST_INPUT/FLEXPART/GHG/NEST/
-STNLIST=(SSL)
+DIRFLEX=${ROOTDIR}TEST_CASE_CH4/FLEXPART/
+DIROPTIONS=${ROOTDIR}TEST_CASE_CH4/FP_FILES/
+STNLIST=(PAL)
 MONLIST=(01)
 YEAR=2012
 
diff --git a/prep_flexpart/sbatch_prep_flexpart.sh b/prep_flexpart/sbatch_prep_flexpart.sh
index 403d640..4373726 100755
--- a/prep_flexpart/sbatch_prep_flexpart.sh
+++ b/prep_flexpart/sbatch_prep_flexpart.sh
@@ -4,6 +4,8 @@ partition=debug
 settings_files='./SETTINGS_ghg'
 #---------------------------------------------------
 
+cp ../../prep_flexpart/prep_flexpart .
+
 cat <<EOF > run_job.sh
 #!/bin/bash
 ./prep_flexpart ${settings_files} 
-- 
GitLab