Silverfrost Forums

Welcome to our forums

Finding files

17 Apr 2009 1:41 #4425

Hi, This is clearly an issue of my not understanding how to tell Plato/Ftn95 where to find data and source files. In the test piece of code below, the file 'test.dat' appears invisible. I created it using a test editor in the same directory as the .f95 file. When the open statement is reached the file 'does not exist'.

            character*4        a
	open(unit=10,file='test.dat',status='old')
	read(10,'(a)') a
	write(6,'(a)') a
	stop
	end

How do I associate filenames with unit numbers? Is there a way to tell Plato 'find the file here'? Is there an equivalent of 'ln -s test.dat fort.10' in Unix? Or is it done through env variables? How?

A (presumably) related problem is the debugger not finding the source code file. When I use the little green arrow to run the prog, the source code window is blank. I would appreciate advice on these...

Thanx, Travis

17 Apr 2009 3:54 #4426

Hi Travis,

Re 'How do I associate filenames with Unit numbers?' - exactly as you have done. The problem is that test.dat must be in the current working directory for what you have done to work. Does Plato put your EXE in the same directory as the fortran source code and run it from there?

If the file isn't found, then the answer is clearly not.

I have in the past resorted to calling CURDIR@ to find which current directory I was in - see the FTN95 CHM helpfile library or the code fragment below.

program x
CHARACTER (LEN=256)::CURDIR@
PRINT *,'You are currently in ',CURDIR@()
END

If you put a correct full path (such as 'c:\MyCode\Source\test.dat' then it would be found. If you don't want to do that, you can always hunt for the file and its directory (hint - again in FTN95.chm, look in the FTN95 library under 'file manipulation routines' - there are several that might help you locate your data file). That might require a few lines of coding to sift out the right file, especially if its name is simple and therefore likely to match several files. (see DIRENT@, FILES@, FEXISTS@ etc).

I suspect that when you create a 'project' in Plato, the EXE is put there, not in the source code directory (folder). I have to say that I have never been able to do anything meaningful with Plato, and I always run FTN95 from the command line (my editor can launch the command line app from its toolbar).

Should you then progress to writing a Windows application, there are various alternative procedures you have to follow, but reading between the lines of your request it looks as though you are just starting out with FTN95 and are simply running a 'console application'.

Regards

Eddie

19 Apr 2009 1:26 #4429

Eddie, Thanks much. Yes there is no problem with finding the 'open'ed files when programs are launched via the command line. SDBG, however, still has trouble with finding the source code file to display. Says something like ' system error 2 occured, The system cannot find file specified file...'. All relevant files are in the same directory, and the debugger is launced from there. Have I set any pointers incorrectly, is there a limit on path length strings, etc...

Thanx, Travis

20 Apr 2009 8:34 #4430

Travis,

Using Eddie's ideas, you could try the following to get a better idea of the error meaning. For safety I only use unit numbers > 10. I think this is mostly FTN77 compatible.

John

character*40 a
integer*2 iostat
!
call Report_Current_Directory
!
open (unit=11,file='test.dat',status='old',iostat=iostat) 
 call report_iostat ('opening file test.dat', iostat)
read (11,1001,iostat=iostat) a 
 call report_iostat ('reading file test.dat', iostat)
if (iostat == 0) write (*,1001) a 
stop 
1001 format (a)
end 

subroutine Report_Current_Directory
CHARACTER CURDIR@*256, location*256
external CURDIR@
!
location = CURDIR@ () 
PRINT *,'You are currently in ',trim(location)
END subroutine Report_Current_Directory

subroutine report_iostat (string, iostat)
integer*2 iostat 
character string*(*), message*80
if (iostat /= 0) then
   CALL FORTRAN_ERROR_MESSAGE@ (iostat, MESSAGE)
   write (*,1000) ' Error ',string,' : ',iostat,' : ', trim (message)
end if
1000 format (a,a,a,i0,a,a)   ! use I4 for F77
end subroutine report_iostat
20 Apr 2009 9:48 #4432

If you know where the file is then the simplest way is to provide its full path in your OPEN statement.

Alternatively, there is a good chance that the file will be found if it is located in a folder that is included in the PATH environment variable.

Please login to reply.