VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
parse_extension.f
Go to the documentation of this file.
1
3
9 SUBROUTINE parse_extension(file_to_parse, file_or_extension, lnc)
10 IMPLICIT NONE
11!-----------------------------------------------
12! D u m m y A r g u m e n t s
13!-----------------------------------------------
14 CHARACTER(LEN=*), INTENT(in) :: file_or_extension
15 CHARACTER(LEN=*), INTENT(inout) :: file_to_parse
16 LOGICAL, INTENT(out) :: lnc
17!-----------------------------------------------
18! L o c a l V a r i a b l e s
19!-----------------------------------------------
20 INTEGER :: index_path, index_comp, index_nc, istat=0
21 LOGICAL :: ltxt
22 CHARACTER(len=LEN(file_to_parse)) :: path
23 CHARACTER(len=LEN(file_to_parse)) :: temp !!Assumes file_to_parse can store it all
24 CHARACTER(LEN=1), PARAMETER :: ch_test = '.'
25!-----------------------------------------------
26!
27! FIRST CHECK IF FILE_OR_EXTENSION IS A FILENAME (FILE_TO_PARSE EMBEDDED)
28! OR AN EXTENSION
29!
30 index_path = index(file_or_extension, trim(file_to_parse))
31 index_comp = index_path
32
33 IF (index_path .gt. 0) THEN
34!
35! MUST BE <FILENAME>. OR <FILENAME>_
36!
37 index_nc = index_path + len_trim(file_to_parse)
38 index_path = index(file_or_extension(index_nc:),ch_test)
39!SPH032510 IF ((ch_test.ne.'.') .and. (ch_test.ne.'_')) index_path = 0
40 END IF
41
42 IF (index_path .gt. 0) THEN
43 file_to_parse = file_or_extension
44!
45! CHECK FOR netcdf FILE EXTENSION (*.nc)
46!
47 index_nc = index(file_to_parse,".nc",back=.true.)
48 lnc = (index_nc .eq. (len_trim(file_to_parse)-2))
49!
50! MAY HAVE PASSED FILE NAME EXTENSION WITHOUT .nc; CHECK IF FILE_TO_PARSE EXISTS
51 IF (.not.lnc) THEN
52 INQUIRE(file=file_to_parse, exist=ltxt, iostat=istat)
53 IF (istat.ne.0 .or. .not.ltxt) THEN
54 file_to_parse = trim(file_to_parse) // ".nc"
55 lnc = .true.
56 END IF
57 END IF
58
59 ELSE
60!
61! CHECK IF TEXT (.txt) OR NETCDF (.nc) FILE EXISTS
62!
63 path = file_to_parse
64 IF (file_or_extension(1:1) == '.' .or.
65 1 file_or_extension(1:1) == '_') THEN
66 temp = trim(path) // file_or_extension
67 ELSE IF (index_comp == 0) THEN
68 temp = trim(path) // '_' // file_or_extension
69 ELSE
70 temp = trim(file_or_extension)
71 END IF
72
73!
74! FIRST LOOK FOR FILE WITH .nc SUFFIX IN file_or_extension
75!
76 file_to_parse = trim(temp)
77 index_nc = index(file_to_parse,".nc",back=.true.)
78 lnc = (index_nc .eq. (len_trim(file_to_parse)-2))
79!
80! NEXT LOOK FOR .txt SUFFIX
81!
82 IF (.not.lnc) THEN
83 index_nc = index(file_to_parse,".txt",back=.true.)
84 ltxt = (index_nc .eq. (len_trim(file_to_parse)-3))
85!
86! CHECK IF file_or_extension WAS GIVEN WITHOUT EXPLICIT .nc OR .txt SUFFIX
87!
88 IF (.not.ltxt) THEN
89 file_to_parse = trim(temp) // '.nc'
90 INQUIRE (file=file_to_parse, exist=lnc, iostat=istat)
91 IF (istat.ne.0 .or. .not.lnc) THEN
92 file_to_parse = trim(path) // '.'
93 1 // trim(file_or_extension) // '.nc'
94 INQUIRE (file=file_to_parse, exist=lnc, iostat=istat)
95 IF (istat.ne.0 .or. .not.lnc) THEN
96 file_to_parse = trim(temp) // '.txt'
97 INQUIRE (file=file_to_parse, exist=ltxt,
98 1 iostat=istat)
99 IF (.not.ltxt) THEN
100 file_to_parse = trim(path) // '.' //
101 1 trim(file_or_extension) // '.txt'
102 INQUIRE (file=file_to_parse, exist=ltxt,
103 1 iostat=istat)
104 END IF
105 END IF
106 END IF
107 END IF
108!
109! DEFAULT (OLD STYLE) FILE NAME WHEN NONE OF THE ABOVE EXIST
110!
111 IF ((istat.ne.0 .or. .not.ltxt) .and. .not.lnc) THEN
112 file_to_parse = trim(path) // '.' // file_or_extension
113 END IF
114
115 END IF
116
117 END IF
118
119 END SUBROUTINE parse_extension
subroutine parse_extension(file_to_parse, file_or_extension, lnc)
Parse the first command-line argument into a filename.