void find_cd() { mvprintw(PROMOTE_LINE, 0, "Enter a string to search for in CD titles: "); char buf[MAX_STRING_LEN + 1]; memset(buf, 0, sizeof(buf)); getstring(buf, sizeof(buf) - 1); FILE *fp = fopen(title_cdb, "r"); if (NULL == fp) { mvprintw(ERROR_LINE, OUTPUT_COL, "%s\n", "find_record(): fopen error"); refresh(); return; } int record_count = 0; char *record = count_record(buf, title_cdb, &record_count); if (record_count > 0 && record != NULL) { char *tmp_ptr = record; char *tmp_ptr2 = record; int string_len = 0; int separator_count = 0; while (*tmp_ptr != '\0') { if (*tmp_ptr == ',') { ++ separator_count; if (1 == separator_count) { strncpy(cur_cd_cat, tmp_ptr2, string_len); } if (2 == separator_count) { strncpy(cur_cd_name, tmp_ptr2, string_len); break; } tmp_ptr2 = ++tmp_ptr; string_len = 1; continue; } ++ tmp_ptr; ++ string_len; } } else { mvprintw(ERROR_LINE, 0, "Nothing found in database"); refresh(); cd_pause(ERROR_LINE + 2); } fclose(fp); }
/*---------------------------------------------------------------*/ static int process_output(int verbose, mbdefaults *mbdflts, options *opts, mb_path ifile, counts *recs, int *error) { char *function_name = "scan_input_heights"; int status = MB_SUCCESS; int i; void *imbio_ptr = NULL; double btime_d, etime_d; int beams_bath_alloc, beams_amp_alloc, pixels_ss_alloc; void *ombio_ptr[SWPLS_MAX_TXERS]; struct mb_io_struct *imb_io_ptr = NULL; void *istore_ptr = NULL; int ofile_init[SWPLS_MAX_TXERS]; mb_path ofile[SWPLS_MAX_TXERS]; struct mbsys_swathplus_struct *istore = NULL; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 function <%s> called\n", function_name); fprintf(stderr, "dbg2 Revision id: %s\n", rcs_id); fprintf(stderr, "dbg2 Input arguments:\n"); fprintf(stderr, "dbg2 verbose: %d\n", verbose); fprintf(stderr, "dbg2 options: %p\n", (void *)opts); } /* open the input file */ if ((status = mb_read_init(opts->verbose, ifile, opts->format, mbdflts->pings_get, mbdflts->lonflip, mbdflts->bounds, mbdflts->btime_i, mbdflts->etime_i, mbdflts->speedmin, mbdflts->timegap, &imbio_ptr, &btime_d, &etime_d, &beams_bath_alloc, &beams_amp_alloc, &pixels_ss_alloc, error)) != MB_SUCCESS) { char message[MAX_ERROR_STRING] = {0}; sprintf(message, "Swath File <%s> not initialized for reading\n", ifile); error_exit(opts->verbose, *error, "mb_read_init", message); } /* get mbio and data structure descriptors */ imb_io_ptr = (struct mb_io_struct *)imbio_ptr; istore_ptr = imb_io_ptr->store_data; /* set the projection for nav data */ if (opts->projection_set == MB_YES) { mb_proj_init(opts->verbose, opts->proj4command, &(imb_io_ptr->pjptr), error); strncpy(imb_io_ptr->projection_id, opts->proj4command, MB_NAME_LENGTH); imb_io_ptr->projection_initialized = MB_YES; } /* setup the output filename(s) for writing */ status = set_outfile_names(opts->verbose, ofile, ifile, &opts->basename, opts->ofile_set, opts->split_txers, error); for (i = 0; i < SWPLS_MAX_TXERS; i++) { ombio_ptr[i] = NULL; ofile_init[i] = MB_NO; } /* start looping over data records */ while (*error <= MB_ERROR_NO_ERROR) { int kind = MB_DATA_NONE; /* read the next record */ status = mb_read_ping(opts->verbose, imbio_ptr, istore_ptr, &kind, error); /* some nonfatal errors do not matter */ if ((*error < MB_ERROR_NO_ERROR) && (MB_ERROR_UNINTELLIGIBLE < *error)) { error = MB_ERROR_NO_ERROR; status = MB_SUCCESS; } istore = (struct mbsys_swathplus_struct *)istore_ptr; if (status == MB_SUCCESS) { status = count_record(opts->verbose, recs, istore, error); } if ((status == MB_SUCCESS) && (opts->print_ascii == MB_YES)) { status = print_latest_record(opts->verbose, istore, error); } /* process the sxp ping data to file */ if ((status == MB_SUCCESS) && (istore->kind == MB_DATA_DATA) && ((istore->type == SWPLS_ID_PROCESSED_PING) || (istore->type == SWPLS_ID_PROCESSED_PING2))) { int obeams_bath, obeams_amp, opixels_ss; struct mb_io_struct *omb_io_ptr = NULL; void *ostore_ptr = NULL; struct mbsys_swathplus_struct *ostore = NULL; int txno = 0; int txidx = 0; if ((status == MB_SUCCESS) && (opts->flip_rejected == MB_YES)) { status = flip_sample_flags(opts->verbose, &(istore->sxp_ping), error); } if ((status == MB_SUCCESS) && (opts->remove_rejected == MB_YES)) { status = remove_rejected_samps(opts->verbose, &(istore->sxp_ping), error); } if ((status == MB_SUCCESS) && (opts->copy_rawamp == MB_YES)) { status = copy_rawamp(opts->verbose, &(istore->sxp_ping), error); } if ((status == MB_SUCCESS) && (opts->write_output == MB_YES)) { /* select the output file based on the txer channel */ status = ping_txno(opts->verbose, istore, &txno, error); txidx = (opts->split_txers == MB_YES) ? txno - 1 : 0; /* initialize the output file if necessary */ if (ofile_init[txidx] == MB_NO) { status = mb_write_init(opts->verbose, ofile[txidx], opts->format, &ombio_ptr[txidx], &obeams_bath, &obeams_amp, &opixels_ss, error); if (status != MB_SUCCESS) { char message[MAX_ERROR_STRING] = {0}; sprintf(message, "SWATHplus file <%s> not initialized for writing.\n", ofile[txidx]); error_exit(verbose, *error, "mb_write_init", message); } if (status == MB_SUCCESS) { ofile_init[txidx] = MB_YES; } } /* assign output pointers based on txer channel */ omb_io_ptr = (struct mb_io_struct *)ombio_ptr[txidx]; ostore_ptr = omb_io_ptr->store_data; ostore = (struct mbsys_swathplus_struct *)ostore_ptr; /* copy the ping from istore to ostore */ if (status == MB_SUCCESS) { status = mbsys_swathplus_copy(opts->verbose, imbio_ptr, istore_ptr, ostore_ptr, error); } /* write the ping to file */ if (status == MB_SUCCESS) { ostore->kind = MB_DATA_DATA; ostore->type = SWPLS_ID_PROCESSED_PING2; status = mb_write_ping(opts->verbose, ombio_ptr[txidx], ostore, error); } /* check for error writing here */ if (status != MB_SUCCESS) { char message[MAX_ERROR_STRING] = {0}; sprintf(message, "Data not written to file <%s>\n", ofile[txidx]); error_exit(opts->verbose, *error, "mb_write_ping", message); } } /* end write sxp data to file */ } /* end processing sxp data */ } /* end looping over all records in file */ /* close the files */ status = mb_close(opts->verbose, &imbio_ptr, error); for (i = 0; i < SWPLS_MAX_TXERS; i++) { if (ofile_init[i] == MB_YES) { status = mb_close(opts->verbose, &ombio_ptr[i], error); ofile_init[i] = MB_NO; } } if (verbose >= 2) { fprintf(stderr, "\ndbg2 function <%s> completed\n", function_name); fprintf(stderr, "dbg2 Return values:\n"); fprintf(stderr, "dbg2 error: %d\n", *error); fprintf(stderr, "dbg2 Return status:\n"); fprintf(stderr, "dbg2 status: %d\n", status); } return (status); } /* process_output */