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

Throw exception if not enough data is passed to cmor.write in Python #500

Merged
merged 5 commits into from
Jun 21, 2019

Conversation

mauzey1
Copy link
Collaborator

@mauzey1 mauzey1 commented Jun 12, 2019

Resolves #485

This change checks the amount of data being passed to cmor.write in Python if it is the expected amount for the amount of time passed (either by setting ntimes_passed or passing time values). It will throw an exception if the amount is lower than expected (or if ntimes_passed is negative).

I also added a test to see if the exception is being thrown.

As for Fortran, it looks like it already handles this issue.

if (tshape(i).gt.dshape(i)) then
write(msg, *) 'In FORTRAN: you passed a 2d array that'&
//' is not big enough to hold your var, your data shape is:',&
dshape,'expected shape was:',tshape,char(0)
error_code = CMOR_CRITICAL
call cmor_handle_error(msg,error_code)

@mauzey1 mauzey1 requested a review from doutriaux1 June 12, 2019 18:20
Copy link
Collaborator

@doutriaux1 doutriaux1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauzey1 could we have a FORTRAN test? Also why is the test called "CV" it's not prepare/cv related.

@mauzey1
Copy link
Collaborator Author

mauzey1 commented Jun 12, 2019

@doutriaux1 It is currently named test_python_CMIP6_CV_not_enough_data.py since the CMIP6_CV tests are the only Python tests currently being used in CI. #493 will add the other Python tests back in.

I will get started on a Fortran test.

@mauzey1
Copy link
Collaborator Author

mauzey1 commented Jun 13, 2019

@doutriaux1 Is there a way to catch an error in Fortran? If cmor_write has an error it will return CMOR_CRITICAL, but I want to catch the "not enough data" message.

@doutriaux1
Copy link
Collaborator

@mauzey1 I was dealing with these sort of things back here: https://github.com/PCMDI/cmor/pull/387/files

Let me know if it does not help you.

@mauzey1
Copy link
Collaborator Author

mauzey1 commented Jun 13, 2019

@doutriaux1 I am not sure what to take from that.

Another issue with the Fortran test is that the error uses CMOR_CRITICAL, which exits the program at cmor_handle_error before cmor_write can return the error flag.

@mauzey1
Copy link
Collaborator Author

mauzey1 commented Jun 19, 2019

@doutriaux1 I have moved the not-enough-data test from the CMIP6 CV tests to the Python tests in the Makefile.

@mauzey1 mauzey1 merged commit 7bd38d0 into master Jun 21, 2019
@mauzey1 mauzey1 deleted the 485_not_passing_enough_data_as_data_passes branch June 21, 2019 21:44
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.

not passing enough times as data passes
2 participants