• R/O
  • SSH
  • HTTPS

p-svm: Commit


Commit MetaInfo

Revision32 (tree)
Zeit2014-02-05 11:13:58
Autorkanai7310

Log Message

とりあえず

Ändern Zusammenfassung

Diff

--- src/IO.c (revision 31)
+++ src/IO.c (revision 32)
@@ -62,6 +62,178 @@
6262 free(line);
6363 }
6464
65+void analysis_ef_(char *input_file, int *NS, int *NN, int *MM, int *fmt)
66+{
67+ char *p,*rr[9];
68+ int i,n_data=0,n_dim;
69+
70+ line=(char*)malloc(LMAX);
71+
72+ p=strtok(input_file," ");
73+ if (p == NULL) p=input_file;
74+ fp=fopen(p,"r");
75+ if (fp == NULL) {
76+ fprintf(stderr,"%s : file open error!\n",p);
77+ exit(EXIT_FAILURE);
78+ }
79+
80+ fgets(line,LMAX,fp);
81+ p=strtok(NULL,"/");
82+ i=0;
83+ while ((p=strtok(NULL,"/")) != NULL) {
84+ if (strchr(p,':') != NULL) fmt[i]=1;
85+ else fmt[i]=0;
86+ i++;
87+ }
88+ if (i == 0 || i > 3) {
89+ fprintf(stderr,"format error !\n");
90+ exit(EXIT_FAILURE);
91+ }
92+ *NS=i;
93+
94+ rewind(fp);
95+
96+ for (i=0;i<3;i++) MM[i]=0;
97+ while (fgets(line,LMAX,fp) != NULL) {
98+ strtok(line,"\r\n");
99+ n_data++;
100+ p=strtok(line,"/");
101+ i=0;
102+ while ((p=strtok(NULL,"/")) != NULL) {
103+ rr[i]=p;
104+ i++;
105+ }
106+ for (i=0;i<*NS;i++) {
107+ if ((p=strtok(rr[i]," ")) != NULL) {
108+ n_dim=1;
109+ }
110+ else exit(EXIT_FAILURE);
111+ while ((p=strtok(NULL," ")) != NULL) n_dim++;
112+ if (n_dim > MM[i]) MM[i]=n_dim;
113+ }
114+ }
115+
116+ *NN=n_data;
117+ for (i=0;i<*NS;i++) {
118+ if (fmt[i] == 1) MM[i]=MM[i]+1;
119+ }
120+
121+ fclose(fp);
122+ free(line);
123+}
124+
125+void read_ef_(char *input_file, int *NS, int *NN, int *MM, int *fmt, double *y,
126+ double *x1, int *pt1, int *nd1,
127+ double *x2, int *pt2, int *nd2,
128+ double *x3, int *pt3, int *nd3)
129+{
130+ char *p,*q,*rr[9];
131+ int *tpt;
132+ double *tx;
133+ int i,j,n;
134+
135+ line=(char*)malloc(LMAX);
136+
137+ p=strtok(input_file," ");
138+ if (p == NULL) p=input_file;
139+ fp=fopen(p,"r");
140+
141+ while (fgets(line,LMAX,fp) != NULL) {
142+ strtok(line,"\r\n");
143+ p=strtok(line,"/");
144+ *y=atof(p); y++;
145+
146+ for (i=0;i<*NS;i++) {
147+ p=strtok(NULL,"/");
148+ rr[i]=p;
149+ }
150+
151+ tx=x1; tpt=pt1;
152+ if (fmt[0] == 0) {
153+ p=strtok(rr[0]," ");
154+ *x1=atof(p);
155+ x1++;
156+ while ((p=strtok(NULL," ")) != NULL) {
157+ *x1=atof(p); x1++;
158+ }
159+ x1=tx+MM[0];
160+ }
161+ else if (fmt[0] == 1) {
162+ p=strtok(rr[0]," ");
163+ q=strchr(p,':'); *q='\0'; q++;
164+ *pt1=atoi(p); pt1++;
165+ *x1=atof(q); x1++;
166+ n=1;
167+ while ((p=strtok(NULL," ")) != NULL) {
168+ q=strchr(p,':'); *q='\0'; q++;
169+ *pt1=atoi(p); pt1++;
170+ *x1=atof(q); x1++;
171+ n++;
172+ }
173+ *nd1=n; nd1++;
174+ x1=tx+MM[0]; pt1=tpt+MM[0];
175+ }
176+ if (*NS == 1) continue;
177+
178+ tx=x2; tpt=pt2;
179+ if (fmt[1] == 0) {
180+ p=strtok(rr[1]," ");
181+ *x2=atof(p);
182+ x2++;
183+ while ((p=strtok(NULL," ")) != NULL) {
184+ *x2=atof(p); x2++;
185+ }
186+ x2=tx+MM[1];
187+ }
188+ else if (fmt[1] == 1) {
189+ p=strtok(rr[1]," ");
190+ q=strchr(p,':'); *q='\0'; q++;
191+ *pt2=atoi(p); pt2++;
192+ *x2=atof(q); x2++;
193+ n=1;
194+ while ((p=strtok(NULL," ")) != NULL) {
195+ q=strchr(p,':'); *q='\0'; q++;
196+ *pt2=atoi(p); pt2++;
197+ *x2=atof(q); x2++;
198+ n++;
199+ }
200+ *nd2=n; nd2++;
201+ x2=tx+MM[1]; pt2=tpt+MM[1];
202+ }
203+ if (*NS == 2) continue;
204+
205+ tx=x3; tpt=pt3;
206+ if (fmt[2] == 0) {
207+ p=strtok(rr[2]," ");
208+ *x3=atof(p);
209+ x3++;
210+ while ((p=strtok(NULL," ")) != NULL) {
211+ *x3=atof(p); x3++;
212+ }
213+ x3=tx+MM[2];
214+ }
215+ else if (fmt[2] == 1) {
216+ p=strtok(rr[2]," ");
217+ q=strchr(p,':'); *q='\0'; q++;
218+ *pt3=atoi(p); pt3++;
219+ *x3=atof(q); x3++;
220+ n=1;
221+ while ((p=strtok(NULL," ")) != NULL) {
222+ q=strchr(p,':'); *q='\0'; q++;
223+ *pt3=atoi(p); pt3++;
224+ *x3=atof(q); x3++;
225+ n++;
226+ }
227+ *nd3=n; nd3++;
228+ x3=tx+MM[0]; pt3=tpt+MM[0];
229+ }
230+
231+ }
232+
233+ fclose(fp);
234+ free(line);
235+}
236+
65237 void read_df_(char *input_file, double *y, double *x)
66238 {
67239 char *p;
Show on old repository browser