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

Redirect output(data files) to another directory

lessonfree
Beginner
899 Views

How to redirect data files to another(from directory where my executable file and loading data are located) directory.

Is it possible to do it from command line at the same time, when I start the code?

0 Kudos
3 Replies
Kevin_D_Intel
Employee
899 Views
There are programmatic methods available for a program to process command line arguments (GETARG) and thuscontrol the location of output files via the OPEN.

If the files are not named in the OPEN, then maybe you can utilize the Intel Fortran specific environment variable control discussed in the Intel Fortran Users Guide in the section titled Assigning Files to Logical Units.

This environment variable methodpermits setting paths to specific files. For example,

export FORT30=/tmp/output

After executing the preceding bash/sh command,when the program executes, allI/O statements to unit 30 will refer to file output in the specified directory, /tmp.

Again, this only works when a file name is not specified in the OPEN statement. You just need knowledge of the unit number to be able to control the path and the name of the file.
0 Kudos
jimdempseyatthecove
Honored Contributor III
899 Views

You might try experimenting with CHDIR(dir_name) after opening up your input files (assuming CHDIR works on Linux). Prior to issuing CHDIR you might want to issue GETCWD to get (save) original current working director such that you can restore this prior to program exit.

The CHDIR can use a directory specified as an environment variable which you can set just prior to launching the app. Or you can pass in the directory as a command line argument. Your choice.

Jim Dempsey
0 Kudos
bubin
New Contributor I
899 Views
Quoting - lessonfree

How to redirect data files to another(from directory where my executable file and loading data are located) directory.

Is it possible to do it from command line at the same time, when I start the code?


There are two other simple ways to redirect output in addition to those mentioned above.

1) If the entire output is done using default i/o unit you can simply do this:

./myprogram > /mypath/myoutput.txt

2) If the output is done into several files called out1, out2, ... then you can create the following links before executing your program:

ln -s /mypath1/mynewout1 out1
ln -s /mypath2/mynewout2 out2
...
./myprogram


0 Kudos
Reply