File: templ.c

package info (click to toggle)
chemtool 1.5-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,036 kB
  • ctags: 2,117
  • sloc: ansic: 31,960; pascal: 825; sh: 153; makefile: 90
file content (110 lines) | stat: -rw-r--r-- 2,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char**argv)
/* dumps a chemtool drawing file in the format used in templates.h */
{
  int d, nb,na;
  int w,h;
  int x[50], y[50] , tx[50], ty[50], xl[50],yl[50],dl[50],b[50];
  char tl[50][50];
  char str[255], str1[255];
  FILE *fpin,*fpout;
  char version[10];
  char filename[100];
  
  if (argc==2) strcpy(filename,argv[1]);

  if ((fpin = fopen (filename, "r")) == NULL)
    return (1);
    strcat(filename,".tmpl");
  if ((fpout = fopen (filename, "w")) == NULL)
    return (1);

  fscanf (fpin, "%s %s %s", str, str1, version);
  if (strcmp (str, "Chemtool") || strcmp (str1, "Version"))
    exit(2);
fprintf(stderr,"%s %s %s\n",str,str1,version); 
  fscanf (fpin, "%s %i %i", str, &w,&h);

  fscanf (fpin, "%s %i", str, &nb);
  if (!strcmp (str, "bonds") || !strcmp (str, "bounds"))
    {				/* typo in versions < 1.1.2 */
	fprintf(stderr,"%d bonds\n",nb);
      for (d = 0; d < nb; d++)
	{
	  fscanf (fpin, "%i %i %i %i %i", &x[d]  , &y[d], &tx[d], &ty[d] , &b[d]);
	}
    }
fprintf(stderr,"bonds ok\n"); 
  fscanf (fpin, "%s %i", str, &na);
  if (!strcmp (str, "atoms"))
    {
    fprintf(stderr,"%d atoms\n",na);
      for (d = 0; d < na; d++)
	{
	  fscanf (fpin, "%i %i %s %i", &xl[d], &yl[d], tl[d], &dl[d]);
	}
    }
fprintf(stderr,"atoms ok\n");
/*
  fscanf (fpin, "%s %i", str, &ns);
  if (!strcmp (str, "splines"))
    {
      for (d = 0; d < ns; d++)
	{
	  fscanf (fpin, "%i %i %i %i %i %i %i %i %i", &x, &y, &tx, &ty,
	  &x2, &y2, &x3, &y3, &b);
	  add_spline (x, y, tx, ty, x2, y2, x3, y3, b, 0);
	}
    }
*/
  fclose (fpin);
	fprintf(fpout,"bonds:%d\n",nb);
	fprintf(fpout,"atoms:%d\n",na);
if (nb>0){
	fprintf(fpout,"{");
	for (d=0;d<nb-1;d++)
	fprintf(fpout,"%d,",x[d]);
	fprintf(fpout,"%d}\n",x[nb-1]);
	fprintf(fpout,"{");
	for (d=0;d<nb-1;d++)
	fprintf(fpout,"%d,",y[d]);
	fprintf(fpout,"%d}\n",y[nb-1]);
	fprintf(fpout,"{");
	for (d=0;d<nb-1;d++)
	fprintf(fpout,"%d,",tx[d]);
	fprintf(fpout,"%d}\n",tx[nb-1]);
	fprintf(fpout,"{");
	for (d=0;d<nb-1;d++)
	fprintf(fpout,"%d,",ty[d]);
	fprintf(fpout,"%d}\n",ty[nb-1]);
	fprintf(fpout,"{");
	for (d=0;d<nb-1;d++)
	fprintf(fpout,"%d,",b[d]);
	fprintf(fpout,"%d}\n",b[nb-1]);
}

if (na>0){	
	fprintf(fpout,"{");
	for (d=0;d<na-1;d++)
	fprintf(fpout,"%d,",xl[d]);
	fprintf(fpout,"%d}\n",xl[na-1]);
	fprintf(fpout,"{");
	for (d=0;d<na-1;d++)
	fprintf(fpout,"%d,",yl[d]);
	fprintf(fpout,"%d}\n",yl[na-1]);
	fprintf(fpout,"{");
	for (d=0;d<na-1;d++)
	fprintf(fpout,"%d,",dl[d]);
	fprintf(fpout,"%d}\n",dl[na-1]);
	fprintf(fpout,"{");
	for (d=0;d<na-1;d++)
	fprintf(fpout,"\"%s\",",tl[d]);
	fprintf(fpout,"\"%s\"}\n",tl[na-1]);
}

fclose(fpout);
exit(0);
}