Adding a new diagnostic output

I am having issues with adding a new 3D diagnostic, Atm(n)%new_var, for output. I registered the variable in atmos_cubed_sphere/tools/fv_diagnostics.F90 using register_diag_field as follows (where "id_new" and "new_variable" are just generic names for that new diagnostic):

1. Within the fv_diag_init subroutine:

       idiag%id_new = register_diag_field("dynamics", 'new_variable', axes(1:3), Time, 'new variable', 'K', missing_value=missing_value)

2. Within the subroutine fv_diag, I added:

       if (idiag%id_new > 0) used=send_data(idiag%id_new, Atm(n)%new_var(isc:iec,jsc:jec,:), Time)

3. I also declared the new integer variable "id_new" in fv_arrays.F90.

4. I added the appropriate line to output this new diagnostic in the diag_table file.

I'm getting an error message that says it's still not properly registered:

       "WARNING from PE     0: diag_util_mod::opening_file: module/field_name (dynamics/new_variable) NOT registered"

Am I doing this correctly? Am I missing something here? Thanks in advance for any pointers!

Yes, of course - apologies for not including that. This is how I added the line in diag_table:

"dynamics",    "new_variable",  "new_variable",  "fv3_history",  "all", .false., "none", 2

It's set as in the default diag_table:

     "fv3_history",             1,  "years",   1, "hours", "time"

This seems to suggest it's only output once a year, but other variables output to fv_history are successfully written out to either dynfHHH.nc or phyfHHH.nc. I'm not sure I fully understand this setting?

You should look for fv3_history.nc files then. The fields in dynfHHH.nc or phyfHHH.nc are not set in fv_diagnostics.F90, but in atmos_cubed_sphere/driver/fvGFS/fv_nggps_diag.F90

I did check for the new diagnostic in the fv3_history.nc file as well, and it wasn't there.

A little update: digging a little deeper, I realized even though the code with my added diagnostics compiled fine, the executable fv3_gfs.x was not actually updated until I removed fv3_gfs.x first, and did a full rebuild. That seems to be the problem. Doing so, I now see my new diagnostic in the fv3_history.nc file!

Thanks for taking a look, jun.wang_1!

The  fv3_gfs.x is generated when you run the ./generate_FV3LAM_wflow.sh script; it is copying the model executable NEMS.exe to fv3_gfs.x.  It is not part of the build step.   It is confusing, and the copy command has been removed from the script.