MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtlib_process_binary_input

Function gmtlib_process_binary_input

src/gmt_io.c:4812–4897  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

4810
4811/*! . */
4812int gmtlib_process_binary_input (struct GMT_CTRL *GMT, uint64_t n_read) {
4813 /* Process a binary record to determine what kind of record it is. Return values:
4814 * 0 = regular record; 1 = segment header (all NaNs); 2 = skip this record
4815 * Also takes these optional actions:
4816 * 1) -: Flips x and u
4817 * 2) Adjusts periodicity on longitudes
4818 * 3) Scales plot dimensions from prevailing unit to internal inches.
4819 * 4) Handles inverse projections if given projected coordinates.
4820 */
4821 uint64_t col_no, n_NaN;
4822 bool bad_record = false, set_nan_flag = false;
4823 /* Here, GMT->current.io.curr_rec has been filled in by fread */
4824
4825 /* Determine if this was a segment header, and if so return */
4826 for (col_no = n_NaN = 0; col_no < n_read; col_no++) {
4827 if (!gmt_M_is_dnan (GMT->current.io.curr_rec[col_no])) { /* Clean data */
4828 if (gmt_input_col_is_nan_proxy (GMT, GMT->current.io.curr_rec[col_no], col_no)) /* Input matched no-data setting, so change to NaN */
4829 GMT->current.io.curr_rec[col_no] = GMT->session.d_NaN;
4830 else if (GMT->common.i.col.select) /* Cannot check here, done in gmtio_bin_colselect instead when order is set */
4831 continue;
4832 else { /* Still clean, so possibly adjust value and skip to next column */
4833 switch (gmt_M_type (GMT, GMT_IN, col_no)) {
4834 case GMT_IS_LON: /* Must account for periodicity in 360 as per current rule */
4835 gmtio_adjust_periodic_lon (GMT, &GMT->current.io.curr_rec[col_no]);
4836 break;
4837 case GMT_IS_LAT:
4838 if (!GMT->common.b.active[2] && (GMT->current.io.curr_rec[col_no] < -90.0 || GMT->current.io.curr_rec[col_no] > +90.0)) {
4839 GMT_Report (GMT->parent, GMT_MSG_WARNING, "Latitude (%g) at line # %" PRIu64 " exceeds -|+ 90! - set to NaN\n", GMT->current.io.curr_rec[col_no], GMT->current.io.rec_no);
4840 GMT->current.io.curr_rec[col_no] = GMT->session.d_NaN;
4841 }
4842 break;
4843 case GMT_IS_DIMENSION: /* Convert to internal inches */
4844 GMT->current.io.curr_rec[col_no] *= GMT->session.u2u[GMT->current.setting.proj_length_unit][GMT_INCH];
4845 break;
4846 case GMT_IS_ABSTIME: case GMT_IS_RELTIME: /* Possibly convert to periodic time */
4847 if (GMT->current.io.cycle_operator && GMT->current.io.cycle_col == (int64_t)col_no)
4848 gmtlib_modulo_time_calculator (GMT, &(GMT->current.io.curr_rec[col_no]));
4849 default: /* Nothing to do unless periodic */
4850 if (GMT->current.io.cycle_operator && GMT->current.io.cycle_col == (int64_t)col_no)
4851 gmtlib_modulo_time_calculator (GMT, &(GMT->current.io.curr_rec[col_no]));
4852 break;
4853 }
4854 continue;
4855 }
4856 }
4857 /* We end up here if we found a NaN */
4858 if (!GMT->current.setting.io_nan_records && GMT->current.io.skip_if_NaN[col_no]) bad_record = true; /* This field is not allowed to be NaN */
4859 if (GMT->current.io.skip_if_NaN[col_no]) set_nan_flag = true;
4860 n_NaN++;
4861 }
4862
4863 if (!GMT->current.io.status && GMT->current.setting.n_bin_header_cols) { /* Must have n_read NaNs to qualify as segment header (if enabled) */
4864 if (n_read >= GMT->current.setting.n_bin_header_cols && n_NaN == n_read) {
4865 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Detected binary segment header near/at line # %" PRIu64 "\n", GMT->current.io.rec_no);
4866 GMT->current.io.status = GMT_IO_SEGMENT_HEADER;
4867 GMT->current.io.segment_header[0] = '\0';
4868 gmt_set_segmentheader (GMT, GMT_OUT, true); /* Turn on "-mo" */
4869 GMT->current.io.seg_no++;

Callers 3

gmtapi_bin_input_memoryFunction · 0.85
gmtio_bin_inputFunction · 0.85
gmtio_nc_inputFunction · 0.85

Calls 8

GMT_ReportFunction · 0.85
gmt_set_segmentheaderFunction · 0.85
gmtio_adjust_projectedFunction · 0.85

Tested by

no test coverage detected