/* Main function */ int main() { int my_func(char*, char*); char *girdi1, *girdi2; char *p_girdi1; char *p_girdi2; int donen1; /* Allocating memory for input entries */ girdi1=malloc(sizeof(char)*200); p_girdi1=girdi1; girdi2=malloc(sizeof(char)*200); p_girdi2=girdi2; /* Reading the input */ scanf("%s", girdi1); /* Dividing the input string into two */ while(*p_girdi1) { if(*p_girdi1=='#') { p_girdi1++; my_strcopy(p_girdi2, p_girdi1); p_girdi1--; *p_girdi1='\0'; } p_girdi1++; } /* Pointers for two strings */ p_girdi1=girdi1; p_girdi2=girdi2; /*Return value of algorithm */ donen1=my_func(p_girdi1,p_girdi2); /*Printing the result */ if(donen1==2 || donen1==1) printf("T\n"); else if(donen1==3 || donen1==0) printf("F\n"); else; /* printf("%s\n", p_girdi1); printf("%s\n", p_girdi2); */ return 0; }
SPARSE_MAT *sparsemat_sran_design(int number_of_units, int *group, SPARSE_MAT contrast) { SPARSE_MAT *res; double *values; int i,j; SPARSE_VEC *contrast_column; /* This subroutine constructs the columns of the design matrix correspdonding to the product random factor (that is, the factor obtained by \lq\lq multiplying together \rq\rq the individual factors in the product (see subroutine |product_random_factor| in file \lq\lq v2b.c \rq\rq)) of a particular block. On entry, |number_of_units| is the number of observations in the data; |*group| is a pointer which points at the beginning of a \lq column \rq of integers length |number_of_units| represening the levels of the product random factor. |contrast| is a |SPARSE_MAT| object representing the contrast matrix for the product random factor. If the random factor has $i$=|contrast.number_of_columns| $\times$ $j$=|contrast.number_of_rows| matrix with elements $c_{ij}$ and if the levels of the product random factor are $l_{1}, \ldtos l_{n}$, then the columns in the design matrix representing the product random factor are: \[ \left( */ res = Calloc(1,SPARSE_MAT); res->number_of_columns = contrast.number_of_columns; res->number_of_rows = number_of_units; res->offset = 0.0; res->columns = Calloc((res->number_of_columns) ,SPARSE_VEC *); if(!(res->columns)) goto noroom; values = Calloc(number_of_units, double); if (!(values)) goto noroom; for(i=0;i<res->number_of_columns;i++) { for(j=0;j<number_of_units;j++) { contrast_column = contrast.columns[i]; values[j] = sparse_el(contrast_column,group[j]); } res->columns[i] = sparse_vec(number_of_units,values); } Free(values); res->column_names = Calloc(res->number_of_columns, char *); if(contrast.column_names) { for(i=0;i<res->number_of_columns;i++) { res->column_names[i] = my_strcopy(contrast.column_names[i]); } } else { res->column_names = (char **) 0; } return res; noroom: fprintf(stderr, "*** sran_design *** dynamic storage overflow\n"); exit(1); }
/* Function for R4 */ int transformation4(char* trp_girdi1,char* trp_girdi2) { int my_func(char* girdi1, char* girdi2); char *bir_bas; char *p_bir; char *ilk_virgul; char *ikinci_virgul; char *kontrol; char *virgul; char *bolunen1; char *bolunen2; char *bolunen12; char *bolunen11; virgul=","; bir_bas=trp_girdi2; p_bir=bir_bas; bolunen1=calloc(200,sizeof(char)); bolunen2=calloc(200,sizeof(char)); bolunen11=calloc(200,sizeof(char)); bolunen12=calloc(200,sizeof(char)); my_strcopy(bolunen11,trp_girdi1); my_strcopy(bolunen12,trp_girdi1); while(*p_bir) { if(*p_bir=='&') { /* Locate the previous comma */ for(kontrol=p_bir;kontrol>=bir_bas;kontrol--) if(*kontrol==',' || kontrol==bir_bas ) { ilk_virgul=kontrol; break; } /*Locate the next comma */ for(kontrol=p_bir;;kontrol++) if(*kontrol==',' || *kontrol=='\0' ) { ikinci_virgul=kontrol; break; } /* Create the divided part I */ strncat(bolunen1, bir_bas,(ilk_virgul-bir_bas)); strcat(bolunen1, virgul); strncat(bolunen1,ilk_virgul+2,(p_bir-ilk_virgul-2)); strcat(bolunen1,ikinci_virgul); /* Create the divided part II */ strncat(bolunen2, bir_bas,(ilk_virgul-bir_bas)); strcat(bolunen2, virgul); strncat(bolunen2,p_bir+1,(ikinci_virgul-p_bir-2)); strcat(bolunen2,ikinci_virgul); /* Control for the divided parts */ /* printf("bolunen1: %s\n", bolunen1); printf("bolunen2: %s\n", bolunen2); */ if( (my_func(bolunen11,bolunen1) == 2 || my_func(bolunen11,bolunen1) == 1 ) && (my_func(bolunen12,bolunen2) == 2 || my_func(bolunen12,bolunen2) == 1) ) { return 1; } else { return 0; } break; } p_bir++; } return 0;}
/* Function for correcting double comma, double minus, etc. */ void duzeltme1(char* trp_girdi1, char* trp_girdi2) { char* birinci; char* birincip; char* ikincip; char *tasimali; tasimali=malloc(200*sizeof(char)); /* Adding comma to the beginning */ birinci=trp_girdi1; if(*birinci!=',' ) { my_strcopy(tasimali,trp_girdi1); trp_girdi1[0]=','; my_strcopy(trp_girdi1+1, tasimali); } /* Adding comma to the end */ birinci=trp_girdi1; for(;*birinci;birinci++) if(*birinci!=',' && *(birinci+1)=='\0') { *(birinci+1)= ','; *(birinci+2)= '\0'; break; } else; /* Removing double commas */ birinci=trp_girdi1; for(;*birinci;birinci++) { if(*birinci==',' && *(birinci+1)==',') for(birincip=birinci,ikincip=birinci+1; *ikincip ; ikincip++,birincip++) { *birincip=*ikincip; *ikincip='\0'; } } /* Removing double minus signs */ birinci=trp_girdi1; for(;*birinci;birinci++) { if(*birinci=='-' && *(birinci+1)=='-') for(birincip=birinci,ikincip=birinci+2; *ikincip ; ikincip++,birincip++) { *birincip=*ikincip; *ikincip='\0'; } } /* For string 2 */ /* Adding comma to the beginning */ birinci=trp_girdi2; if(*birinci!=',' ) { my_strcopy(tasimali,trp_girdi1); trp_girdi1[0]=','; my_strcopy(trp_girdi1+1, tasimali); } /* Adding comma to the end */ birinci=trp_girdi2; for(;*birinci;birinci++) if(*birinci!=',' && *(birinci+1)=='\0') { *(birinci+1)= ','; *(birinci+2)= '\0'; break; } else; /* Removing double comma */ birinci=trp_girdi2; for(;*birinci;birinci++) { if(*birinci==',' && *(birinci+1)==',') for(birincip=birinci,ikincip=birinci+1; *ikincip ; ikincip++,birincip++) { *birincip=*ikincip; *ikincip='\0'; } } /* Removing double minus signs */ birinci=trp_girdi2; for(;*birinci;birinci++) { if(*birinci=='-' && *(birinci+1)=='-') for(birincip=birinci,ikincip=birinci+2; *ikincip ; ikincip++,birincip++) { *birincip=*ikincip; *ikincip='\0'; } } }