1 #define PI            3.1415926535897932384626
2 
3 #include <stdio.h>
4 #include <math.h>
5 #include <stdlib.h>
6 #include <string.h>
7 
8 void fnjoint();
9 void chcp();
10 double sgn();
11 void ATV(double atvx[15],double atvy[15], double atvz[15],
12          double tvx[5],double tvy[5],double tvz[5]);
13 
main()14 main()
15 {
16   static int atomnum,n,i,j,k,l,m,i1,i2,j1,j2;
17   static double za0,za1,za2,za3;
18   static double ka1,ka2,ka3,al,be,ga,c1,c2,c3,s2,s3;
19   static double **xyz,rxyz[10],tvxyz[5][4];
20   static double tvx[5],tvy[5],tvz[5];
21   static double atvx[15],atvy[15],atvz[15];
22   static double la1,la2,la3,ang1,ang2,ang3;
23   static double r,dx,dy,dz;
24   static char Name[100];
25 
26  /*-----------  input data  ------------------------------------*/
27 
28   scanf("%lf %lf %lf",&la1,&la2,&la3);
29   scanf("%lf %lf %lf",&ang1,&ang2,&ang3);
30   scanf("%i",&atomnum);
31 
32   xyz = (double**)malloc(sizeof(double*)*(atomnum+1));
33   for (i=0; i<=atomnum; i++){
34     xyz[i] = (double*)malloc(sizeof(double)*4);
35   }
36 
37   ang1 = PI*ang1/180.0;
38   ang2 = PI*ang2/180.0;
39   ang3 = PI*ang3/180.0;
40 
41   tvx[1] = la1*cos(ang2);
42   tvz[1] = (la1*cos(ang3)-tvx[1]*cos(ang1))/sin(ang1);
43   tvy[1] = sqrt(la1*la1-tvx[1]*tvx[1]-tvz[1]*tvz[1]);
44   tvx[2] = la2*cos(ang1);
45   tvy[2] = 0;
46   tvz[2] = la2*sin(ang1);
47   tvx[3] = la3;
48   tvy[3] = 0;
49   tvz[3] = 0;
50 
51   ATV(atvx,atvy,atvz,tvx,tvy,tvz);
52 
53   for (i=1; i<=atomnum; i++){
54     scanf("%lf  %s %lf %lf %lf",&za0,&Name,&za1,&za2,&za3);
55     xyz[i][0] = za0;
56     xyz[i][1] = za1*tvx[1] + za2*tvx[2] + za3*tvx[3];
57     xyz[i][2] = za1*tvy[1] + za2*tvy[2] + za3*tvy[3];
58     xyz[i][3] = za1*tvz[1] + za2*tvz[2] + za3*tvz[3];
59     printf("%4d   %3s %16.12f  %16.12f  %16.12f\n",
60              i,Name,xyz[i][1],xyz[i][2],xyz[i][3]);
61   }
62 
63   /***************************
64    distance between two atoms
65   ***************************/
66 
67   /*
68   for (i=1; i<=atomnum; i++){
69     for (j=1; j<=atomnum; j++){
70       if (i!=j){
71         dx = xyz[i][1] - xyz[j][1];
72         dy = xyz[i][2] - xyz[j][2];
73         dz = xyz[i][3] - xyz[j][3];
74         r = sqrt(dx*dx + dy*dy + dz*dz);
75         printf("Atoms %4d and %4d   R=%15.12f\n",i,j,r);
76       }
77     }
78   }
79   */
80 
81   /* freeing of array */
82   for (i=0; i<=atomnum; i++){
83     free(xyz[i]);
84   }
85   free(xyz);
86 }
87 
ATV(double atvx[15],double atvy[15],double atvz[15],double tvx[5],double tvy[5],double tvz[5])88 void ATV(double atvx[15],double atvy[15], double atvz[15],
89          double tvx[5],double tvy[5],double tvz[5])
90 
91 {
92 
93   atvx[0] = 0;
94   atvy[0] = 0;
95   atvz[0] = 0;
96   atvx[1] = tvx[1];
97   atvy[1] = tvy[1];
98   atvz[1] = tvz[1];
99   atvx[2] = tvx[2];
100   atvy[2] = tvy[2];
101   atvz[2] = tvz[2];
102   atvx[3] = tvx[3];
103   atvy[3] = tvy[3];
104   atvz[3] = tvz[3];
105   atvx[4] = tvx[1] + tvx[3];
106   atvy[4] = tvy[1] + tvy[3];
107   atvz[4] = tvz[1] + tvz[3];
108   atvx[5] = tvx[1] - tvx[3];
109   atvy[5] = tvy[1] - tvy[3];
110   atvz[5] = tvz[1] - tvz[3];
111   atvx[6] = tvx[1] + tvx[2];
112   atvy[6] = tvy[1] + tvy[2];
113   atvz[6] = tvz[1] + tvz[2];
114   atvx[7] = tvx[1] - tvx[2];
115   atvy[7] = tvy[1] - tvy[2];
116   atvz[7] = tvz[1] - tvz[2];
117   atvx[8] = tvx[2] + tvx[3];
118   atvy[8] = tvy[2] + tvy[3];
119   atvz[8] = tvz[2] + tvz[3];
120   atvx[9] = tvx[2] - tvx[3];
121   atvy[9] = tvy[2] - tvy[3];
122   atvz[9] = tvz[2] - tvz[3];
123   atvx[10] = tvx[1] + tvx[2] + tvx[3];
124   atvy[10] = tvy[1] + tvy[2] + tvy[3];
125   atvz[10] = tvz[1] + tvz[2] + tvz[3];
126   atvx[11] = -tvx[1] + tvx[2] + tvx[3];
127   atvy[11] = -tvy[1] + tvy[2] + tvy[3];
128   atvz[11] = -tvz[1] + tvz[2] + tvz[3];
129   atvx[12] = tvx[1] - tvx[2] + tvx[3];
130   atvy[12] = tvy[1] - tvy[2] + tvy[3];
131   atvz[12] = tvz[1] - tvz[2] + tvz[3];
132   atvx[13] = tvx[1] + tvx[2] - tvx[3];
133   atvy[13] = tvy[1] + tvy[2] - tvy[3];
134   atvz[13] = tvz[1] + tvz[2] - tvz[3];
135 
136 }
137 
138 
fnjoint(char name1[100],char name2[100],char name3[100])139 void fnjoint(char name1[100],char name2[100],char name3[100])
140 {
141  static char name4[100];
142 	char *f1 = name1,
143 	     *f2 = name2,
144 	     *f3 = name3,
145 	     *f4 = name4;
146 
147    while(*f1)
148     {
149      *f4 = *f1;
150      *f1++;
151      *f4++;
152     }
153    while(*f2)
154     {
155      *f4 = *f2;
156      *f2++;
157      *f4++;
158     }
159    while(*f3)
160     {
161      *f4 = *f3;
162      *f3++;
163      *f4++;
164     }
165     *f4 = *f3;
166     chcp(name3,name4);
167 }
168 
chcp(char name1[100],char name2[100])169 void chcp(char name1[100],char name2[100])
170 {
171 	  char *f1 = name1,
172 	       *f2 = name2;
173 
174    while(*f2)
175     {
176      *f1 = *f2;
177      *f1++;
178      *f2++;
179     }
180     *f1 = *f2;
181 }
182 
183 
sgn(double nu)184 double sgn(double nu)
185  {
186  double result;
187   if (nu<0)
188     result = -1;
189    else
190     result = 1;
191   return result;
192  }
193 
194