| 14865 | } |
| 14866 | |
| 14867 | GMT_LOCAL void *gmtapi_matrix2vector (struct GMTAPI_CTRL *API, struct GMT_MATRIX *In, struct GMT_VECTOR *Out, unsigned int header, unsigned int mode) { |
| 14868 | /* Convert a matrix to vectors. |
| 14869 | * If Out is not NULL then we assume it has enough rows to hold the vector rows. |
| 14870 | * header controls what we do with headers. |
| 14871 | * If mode > 0 then it is assumed to hold GMT_TYPE-1, else we assume the GMT default setting. |
| 14872 | */ |
| 14873 | uint64_t row, col, ij; |
| 14874 | bool alloc = (Out == NULL); |
| 14875 | double value; |
| 14876 | struct GMT_CTRL *GMT = API->GMT; |
| 14877 | GMT_getfunction api_get_val_m = NULL; |
| 14878 | GMT_putfunction api_put_val_v = NULL; |
| 14879 | p_func_uint64_t GMT_2D_to_index = NULL; |
| 14880 | if (header) GMT_Report (API, GMT_MSG_WARNING, "gmtapi_matrix2vector: Header stripping not implemented yet - ignored!\n"); |
| 14881 | if (alloc) { |
| 14882 | if ((Out = gmt_create_vector (GMT, In->n_columns, GMT_OUT)) == NULL) |
| 14883 | return_null (API, GMT_MEMORY_ERROR); |
| 14884 | Out->n_rows = In->n_rows; |
| 14885 | for (col = 0; col < Out->n_columns; col++) /* Set same export data type for all vectors */ |
| 14886 | Out->type[col] = (mode) ? mode - 1 : API->GMT->current.setting.export_type; |
| 14887 | if ((API->error = gmtlib_alloc_vectors (GMT, Out, Out->n_rows)) != GMT_NOERROR) { |
| 14888 | gmt_M_free (GMT, Out); |
| 14889 | return_null (API, GMT_MEMORY_ERROR); |
| 14890 | } |
| 14891 | } |
| 14892 | |
| 14893 | if ((api_get_val_m = gmtapi_select_get_function (API, In->type)) == NULL) { |
| 14894 | if (alloc) gmt_M_free (GMT, Out); |
| 14895 | return_null (API, GMT_NOT_A_VALID_TYPE); |
| 14896 | } |
| 14897 | if ((api_put_val_v = gmtapi_select_put_function (API, GMT->current.setting.export_type)) == NULL) { /* Since all columns are of same type we get the pointer here */ |
| 14898 | if (alloc) gmt_M_free (GMT, Out); |
| 14899 | return_null (API, GMT_NOT_A_VALID_TYPE); |
| 14900 | } |
| 14901 | if ((GMT_2D_to_index = gmtapi_get_2d_to_index (API, In->shape, GMT_GRID_IS_REAL)) == NULL) { |
| 14902 | if (alloc) gmt_M_free (GMT, Out); |
| 14903 | return_null (API, GMT_WRONG_MATRIX_SHAPE); |
| 14904 | } |
| 14905 | for (row = 0; row < In->n_rows; row++) { |
| 14906 | for (col = 0; col < In->n_columns; col++) { |
| 14907 | ij = GMT_2D_to_index (row, col, In->dim); /* Index into the user data matrix depends on layout (M->shape) */ |
| 14908 | api_get_val_m (&(In->data), ij, &value); |
| 14909 | api_put_val_v (&(Out->data[col]), row, value); |
| 14910 | } |
| 14911 | } |
| 14912 | return Out; |
| 14913 | } |
| 14914 | |
| 14915 | /* GMT_VECTOR to GMT_* : */ |
| 14916 |
no test coverage detected