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

how to detect file already open before executing OPEN

larryscheier
Beginner
5,896 Views
I have a very simple OPEN statement that is only executed if the file exists:
INQUIRE(FILE=DsnProfExportName, EXIST=FILE_EXIST)
IF (FILE_EXIST) THEN
OPEN(90,FILE=DsnProfExportName, STATUS='OLD', ERR= 100)
END IF
....
!Error trap
100 ErrorFound = .TRUE.

I thought the "ERR=100" would be able to trap an error such as when the file is already open in Excel but instead of going to statement 100, the runtime crashes on the line with the OPEN statement and displays: "forrtl: severe (46): inconsistent OPEN/CLOSE parameters, unit 90, file unknown"

If the "ERR=xxx" can't catch if the file is already open in another process is there a way to at least detect an already open file (especially one that is write protected)?

Thanks!
Lawrence


0 Kudos
28 Replies
WHeat_
Beginner
1,159 Views

Thank you for your reply, you are right! when I'm working on a machine that is installed windows 7, it works and I do not have this message ! but with windows 8 i have this error. So, what I can do to avoid that ?

Thanks, App4619!

0 Kudos
WHeat_
Beginner
1,159 Views

I think that this type of error is related to windows 8. My question is: How I can to compile a code f77 on Microsoft Visual Studio ? (when i open a new project, directly the format is f90! so i can not bluid a project on f77

Thank you for your help.

0 Kudos
Steven_L_Intel1
Employee
1,159 Views
Yes you can build F77 code. As long as the source files have the .f or .for file type, it will build fine. When you create a new source file, you have the option of fixed-form source. What is the full path of the folder in which you're running the program? Note that Windows makes it difficult to run programs that write to folders under Program Files.
0 Kudos
WHeat_
Beginner
1,159 Views

Thank you Steve,

Good, I chose the option of fixed-form source and i write a simple program in f77. Now, how could i compile this program  built it and run it  ?

 Program test
      
C------- DECLARATION ------------
      
       INTEGER I IT
       REAL AMPLI(10),T,FREQ,pi
       
C------- INITIALISATION ---------
      FREQ = 50
      pi = 3.1416
      IT = 0
C-----THE BODY OF THE PROGRAM----
      DO I =1,10
          IT = IT + 2
          T = FLOAT(IT)
          AMPLI(I) = SIN(2*pi*FREQ*T)
          WRITE(*,100) IT
      ENDDO
100   FORMAT(1X,I2)
      END

 

0 Kudos
Steven_L_Intel1
Employee
1,159 Views

Select Build > Build Solution in Visual Studio. It's no different than building free-form source. I assume that you took this code and added it into a fixed-form source file that is in a Fortran Console Application project.

0 Kudos
WHeat_
Beginner
1,159 Views

when I select Build, I have only one choice  "execute code analysis on the solution Alt+F11" !

In free-form, it is very simple : when I create a new Projet, and I select 'Main Program Code', and I write my code, so in Solution explorer  these is :

Header Files

Resources Files

Source Files

ReadMe.txt

In Free Form I can easily Build the solution and run it.

But in Fixed form, there is only  "Solution(0projets)"  so I can not Build this Solution!!

0 Kudos
Steven_L_Intel1
Employee
1,159 Views

Right click on the project, select Add > Existing Item. Select your source file and click Add. Or in the future, select Add > New Item. Then when the Intel Visual Fortran Project Items dialog comes up, select "Fortran Fixed-Form file".

Alternatively, let the project wizard create the new project with free-form source. In the Solution Explorer, right click on the file and select Rename. Rename it to a .for file. Now it is fixed-form.

0 Kudos
WHeat_
Beginner
1,159 Views

 

Thank you for your hep Steve.

0 Kudos
Reply