Skip to content

Fix size() for large variables >= 2^31 values#482

Open
Dave-Allured wants to merge 1 commit into
Unidata:mainfrom
Dave-Allured:size.63-bit.1
Open

Fix size() for large variables >= 2^31 values#482
Dave-Allured wants to merge 1 commit into
Unidata:mainfrom
Dave-Allured:size.63-bit.1

Conversation

@Dave-Allured
Copy link
Copy Markdown

Refer to #476. This PR might resolve the issue.

This is a straightforward PR, but it is untested. Please run this through CI, or let me know how I can enable CI on my personal fork of netcdf-fortran.

This PR supports large array variables with aggregate size (total number of values [not bytes]) exceeding the original code limit of MAX_INT (2^31 - 1).

The original library code created temp arrays like this. The original fortran 90 size() intrinsic function returned only 32-bit integers. This overflowed and failed whenever the total number of elements (product of multiple dimensions) exceeded MAX_INT:

allocate(defaultIntArray(size(values)))

Fortran 2003+ allows 64-bit integers to be optionally specified for the size() intrinsic. The array limit now becomes MAX_INT64 (2^63 - 1) total number of values:

allocate(defaultIntArray(size(values,kind=EightByteInt)))

This PR fixes all 28 instances of this allocate construction, across three different source files in the fortran/ source directory.

This PR will require a minimum standard of fortran 2003 to build netcdf-fortran. I do not know whether the current overall requirement has already reached fortran 2003.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant