JPRED-2 Add sources of all binaries (except alscript) to Git
[jpred.git] / sources / ncoils / read_matrix.c
1 #include <ncoils.h>
2
3
4 struct hept_pref *read_matrix(FILE *IN) {
5
6         int i,j;
7         int pt,aa_len;
8         int win;
9
10         float m_g,sd_g,m_cc,sd_cc,sc;
11         float hept[7];
12
13         char buff[1000],junk[1000];
14
15         struct hept_pref *h;
16
17         aa_len = strlen(AAs);
18
19         h = (struct hept_pref*)malloc(sizeof(struct hept_pref));
20
21         h->m = (float**)malloc(aa_len*sizeof(float*));
22         for(i=0; i<aa_len; ++i) {
23                 h->m[i]=(float*)malloc(7*sizeof(float));
24                 for(j=0; j<7; ++j) {
25                         h->m[i][j]=-1;
26                 }
27         }
28         h->f = (struct fit_dat*)malloc(sizeof(struct fit_dat));
29         h->n = 0;
30         h->smallest=1.0;
31
32         while(fgets(buff,999,IN)!=NULL) {
33                 if(buff[0]!='%') {
34                    if((strncmp(buff,"uw ",3)==0) || (strncmp(buff,"w ",2)==0)) {
35                         i = h->n;
36                         if(strncmp(buff,"uw ",3)==0) { h->f[i].w=0; }
37                         else { h->f[i].w=1; }
38                         sscanf(buff,"%s %d %f %f %f %f %f",
39                                 &junk[0],&win,&m_cc,&sd_cc,&m_g,&sd_g,&sc);
40                                 h->f[i].win   = win;
41                                 h->f[i].m_cc  = (float)m_cc; 
42                                 h->f[i].sd_cc = (float)sd_cc;
43                                 h->f[i].m_g   = (float)m_g;
44                                 h->f[i].sd_g  = (float)sd_g;
45                                 h->f[i].sc    = (float)sc;
46                         h->n++;
47                         h->f = (struct fit_dat*)realloc(h->f,((h->n)+1)*sizeof(struct fit_dat)); 
48                         if((h->n)>=9) { 
49                                 fprintf(stderr,"Error: too many window parms in matrix file\n");
50                                 exit(-1);
51                         }
52                     } else if(buff[0]>='A' && buff[0]<='Z') { /* AA data */
53                         pt = (int)(buff[0]-'A');
54                         if(h->m[pt][0]==-1) {
55                                 sscanf(buff,"%s%f%f%f%f%f%f%f",
56                                         &junk[0],
57                                         &hept[0],&hept[1],&hept[2],&hept[3],&hept[4],
58                                         &hept[5],&hept[6]);
59                                 for(i=0; i<7; ++i) {
60                                         h->m[pt][i] = (float)hept[i];
61                                         if(h->m[pt][i]>0) {
62                                                 if(h->m[pt][i]<h->smallest) { h->smallest = h->m[pt][i]; }
63                                         } else {
64                                                 h->m[pt][i]=-1; /* Don't permit zero values */
65                                         }
66                                 }
67 /*                              printf("AA %c %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f\n",buff[0],
68                                         h->m[pt][0],h->m[pt][1],h->m[pt][2],h->m[pt][3],h->m[pt][4],
69                                         h->m[pt][5],h->m[pt][6]);
70 */
71
72                         } else {
73                                 fprintf(stderr,"Warning: multiple entries for AA %c in matrix file\n",buff[0]);
74                         }
75                     } else {
76                         fprintf(stderr,"Warning: strange characters in matrix file\n");
77                         fprintf(stderr,"Ignoring line: %s",buff);
78                     }
79                 }
80         }
81         return h;
82 }
83