Write out 2d array to JSON file
Closed this issue · 3 comments
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!
Yes you can do it. I can try to work up a simple example...
Look at the example here: #547
Wonderful, works for me! Thanks, @jacobwilliams.