| 14943 | } |
| 14944 | |
| 14945 | GMT_LOCAL void * gmtapi_vector2matrix (struct GMTAPI_CTRL *API, struct GMT_VECTOR *In, struct GMT_MATRIX *Out, unsigned int header, unsigned int mode) { |
| 14946 | /* Convert a vector to a matrix. |
| 14947 | * If Out is not NULL then we assume it has enough rows to hold the rows. |
| 14948 | * header controls what we do with headers. |
| 14949 | * If mode > 0 then it is assumed to hold GMT_TYPE-1, else we assume the GMT default setting. |
| 14950 | */ |
| 14951 | uint64_t row, col, ij; |
| 14952 | bool alloc = (Out == NULL); |
| 14953 | double value; |
| 14954 | struct GMT_CTRL *GMT = API->GMT; |
| 14955 | GMT_getfunction api_get_val = NULL; |
| 14956 | GMT_putfunction api_put_val = NULL; |
| 14957 | p_func_uint64_t GMT_2D_to_index = NULL; |
| 14958 | if (header) GMT_Report (API, GMT_MSG_WARNING, "gmtapi_vector2matrix: Header stripping not implemented yet - ignored!\n"); |
| 14959 | if (alloc) { |
| 14960 | struct GMT_MATRIX_HIDDEN *MH = NULL; |
| 14961 | Out = gmtlib_create_matrix (GMT, 1U, 0); |
| 14962 | Out->n_columns = In->n_columns; |
| 14963 | Out->n_rows = In->n_rows; |
| 14964 | Out->type = (mode) ? mode - 1 : API->GMT->current.setting.export_type; |
| 14965 | if (gmtlib_alloc_univector (GMT, &(Out->data), Out->type, Out->n_rows * Out->n_columns)) { |
| 14966 | gmt_M_free (GMT, Out); |
| 14967 | return (NULL); |
| 14968 | } |
| 14969 | MH = gmt_get_M_hidden (Out); |
| 14970 | MH->alloc_mode = GMT_ALLOC_INTERNALLY; |
| 14971 | MH->alloc_level = GMT->hidden.func_level; /* Must be freed at this level. */ |
| 14972 | } |
| 14973 | |
| 14974 | if ((GMT_2D_to_index = gmtapi_get_2d_to_index (API, Out->shape, GMT_GRID_IS_REAL)) == NULL) { |
| 14975 | gmt_M_free (GMT, Out); |
| 14976 | return (NULL); |
| 14977 | } |
| 14978 | if ((api_put_val = gmtapi_select_put_function (API, Out->type)) == NULL) { /* Since all columns are of same type we get the pointer here */ |
| 14979 | gmt_M_free (GMT, Out); |
| 14980 | return (NULL); |
| 14981 | } |
| 14982 | for (col = 0; col < In->n_columns; col++) { |
| 14983 | if ((api_get_val = gmtapi_select_get_function (API, In->type[col])) == NULL) { |
| 14984 | gmt_M_free (GMT, Out); |
| 14985 | return (NULL); |
| 14986 | } |
| 14987 | for (row = 0; row < In->n_rows; row++) { |
| 14988 | api_get_val (&(In->data[col]), row, &value); |
| 14989 | ij = GMT_2D_to_index (row, col, Out->dim); |
| 14990 | api_put_val (&(Out->data), ij, value); |
| 14991 | } |
| 14992 | } |
| 14993 | return Out; |
| 14994 | } |
| 14995 | |
| 14996 | /* New function to convert between objects */ |
| 14997 |
no test coverage detected