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

File format for executable fortran code

Vail_Cet
Beginner
1,391 Views
hi all,

I am using an executable file, compiled on intel visual fortran. trying to call from on windows 32 platform

the code is supposed to read a parameter file name (.txt) which contains paths to input data files and output file (all .txt format). the parameter file is striclty in a tab delimited .txt file in format specified below

FILENAMES [Data,Grid,Output]:
~/Data/Data.txt
~/Data/Grid.txt
~/Outputs/Output.txt

When i run the .exe file i get an error message of invalid input file, am not very experience in fortran or using format data file for I/O but am not sure where the error is likely to be
a) parameter file which reads the filenames and result in errors in individual files (ie, the data file which is a tab delimited text file, or grid file?

b) the paths - in this case - should the paths be fully specified such as c:\\folder1\\folder2\\filename or is the notation "~\\folder\\" correct?

c)first line - in which case i should omit the line specifying the name of the three .txt file

Although i have access to source code for the .exe file i think the problems could be the combination of above. could anyone point out if mistake could be in way the paths are specified or down to data files?

Thanks
Vailcet
0 Kudos
6 Replies
mecej4
Honored Contributor III
1,391 Views
The abbreviation '~' for "user's home directory" is interpreted and translated typically by a Unix shell. It is not handled in the same way by the standard shell (cmd.exe) in Windows. You will have to hard code it or expand it by some other means.
0 Kudos
Steven_L_Intel1
Employee
1,391 Views
The file paths are in Linux/UNIX format with both the tilde and forward slashes not what Windows wants to see. The input file will need to have Windows-style file paths. These can be absolute (C:\MyFolder\filename.dat) or relative (MySubFolder\filename.dat) where the location of the EXE is the starting point (unless you are executing from within Visual Studio, then the project directory is the default.)
0 Kudos
Vail_Cet
Beginner
1,391 Views
Many thanks Steve,

I have tried changing the paths to something like this:

FILENAMES [Data,Grid,Output]:
C:\ED_ST\Data\Data.txt
C:\ED_ST\Data\Grid.txt
C:\ED_ST\Outputs\IDW_out.txt

But still the executable run just aborts after attempting to read the files i guess

How can i call this from visual fortran ? - when i build the solution i get the executable version...

sorry for my lack of knowledge with fortran..

Thanks alot


0 Kudos
mecej4
Honored Contributor III
1,391 Views
> the parameter file is striclty in a tab delimited .txt file in format specified below

The file that you showed is not tab delimited; there is nothing to delimit, since each line contains only one text field.

You are asking questions that I cannot answer because you have not shown us the READ statements and the formats that they use. You use terminology in an unclear way, and the amount of information provided is insufficient.

At this point, the questions have little to do with Fortran, and should be addressed to the author of the program.
0 Kudos
Vail_Cet
Beginner
1,391 Views
Thanks again,

the .exe file i created after compiling several source code file to which this two subroutines are part:

1.
MODULE global
IMPLICIT NONE
SAVE

!Derived types
TYPE point
INTEGER :: oid,sid
REAL :: x,y,t,value,secondary,h
END TYPE point

!Global parameter declarations
REAL,PARAMETER :: pi=3.141592654

!Global variable declarations
REAL :: omega
CHARACTER(20),DIMENSION(7) :: names

!Global array declarations
TYPE(point),DIMENSION(:),ALLOCATABLE :: observations

END MODULE global

and 2.

SUBROUTINE getparams(datafile,outfile,db,neighbors,n)
USE global
IMPLICIT NONE

!Dummy argument declarations
INTEGER,INTENT(out) :: neighbors,db,n
CHARACTER(100),INTENT(out) :: datafile,outfile

!Local parameter declarations
INTEGER,PARAMETER :: in=30,out=40

!Local variable declarations
INTEGER :: i,ios
CHARACTER(100) :: parameterfile,gridfile

!Read parameters
PRINT '("Enter parameter file name")'
DO
READ '(A)', parameterfile
OPEN(UNIT=in,FILE=parameterfile,STATUS="OLD",IOSTAT=ios)
IF(ios==0) EXIT
PRINT '(/"Unable to read parameter file: Please try again"/)'
END DO
PRINT*, ""

!Read file names and parameters
READ(UNIT=in,FMT=101) datafile,gridfile,outfile
READ(in,*)omega
READ(in,'(//I//)')db
READ(in,*)neighbors

!Prepare the observations vector
CALL dataframe(datafile,n)

!Close the file
CLOSE(UNIT=in)

!Open grid file
IF(db .NE. 2) THEN
OPEN(UNIT=in,FILE=gridfile,STATUS="OLD",IOSTAT=ios)
IF(ios .NE. 0) THEN
PRINT '("Invalid prediction locations file!"/)'
PAUSE
STOP
END IF
ELSE
OPEN(UNIT=in,FILE=datafile,STATUS="OLD",IOSTAT=ios)
IF(ios .NE. 0) THEN
PRINT '("Invalid data file!"/)'
PAUSE
STOP
END IF

!Skip header
READ(in,*)
END IF

!Skip header
READ(in,*)

!Open output file
OPEN(UNIT=out,FILE=outfile,IOSTAT=ios)
IF(ios .NE. 0) THEN
PRINT '("Invalid output file name!"/)'
PAUSE
STOP
END IF

PRINT '("Interpolation by Inverse distance weighting")'
PRINT '("Omega = ",1X,F5.3/)', omega

!Report operating mode
IF (db == 0) THEN
PRINT '("Operating in debug mode."/)'
ELSE IF (db == 1) THEN
PRINT '("Operating in default mode."/)'
ELSE
PRINT '("Operating in jack knife mode."/)'
END IF

!Write header on output file
IF(db .NE. 2) THEN
WRITE(out,FMT=201) TRIM(names(7))
ELSE
WRITE(out,FMT=202) TRIM(names(7)),TRIM(names(6))
END IF

!Format definitions
!Inputs
101 FORMAT (/A100/A100/A100//)

!Outputs
201 FORMAT (3X,"East",3X,"North",3X,"Time",3X,"Estimate",3X,&
A20,3X,"Residual",3X,"Nearest",3X,"Mu_Dist",3X,"Nearest.ID")
202 FORMAT (3X,"SID",3X,"East",3X,"North",3X,"Time",3X,"Estimate",3X,A20,3X,"Residual",3X,A20,3X,&
3X,"Error",3X,"Nearest",3x,"Mu_Dist",3X,"Nearest.ID")

END SUBROUTINE getparams

Thanks for insights
0 Kudos
mecej4
Honored Contributor III
1,391 Views
Adding the following main program,

[fortran]program driver
  character*100 datafile,outfile
  integer db,neighbors,n
  call getparams(datafile,outfile,db,neighbors,n)
  write(*,10)trim(datafile),trim(outfile)
10 format(1x,'|',A,'|')
end program driver
[/fortran]
commenting out the CALL to the missing subroutine, adding RETURN after the first READ in your subroutine, and running the program with your data file gives

[bash]Enter parameter file name
dat

 |C:ED_STDataData.txt|
 |C:ED_STOutputsIDW_out.txt|[/bash]
What errors did you run into?
0 Kudos
Reply