1      subroutine ana_wrtxyz(lfnxxx,filxxx,sgmnam,isel,xs,qs,
2     + iwsel,xw,logs,logw,ndxw)
3c
4c $Id$
5c
6      implicit none
7c
8#include "ana_common.fh"
9c
10      character*16 sgmnam(msa)
11      integer isel(msa),iwsel(mwm),ndxw(nwm)
12      integer lfnxxx
13      real*8 xs(msa,3),qs(msa),xw(mwm,mwa,3)
14      character*255 filxxx
15      logical logs,logw
16      character*2 atom
17c
18      integer i,j,k,length
19c
20      if(me.eq.0) then
21c
22      length=index(filxxx,' ')-1
23      open(unit=lfnxxx,file=filxxx(1:length),form='formatted',
24     + status='unknown')
25c
26      rewind(lfnxxx)
27c
28      write(lfnxxx,1000) nsa
29 1000 format('* Coordinates in XYZ format',/,i5)
30      if(logs) then
31      do 1 i=1,nsa
32      if(isel(i).gt.0) then
33      atom=sgmnam(i)(6:7)
34      if(atom(1:1).eq.'1') atom(1:1)=' '
35      if(atom(1:1).eq.'2') atom(1:1)=' '
36      if(atom(1:1).eq.'3') atom(1:1)=' '
37      if(atom(1:1).eq.'4') atom(1:1)=' '
38      if(atom(1:1).eq.'5') atom(1:1)=' '
39      if(atom(1:1).eq.'6') atom(1:1)=' '
40      if(atom(1:1).eq.'7') atom(1:1)=' '
41      if(atom(1:1).eq.'8') atom(1:1)=' '
42      if(atom(1:1).eq.'9') atom(1:1)=' '
43      if(atom(1:1).eq.'0') atom(1:1)=' '
44      if(atom(1:1).eq.' ') atom=atom(2:2)//' '
45      write(lfnxxx,1001) atom,(1.0d1*xs(i,k),k=1,3)
46 1001 format(a2,3f12.6)
47      endif
48    1 continue
49      else
50      do 2 i=1,nsa
51      atom=sgmnam(i)(6:7)
52      if(atom(1:1).eq.'1') atom(1:1)=' '
53      if(atom(1:1).eq.'2') atom(1:1)=' '
54      if(atom(1:1).eq.'3') atom(1:1)=' '
55      if(atom(1:1).eq.'4') atom(1:1)=' '
56      if(atom(1:1).eq.'5') atom(1:1)=' '
57      if(atom(1:1).eq.'6') atom(1:1)=' '
58      if(atom(1:1).eq.'7') atom(1:1)=' '
59      if(atom(1:1).eq.'8') atom(1:1)=' '
60      if(atom(1:1).eq.'9') atom(1:1)=' '
61      if(atom(1:1).eq.'0') atom(1:1)=' '
62      if(atom(1:1).eq.' ') atom=atom(2:2)//' '
63      write(lfnxxx,1001) atom,(1.0d1*xs(i,k),k=1,3)
64    2 continue
65      endif
66c
67      if(logw) then
68      do 3 i=1,nwm
69      if(iwsel(i).ne.0) then
70      do 4 j=1,nwa
71      atom=wnam(j)(6:7)
72      if(atom(1:1).eq.'1') atom(1:1)=' '
73      if(atom(1:1).eq.'2') atom(1:1)=' '
74      if(atom(1:1).eq.'3') atom(1:1)=' '
75      if(atom(1:1).eq.'4') atom(1:1)=' '
76      if(atom(1:1).eq.'5') atom(1:1)=' '
77      if(atom(1:1).eq.'6') atom(1:1)=' '
78      if(atom(1:1).eq.'7') atom(1:1)=' '
79      if(atom(1:1).eq.'8') atom(1:1)=' '
80      if(atom(1:1).eq.'9') atom(1:1)=' '
81      if(atom(1:1).eq.'0') atom(1:1)=' '
82      if(atom(1:1).eq.' ') atom=atom(2:2)//' '
83      write(lfnxxx,1001) atom,(1.0d1*xw(i,j,k),k=1,3)
84    4 continue
85      endif
86    3 continue
87      endif
88c
89      close(unit=lfnxxx)
90c
91      length=index(filxxx,' ')-1
92      open(unit=lfnxxx,file=filxxx(1:length)//'q',form='formatted',
93     + status='unknown')
94c
95      rewind(lfnxxx)
96c
97      write(lfnxxx,1002) nsa,1,box
98 1002 format(i7,i3,3f12.6)
99      if(logs) then
100      do 5 i=1,nsa
101      if(isel(i).gt.0) then
102      atom=sgmnam(i)(6:7)
103      if(atom(1:1).eq.'1') atom(1:1)=' '
104      if(atom(1:1).eq.'2') atom(1:1)=' '
105      if(atom(1:1).eq.'3') atom(1:1)=' '
106      if(atom(1:1).eq.'4') atom(1:1)=' '
107      if(atom(1:1).eq.'5') atom(1:1)=' '
108      if(atom(1:1).eq.'6') atom(1:1)=' '
109      if(atom(1:1).eq.'7') atom(1:1)=' '
110      if(atom(1:1).eq.'8') atom(1:1)=' '
111      if(atom(1:1).eq.'9') atom(1:1)=' '
112      if(atom(1:1).eq.'0') atom(1:1)=' '
113      if(atom(1:1).eq.' ') atom=atom(2:2)//' '
114      write(lfnxxx,1003) atom,(1.0d1*xs(i,k),k=1,3),qs(i)
115 1003 format(a2,4f12.6)
116      endif
117    5 continue
118      else
119      do 6 i=1,nsa
120      atom=sgmnam(i)(6:7)
121      if(atom(1:1).eq.'1') atom(1:1)=' '
122      if(atom(1:1).eq.'2') atom(1:1)=' '
123      if(atom(1:1).eq.'3') atom(1:1)=' '
124      if(atom(1:1).eq.'4') atom(1:1)=' '
125      if(atom(1:1).eq.'5') atom(1:1)=' '
126      if(atom(1:1).eq.'6') atom(1:1)=' '
127      if(atom(1:1).eq.'7') atom(1:1)=' '
128      if(atom(1:1).eq.'8') atom(1:1)=' '
129      if(atom(1:1).eq.'9') atom(1:1)=' '
130      if(atom(1:1).eq.'0') atom(1:1)=' '
131      if(atom(1:1).eq.' ') atom=atom(2:2)//' '
132      write(lfnxxx,1003) atom,(1.0d1*xs(i,k),k=1,3),qs(i)
133    6 continue
134      endif
135c
136      close(unit=lfnxxx)
137c
138      endif
139c
140      return
141      end
142