source: tags/initial/GDE/LOOPTOOL/WriteData.c

Last change on this file was 2, checked in by oldcode, 24 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1
2#include <xview/xview.h>
3#include <xview/canvas.h>
4#include <stdio.h>
5#include <string.h>
6#include <malloc.h>
7#include "loop.h"
8#include "globals.h"
9
10SaveTemp()
11{
12        int i,j;
13        FILE *outfile;
14        Base base;
15       
16        outfile = fopen("loop.temp","w");
17        if(outfile == NULL)
18        {
19                fprintf(stderr,"Sorry, cannot open save file\n");
20                return;
21        }
22
23        for(i=0;i<seqlen;i++)
24        {
25                base = baselist[i];
26                fprintf(outfile,"index %d\n",base.rel_loc);
27                fprintf(outfile,"attr %d\n",base.attr);
28                fprintf(outfile,"size %d\n",base.size);
29                fprintf(outfile,"dir %d\n",base.dir);
30                if(base.label !=NULL)
31                        fprintf(outfile,"label %s\n",base.label->text);
32                if(base.dforw.pair != -1)
33                        fprintf(outfile,"distance %d %f\n",
34                        baselist[base.dforw.pair].rel_loc,base.dforw.dist);
35                if(base.posnum>0)
36                {
37                        fprintf(outfile,"positional %d\n",base.posnum);
38                        for(j=0;j<base.posnum;j++)
39                                fprintf(outfile,"%d %f %f\n",
40                                baselist[base.pos->pair].rel_loc,
41                                base.pos->dx,base.pos->dy);
42                }
43        }
44        fclose(outfile);
45        return;
46}
47
48ImposeTemp()
49{
50        int i,j,k,nxd,temp;
51        double x,y,ftemp;
52        char inlin[132];
53
54        for(;fgets(inlin,132,tempfile) != NULL;)
55        {
56                if(find("index",inlin))
57                {
58                        sscanf(inlin,"%*6c%d",&temp);
59                        nxd = ReltoAbs(temp);
60                }
61
62                else if(find("attr",inlin))
63                {
64                        sscanf(inlin,"%*5c%d",&temp);
65                        baselist[nxd].attr = temp;
66                }
67
68                else if(find("size",inlin))
69                {
70                        sscanf(inlin,"%*5c%d",&temp);
71                        baselist[nxd].size = temp;
72                }
73
74                else if(find("dir",inlin))
75                {
76                        sscanf(inlin,"%*4c%d",&temp);
77                        baselist[nxd].dir = temp;
78                }
79
80                else if(find("distance",inlin))
81                {
82                        sscanf(inlin,"%*9c%d %f",&temp,&ftemp);
83                        baselist[nxd].dforw.pair = ReltoAbs(temp);
84                        baselist[nxd].dforw.dist = ftemp;
85                }
86
87                else if(find("positional",inlin))
88                {
89                        sscanf(inlin,"%*11c%d",&k);
90                        for(j=0;j<k;j++)
91                        {
92                                baselist[nxd].posnum = -1;
93                                fscanf(tempfile,"%d %f %f",&temp,&x,&y);
94                                SetPos(nxd,ReltoAbs(temp),x,y);
95                        }
96                }
97        }
98        return;
99}
100
101
102ReltoAbs(ndx)
103int ndx;
104{
105        int i,j;
106        for(j=0;j<seqlen;j++)
107                if(baselist[j].rel_loc == ndx)
108                        return(j);
109        fprintf(stderr," Rel to Abs: not found in %d positions\n",seqlen);
110        return(-1);
111}
112
113find(a,b)
114char *a,*b;
115{
116        int i,j,len1,len2,dif,flag = FALSE;
117
118        dif = (len2 = strlen(b)) - (len1 = strlen(a));
119
120        for(j=0;j<dif && flag == FALSE;j++)
121        {
122                flag = TRUE;
123                for(i=0;i<len1 && flag;i++)
124                        flag = (a[i] == b[i+j])?TRUE:FALSE;
125
126        }
127        return(flag);
128}
Note: See TracBrowser for help on using the repository browser.