Skip to content

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

Closed

Conversation

jacopo-chevallard
Copy link

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.

Copy link
Contributor

@zbeekman zbeekman left a 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)
Copy link
Contributor

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)

Copy link
Owner

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alignment

@zbeekman
Copy link
Contributor

zbeekman commented Oct 3, 2016

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)
Copy link
Owner

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.

Copy link
Author

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

@jacobwilliams
Copy link
Owner

Give me some time to look at this. I'm OK in principle with merging it in. Thanks!

@jacopo-chevallard
Copy link
Author

Ok, good!

@jacobwilliams
Copy link
Owner

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 real32's why not also real128's? Or all the various integer kinds? The way it's structured now, that would be a ton of duplicate code and wrappers to add (unless and until we can get some kind of sane generic programming feature in Fortran 2020...)

@jacopo-chevallard
Copy link
Author

hi Jacob,

Are the recent changes where you can specify the kinds of the integer and reals via a compiler directive enough for your purposes?

I fear not, since I need to be able to use both real kind at the same time

I'm now hesitant about this because if we add real32's why not also real128's? Or all the various integer kinds?

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, ...
Similarly, most scientific codes perform calculations with real and not integer numbers, so I don't think there will be any strong need of different integer kinds.

The way it's structured now, that would be a ton of duplicate code and wrappers to add (unless and until we can get some kind of sane generic programming feature in Fortran 2020...)

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.
This is what I do usually, and it helped me a lot in reducing errors and to ease the update of the code (I only have to update one function/subroutine, then fypp will create the different combinations of types/shapes).
You can take a look at the attached archived to get an idea of how to sue fypp for templating.

fypp_example.tar.gz

fypp_example2.tar.gz

I created the *f90 files from the *fpp ones with command

 fypp file_name.fpp file_name.f90 -l 100 -f smart

@jacobwilliams
Copy link
Owner

I'm going to assume this has been superseded by: #239 and #387.

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

Successfully merging this pull request may close these issues.

4 participants