1 /*
2
3 *****************************************************************************
4 * Author: *
5 * ------ *
6 * Anton Kokalj Email: Tone.Kokalj@ijs.si *
7 * Department of Physical and Organic Chemistry Phone: x 386 1 477 3523 *
8 * Jozef Stefan Institute Fax: x 386 1 477 3811 *
9 * Jamova 39, SI-1000 Ljubljana *
10 * SLOVENIA *
11 * *
12 * Source: $XCRYSDEN_TOPDIR/C/xcFractCoor.c
13 * ------ *
14 * Copyright (c) 1996-2003 by Anton Kokalj *
15 *****************************************************************************
16
17 */
18
19 #include <tk.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <math.h>
23 #include "xcGLparam.h"
24 #include "struct.h"
25 #include "xcfunc.h"
26
27 int XC_FractCoorCmd(ClientData clientData, Tcl_Interp *interp,
28 int argc, const char *argv[]);
29
30 /* ------------------------------------------------------------ *
31 * *
32 * xc_fractcoor -ctype prim|conv -coor {x y z} *
33 * *
34 * ------------------------------------------------------------ */
35 int
XC_FractCoorCmd(ClientData clientData,Tcl_Interp * interp,int argc,const char * argv[])36 XC_FractCoorCmd(ClientData clientData, Tcl_Interp *interp,
37 int argc, const char *argv[])
38 {
39 register int i;
40 double (*rvec)[4];
41 float frcoor[4];
42 char *result = Tcl_Alloc( sizeof(char) * 128);
43 GetComOption coor = { 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} };
45
46 if ( argc != 5 ) {
47 Tcl_SetResult(interp, "Usage: xc_fractcoor -ctype prim|coor -coor {x y z}", TCL_STATIC);
48 return TCL_ERROR;
49 }
50
51 for (i=1; i<argc; i+=2) {
52 if ( strcmp(argv[i], "-ctype") == 0 ) {
53 if ( strcmp(argv[i+1], "prim") == 0 )
54 rvec = vec.recprim;
55 else if ( strcmp(argv[i+1], "conv") == 0 )
56 rvec = vec.recconv;
57 else {
58 char rss[1024];
59 snprintf(rss, sizeof(rss), "unknown cell type %s, must be prim or conv",
60 argv[i+1]);
61 Tcl_SetResult(interp, rss, TCL_VOLATILE);
62 return TCL_ERROR;
63 }
64 }
65 else if ( strcmp(argv[i], "-coor") == 0 ) {
66 if ( !xcSplitList(XC_GET_XYZ, interp, &argv[i+1], &coor) ) {
67 char rss[1024];
68 snprintf(rss, sizeof(rss), "parse error; when parsing -coor {%s}; should be -coor {x y z}", argv[i+1]);
69 Tcl_SetResult(interp, rss, TCL_VOLATILE);
70 return TCL_ERROR;
71 }
72 }
73 else {
74 char rss[1024];
75 snprintf(rss, sizeof(rss),"unknown option %s, must be -ctype or -coor",
76 argv[i]);
77 Tcl_SetResult(interp, rss, TCL_VOLATILE);
78 return TCL_ERROR;
79 }
80 }
81
82 GetFractionalCoor(rvec, coor.vec, frcoor);
83
84 sprintf(result, "%f %f %f", frcoor[0], frcoor[1], frcoor[2]);
85 Tcl_SetResult(interp, result, TCL_DYNAMIC);
86 return TCL_OK;
87 }
88
89
90 void
GetFractionalCoor(double ivec[][4],float coor[4],float frcoor[])91 GetFractionalCoor(double ivec[][4], float coor[4], float frcoor[])
92 {
93 frcoor[0] = ivec[0][0]*coor[0] + ivec[0][1]*coor[1] + ivec[0][2]*coor[2];
94 frcoor[1] = ivec[1][0]*coor[0] + ivec[1][1]*coor[1] + ivec[1][2]*coor[2];
95 frcoor[2] = ivec[2][0]*coor[0] + ivec[2][1]*coor[1] + ivec[2][2]*coor[2];
96 }
97
98