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

Write out 2d array to JSON file #546

Closed
seamanticscience opened this issue Nov 17, 2023 · 3 comments · Fixed by #547
Closed

Write out 2d array to JSON file #546

seamanticscience opened this issue Nov 17, 2023 · 3 comments · Fixed by #547
Labels

Comments

@seamanticscience
Copy link

seamanticscience commented Nov 17, 2023

Hello! I'm implementing JSON I/O into a simple Fortran box model of the ocean. I was able to use json-fortran to read in a set of parameters (including a 2d-array, thanks to the instructions here) from a JSON file, but I'm having difficulty writing out 2d arrays.

Here's an example of the JSON input that I can read to an MxN Fortran array and I want to write back out:

 "Pcir" : [
         [0.00, 0.35, 0.15, 0.00, 0.50, 0.00],
         [1.00, 0.00, 0.00, 0.25, 0.00, 0.00],
         [0.00, 0.00, 0.00, 1.00, 0.00, 0.00],
         [0.00, 0.90, 0.55, 0.00, 0.00, 0.90],
         [0.00, 0.00, 0.30, 0.00, 0.00, 0.70],
         [0.00, 0.00, 0.00, 1.10, 0.50, 0.00]
]

I realize one way to approach this would be to unroll the array and write out as an MxN-length vector. However, I'm wondering if there is a way to write the array out as an M-length vector of N-length vectors consistent with the example above?

Thanks in advance!

@jacobwilliams
Copy link
Owner

Yes you can do it. I can try to work up a simple example...

jacobwilliams added a commit that referenced this issue Nov 18, 2023
@jacobwilliams
Copy link
Owner

Look at the example here: #547

@seamanticscience
Copy link
Author

Wonderful, works for me! Thanks, @jacobwilliams.

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

Successfully merging a pull request may close this issue.

2 participants