int dfreerdp_run(freerdp* instance) { int i; int fds; int max_fds; int rcount; int wcount; void* rfds[32]; void* wfds[32]; fd_set rfds_set; fd_set wfds_set; dfInfo* dfi; dfContext* context; rdpChannels* channels; ZeroMemory(rfds, sizeof(rfds)); ZeroMemory(wfds, sizeof(wfds)); if (!freerdp_connect(instance)) return 0; context = (dfContext*) instance->context; dfi = context->dfi; channels = instance->context->channels; while (1) { rcount = 0; wcount = 0; if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) { fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); break; } if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != TRUE) { fprintf(stderr, "Failed to get channel manager file descriptor\n"); break; } if (df_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) { fprintf(stderr, "Failed to get dfreerdp file descriptor\n"); break; } max_fds = 0; FD_ZERO(&rfds_set); FD_ZERO(&wfds_set); for (i = 0; i < rcount; i++) { fds = (int)(long)(rfds[i]); if (fds > max_fds) max_fds = fds; FD_SET(fds, &rfds_set); } if (max_fds == 0) break; if (select(max_fds + 1, &rfds_set, &wfds_set, NULL, NULL) == -1) { /* these are not really errors */ if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { fprintf(stderr, "dfreerdp_run: select failed\n"); break; } } if (freerdp_check_fds(instance) != TRUE) { fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); break; } if (df_check_fds(instance, &rfds_set) != TRUE) { fprintf(stderr, "Failed to check dfreerdp file descriptor\n"); break; } if (freerdp_channels_check_fds(channels, instance) != TRUE) { fprintf(stderr, "Failed to check channel manager file descriptor\n"); break; } df_process_channel_event(channels, instance); } freerdp_channels_close(channels, instance); freerdp_channels_free(channels); df_free(dfi); gdi_free(instance); freerdp_disconnect(instance); freerdp_free(instance); return 0; }
int main(int argc, char* argv[]) { int i,n, status; char* datafile, *treefile, *taxacolumn; PhyAnimal model; DataFrame *df; PhyTreeList *treelist; double lh; pm_rng *rng; DenseVector *v,*v2; mc2_animal mc2; /* test random number generator */ /* rng = pm_rng_new(pm_rng_default); v = dense_vector_new(30); dense_vector_print(v,stdout); dense_vector_ran_gaussian(v,rng,5,1); printf("done\n"); dense_vector_print(v,stdout); exit(0); v2 = dense_vector_new(15); dense_vector_copy_idx(v2,2,v,0, 100); printf("\n"); dense_vector_print(v2,stdout); */ /*Dense *A, *B; A = dense_new(4,3); B = dense_new(3,4); dense_set_diag(A,2); dense_print(A,stdout); if (dense_copy_trans(B,A)!=0) { printf("wrong arguments \n"); exit(0); } dense_print(B,stdout); */ if (argc < 5) { printf("Insufficient number of arguments\n"); printf("Syntax: <DataFile> <TreeFile> y x1 x2 x3 taxaColumn\n"); exit(EXIT_FAILURE); } datafile = argv[1]; treefile = argv[2]; taxacolumn = argv[argc-1]; printf("Data %s Tree %s\n",datafile,treefile); if(argc == 5) { model = phyanimal_new(&argv[3],1,NULL,0); } else { model = phyanimal_new(&argv[3],1,&argv[4],argc-5); } if (model == NULL) { pm_error_print(NULL,stdout); exit(EXIT_FAILURE); } phyanimal_print(model,stdout); /* Read DataFrame */ df = df_load_new(datafile); if (df == NULL) { pm_error_print(NULL,stdout); exit(EXIT_FAILURE); } /* read tree */ treelist = phytreelist_build(treefile,NEWICK); if (treelist == NULL) { printf("Couldn't build tree\n"); pm_error_print(NULL,stdout); exit(EXIT_FAILURE); } if (treelist->num_trees > 0) { status = phyanimal_load_data(model,df,taxacolumn,treelist->trees[0],0); if (status != PM_SUCCESS) { printf("Couldn't load data\n"); pm_error_print(NULL,stdout); exit(EXIT_FAILURE); } } printf("Fitting\n"); phyanimal_fit(model,0); phyanimal_print(model,stdout); printf("MCMC\n"); mc2 = mc2_animal_new(model); status = mc2_animal_run(mc2,30,5,10); if (status != 0) { printf("mcmc simulation failed\n"); } mc2_animal_free(&mc2); df_free(&df); phyanimal_free(&model); exit(EXIT_SUCCESS); }