From 53324c34c9b689d1ab2e245a0e12ebe36050c044 Mon Sep 17 00:00:00 2001
From: ronesy <rlt@nilu.no>
Date: Tue, 18 Oct 2022 11:15:35 +0200
Subject: [PATCH] bug fix in calculating cost for lognormal in m1qn3_interface

---
 source/m1qn3_interface.f90 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source/m1qn3_interface.f90 b/source/m1qn3_interface.f90
index 52a3d19..68ca430 100644
--- a/source/m1qn3_interface.f90
+++ b/source/m1qn3_interface.f90
@@ -190,11 +190,11 @@ subroutine m1qn3_interface(iter, grad, files, config, fluxes, obs, states, covar
       if ( config%lognormal ) then
         ! lognormal
         ! 2Jp = 2*sum(z) + x^Tx (where x = state vector in chi space and z is state vector in physical space)
-        cost_p = sum(states%px) + dot_product(x,x)
+        cost_p = 2.*sum(states%px) + real(dot_product(x,x),kind=4)
       else
         ! normal
         ! 2Jp = x^Tx (where x = state vector in chi space)
-        cost_p = dot_product(x,x) 
+        cost_p = real(dot_product(x,x),kind=4) 
       endif
       ! J = 0.5*(Jp + Jo) 
       cost = 0.5*(cost_p + cost_o)
-- 
GitLab