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

Function GMT_Set_Columns

src/gmt_api.c:15159–15212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15157#endif
15158
15159int GMT_Set_Columns (void *V_API, unsigned int direction, unsigned int n_cols, unsigned int mode) {
15160 /* Specify how many input or output columns to use for record-by-record output, if fixed */
15161 int error = 0;
15162 uint64_t n_in = 0;
15163 struct GMTAPI_CTRL *API = NULL;
15164 if (!(direction == GMT_IN || direction == GMT_OUT)) return_error (V_API, GMT_NOT_A_VALID_DIRECTION);
15165 if (direction == GMT_IN && !(mode == GMT_COL_FIX || mode == GMT_COL_VAR || mode == GMT_COL_FIX_NO_TEXT)) return_error (V_API, GMT_NOT_A_VALID_MODE);
15166 if (V_API == NULL) return_error (V_API, GMT_NOT_A_SESSION);
15167 API = gmtapi_get_api_ptr (V_API);
15168 API->error = GMT_NOERROR;
15169
15170 if (direction == GMT_OUT) { /* Output */
15171 if ((mode == GMT_COL_ADD || mode == GMT_COL_SUB) && (n_in = gmt_get_cols (API->GMT, GMT_IN)) == 0) { /* Get number of input columns */
15172 GMT_Report (API, GMT_MSG_ERROR, "GMT_Set_Columns: Premature call - number of input columns not known yet\n");
15173 return_error (API, GMT_N_COLS_NOT_SET);
15174 }
15175 /* If no columns specified we set output to the same as input columns */
15176 if (n_cols == 0 && mode != GMT_COL_FIX && (error = gmt_set_cols (API->GMT, GMT_OUT, n_in)) != 0)
15177 return_error (API, GMT_N_COLS_NOT_SET);
15178 /* Set output record type */
15179 if (n_cols == 0)
15180 API->GMT->current.io.record_type[GMT_OUT] = GMT_WRITE_TEXT;
15181 else if (mode == GMT_COL_FIX_NO_TEXT)
15182 API->GMT->current.io.record_type[GMT_OUT] = GMT_WRITE_DATA;
15183 else
15184 API->GMT->current.io.record_type[GMT_OUT] = GMT_WRITE_MIXED;
15185 }
15186
15187 /* Get here when n_cols is not zero (of we have a special case), so must consult mode */
15188
15189 switch (mode) {
15190 case GMT_COL_FIX_NO_TEXT: /* Specific a fixed number of columns, and ignore trailing text */
15191 API->GMT->current.io.trailing_text[direction] = false;
15192 /* Intentionally fall through - to set columns */
15193 case GMT_COL_FIX: /* Specific a fixed number of columns */
15194 error = gmt_set_cols (API->GMT, direction, n_cols);
15195 break;
15196 case GMT_COL_VAR: /* Flag we have a variable number of input columns */
15197 API->GMT->current.io.variable_in_columns = true;
15198 break;
15199 case GMT_COL_ADD: /* Add to the number of input columns */
15200 error = gmt_set_cols (API->GMT, GMT_OUT, n_in + n_cols);
15201 break;
15202 case GMT_COL_SUB: /* Subtract from the number of input columns */
15203 if (n_cols >= n_in) {
15204 GMT_Report (API, GMT_MSG_ERROR, "GMT_Set_Columns: Cannot specify less than one output column!\n");
15205 return_error (API, GMT_DIM_TOO_SMALL);
15206 }
15207 error = gmt_set_cols (API->GMT, GMT_OUT, n_in - n_cols);
15208 break;
15209 }
15210 if (error) return_error (API, GMT_N_COLS_NOT_SET);
15211 return (GMT_NOERROR);
15212}
15213
15214#ifdef FORTRAN_API
15215int GMT_Set_Columns_ (unsigned int *direction, unsigned int *n_cols, unsigned int *mode) {

Callers 15

GMT_gmtconvertFunction · 0.85
GMT_grdvolumeFunction · 0.85
GMT_nearneighborFunction · 0.85
GMT_pswiggleFunction · 0.85
GMT_pssolarFunction · 0.85
GMT_grdeditFunction · 0.85
GMT_makecptFunction · 0.85
GMT_greensplineFunction · 0.85
GMT_grd2xyzFunction · 0.85
GMT_gmtspatialFunction · 0.85
gmt_decorate_prepFunction · 0.85
gmt_contlabel_prepFunction · 0.85

Calls 4

gmtapi_get_api_ptrFunction · 0.85
gmt_get_colsFunction · 0.85
GMT_ReportFunction · 0.85
gmt_set_colsFunction · 0.85

Tested by 2

GMT_spectrum1dFunction · 0.68
mainFunction · 0.68