How to store output files for one code with different input files?

How to store output files for one code with different input files?

I have one solution, one project and one source file. My source file is named console1.

I want to RUN it for different input files.

What is best way to accomplish this so that output files for each of them to be stored in separate folders?

What I do now is cut and copy input and output files from Console1 folder to another place and then bring in the next input file I want to run and then run the program.

Obviously it is not a smart way but solves my problem.

How can I arrange different input files to be shown in the Solution Explorer, and get the output files stored in different folders.

I hope I was able to explain what am I looking for.

6 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

take a look at intrinsic routine GetArg
when starting your program pass a name for input/output files and then simply add the suffix for the input/output files
or simply ask yourself at start of the program for the input/ouput file name prefix (and add the suffix after (IN, OUT, etc)
do you need to store indifferent folders?
if so you could also ask for a folder name and if it exists, use it, if not, create it.
one last option is an automatic file naming scheme...simply start with Name001.In Name001.Out or something like that and loop until the next one in sequence doesn't exist and then use that name for input/output and/or directory)

Rather than getarg, use the standard intrinsic GET_COMMAND_ARGUMENT. Another possibility is to have the program prompt the user for the filename(s) to use. If you are ambitious, you can even use the Windows API routines GetOpenFilename and GetSaveFilename, though given your unfamiliarity with Fortran and Windows programming, Rasoul, I would not recommend that at this time for you.

Steve - Intel Developer Support

Dear Henry
Thanks for your valuable comments.
Where can I find intrinsic routine GetArg? Is it inside IVF?
You wrote:

when starting your program pass a name for input/output files

Do you mean I do this inside my program? Sorry I couldn't understand what shall I do to accomplish.

Your next solution is:

simply ask yourself at start of the program for the input/ouput file name prefix

I think this is same as previous one, but I couldn't get how to do it.

Probably at present automatic file naming is too much for me. If I can do one of your first methods, that will be enough for me.

Suppose I have WORD open. In order to write new letters. I don't need to close the word for every letter and open it again. Simply I can save previous one and select new. I assume there might be such a method in FORTRAN as well, like what you mentioned, but I can't figure out how to do it.
Could you please explain in more novice level, what steps I have to do? Thanks in advance.

Quote:

Steve Lionel (Intel) wrote:

Rather than getarg, use the standard intrinsic GET_COMMAND_ARGUMENT. Another possibility is to have the program prompt the user for the filename(s) to use. If you are ambitious, you can even use the Windows API routines GetOpenFilename and GetSaveFilename, though given your unfamiliarity with Fortran and Windows programming, Rasoul, I would not recommend that at this time for you.

OK forget the ambition for present, how can I use your first solution, GET_COMMAND_ARGUMENT?
Doesn't Visual Studio has a routine to handle this simple task? Where should I put/use the GET_COMMAND_ARGUMENT. Is it inside my source code or else where?

GET_COMMAND_ARGUMENT is a Fortran intrinsic function. While it takes four arguments, only the first two are required. The first is an integer number saying which argument you want, starting at 1. The second is a character variable into which is stored the argument string if it exists. The third argument is an integer variable into which is stored the length, and the fourth is an integer variable into which is stored a status value - 0 indicates success

Here's an example of using it:


program test

character(100) filename

integer :: flength, fstatus

call get_command_argument(1,filename,flength, fstatus)

if (fstatus == 0) then

  print *, "Got filename ", trim(filename)

  open (unit=7, file=filename)

  end if

end

When running the program from the command line you might say:

myprog file1.txt

then the call to GET_COMMAND_ARGUMENT would return "file1.txt".

In Visual Studio, you can specify command arguments in the project property Debugging > Command Arguments

Steve - Intel Developer Support

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui