Logic for initializing C isotopes and maybe other variables incorrect when using init_interp
- Dominant language
- Fortran
- Stars
- 352
- Forks
- 361
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
**Bill Sacks < sacks@ucar.edu > - 2017-07-26 06:34:15 -0600**
**Bugzilla Id:** [2496](http://bugz.cgd.ucar.edu/show_bug.cgi?id=2496)
**Bugzilla CC:** cdkoven@lbl.gov, dlawren@ucar.edu, erik@ucar.edu, mvertens@ucar.edu, rfisher@ucar.edu,
Ben pointed this problem out with respect to water isotopes, but I realized that the same problem occurs in existing code for carbon isotopes and possibly other variables: For a number of variables, there is code in the Restart routine that says: If the variable isn't found on the restart file, then initialize it based on some other variable that is guaranteed to be on the restart file - e.g., initialize c13 to the bulk C value times some constant. My understanding is that this code is important when you're transitioning from a run without some option (e.g., without ciso) to a run with that option turned on.
This code works fine if use_init_interp = .false., but I'm pretty sure it won't work with use_init_interp = .true.: Imagine you're doing a run with ciso true, pointing to an finidat file that was generated with ciso false, with use_init_interp true. In this case, finidat_interp_dest.nc is written with all of the C isotope fields present, at their cold start values. In init_interp, these fields will be skipped because they're not found on the source finidat file - and thus they will remain present in the finidat_interp_dest file, with values at the cold start values. Then, back in the CLM Restart routines, the code that checks whether the variable is present on the restart file will say, "Yup, it's present", and so the code for newly-initializing the C isotope fields will never be executed.
Ben and I discussed a number of solutions yesterday, none of them completely satisfying. I won't lay those all out here. But I will lay out one more variation that I just thought of, which has the advantage of NOT requiring finding and changing all of the existing code that has patterns like the C isotope code:
When we write a restart file, add a new attribute to every field like "valid_data" (though we may want to come up with a better name). In the restartvar routine, that would be set to 1 (true) everywhere. Then, in initInterp, in the conditional that checks whether a given output variable is absent from the input file (the lines of code around the message, "variable is NOT on input file"): Set this valid_data attribute to 0 (false). (Aside: it's important that the new attribute value take up no more space than the old attribute value, according to what's allowed in netcdf when you have left 'define' mode. So, for example, it would NOT work to set it to 'true' originally and 'false' in init_interp.) Then, back in the restartvar routine, on read: it would check the value of this valid_data attribute; if 0, then it skips reading the data and sets readvar to .false.
Ben, note that, unlike the solutions we were brainstorming yesterday, this solution does NOT involve identifying the relevant variables and giving them a new interpinic_flag behavior; instead, this solution would apply to ALL variables. I believe it's safe to apply this to all variables. i.e., for these variables that aren't present on the finidat source file, the end result should be the same whether or not we read the data in the Restart routine: they should end up at their cold start values in either case. But if we go with this solution, we may want to give this a little more thought to make sure it's safe.
Contributor guide
Assessment
This issue has not been assessed yet.