New URL for NEMO forge!

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
#1934 (Bug in diawri.F90:dia_wri() for kinetic energy (eken)) – NEMO

Opened 6 years ago

Closed 6 years ago

Last modified 22 months ago

#1934 closed Bug (fixed)

Bug in diawri.F90:dia_wri() for kinetic energy (eken)

Reported by: pderian Owned by: nemo
Priority: low Milestone:
Component: OCE Version: v3.6
Severity: Keywords: OPA eken kinetic outputs v3.6



Experienced "Segmentation fault - invalid memory reference" crashes in diawri.F90:dia_wri() (with key_iomput) when trying to output kinetic energy (field id="eken").


Looking at dia_wri(), there is these lines 297-299:

      IF ( iom_use("eken") ) THEN
         rke(:,:,jk) = 0._wp                               !      kinetic energy
         DO jk = 1, jpkm1

It is unclear why the "rke(:,:,jk) = 0._wp" assignment involves the jk variable in this context. The value of the later is not guaranteed and out-of-bound crash could occur?


Commenting said line 298 fixes the issue.

Commit History (2)


#1934 and #1935 - correct calculation of KE in diawri.F90


#1934 and #1935 - correct KE calculation in diawri.F90

Change History (8)

comment:1 Changed 6 years ago by timgraham

Coincidentally we were looking at this bit of code earlier this morning for another reason. The error you have seen is a bug but the suggested fix is not correct. Line 298 should be replaced with

         rke(:,:,jpk) = 0._wp                               !      kinetic energy

so that the bottom grid point is set to zero (this is because the loop at line 299 only goes to jpkm1. If this is not done then with some compilers invalid values will occur in the bottom grid cell and will cause an error in XIOS later and these errors are really hard to find.

The reason we were looking at the code is that the units suggest that there is a bug. I'll open another ticket for this though.

Last edited 6 years ago by nicolasmartin (previous) (diff)

comment:2 Changed 6 years ago by pderian

I see; thanks Tim for the correct fix!

comment:3 Changed 6 years ago by timgraham

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

Fixed at r8464 of nemo_v3_6_stable and r8465 in the trunk along with another more serious issue in ticket #1935

comment:4 Changed 6 years ago by nemo

  • Keywords outputs added; output removed

comment:5 Changed 6 years ago by nemo

  • Keywords energy removed

comment:6 Changed 6 years ago by nemo

  • Keywords release-3.6* added

comment:7 Changed 6 years ago by nemo

  • Keywords release-3.6* removed

comment:8 Changed 22 months ago by nemo

  • Keywords OPA v3.6 added
Note: See TracTickets for help on using tickets.