/** * Serializes the document model according to the given document type * and creates a byte stream from it. * * @param p0 the destination (Hand over as reference!) * @param p1 the destination count * @param p2 the destination size * @param p3 the source * @param p4 the source count * @param p5 the type * @param p6 the type count */ void serialize(void* p0, void* p1, void* p2, const void* p3, const void* p4, const void* p5, const void* p6) { // The comparison result. int r = 0; if (r != 1) { compare_arrays(p5, p6, (void*) CYBOL_ABSTRACTION, (void*) CYBOL_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_xml(p0, p1, p2, p3, p4); } } if (r != 1) { compare_arrays(p5, p6, (void*) OPERATION_ABSTRACTION, (void*) OPERATION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_string(p0, p1, p2, p3, p4); } } if (r != 1) { compare_arrays(p5, p6, (void*) STRING_ABSTRACTION, (void*) STRING_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_string(p0, p1, p2, p3, p4); } } if (r != 1) { compare_arrays(p5, p6, (void*) BOOLEAN_ABSTRACTION, (void*) BOOLEAN_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_boolean(p0, p1, p2, p3, p4); } } if (r != 1) { compare_arrays(p5, p6, (void*) INTEGER_ABSTRACTION, (void*) INTEGER_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_integer(p0, p1, p2, p3, p4); } } if (r != 1) { compare_arrays(p5, p6, (void*) VECTOR_ABSTRACTION, (void*) VECTOR_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_vector(p0, p1, p2, p3, p4); } } if (r != 1) { compare_arrays(p5, p6, (void*) DOUBLE_ABSTRACTION, (void*) DOUBLE_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_double(p0, p1, p2, p3, p4); } } if (r != 1) { compare_arrays(p5, p6, (void*) FRACTION_ABSTRACTION, (void*) FRACTION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_fraction(p0, p1, p2, p3, p4); } } if (r != 1) { compare_arrays(p5, p6, (void*) COMPLEX_ABSTRACTION, (void*) COMPLEX_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_complex(p0, p1, p2, p3, p4); } } if (r != 1) { compare_arrays(p5, p6, (void*) TIME_ABSTRACTION, (void*) TIME_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY); if (r == 1) { serialize_time(p0, p1, p2, p3, p4); } } // // CONFIGURATION_ABSTRACTION // // CAUTION! Parameters of the internals memory MUST NOT be written // to the configuration file which was given at command line! // The CYBOI configuration file can only be edited MANUALLY. // //?? Later, distinguish file types according to abstraction, //?? for example xml, html, sxi, txt, rtf, //?? adl (from OpenEHR), KIF, ODL etc.! //?? For now, only the cybol file format is considered. }
int datafile_save(datafile *data, char *filename) { int ret = 0; FILE *out = fopen(filename, "w"); if (!out) return error("Error opening file %s", filename); // Write the file fprintf(out, "### tsreduce reduction data\n"); if (data->version) fprintf(out, "# Version: %d\n", data->version); if (data->frame_dir) fprintf(out, "# FrameDir: %s\n", data->frame_dir); if (data->frame_pattern) fprintf(out, "# FramePattern: %s\n", data->frame_pattern); if (data->bias_template) fprintf(out, "# BiasTemplate: %s\n", data->bias_template); if (data->dark_template) fprintf(out, "# DarkTemplate: %s\n", data->dark_template); if (data->flat_template) fprintf(out, "# FlatTemplate: %s\n", data->flat_template); if (data->reference_frame) fprintf(out, "# ReferenceFrame: %s\n", data->reference_frame); if (data->mmi_filter_sigma != MMI_FILTER_SIGMA_DEFAULT) fprintf(out, "# MMIFilterSigma: %d\n", data->mmi_filter_sigma); if (data->ratio_fit_degree != RATIO_FIT_DEGREE_DEFAULT) fprintf(out, "# RatioFitDegree: %d\n", data->ratio_fit_degree); if (data->plot_max_raw != PLOT_MAX_RAW_DEFAULT) fprintf(out, "# PlotMaxRaw: %g\n", data->plot_max_raw); if (data->plot_max_dft != PLOT_MAX_DFT_DEFAULT) fprintf(out, "# PlotMaxDft: %g\n", data->plot_max_dft); if (data->plot_min_uhz != PLOT_MIN_UHZ_DEFAULT) fprintf(out, "# PlotMinUhz: %g\n", data->plot_min_uhz); if (data->plot_max_uhz != PLOT_MAX_UHZ_DEFAULT) fprintf(out, "# PlotMaxUhz: %g\n", data->plot_max_uhz); if (data->plot_error_bars != PLOT_ERROR_BARS_DEFAULT) fprintf(out, "# PlotErrorBars: %d\n", data->plot_error_bars); if (data->plot_fwhm_smooth != PLOT_FWHM_SMOOTH_DEFAULT) fprintf(out, "# PlotFwhmSmooth: %hhd\n", data->plot_fwhm_smooth); if (data->ccd_gain != CCD_GAIN_DEFAULT) fprintf(out, "# CCDGain: %g\n", data->ccd_gain); if (data->ccd_readnoise != CCD_READNOISE_DEFAULT) fprintf(out, "# CCDReadNoise: %g\n", data->ccd_readnoise); if (data->ccd_platescale != CCD_PLATESCALE_DEFAULT) fprintf(out, "# CCDPlateScale: %g\n", data->ccd_platescale); if (data->reference_time.time) { char datetimebuf[24]; serialize_time(data->reference_time, datetimebuf); fprintf(out, "# ReferenceTime: %s\n", datetimebuf); } if (data->coord_ra) fprintf(out, "# RA: %s\n", data->coord_ra); if (data->coord_dec) fprintf(out, "# DEC: %s\n", data->coord_dec); fprintf(out, "### (x, y, Radius, Inner Sky Radius, Outer Sky Radius) [plot scale] - Label\n"); for (size_t i = 0; i < data->target_count; i++) { aperture *t = &data->targets[i].aperture; fprintf(out, "# Target: (%6.2f, %6.2f, %6.2f, %6.2f, %6.2f) [%.2f] - %s\n", t->x, t->y, t->r, t->s1, t->s2, data->targets[i].scale, data->targets[i].label); } if (data->num_blocked_ranges > 0) fprintf(out, "### (Start (s), End (s))\n"); for (size_t i = 0; i < data->num_blocked_ranges; i++) fprintf(out, "# BlockRange: (%g, %g)\n", data->blocked_ranges[i].x, data->blocked_ranges[i].y); if (data->num_ratio_offsets > 0) fprintf(out, "### (Start (s), End (s), offset)\n"); for (size_t i = 0; i < data->num_ratio_offsets; i++) fprintf(out, "# RatioOffset: (%g, %g, %g)\n", data->ratio_offsets[i].x, data->ratio_offsets[i].y, data->ratio_offsets[i].z); if (data->obs_start) { fprintf(out, "### Filename "); size_t padding = strlen(data->obs_start->filename); padding = (padding < 10) ? 0 : padding - 10; for (size_t i = 0; i < padding; i++) fprintf(out, " "); fprintf(out, "Mid Time"); for (size_t i = 0; i < data->target_count; i++) fprintf(out, " | Star Noise Sky x y FWHM "); fprintf(out, "\n"); fprintf(out, "### "); for (size_t i = 0; i < padding + 12; i++) fprintf(out, " "); fprintf(out, "(s) "); for (size_t i = 0; i < data->target_count; i++) fprintf(out, " | (ADU/s) (ADU/s) (ADU/s) (px) (px) (px) "); fprintf(out, "\n"); } // Ensure observations are sorted by increasing time struct observation **obs = malloc(data->obs_count*sizeof(struct observation *)); if (!obs) error_jump(allocation_error, ret, "Allocation failed for sorting array"); struct observation *o = data->obs_start; for (size_t i = 0; i < data->obs_count; i++) { obs[i] = o; o = o->next; } qsort(obs, data->obs_count, sizeof(struct observation *), compare_observation); for (size_t i = 0; i < data->obs_count; i++) { fprintf(out, "%10s ", obs[i]->filename); fprintf(out, "%9.3f ", obs[i]->time); for (size_t j = 0; j < data->target_count; j++) { fprintf(out, "%10.2f ", obs[i]->star[j]); fprintf(out, "%6.2f ", obs[i]->noise[j]); fprintf(out, "%9.2f ", obs[i]->sky[j]); fprintf(out, "%6.2f %6.2f ", obs[i]->pos[j].x, obs[i]->pos[j].y); fprintf(out, "%5.2f ", obs[i]->fwhm[j]); } fprintf(out, "\n"); } free(obs); allocation_error: fclose(out); return ret; }