-
Notifications
You must be signed in to change notification settings - Fork 87
Reading an empty JSON array allocates a random length FORTRAN array #276
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I think because the arrays are empty in JSON, they are coming back from the You could check if they are allocated using something like: if (.not. allocated(integerArray1)) then
write(*,*) 'integerArray1 is empty!'
end if For this case, I wonder if I should have the routine return the vector allocated, but with 0 length? Is that possible in Fortran? (I've never tried it) Also, because you are using the call json%get('values4', integerArray4, found)
if (found) then
print *, integerArray4(:)
print *, size(integerArray4)
else
call exit(4)
end if |
Hi! Thanks for such a quick reply! I think you're right, checking for allocation is the way to go and works perfectly 👍 As for the 0-length array, well... I'm not a Fortran guy so from other languages perspective I find it useful to have the difference: this JSON value doesn't exist VS this JSON value is an array with 0 length I just tried on gfortran and compiling this works fine and prints 0: integer,dimension(0) :: arrayNull
print *, size(arrayNull) But I don't know about other compilers And thanks for the tip ✌️ |
I'll look into the 0-length array thing and see if that is standard... |
According to "Modern Fortran Explained", zero-sized arrays are allowed. So, I think I'll make that change to the code. I agree, it corresponds better to the JSON |
…rray with zero length. Fixes #276
* When reading an empty JSON array it is now returned as an allocated array with zero length. Fixes #276 * fixed unicode issues in last commit.
Hello! First of all thanks a lot for this library, you're saving my life!
Now let's come to the issue, this is an example code:
and the output is:
Since I'm reading those values from a DB I cannot know how long those arrays will be, so there is no check I can do to work it out...
built using: build.sh
OS: x86_64 Ubuntu 16.04
compile command: gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -o "array_test.o" "../array_test.f90"
link command: gfortran -L"/home/andrea/workspace/strutture-energia/fortran-test" -o "array-test" ./array_test.o -ljsonfortran
gfortran -v output:
The text was updated successfully, but these errors were encountered: