| 2063 | } |
| 2064 | |
| 2065 | GMT_LOCAL int gmtapi_init_grdheader (struct GMT_CTRL *GMT, unsigned int direction, struct GMT_GRID_HEADER *header, struct GMT_OPTION *options, |
| 2066 | uint64_t dim[], double wesn[], double inc[], unsigned int registration, unsigned int mode) { |
| 2067 | /* Convenient way of setting a header struct wesn, inc, and registration, then compute dimensions, etc. */ |
| 2068 | double wesn_dup[4] = {0.0, 0.0, 0.0, 0.0}, inc_dup[2] = {0.0, 0.0}; |
| 2069 | unsigned int n_layers = 1; |
| 2070 | static char *regtype[2] = {"gridline", "pixel"}; |
| 2071 | struct GMT_GRID_HEADER_HIDDEN *HH = gmt_get_H_hidden (header); |
| 2072 | gmt_M_unused(mode); |
| 2073 | |
| 2074 | if (registration & GMT_GRID_DEFAULT_REG) registration |= GMT->common.R.registration; /* Set the default registration */ |
| 2075 | registration = (registration & 1); /* Knock off any GMT_GRID_DEFAULT_REG bit */ |
| 2076 | if (dim && (wesn == NULL || (gmt_M_is_zero (wesn[XLO]) && gmt_M_is_zero (wesn[XHI]) && gmt_M_is_zero (wesn[YLO]) && gmt_M_is_zero (wesn[YHI]))) && (inc == NULL || (gmt_M_is_zero (inc[GMT_X]) && gmt_M_is_zero (inc[GMT_Y])))) { /* Gave dimension instead, set range and inc (1/1) while considering registration */ |
| 2077 | gmt_M_memset (wesn_dup, 4, double); |
| 2078 | wesn_dup[XHI] = (double)(dim[GMT_X]); |
| 2079 | wesn_dup[YHI] = (double)(dim[GMT_Y]); |
| 2080 | inc_dup[GMT_X] = inc_dup[GMT_Y] = 1.0; |
| 2081 | if (registration == GMT_GRID_NODE_REG) wesn_dup[XHI] -= 1.0, wesn_dup[YHI] -= 1.0; |
| 2082 | if (dim[GMT_Z] > 1) n_layers = (unsigned int)dim[GMT_Z]; |
| 2083 | GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Grid/Image dimensions imply w/e/s/n = 0/%g/0/%g, inc = 1/1, %s registration, n_layers = %u\n", |
| 2084 | wesn_dup[XHI], wesn_dup[YHI], regtype[registration], n_layers); |
| 2085 | } |
| 2086 | else { /* Must infer dimension etc from wesn, inc, registration */ |
| 2087 | if (wesn == NULL) { /* Must select -R setting */ |
| 2088 | if (!GMT->common.R.active[RSET]) { |
| 2089 | GMT_Report (GMT->parent, GMT_MSG_ERROR, "No w/e/s/n given and no -R in effect. Cannot initialize new grid\n"); |
| 2090 | return GMT_ARG_IS_NULL; |
| 2091 | } |
| 2092 | } |
| 2093 | else /* In case user is passing header->wesn etc we must save them first as gmt_grd_init will clobber them */ |
| 2094 | gmt_M_memcpy (wesn_dup, wesn, 4, double); |
| 2095 | if (inc == NULL) { /* Must select -I setting */ |
| 2096 | if (!GMT->common.R.active[ISET]) { |
| 2097 | GMT_Report (GMT->parent, GMT_MSG_ERROR, "No increment given and no -I in effect. Cannot initialize new grid\n"); |
| 2098 | return GMT_ARG_IS_NULL; |
| 2099 | } |
| 2100 | } |
| 2101 | else /* In case user is passing header->inc etc we must save them first as gmt_grd_init will clobber them */ |
| 2102 | gmt_M_memcpy (inc_dup, inc, 2, double); |
| 2103 | if (dim && dim[GMT_Z] > 1) n_layers = (unsigned int)dim[GMT_Z]; |
| 2104 | if (inc != NULL) { |
| 2105 | GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Grid/Image dimensions imply w/e/s/n = %g/%g/%g/%g, inc = %g/%g, %s registration, n_layers = %u\n", |
| 2106 | wesn_dup[XLO], wesn_dup[XHI], wesn_dup[YLO], wesn_dup[YHI], inc[GMT_X], inc[GMT_Y], regtype[registration], n_layers); |
| 2107 | } |
| 2108 | } |
| 2109 | /* Clobber header and reset */ |
| 2110 | gmt_grd_init (GMT, header, options, false); /* This is for new grids only so update is always false */ |
| 2111 | if (dim == NULL && wesn == NULL) |
| 2112 | gmt_M_memcpy (header->wesn, GMT->common.R.wesn, 4, double); |
| 2113 | else |
| 2114 | gmt_M_memcpy (header->wesn, wesn_dup, 4, double); |
| 2115 | if (dim == NULL && inc == NULL) |
| 2116 | gmt_M_memcpy (header->inc, GMT->common.R.inc, 2, double); |
| 2117 | else |
| 2118 | gmt_M_memcpy (header->inc, inc_dup, 2, double); |
| 2119 | header->registration = registration; |
| 2120 | /* Copy row-order from R.row_order, if set */ |
| 2121 | if (GMT->common.R.row_order) HH->row_order = GMT->common.R.row_order; |
| 2122 | /* Mode may contain complex mode information */ |
no test coverage detected