Opened 7 years ago
Closed 5 years ago
#2078 closed Defect (fixed)
cn_dir corrupts AGRIF input filenames
Reported by: | fschwarzkopf | Owned by: | jchanut |
---|---|---|---|
Priority: | low | Milestone: | |
Component: | AGRIF | Version: | trunk |
Severity: | minor | Keywords: | AGRIF |
Cc: | fschwarzkopf |
Description (last modified by nicolasmartin)
Context
Input files (forcing etc.) cannot be found if cn_dir differs from ./ in nested configurations.
Analysis
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.
Example:
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 (1)
Changeset | Author | Time | ChangeLog |
---|---|---|---|
11554 | jchanut | 2019-09-17T11:46:30+02:00 | #2078: add Franziska's fix to correct input/output paths with AGRIF |
Attachments (1)
Change History (11)
comment:1 Changed 7 years ago by nicolasmartin
- Description modified (diff)
comment:2 Changed 7 years ago by clevy
- Resolution set to wontfix
- Status changed from new to closed
comment:3 Changed 7 years ago by clevy
- Resolution wontfix deleted
- Status changed from closed to reopened
comment:4 Changed 7 years ago by mscheinert
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)) clname=TRIM(cltmpn)//TRIM(Agrif_CFixed())//'_'//TRIM(clname) ENDIF
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 7 years ago by jchanut
- Component changed from OPA to AGRIF
comment:6 Changed 7 years ago by nemo
- Owner set to jchanut
- Status changed from reopened to assigned
comment:7 Changed 6 years ago by jchanut
- Version changed from v3.6 to trunk
comment:8 Changed 6 years ago by fschwarzkopf
- Version trunk deleted
The above provided fix also works in NEMO4 (iom.F90 line 699; subroutine iom_open).
A similar erroneous behaviour occurs for writing output (using xios) into a directory different from the current working directory defined in file_definition;
e.g. <file_definition type="one_file" name="/path/to/output/@expname@_@freq@_@startdate@_@enddate@" sync_freq="1mo" min_digits="4">
This can be analogously fixed in subroutine iom_update_file_name, substituting line 2323:
IF( jn == 1 .AND. TRIM(Agrif_CFixed()) /= '0' ) clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
by
IF( jn == 1 .AND. TRIM(Agrif_CFixed()) /= '0' ) THEN iln = INDEX(clname,'/',BACK=.true.) cltmpn = clname(1:iln) clname = clname(iln+1:LEN_TRIM(clname)) clname = TRIM(cltmpn)//TRIM(Agrif_CFixed())//'_'//TRIM(clname) ENDIF
iln and cltmpn need to be declared:
CHARACTER(LEN=256) :: cltmpn INTEGER :: iln
Btw: only one file_definition is used. I.e. if file_definitions in file_def_nemo-oce.xml, file_def_nemo-ice.xml and others differ, only the last one given in context_nemo.xml is used.
comment:9 Changed 5 years ago by jchanut
In 11554:
comment:10 Changed 5 years ago by jchanut
- Resolution set to fixed
- Status changed from assigned to closed
- Version set to trunk
Yes, this is the way AGRIF works...