changes in wham
[unres.git] / source / unres / src_Eshel / openunits.F
1       subroutine openunits
2       implicit real*8 (a-h,o-z)
3       include 'DIMENSIONS'    
4 #ifdef MPI
5       include 'mpif.h'
6       character*16 form,nodename
7       integer nodelen
8 #endif
9       include 'COMMON.SETUP'
10       include 'COMMON.IOUNITS'
11       include 'COMMON.MD'
12       include 'COMMON.CONTROL'
13       integer lenpre,lenpot,ilen,lentmp
14       external ilen
15       character*3 out1file_text,ucase
16       character*3 ll
17       external ucase
18 c      print *,"Processor",myrank,"fg_rank",fg_rank," entered openunits"
19       call getenv_loc("PREFIX",prefix)
20       pref_orig = prefix
21       call getenv_loc("POT",pot)
22       call getenv_loc("DIRTMP",tmpdir)
23       call getenv_loc("CURDIR",curdir)
24       call getenv_loc("OUT1FILE",out1file_text)
25 c      print *,"Processor",myrank,"fg_rank",fg_rank," did GETENV"
26       out1file_text=ucase(out1file_text)
27       if (out1file_text(1:1).eq."Y") then
28         out1file=.true.
29       else 
30         out1file=fg_rank.gt.0
31       endif
32       lenpre=ilen(prefix)
33       lenpot=ilen(pot)
34       lentmp=ilen(tmpdir)
35       if (lentmp.gt.0) then
36           write (*,'(80(1h!))')
37           write (*,'(a,19x,a,19x,a)') "!","  A T T E N T I O N  ","!"
38           write (*,'(80(1h!))')
39           write (*,*)"All output files will be on node /tmp directory." 
40 #ifdef MPI
41         call  MPI_GET_PROCESSOR_NAME( nodename, nodelen, IERROR )
42         if (me.eq.king) then
43           write (*,*) "The master node is ",nodename
44         else if (fg_rank.eq.0) then
45           write (*,*) "I am the CG slave node ",nodename
46         else 
47           write (*,*) "I am the FG slave node ",nodename
48         endif
49 #endif
50         PREFIX = tmpdir(:lentmp)//'/'//prefix(:lenpre)
51         lenpre = lentmp+lenpre+1
52       endif
53       entname=prefix(:lenpre)//'_'//pot(:lenpot)//'.entr'
54 C Get the names and open the input files
55 #if defined(WINIFL) || defined(WINPGI)
56       open(1,file=pref_orig(:ilen(pref_orig))//
57      &  '.inp',status='old',readonly,shared)
58        open (9,file=prefix(:ilen(prefix))//'.intin',status='unknown')
59 C      open (18,file=prefix(:ilen(prefix))//'.entin',status='unknown')
60 C Get parameter filenames and open the parameter files.
61       call getenv_loc('BONDPAR',bondname)
62       open (ibond,file=bondname,status='old',readonly,shared)
63       call getenv_loc('THETPAR',thetname)
64       open (ithep,file=thetname,status='old',readonly,shared)
65 #ifndef CRYST_THETA
66       call getenv_loc('THETPARPDB',thetname_pdb)
67       open (ithep_pdb,file=thetname_pdb,status='old',readonly,shared)
68 #endif
69       call getenv_loc('ROTPAR',rotname)
70       open (irotam,file=rotname,status='old',readonly,shared)
71 #ifndef CRYST_SC
72       call getenv_loc('ROTPARPDB',rotname_pdb)
73       open (irotam_pdb,file=rotname_pdb,status='old',readonly,shared)
74 #endif
75       call getenv_loc('TORPAR',torname)
76       open (itorp,file=torname,status='old',readonly,shared)
77       call getenv_loc('TORDPAR',tordname)
78       open (itordp,file=tordname,status='old',readonly,shared)
79       call getenv_loc('FOURIER',fouriername)
80       open (ifourier,file=fouriername,status='old',readonly,shared)
81       call getenv_loc('ELEPAR',elename)
82       open (ielep,file=elename,status='old',readonly,shared)
83       call getenv_loc('SIDEPAR',sidename)
84       open (isidep,file=sidename,status='old',readonly,shared)
85 #elif (defined CRAY) || (defined AIX)
86       open(1,file=pref_orig(:ilen(pref_orig))//'.inp',status='old',
87      &  action='read')
88 c      print *,"Processor",myrank," opened file 1" 
89       open (9,file=prefix(:ilen(prefix))//'.intin',status='unknown')
90 c      print *,"Processor",myrank," opened file 9" 
91 C      open (18,file=prefix(:ilen(prefix))//'.entin',status='unknown')
92 C Get parameter filenames and open the parameter files.
93       call getenv_loc('BONDPAR',bondname)
94       open (ibond,file=bondname,status='old',action='read')
95 c      print *,"Processor",myrank," opened file IBOND" 
96       call getenv_loc('THETPAR',thetname)
97       open (ithep,file=thetname,status='old',action='read')
98 c      print *,"Processor",myrank," opened file ITHEP" 
99 #ifndef CRYST_THETA
100       call getenv_loc('THETPARPDB',thetname_pdb)
101       open (ithep_pdb,file=thetname_pdb,status='old',action='read')
102 #endif
103       call getenv_loc('ROTPAR',rotname)
104       open (irotam,file=rotname,status='old',action='read')
105 c      print *,"Processor",myrank," opened file IROTAM" 
106 #ifndef CRYST_SC
107       call getenv_loc('ROTPARPDB',rotname_pdb)
108       open (irotam_pdb,file=rotname_pdb,status='old',action='read')
109 #endif
110       call getenv_loc('TORPAR',torname)
111       open (itorp,file=torname,status='old',action='read')
112 c      print *,"Processor",myrank," opened file ITORP" 
113       call getenv_loc('TORDPAR',tordname)
114       open (itordp,file=tordname,status='old',action='read')
115 c      print *,"Processor",myrank," opened file ITORDP" 
116       call getenv_loc('SCCORPAR',sccorname)
117       open (isccor,file=sccorname,status='old',action='read')
118 c      print *,"Processor",myrank," opened file ISCCOR" 
119       call getenv_loc('FOURIER',fouriername)
120       open (ifourier,file=fouriername,status='old',action='read')
121 c      print *,"Processor",myrank," opened file IFOURIER" 
122       call getenv_loc('ELEPAR',elename)
123       open (ielep,file=elename,status='old',action='read')
124 c      print *,"Processor",myrank," opened file IELEP" 
125       call getenv_loc('SIDEPAR',sidename)
126       open (isidep,file=sidename,status='old',action='read')
127 c      print *,"Processor",myrank," opened file ISIDEP" 
128 c      print *,"Processor",myrank," opened parameter files" 
129 #elif (defined G77)
130       open(1,file=pref_orig(:ilen(pref_orig))//'.inp',status='old')
131       open (9,file=prefix(:ilen(prefix))//'.intin',status='unknown')
132 C      open (18,file=prefix(:ilen(prefix))//'.entin',status='unknown')
133 C Get parameter filenames and open the parameter files.
134       call getenv_loc('BONDPAR',bondname)
135       open (ibond,file=bondname,status='old')
136       call getenv_loc('THETPAR',thetname)
137       open (ithep,file=thetname,status='old')
138 #ifndef CRYST_THETA
139       call getenv_loc('THETPARPDB',thetname_pdb)
140       open (ithep_pdb,file=thetname_pdb,status='old')
141 #endif
142       call getenv_loc('ROTPAR',rotname)
143       open (irotam,file=rotname,status='old')
144 #ifndef CRYST_SC
145       call getenv_loc('ROTPARPDB',rotname_pdb)
146       open (irotam_pdb,file=rotname_pdb,status='old')
147 #endif
148       call getenv_loc('TORPAR',torname)
149       open (itorp,file=torname,status='old')
150       call getenv_loc('TORDPAR',tordname)
151       open (itordp,file=tordname,status='old')
152       call getenv_loc('SCCORPAR',sccorname)
153       open (isccor,file=sccorname,status='old')
154       call getenv_loc('FOURIER',fouriername)
155       open (ifourier,file=fouriername,status='old')
156       call getenv_loc('ELEPAR',elename)
157       open (ielep,file=elename,status='old')
158       call getenv_loc('SIDEPAR',sidename)
159       open (isidep,file=sidename,status='old')
160 #else
161       open(1,file=pref_orig(:ilen(pref_orig))//'.inp',status='old',
162      &action='read')
163        open (9,file=prefix(:ilen(prefix))//'.intin',status='unknown')
164 C      open (18,file=prefix(:ilen(prefix))//'.entin',status='unknown')
165 C Get parameter filenames and open the parameter files.
166       call getenv_loc('BONDPAR',bondname)
167       open (ibond,file=bondname,status='old',action='read')
168       call getenv_loc('THETPAR',thetname)
169       open (ithep,file=thetname,status='old',action='read')
170 #ifndef CRYST_THETA
171       call getenv_loc('THETPARPDB',thetname_pdb)
172       print *,"thetname_pdb ",thetname_pdb
173       open (ithep_pdb,file=thetname_pdb,status='old',action='read')
174       print *,ithep_pdb," opened"
175 #endif
176       call getenv_loc('ROTPAR',rotname)
177       open (irotam,file=rotname,status='old',action='read')
178 #ifndef CRYST_SC
179       call getenv_loc('ROTPARPDB',rotname_pdb)
180       open (irotam_pdb,file=rotname_pdb,status='old',action='read')
181 #endif
182       call getenv_loc('TORPAR',torname)
183       open (itorp,file=torname,status='old',action='read')
184       call getenv_loc('TORDPAR',tordname)
185       open (itordp,file=tordname,status='old',action='read')
186       call getenv_loc('SCCORPAR',sccorname)
187       open (isccor,file=sccorname,status='old',action='read')
188       call getenv_loc('FOURIER',fouriername)
189       open (ifourier,file=fouriername,status='old',action='read')
190       call getenv_loc('ELEPAR',elename)
191       open (ielep,file=elename,status='old',action='read')
192       call getenv_loc('SIDEPAR',sidename)
193       open (isidep,file=sidename,status='old',action='read')
194 #endif
195 #ifndef OLDSCP
196 C
197 C 8/9/01 In the newest version SCp interaction constants are read from a file
198 C Use -DOLDSCP to use hard-coded constants instead.
199 C
200       call getenv_loc('SCPPAR',scpname)
201 #if defined(WINIFL) || defined(WINPGI)
202       open (iscpp,file=scpname,status='old',readonly,shared)
203 #elif (defined CRAY)  || (defined AIX)
204       open (iscpp,file=scpname,status='old',action='read')
205 #elif (defined G77)
206       open (iscpp,file=scpname,status='old')
207 #else
208       open (iscpp,file=scpname,status='old',action='read')
209 #endif
210 #endif
211       call getenv_loc('PATTERN',patname)
212 #if defined(WINIFL) || defined(WINPGI)
213       open (icbase,file=patname,status='old',readonly,shared)
214 #elif (defined CRAY)  || (defined AIX)
215       open (icbase,file=patname,status='old',action='read')
216 #elif (defined G77)
217       open (icbase,file=patname,status='old')
218 #else
219       open (icbase,file=patname,status='old',action='read')
220 #endif
221 #ifdef MPI
222 C Open output file only for CG processes
223 c      print *,"Processor",myrank," fg_rank",fg_rank
224       if (fg_rank.eq.0) then
225
226       if (nodes.eq.1) then
227         npos=3
228       else
229         npos = dlog10(dfloat(nodes-1))+1
230       endif
231       if (npos.lt.3) npos=3
232       write (liczba,'(i1)') npos
233       form = '(bz,i'//liczba(:ilen(liczba))//'.'//liczba(:ilen(liczba))
234      &  //')'
235       write (liczba,form) me
236       outname=prefix(:lenpre)//'.out_'//pot(:lenpot)//
237      &  liczba(:ilen(liczba))
238       intname=prefix(:lenpre)//'_'//pot(:lenpot)//liczba(:ilen(liczba))
239      &  //'.int'
240       pdbname(1)=prefix(:lenpre)//'_'//pot(:lenpot)//
241      & liczba(:ilen(liczba))
242      &  //'.pdb'
243       mol2name=prefix(:lenpre)//'_'//pot(:lenpot)//
244      &  liczba(:ilen(liczba))//'.mol2'
245       statname=prefix(:lenpre)//'_'//pot(:lenpot)//
246      &  liczba(:ilen(liczba))//'.stat'
247       if (lentmp.gt.0)
248      &  call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_'//pot(:lenpot)
249      &      //liczba(:ilen(liczba))//'.stat')
250       rest2name=prefix(:ilen(prefix))//"_"//liczba(:ilen(liczba))
251      &  //'.rst'
252       if(usampl) then
253           qname=prefix(:lenpre)//'_'//pot(:lenpot)//
254      & liczba(:ilen(liczba))//'.const'
255       endif 
256
257       endif
258 #else
259       outname=prefix(:lenpre)//'.out_'//pot(:lenpot)
260       intname=prefix(:lenpre)//'_'//pot(:lenpot)//'.int'
261       pdbname(1)=prefix(:lenpre)//'_'//pot(:lenpot)//'.pdb'
262       mol2name=prefix(:lenpre)//'_'//pot(:lenpot)//'.mol2'
263       statname=prefix(:lenpre)//'_'//pot(:lenpot)//'.stat'
264       if (lentmp.gt.0)
265      &  call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_'//pot(:lenpot)
266      &    //'.stat')
267       rest2name=prefix(:ilen(prefix))//'.rst'
268 #endif
269 #if defined(AIX) || defined(PGI)
270       if (me.eq.king .or. .not. out1file) 
271      &   open(iout,file=outname,status='unknown')
272 c#define DEBUG
273 #ifdef DEBUG
274       if (fg_rank.gt.0) then
275         write (liczba,'(i3.3)') myrank/nfgtasks
276         write (ll,'(bz,i3.3)') fg_rank
277         open(iout,file="debug"//liczba(:ilen(liczba))//"."//ll,
278      &   status='unknown')
279       endif
280 #endif
281 c#undef DEBUG
282       if(me.eq.king) then
283        open(igeom,file=intname,status='unknown',position='append')
284        open(ipdb,file=pdbname(1),status='unknown')
285        open(imol2,file=mol2name,status='unknown')
286        open(istat,file=statname,status='unknown',position='append')
287       else
288 c1out       open(iout,file=outname,status='unknown')
289       endif
290 #else
291       if (me.eq.king .or. .not.out1file)
292      &    open(iout,file=outname,status='unknown')
293 c#define DEBUG
294 #ifdef DEBUG
295       if (fg_rank.gt.0) then
296         print "Processor",fg_rank," opening output file"
297         write (liczba,'(i3.3)') myrank/nfgtasks
298         write (ll,'(bz,i3.3)') fg_rank
299         open(iout,file="debug"//liczba(:ilen(liczba))//"."//ll,
300      &   status='unknown')
301       endif
302 #endif
303 c#undef DEBUG
304       if(me.eq.king) then
305        open(igeom,file=intname,status='unknown',access='append')
306        open(ipdb,file=pdbname(1),status='unknown')
307        open(imol2,file=mol2name,status='unknown')
308        open(istat,file=statname,status='unknown',access='append')
309       else
310 c1out       open(iout,file=outname,status='unknown')
311       endif
312 #endif
313 csa      csa_rbank=prefix(:lenpre)//'.CSA.rbank'
314 csa      csa_seed=prefix(:lenpre)//'.CSA.seed'
315 csa      csa_history=prefix(:lenpre)//'.CSA.history'
316 csa      csa_bank=prefix(:lenpre)//'.CSA.bank'
317 csa      csa_bank1=prefix(:lenpre)//'.CSA.bank1'
318 csa      csa_alpha=prefix(:lenpre)//'.CSA.alpha'
319 csa      csa_alpha1=prefix(:lenpre)//'.CSA.alpha1'
320 csac!bankt      csa_bankt=prefix(:lenpre)//'.CSA.bankt'
321 csa      csa_int=prefix(:lenpre)//'.int'
322 csa      csa_bank_reminimized=prefix(:lenpre)//'.CSA.bank_reminimized'
323 csa      csa_native_int=prefix(:lenpre)//'.CSA.native.int'
324 csa      csa_in=prefix(:lenpre)//'.CSA.in'
325 c      print *,"Processor",myrank,"fg_rank",fg_rank," opened files"
326 C Write file names
327       if (me.eq.king)then
328       write (iout,'(80(1h-))')
329       write (iout,'(30x,a)') "FILE ASSIGNMENT"
330       write (iout,'(80(1h-))')
331       write (iout,*) "Input file                      : ",
332      &  pref_orig(:ilen(pref_orig))//'.inp'
333       write (iout,*) "Output file                     : ",
334      &  outname(:ilen(outname))
335       write (iout,*)
336       write (iout,*) "Sidechain potential file        : ",
337      &  sidename(:ilen(sidename))
338 #ifndef OLDSCP
339       write (iout,*) "SCp potential file              : ",
340      &  scpname(:ilen(scpname))
341 #endif
342       write (iout,*) "Electrostatic potential file    : ",
343      &  elename(:ilen(elename))
344       write (iout,*) "Cumulant coefficient file       : ",
345      &  fouriername(:ilen(fouriername))
346       write (iout,*) "Torsional parameter file        : ",
347      &  torname(:ilen(torname))
348       write (iout,*) "Double torsional parameter file : ",
349      &  tordname(:ilen(tordname))
350       write (iout,*) "SCCOR parameter file : ",
351      &  sccorname(:ilen(sccorname))
352       write (iout,*) "Bond & inertia constant file    : ",
353      &  bondname(:ilen(bondname))
354       write (iout,*) "Bending parameter file          : ",
355      &  thetname(:ilen(thetname))
356       write (iout,*) "Rotamer parameter file          : ",
357      &  rotname(:ilen(rotname))
358       write (iout,*) "Threading database              : ",
359      &  patname(:ilen(patname))
360       if (lentmp.ne.0) 
361      &write (iout,*)" DIRTMP                          : ",
362      &  tmpdir(:lentmp)
363       write (iout,'(80(1h-))')
364       endif
365       return
366       end
367