where to put input data file for reading input parameters?

where to put input data file for reading input parameters?

Sorry if this question is simple but I don't know where to find the answer.

I have put my input data in a file called ERAUL_4.DAT

I have following command in my code to read the data from it:

      DATA IRE /5/

      OPEN (5, FILE = 'ERAUL_4.DAT')
      OPEN (7, FILE = 'outdata4.txt')
      OPEN (8, FILE = 'VERPARAMET.TXT')

      WRITE(7,*)  '1'
      READ(IRE,11) JP(1),JP(2),JP(3),JP(5)                                    
      WRITE(7,211) JP(1),JP(2),JP(3),JP(5)                                     
      WRITE(8,11)  JP(1),JP(2),JP(3),JP(5)                                     
   11 FORMAT(4I5)                                                              
  211 FORMAT(4(I5,', '))

This is a fixed format code.

My project name is called: ConsoleApplication3

I put my input file in the same folder as my project foler (ConsoleApplication3)

Programs runs with no warning.

It seams that it doesn't read the input data becasue I can't get output file.

Am I missing somethiing here?

What is wrong with it?

30 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

Search for the output files by name using Windows Search. If the program ran without any error messages, it must have found the input file. You may have more than one copy of the input file.

Input and output files are, by default, located in the current working directory. When you use an IDE such as Visual Studio, the concept of current working directory becomes a little nebulous.

Dear mecej4

Thanks for your comments. I will search.
Could you please guide me to a site where I can get the basics of input and output in Fortran? I had worked with fortran more than 25 years ago and this is the first time I want to RUN it using Visual Studio.

be sure to add error and endof file routings to your code for the OPEN, READ & Write statements and then write a message so you can see if the file is found and opened.
In Visual Studio access Project->Properties->Debugging
see Working Directory to set to something other than the default
Otherwise it will run in either Debug or Release Folders which are sub-directories from your Project location.
Help->Intel Visual Fortran...
will direct you to the User and Reference Manual which also points to samples which should get you up to speed!

look at the

Quote:

mecej4 wrote:

Search for the output files by name using Windows Search. If the program ran without any error messages, it must have found the input file. You may have more than one copy of the input file.

Input and output files are, by default, located in the current working directory. When you use an IDE such as Visual Studio, the concept of current working directory becomes a little nebulous.

Searching the output file didn't find it.

Quote:

bmchenry wrote:

be sure to add error and endof file routings to your code for the OPEN, READ & Write statements and then write a message so you can see if the file is found and opened.
In Visual Studio access Project->Properties->Debugging
see Working Directory to set to something other than the default
Otherwise it will run in either Debug or Release Folders which are sub-directories from your Project location.
Help->Intel Visual Fortran...
will direct you to the User and Reference Manual which also points to samples which should get you up to speed!

look at the

Dear bmchenry
Thanks for your comment. I am aware of putting messages for print so that I can trace them and already did it.
You talked about working directories. How can I access its settings to change to a known place for me?

From Visual Studio access
Project->XXXX Properties->Debugging
(XXXX wll be your project name)
set the Working Directory to the directory you want to use.

I checked Visual Studios site for help on
http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k...

but couldn't find anything related to FORTRAN samples or guidelines. Perhaps I should look for something other than key word "FORTRAN"

Also in MSDN Forum site, a search with FORTRAN didn't bring anything. The only thing is F#. Is it really different from FORTRAN?

I find the exe file in:
ConsoleApplication3\ConsoleApplication3\bin\Debug

Double clicking this exe file just pops up Command line prompt for less than a second and closes up immediately.
How can I keep it remain on the screen?

Dear bmchenry

I found the working directory path. IT is as follows:
Right click the application name in Solution explorer, go to properties, go to "debug" tab
and working directory is under Start Options heading

