gfxgfx
 
Please login or register.

Login with username, password and session length
 
gfx gfx
gfx
1565 Posts in 517 Topics by 752 Members - Latest Member: zaikunzhang September 25, 2021, 05:23:05 PM
*
gfx* Home | Help | Search | Login | Register | gfx
gfx
Absoft User Forum  |  Support  |  Macintosh  |  Set Working Directory with MRWE ?
gfx
gfxgfx
 

Author Topic: Set Working Directory with MRWE ?  (Read 3833 times)

michalowicz

  • Newbie
  • *
  • Posts: 7
Set Working Directory with MRWE ?
« on: May 28, 2010, 01:40:28 AM »
I renew an old question :

Wriing MRWE applicaitons I often use open(unit=n,file='',.....  in order to open the standard file browser, either on MACOSX or on WIndows systems.
It works fine, HOWEVER :

- On Windows systems it seems that if you open a file in a directory by this way, this directory is set as the working directory; If you open and write a new file  without specifying the path in the program, it is set to the last open directory.

-On MacOSX, the working directory is set to the applicaiton directory, and cannot be changed just by opening a file outside this application directory. You must use a system-specific API (which cannot be the same for both systems !) to do that. And it is exactly what I would like to avoid : chnaging the code while going from one system to the other.

So, my question : Is the subroutine which manage the open(unit=n,file='',...)  command open or not in MRWE. If yes, where can I find it ? And is it difficult or not to write the routine which set the working directory, as i was provided in the old Stdfile routine of the first versions of Absoft Fortran for the Mac.

Another possibility is to get the path name of a file onpned with open(unit=n,file='',...
In standard  fortran, it's easy to get the file name (without the path ) by INQUIRE(unit=n,file=filename).
But the file path ? I have understood that it is impossible in the standard I/O functions. Is there a MRWE finction which allows to get the pathname ?



Alain
« Last Edit: May 28, 2010, 02:20:37 AM by michalowicz »

forumadmin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
Re: Set Working Directory with MRWE ?
« Reply #1 on: May 28, 2010, 09:08:57 AM »
Use the Unix library function chdir(). You can find a summary of chdir() in:

/Applications/Absoft11.0/doc/SupportLibraries.pdf

michalowicz

  • Newbie
  • *
  • Posts: 7
Re: Set Working Directory with MRWE ?
« Reply #2 on: May 30, 2010, 07:09:01 AM »
Thanks,
I tried and it works well. If you know a directory name, you can easily change the working directory by the unix function chdir. You can also get the working directory name by getcwd.

However, the question is still open : how to get the directory name of a file connected to unit n n ?

Example :

character*512 filename
Open(unit=1,file='',status='old")
inquire(unit=1,name=filename)

this piece of code opens the standard file browser. You can open a file and connect it to unit n 1.
You can get its file name in the character variable filename

But How to get its directory, the one you need to use the unx function chdir ?

Not so obvious, insn't it ?

Alain
« Last Edit: May 30, 2010, 09:39:56 AM by michalowicz »

Brad

  • Newbie
  • *
  • Posts: 1
Re: Set Working Directory with MRWE ?
« Reply #3 on: February 17, 2013, 02:28:30 AM »
I am faced with the same issue. Earlier versions of FORTRAN (maybe back in the old Language Systems days) use to have a variable in the open command (I think) that would return the path to the file just opened using open(1,file = '' ...)

A solution to this would be a big help

forumadmin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
Re: Set Working Directory with MRWE ?
« Reply #4 on: February 18, 2013, 10:50:31 AM »
If the file specified in the OPEN statement has a fully qualified path name, then you won't need the path. If the file is opened with just a filename or a relative path name, then all you need is the current working directory. You can get this with the getcwd() function in the Unix support library. See page 16 of the Absoft support library manual.

Absoft User Forum  |  Support  |  Macintosh  |  Set Working Directory with MRWE ?
 

gfxgfx
gfx gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!