-
Notifications
You must be signed in to change notification settings - Fork 2
/
abs_path.f
40 lines (32 loc) · 1.11 KB
/
abs_path.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
c% Convert relative to absolute path name. The program creates file if it
c% does not exist and then calls ``realpath'' --- C-wrapper to the library
c% function ``realpath''
c%
c% Bugs: this program fails if file does not exist and cannot be created by
c% the user, or if directory is unreadable.
subroutine get_absolute_path (filename,pathname)
implicit none
character filename*(*),pathname*(*)
integer lnblnk
logical exist
integer unit,newunit
character name*200
integer i
c% create file if it does not exist
inquire (file=filename,exist=exist)
if (.not.exist) then
unit = newunit()
open(unit,file=filename,status='new')
endif
c% put file name to a C (null-terminated) string
name = filename
i = lnblnk(filename)
name (i+1:i+1) = char(0)
c% realpath\_ just calls the library function realpath (see real\_path.c)
call realpath (name,pathname)
c% convert C string to the fortran format
call fixstring(pathname)
c% delete temprorary file.
if (.not.exist) close (unit,status='delete')
return
end