with Visual Studio open (and Fortran installed) when you select help menu you should see
Intel Visual Fortran Composer XE 2013 (or which version you are using)
select that menu option and it should present you with the Help viewer OR simply open the Fortran help file
below is some screen captures on it
also you can use
Read(*,*)
i believe on a console application to read/pause the program
set up a variable to read and then write it to the console to pause and continue
integer something1, something2
read(*,*) something1
write(*,*) something1
read(*,*) something2
etc...

附件: 

附件尺寸
下载 helpmenu.jpg49.44 KB
下载 helpmore.jpg151.37 KB

If you run a program from within Visual Studio, the default directory is the one containing the project file - it is not "nebulous". Typically this is not the directory containing the EXE.

With the code as shown, if the file does not exist in the default directory an empty file will be created.

Steve - Intel Developer Support

Quote:

bmchenry wrote:

with Visual Studio open (and Fortran installed) when you select help menu you should see
Intel Visual Fortran Composer XE 2013 (or which version you are using)
select that menu option and it should present you with the Help viewer OR simply open the Fortran help file
below is some screen captures on it
also you can use
Read(*,*)
i believe on a console application to read/pause the program
set up a variable to read and then write it to the console to pause and continue
integer something1, something2
read(*,*) something1
write(*,*) something1
read(*,*) something2
etc...

Dear Henry
What you mentioned in the help menu, exists but it connects to online help. An icon appears in system taskbar referring to
http://127.0.0.1:47873/help/0-1540/ms.help?product=VS&productVersion=100...

A screenshot is attached. I couldn't get the information I nee regarding READ/Write format from that help.

This is the help site screenshot

附件: 

附件尺寸
下载 helpwebsite.jpg121.02 KB

Quote:

Steve Lionel (Intel) wrote:

If you run a program from within Visual Studio, the default directory is the one containing the project file - it is not "nebulous". Typically this is not the directory containing the EXE.

With the code as shown, if the file does not exist in the default directory an empty file will be created.

Dear Steve thanks for help and support.

There are few files with different extensions like as follows in the project folder:
ConsoleApplication3.sln
ConsoleApplication3.suo
Program.for
ConsoleApplication3.fsproj
ConsoleApplication3.exe
ConsoleApplication3.pdb
ConsoleApplication3.XML

Which one is the empty file?
I suppose debuging will make the exe file, if ther is no error. Am I correct?
The execution of exe file will run the code and should read the input file. I have the input put inside the project folder. Then it should produce the output file presumably inside the project folder with the name I have opened but I can't find it.

One more question. Is it necessary to compile the code after debugging or debugging will compile the code as well? And in order to run the code is it necessary to double click the exe file inside project folder or VS will run and show the result in OUTPUT tab?

This is the screen shot.

I think that you have some confusion between debugging, compiling and the connection between the two.

Compiling and linking must be completed without errors in order to produce an EXE. If the Debug Configuration was used, the EXE can be run inside the VS debugger. Whether the Debug or Release configuration was used, the resulting EXE can definitely be run, and may or may not produce run time errors.

That you see the ConsoleApplication3.exe file in the same folder as the project files indicates that you do not have the default configuration, probably as a consequence of choosing one or more options in Visual Studio without being aware of the consequences. Furthermore, without a full directory listing in your post it is impossible to tell whether the EXE file that you listed is a vestige of an old compilation, whether it is that file or another, more recent, EXE that exists in a subdirectory and gets run when you choose Debug or Run.

IDEs are popular and simplify working, but when things don't work the environment is more complex and it takes more work to pin things down. Perhaps you can discard the present error-ridden project and start with a clean slate.

None of the files you show would be the empty file as written by the program. Perhaps the program did not run at all. Either the file would have the name given to it in the program, or it would be something like fort.7 for a file written on unit 7.

Steve - Intel Developer Support

Dear Henry
The info at http://127.0.0.1:47873/help/0-1540/ms.help?product=VS&productVersion=100...
gives good info regarding read/write.
I hope it will solve my issue.
Thanks

Quote:

