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

Exception Handling with Quickwin

sumitm
Beginner
1,000 Views
Hi,

I have some simple quickwin programs that read input files, does some operation on them and close. It is used on a webserver.
We have tried to make it such that it does not crash but I beieve there are input values etc that can cause runtime errors when running the calculations part of it (not only divide by zero but also square root of negative numbers or artangent calculations etc.).

What I need is something that does not pop up a messagebox with the error when it crashes. Instead of it would send that same message to a text file and quit the application. This is required so that
Most of the error handling examples provided with the samples have a C wrapper. I do not have a C compiler.
Can anyone show a simple example (not only floating point errors but any and all other) in CVF 6.6 where the crash leads to an automatic exit with no pop up message and the error being written to a error.txt file.

There is one function written in fortran in CSLEXCP4 but it is called within C in a try block (code for that is copied below). How do I call the following in CVF (in the beginning or end or in a loop).
Any help would be greatly appreciated.

Sumit
INTEGER(4) FUNCTION CHECK_EXCEPTION_INFO ( ExceptionInfo )
	USE DFLIB
	USE DFWINTY
	USE DFWIN
	!DEC$ ATTRIBUTES REFERENCE :: ExceptionInfo
	TYPE(T_EXCEPTION_POINTERS) ExceptionInfo

	TYPE(T_EXCEPTION_RECORD) ERECPTR
	TYPE(T_CONTEXT) CTXPTR

	POINTER(EPTR,ERECPTR)
	POINTER(CTXP,CTXPTR)

	LOGICAL(4) STS

	EPTR = ExceptionInfo.ExceptionRecord
	CTXP = ExceptionInfo.ContextRecord

	IF ( ERECPTR.ExceptionCode .EQ. STATUS_FLOAT_DIVIDE_BY_ZERO ) THEN
		CALL TRACEBACKQQ(STRING='Handler:  Saw floating divide by zero.', &
							USER_EXIT_CODE=-1, &
							EPTR=%LOC(ExceptionInfo))
		CHECK_EXCEPTION_INFO = EXCEPTION_EXECUTE_HANDLER
	ELSEIF ( ERECPTR.ExceptionCode .EQ. STATUS_FLOAT_UNDERFLOW ) THEN
		CALL TRACEBACKQQ(STRING='Handler:  Saw floating underflow, let default handler deal with it on x86.', &
							USER_EXIT_CODE=-1, &
							EPTR=%LOC(ExceptionInfo))
		CHECK_EXCEPTION_INFO = EXCEPTION_CONTINUE_SEARCH
	ELSE
		PRINT *, 'Saw other than expected exception.'
		CHECK_EXCEPTION_INFO = EXCEPTION_CONTINUE_SEARCH
	END IF

	END
0 Kudos
15 Replies
Steven_L_Intel1
Employee
1,000 Views
You can disable the popup through an environment variable - look up "environment variables" in the on-disk documentation.

Why are you using a QuickWin app as a web server?

Steve
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,000 Views
Sumit, see also GET/SETCONTROLFPQQ -- Floating-point exceptions are maskable. C equivalent is _controlfp. Don't know whether it's what you want (if FP exceptions are masked, you get NaNs and Infs normally).

Jugoslav
0 Kudos
sumitm
Beginner
1,000 Views
Thanks Steve,
The following environment variables took care of it.
Only the error file got appended each time. So I had to do a delfilesqq to the error file before writing to it so that only the last error is displayed.
res1=SETENVQQ("FOR_DISABLE_DIAGNOSTIC_DISPLAY=T")
res2=SETENVQQ("FOR_DIAGNOSTIC_LOG_FILE=error.txt")


Steve the reason I am using quickwin and not console is because I use extensive amount of quickwin graphics and it was not possible for me to rewrite all the routines in the time frame I had. I would like to work on it some time in the future.

One request I would like to make for a future release is if Quickwin would enable displaying graphic images to memory. Rightnow the device outputs are (Console (std) or ports). With that it could write to a virtual screen with predefined resolution.
I use a saveimage command to save the graphics to a bmp file which my C# developer converts to a png and displays on the web.

Thanks again for your help.

0 Kudos
sumitm
Beginner
1,000 Views
Hi,

