- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want my programto read a user-specified real number for example 3.1415 from a character*6 TVAR
I use the control GetDlgItemText to read the textstring from the control, and everything is fine.
The variables in question are decalered as Character*6 TVAR, and real*4 RDIG
I then use the internal read:
read(string,'(F6.4)',err=xx))RDIG ( the textstring TVAR looks like "3.1415")
This read statement always fails, and I think it is the decimalpoint in the user-written textstring TVAR that
causes the error. Can anyone tell me the reason for this, and,is there a better way to do this
Regards
Reidar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think that the read fail can be caused by the trailing char(0).
Indeed it is -- you have to be careful to convert between C-style and Fortran-style strings when doing Windows programming:
[cpp]!C to Fortran string = string(1 : index(string,char(0))-1) !Fortran to C string = trim(string)//char(0)[/cpp]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We use
read(string,*) x
to convert the number in string into the real number x. I dont know if this is good fortran programming style, but it works ;-)
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think that the read fail can be caused by the trailing char(0).
Something like that can be safer
[cpp]l=getdlgitemtext(...,loc(string)) read(string(1:l),*,iostat=ioerr) x[/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think that the read fail can be caused by the trailing char(0).
Indeed it is -- you have to be careful to convert between C-style and Fortran-style strings when doing Windows programming:
[cpp]!C to Fortran string = string(1 : index(string,char(0))-1) !Fortran to C string = trim(string)//char(0)[/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a function to do that job
[cpp]function cstring(string) character*(*) string character*(len_trim(string)+1) cstring cstring=trim(string)//char(0) end function [/cpp]

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page