- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I compiled this following code in Fedora 11 with intel fortran compiler 11. If the 'filename' is in the same folder of a.out, it find the file. Or it will not find the file even I gave the full path of the file, like ''/home/yj/e.txt''
Why? I never have such problem in Windows os.
program main
implicit none
character(len=300)::filename
logical::exists
write(*,*) 'Input your file name'
read(*,*) filename
inquire(file=filename,exist=exists)
if (exists) then
write(*,*) 'file exists'
else
write(*,*)'I did not find that file.'
end if
stop
end program
Why? I never have such problem in Windows os.
program main
implicit none
character(len=300)::filename
logical::exists
write(*,*) 'Input your file name'
read(*,*) filename
inquire(file=filename,exist=exists)
if (exists) then
write(*,*) 'file exists'
else
write(*,*)'I did not find that file.'
end if
stop
end program
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have problems when you enter the complete path in linux, but not in Windows, since Windows uses and linux uses /, and everything after a / is stripped.
You can fix this by changing your read statement to
read (*,100) filename
100 format ((A))
However, the program as posted shouldn't have any problems just entering the filename without the full path, so I'm confused by that....
By the way,might not be a bad idea (I think) to change your inquire call to:
inquire(file=TRIM(filename),exist=exists)
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - mrentropy
You have problems when you enter the complete path in linux, but not in Windows, since Windows uses and linux uses /, and everything after a / is stripped.
You can fix this by changing your read statement to
read (*,100) filename
100 format ((A))
However, the program as posted shouldn't have any problems just entering the filename without the full path, so I'm confused by that....
By the way,might not be a bad idea (I think) to change your inquire call to:
inquire(file=TRIM(filename),exist=exists)
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - yjyincj
Quoting - mrentropy
You have problems when you enter the complete path in linux, but not in Windows, since Windows uses and linux uses /, and everything after a / is stripped.
You can fix this by changing your read statement to
read (*,100) filename
100 format ((A))
However, the program as posted shouldn't have any problems just entering the filename without the full path, so I'm confused by that....
By the way,might not be a bad idea (I think) to change your inquire call to:
inquire(file=TRIM(filename),exist=exists)
Peter
A few minor comments:
1. You shouldn't need the extra parentheses in the format statement. I.e., you should be able to use
100 format(A)
2. Some people prefer to include small formats directly in a read or write statement. E.g.,
read(*,'(A)') filename
3. You could even continue using read(*,*) filename if you make a small change in how you enter the input. Instead of entering
/path/to/filename
you could enter either
'/path/to/filename'
or
"/path/to/filename"
Either form of quoting causes the "/"s in the path to be read as data instead of as a signal to end the input.
-Kurt

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page