static gchar* asc_format_header(GwyContainer *data, GwyDataField *dfield, gboolean *zunit_is_nm) { static const gchar asc_header_template[] = "# File Format = ASCII\n" "# Created by Gwyddion %s\n" "# Original file: %s\n" "# x-pixels = %u\n" "# y-pixels = %u\n" "# x-length = %s\n" "# y-length = %s\n" "# x-offset = %s\n" "# y-offset = %s\n" "# Bit2nm = 1.0\n" "%s" "# Start of Data:\n"; GwySIUnit *zunit; gchar *header, *zunit_str, *zunit_line; gchar xreal_str[G_ASCII_DTOSTR_BUF_SIZE], yreal_str[G_ASCII_DTOSTR_BUF_SIZE], xoff_str[G_ASCII_DTOSTR_BUF_SIZE], yoff_str[G_ASCII_DTOSTR_BUF_SIZE]; const guchar *filename = "NONE"; gdouble xreal, yreal, xoff, yoff; /* XXX: Gwyddion can have lateral dimensions as whatever we want. But * who knows about the SPIP ASC format... */ xreal = gwy_data_field_get_xreal(dfield)/Nanometer; yreal = gwy_data_field_get_yreal(dfield)/Nanometer; xoff = gwy_data_field_get_xoffset(dfield)/Nanometer; yoff = gwy_data_field_get_yoffset(dfield)/Nanometer; zunit = gwy_data_field_get_si_unit_z(dfield); g_ascii_dtostr(xreal_str, G_ASCII_DTOSTR_BUF_SIZE, xreal); g_ascii_dtostr(yreal_str, G_ASCII_DTOSTR_BUF_SIZE, yreal); g_ascii_dtostr(xoff_str, G_ASCII_DTOSTR_BUF_SIZE, xoff); g_ascii_dtostr(yoff_str, G_ASCII_DTOSTR_BUF_SIZE, yoff); zunit_str = gwy_si_unit_get_string(zunit, GWY_SI_UNIT_FORMAT_PLAIN); if ((*zunit_is_nm = gwy_strequal(zunit_str, "m"))) zunit_line = g_strdup(""); else zunit_line = g_strdup_printf("# z-unit = %s\n", zunit_str); gwy_container_gis_string_by_name(data, "/filename", &filename); header = g_strdup_printf(asc_header_template, gwy_version_string(), filename, gwy_data_field_get_xres(dfield), gwy_data_field_get_yres(dfield), xreal_str, yreal_str, xoff_str, yoff_str, zunit_line); g_free(zunit_str); g_free(zunit_line); return header; }
static void prof_update_curve(ProfControls *controls, gint i) { GwyGraphCurveModel *gcmodel; gdouble xy[4], h; gint xl0, yl0, xl1, yl1; gint n, lineres; gchar *desc; g_return_if_fail(gwy_selection_get_object(controls->selection, i, xy)); /* The ω=0 pixel is always at res/2, for even dimensions it means it is * shifted half-a-pixel to the right from the precise centre. */ xl0 = gwy_data_field_get_xres(controls->psdffield)/2; yl0 = gwy_data_field_get_yres(controls->psdffield)/2; xl1 = floor(gwy_data_field_rtoj(controls->psdffield, xy[0])); yl1 = floor(gwy_data_field_rtoi(controls->psdffield, xy[1])); xy[0] += gwy_data_field_get_xoffset(controls->psdffield); xy[1] += gwy_data_field_get_yoffset(controls->psdffield); h = hypot(controls->hx*xy[0], controls->hy*xy[1])/hypot(xy[0], xy[1]); if (!controls->args->fixres) { lineres = GWY_ROUND(hypot(abs(xl0 - xl1) + 1, abs(yl0 - yl1) + 1)); lineres = MAX(lineres, MIN_RESOLUTION); } else lineres = controls->args->resolution; gwy_data_field_get_profile(controls->psdffield, controls->line, xl0, yl0, xl1, yl1, lineres, 1, controls->args->interpolation); gwy_data_line_multiply(controls->line, h); n = gwy_graph_model_get_n_curves(controls->gmodel); if (i < n) { gcmodel = gwy_graph_model_get_curve(controls->gmodel, i); } else { gcmodel = gwy_graph_curve_model_new(); g_object_set(gcmodel, "mode", GWY_GRAPH_CURVE_LINE, "color", gwy_graph_get_preset_color(i), NULL); gwy_graph_model_add_curve(controls->gmodel, gcmodel); g_object_unref(gcmodel); } gwy_graph_curve_model_set_data_from_dataline(gcmodel, controls->line, 0, 0); desc = g_strdup_printf(_("PSDF %.0f°"), 180.0/G_PI*atan2(-xy[1], xy[0])); g_object_set(gcmodel, "description", desc, NULL); g_free(desc); }
static void null_offsets(GwyContainer *data, GwyRunType run) { GwyDataField *dfields[3]; GQuark quarks[3]; guint i; gint id; g_return_if_fail(run & BASICOPS_RUN_MODES); gwy_app_data_browser_get_current(GWY_APP_DATA_FIELD, dfields + 0, GWY_APP_MASK_FIELD, dfields + 1, GWY_APP_SHOW_FIELD, dfields + 2, GWY_APP_DATA_FIELD_KEY, quarks + 0, GWY_APP_MASK_FIELD_KEY, quarks + 1, GWY_APP_SHOW_FIELD_KEY, quarks + 2, GWY_APP_DATA_FIELD_ID, &id, 0); clean_quarks(G_N_ELEMENTS(quarks), quarks, dfields); for (i = 0; i < G_N_ELEMENTS(dfields); i++) { if (dfields[i] && !gwy_data_field_get_xoffset(dfields[i]) && !gwy_data_field_get_yoffset(dfields[i])) { quarks[i] = 0; dfields[i] = NULL; } } if (!dfields[0] && !dfields[1] && !dfields[2]) return; gwy_app_undo_qcheckpointv(data, G_N_ELEMENTS(quarks), quarks); for (i = 0; i < G_N_ELEMENTS(dfields); i++) { if (dfields[i]) { gwy_data_field_set_xoffset(dfields[i], 0.0); gwy_data_field_set_yoffset(dfields[i], 0.0); gwy_data_field_data_changed(dfields[i]); } } gwy_app_channel_log_add_proc(data, id, id); }
static gboolean gsf_export(GwyContainer *container, const gchar *filename, G_GNUC_UNUSED GwyRunType mode, GError **error) { static const gchar zeroes[4] = { 0, 0, 0, 0 }; GString *header = NULL; gfloat *dfl = NULL; guint i, xres, yres, padding; gint id; GwyDataField *dfield; const gdouble *d; gdouble v; gchar *s; GwySIUnit *unit, *emptyunit; FILE *fh; gwy_app_data_browser_get_current(GWY_APP_DATA_FIELD, &dfield, GWY_APP_DATA_FIELD_ID, &id, 0); if (!dfield) { err_NO_CHANNEL_EXPORT(error); return FALSE; } if (!(fh = g_fopen(filename, "wb"))) { err_OPEN_WRITE(error); return FALSE; } xres = gwy_data_field_get_xres(dfield); yres = gwy_data_field_get_yres(dfield); header = g_string_new(MAGIC); g_string_append_printf(header, "XRes = %u\n", xres); g_string_append_printf(header, "YRes = %u\n", yres); append_num(header, "XReal", gwy_data_field_get_xreal(dfield)); append_num(header, "YReal", gwy_data_field_get_yreal(dfield)); if ((v = gwy_data_field_get_xoffset(dfield))) append_num(header, "XOffset", v); if ((v = gwy_data_field_get_yoffset(dfield))) append_num(header, "YOffset", v); emptyunit = gwy_si_unit_new(NULL); unit = gwy_data_field_get_si_unit_xy(dfield); if (!gwy_si_unit_equal(unit, emptyunit)) { s = gwy_si_unit_get_string(unit, GWY_SI_UNIT_FORMAT_PLAIN); g_string_append_printf(header, "XYUnits = %s\n", s); g_free(s); } unit = gwy_data_field_get_si_unit_z(dfield); if (!gwy_si_unit_equal(unit, emptyunit)) { s = gwy_si_unit_get_string(unit, GWY_SI_UNIT_FORMAT_PLAIN); g_string_append_printf(header, "ZUnits = %s\n", s); g_free(s); } g_object_unref(emptyunit); s = gwy_app_get_data_field_title(container, id); g_string_append_printf(header, "Title = %s\n", s); g_free(s); if (fwrite(header->str, 1, header->len, fh) != header->len) { err_WRITE(error); goto fail; } padding = 4 - (header->len % 4); if (fwrite(zeroes, 1, padding, fh) != padding) { err_WRITE(error); goto fail; } g_string_free(header, TRUE); header = NULL; dfl = g_new(gfloat, xres*yres); d = gwy_data_field_get_data_const(dfield); for (i = 0; i < xres*yres; i++) { union { guchar pp[4]; float f; } z; z.f = d[i]; #if (G_BYTE_ORDER == G_BIG_ENDIAN) GWY_SWAP(guchar, z.pp[0], z.pp[3]); GWY_SWAP(guchar, z.pp[1], z.pp[2]); #endif dfl[i] = z.f; } if (fwrite(dfl, sizeof(gfloat), xres*yres, fh) != xres*yres) { err_WRITE(error); goto fail; } g_free(dfl); fclose(fh); return TRUE; fail: if (fh) fclose(fh); g_unlink(filename); if (header) g_string_free(header, TRUE); g_free(dfl); return FALSE; }