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

Function gmtapi_grid2matrix

src/gmt_api.c:6873–6912  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6871}
6872
6873GMT_LOCAL void *gmtapi_grid2matrix (struct GMTAPI_CTRL *API, struct GMT_GRID *In, struct GMT_MATRIX *Out) {
6874 bool alloc = (Out == NULL);
6875 openmp_int row, col;
6876 uint64_t ij, ij_M;
6877 double d;
6878 GMT_putfunction api_put_val = NULL;
6879 p_func_uint64_t GMT_2D_to_index = NULL;
6880
6881 if (alloc) Out = gmtlib_create_matrix (API->GMT, 1U, 0);
6882
6883 gmtapi_grdheader_to_matrixinfo (API->GMT, In->header, Out);
6884 if (alloc) { /* Allocate the matrix itself */
6885 int error;
6886 Out->type = API->GMT->current.setting.export_type;
6887 Out->registration = In->header->registration;
6888 Out->shape = GMT_IS_ROW_FORMAT; /* For now */
6889 Out->dim = (Out->shape == GMT_IS_ROW_FORMAT) ? Out->n_columns : Out->n_rows; /* Matrix layout order */
6890
6891 if ((error = gmtlib_alloc_univector (API->GMT, &(Out->data), Out->type, Out->n_rows * Out->n_columns)) != GMT_NOERROR) {
6892 gmt_M_free (API->GMT, Out);
6893 return_null (API, error);
6894 }
6895 }
6896 if ((GMT_2D_to_index = gmtapi_get_2d_to_index (API, Out->shape, GMT_GRID_IS_REAL)) == NULL) {
6897 if (alloc) gmt_M_free (API->GMT, Out);
6898 return_null (API, GMT_WRONG_MATRIX_SHAPE);
6899 }
6900 if ((api_put_val = gmtapi_select_put_function (API, Out->type)) == NULL) {
6901 if (alloc) gmt_M_free (API->GMT, Out);
6902 return_null (API, GMT_NOT_A_VALID_TYPE);
6903 }
6904
6905 gmt_M_grd_loop (API->GMT, In, row, col, ij) {
6906 d = In->data[ij];
6907 ij_M = GMT_2D_to_index (row, col, Out->dim);
6908 api_put_val (&(Out->data), ij_M, d);
6909 }
6910
6911 return Out;
6912}
6913
6914GMT_LOCAL void *gmtapi_matrix2grid (struct GMTAPI_CTRL *API, struct GMT_MATRIX *In, struct GMT_GRID *Out) {
6915 bool alloc = (Out == NULL);

Callers 2

gmtapi_import_matrixFunction · 0.85
GMT_Convert_DataFunction · 0.85

Calls 5

gmtlib_create_matrixFunction · 0.85
gmtlib_alloc_univectorFunction · 0.85
gmtapi_get_2d_to_indexFunction · 0.85

Tested by

no test coverage detected