Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshots of integer pbuf fields are incorrect #1243

Open
jimmielin opened this issue Jan 30, 2025 · 0 comments
Open

Snapshots of integer pbuf fields are incorrect #1243

jimmielin opened this issue Jan 30, 2025 · 0 comments
Labels
bug Something isn't working correctly

Comments

@jimmielin
Copy link
Member

jimmielin commented Jan 30, 2025

What happened?

Snapshot writing of integer type (dtype_i4) pbuf fields are incorrect.

cam_snapshot_common.F90::cam_pbuf_snapshot_all_outfld reads all pbuf fields into a real(r8) array but if the data is in dtype_i4 the data read into the arrays will not be correct:

subroutine cam_pbuf_snapshot_all_outfld(lchnk, file_num, pbuf)
   use physics_buffer, only: pbuf_is_used

   integer,                   intent(in) :: lchnk
   integer,                            intent(in) :: file_num
   type(physics_buffer_desc), pointer, intent(in) :: pbuf(:)

   integer :: i, pbuf_idx, ndims
   real(r8), pointer, dimension(:,:)           :: tmpptr2d
   real(r8), pointer, dimension(:,:,:)         :: tmpptr3d
   real(r8), pointer, dimension(:,:,:,:)       :: tmpptr4d
   real(r8), pointer, dimension(:,:,:,:,:)     :: tmpptr5d


   do i=1, npbuf_var

      pbuf_idx= pbuf_get_index(pbuf_snapshot(i)%ddt_string)

...
         ! Retrieve the pbuf data (dependent on the number of dimensions)
         ndims = count(pbuf_snapshot(i)%dim_name(:) /= '')

         select case (ndims)  ! Note that dimension 5 and 6 do not work with pbuf_get_field, so these are not used here

         case (1)
            call pbuf_get_field(pbuf, pbuf_idx, tmpptr2d)
            call outfld(pbuf_snapshot(i)%standard_name, tmpptr2d, pcols, lchnk)
...

What are the steps to reproduce the bug?

Observe saved snapshot files for pbuf fields that have dtype_i4, e.g.

   ! wg top level index of deep cumulus convection.
   call pbuf_add_field('ZM_JT', 'physpkg', dtype_i4, (/pcols/), zm_jt_idx)

   ! wg gathered values of maxi.
   call pbuf_add_field('ZM_MAXG', 'physpkg', dtype_i4, (/pcols/), zm_maxg_idx)

   ! map gathered points to chunk index
   call pbuf_add_field('ZM_IDEEP', 'physpkg', dtype_i4, (/pcols/), zm_ideep_idx)

instead of actual values, the data is written incorrectly:

 pbuf_ZM_JT =
  4.03179200377274e-313, 4.24399158286927e-313, 4.03179200382215e-313,
    4.03179200377274e-313, 4.88059032015885e-313, 4.88059032035648e-313,
    4.88059032035648e-313, 3.81959242487384e-313, 4.45619116191639e-313,

What CAM tag were you using?

cam6_4_047

What machine were you running CAM on?

CISL machine (e.g. cheyenne)

What compiler were you using?

Intel

Path to a case directory, if applicable

No response

Will you be addressing this bug yourself?

Any CAM SE can do this

Extra info

No response

@jimmielin jimmielin added the bug Something isn't working correctly label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
Status: To Do
Development

No branches or pull requests

1 participant