- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello friends!
I am receiving a warning message of overflow(see attached) when trying to convert character to real.
This is the simple piece of code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hm, also not correct. I will encourage you to have a look into the help: https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-format-specifications
What you have done in 1) is to write the real number as 5 digit field to a 4 character long character variable. Does not match, isn't it.Try something like this:
program test implicit none real(kind=1.0) :: num_nlevels character(len=100) :: nLevels write(nLevels,'(F5.0)') num_nlevels write(*,'(a)') trim(nLevels) ! or write(nLevels,'(I0)') nint(num_nlevels) write(*,'(a)') trim(nLevels) end program test
ps: Arjen was faster ;-)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hm, you have defined num_levels as a real and you are using an integer format to read it from the character string. There is a discrepancy here ;).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Arjen!
My fault, lack of attention, sorry!!!! I made a mistake copying the code.
I tried both; define "num_nLevels" as integer and real. In both cases it is giving me back the same error (output statement overflows record)
1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well, for case 1 you are trying to put 5 characters into a character string of length 4. And depending on the actual value of num_levels (you do not show it), this sting length might not be enough in case 2 either.
Why not try with a much larger character length? 20 or 40, say. Just to see what happens.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hm, also not correct. I will encourage you to have a look into the help: https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-format-specifications
What you have done in 1) is to write the real number as 5 digit field to a 4 character long character variable. Does not match, isn't it.Try something like this:
program test implicit none real(kind=1.0) :: num_nlevels character(len=100) :: nLevels write(nLevels,'(F5.0)') num_nlevels write(*,'(a)') trim(nLevels) ! or write(nLevels,'(I0)') nint(num_nlevels) write(*,'(a)') trim(nLevels) end program test
ps: Arjen was faster ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your time and your effort. These format problems are annoying issues difficult to handle. Johannes, thank you for the link and the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello again!
I am sadly stuck in the middle of nowhere and I don't know what else I can try. I am using VisualStudio for Fortran developings. I can not attach a dat file, so I captured screen.
Please someone that tells me why trying write(strlevels,'(F7.0)') nlevels does not work.
THANK YOU!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You want READ and not WRITE if you want to convert the character representation into a REAL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Once again Doctor, thank you. Programming in Fortran makes me feel I do not know anything. Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, in case you will like to read and parse *.JSON files
(open(2,file='C:\file.JSON',status='unknown'),
you might like to use a pure Fortran library written by Jacob Williams:
https://github.com/jacobwilliams/json-fortran
To take advantage from this lib, you might need to enhance your Fortran base skills.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page