I now have a followup question. Is there any way to write to stderr or stdout from a quickwin app. I see that the documentation says that only console applications write to standard error device. Quickwin writes to a message box. For now I have disabled the writing to a message box. If I write to a static file like err.txt that presents file locking problems when two users access the same file at the same time on the web server.

I tried myrpog.exe > error.txt and while it creates the file error.txt, there is nothing in it. Is there another setting I need to change.

My only option to prevent file locking is to get the error filename in the command line through getarg and concatenate it to the statement "FOR_DIAGNOSTIC_LOG_FILE=error.txt"

My C# developer says writing to Stderr should be very easy. Is there something I am missing. I looked at the inherit samples under ADVANCED / WIN32. That is way beyond my capabilities.

Thanks for any help.

Sumit
0 Kudos
Steven_L_Intel1
Employee
1,000 Views
There is no stderr or stdout when running a QuickWin application, as there is no console window. If you wish to create one, you can, with a call to AllocConsole. You could then open CONOUT$ as a file and write to it.

I don't understand your question about writing graphics to memory. You can do that now with a window that has been hidden, but I'm sure someone else with more Windows programming expertise than I could explain better.

Steve
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,000 Views
You can always use APIs CreateFile/WriteFile to write to "anything" (Real file, pipe, console, serial port,...). GetStdHandle API should tell you what are the handles of stdin, stdout, and stderr.

However, I'm not sure what's the stdout in a QW app (and if there's any). READ(* and WRITE(* are totally different routines in QW (graphic output) than in other types of output. But that poses another question... why do you need "stdout" -- whatever it is?

Jugoslav


0 Kudos
sumitm
Beginner
1,000 Views
Jugoslav and Steve,
Thanks for your help.
Regarding AllocConsole, I implemented the following code and while it opens a console window, I did not see any error output there. I have no idea how this should work but my C# developer says that this (stderr, stdout) way if there is an error it will get displayed on the webpage running the C# application where my Fortran quickwins are run with command line arguments.
sts=AllocConsole()
handl = GetStdHandle(STD_OUTPUT_HANDLE)

res1=SETENVQQ("FOR_DISABLE_DIAGNOSTIC_DISPLAY=T")
res2=SETENVQQ("FOR_DIAGNOSTIC_LOG_FILE=error.txt ")

!CALL TRACEBACKQQ("My application message string")
call GETARG(4,fln1)   ! mat_dist.txt
call GETARG(5,fln2)   !MDE.bmp
call GETARG(6,fln3)   ! stretch.bmp
call GETARG(7,fln4)   ! crystallinity.bmp
Call Read_Bottle
Call Read_BlowMolding_Input
Call Read_Temp_output
call View_MatDist
 Open  OPEN (UNIT = 4, FILE = 'CONOUT$') !,ERR=100)
 close(4)
 sts=FreeConsole() 

I am probably doing something wrong.
Also myprog.exe > Buglist.txt also does not work. It makes the file Buglist.txt but there is nothing in it even though I set it for a condition where the program crashed and exited.

On the writing to memory, Jugoslav has the XFTGDI thing where he writes to a virtual screen of XPixel Across and Y Pixels down.


xDC= XMemoryDC(XPixel,Ypixel)
In my quickwin graphics I write to the actual screen with the following statement

    TYPE (windowconfig)  myscreen
      COMMON               myscreen
    open (unit=5,File='user',Title='PTI-GRAPHICS',IOFOCUS=.TRUE., status='unknown')
  statusmode = SETwindowCONFIG(myscreen)

My final objective is to save it to a file that would be displayed on the web. So I just need the application to quitely write the graphics file much like a console application without displaying anything on screen when the command line executeable is run.

When I look at the documentation for setwindowconfig I see that there are somethings that are unused like memory, monitor etc. I do not know if it is the same meomory I am thinking about but if there was a buffer/memory this could be written to instead of myscreen, it would have been easier for me. So that was the feature of Quickwin I was requesting. It can be done in Win32 but thats a long step for me. I am probably off base here but I hope you understand what I was asking for.

Thanks
0 Kudos
Steven_L_Intel1
Employee
1,000 Views
Your C# developer is apparently assuming a .NET managed code environment and the C# run-time system. You're not using that. There is no stdout for QuickWin.

