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

Function gmt_contlabel_save_begin

src/gmt_plot.c:7916–7947  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7914}
7915
7916int gmt_contlabel_save_begin (struct GMT_CTRL *GMT, struct GMT_CONTOUR *G) {
7917 int kind;
7918 uint64_t k, seg, dim[4] = {1, 1, GMT_SMALL_CHUNK, 3}; /* Single table with 1 segment and unknown rows, each with 3 columns and trailing text */
7919 char record[GMT_BUFSIZ] = {""};
7920 char *xname[2] = {"x", "lon"}, *yname[2] = {"y", "lat"};
7921 double angle = 0.0;
7922 struct GMT_CONTOUR_LINE *L = NULL;
7923
7924 /* Save the lon, lat, angle, text for each annotation to specified file */
7925
7926 kind = gmt_M_is_geographic (GMT, GMT_IN);
7927 if ((G->Out = GMT_Create_Data (GMT->parent, GMT_IS_DATASET, GMT_IS_POINT, GMT_WITH_STRINGS, dim, NULL, NULL, 0, 0, NULL)) == NULL) {
7928 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Unable to create a dataset\n");
7929 return (GMT_MEMORY_ERROR); /* Establishes data output */
7930 }
7931 /* Write lon, lat, angle, label record */
7932 snprintf (record, GMT_BUFSIZ, "# %s%s%s%sangle%slabel", xname[kind], GMT->current.setting.io_col_separator, yname[kind],
7933 GMT->current.setting.io_col_separator, GMT->current.setting.io_col_separator);
7934 GMT_Set_Comment (GMT->parent, GMT_IS_DATASET, GMT_COMMENT_IS_TEXT | GMT_COMMENT_IS_COMMAND, record, G->Out);
7935 G->Out->table[0]->segment[0]->n_rows = 0;
7936 for (seg = 0; seg < G->n_segments; seg++) {
7937 L = G->segment[seg]; /* Pointer to current segment */
7938 if (!L->annot || L->n_labels == 0) continue;
7939 for (k = 0; k < L->n_labels; k++) {
7940 angle = fmod (2.0 * (L->L[k].angle + 360.0), 360.0) / 2.0; /* Get text line in 0-180 range */
7941 gmt_add_label_record (GMT, G->Out, L->L[k].x, L->L[k].y, angle, L->L[k].label); /* Store text record */
7942 }
7943 }
7944 gmtlib_finalize_dataset (GMT, G->Out);
7945 return (GMT_NOERROR);
7946 /* To finish and close the file, call gmt_contlabel_save_end */
7947}
7948
7949int gmt_contlabel_save_end (struct GMT_CTRL *GMT, struct GMT_CONTOUR *G) {
7950 /* Finalize this dataset and write it out */

Callers 4

GMT_psxyFunction · 0.85
GMT_psxyzFunction · 0.85
GMT_grdcontourFunction · 0.85
GMT_pscontourFunction · 0.85

Calls 5

GMT_Create_DataFunction · 0.85
GMT_ReportFunction · 0.85
GMT_Set_CommentFunction · 0.85
gmt_add_label_recordFunction · 0.85
gmtlib_finalize_datasetFunction · 0.85

Tested by

no test coverage detected