55c ## All Rights Reserved ##
66c ###################################################
77c
8- c #############################################################
9- c ## ##
10- c ## subroutine getprm -- get force field parameter file ##
11- c ## ##
12- c #############################################################
8+ c ##############################################################
9+ c ## ##
10+ c ## subroutine getprm -- get force field parameter files ##
11+ c ## ##
12+ c ##############################################################
1313c
1414c
15- c "getprm" finds the potential energy parameter file
16- c and then opens and reads the parameters
15+ c "getprm" finds any potential energy parameter files and
16+ c then opens and reads the parameters
1717c
1818c
1919 subroutine getprm
@@ -24,27 +24,53 @@ subroutine getprm
2424 use keys
2525 use params
2626 implicit none
27+ integer maxfile
28+ parameter (maxfile= 12 )
2729 integer i,j,iprm
28- integer nask,next
30+ integer nfile,nask
31+ integer trimtext,next
2932 integer freeunit
30- integer trimtext
3133 logical exist,useprm
3234 character * 4 none
3335 character * 20 keyword
3436 character * 240 prmfile
3537 character * 240 prefix
3638 character * 240 record
3739 character * 240 string
40+ character * 240 ifile(maxfile)
3841c
3942c
40- c set the default name for the parameter file
43+ c set default usage and number of parameter files
4144c
4245 useprm = .true.
46+ nfile = 0
47+ c
48+ c check for parameter file with base name of current system
49+ c
4350 prmfile = filename(1 :leng)// ' .prm'
51+ call version (prmfile,' old' )
52+ inquire (file= prmfile,exist= exist)
53+ if (exist) then
54+ nfile = nfile + 1
55+ ifile(nfile) = prmfile
56+ end if
57+ c
58+ c check for the existence of a generic parameter file
59+ c
60+ if (ldir .eq. 0 ) then
61+ prmfile = ' tinker.prm'
62+ else
63+ prmfile = filename(1 :ldir)// ' tinker.prm'
64+ end if
65+ call version (prmfile,' old' )
66+ inquire (file= prmfile,exist= exist)
67+ if (exist) then
68+ nfile = nfile + 1
69+ ifile(nfile) = prmfile
70+ end if
4471c
4572c try to get a parameter filename from the command line
4673c
47- exist = .false.
4874 do i = 1 , narg-1
4975 string = arg(i)
5076 call upcase (string)
@@ -57,29 +83,72 @@ subroutine getprm
5783 end if
5884 call suffix (prmfile,' prm' ,' old' )
5985 inquire (file= prmfile,exist= exist)
60- if (.not. exist) then
86+ if (exist) then
87+ nfile = nfile + 1
88+ ifile(nfile) = prmfile
89+ else
6190 write (iout,10 )
62- 10 format (/ ,' GETPRM -- Parameter File Specified ' ,
63- & ' on Command Line not Found' )
91+ 10 format (/ ,' GETPRM -- Parameter File Named on ' ,
92+ & ' Command Line not Found' )
6493 call fatal
6594 end if
6695 end if
6796 end do
6897c
6998c search the keyword list for the parameter filename
7099c
71- if (.not. exist) then
72- do i = 1 , nkey
100+ do i = 1 , nkey
101+ next = 1
102+ record = keyline(i)
103+ call gettext (record,keyword,next)
104+ call upcase (keyword)
105+ if (keyword(1 :11 ).eq. ' PARAMETERS '
106+ & .or. keyword(1 :10 ).eq. ' PARAMETER ' ) then
107+ string = record(next:240 )
73108 next = 1
74- record = keyline(i)
75- call gettext (record,keyword,next)
76- call upcase (keyword)
77- if (keyword(1 :11 ).eq. ' PARAMETERS '
78- & .or. keyword(1 :10 ).eq. ' PARAMETER ' ) then
79- string = record(next:240 )
80- next = 1
81- call getstring (string,prmfile,next)
82- if (next .eq. 1 ) call gettext (string,prmfile,next)
109+ call getstring (string,prmfile,next)
110+ if (next .eq. 1 ) call gettext (string,prmfile,next)
111+ if (prmfile(1 :2 ) .eq. ' ~/' ) then
112+ call getenv (' HOME' ,prefix)
113+ prmfile = prefix(1 :trimtext(prefix))//
114+ & prmfile(2 :trimtext(prmfile))
115+ end if
116+ call suffix (prmfile,' prm' ,' old' )
117+ inquire (file= prmfile,exist= exist)
118+ if (exist) then
119+ do j = 1 , nfile
120+ if (prmfile .eq. ifile(j)) goto 20
121+ end do
122+ nfile = nfile + 1
123+ ifile(nfile) = prmfile
124+ 20 continue
125+ else
126+ none = prmfile(1 :4 )
127+ call upcase (none)
128+ if (none .eq. ' NONE' ) useprm = .false.
129+ end if
130+ end if
131+ end do
132+ if (.not. useprm) nfile = 0
133+ c
134+ c if necessary, ask for the parameter filename
135+ c
136+ if (useprm .and. nfile.eq. 0 ) then
137+ nask = 0
138+ exist = .false.
139+ do while (.not. exist .and. nask.lt. maxask)
140+ nask = nask + 1
141+ write (iout,30 )
142+ 30 format (/ ,' Enter Parameter File Name [<Enter>=NONE] : ' ,$)
143+ read (input,40 ) prmfile
144+ 40 format (a240)
145+ next = 1
146+ call getword (prmfile,none,next)
147+ call upcase (none)
148+ if (next.eq. 1 .or. none.eq. ' NONE' ) then
149+ exist = .true.
150+ useprm = .false.
151+ else
83152 if (prmfile(1 :2 ) .eq. ' ~/' ) then
84153 call getenv (' HOME' ,prefix)
85154 prmfile = prefix(1 :trimtext(prefix))//
@@ -91,77 +160,56 @@ subroutine getprm
91160 end do
92161 end if
93162c
94- c test for user specified absence of a parameter file
163+ c check to make sure a parameter file is available
95164c
96- if (.not. exist) then
97- none = prmfile(1 :4 )
98- call upcase (none)
99- if (none .eq. ' NONE' ) then
100- exist = .true.
101- useprm = .false.
102- end if
165+ if (useprm .and. nfile.eq. 0 ) then
166+ write (iout,50 )
167+ 50 format (/ ,' GETPRM -- A Valid Parameter File' ,
168+ & ' was not Provided' )
169+ call fatal
103170 end if
104171c
105- c if necessary, ask for the parameter filename
106- c
107- nask = 0
108- do while (.not. exist .and. nask.lt. maxask)
109- nask = nask + 1
110- write (iout,20 )
111- 20 format (/ ,' Enter Parameter File Name [<Enter>=NONE] : ' ,$)
112- read (input,30 ) prmfile
113- 30 format (a240)
114- next = 1
115- call getword (prmfile,none,next)
116- call upcase (none)
117- if (next .eq. 1 ) then
118- exist = .true.
119- useprm = .false.
120- else if (none.eq. ' NONE' .and. next.eq. 5 ) then
121- exist = .true.
122- useprm = .false.
123- else
124- if (prmfile(1 :2 ) .eq. ' ~/' ) then
125- call getenv (' HOME' ,prefix)
126- prmfile = prefix(1 :trimtext(prefix))//
127- & prmfile(2 :trimtext(prmfile))
128- end if
129- call suffix (prmfile,' prm' ,' old' )
130- inquire (file= prmfile,exist= exist)
131- end if
132- end do
133- if (.not. exist) call fatal
134- c
135- c read the parameter file to get number of lines
172+ c read the parameter files and count the total lines
136173c
137174 nprm = 0
138175 if (useprm) then
139- iprm = freeunit ()
140- open (unit= iprm,file= prmfile,status= ' old' )
141- rewind (unit= iprm)
142- do while (.true. )
143- read (iprm,40 ,err= 50 ,end= 50 )
144- 40 format ()
145- nprm = nprm + 1
176+ do i = 1 , nfile
177+ iprm = freeunit ()
178+ prmfile = ifile(i)
179+ open (unit= iprm,file= prmfile,status= ' old' )
180+ rewind (unit= iprm)
181+ do while (.true. )
182+ read (iprm,60 ,err= 70 ,end= 70 )
183+ 60 format ()
184+ nprm = nprm + 1
185+ end do
186+ 70 continue
187+ close (unit= iprm)
146188 end do
147- 50 continue
148- rewind (unit= iprm)
149189 end if
150190c
151191c perform dynamic allocation of some global arrays
152192c
153193 if (allocated(prmline)) deallocate (prmline)
154194 allocate (prmline(nprm))
155195c
156- c reread the parameter file and store for latter use
196+ c reread the parameter files and store for latter use
157197c
158- do i = 1 , nprm
159- read (iprm,60 ,err= 70 ,end= 70 ) record
160- 60 format (a240)
161- prmline(i) = record
198+ nprm = 0
199+ do i = 1 , nfile
200+ iprm = freeunit ()
201+ prmfile = ifile(i)
202+ open (unit= iprm,file= prmfile,status= ' old' )
203+ rewind (unit= iprm)
204+ dowhile (.true. )
205+ read (iprm,80 ,err= 90 ,end= 90 ) record
206+ 80 format (a240)
207+ nprm = nprm + 1
208+ prmline(nprm) = record
209+ end do
210+ 90 continue
211+ close (unit= iprm)
162212 end do
163- 70 continue
164- close (unit= iprm)
165213c
166214c convert underbar characters to dashes in all keywords
167215c
0 commit comments