# \[v4.0.x\] Compilation with AGRIF fails for \`jpksed\` in \*sedchem.f90\*

**URL:** <https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119>\
**Category:** v4.0.x\
**Tags:** AGRIF, SED\
**Created:** [2 September 2021 14:30 UTC](https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119 "2021-09-02T14:30:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrea.gierisch](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@andrea.gierisch](https://nemo-ocean.discourse.group/u/andrea.gierisch)\
**Post date:** [2 September 2021 14:30 UTC](https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119/1 "2021-09-02T14:30:52Z")

</div>

Hi,  
I would like to run NEMO 4.0.6 with both AGRIF and TOP, which should be possible according to  
[https://forge.ipsl.jussieu.fr/nemo/chrome/site/doc/NEMO/guide/html/tracers.html](https://forge.ipsl.jussieu.fr/nemo/chrome/site/doc/NEMO/guide/html/tracers.html)  
But unfortunately I don’t manage to compile with both `key_top` and `key_agrif` activated.

I can compile AGRIF\_DEMO and ORCA2\_ICE\_PISCES without problems, but if I try to combine them like this

```shell
$ ./makenemo -r ORCA2_ICE_PISCES -n ORCA2_ICE_PISCES_AGRIF -m XC50_dmi_fast add_key 'key_agrif'

```

or like this

```shell
$ ./makenemo -r AGRIF_DEMO -n AGRIFTOP -m XC50_dmi_fast -d 'OCE TOP ICE NST' add_key 'key_top'

```

I get the following error message:

```nohighlight
touch /home/ang/nemoSourcecode/release4.0.6_r15206/cfgs/AGRIFTOP/BLD/flags/FFLAGS __nemo__ sedchem.flags
fcm_internal compile:F nemo /home/ang/nemoSourcecode/release4.0.6_r15206/cfgs/AGRIFTOP/BLD/ppsrc/nemo/sedchem.f90 sedchem.o
ftn -o sedchem.o -I/home/ang/nemoSourcecode/release4.0.6_r15206/cfgs/AGRIFTOP/BLD/inc -i4 -r8 -O2 -fp-model fast -fpp -init=zero -I/data/ang/NEMO/sourcecode/xios-2.5/inc -I/opt/cray/pe/netcdf-hdf5parallel/4.4.1.1.6/INTEL/16.0//include -I/opt/cray/pe/hdf5-parallel/1.10.1.1/INTEL/160//include -c /home/ang/nemoSourcecode/release4.0.6_r15206/cfgs/AGRIFTOP/BLD/ppsrc/nemo/sedchem.f90
/home/ang/nemoSourcecode/release4.0.6_r15206/cfgs/AGRIFTOP/BLD/ppsrc/nemo/sedchem.f90(337): error #7915: A specification expression object must be a dummy argument, a COMMON block object, or an object accessible through host or use association - may be used in multiple contained procedures. [JPKSED]
     &1:jpksed) :: p_hini
--------^
/home/ang/nemoSourcecode/release4.0.6_r15206/cfgs/AGRIFTOP/BLD/ppsrc/nemo/sedchem.f90(337): error #6404: This name does not have a type, and must have an explicit type. [JPKSED]
     &1:jpksed) :: p_hini
--------^
compilation aborted for /home/ang/nemoSourcecode/release4.0.6_r15206/cfgs/AGRIFTOP/BLD/ppsrc/nemo/sedchem.f90 (code 1)
fcm_internal compile failed (256)
/home/ang/nemoSourcecode/release4.0.6_r15206/cfgs/AGRIFTOP/BLD/Makefile:2745: recipe for target 'sedchem.o' failed
gmake: *** [sedchem.o] Error 1
gmake -f /home/ang/nemoSourcecode/release4.0.6_r15206/cfgs/AGRIFTOP/BLD/Makefile -j 1 all failed (2) at /netapp/research/ang/nemoSourcecode/release4.0.6_r15206/ext/FCM/bin/../lib/Fcm/Build.pm line 597.
->Make: 877 seconds
->TOTAL: 896 seconds
Build failed on Thu Sep 2 13:29:44 2021.

```

Looking into _ppsrc/nemo/sedchem.f90_ I get the impression that maybe the variable `jpksed` didn’t get replaced properly by the Agrif-preprocessor??

```fortran
332 SUBROUTINE ahini_for_at_sed(p_hini) 333                                                                                                                                                                                                               
334                                                                                                                                                                                                               
335 use Agrif_Util 336 real(wp), intent(OUT), dimension(1: Agrif_tabvars_i(927)% iarray0,&                                                                                                                                     
337 &1:jpksed) :: p_hini   

```

This line corresponds to

```fortran
REAL(wp), DIMENSION(jpoce,jpksed), INTENT(OUT) :: p_hini

```

in _src/TOP/PISCES/SED/sedchem.F90_

I would be happy if someone has a hint for me…  
Thanks,  
Andrea

PS: I use the intel compiler and this is my arch-file:

```perl
%NCDF_HOME /opt/cray/pe/netcdf-hdf5parallel/4.4.1.1.6/INTEL/16.0/       
%HDF5_HOME /opt/cray/pe/hdf5-parallel/1.10.1.1/INTEL/160/ 
%NCDF_INC -I%NCDF_HOME/include -I%HDF5_HOME/include 
%NCDF_LIB -L%HDF5_HOME/lib -L%NCDF_HOME/lib -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz

%XIOS_HOME /data/ang/NEMO/sourcecode/xios-2.5
%XIOS_INC -I%XIOS_HOME/inc
%XIOS_LIB -L%XIOS_HOME/lib -lxios

%CPP cpp -Dkey_nosignedzero -DAGRIF_MPI
%FC ftn
%FCFLAGS -i4 -r8 -O2 -fp-model fast -fpp -init=zero 
%FFLAGS %FCFLAGS
%LD CC -Wl,"--allow-multiple-definition"
%LDFLAGS             
%FPPFLAGS -P -C -traditional -x f95-cpp-input
%AR ar
%ARFLAGS rs
%MK gmake
 
%USER_INC %XIOS_INC %NCDF_INC
%USER_LIB %XIOS_LIB %NCDF_LIB

%CC cc
%CFLAGS -O0

```

---

<div class="post-metadata">

**Author:** ![acc](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@acc](https://nemo-ocean.discourse.group/u/acc)\
**Post date:** [7 September 2021 15:19 UTC](https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119/2 "2021-09-07T15:19:56Z")

</div>

> [@andrea.gierisch](#):
>
> add\_key ‘key\_agrif’

Hi Andrea, There does indeed appear to be a strange scoping problem with the SED modules when compiled with AGRIF. It isn’t clear whether or not `jpksed` needs to be replaced by the AGRIF preprocessor. I would assume it is the same in all nests. However, it can be set via the namelist (not very coding convention compliant!). Regardless, it should be known to in _sedchem.F90_ from the `par_sed` module (which is included in the SED module). Perhaps the layers of modules have confused the scope?

I can get your first example to compile with these two additional `USE` statements:

```diff
Index: TOP/PISCES/SED/sedchem.F90
===================================================================
--- TOP/PISCES/SED/sedchem.F90	(revision 15228)
+++ TOP/PISCES/SED/sedchem.F90	(working copy)
@@ -5,6 +5,7 @@
    !! sediment : Variable for chemistry of the CO2 cycle
    !!======================================================================
    !! modules used
+ USE par_sed, ONLY : jpksed
    USE sed ! sediment global variable
    USE sedarr
    USE eosbn2, ONLY : neos
Index: TOP/PISCES/SED/seddta.F90
===================================================================
--- TOP/PISCES/SED/seddta.F90	(revision 15228)
+++ TOP/PISCES/SED/seddta.F90	(working copy)
@@ -7,6 +7,7 @@
    !! * Modules used
    USE sed
    USE sedarr
+ USE par_pisces
    USE phycst, ONLY : rday
    USE iom
    USE lib_mpp ! distribued memory computing library

```

-neither of which should be necessary. No guarantee this will run and it’ll take a real AGRIF expert to provide an explanation and proper solution, but you could try this in the absence of any other ideas.

---

<div class="post-metadata">

**Author:** ![jchanut](https://yyz2.discourse-cdn.com/free1/user_avatar/nemo-ocean.discourse.group/jchanut/32/9_2.png) [@jchanut](https://nemo-ocean.discourse.group/u/jchanut)\
**Post date:** [8 September 2021 11:00 UTC](https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119/3 "2021-09-08T11:00:25Z")

</div>

My experience is that using layers of modules to define a variable does not work with AGRIF pre-processing. Using `par_sed` in _sedchem.F90_ appears unavoidable. Looking at the trunk, which has an AGRIF-TOP reference configuration (e.g. AGRIF\_DEMO, running Age tracer only though), `par_sed` is indeed used.  
This said, @acc, why did you have to use `par_pisces` in _seddta.F90_ ?

---

<div class="post-metadata">

**Author:** ![acc](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@acc](https://nemo-ocean.discourse.group/u/acc)\
**Post date:** [8 September 2021 11:41 UTC](https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119/4 "2021-09-08T11:41:51Z")

</div>

Using `par_sed` directly fixed _sedchem.F90_ but then I encountered issues with `seddta.F90` that claimed not to know any of the tracer indices (jpno3 etc.). Another layered modules issue, I believe (although it isn’t immediately obvious how even the non-AGRIF version of `seddta.F90` is supposed to know?).

---

<div class="post-metadata">

**Author:** ![jchanut](https://yyz2.discourse-cdn.com/free1/user_avatar/nemo-ocean.discourse.group/jchanut/32/9_2.png) [@jchanut](https://nemo-ocean.discourse.group/u/jchanut)\
**Post date:** [8 September 2021 13:58 UTC](https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119/5 "2021-09-08T13:58:17Z")

</div>

Thanks Andrew: I raise a ticket. @andrea.gierisch, you’ll find the above compilation fixes in the NEMO r4.0-HEAD (which will become NEMO 4.0.7 very soon).

---

<div class="post-metadata">

**Author:** ![clem](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@clem](https://nemo-ocean.discourse.group/u/clem)\
**Post date:** [8 September 2021 14:11 UTC](https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119/6 "2021-09-08T14:11:16Z")

</div>

I did the changes for both the trunk and 4.0-HEAD. I just run a quick (ha ha ha) sette to see if it breaks anything and then I’ll commit

---

<div class="post-metadata">

**Author:** ![jchanut](https://yyz2.discourse-cdn.com/free1/user_avatar/nemo-ocean.discourse.group/jchanut/32/9_2.png) [@jchanut](https://nemo-ocean.discourse.group/u/jchanut)\
**Post date:** [8 September 2021 14:15 UTC](https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119/7 "2021-09-08T14:15:34Z")

</div>

ok, refers to ticket [#2719](https://forge.ipsl.jussieu.fr/nemo/ticket/2719) then.  
But it should already be fine in the trunk ?

---

<div class="post-metadata">

**Author:** ![clem](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@clem](https://nemo-ocean.discourse.group/u/clem)\
**Post date:** [8 September 2021 14:29 UTC](https://nemo-ocean.discourse.group/t/v4-0-x-compilation-with-agrif-fails-for-jpksed-in-sedchem-f90/119/8 "2021-09-08T14:29:28Z")

</div>

I’ll put the exact same `USE` in 4.0 and the trunk (not the case right now).
