From e2188d2b01a8d36258ac217c29da058c94f934f2 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Tue, 22 Oct 2024 11:37:36 +0100 Subject: [PATCH 1/3] Add allocate guards for arrays in pressure_mod --- GeosUtil/pressure_mod.F90 | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/GeosUtil/pressure_mod.F90 b/GeosUtil/pressure_mod.F90 index f81a1268d..18f816f2e 100644 --- a/GeosUtil/pressure_mod.F90 +++ b/GeosUtil/pressure_mod.F90 @@ -517,39 +517,47 @@ SUBROUTINE INIT_PRESSURE( Input_Opt, State_Grid, RC ) RC = GC_SUCCESS ThisLoc = ' -> at Init_Pressure (in GeosUtil/pressure_mod.F90)' - ALLOCATE( PFLT_DRY( State_Grid%NX, State_Grid%NY ), STAT=RC ) + IF (.NOT. ALLOCATED( PFLT_DRY )) + ALLOCATE( PFLT_DRY( State_Grid%NX, State_Grid%NY ), STAT=RC ) CALL GC_CheckVar( 'vdiff_mod.F90:PFLT_DRY', 2, RC ) IF ( RC /= GC_SUCCESS ) RETURN PFLT_DRY = 0e+0_fp - ALLOCATE( PFLT_WET( State_Grid%NX, State_Grid%NY ), STAT=RC ) + IF (.NOT. ALLOCATED( PFLT_WET )) + ALLOCATE( PFLT_WET( State_Grid%NX, State_Grid%NY ), STAT=RC ) CALL GC_CheckVar( 'vdiff_mod.F90:PFLT_WET', 2, RC ) IF ( RC /= GC_SUCCESS ) RETURN PFLT_WET = 0e+0_fp - ALLOCATE( AP( State_Grid%NZ+1 ), STAT=RC ) + IF (.NOT. ALLOCATED( AP )) + ALLOCATE( AP( State_Grid%NZ+1 ), STAT=RC ) CALL GC_CheckVar( 'vdiff_mod.F90:AP', 2, RC ) IF ( RC /= GC_SUCCESS ) RETURN AP = 1e+0_fp - ALLOCATE( BP( State_Grid%NZ+1 ), STAT=RC ) + IF (.NOT. ALLOCATED( BP )) + ALLOCATE( BP( State_Grid%NZ+1 ), STAT=RC ) CALL GC_CheckVar( 'vdiff_mod.F90:BP', 2, RC ) IF ( RC /= GC_SUCCESS ) RETURN BP = 0e+0_fp - ALLOCATE( AP_FULLGRID( State_Grid%NativeNZ+1 ), STAT=RC ) + IF (.NOT. ALLOCATED( AP_FULLGRID )) + ALLOCATE( AP_FULLGRID( State_Grid%NativeNZ+1 ), STAT=RC ) CALL GC_CheckVar( 'vdiff_mod.F90:AP_FULLGRID', 2, RC ) IF ( RC /= GC_SUCCESS ) RETURN AP = 1e+0_fp - ALLOCATE( BP_FULLGRID( State_Grid%NativeNZ+1 ), STAT=RC ) + IF (.NOT. ALLOCATED( BP_FULLGRID )) + ALLOCATE( BP_FULLGRID( State_Grid%NativeNZ+1 ), STAT=RC ) CALL GC_CheckVar( 'vdiff_mod.F90:BP_FULLGRID', 2, RC ) IF ( RC /= GC_SUCCESS ) RETURN BP = 0e+0_fp #if defined( ESMF_ ) || defined( MODEL_ ) - ALLOCATE( EXTERNAL_PEDGE( State_Grid%NX, State_Grid%NY, State_Grid%NZ+1 ), & - STAT=RC ) + IF (.NOT. ALLOCATED( EXTERNAL_PEDGE )) + ALLOCATE( EXTERNAL_PEDGE( State_Grid%NX, State_Grid%NY, & + State_Grid%NZ+1 ), & + STAT=RC ) CALL GC_CheckVar( 'vdiff_mod.F90:EXTERNAL_PEDGE', 2, RC ) IF ( RC /= GC_SUCCESS ) RETURN EXTERNAL_PEDGE = 0e+0_fp From 9870afb79f16cca57b2f1d5c06de2fb5bf79162c Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Tue, 22 Oct 2024 15:57:57 +0100 Subject: [PATCH 2/3] Add CHANGELOG note --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 860e97617..50413a85d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This file documents all notable changes to the GEOS-Chem repository starting in The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +### Fixed +- Added allocate guards for arrays in `pressure_mod` + ## [14.4.3] - 2024-08-13 ### Added - Added ModelEe.2 (GCAP 2.0) simulation to integration tests for GCClassic From a02905c405361e9063381561045cc5524417a492 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Tue, 29 Oct 2024 16:45:39 +0000 Subject: [PATCH 3/3] Avoid zeroing twice in INIT_PRESSURE --- GeosUtil/pressure_mod.F90 | 63 ++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/GeosUtil/pressure_mod.F90 b/GeosUtil/pressure_mod.F90 index 18f816f2e..f8de6e71e 100644 --- a/GeosUtil/pressure_mod.F90 +++ b/GeosUtil/pressure_mod.F90 @@ -517,50 +517,57 @@ SUBROUTINE INIT_PRESSURE( Input_Opt, State_Grid, RC ) RC = GC_SUCCESS ThisLoc = ' -> at Init_Pressure (in GeosUtil/pressure_mod.F90)' - IF (.NOT. ALLOCATED( PFLT_DRY )) + IF (.NOT. ALLOCATED( PFLT_DRY )) THEN ALLOCATE( PFLT_DRY( State_Grid%NX, State_Grid%NY ), STAT=RC ) - CALL GC_CheckVar( 'vdiff_mod.F90:PFLT_DRY', 2, RC ) - IF ( RC /= GC_SUCCESS ) RETURN - PFLT_DRY = 0e+0_fp + CALL GC_CheckVar( 'vdiff_mod.F90:PFLT_DRY', 2, RC ) + IF ( RC /= GC_SUCCESS ) RETURN + PFLT_DRY = 0e+0_fp + END IF - IF (.NOT. ALLOCATED( PFLT_WET )) + IF (.NOT. ALLOCATED( PFLT_WET )) THEN ALLOCATE( PFLT_WET( State_Grid%NX, State_Grid%NY ), STAT=RC ) - CALL GC_CheckVar( 'vdiff_mod.F90:PFLT_WET', 2, RC ) - IF ( RC /= GC_SUCCESS ) RETURN - PFLT_WET = 0e+0_fp + CALL GC_CheckVar( 'vdiff_mod.F90:PFLT_WET', 2, RC ) + IF ( RC /= GC_SUCCESS ) RETURN + PFLT_WET = 0e+0_fp + END IF - IF (.NOT. ALLOCATED( AP )) + IF (.NOT. ALLOCATED( AP )) THEN ALLOCATE( AP( State_Grid%NZ+1 ), STAT=RC ) - CALL GC_CheckVar( 'vdiff_mod.F90:AP', 2, RC ) - IF ( RC /= GC_SUCCESS ) RETURN - AP = 1e+0_fp + CALL GC_CheckVar( 'vdiff_mod.F90:AP', 2, RC ) + IF ( RC /= GC_SUCCESS ) RETURN + AP = 1e+0_fp + END IF - IF (.NOT. ALLOCATED( BP )) + IF (.NOT. ALLOCATED( BP )) THEN ALLOCATE( BP( State_Grid%NZ+1 ), STAT=RC ) - CALL GC_CheckVar( 'vdiff_mod.F90:BP', 2, RC ) - IF ( RC /= GC_SUCCESS ) RETURN - BP = 0e+0_fp + CALL GC_CheckVar( 'vdiff_mod.F90:BP', 2, RC ) + IF ( RC /= GC_SUCCESS ) RETURN + BP = 0e+0_fp + END IF - IF (.NOT. ALLOCATED( AP_FULLGRID )) + IF (.NOT. ALLOCATED( AP_FULLGRID )) THEN ALLOCATE( AP_FULLGRID( State_Grid%NativeNZ+1 ), STAT=RC ) - CALL GC_CheckVar( 'vdiff_mod.F90:AP_FULLGRID', 2, RC ) - IF ( RC /= GC_SUCCESS ) RETURN - AP = 1e+0_fp + CALL GC_CheckVar( 'vdiff_mod.F90:AP_FULLGRID', 2, RC ) + IF ( RC /= GC_SUCCESS ) RETURN + AP = 1e+0_fp + END IF - IF (.NOT. ALLOCATED( BP_FULLGRID )) + IF (.NOT. ALLOCATED( BP_FULLGRID )) THEN ALLOCATE( BP_FULLGRID( State_Grid%NativeNZ+1 ), STAT=RC ) - CALL GC_CheckVar( 'vdiff_mod.F90:BP_FULLGRID', 2, RC ) - IF ( RC /= GC_SUCCESS ) RETURN - BP = 0e+0_fp + CALL GC_CheckVar( 'vdiff_mod.F90:BP_FULLGRID', 2, RC ) + IF ( RC /= GC_SUCCESS ) RETURN + BP = 0e+0_fp + END IF #if defined( ESMF_ ) || defined( MODEL_ ) - IF (.NOT. ALLOCATED( EXTERNAL_PEDGE )) + IF (.NOT. ALLOCATED( EXTERNAL_PEDGE )) THEN ALLOCATE( EXTERNAL_PEDGE( State_Grid%NX, State_Grid%NY, & State_Grid%NZ+1 ), & STAT=RC ) - CALL GC_CheckVar( 'vdiff_mod.F90:EXTERNAL_PEDGE', 2, RC ) - IF ( RC /= GC_SUCCESS ) RETURN - EXTERNAL_PEDGE = 0e+0_fp + CALL GC_CheckVar( 'vdiff_mod.F90:EXTERNAL_PEDGE', 2, RC ) + IF ( RC /= GC_SUCCESS ) RETURN + EXTERNAL_PEDGE = 0e+0_fp + END IF #endif IF ( State_Grid%NZ == 47 ) THEN