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

Check if keyword is valid #534

Closed
jphaupt opened this issue Apr 25, 2023 · 1 comment
Closed

Check if keyword is valid #534

jphaupt opened this issue Apr 25, 2023 · 1 comment
Labels

Comments

@jphaupt
Copy link

jphaupt commented Apr 25, 2023

We are using json-fortran as an input file reader for one of our libraries. Perhaps this is outside the scope of your project, but is it possible to check if a keyword is invalid/unrecognised, or would this have to be done separately? E.g. check if data present in the json was not read by the program.

I guess this would involve reading each keyword present in the json and comparing it to all possible keywords (which would be done outside json-fortran, or given as input), and failing if not.

I just want some error checking, e.g. say x0 has a default value of 0 if it is not found, but the user erroneously inputs "z0": 5. At the moment, the code would simply ignore z0 (and set x0=0 which is not what the user actually wanted), but I would like it to stop.

@jacobwilliams
Copy link
Owner

There are various ways to check if a variable is in the file. The json_file type has a .in operator, so you can do stuff like this:

if (.not. ('x0' .in. f)) error stop 'x0 not found'

Some of the other routines have a found optional argument, so you could check if a variable was found, etc.

To check if a variable is there but not recognized, I think you'd just have to iterate over all the keys and compare them to the list and flag the ones not recognized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants