9d0f5a2ca85b76092d0931292dc2388a1e8e0b31
[physik/posic.git] / visual / visual.c
1 /*
2  * visual.c - visualization functions
3  *
4  * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
5  *
6  */
7
8 #define _GNU_SOURCE
9 #include <stdio.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <fcntl.h>
13 #include <unistd.h>
14 #include <string.h>
15
16 #include "visual.h"
17 #include "../moldyn.h"
18 #include "../math/math.h"
19
20 int visual_init(t_visual *v,char *filebase) {
21
22         char file[128+8];
23
24         strncpy(v->fb,filebase,128);
25         memset(file,0,128+8);
26         sprintf(file,"%s.scr",v->fb);
27
28         v->fd=open(file,O_WRONLY|O_CREAT|O_TRUNC);
29         if(v->fd<0) {
30                 perror("open visual fd");
31                 return -1;
32         }
33
34         return 0;
35 }
36
37 int visual_tini(t_visual *v) {
38
39         if(v->fd) close(v->fd);
40
41         return 0;
42 }
43
44 int visual_atoms(t_visual *v,double time,t_atom *atom,int n) {
45
46         int i,fd;
47         char file[128+64];
48
49         char pse[19][4]={
50                 "foo",
51                 "H",
52                 "He",
53                 "Li",
54                 "Be",
55                 "B",
56                 "C",
57                 "N",
58                 "O",
59                 "F",
60                 "Ne",
61                 "Na",
62                 "Mg",
63                 "Al",
64                 "Si",
65                 "P",
66                 "S",
67                 "Cl",
68                 "Ar",
69         };
70
71         sprintf(file,"%s-%.15f.xyz",v->fb,time);
72         fd=open(file,O_WRONLY|O_CREAT|O_TRUNC);
73         if(fd<0) {
74                 perror("open visual save file fd");
75                 return -1;
76         }
77
78         /* script file update */
79         dprintf(v->fd,"load xyz %s\n",file);
80         dprintf(v->fd,"spacefill 200\n");
81         //dprintf(v->fd,"rotate x 100\n");
82         //dprintf(v->fd,"rotate y 10\n");
83         dprintf(v->fd,"set ambient 20\n");
84         dprintf(v->fd,"set specular on\n");
85         sprintf(file,"%s-%.15f.ppm",v->fb,time);
86         dprintf(v->fd,"write ppm %s\n",file);
87         dprintf(v->fd,"zap\n");
88
89         /* write the actual data file */
90         dprintf(fd,"%d\n",n);
91         dprintf(fd,"atoms at time %.15f\n",time);
92         for(i=0;i<n;i++)
93                 dprintf(fd,"%s %f %f %f\n",pse[atom[i].element],
94                                            atom[i].r.x,atom[i].r.y,atom[i].r.z);
95         close(fd);
96
97         return 0;
98 }
99