- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Dear all,
I wrote a programin Fortran to dynamically link a dll written in C++. I am using VS2008 with Intel Visual Fortran Compiler 10.1.019. It compiles / links with no errors. However I get a run-timeerror 'forrtl: severe (157) Program Exception - Access violation' .
The same code compiles/links/and runs with no errors in Compaq Visual Fortran Professional Edition 6.1.0.
Intel VFC debbuger points out that the error is in line 80:
Write (*,100) "ModelSetModelCpIgStandard returns: ", resModelSetComponentName
If instead of that, I write:
Write (*,*)resModelSetComponentName
... the program runs with no errors. Wierd, huh? I have no clue what's going on.
Any help is appreciated,
Paco
Program
Fortran_Calls_CUse
kernel32 ! Declares Win32 API routinesImplicit None
! Declare the interface to functions in BaseCalc.dll
Interface
Function ModelClear () Integer ModelClear End function ModelClear Function ModelSetModelEOS (Model) Integer ModelSetModelEOS Character, Intent(IN) :: Model*7 End function ModelSetModelEOS Function ModelSetModelCpIgStandard (CpIgStnd) Integer ModelSetModelCpIgStandard Character, Intent(IN) :: CpIgStnd*10 End function ModelSetModelCpIgStandard Function ModelSetComponentName (CompIndex,CompName) Integer ModelSetComponentName Character, Intent(IN) :: CompName*8 Integer, Intent(IN) :: CompIndex !DEC$ ATTRIBUTES VALUE:: CompIndex End function ModelSetComponentNameEnd Interface
! De clare variables
Integer
(HANDLE) :: dll_handleInteger
(BOOL) :: free_statusInteger
resModelClear, resModelSetModelEOS, resModelSetModelCpIgStandard, resModelSetComponentNameInteger
iInteger
ComponentIndexCharacter
ModelName*7, CpIg*10, ComponentName*8! Declare pointers to the functions.
Pointer
(p_ModelClear, ModelClear)Pointer
(p_ModelSetModelEOS, ModelSetModelEOS)Pointer
(p_ModelSetModelCpIgStandard, ModelSetModelCpIgStandard)Pointer
(p_ModelSetComponentName,ModelSetComponentName)Parameter
(ModelName = 'PC-SAFT') ! The selected Model is PC-SAFTParameter
(CpIg = 'Polynomial') ! The selected Cp model is PolynomialParameter
(ComponentName = 'n-Hexane') ! Modeling n-Hexane as only component in the systemParameter
(ComponentIndex = 0) !dll_handle = LoadLibrary ("BaseCalc.dll"C)
! Access function(s) in Library 'BaseCalc.dll'
p_ModelClear = GetProcAddress (dll_handle, "ModelClear"C)
p_ModelSetModelEOS = GetProcAddress (dll_handle, "ModelSetModelEOS"C)
p_ModelSetModelCpIgStandard = GetProcAddress (dll_handle, "ModelSetModelCpIgStandard"C)
p_ModelSetComponentName = GetProcAddress (dll_handle, "ModelSetComponentName"C)
100
Format(A,T60,i5)200
Format(A,i1,A,T60,i5)!Call function(s) and get returned value
resModelClear = ModelClear()
Write
(*,100) "ModelClear returns: ", resModelClearresModelSetModelEOS = ModelSetModelEOS(ModelName)
Write
(*,100) "ModelSetModelEOS returns: ", resModelSetModelEOSresModelSetModelCpIgStandard = ModelSetModelCpIgStandard(CpIg)
Write
(*,100) "ModelSetModelCpIgStandard returns: ", resModelSetModelCpIgStandardresModelSetComponentName = ModelSetComponentName(ComponentIndex,ComponentName)
Write
(*,100) "ModelSetModelCpIgStandard returns: ", resModelSetComponentName! Unload the library
free_status = FreeLibrary (dll_handle)
! End of main program
Pause
End
Program Fortran_Calls_C- Etiquetas:
- Intel® Fortran Compiler
Enlace copiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Perhaps the easiest thing is to add /iface:cvf to the compile options. Alternatively, add directives to the interfaces to specify STDCALL, REFERENCE, MIXED_STR_LEN_ARG and the appropriate ALIAS.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Steve,
/iface:cvf did the trick.
Thanks,
Paco
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
The same program works fine in CVF, i tried setting calling function \iface:cvf but does not help me.
Any suggestions would be appreciated.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
2. Provide source code for a short working example so that the issues can be diagnosed.
3. The following are guidelines for what to expect when changing compilers:
(a) If the source code is all in Fortran and is bug free and self-contained, just using the new compiler should suffice.
(b) If a custom library is used in addition to the Fortran runtime, this library is compatible with CVF, and this library does not use the Fortran runtime, compiling your sources using /iface:cvf should suffice.
(c) If neither (a) nor (b) applies, with luck /iface:cvf may work -- this is worth trying since the effort needed is trivial.
(d) If neither (a) nor (b) aplies, and /iface:cvf does not produce a working application, you have to decide whether
(d1) you should look for IVF-compatible third party libraries, or
(d2) you should spend time writing DEC $ directives to facilitate making correct calls to the libraries, assuming that these calls are documented and your application does not create a conflict between the IVF and CVF runtimes, or
(d3) you should give up.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Hi Thanks for the reply,
After changing the declaration of few variable i am able to debug the program,
I have so many write statements in my program, below are 2 of them,
Write (2,'(" Dummy 1 ,[BTU/kWh]",
Write (2,'(" Dummy 2 ,[frac]",
If i comment the second write statement everything works fine, but if i am uncomment second line and try to debug, i am getting access violation at writing location error.
Any suggestions?
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Access violations, in particular, are related to using variables that have not been allocated or are being accessed with improper subscripts, etc. Not knowing how the variables in the two I/O lists were declared and allocated, it is impossible to say why you receive an access violation.
Create and post complete source for a small example that demonstrates the problem, and give information about the OS, platform and compiler versions, compiler options used, and any needed input data files.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I have just finished a many-month effort to migrate approx 750k sloc from CVF/VS6 to IVF/VS9. There were thousands of minor syntax errors, and roughly 50-100 run time errors (so far), mostly short-circuit, string length and string termination problems. Although there are certainly things I could complain about (e.g. the lack of short-circuit support) I found ZERO defects attributable to the compiler.
For instance, you may have defects lying in CVF code for years. A common one is an unterminated string that sits adjacent to a variable that happens to be a zero, thus terminating the string. A different compiler can choose to locate variables differently, and suddenly you have an access violation in code that has run correctly for 10 years.
When I have run into writelines moving the defect around, it is often been string length problems corrupting the string table. If you are running mixed language FORTRAN/C, I would take a look at any usages of strcpy, and also make sure all your C string lengths are long enough for the string operations you perform. Also, I would run the exe and attach the debugger, and see if the debugger tells you about corruption near
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Write (2,'(" Dummy 1 ,[BTU/kWh]",
In the above line
How to write same line multiple times in Intel Fortran? Any help would be appreciated.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
If you are exceeding the bounds of the arrays in the I/O lists, you are likely to have puzzling consequences such as access violations, program hang ups, etc.
>For example if NUMOD is 2, then write statementwill writethe same line 3 times.
No. Once you get the bugs fixed and run the program, you will not see multiple lines as you stated, because a format group with a definite repeat-count prefix simply repeats the format group the specified number of times, and there are no new line format specs ('/') there.
If you want multiple lines, you have to make them happen by writing a suitable format specification or by changing the WRITE statement.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I concluded that he wished to write multiple lines, but, because of the access violation did not actually see any corresponding output; so format reversion is not yet known to be an issue.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I understand with information i shared it is difficult to pin point the error but then my employer policy dont allow me to post my entirecode.
Somehow removing
For example, Write (2,'(" Dummy 2 ,[frac]",
Dummy 2 200 400 600
After removing
Dummy 2
200
400
600
Any suggestion to print multiple results in same format like tab separated is appreciated.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
(i) you take the trouble to describe your wishes and problems less ambiguously, and
(ii) you show more diligence in giving consideration to the advice that has already been offered,
you may find better support here.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I understand with single line of code i shared it is difficult for you to pin point the error but then my employer policy dont allow me to share the complete code.
Somehow removing
As you pointed out, Write (2,'("Dummy2,[BTU/kWh]",
For ex: if NUMOD is 2, then my result is
Dummy2 200 400 600
But after removing
Dummy2
200
400
600
Any suggestions on printed the result in tab separated format is appreciated
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
But that amounts to killing the patient to stop his coughing.
You have bugs (in code that you have not shown) that are causing access violations. You have to locate and fix those bugs.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Write (2,'("Dummy2,[BTU/kWh]",
Write (2,'(
"Dummy2,[BTU/kWh]",*** note single text arg ***
)') (tCCALC_OUTPUTS(j)%Res(100+317,1),j=0,NUMOD)
but it only has "Dummy2"
Please explain?
Jim Dempsey
- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla