Topic: different behavior in program runs from SF and direct calling exe-file

I find several disadvantages running exe files directly. One point i reported earlier, a new case is that the program stops without any message after using a procedure reading  data from file, editing and writing back to file. In a run started from SF the occur no error. So I can't debug this crash. There are several print statements in this procedure. Do they haven any influence of this crashes?

Regards Klaus

Re: different behavior in program runs from SF and direct calling exe-file

Klaus,

When you say "the program stops without any message,"  does the program crash, or does it just appear to freeze?

Assuming you're running on Windows, you may be able to attach Simply Fortran's debugger to the program as it runs outside of Simply Fortran.  If your program is freezing, just start Simply Fortran, load your project, and select "Attach..." in the Debug menu (on Windows, at least).  You should get a current listing in the Stack view of the Debug panel so you can at least see where your program is frozen.

The only difference with running from Simply Fortran is that the working directory is configured by Simply Fortran when the executable is launched.  In theory, there is no other difference from just starting it from Windows Explorer or the command prompt.

Jeff Armstrong
Approximatrix, LLC

Re: different behavior in program runs from SF and direct calling exe-file

hello Jeff,
The program crashes after some second (no freeze). I'll check the path to read and write. My program has a user defined object directory and a directory for standard sources, but preliminary files are contained in the directory containing the executable.
What about the print statements if there is no SF console? The only reason that I do temporary print is to get a quick log of a program run

Regards, Klaus

Re: different behavior in program runs from SF and direct calling exe-file

Klaus,

Are you compiling with the Windows GUI option enabled?  Just curious, but you shouldn't if you're attempting to use Print or Write statements.  Also, do you explicitly point units 5 or 6 at files?  That should also be avoided under all circumstances.

Jeff Armstrong
Approximatrix, LLC

Re: different behavior in program runs from SF and direct calling exe-file

Jeff,
For compiling I use the SF defaults.
For IO no units 5 and 6 are used. I have a file with standard units, UNITS.fi with following content:
        INTEGER(4), parameter  ::  IO_TM = 0
    INTEGER(4), parameter  ::  IO_IN = 1
    INTEGER(4), parameter  ::  IO_IN2= 2
    INTEGER(4), parameter  ::  IO_PR = 7
    INTEGER(4), parameter  ::  IO_OT = 8
    INTEGER(4), parameter  ::  IO_OT2= 9
    INTEGER(4), parameter  ::  IO_KL = 3
IO_TM is still a heritage from CVF, even as IO_PR for direct printing

Wherever I use IO the file is added by an include file

Is unit 0 also an problem? May be somewhere it is still used in a single case.
Regards, Klaus

Re: different behavior in program runs from SF and direct calling exe-file

Jeff, problem solved!
The crash was caused by an unit in an open statement for output (error by iostat=2). Notwithstanding prior mentioned parameters, there was a variable unit specified out side the procedure where the crash happened as follows
integer IOunit
IOunit =  IO_OT
While parameter IO_OT is declared as integer(4)
Is Integer  the same as integer(4) as i have learned ? I am in doubt, because I had more troubles and decided to use not more both for the same variable. Unfortunately I have a lot elder software still in CVF.

However i still wonder why the crash doesn't starting the program in SF

Regards, Klaus

Re: different behavior in program runs from SF and direct calling exe-file

Klaus,

Unless you state otherwise, on Windows integer defaults to integer(kind=4) unless you explicitly state otherwise or you've added a compiler flag to change default behavior.

I'm not sure why the program doesn't crash immediately, but it might only die when input/output is attempted on a bad unit.

As a general rule, unit numbers below 20 are all dangerous for legacy reasons. Many of those units have special meaning on certain compilers.  I think one Fortran 90 compiler I used in the distant past had unit=13 pointing at a printer, for example.  I normally suggest using unit numbers above 100 to be safe.

Jeff Armstrong
Approximatrix, LLC

Re: different behavior in program runs from SF and direct calling exe-file

Thanks Jeff,
I shall follow up your advice and use units lager than 100. Generally I only have to change the IO unit parameter file, I think, like:
....
INTEGER, parameter  ::  IO_IN = 101
....
First I must look in source files to see if there are nasty consequences...
Also I shall remove after testing print statement or change it to write statements sending this messages to an already existing report file

regards, Klaus