From 9ec52f8eb54d8ebad2f7d90c23eb8e8fa0176ea9 Mon Sep 17 00:00:00 2001
From: Sabine <sabine.eckhardt@nilu.no>
Date: Tue, 1 Oct 2024 13:12:26 +0200
Subject: [PATCH] FP11 CONTROL files created

---
 prep_flexpart/main.f90          |  2 +
 prep_flexpart/makefile          | 84 ++++++++++++++++++---------------
 prep_flexpart/mod_settings.f90  |  2 +-
 prep_flexpart/prep_ageclass.f90 |  6 +--
 prep_flexpart/prep_command.f90  | 46 +++++++++++++-----
 prep_flexpart/prep_releases.f90 |  6 ++-
 prep_flexpart/read_basic.f90    |  2 +-
 source/calc_conc.f90            |  4 +-
 8 files changed, 93 insertions(+), 59 deletions(-)

diff --git a/prep_flexpart/main.f90 b/prep_flexpart/main.f90
index a975fb6..f48a0c2 100644
--- a/prep_flexpart/main.f90
+++ b/prep_flexpart/main.f90
@@ -128,8 +128,10 @@ program main
 
       ! write AGECLASS
       if ( settings%lFPversion.eq.0 ) then
+         write(*,*) 'Preparing ageclass for FP10', settings%lFPversion
          call prep_ageclass_FP10(settings, jd, nr)
       else
+         write(*,*) 'Preparing ageclass for FP11', settings%lFPversion
          call prep_ageclass(settings, jd, nr)
       endif
 
diff --git a/prep_flexpart/makefile b/prep_flexpart/makefile
index 48216e5..a3a0e4b 100644
--- a/prep_flexpart/makefile
+++ b/prep_flexpart/makefile
@@ -1,46 +1,52 @@
-F90     = gfortran
-LIBPATH = /usr/lib/
-INCPATH = /usr/include/
-LNK = -o
-CMPL = -c
-LIBS = -lnetcdf -lnetcdff -llapack
-#FFLAGS   = -O2 -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -ffree-form
-FFLAGS = -O0 -g -m64 -fbounds-check -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -ffree-form \
-         -fbacktrace
-LDFLAGS  = $(FFLAGS)  -L$(LIBPATH) -I$(INCPATH) $(LIBS)
+F90      = /apps/sw/ubuntu22.04/gcc-11.4.0/gcc-13.2.0-tkesyophy2o6rjlzknndu3b4oyasvuqm/bin/gfortran
+LIBPATH1 = /apps/sw/ubuntu22.04/gcc-13.2.0/netcdf-fortran-4.6.1-ubcs4l6pjwpgoeyvz32wpzyzykib6bwm/lib/
+INCPATH1 = /apps/sw/ubuntu22.04/gcc-13.2.0/netcdf-fortran-4.6.1-ubcs4l6pjwpgoeyvz32wpzyzykib6bwm/include/
+
+# OPTIMIZATION LEVEL
+O_LEV = 0 # [0,1,2,3,g,s,fast]
+
+LIBS = -lm -DUSE_NCF -lnetcdff
+
+FFLAGS   = -I$(INCPATH1) -O$(O_LEV) -g -cpp -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -fmessage-length=0 -flto=jobserver -O$(O_LEV) -DUSE_NCF -lnetcdff -fbacktrace -Warray-bounds -fcheck=all # -march=native
+
+LDFLAGS  = $(FFLAGS) -L$(LIBPATH1) -Wl,-rpath,$(LIBPATH1) $(LIBS)
 
 MAIN = prep_flexpart
 
