static void process_gpgga_token(void) { switch (token_nr) { #if PARSE_GPS_TIME case 1: /* time * HHMMSS(.sssss) */ parse_clock(&nmea_wip.gga.clock); break; #endif case 2: /* latitude * BBBB.BBBB */ parse_coord(&nmea_wip.gga.lat); break; case 3: /* orientation * N north * S south */ if (token_buffer[0] == 'N') { nmea_wip.gga.flags |= (1<<NMEA_RMC_FLAGS_LAT_NORTH); } else { nmea_wip.gga.flags &= ~(1<<NMEA_RMC_FLAGS_LAT_NORTH); } break; case 4: /* longitude * LLLLL.LLLL */ parse_coord(&nmea_wip.gga.lon); break; case 5: /* orientation * E east * W west */ if (token_buffer[0] == 'E') { nmea_wip.gga.flags |= (1<<NMEA_RMC_FLAGS_LON_EAST); } else { nmea_wip.gga.flags &= ~(1<<NMEA_RMC_FLAGS_LON_EAST); } break; case 6: /* signal quality */ nmea_wip.gga.quality = atoi(token_buffer); if (nmea_wip.gga.quality) { nmea_wip.gga.flags |= (1<<NMEA_RMC_FLAGS_STATUS_OK); } else { nmea_wip.gga.flags &= ~(1<<NMEA_RMC_FLAGS_STATUS_OK); } break; case 7: /* number of used satellites */ nmea_wip.gga.sats = atoi(token_buffer); break; #if PARSE_GPS_ALTITUDE case 9: /* altitude */ parse_altitude(&nmea_wip.gga.alt); break; #endif default: /* nothing to do */ break; } }
void load_cfile_sim() { long line_count = 0; FILE * fp; /* the following variable is used for checking whether we have a newick string in the species&tree tag, in the case of 1 species. For species trees we do not accept a tree, whereas for network we require a newick string. The program always reads a line. If that line is a tree it is processed, otherwise this variable is set such that we do not read another line */ long line_not_processed = 0; fp = xopen(opt_simulate,"r"); while (line_not_processed || getnextline(fp)) { int valid = 0; char * token; char * value; long token_len; line_not_processed = 0; ++line_count; token_len = get_token(line,&token,&value); if (!token_len) continue; if (token_len < 0) fatal("Invalid syntax when parsing file %s on line %ld", opt_simulate, line_count); if (token_len == 4) { if (!strncasecmp(token,"seed",4)) { if (!get_long(value,&opt_seed)) fatal("Option 'seed' expects one integer (line %ld)", line_count); if (opt_seed == -1) opt_seed = (long)time(NULL); valid = 1; } else if (!strncasecmp(token,"arch",4)) { char * temp; if (!get_string(value,&temp)) fatal("Option %s expects a string (line %ld)", token, line_count); if (!strcmp(temp,"cpu")) opt_arch = PLL_ATTRIB_ARCH_CPU; else if (!strcasecmp(temp,"sse")) opt_arch = PLL_ATTRIB_ARCH_SSE; else if (!strcasecmp(temp,"avx")) opt_arch = PLL_ATTRIB_ARCH_AVX; else if (!strcasecmp(temp,"avx2")) opt_arch = PLL_ATTRIB_ARCH_AVX2; else fatal("Invalid instruction set (%s) (line %ld)", temp, line_count); free(temp); valid = 1; } } else if (token_len == 5) { if (!strncasecmp(token,"clock",5)) { if (!parse_clock(value)) fatal("Option 'clock' expects values '1', '2 a' or '3 a' (line %ld)", line_count); valid = 1; } else if (!strncasecmp(token,"model",5)) { if (!get_long(value,&opt_model) || opt_model < 0) fatal("Option 'model' expects value '%d' or '%d' (line %ld)", BPP_DNA_MODEL_JC69, BPP_DNA_MODEL_GTR, line_count); valid = 1; } } else if (token_len == 6) { if (!strncasecmp(token,"qrates",6)) { if (!parse_qrates(value)) fatal("Option 'qrates' expects one switch and 6 values (line %ld)", line_count); valid = 1; } } else if (token_len == 7) { if (!strncasecmp(token,"seqfile",7)) { if (!get_string(value, &opt_msafile)) fatal("Option '%s' expects a string (line %ld)", token, line_count); valid = 1; } else if (!strncasecmp(token,"diploid",7)) { if (!parse_diploid(value)) fatal("Option %s expects values 0 or 1 for each species (line %ld)", token,line_count); valid = 1; } } else if (token_len == 8) { if (!strncasecmp(token,"treefile",8)) { if (!get_string(value, &opt_treefile)) fatal("Option 'treefile' expects a string (line %ld)", line_count); valid = 1; } else if (!strncasecmp(token,"imapfile",8)) { if (!get_string(value, &opt_mapfile)) fatal("Option 'imapfile' expects a string (line %ld)", line_count); valid = 1; } } else if (token_len == 9) { if (!strncasecmp(token,"basefreqs",9)) { if (!parse_basefreqs(value)) fatal("Option 'basefreqs' expects one switch and 4 values (line %ld)", line_count); valid = 1; } else if (!strncasecmp(token,"migration",9)) { if (!get_long(value,&opt_migration)) fatal("Option 'migration' expects one integer (line %ld)", line_count); parse_migration_matrix(fp, line_count); valid = 1; } } else if (token_len == 10) { if (!strncasecmp(token,"concatfile",10)) { if (!get_string(value,&opt_concatfile)) fatal("Option 'concatfile' expects a string (line %ld)", line_count); valid = 1; } } else if (token_len == 11) { if (!strncasecmp(token,"loci&length",11)) { if (!parse_loci_and_lengths(value)) fatal("Option 'loci&length' expects two positive integer values (line %ld)", line_count); valid = 1; } } else if (token_len == 12) { if (!strncasecmp(token,"species&tree",12)) { /* TODO: Currently only the old BPP format is allowed. Make it also accept only the tree in newick format, i.e. one line instead of 3 */ long spcount = 0; if (!parse_speciesandtree(value,&spcount)) fatal("Erroneous format of 'species&tree' (line %ld)", line_count); if (!getnextline(fp)) fatal("Incomplete 'species&tree' record (line %ld)", line_count); ++line_count; if (!readandvalidatecount(line,spcount)) fatal("Erroneous enumeration of species sequences in 'species&tree' " "tag (line %ld).\nExpected number of species is %ld.\n", line_count, spcount); if (spcount > 1) { if (!getnextline(fp)) fatal("Incomplete 'species&tree' record (line %ld)", line_count); ++line_count; if (!get_tree_string_with_thetas(line,&opt_streenewick)) fatal("Expected newick tree string in 'species&tree' (line %ld) ", "with ending ';' character", line_count); } else if (spcount == 1) { /* TODO: This is an ugly hack to account for the case where we have 1 species and a network */ int reached_eof = 0; if (!getnextline(fp)) reached_eof = 1; ++line_count; line_not_processed = 1; if (!reached_eof && starts_with_opar(line)) { if (!get_string(line,&opt_streenewick)) fatal("Expected newick string in 'species&tree' (line %ld)", line_count); line_not_processed = 0; } else { opt_streenewick = (char *)xmalloc((size_t)(strlen(opt_reorder)+2) * sizeof(char)); strcpy(opt_streenewick, opt_reorder); opt_streenewick[strlen(opt_reorder)] = ';'; opt_streenewick[strlen(opt_reorder)+1] = '\0'; } if (reached_eof) break; } valid = 1; } } else if (token_len == 13) { if (!strncasecmp(token,"modelparafile",13)) { if (!get_string(value,&opt_modelparafile)) fatal("Option 'modelparafile' expects a string (line %ld)", line_count); valid = 1; } } else if (token_len == 14) { if (!strncasecmp(token,"alpha_siterate",14)) { if (!parse_siterate(value)) fatal("Erroneous format of 'alpha_siterate' (line %ld)", line_count); valid = 1; } } else if (token_len == 15) { if (!strncasecmp(token,"alpha_locusrate",15)) { if (!get_double(value, &opt_locusrate_alpha)) fatal("Option 'alpha_locusrate' expects one value (line %ld)", line_count); if (opt_locusrate_alpha < 0) fatal("Option 'alpha_locusrate' expects a non-negative value (line %ld)", line_count); if (opt_locusrate_alpha == 0) opt_est_locusrate = 0; else opt_est_locusrate = 1; valid = 1; } } if (!valid) fatal("Invalid syntax when parsing file %s on line %ld", opt_simulate, line_count); } check_validity(); #if 0 if (opt_diploid) update_sp_seqcount(); #endif fclose(fp); }
static void process_gprmc_token(void) { switch (token_nr) { #if !PARSE_GPS_NMEA_GGA /* avoid duplicate parsing code */ #if PARSE_GPS_TIME case 1: /* time * HHMMSS(.sssss) */ parse_clock(&nmea_wip.rmc.clock); break; #endif case 2: /* status * A OK * V Warning */ if (token_buffer[0] == 'A') { nmea_wip.rmc.flags |= (1<<NMEA_RMC_FLAGS_STATUS_OK); } else { nmea_wip.rmc.flags &= ~(1<<NMEA_RMC_FLAGS_STATUS_OK); } break; case 3: /* latitude * BBBB.BBBB */ parse_coord(&nmea_wip.rmc.lat); break; case 4: /* orientation * N north * S south */ if (token_buffer[0] == 'N') { nmea_wip.rmc.flags |= (1<<NMEA_RMC_FLAGS_LAT_NORTH); } else { nmea_wip.rmc.flags &= ~(1<<NMEA_RMC_FLAGS_LAT_NORTH); } break; case 5: /* longitude * LLLLL.LLLL */ parse_coord(&nmea_wip.rmc.lon); break; case 6: /* orientation * E east * W west */ if (token_buffer[0] == 'E') { nmea_wip.rmc.flags |= (1<<NMEA_RMC_FLAGS_LON_EAST); } else { nmea_wip.rmc.flags &= ~(1<<NMEA_RMC_FLAGS_LON_EAST); } break; #endif case 7: /* speed * GG.G */ break; case 8: /* course * RR.R */ break; #if PARSE_GPS_TIME case 9: /* date * DDMMYY */ parse_date(&nmea_wip.rmc.date); break; #endif case 10: /* magnetic declination * M.M */ break; case 11: /* sign of declination * E east * W west */ break; case 12: /* signal integrity * A autonomous mode * D differential mode * E estimated mode * M manual input mode * S simulated mode * N data not valid */ break; } }