File: read_matrix.c

package info (click to toggle)
gentle 1.9%2Bcvs20100605%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze
  • size: 12,264 kB
  • ctags: 5,235
  • sloc: cpp: 41,571; ansic: 3,978; sh: 1,420; makefile: 291
file content (83 lines) | stat: -rw-r--r-- 2,132 bytes parent folder | download | duplicates (8)
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
#include <ncoils.h>


struct hept_pref *read_matrix(FILE *IN) {

	int i,j;
	int pt,aa_len;
	int win;

	float m_g,sd_g,m_cc,sd_cc,sc;
	float hept[7];

	char buff[1000],junk[1000];

	struct hept_pref *h;

	aa_len = strlen(AAs);

	h = (struct hept_pref*)malloc(sizeof(struct hept_pref));

	h->m = (float**)malloc(aa_len*sizeof(float*));
	for(i=0; i<aa_len; ++i) {
		h->m[i]=(float*)malloc(7*sizeof(float));
		for(j=0; j<7; ++j) {
			h->m[i][j]=-1;
		}
	}
	h->f = (struct fit_dat*)malloc(sizeof(struct fit_dat));
	h->n = 0;
	h->smallest=1.0;

	while(fgets(buff,999,IN)!=NULL) {
		if(buff[0]!='%') {
		   if((strncmp(buff,"uw ",3)==0) || (strncmp(buff,"w ",2)==0)) {
			i = h->n;
		        if(strncmp(buff,"uw ",3)==0) { h->f[i].w=0; }
			else { h->f[i].w=1; }
			sscanf(buff,"%s %d %f %f %f %f %f",
				&junk[0],&win,&m_cc,&sd_cc,&m_g,&sd_g,&sc);
				h->f[i].win   = win;
				h->f[i].m_cc  = (float)m_cc; 
				h->f[i].sd_cc = (float)sd_cc;
				h->f[i].m_g   = (float)m_g;
				h->f[i].sd_g  = (float)sd_g;
				h->f[i].sc    = (float)sc;
			h->n++;
			h->f = (struct fit_dat*)realloc(h->f,((h->n)+1)*sizeof(struct fit_dat)); 
			if((h->n)>=9) { 
				fprintf(stderr,"Error: too many window parms in matrix file\n");
				exit(-1);
			}
		    } else if(buff[0]>='A' && buff[0]<='Z') { /* AA data */
			pt = (int)(buff[0]-'A');
			if(h->m[pt][0]==-1) {
				sscanf(buff,"%s%f%f%f%f%f%f%f",
					&junk[0],
					&hept[0],&hept[1],&hept[2],&hept[3],&hept[4],
					&hept[5],&hept[6]);
				for(i=0; i<7; ++i) {
					h->m[pt][i] = (float)hept[i];
					if(h->m[pt][i]>0) {
						if(h->m[pt][i]<h->smallest) { h->smallest = h->m[pt][i]; }
					} else {
						h->m[pt][i]=-1; /* Don't permit zero values */
					}
				}
/*				printf("AA %c %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f\n",buff[0],
					h->m[pt][0],h->m[pt][1],h->m[pt][2],h->m[pt][3],h->m[pt][4],
					h->m[pt][5],h->m[pt][6]);
*/

			} else {
				fprintf(stderr,"Warning: multiple entries for AA %c in matrix file\n",buff[0]);
			}
		    } else {
			fprintf(stderr,"Warning: strange characters in matrix file\n");
			fprintf(stderr,"Ignoring line: %s",buff);
		    }
		}
	}
	return h;
}