Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

READ not working

Brooks_Van_Horn
New Contributor I
1,221 Views

I am developing a windows dialog based program and have a problem with:

       num = GetDlgItemText(hwDlg, IDC_M1, myBuffer,20)
       If (num /= 0) Then
          iostatus = 1
          do while (iostatus /= 0)
             Read(myBuffer,*,iostat=iostatus) X
          end do

myBuffer = '25.6                  '
num = 4
and X = garbage
iostatus = 59

without the do while and the iostat, the program has a break at the read statement. When I programmed in C++, there was a lock function to keep myBuffer in real ,memory so the i/o works. This is part of a callback routine. What can I do to fix this?

Brooks

0 Kudos
7 Replies
jimdempseyatthecove
Honored Contributor III
1,221 Views

Are you saying, without the do while, you suspect that between the GetDlgItemText into myBuffer, and the internal READ from the text in myBuffer into the numeric X, that the O/S paging system paged out the memory with myBuffer?

If there is a paging issue, and I emphasize if, then it is possible that only part of myBuffer was touched (and paged in) by GetDlgItemText. If this is the case, then immediately preceeding GetDlgItemText, insert

myBuffer = ' '

Note, if the above causes a fault, then your myBuffer address is corrupted or uninitialized.

Jim Dempsey

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,221 Views

I should have mentioned that paging should not have caused a problem.

Jim Dempsey

0 Kudos
andrew_4619
Honored Contributor III
1,221 Views

Two points. ISTATUS=0  OK read /= 0 is a read error. You logic this seems strange! Secondly what is the value of IOSTAT after the first read, that this give you the indication of why it failed.

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,221 Views

Andrew,

he is setting IOSTATUS=1 prior to the do while loop. He expects it to iterate once, but is stating he is experiencing it iterating more than once. His suspicion is that myBuffer experiences a page fault, and that this fault returns an error (status) that is non-zero. Then the second time through, no page fault, no error. Page faults should not be returned as an error (except for non-pagable interrupt level code).

GetDlgItemText will not padd the buffer with blanks, it returns the number of valid bytes. Brooks should pre-set the buffer to ' ' prior to call (or use the length returned to restrict the "input" to the valid bytes:

Read(myBuffer(1:num),*,iostat=iostatus) X

Jim Dempsey

0 Kudos
andrew_4619
Honored Contributor III
1,221 Views

D'oh, I should have read more closely. But 59 is a read format error so the buffer string presumably has some junk in it that cannot translate to a number? Is buffer actually declared as 20 long? I normally pass len(buffer) BTW.

 

0 Kudos
Steven_L_Intel1
Employee
1,221 Views

It's always difficult to diagnose a problem when all we have is snippets, descriptions and pseudo code, but I am going to guess that the callback routine does not include a !DEC$ ATTRIBUTES STDCALL directive, leading to stack corruption. (Note that STDCALL by itself will change to pass-by-value, so add REFERENCE if you want that.) Windows dialog callback routines must be STDCALL. I don't think page faults have anything to do with it.

 

 

0 Kudos
GVautier
New Contributor III
1,221 Views

jimdempseyatthecove wrote:

 

Read(myBuffer(1:num),*,iostat=iostatus) X

 

Effectively, that's the way the read from the string returned by GetDlgItemText must be done.

Fix your code before searching for another error

0 Kudos
Reply