-SRCS =   mod_var.f90 \
-         mod_settings.f90 \
-         mod_dates.f90 \
-         mod_tools.f90 \
-         mod_obs.f90 \
-         mod_strings.f90 \
-         read_reclist.f90 \
-         list_obsfiles.f90 \
-         prep_pathnames.f90 \
-         prep_command.f90 \
-         prep_outgrid.f90 \
-         prep_ageclass.f90 \
-         prep_ageclass_FP10.f90 \
-         prep_releases.f90 \
-         prep_releases_reg.f90 \
-         process_obs.f90 \
-         read_obspack.f90 \
-         read_wdcgg.f90 \
-         read_noaa.f90 \
-         read_icos.f90 \
-         read_basic.f90 \
-         main.f90 
-           
-
-OBJECTS = $(SRCS:.f90=.o)
-$(MAIN): $(OBJECTS) $(MODULES)
-	$(F90) $(LNK) $(MAIN) $(OBJECTS) $(LIBS)
+MODULES  =   mod_var.o \
+         mod_settings.o \
+         mod_dates.o \
+         mod_tools.o \
+         mod_obs.o \
+         mod_strings.o
+
+OBJECTS =   read_reclist.o \
+         list_obsfiles.o \
+         prep_pathnames.o \
+         prep_command.o \
+         prep_outgrid.o \
+         prep_ageclass.o \
+         prep_ageclass_FP10.o \
+         prep_releases.o \
+         prep_releases_reg.o \
+         process_obs.o \
+         read_obspack.o \
+         read_wdcgg.o \
+         read_noaa.o \
+         read_icos.o \
+         read_basic.o \
+         main.o
+
+%.o: %.mod
+
+$(MAIN): $(MODULES) $(OBJECTS)
+	+$(F90) -o $@ $(MODULES) $(OBJECTS) $(LDFLAGS)
+
 %.o : %.f90
-	$(F90) $(LDFLAGS) $(CMPL) $<  -o $@
+	+$(F90) -c $(FFLAGS) $< 
 
 clean:
-	rm -f $(OBJECTS) $(MODULES)
+	rm -f *.o *.mod
+
+.SUFFIXES = $(SUFFIXES) .f90
 
diff --git a/prep_flexpart/mod_settings.f90 b/prep_flexpart/mod_settings.f90
index 924313e..beb460e 100644
--- a/prep_flexpart/mod_settings.f90
+++ b/prep_flexpart/mod_settings.f90
@@ -353,7 +353,7 @@ module mod_settings
           ! General settings
           identifier = "lFPversion:"
           call read_content (line, identifier, cc, cn, cl, match)
-          if ( match ) settings%lselect = int(cn)
+          if ( match ) settings%lFPversion = int(cn)
           identifier = "lselect:"
           call read_content (line, identifier, cc, cn, cl, match)
           if ( match ) settings%lselect = int(cn)
diff --git a/prep_flexpart/prep_ageclass.f90 b/prep_flexpart/prep_ageclass.f90
index 3813158..fbeac57 100644
--- a/prep_flexpart/prep_ageclass.f90
+++ b/prep_flexpart/prep_ageclass.f90
@@ -54,11 +54,11 @@ subroutine prep_ageclass(settings, jd, nr)
 
 
   ! FP 11
+  namelist /nage/ &
+      nageclass
   namelist /ageclass/ &
       lage
 
-  namelist /nage/ &
-      nageclass
  
 
   ! preset namelist variables
@@ -73,8 +73,8 @@ subroutine prep_ageclass(settings, jd, nr)
 
   if( settings%lnamelist.eq.1 ) then
     ! use namelist file format, FP11
-    write(100,nml=ageclass)
     write(100,nml=nage)
+    write(100,nml=ageclass)
   else
     ! use old file format
     write(100,fmt='(A48)') '************************************************'
diff --git a/prep_flexpart/prep_command.f90 b/prep_flexpart/prep_command.f90
index 21cdd08..9a310e9 100644
--- a/prep_flexpart/prep_command.f90
+++ b/prep_flexpart/prep_command.f90
@@ -57,11 +57,12 @@ subroutine prep_command(settings, jd, nr)
   integer                       :: ldirect                ! runtime mode (currently only backwards: ldirect = -1)
   integer                       :: ibdate, ibtime
   integer                       :: iedate, ietime
-  integer                       :: partsplit
+!  integer                       :: partsplit
   integer                       :: loutstep
   integer                       :: loutaver
   integer                       :: loutsample
