! . */
| 7139 | |
| 7140 | /*! . */ |
| 7141 | GMT_LOCAL int gmtapi_export_matrix (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode, struct GMT_MATRIX *M_obj) { |
| 7142 | /* Does the actual work of writing out the specified Matrix to a destination. Only FILE supported for testing. |
| 7143 | */ |
| 7144 | int item, error; |
| 7145 | unsigned int kind; |
| 7146 | struct GMTAPI_DATA_OBJECT *S_obj = NULL; |
| 7147 | struct GMT_CTRL *GMT = API->GMT; |
| 7148 | |
| 7149 | GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_export_matrix: Passed ID = %d and mode = %d\n", object_ID, mode); |
| 7150 | |
| 7151 | if (object_ID == GMT_NOTSET) return (gmtlib_report_error (API, GMT_OUTPUT_NOT_SET)); |
| 7152 | if ((item = gmtlib_validate_id (API, GMT_IS_MATRIX, object_ID, GMT_OUT, GMT_NOTSET)) == GMT_NOTSET) return (gmtlib_report_error (API, API->error)); |
| 7153 | |
| 7154 | S_obj = API->object[item]; /* This is the API object for the output destination */ |
| 7155 | 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 */ |
| 7156 | return (gmtlib_report_error (API, GMT_WRITTEN_ONCE)); |
| 7157 | } |
| 7158 | if (mode & GMT_IO_RESET) mode -= GMT_IO_RESET; |
| 7159 | |
| 7160 | /* Passed sanity and allowed to write */ |
| 7161 | |
| 7162 | switch (S_obj->method) { /* File, array, stream etc ? */ |
| 7163 | case GMT_IS_FILE: |
| 7164 | /* gmtapi_write_matrix will report where it is writing from if level is GMT_MSG_INFORMATION */ |
| 7165 | GMT_Report (API, GMT_MSG_INFORMATION, "Write MATRIX to %s %s\n", gmtapi_method (S_obj->method), S_obj->filename); |
| 7166 | if (S_obj->geometry == GMT_IS_SURFACE) { /* Must convert matrix to grid then write to file */ |
| 7167 | struct GMT_GRID *G; |
| 7168 | G = gmtapi_matrix2grid (API, M_obj, NULL); /* Convert the matrix to a grid */ |
| 7169 | error = gmtapi_export_grid (API, object_ID, mode, G); |
| 7170 | if (gmtapi_destroy_grid (API, &G)) |
| 7171 | return (gmtlib_report_error (API, GMT_DATA_READ_ERROR)); |
| 7172 | } |
| 7173 | else if ((error = gmtapi_write_matrix (GMT, S_obj->filename, S_obj->method, mode, M_obj))) return (gmtlib_report_error (API, error)); |
| 7174 | break; |
| 7175 | case GMT_IS_STREAM: |
| 7176 | /* gmtapi_write_matrix will report where it is writing from if level is GMT_MSG_INFORMATION */ |
| 7177 | kind = (S_obj->fp == GMT->session.std[GMT_OUT]) ? 0 : 1; /* For message only: 0 if stdout, 1 otherwise for user pointer */ |
| 7178 | GMT_Report (API, GMT_MSG_INFORMATION, "Write MATRIX to %s %s output stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]); |
| 7179 | if ((error = gmtapi_write_matrix (GMT, S_obj->fp, S_obj->method, mode, M_obj))) return (gmtlib_report_error (API, error)); |
| 7180 | break; |
| 7181 | case GMT_IS_FDESC: |
| 7182 | /* gmtapi_write_matrix will report where it is writing from if level is GMT_MSG_INFORMATION */ |
| 7183 | kind = (*((int *)S_obj->fp) == GMT_OUT) ? 0 : 1; /* For message only: 0 if stdout, 1 otherwise for user pointer */ |
| 7184 | GMT_Report (API, GMT_MSG_INFORMATION, "Write MATRIX to %s %s output stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]); |
| 7185 | if ((error = gmtapi_write_matrix (GMT, S_obj->fp, S_obj->method, mode, M_obj))) return (gmtlib_report_error (API, error)); |
| 7186 | break; |
| 7187 | default: |
| 7188 | GMT_Report (API, GMT_MSG_ERROR, "Wrong method used to export MATRIX\n"); |
| 7189 | return (gmtlib_report_error (API, GMT_NOT_A_VALID_METHOD)); |
| 7190 | break; |
| 7191 | } |
| 7192 | S_obj->status = GMT_IS_USED; /* Mark as written */ |
| 7193 | |
| 7194 | return GMT_NOERROR; |
| 7195 | } |
| 7196 | |
| 7197 | GMT_LOCAL int gmtapi_write_vector (struct GMT_CTRL *GMT, void *dest, unsigned int dest_type, unsigned int mode, struct GMT_VECTOR *V) { |
| 7198 | /* We write the VECTOR to fp [or stdout]. |
no test coverage detected