#include #include #include #ifdef __MWERKS__ #include "console.h" #endif /*prototypes*/ void CreateSequences(FILE *fv); /*variables*/ char **names, **sequences; int numTaxa, numSites; /**************/ void CreateSequences(FILE *fv) { int i; char str[255]; fgets(str, 255, fv); if ( sscanf( str, " %d %d", &numTaxa, &numSites)!=2 ) { fprintf(stderr, "Error reading PHYLIP parameters from input\n"); exit(0); } if ( (names=(char **)malloc(sizeof(char *)*numTaxa))==NULL ) { fprintf(stderr, "Out of memory allocating names\n"); exit(0); } if ( (sequences=(char **)malloc(sizeof(char *)*numTaxa))==NULL ) { fprintf(stderr, "Out of memory allocating sequences\n"); exit(0); } for(i=0;i1) { if ( (fv=fopen(argv[1], "rt"))==NULL ) { fprintf(stderr, "Can't open file, '%s'\n", argv[1]); exit(0); } } CreateSequences(stdin); fprintf(stdout, "#NEXUS\n\n"); fprintf(stderr, "Sequences converted:\n"); dset=0; do{ fgets(str, 255, stdin); if ( sscanf( str, " %d %d", &n1, &n2)!=2 ) { fprintf(stderr, "Error reading parameters for dataset %d\n", dset+1); exit(0); } if ( n1!=numTaxa || n2!=numSites ) { fprintf(stderr, "Parameters for dataset %d don't match the first dataset\n", dset+1); exit(0); } n=0; do { ch=fgetc(stdin); while ( !feof(stdin) && isspace(ch)) ch=fgetc(stdin); if ( feof(stdin) && n==0) { fprintf(stderr, "\n\nFinished!\n"); exit(0); } if ( feof(stdin) ) { fprintf(stderr, "Unexpected end of file on standard input\n"); exit(0); } if(n==0) { fprintf(stdout, "[Dataset %d]\n", dset+1); fprintf(stdout, "BEGIN DATA;\n\tDIMENSIONS NTAX=%d NCHAR=%d;\n\tFORMAT MISSING=? GAP=- DATATYPE=DNA;\n\tMATRIX\n", numTaxa, numSites); } i=0; while ( i<10 && !feof(stdin) && !isspace(ch) ) { names[n][i]=ch; ch=fgetc(stdin); i++; } while (i<10) { names[n][i]=' '; i++; } names[n][10]='\0'; if (i==0) { fprintf(stderr, "Name missing for species %d\n", n+1); exit(0); } while (!feof(stdin) && i<10) { ch=fgetc(stdin); i++; } if ( feof(stdin) ) { fprintf(stderr, "Unexpected end of file on standard input\n"); exit(0); } b=0; while ( !feof(stdin) && b