Opened 4 months ago

Last modified 2 months ago

#2078 assigned Defect

cn_dir corrupts AGRIF input filenames

Reported by:Franziska Schwarzkopf Component: AGRIF
Version: release-3.6 Severity: minor
Keywords: AGRIF Cc: Franziska Schwarzkopf
Owned by:Jerome Chanut Milestone:
Priority: low

Description (last modified by Nicolas MARTIN)


Input files (forcing etc.) cannot be found if cn_dir differs from ./ in nested configurations.


In AGRIF configurations, when cn_dir differs from ./ inputfiles for the child grid(s) cannot be found. The prefix for the child(s)-filenames is inserted after the first / in cn_dir and not in front of the filename itself.


filename = 'myfile'
cn_dir = './'

—> /1_myfile

filename = 'myfile'
cn_dir = '/path/to/my/file/'

—> /1_path/to/my/file/myfile
instead of /path/to/my/file/1_myfile

Commit History (0)

(No commits)

Change History (6)

comment:1 Changed 4 months ago by Nicolas MARTIN

  • Description modified (diff)

comment:2 Changed 3 months ago by Claire Levy

  • Resolution set to wontfix
  • Status changed from new to closed

Yes, this is the way AGRIF works…

comment:3 Changed 3 months ago by Claire Levy

  • Resolution wontfix deleted
  • Status changed from closed to reopened

comment:4 Changed 3 months ago by Markus Scheinert

On one hand, the effective path to some input-file is meant to be composed by cn_dir//clname, isn't it?
On the other hand any nest-specific file (not the path) needs a prefix consisting of the number of the nest and an underscore, e.g. '1_'.

And this works perfectly without any nests or with nests but with cn_dir only containing a simple './'. But with AGRIF the logic fails if the path in cn_dir has more than one sub-directory in it, because the Fortran function "INDEX()" (see code below) only returns the first position of a pattern, which is "/" in the case on hand. However, the actual position of interest in this pattern-search is the LAST occurrence of "/" in the string clname - in order to extract the filename from the full path without knowing about the original cn_dir.

see iom.F90:

      IF ( .NOT. Agrif_Root() .AND. .NOT. lliof ) THEN

         iln    = INDEX(clname,'/')

         cltmpn = clname(1:iln)
         clname = clname(iln+1:LEN_TRIM(clname))

Erroneous result for the given example

Given cn_dir='/path/to/my/file/' and an already composed clname='/path/to/my/file/my_file', the INDEX() call results in iln=1 instead of iln=17 and thus the extracted filename becomes 'path/to/my/file/my_file'. And consequently for the first nest we get: '1_path/to/my/file/my_file' instead of the intended '/path/to/my/file/1_my_file'.

Proposed SOLUTION:

Find the last occurrence of "/" by searching from the right to the left. Enable back-search in the INDEX() call when diagnosing iln in the code excerpt from above:

         iln    = INDEX(clname,'/',BACK=.true.)

comment:5 Changed 2 months ago by Jerome Chanut

  • Component changed from OPA to AGRIF

comment:6 Changed 2 months ago by nemo

  • Owner set to jchanut
  • Status changed from reopened to assigned
Note: See TracTickets for help on using tickets.