static GwyDataField* read_data_field(const guchar *buffer, gint xres, gint yres, NetCDFType type) { GwyDataField *dfield; gdouble *data; gint i; dfield = gwy_data_field_new(xres, yres, 1.0, 1.0, FALSE); data = gwy_data_field_get_data(dfield); switch (type) { case NC_BYTE: case NC_CHAR: { const gint8 *d8 = (const gint8*)buffer; for (i = 0; i < xres*yres; i++) data[i] = d8[i]; } break; case NC_SHORT: { const gint16 *d16 = (const gint16*)buffer; for (i = 0; i < xres*yres; i++) data[i] = GINT16_FROM_BE(d16[i]); } break; case NC_INT: { const gint32 *d32 = (const gint32*)buffer; for (i = 0; i < xres*yres; i++) data[i] = GINT32_FROM_BE(d32[i]); } break; case NC_FLOAT: for (i = 0; i < xres*yres; i++) data[i] = gwy_get_gfloat_be(&buffer); break; case NC_DOUBLE: for (i = 0; i < xres*yres; i++) data[i] = gwy_get_gdouble_be(&buffer); break; default: g_return_val_if_reached(dfield); break; } return dfield; }
static GwySIUnit* read_real_size(const NetCDF *cdffile, const gchar *name, gdouble *real, gint *power10) { const NetCDFVar *var; const NetCDFAttr *attr; GwySIUnit *siunit; const guchar *p; gchar *s; *real = 1.0; *power10 = 0; if (!(var = cdffile_get_var(cdffile, name))) return NULL; /* * Warning: Madness ahead. * * Older GXSM files contain "AA" in "unit", that makes sense, as the units * are Angstroems. * * Newer GXSM files contain "nm" in "unit" though, in spite of the units * being still Angstroems. They seem to contain the real units in * "var_unit". The info field reads: * * This number is alwalys stored in Angstroem. Unit is used for user * display only. * * In addition they invented yet another Angstroem abbreviation: Ang. */ attr = cdffile_get_attr(var->attrs, var->nattrs, "var_unit"); if (!attr || attr->type != NC_CHAR) { attr = cdffile_get_attr(var->attrs, var->nattrs, "unit"); if (!attr || attr->type != NC_CHAR) return NULL; } if (!attr->nelems) s = NULL; else s = g_strndup(attr->values, attr->nelems); siunit = gwy_si_unit_new_parse(s, power10); g_free(s); p = (const guchar*)(cdffile->buffer + var->begin); if (var->type == NC_DOUBLE) *real = gwy_get_gdouble_be(&p); else if (var->type == NC_FLOAT) *real = gwy_get_gfloat_be(&p); else g_warning("Size is not a floating point number"); return siunit; }
static gboolean mprofile_read_header(const guchar *buffer, gsize size, MProFile *mprofile, GError **error) { const guchar *p; guint i; p = buffer; if (size < HEADER_SIZE + 2) { err_TOO_SHORT(error); return FALSE; } get_CHARARRAY(mprofile->magic, &p); if (memcmp(mprofile->magic, MAGIC, MAGIC_SIZE) != 0) { err_FILE_TYPE(error, "MetroPro"); return FALSE; } mprofile->header_format = gwy_get_guint16_be(&p); if (mprofile->header_format != 1) { err_UNSUPPORTED(error, "FormatVersion"); return FALSE; } mprofile->header_size = gwy_get_guint32_be(&p); gwy_debug("header_format: %d, header_size: %d", mprofile->header_format, mprofile->header_size); if (mprofile->header_size < 570) { g_set_error(error, GWY_MODULE_FILE_ERROR, GWY_MODULE_FILE_ERROR_DATA, _("File header is too short.")); return FALSE; } if (mprofile->header_size > size) { g_set_error(error, GWY_MODULE_FILE_ERROR, GWY_MODULE_FILE_ERROR_DATA, _("File header is larger than file.")); return FALSE; } mprofile->software_type = gwy_get_guint16_be(&p); get_CHARARRAY0(mprofile->software_date, &p); gwy_debug("software_type: %d, software_date: %s", mprofile->software_type, mprofile->software_date); mprofile->version_major = gwy_get_guint16_be(&p); mprofile->version_minor = gwy_get_guint16_be(&p); mprofile->version_micro = gwy_get_guint16_be(&p); gwy_debug("version: %d.%d.%d", mprofile->version_major, mprofile->version_minor, mprofile->version_micro); mprofile->intens_xoff = gwy_get_guint16_be(&p); mprofile->intens_yoff = gwy_get_guint16_be(&p); mprofile->intens_xres = gwy_get_guint16_be(&p); mprofile->intens_yres = gwy_get_guint16_be(&p); gwy_debug("INTENS xres: %d, yres: %d, xoff: %d, yoff: %d", mprofile->intens_xres, mprofile->intens_yres, mprofile->intens_xoff, mprofile->intens_yoff); mprofile->nbuckets = gwy_get_guint16_be(&p); mprofile->intens_range = gwy_get_guint16_be(&p); mprofile->intens_nbytes = gwy_get_guint32_be(&p); gwy_debug("intens_nbytes: %d, expecting: %d", mprofile->intens_nbytes, 2*mprofile->intens_xres*mprofile->intens_yres*mprofile->nbuckets); mprofile->phase_xoff = gwy_get_guint16_be(&p); mprofile->phase_yoff = gwy_get_guint16_be(&p); mprofile->phase_xres = gwy_get_guint16_be(&p); mprofile->phase_yres = gwy_get_guint16_be(&p); gwy_debug("PHASE xres: %d, yres: %d, xoff: %d, yoff: %d", mprofile->phase_xres, mprofile->phase_yres, mprofile->phase_xoff, mprofile->phase_yoff); mprofile->phase_nbytes = gwy_get_guint32_be(&p); gwy_debug("phase_nbytes: %d, expecting: %d", mprofile->phase_nbytes, 4*mprofile->phase_xres*mprofile->phase_yres); mprofile->timestamp = gwy_get_guint32_be(&p); get_CHARARRAY0(mprofile->comment, &p); gwy_debug("comment: %s", mprofile->comment); mprofile->source = gwy_get_guint16_be(&p); mprofile->scale_factor = gwy_get_gfloat_be(&p); mprofile->wavelength_in = gwy_get_gfloat_be(&p); mprofile->numeric_aperture = gwy_get_gfloat_be(&p); mprofile->obliquity_factor = gwy_get_gfloat_be(&p); mprofile->magnification = gwy_get_gfloat_be(&p); mprofile->camera_res = gwy_get_gfloat_be(&p); mprofile->acquire_mode = gwy_get_guint16_be(&p); gwy_debug("acquire_mode: %d", mprofile->acquire_mode); mprofile->intens_avgs = gwy_get_guint16_be(&p); if (!mprofile->intens_avgs) mprofile->intens_avgs = 1; mprofile->pzt_cal = gwy_get_guint16_be(&p); mprofile->pzt_gain_tolerance = gwy_get_guint16_be(&p); mprofile->pzt_gain = gwy_get_guint16_be(&p); mprofile->part_thickness = gwy_get_gfloat_be(&p); mprofile->agc = gwy_get_guint16_be(&p); mprofile->target_range = gwy_get_gfloat_be(&p); p += 2; mprofile->min_mod = gwy_get_guint32_be(&p); mprofile->min_mod_pts = gwy_get_guint32_be(&p); mprofile->phase_res = gwy_get_guint16_be(&p); mprofile->min_area_size = gwy_get_guint32_be(&p); mprofile->discont_action = gwy_get_guint16_be(&p); mprofile->discont_filter = gwy_get_gfloat_be(&p); mprofile->connection_order = gwy_get_guint16_be(&p); mprofile->data_inverted = gwy_get_guint16_be(&p); mprofile->camera_width = gwy_get_guint16_be(&p); mprofile->camera_height = gwy_get_guint16_be(&p); mprofile->system_type = gwy_get_guint16_be(&p); mprofile->system_board = gwy_get_guint16_be(&p); mprofile->system_serial = gwy_get_guint16_be(&p); mprofile->instrument_id = gwy_get_guint16_be(&p); get_CHARARRAY0(mprofile->objective_name, &p); get_CHARARRAY0(mprofile->part_num, &p); gwy_debug("part_num: %s", mprofile->part_num); mprofile->code_vtype = gwy_get_guint16_be(&p); mprofile->phase_avgs = gwy_get_guint16_be(&p); mprofile->subtract_sys_err = gwy_get_guint16_be(&p); p += 16; get_CHARARRAY0(mprofile->part_ser_num, &p); mprofile->refactive_index = gwy_get_gfloat_be(&p); mprofile->remove_tilt_bias = gwy_get_guint16_be(&p); mprofile->remove_fringes = gwy_get_guint16_be(&p); mprofile->max_area_size = gwy_get_guint32_be(&p); mprofile->setup_type = gwy_get_guint16_be(&p); p += 2; mprofile->pre_connect_filter = gwy_get_gfloat_be(&p); mprofile->wavelength2 = gwy_get_gfloat_be(&p); mprofile->wavelength_fold = gwy_get_guint16_be(&p); mprofile->wavelength1 = gwy_get_gfloat_be(&p); mprofile->wavelength3 = gwy_get_gfloat_be(&p); mprofile->wavelength4 = gwy_get_gfloat_be(&p); get_CHARARRAY0(mprofile->wavelength_select, &p); mprofile->fda_res = gwy_get_guint16_be(&p); get_CHARARRAY0(mprofile->scan_description, &p); gwy_debug("scan_description: %s", mprofile->scan_description); mprofile->nfiducials = gwy_get_guint16_be(&p); for (i = 0; i < G_N_ELEMENTS(mprofile->fiducials); i++) mprofile->fiducials[i] = gwy_get_gfloat_be(&p); mprofile->pixel_width = gwy_get_gfloat_be(&p); mprofile->pixel_height = gwy_get_gfloat_be(&p); mprofile->exit_pupil_diam = gwy_get_gfloat_be(&p); mprofile->light_level_pct = gwy_get_gfloat_be(&p); mprofile->coords_state = gwy_get_guint32_be(&p); mprofile->xpos = gwy_get_gfloat_be(&p); mprofile->ypos = gwy_get_gfloat_be(&p); mprofile->zpos = gwy_get_gfloat_be(&p); mprofile->xrot = gwy_get_gfloat_be(&p); mprofile->yrot = gwy_get_gfloat_be(&p); mprofile->zrot = gwy_get_gfloat_be(&p); mprofile->coherence_mode = gwy_get_guint16_be(&p); mprofile->surface_filter = gwy_get_guint16_be(&p); get_CHARARRAY0(mprofile->sys_err_file, &p); get_CHARARRAY0(mprofile->zoom_desc, &p); return TRUE; }
static gboolean read_parameters(const guchar *buffer, guint size, StmprgFile *stmprgfile, GError **error) { const guchar *p = buffer + MAGIC_SIZE; StmprgMainfield *mainfield; StmprgControl *control; StmprgOtherControl *other_control; gwy_debug("tp file size is %u, expecting %u", size, PARAM_SIZE); if (size < PARAM_SIZE) { g_set_error(error, GWY_MODULE_FILE_ERROR, GWY_MODULE_FILE_ERROR_DATA, _("Parameter file is too short.")); return FALSE; } /* mainfield */ mainfield = &stmprgfile->mainfield; mainfield->start_x = gwy_get_gfloat_be(&p); mainfield->start_y = gwy_get_gfloat_be(&p); mainfield->field_x = gwy_get_gfloat_be(&p); mainfield->field_y = gwy_get_gfloat_be(&p); mainfield->inc_x = gwy_get_gfloat_be(&p); mainfield->inc_y = gwy_get_gfloat_be(&p); mainfield->points = gwy_get_gint32_be(&p); mainfield->lines = gwy_get_gint32_be(&p); mainfield->angle = gwy_get_gfloat_be(&p); mainfield->sol_x = gwy_get_gfloat_be(&p); mainfield->sol_y = gwy_get_gfloat_be(&p); mainfield->sol_z = gwy_get_gfloat_be(&p); mainfield->sol_ext1 = gwy_get_gfloat_be(&p); mainfield->sol_ext2 = gwy_get_gfloat_be(&p); mainfield->sol_h = gwy_get_gfloat_be(&p); g_assert(p - buffer == MAGIC_SIZE + MAINFIELD_SIZE); gwy_debug("start_x = %g", mainfield->start_x); gwy_debug("start_y = %g", mainfield->start_y); gwy_debug("field_x = %g", mainfield->field_x); gwy_debug("field_y = %g", mainfield->field_y); gwy_debug("inc_x = %g", mainfield->inc_x); gwy_debug("inc_y = %g", mainfield->inc_y); gwy_debug("points = %d", mainfield->points); gwy_debug("lines = %d", mainfield->lines); gwy_debug("angle = %g", mainfield->angle); gwy_debug("sol_x = %g", mainfield->sol_x); gwy_debug("sol_y = %g", mainfield->sol_y); gwy_debug("sol_z = %g", mainfield->sol_z); gwy_debug("sol_ext1 = %g", mainfield->sol_ext1); gwy_debug("sol_ext2 = %g", mainfield->sol_ext2); gwy_debug("sol_h = %g", mainfield->sol_h); if (err_DIMENSION(error, mainfield->points) || err_DIMENSION(error, mainfield->lines)) return FALSE; /* control */ control = &stmprgfile->control; control->mode = *(p++); control->channel1 = *(p++); control->channel2 = *(p++); control->channel3 = *(p++); control->spectr = *(p++); control->cfree = *(p++); control->type = gwy_get_gint16_be(&p); control->steps_x = gwy_get_gint32_be(&p); control->steps_y = gwy_get_gint32_be(&p); control->dac_speed = gwy_get_gint32_be(&p); control->poi_inc = gwy_get_gfloat_be(&p); control->lin_inc = gwy_get_gfloat_be(&p); control->ad1_reads = gwy_get_gint32_be(&p); control->ad2_reads = gwy_get_gint32_be(&p); control->ad3_reads = gwy_get_gint32_be(&p); control->analog_ave = gwy_get_gint32_be(&p); control->speed = gwy_get_gint32_be(&p); control->voltage = gwy_get_gfloat_be(&p); control->voltage_l = gwy_get_gfloat_be(&p); control->voltage_r = gwy_get_gfloat_be(&p); control->volt_flag = gwy_get_gint32_be(&p); control->volt_region = gwy_get_gint32_be(&p); control->current = gwy_get_gfloat_be(&p); control->current_l = gwy_get_gfloat_be(&p); control->current_r = gwy_get_gfloat_be(&p); control->curr_flag = gwy_get_gint32_be(&p); control->curr_region = gwy_get_gint32_be(&p); control->spec_lstart = gwy_get_gfloat_be(&p); control->spec_lend = gwy_get_gfloat_be(&p); control->spec_linc = gwy_get_gfloat_be(&p); control->spec_lsteps = gwy_get_guint32_be(&p); control->spec_rstart = gwy_get_gfloat_be(&p); control->spec_rend = gwy_get_gfloat_be(&p); control->spec_rinc = gwy_get_gfloat_be(&p); control->spec_rsteps = gwy_get_guint32_be(&p); control->version = gwy_get_gfloat_be(&p); control->free_lend = gwy_get_gfloat_be(&p); control->free_linc = gwy_get_gfloat_be(&p); control->free_lsteps = gwy_get_guint32_be(&p); control->free_rstart = gwy_get_gfloat_be(&p); control->free_rend = gwy_get_gfloat_be(&p); control->free_rinc = gwy_get_gfloat_be(&p); control->free_rsteps = gwy_get_guint32_be(&p); control->timer1 = gwy_get_guint32_be(&p); control->timer2 = gwy_get_guint32_be(&p); control->timer3 = gwy_get_guint32_be(&p); control->timer4 = gwy_get_guint32_be(&p); control->m_time = gwy_get_guint32_be(&p); control->u_divider = gwy_get_gfloat_be(&p); control->fb_control = gwy_get_gint32_be(&p); control->fb_delay = gwy_get_gint32_be(&p); control->point_time = gwy_get_gint32_be(&p); control->spec_time = gwy_get_gint32_be(&p); control->spec_delay = gwy_get_gint32_be(&p); control->fm = gwy_get_gint16_be(&p); control->fm_prgmode = gwy_get_gint16_be(&p); control->fm_channel1 = gwy_get_gint32_be(&p); control->fm_channel2 = gwy_get_gint32_be(&p); control->fm_wait = gwy_get_gint32_be(&p); control->fm_frames = gwy_get_gint32_be(&p); control->fm_delay = gwy_get_gint16_be(&p); control->spectr_edit = gwy_get_gint16_be(&p); control->fm_speed = gwy_get_gint16_be(&p); control->fm_reads = gwy_get_gint16_be(&p); g_assert(p - buffer == MAGIC_SIZE + MAINFIELD_SIZE + CONTROL_SIZE); gwy_debug("type = %d", control->type); gwy_debug("steps_x = %d", control->steps_x); gwy_debug("steps_y = %d", control->steps_y); gwy_debug("dac_speed = %d", control->dac_speed); gwy_debug("poi_inc = %g", control->poi_inc); gwy_debug("lin_inc = %g", control->lin_inc); gwy_debug("ad1_reads = %d", control->ad1_reads); gwy_debug("ad2_reads = %d", control->ad2_reads); gwy_debug("ad3_reads = %d", control->ad3_reads); gwy_debug("analog_ave = %d", control->analog_ave); gwy_debug("speed = %d", control->speed); gwy_debug("voltage = %g", control->voltage); gwy_debug("voltage_l = %g", control->voltage_l); gwy_debug("voltage_r = %g", control->voltage_r); gwy_debug("volt_flag = %d", control->volt_flag); gwy_debug("volt_region = %d", control->volt_region); gwy_debug("current = %g", control->current); gwy_debug("current_l = %g", control->current_l); gwy_debug("current_r = %g", control->current_r); gwy_debug("curr_flag = %d", control->curr_flag); gwy_debug("curr_region = %d", control->curr_region); gwy_debug("spec_lstart = %g", control->spec_lstart); gwy_debug("spec_lend = %g", control->spec_lend); gwy_debug("spec_linc = %g", control->spec_linc); gwy_debug("spec_lsteps = %u", control->spec_lsteps); gwy_debug("spec_rstart = %g", control->spec_rstart); gwy_debug("spec_rend = %g", control->spec_rend); gwy_debug("spec_rinc = %g", control->spec_rinc); gwy_debug("spec_rsteps = %u", control->spec_rsteps); gwy_debug("version = %g", control->version); gwy_debug("free_lend = %g", control->free_lend); gwy_debug("free_linc = %g", control->free_linc); gwy_debug("free_lsteps = %u", control->free_lsteps); gwy_debug("free_rstart = %g", control->free_rstart); gwy_debug("free_rend = %g", control->free_rend); gwy_debug("free_rinc = %g", control->free_rinc); gwy_debug("free_rsteps = %u", control->free_rsteps); gwy_debug("timer1 = %u", control->timer1); gwy_debug("timer2 = %u", control->timer2); gwy_debug("timer3 = %u", control->timer3); gwy_debug("timer4 = %u", control->timer4); gwy_debug("m_time = %u", control->m_time); gwy_debug("u_divider = %g", control->u_divider); gwy_debug("fb_control = %d", control->fb_control); gwy_debug("fb_delay = %d", control->fb_delay); gwy_debug("point_time = %d", control->point_time); gwy_debug("spec_time = %d", control->spec_time); gwy_debug("spec_delay = %d", control->spec_delay); gwy_debug("fm = %d", control->fm); gwy_debug("fm_prgmode = %d", control->fm_prgmode); gwy_debug("fm_channel1 = %d", control->fm_channel1); gwy_debug("fm_channel2 = %d", control->fm_channel2); gwy_debug("fm_wait = %d", control->fm_wait); gwy_debug("fm_frames = %d", control->fm_frames); gwy_debug("fm_delay = %d", control->fm_delay); gwy_debug("spectr_edit = %d", control->spectr_edit); gwy_debug("fm_speed = %d", control->fm_speed); gwy_debug("fm_reads = %d", control->fm_reads); /* other_control */ other_control = &stmprgfile->other_control; other_control->version = gwy_get_gfloat_be(&p); other_control->adc_data_l = gwy_get_gint32_be(&p); other_control->adc_data_r = gwy_get_gint32_be(&p); other_control->first_zp = gwy_get_gint16_be(&p); other_control->last_zp = gwy_get_gint16_be(&p); other_control->zdrift = gwy_get_gfloat_be(&p); other_control->savememory = gwy_get_gint32_be(&p); get_CHARARRAY0(other_control->date, &p); get_CHARARRAY0(other_control->comment, &p); get_CHARARRAY0(other_control->username, &p); get_CHARARRAY0(other_control->macro_file, &p); get_CHARARRAY0(other_control->cext_a, &p); get_CHARARRAY0(other_control->cext_b, &p); other_control->contscan = gwy_get_gint32_be(&p); other_control->spec_loop = gwy_get_gint32_be(&p); other_control->ext_c = gwy_get_gint32_be(&p); other_control->fm_zlift = gwy_get_gfloat_be(&p); other_control->ext_a = gwy_get_gint32_be(&p); other_control->vme_release = gwy_get_gfloat_be(&p); g_assert(p - buffer == PARAM_SIZE); gwy_debug("version = %g", other_control->version); gwy_debug("adc_data_l = %d", other_control->adc_data_l); gwy_debug("adc_data_r = %d", other_control->adc_data_r); gwy_debug("first_zp = %d", other_control->first_zp); gwy_debug("last_zp = %d", other_control->last_zp); gwy_debug("zdrift = %g", other_control->zdrift); gwy_debug("savememory = %d", other_control->savememory); gwy_debug("date = %s", other_control->date); gwy_debug("comment = %s", other_control->comment); gwy_debug("username = %s", other_control->username); gwy_debug("macro_file = %s", other_control->macro_file); gwy_debug("cext_a = %s", other_control->cext_a); gwy_debug("cext_b = %s", other_control->cext_b); gwy_debug("contscan = %d", other_control->contscan); gwy_debug("spec_loop = %d", other_control->spec_loop); gwy_debug("ext_c = %d", other_control->ext_c); gwy_debug("fm_zlift = %g", other_control->fm_zlift); gwy_debug("ext_a = %d", other_control->ext_a); gwy_debug("vme_release = %g", other_control->vme_release); return TRUE; }