Steve Lionel (Intel) wrote:

None of the files you show would be the empty file as written by the program. Perhaps the program did not run at all. Either the file would have the name given to it in the program, or it would be something like fort.7 for a file written on unit 7.

Isn't there any way/procedure to check and be sure that the program is executed or not?

It should be somewhat obvious when you ask the program to run whether or not it did run. If you need to check specific parts of the program, set a breakpoint and run under the debugger.

Steve - Intel Developer Support

Quote:

Rasoul K. wrote:
...

There are few files with different extensions like as follows in the project folder:
...
ConsoleApplication3.fsproj
...

That is the project settings file for a completely different language (F#). Given other postings - are you sure you are using a Fortran project?

The project settings file for an Intel Visual Fortran project in Visual Studio has a .vfproj extension.

Quote:

IanH wrote:

Quote:

Rasoul K. wrote:...

There are few files with different extensions like as follows in the project folder:
...
ConsoleApplication3.fsproj
...

That is the project settings file for a completely different language (F#). Given other postings - are you sure you are using a Fortran project?

The project settings file for an Intel Visual Fortran project in Visual Studio has a .vfproj extension.

Dear Ian

Thanks for your reply. You pointed exactly to the problem. I would never find out this by myself.
I opened a project and then copy/pasted the code inside. Mistakenly I have opened a F# project.
Now let me try again and post here what happens.

Hi Stev and all,

I have recently installed the fortran compiler XE 2013 sp1 and running it under VS2013 in my win8.1 mechine.

My fortran project folder is saved under the mydocument/VS2013/project folder. I put the *.dat input file inside the project folder. The program was running well in *.f90 old version. The project can be compiled without any error but when I run the program, it ends with message the  end of the file during read....The dat file is with required data and the project was created under Intel fortran, console, program and copy and pasted from the f90. Do I need to save the dat file somewhere else?

Thanks in advance. 

 

have already solved the problem. Thanks

rabi L,  

have already solved the problem. Thanks 

how did you solve the problem? I have the same kind of problem but have not been able to find a solution to it. Please share your findings. 

I think that using relative file names in a program is not a good practice. The current working directory from which relative pathnames will be resolved may vary.

The best way is to use absolute pathnames that you can build yourself in your program using the full program name for example or a predefined windows path (Application data) for example.

The API function GetModuleFileName will give you the absolute pathname of your executable. You can extract the path from it.

The API function SHGetFolderPath will give you predefined windows path like "Application data".

 

 

 

#27 is good advice but you might not want to use the API functions. If you want to put the files in the same place as the exe then the code snip below gives the correct path. get_command_argument is an intrinsic function.

...
call get_exe_path(gpth,npth)
myfile=gpth(1:npth)//'the_name_string_of_your_file'
Subroutine get_exe_path(gpth,npth) !get exe path from cmd line
     implicit none
    integer, intent(out)          :: npth
    character(len=*), intent(out) :: gpth
    integer                       :: ilen, istat  
    character(len=512)            :: garg
    gpth=' '
    npth=0
    call get_command_argument (0, garg, ilen, istat)
    if(istat == 0) then
        npth=index(garg,'\',.true.)
        gpth=garg(1:npth)
    endif 
end subroutine

 

Hello

app4619 you are right but I didn't talk about the command line argument, because as far as I know  if you launch the program form a console without specifying the full path, it will not be available. You only got the program name entered in the command line

Quote:

gvautier wrote:

Hello

app4619 you are right but I didn't talk about the command line argument, because as far as I know  if you launch the program form a console without specifying the full path, it will not be available. You only got the program name entered in the command line

 

Yes that is correct. If you are running from a command prompt and this is local to the exe  you are unlikely to be having a path problem. I find that windows has some complex system of 'remembering' folders that varies from version to version and I am now also finding that the "current" folder for reading can be different to that for writing. 

发表评论

登录添加评论。还不是成员?立即加入