Specifying the working directory as the default for READ and WRITE statements using XCODE4

Specifying the working directory as the default for READ and WRITE statements using XCODE4

I have an application with an OPEN statement specifying a static filename for program input data accessed with READ statements (i.e., FILE = 'MY.in') and the same situation for program output via WRITE statements (i.e., FILE = 'MY.out').  I would like the ability for the user to store the input files in a working directory they create to meet their needs before program execution and the output files produced in the working directory during program execution.  Compiling the program with Xcode 4 requires the input file to be located in the root directory and the output files are produced there also.  What options or settings do I need to make to change this, so that the files will be saved in a working directory created to meet the needs of the user?

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Have your tried setting the current directory to that of the user preferred data file directory, then using a fully qualified path to run the program?

cd /users/preferred/directory
/location/of/executable/programName {args}

Jim Dempsey


I don't know offhand how to do this in Xcode. If it were Visual Studio, sure. I'll ask one of our Mac experts to chime in on Monday.

Steve - Intel Developer Support

Jim and Steve - Thanks for the quick replies.  Here is a little more information.  The applications I am working with perform as I've described in Visual Studio.  They happen to be U.S. EPA computer models.  I am porting the applications to a Mac and noticed that the input files have to be in the root directory if I refer to them with no path in the OPEN statements (contrary to Visual Studio).  I would like to set up the applications this way so that all the user has to do is create a working directory of their chosing, copy the application to the working directory, and create an input data file with the pre-defined name 'MY.INP'.  That way all a user has to do is double-click on the application, which accesses MY.INP and produces results in an output file named 'MY.OUT' -- all within the working directory.  This happens to be the standard practice for these EPA models operating in Windows, so I would like to preserve the same user experience in OS X, if possible.  Also, the user working directory is not set and can change depending on the project.  Thanks again for your suggestions.

In your OPEN statement use FILE='./MY.in' or './MY.out'

"(period)(forward slash)" means current directory

Depending on O/S (MAC, Linux, *inux), omitting ./ resorts to using a search path (including /root) that apparently omits current directory.

Jim Dempsey



Additional information. I am not a MAC user so I cannot attest to what is or what is not Standare Operating Procedure, but I can inform you of what to look for.

In the MS Windows environment, when you double click on a file in the browser, the action is to set the current directory to that of the file being clicked on. When the double click is on a ShortCut, the ShortCut has a property that can specify (override) the current directory.

The MAC "browser" may behave entirely different behavior. On Ubuntu Linux (not booted right now), I am not sure but I think I recal the browser has a navigable current directory and seperable viewing directory (iow, launch of application may have current directory different than location of app). Also, I seem to recall you can set properties that include current directory.

What I would suggest you do as an experiment,

1) create a simple app that writes to FILE = 'MY.out' (don't run it from the IDE, don't run it from the file browser)
2) copy the app to a test directory (make an empty one)
3) launch a command window (DOS box)
4) Use CD to set current directory to that of application
5) Run the program, use ./YourProgramName (prepend ./)
6) assuming no error message

Where did MY.out get written to?

If written to test directory, then issue is with what the MAC browser uses for current directory.

Jim Dempsey



Jim -

You make an excellent point.  Double-clicking on the application in the working directory in Finder (the OS X browser) requires the input file to be located in the root directory and produces the output file in root directory.  Executing the application in the working directory in an OS X Terminal session (similar to a Windows DOS session) operates as desired.  The input file can be located in a working directory to produce an output file in the working directory.  By the way, I did try your suggestion of FILE='./MY.INP', but it produced the same result as FILE = 'MY.INP'.  Thank you for your help.

- Michael

>>...Finder (the OS X browser) requires the input file to be located in the root directory

It is more likely that Finder uses the current folder at time of launch of Finder (and which happened to be your root folder).

Try launchig OSX Terminal session,
CD to test folder
Issue command line to launch Finder (but do not change current directory)
Use Finder to launch app (delete MY.INP, MY.OUT prior to doing so)

A potential fix for you is to create a shell script and insert it into your application folder.
Most shell scripts can query the shell to identify the folder of the shell script itself.
These shells also have functions that can strip off the script name (leaving path to script).
This then could be used to set current directory before running your application.

Jim Dempsey


Leave a Comment

Please sign in to add a comment. Not a member? Join today