# Inquire, open file operation failed in dll functions

## Inquire, open file operation failed in dll functions

Hi:

I'm having a very strange problem regarding file operations in a function loaded from dll. Basically all file operations such as inquire, and open are failed and my program gives me a "runtime error R6030, CRT not initialized." I did some research on web, some people say it may be related to UAC control. I tried enable/disable UAC control in project property settings. But no luck.

I'm using IVF 2011.11.344 for windows. My program did work well when compiled with previous versions of IVF. So it seems that something changed reagrding dll projects in that version of IVF.

Does any one has similar issue?

Thanks,

Jim

11 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

This is something we have not seen before. Which version of Visual Studio are you using? Did you use a different VS before?

Steve - Intel Developer Support

I have the same problem, but I have a static lib linked to a c++ program.  Filenames are passed from C++ to Fortran subroutine followed by the string length on the C++ side, INQUIRE(FILE=INSTRING,EXIST=EX) on the fortran side returns .FALSE. when the file does exist, INSTRING is a full path to the file which can be opened in notepad. Trying to open the file results in forrtl: severe (43): file name specification error.  Fortran is static library, c++ is using /MT

extern "C" void FMAIN(char *, size_t);

size_t length=strlen(file_in);

FMAIN(file_in, length);

SUBROUTINE FMAIN(INSTRING)

OPEN(UNIT=UNIT_INFILE,FILE=INSTRING,STATUS='OLD') !!!  forrtl: severe (43): file name specification

c++ options:

/ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MT /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\mdxbrace.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue

That hardly sounds like the same problem - you're not getting a "CRT not initialized" error.

I don't see a declaration of INSTRING. Please show all the declaration section of the Fortran code. Have you tried displaying the filename as it gets received by the Fortran code? Perhaps using Z output might reveal an invalid character.

Steve - Intel Developer Support

The filename looked fine in the debugger, it probably had to do with null terminated strings in C vs Fortran.  I assumed that a C main was a good idea for linking in 3rd party libraries.  When I used a Fortran main the INQUIRE and OPEN statements worked fine and the project is simpler as well.  I can still use 3rd party libraries with ISO_C_BINDING without using a C main.  Sorry about the comparison (I posted without enough thinking)

For the INSTRING problem, it looks like a c string problem.
Could you try copying the file name to a local fortran character variable. I would also report INSTRING and the string length before the OPEN.  Something like:

character local_string*256
local_string = INSTRING
write (*,*) 'Opening ', trim(local_string),' on unit',unit_infile,len_trim(local_string)
OPEN (UNIT=UNIT_INFILE, FILE=local_string, STATUS='OLD', iostat=iostat)

You could also test local_string for invalid characters in the name

do i = 1, len(local_string)
if ( INDEX ('ABCDEFGHIJKLMNOPQRSTUVWXYZ', local_string(i:i)) > 0) cycle
if ( INDEX ('abcdefghijklmnopqrstuvwxyz', local_string(i:i)) > 0) cycle
if ( INDEX ('1234567890 ',                local_string(i:i)) > 0) cycle
if ( INDEX ('-=!@#$%^&()_+[]{};,./', local_string(i:i)) > 0) cycle write (*,*) 'invalid file name character ',local_string(i:i), ichar (local_string(i:i)) end do  John John's checking code could be done more compactly with the VERIFY intrinsic and no need for a loop. character(*), parameter :: valid_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'' // & 'abcdefghijklmnopqrstuvwxyz' // & '1234567890 -=!@#$%^&()_+[]{};,./'
...
i = VERIFY(local_string, valid_chars)
if (i > 0) write (*,*) "Invalid character at position ", i


Steve - Intel Developer Support

Thanks for VERIFY example Steve, another very useful function that I was blissfully unaware of. The example above is pretty clear to what it does but  I then read the system help topic and it didn't seem consistent with your example. I had to read it through carefully a couple of times times before  I realised is was consistent. I think the code snipped above (or simillar) would greatly enhance that help topic as this  it is something that users must often want to do (or similar).

Futher INDEX, SCAN and VERIFY topics should IMO all cross referance (they partially do this). When I look at help if the are cross refferanced topics that I do not reconize/know I often then have a read....

Uhm... by any chance is the file specification string, as used by Fortran code, expressed as a file specification string as used by C/C++?

IOW "foo\\bar\\data.txt" with double \\.

This won't work in Fortran.

Jim Dempsey

Jim,

That's exactly the case, thanks for pointing it out.

Eric

Jim,

That's the problem, thanks for pointing it out.

Eric