-  integer                       :: itsplit                ! time constant for particle splitting (secs)
+  integer                       :: loutrestart
+!  integer                       :: itsplit                ! time constant for particle splitting (secs)
   integer                       :: lsynctime              ! synchronisation interval of flexpart (secs)
   real                          :: ctl                    ! factor by which time step must be smaller than tl
   integer                       :: ifine                  ! factor by which to decrease time step for vertical motion
@@ -69,12 +70,19 @@ subroutine prep_command(settings, jd, nr)
   integer                       :: ipout                  ! particle dump (0 = never, 1 = every output interval, 2 = only at end)
   integer                       :: lsubgrid               ! use subgrid terrain effect parameterization (0 = no, 1 = yes)
   integer                       :: lconvection            ! use convection (0 = no, 1 = yes)
+  integer                       :: lturbulence            ! FP11
+  integer                       :: lturbulence_meso       ! FP11
+  integer                       :: nxshift                ! FP11
+  integer                       :: maxthreadgrid          ! FP11
+  integer                       :: maxfilesize            ! FP11
+  integer                       :: logvertinterp          ! FP11
+  integer                       :: bcscheme               ! FP11
   integer                       :: lagespectra            ! calculate age spectra (0 = no, 1 = yes)
   integer                       :: ipin                   ! continue simulation with dumped particle data (0 = no, 1 = yes)
   integer                       :: ioutputforeachrelease  ! create output file for each release location (0 = no, 1 = yes)
   integer                       :: mdomainfill            ! domain filling option (0 = no, 1 = yes)
   integer                       :: mquasilag              ! quasilagrangian mode to track particles (0 = no, 1 = yes)
-  integer                       :: surf_only              ! save only surface layer in grid_time files = 1, full resolution = 0
+  integer                       :: sfc_only              ! save only surface layer in grid_time files = 1, full resolution = 0
   integer                       :: lnetcdfout             ! netcdf output (0 = no, 1 = yes)
   integer                       :: cblflag                ! 
   integer                       :: linversionout          ! one grid_time file per release = 1, or per timestep (original format) = 0
@@ -92,7 +100,7 @@ subroutine prep_command(settings, jd, nr)
     loutstep, &
     loutaver, &
     loutsample, &
-    itsplit, &
+!    itsplit, &
     lsynctime, &
     ctl, &
     ifine, &
@@ -100,6 +108,14 @@ subroutine prep_command(settings, jd, nr)
     ipout, &
     lsubgrid, &
     lconvection, &
+    lturbulence, &
+    lturbulence_meso, &
+    nxshift, &
+    maxthreadgrid, &
+    maxfilesize, &
+    logvertinterp, &
+    bcscheme, &
+    loutrestart, &
     lagespectra, &
     ipin, &
     ioutputforeachrelease, &
@@ -111,7 +127,7 @@ subroutine prep_command(settings, jd, nr)
     nested_output, &
     linit_cond, &
     lnetcdfout, &
-    surf_only, &
+    sfc_only, &
     cblflag, &
     linversionout, &
     ohfields_path
@@ -144,14 +160,23 @@ subroutine prep_command(settings, jd, nr)
   loutstep = settings%outrate
   loutaver = settings%outaverage
   loutsample = settings%outsample
-  itsplit = 999999999
+!  itsplit = 999999999
   lsynctime = lsync
   ctl = -5
   ifine = 4
   iout = 1
-  ipout = 2
+  ipout = 0
   lsubgrid = 1
   lconvection = 1
+  lturbulence = 1
+  lturbulence_meso = 0
+  lnetcdfout = 0
+  nxshift = 1
+  maxthreadgrid = 1
+  maxfilesize = 10000
+  logvertinterp = 0
+  bcscheme = 1
+  loutrestart = -1
   lagespectra = 1
   ipin = 0
   ioutputforeachrelease = 1
@@ -162,8 +187,7 @@ subroutine prep_command(settings, jd, nr)
   mquasilag = 0
   nested_output = settings%lnested
   linit_cond = settings%linit_cond
-  lnetcdfout = 0
-  surf_only = 1
+  sfc_only = 1
   cblflag = 0
   linversionout = 1
   ohfields_path = trim(settings%path_ohfield)
