static void gwy_spectra_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GwySpectra *spectra = GWY_SPECTRA(object); switch (prop_id) { case PROP_TITLE: gwy_spectra_set_title(spectra, g_value_get_string(value)); break; case PROP_SPECTRUM_X_LABEL: gwy_spectra_set_spectrum_x_label(spectra, g_value_get_string(value)); break; case PROP_SPECTRUM_Y_LABEL: gwy_spectra_set_spectrum_y_label(spectra, g_value_get_string(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
static GwySpectra* rhkspm32_read_spectra(RHKPage *rhkpage) { guint i, j; gdouble *data; GwySIUnit *siunit = NULL; GwyDataLine *dline; GwySpectra *spectra = NULL; GPtrArray *spectrum = NULL; // i'm leaving this alone, though it probably doesn't make sense, // and i should just create graphs straight away - but in case of // future use, i'll just convert the data later to graphs // xres stores number of data points per spectra, // yres stores the number of spectra // reading data gwy_debug("rhk-spm32: %d spectra in this page\n", rhkpage->yres); for (i = 0; i < rhkpage->yres; i++) { dline = gwy_data_line_new(rhkpage->xres, rhkpage->x.scale, FALSE); gwy_data_line_set_offset(dline, (rhkpage->x.offset)); data = gwy_data_line_get_data(dline); // store line data in physical units - which are the z values, not y if ((rhkpage->data_type) == RHK_DATA_INT16) { const guint16 *p = (const guint16*)(rhkpage->buffer + rhkpage->data_offset); for (j = 0; j < rhkpage->xres; j++) { data[j] = GINT16_FROM_LE(p[i*(rhkpage->xres) + j]) *(rhkpage->z.scale)+(rhkpage->z.offset); } } else if ((rhkpage->data_type) == RHK_DATA_SINGLE) { const guchar *p = (const guchar*)(rhkpage->buffer + rhkpage->data_offset); for (j = 0; j < rhkpage->xres; j++) { data[j] = gwy_get_gfloat_le(&p)*rhkpage->z.scale + rhkpage->z.offset; } } siunit = gwy_si_unit_new(rhkpage->x.units); gwy_data_line_set_si_unit_x(dline, siunit); g_object_unref(siunit); // the y units (and data) for a 1D graph are stored in Z in the rhk // spm32 format! /* Fix "/\xfbHz" to "/Hz". * XXX: It might be still wrong as the strange character might mean * sqrt. */ if (g_str_has_suffix(rhkpage->z.units, "/\xfbHz")) { gchar *s = gwy_strkill(g_strdup(rhkpage->z.units), "\xfb"); siunit = gwy_si_unit_new(s); g_free(s); } else siunit = gwy_si_unit_new(rhkpage->z.units); gwy_data_line_set_si_unit_y(dline, siunit); g_object_unref(siunit); if (!spectrum) spectrum = g_ptr_array_sized_new(rhkpage->yres); g_ptr_array_add(spectrum, dline); } gwy_debug("rhk-spm32: finished parsing sps data\n"); spectra = gwy_spectra_new(); for (i = 0; i < rhkpage->yres; i++) { dline = g_ptr_array_index(spectrum, i); // since RHK spm32 does not record where it took the spectra, // i'm setting these to zero gwy_spectra_add_spectrum(spectra, dline, 0, 0); g_object_unref(dline); } gwy_spectra_set_title(spectra, rhkpage->label); if (spectrum) g_ptr_array_free(spectrum, TRUE); return spectra; }
static GwyContainer* omicron_load(const gchar *filename, G_GNUC_UNUSED GwyRunType mode, GError **error) { OmicronFile ofile; GwyContainer *container = NULL, *meta; gchar *text = NULL; GError *err = NULL; GwyDataField *dfield = NULL; GwySpectra *spectra = NULL; gchar key[32]; guint i; /* @text must not be destroyed while @ofile is still in used because * all strings are only references there */ if (!g_file_get_contents(filename, &text, NULL, &err)) { err_GET_FILE_CONTENTS(error, &err); return NULL; } gwy_clear(&ofile, 1); ofile.filename = filename; if (!omicron_read_header(text, &ofile, error)) goto fail; if (!ofile.topo_channels || !ofile.topo_channels->len) { err_NO_DATA(error); goto fail; } container = gwy_container_new(); /* First Load the Topographic Data */ for (i = 0; i < ofile.topo_channels->len; i++) { OmicronTopoChannel *channel; channel = g_ptr_array_index(ofile.topo_channels, i); dfield = omicron_read_data(&ofile, channel, error); if (!dfield) { gwy_object_unref(container); goto fail; } g_snprintf(key, sizeof(key), "/%u/data", i); gwy_container_set_object_by_name(container, key, dfield); g_object_unref(dfield); if (channel->name) { gchar *s; g_snprintf(key, sizeof(key), "/%u/data/title", i); if (channel->scandir == SCAN_FORWARD) s = g_strdup_printf("%s (Forward)", channel->name); else if (channel->scandir == SCAN_BACKWARD) s = g_strdup_printf("%s (Backward)", channel->name); else s = g_strdup(channel->name); gwy_container_set_string_by_name(container, key, s); } if ((meta = omicron_make_meta(&ofile))) { g_snprintf(key, sizeof(key), "/%u/meta", i); gwy_container_set_object_by_name(container, key, meta); g_object_unref(meta); } } /* Then load the spectroscopy data. */ /* * There are two types of spectroscopy file: * * a) Single Point Spectroscopy Files * Single point which is stored by SCALA as an ascii file. Any number of * single point spectrums may be aquired, but the number is normally * quite small. These files are identified by their filename *.cs[0..3] * * b) Binary Spectroscopy Files * When large numbers of spectra are aquired on a regular grid they are * stored in BE binary. These data are aquired during the scan, and so * can be aquired during the forward scan or the backward scan. * * Forwards scan files can be indentified from their filename *.sf[0..3] * Backward scan files can be indentified from their filename *.sb[0..3] */ if (ofile.spectro_channels) { for (i = 0; i < ofile.spectro_channels->len; i++) { OmicronSpectroChannel *channel; channel = g_ptr_array_index(ofile.spectro_channels, i); if (omicron_has_extension(channel->filename, "cs")) { gchar *t; GQuark quark; spectra = omicron_read_cs_data(&ofile, channel, error); if (!spectra) { gwy_object_unref(container); goto fail; } if (!gwy_spectra_get_n_spectra(spectra)) { gwy_debug("Spectra %u is empty, ignoring", i); g_object_unref(spectra); continue; } /* FIXME */ t = g_strconcat(channel->chan, "-", channel->param, NULL); gwy_spectra_set_title(spectra, t); g_free(t); quark = gwy_app_get_spectra_key_for_id(i); gwy_container_set_object(container, quark, spectra); g_object_unref(spectra); } else if (omicron_has_extension(channel->filename, "sf") || omicron_has_extension(channel->filename, "sb")) { /* FIXME */ } else { g_warning("Cannot determine spectra type of %s", channel->filename); } } } fail: omicron_file_free(&ofile); g_free(text); return container; }