-
Notifications
You must be signed in to change notification settings - Fork 88
Support for real32 #229
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
Support for real32 #229
Conversation
Added support for real32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my very cursory overview, this all looks good to me.
In one or two places I have some minor concerns about backwards compatibility, and other than that, just code alignment issues...
My rule of thumb for code alignment issues is as follows:
- If added new code blocks (multiple lines) then ensure the alignment follows the conventions in those new lines.
- If a single line modification is needed, don't worry about alignment because you otherwise you'll introduce white space changes and hide any substantive change you made to the code.
Of course I defer to our BDFL, @jacobwilliams, and his all knowing judgement of all things JSON-Fortran, but wanted to add my $0.02 saying that this mostly looks great and would be a nice addition to JSON-Fortran.
@@ -1231,7 +1331,7 @@ end subroutine wrap_json_file_update_logical | |||
!# See also | |||
! * [[json_update_double]] | |||
|
|||
subroutine json_file_update_real(me,name,val,found) | |||
subroutine json_file_update_double(me,name,val,found) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this a public method? (I'm concerned about backwards compatibility)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is private, so it should be OK.
@@ -1255,7 +1397,7 @@ subroutine wrap_json_file_update_real(me,name,val,found) | |||
|
|||
class(json_file),intent(inout) :: me | |||
character(kind=CDK,len=*),intent(in) :: name | |||
real(RK),intent(in) :: val | |||
real(RK32),intent(in) :: val |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some white space should be deleted here for stylistic consistency. I think RK was publicly exposed, but I doubt anyone was using it; the only kind parameter that should have a large impact on client code is the character kind....
str = repeat(star,len(str)) | ||
end if | ||
|
||
end subroutine real32_to_string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this subroutine necessary? Couldn't you just create a wrapper for the real_to_string that handles doubles and just cast the 32 bit real as a 64bit real before passing it? (You could use different default edit descriptors like you do here and just pass them in to the original to_string subroutine.)
@@ -117,7 +117,8 @@ module json_value_module | |||
|
|||
character(kind=CK,len=:),allocatable :: name !! variable name | |||
|
|||
real(RK),allocatable :: dbl_value !! real data for this variable | |||
real(RK32),allocatable :: real_value !! real32 data for this variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
White space alignment...
@@ -2579,6 +2729,59 @@ subroutine wrap_json_value_add_double_vec(json, p, name, val) | |||
call json%add(p, to_unicode(name), val) | |||
|
|||
end subroutine wrap_json_value_add_double_vec | |||
|
|||
!***************************************************************************************** | |||
!> author: Jacob Williams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wrote this, @jacopo-chevallard, you should probably put yourself as the author... or at least add yourself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really just did copy/paste and changed a few kinds, so no need to add my name, unless it helps to better track the work
|
||
class(json_core),intent(inout) :: json | ||
character(kind=CK,len=*),intent(in) :: str | ||
real(RK32) :: rval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alignment
|
||
class(json_core),intent(inout) :: json | ||
type(json_value),pointer :: me | ||
real(RK32),intent(out) :: value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alignment
class(json_core),intent(inout) :: json | ||
type(json_value),pointer :: p | ||
character(kind=CK,len=*),intent(in) :: name | ||
real(RK32),intent(in) :: val |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alignment
character(kind=CDK,len=*),intent(in) :: path | ||
real(RK32),dimension(:),allocatable,intent(out) :: vec | ||
logical(LK),intent(out),optional :: found | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alignment
Also my other concern is minimizing code duplication... I forgot to mention that in my review above. |
!> | ||
! Get a pointer of the [[json_value]] in this [[json_file]]. | ||
|
||
subroutine get_json_value_in_file(me,value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This routine is not necessary, since it does the same thing as json_file_get_root
, unless I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you're right, calling the generic get
with a json_value
argument will do the job
Give me some time to look at this. I'm OK in principle with merging it in. Thanks! |
Ok, good! |
I guess I lost track of this. Are the recent changes where you can specify the kinds of the integer and reals via a compiler directive enough for your purposes? I'm now hesitant about this because if we add |
hi Jacob,
I fear not, since I need to be able to use both real kind at the same time
I think it's safe to say that in 99% of the scientific codes the only used real kinds are "single" (real32) and double (real64) precision, so there is no need to worry about real128, ...
Also, I agree that generic programming (templating-like) would ease a lot these types of implementations, but you can already get a templating-like programming using modern Python-based pre-processors like fypp. I created the *f90 files from the *fpp ones with command
|
Hi Jacob, I'm reopening this (see #222) since I realised that maintaining a parallel fork of your original repository is quite unpractical, as it obliges me to rebase each time you submit a new release, while it would be much simpler to just integrate my modifications (if you agree!).
Nothing changed from #222, so the information contained there is still valid.