@@ -189,7 +213,7 @@ subroutine prep_command(settings, jd, nr)
     write(100,fmt='(I5)')          settings%outrate
     write(100,fmt='(I5)')          settings%outaverage
     write(100,fmt='(I5)')          settings%outsample
-    write(100,fmt='(I9)')          itsplit
+!    write(100,fmt='(I9)')          itsplit
     write(100,fmt='(I3,3X,A14)')   lsynctime,'SYNC'
     write(100,fmt='(F5.2,1X,A10)') ctl,'CTL'
     write(100,fmt='(I3,3X,A14)')   ifine,'IFINE'
@@ -207,7 +231,7 @@ subroutine prep_command(settings, jd, nr)
     write(100,fmt='(I1,5X,A14)')   mquasilag,'MQUASILAG'
     write(100,fmt='(I1,5X,A14)')   settings%lnested,'NESTED_OUTPUT'
     write(100,fmt='(I1,5X,A14)')   settings%linit_cond,'LINIT_COND'
-    write(100,fmt='(I1,5X,A14)')   surf_only,'SURF_ONLY'
+    write(100,fmt='(I1,5X,A14)')   sfc_only,'SURF_ONLY'
     write(100,fmt='(I1,5X,A14)')   linversionout,'LINVERSIONOUT'
   endif
 
diff --git a/prep_flexpart/prep_releases.f90 b/prep_flexpart/prep_releases.f90
index 350ee58..a015180 100644
--- a/prep_flexpart/prep_releases.f90
+++ b/prep_flexpart/prep_releases.f90
@@ -94,9 +94,11 @@ subroutine prep_releases(settings, jd, nr, nobs, obs)
   nchar = len_trim(settings%species)
   do while ( ierr.eq.0 )
     read (100, fmt='(A)', iostat=ierr) line
-    if ( line(len_trim(line)-nchar+1:len_trim(line)) == trim(settings%species) ) ierr = 1
+! sec - reads the last char   if ( line(len_trim(line)-nchar+1:len_trim(line)) == trim(settings%species) ) ierr = 1
+    if ( line(5:5+nchar-1) == trim(settings%species) ) ierr = 1
   end do
-  read(line(9:11),*) spec
+! sec - read(line(9:11),*) spec
+  read(line(1:3),*) spec
   write(aspec,fmt='(I3.3)') spec
 
   ! preset namelist variables releases_ctrl
diff --git a/prep_flexpart/read_basic.f90 b/prep_flexpart/read_basic.f90
index fc0c5a2..9f29efa 100644
--- a/prep_flexpart/read_basic.f90
+++ b/prep_flexpart/read_basic.f90
@@ -181,7 +181,7 @@ subroutine read_basic(settings, jd, nr, nobs, obs)
   if ( nobs.eq.0 ) go to 20
 
   ! write formatted obs to file
-  file_out = trim(settings%path_obsout)//trim(recname(nr))//'_'//trim(settings%species)//'.txt'
+  file_out = trim(settings%path_obsout)//trim(recname(nr))//'_'//trim(settings%species)//'.gob'
   inquire(file=trim(file_out),exist=lexist)
   if( lexist ) then
     ! append to existing
diff --git a/source/calc_conc.f90 b/source/calc_conc.f90
index d08fdd0..c3e1a0f 100644
--- a/source/calc_conc.f90
+++ b/source/calc_conc.f90
@@ -76,8 +76,8 @@ subroutine calc_conc(config, fluxes, obs, ngrid, gtime, hnest, hbkg, iobs, ix1,
     flxbg = fluxes%flxnee(:,:,ind) + &
                     fluxes%flxff(:,:,ind) + &
                     fluxes%flxocn(:,:,ind) 
-  else if ( trim(config%spec).eq.'ghg' ) then
-    ! GHG species
+  else if (( trim(config%spec).eq.'ghg' ) .or. ( trim(config%spec).eq.'bca' )) then
+    ! GHG or BC aerosol species
     flxbg = fluxes%flx(:,:,ind)
   endif
 
-- 
GitLab