initial checkin of the new concept approach
[physik/posic.git] / visual / visual.c
diff --git a/visual/visual.c b/visual/visual.c
new file mode 100644 (file)
index 0000000..6ad527a
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * visual.c - visualization functions
+ *
+ * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "visual.h"
+#include "../moldyn.h"
+#include "../math/math.h"
+
+int visual_init(t_visual *v,char *filebase) {
+
+       char file[128+8];
+
+       strncpy(v->fb,filebase,128);
+       memset(file,0,128+8);
+       sprintf(file,"%s.scr",v->fb);
+
+       v->fd=open(file,O_WRONLY);
+       if(v->fd<0) {
+               perror("open visual fd");
+               return -1;
+       }
+
+       return 0;
+}
+
+int visual_tini(t_visual *v) {
+
+       if(v->fd) close(v->fd);
+
+       return 0;
+}
+
+int visual_atoms(t_visual *v,double time,t_atom *atom,int n) {
+
+       int i,fd;
+       char file[128+64];
+
+       char pse[19][4]={
+               "foo",
+               "H",
+               "He",
+               "Li",
+               "Be",
+               "B",
+               "C",
+               "N",
+               "O",
+               "F",
+               "Ne",
+               "Na",
+               "Mg",
+               "Al",
+               "Si",
+               "P",
+               "S",
+               "Cl",
+               "Ar",
+       };
+
+       sprintf(file,"%s-%.15f.xyz",v->fb,time);
+       fd=open(file,O_WRONLY);
+       if(fd<0) {
+               perror("open visual save file fd");
+               return -1;
+       }
+
+       /* script file update */
+       dprintf(v->fd,"load xyz %s\n",file);
+       dprintf(v->fd,"spacefill 200\n");
+       dprintf(v->fd,"rotate x 11\n");
+       dprintf(v->fd,"rotate y 13\n");
+       dprintf(v->fd,"set ambient 20\n");
+       dprintf(v->fd,"set specular on\n");
+       sprintf(file,"%s-%.15f.ppm",v->fb,time);
+       dprintf(v->fd,"write ppm %s\n",file);
+       dprintf(v->fd,"zap\n");
+
+       /* write the actual data file */
+       dprintf(fd,"Atoms at time %.15f\n",time);
+       dprintf(fd,"%d\n",n);
+       for(i=0;i<n;i++)
+               dprintf(fd,"%s %f %f %f\n",pse[atom[i].element],
+                                          atom[i].r.x,atom[i].r.y,atom[i].r.z);
+       close(fd);
+
+       return 0;
+}
+