! . */
| 7296 | |
| 7297 | /*! . */ |
| 7298 | GMT_LOCAL int gmtapi_export_vector (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode, struct GMT_VECTOR *V_obj) { |
| 7299 | /* Does the actual work of writing out the specified Matrix to a destination. Only FILE supported for testing. |
| 7300 | */ |
| 7301 | int item, error; |
| 7302 | unsigned int kind; |
| 7303 | struct GMTAPI_DATA_OBJECT *S_obj = NULL; |
| 7304 | struct GMT_CTRL *GMT = API->GMT; |
| 7305 | |
| 7306 | GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_export_vector: Passed ID = %d and mode = %d\n", object_ID, mode); |
| 7307 | |
| 7308 | if (object_ID == GMT_NOTSET) return (gmtlib_report_error (API, GMT_OUTPUT_NOT_SET)); |
| 7309 | if ((item = gmtlib_validate_id (API, GMT_IS_VECTOR, object_ID, GMT_OUT, GMT_NOTSET)) == GMT_NOTSET) return (gmtlib_report_error (API, API->error)); |
| 7310 | |
| 7311 | S_obj = API->object[item]; /* This is the API object for the output destination */ |
| 7312 | if (S_obj->status != GMT_IS_UNUSED && !(mode & GMT_IO_RESET)) { /* Only allow writing of a data set once, unless we override by resetting the mode */ |
| 7313 | return (gmtlib_report_error (API, GMT_WRITTEN_ONCE)); |
| 7314 | } |
| 7315 | if (mode & GMT_IO_RESET) mode -= GMT_IO_RESET; |
| 7316 | |
| 7317 | /* Passed sanity and allowed to write */ |
| 7318 | |
| 7319 | switch (S_obj->method) { /* File, array, stream etc ? */ |
| 7320 | case GMT_IS_FILE: |
| 7321 | /* gmtapi_write_vector will report where it is writing from if level is GMT_MSG_INFORMATION */ |
| 7322 | GMT_Report (API, GMT_MSG_INFORMATION, "Write VECTOR to %s %s\n", gmtapi_method (S_obj->method), S_obj->filename); |
| 7323 | if ((error = gmtapi_write_vector (GMT, S_obj->filename, S_obj->method, mode, V_obj))) return (gmtlib_report_error (API, error)); |
| 7324 | break; |
| 7325 | case GMT_IS_STREAM: |
| 7326 | /* gmtapi_write_vector will report where it is writing from if level is GMT_MSG_INFORMATION */ |
| 7327 | kind = (S_obj->fp == GMT->session.std[GMT_OUT]) ? 0 : 1; /* For message only: 0 if stdout, 1 otherwise for user pointer */ |
| 7328 | GMT_Report (API, GMT_MSG_INFORMATION, "Write VECTOR to %s %s output stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]); |
| 7329 | if ((error = gmtapi_write_vector (GMT, S_obj->fp, S_obj->method, mode, V_obj))) return (gmtlib_report_error (API, error)); |
| 7330 | break; |
| 7331 | case GMT_IS_FDESC: |
| 7332 | /* gmtapi_write_vector will report where it is writing from if level is GMT_MSG_INFORMATION */ |
| 7333 | kind = (*((int *)S_obj->fp) == GMT_OUT) ? 0 : 1; /* For message only: 0 if stdout, 1 otherwise for user pointer */ |
| 7334 | GMT_Report (API, GMT_MSG_INFORMATION, "Write VECTOR to %s %s output stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]); |
| 7335 | if ((error = gmtapi_write_vector (GMT, S_obj->fp, S_obj->method, mode, V_obj))) return (gmtlib_report_error (API, error)); |
| 7336 | break; |
| 7337 | default: |
| 7338 | GMT_Report (API, GMT_MSG_ERROR, "Wrong method used to export VECTOR\n"); |
| 7339 | return (gmtlib_report_error (API, GMT_NOT_A_VALID_METHOD)); |
| 7340 | break; |
| 7341 | } |
| 7342 | S_obj->status = GMT_IS_USED; /* Mark as written */ |
| 7343 | |
| 7344 | return GMT_NOERROR; |
| 7345 | } |
| 7346 | |
| 7347 | GMT_LOCAL struct GMT_VECTOR *gmtapi_read_vector (struct GMT_CTRL *GMT, void *source, unsigned int src_type, unsigned int mode) { |
| 7348 | /* We read the VECTOR from fp [or stdin]. |
no test coverage detected