forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File existence - please help

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
christyleomin



Joined: 08 Apr 2011
Posts: 155

PostPosted: Fri Oct 14, 2011 10:44 am    Post subject: File existence - please help Reply with quote

I am reading several files stored at a particualr location.

There might be 'N' number of files which are ALWAYS named as;

1) file01
2)file 02
3)---

10)file10

-----

N) file N

Now, I successively open files using;

Code:
open(unit=1,
     1     file='file01',
     2     status='old',
     3     form='unformatted',
     4     access='direct',
     5     recl=512*8)

...do calculations

then open next file

...do calcualtions

..and so on

----


How do I find (before opening a file- say file06) whether it exists or not.

For the first file, the user specifies the file name and location, but it is the program which needs to find whether file02 exists and do coresponding calcualtions.

How could I find before the open statement whether file 02 exists or not?
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Fri Oct 14, 2011 11:03 am    Post subject: Reply with quote

You could use the following function, to test if the file exists, before calling open, such as:-

Code:

   if ( file_exists (File_Name) ) Then
      OPEN (file=File_name,           &
            Status='OLD',             &
            form='unformatted',       &
            access='direct',          &
            recl=512*8,               &
            IOSTAT=IOSTAT,
.....
      LOGICAL FUNCTION File_Exists (FILE_NAME)
!
!   Tests for the existence of a file
!
      character (len=*),        intent (in)     :: file_name
!
      LOGICAL   EXIST
      INTEGER*4 IOSTAT
!
      INQUIRE (FILE = FILE_NAME, EXIST = EXIST, IOSTAT = IOSTAT )
      IF (IOSTAT /= 0) EXIST = .FALSE.
!
      file_exists = EXIST
!
      END

Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7925
Location: Salford, UK

PostPosted: Fri Oct 14, 2011 11:46 am    Post subject: Reply with quote

There is also the functin FEXISTS@ in the FTN95 library.
Back to top
View user's profile Send private message AIM Address
christyleomin



Joined: 08 Apr 2011
Posts: 155

PostPosted: Fri Oct 14, 2011 1:56 pm    Post subject: Reply with quote

Does INQUIRE statement work in Fortrann 77 as well because the code has to be replicated in F77 as well..
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: Düsseldorf, Germany

PostPosted: Fri Oct 14, 2011 3:55 pm    Post subject: Reply with quote

Yes. For instance, look here:
http://www.univ-orleans.fr/EXT/ASTEX/astex/doc/en/prof77/html/prof77.htm

Regards - Wilfried
Back to top
View user's profile Send private message
christyleomin



Joined: 08 Apr 2011
Posts: 155

PostPosted: Sat Oct 15, 2011 4:55 pm    Post subject: Reply with quote

Thanks to all.It helps a lot!
Back to top
View user's profile Send private message
johannes



Joined: 21 Jan 2011
Posts: 65
Location: Leimen, Germany

PostPosted: Wed Nov 23, 2011 6:47 pm    Post subject: Reply with quote

Just to add a comment, how to automatically fill the correct file names, esp. file02 etc. in other words how to make the leading zeros for file number <10.

For this purpose use the In.m descriptor, which adds leading zeros

character*6 filename
do i=1,20
write (filename,'(A4,I2.2)') 'file',i
enddo
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group