Steve
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,000 Views
Huh... for the start, I admit I don't know the general answer. I'll just try to give some info:

In general, when an unusual condition is met, an exception is raised. If the exception is raised within Fortran run-time library (RTL) (intrinsic routines, I/O routines), the exception will be handled in the sense that, by default, a message box is displayed with traceback information and sensible error description, depending on the context ("Array already allocated", "End of file found" etc.). If you override the default with SETENVQQ("FOR_...), the error code will go to the file instead.

However, if the exception is not within RTL, but your code (Array out of bounds, Access violation), it is not handled (and it cannot be handled solely by Fortran, except some FP exceptions), the application crashes and standard system dialog is popped out (e.g. "Unhanled exception in YourApp.exe: Access violation"). There's nothing you can do to prevent that.

Even if only the former is case you want to prevent, I think the code you posted is the best you can do. Terms like stdout and stderr are a bit vague in GUI environment -- a GUI program need not have stdout and stderr. I don't think that RTL error messages in QW case go to stderr. I guess your C# programmer referred to the technique similar to the one described in this MSDN article but I don't think it is much useful if the "child" (your) application is not a console application.

Jugoslav
0 Kudos
james1
Beginner
1,000 Views
It seems like you are trying to fit a square peg in a round hole here. You want an application that is not a Windows application but that runs as a webserver CGI or something of that sort.

If this is the case, you very likely want to approach this as a console application and use a different graphics library (something like gd is typical) so as not to rely on QW, and rather than plotting results to a window would do so to a file instead (in a format appropriate for a client browser as well).

James
0 Kudos
sumitm
Beginner
1,000 Views
Thank you all for your help.
Looks like I need to take the plunge with win32 graphics.
Jugoslav, I have started with your XFTGDI and have made some progress (please find attached).

I am stuck on two things.
How do I get the last position moved to or drawn to.
I thought XGETPixel_W was it
ist=XGetPixel_W(xDC1,locx,locY,icolor)

but the compiler wanrns that variables LOCX & LOCY are used before its value has been defined
I need a Quickwin equivalent of
CALL GETCURRENTPOSITION_W(lastp)
status= LINETO_W(DBLE(sx)+lastp%wx,DBLE(sy)+lastp%wy)
where lastp is of type wxycoord
The other thing is about polygons. How do I fill them using XPOlygon.

Thanks for any help

status = POLYGON_W($GFILLINTERIOR, poly, INT2(4))
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,000 Views
Sorry, XFTGDI does not expose concept of "last position" to the user. (XGetPixel just returns the color of given pixel -- iX and iY are INTENT(IN), thus compilerwaring). Frankly, I didn't see a sensible use for equivalent of GetCurrentPosition(_W) [and returned wxycoord from MoveTo(_W)]. How was lastp set before these two lines?

Polygons (and all shapes) are by default filled using the brush previously set by XSetBrush, and the line is drawn using the pen previously set by XSetPen. ("Empty" brush has iStyle=BS_HOLLOW). Additionally, XPolygon, XRectangle etc. have additional optional arguments of type X_BRUSH and X_PEN, which, if present, override the current pen/brush.

Last version of XFTGDI has XPolyLine added -- XPolygons are closed by default -- I didn't upload it yet.

Feel free to send me the sources by e-mail -- I think I'll find some spare time these days (not over the weekend :-)).

Jugoslav
0 Kudos
sumitm
Beginner
1,000 Views
Hi,
Its been a while but I have converted most of the applications to console type and I now get std err very well.
My question is more on the graphics side.
How do I write text vertically or specifically, what is the equivalent of SETGTEXTROTATION(angle)

I tried converting SCIVERTTEXT (from Scigraph) but that only gives me horizontal characters lined up vertically.
Thanks for any help
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,000 Views
How do I write text vertically or specifically, what is the equivalent of SETGTEXTROTATION(angle)

As you said, it's been a while, so I've lost the flow of the thread. Where? If in XFTGDI, it's iEscapement argument of XSetFont; in Win32, there are nEscapement and nOrientation arguments of CreateFont.

Jugoslav
0 Kudos
sumitm
Beginner
1,000 Views
Thank You
iEscapement works really well!
0 Kudos
Reply