- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everybody, I just have a problem with converting, e.g.
Let's have a vector
p= [2.5 2.1 2.5 2.1]
now we have
character*3 par1
And this should work (but its not)
read( par1 , '(i3)' ) p(1)
Problem is, that i really don't know, what does i3 mean.
Is there some better approach for this conversion?
Last thing I have to ask is concatenation (this also is not working):
write(OUT_F,"(a26)")("OUT"//"_text_"//p(1)//"_"//p(2)//"_"
$ //p(3)//"_"//p(4)//"_"//".rep")
I havent found anything what can give mi information what to do. Error is:
error #6358: Constants and expressions are invalid in read-only I/O lists.
And it is not included on Intels website.
Can someone help me, please?
Thank you. Rosa
Let's have a vector
p= [2.5 2.1 2.5 2.1]
now we have
character*3 par1
And this should work (but its not)
read( par1 , '(i3)' ) p(1)
Problem is, that i really don't know, what does i3 mean.
Is there some better approach for this conversion?
Last thing I have to ask is concatenation (this also is not working):
write(OUT_F,"(a26)")("OUT"//"_text_"//p(1)//"_"//p(2)//"_"
$ //p(3)//"_"//p(4)//"_"//".rep")
I havent found anything what can give mi information what to do. Error is:
error #6358: Constants and expressions are invalid in read-only I/O lists.
And it is not included on Intels website.
Can someone help me, please?
Thank you. Rosa
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Instead of
read( par1 , '(i3)' ) p(1)
you need
write (par1, '(i3)') p(1)
Reason: par1 is an "internal file". Initially, the file is empty. There is nothing there to read; furthermore, you already have a value in p(1). You want to write to the internal file the value of p(1), encoded using the format descriptor i3. This descriptor says that the quantity being encoded is an integer, and that three digits (or blanks and digits) are to be output.
Your write statement is wrong because you are trying to concatenate strings with non-strings.
Read the language manuals, Fortran text-books and use on-line tutorials.
read( par1 , '(i3)' ) p(1)
you need
write (par1, '(i3)') p(1)
Reason: par1 is an "internal file". Initially, the file is empty. There is nothing there to read; furthermore, you already have a value in p(1). You want to write to the internal file the value of p(1), encoded using the format descriptor i3. This descriptor says that the quantity being encoded is an integer, and that three digits (or blanks and digits) are to be output.
Your write statement is wrong because you are trying to concatenate strings with non-strings.
Read the language manuals, Fortran text-books and use on-line tutorials.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So the only way to convert real to character is to save real type to a file and then read into character one? I googled this and it seemed to that this conversion should be possible.
Saving p(1) into par1 (character type) was there to substitute it into second term where you correctly mentioned that there is unexpected type. But there's not much information about ways how to do it.
Saving p(1) into par1 (character type) was there to substitute it into second term where you correctly mentioned that there is unexpected type. But there's not much information about ways how to do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The phrase "internal file" is potentially confusing to people coming to Fortran programming from a background in other languages. An "internal file" is not a file in the sense used in describing operating systems, file systems, etc. Usually, an internal file is just a block of memory which may be treated as if it is a file (with some restrictions that do not apply to external files) during the lifetime of a program. Compare a Fortran internal file I/O operation to using the C sprintf/sscanf functions.
Here is a small program to illustrate:
Here is a small program to illustrate:
[fortran]program explore real :: p(4) = [2.5, 2.1, 2.5, 2.1] character(len=3) :: str1 write(str1,'(F3.1)')p(2) ! ! now that p(2) has been encoded into a string, we can concatenate the ! string with other strings ! write(*,*)' After writing p(2) to str1, str1 is : |' // str1 // '|' ! end program explore [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Great, it's working. Thank you a lot!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page