Example #1
0
static void free_device_data(oskar_Simulator* h, int* status)
{
    int i;
    if (!h->d) return;
    for (i = 0; i < h->num_devices; ++i)
    {
        DeviceData* d = &(h->d[i]);
        if (!d) continue;
        if (i < h->num_gpus)
            oskar_device_set(h->gpu_ids[i], status);
        oskar_timer_free(d->tmr_compute);
        oskar_timer_free(d->tmr_copy);
        oskar_timer_free(d->tmr_clip);
        oskar_timer_free(d->tmr_E);
        oskar_timer_free(d->tmr_K);
        oskar_timer_free(d->tmr_join);
        oskar_timer_free(d->tmr_correlate);
        oskar_vis_block_free(d->vis_block_cpu[0], status);
        oskar_vis_block_free(d->vis_block_cpu[1], status);
        oskar_vis_block_free(d->vis_block, status);
        oskar_mem_free(d->u, status);
        oskar_mem_free(d->v, status);
        oskar_mem_free(d->w, status);
        oskar_sky_free(d->chunk, status);
        oskar_sky_free(d->chunk_clip, status);
        oskar_telescope_free(d->tel, status);
        oskar_station_work_free(d->station_work, status);
        oskar_jones_free(d->J, status);
        oskar_jones_free(d->E, status);
        oskar_jones_free(d->K, status);
        oskar_jones_free(d->R, status);
        memset(d, 0, sizeof(DeviceData));
    }
}
Example #2
0
static void vis_block_free(PyObject* capsule)
{
    int status = 0;
    oskar_vis_block_free((oskar_VisBlock*) get_handle(capsule, name), &status);
}
Example #3
0
/*
 * Translation layer from new file format to old structure.
 * This will be deleted when the old oskar_Vis structure is fully retired.
 */
oskar_Vis* oskar_vis_read_new(oskar_Binary* h, int* status)
{
    oskar_VisHeader* hdr = 0;
    oskar_VisBlock* blk = 0;
    oskar_Vis* vis = 0;
    oskar_Mem* amp = 0;
    const oskar_Mem* xcorr = 0;
    int amp_type, max_times_per_block, num_channels, num_stations, num_times;
    int i, num_blocks;
    double freq_ref_hz, freq_inc_hz, time_ref_mjd_utc, time_inc_sec;

    /* Try to read the new header. */
    hdr = oskar_vis_header_read(h, status);
    if (*status)
    {
        oskar_vis_header_free(hdr, status);
        return 0;
    }

    /* Create the old vis structure. */
    amp_type = oskar_vis_header_amp_type(hdr);
    max_times_per_block = oskar_vis_header_max_times_per_block(hdr);
    num_channels = oskar_vis_header_num_channels_total(hdr);
    num_stations = oskar_vis_header_num_stations(hdr);
    num_times = oskar_vis_header_num_times_total(hdr);
    vis = oskar_vis_create(amp_type, OSKAR_CPU, num_channels, num_times,
            num_stations, status);
    if (*status)
    {
        oskar_vis_header_free(hdr, status);
        oskar_vis_free(vis, status);
        return 0;
    }

    /* Copy station coordinates and metadata. */
    freq_ref_hz = oskar_vis_header_freq_start_hz(hdr);
    freq_inc_hz = oskar_vis_header_freq_inc_hz(hdr);
    time_ref_mjd_utc = oskar_vis_header_time_start_mjd_utc(hdr);
    time_inc_sec = oskar_vis_header_time_inc_sec(hdr);
    oskar_mem_copy(oskar_vis_station_x_offset_ecef_metres(vis),
            oskar_vis_header_station_x_offset_ecef_metres_const(hdr), status);
    oskar_mem_copy(oskar_vis_station_y_offset_ecef_metres(vis),
            oskar_vis_header_station_y_offset_ecef_metres_const(hdr), status);
    oskar_mem_copy(oskar_vis_station_z_offset_ecef_metres(vis),
            oskar_vis_header_station_z_offset_ecef_metres_const(hdr), status);
    oskar_mem_copy(oskar_vis_settings(vis),
            oskar_vis_header_settings_const(hdr), status);
    oskar_mem_copy(oskar_vis_telescope_path(vis),
            oskar_vis_header_telescope_path_const(hdr), status);
    oskar_vis_set_channel_bandwidth_hz(vis,
            oskar_vis_header_channel_bandwidth_hz(hdr));
    oskar_vis_set_freq_inc_hz(vis, freq_inc_hz);
    oskar_vis_set_freq_start_hz(vis, freq_ref_hz);
    oskar_vis_set_phase_centre(vis,
            oskar_vis_header_phase_centre_ra_deg(hdr),
            oskar_vis_header_phase_centre_dec_deg(hdr));
    oskar_vis_set_telescope_position(vis,
            oskar_vis_header_telescope_lon_deg(hdr),
            oskar_vis_header_telescope_lat_deg(hdr),
            oskar_vis_header_telescope_alt_metres(hdr));
    oskar_vis_set_time_average_sec(vis,
            oskar_vis_header_time_average_sec(hdr));
    oskar_vis_set_time_inc_sec(vis, time_inc_sec);
    oskar_vis_set_time_start_mjd_utc(vis, time_ref_mjd_utc);

    /* Create a visibility block to read into. */
    blk = oskar_vis_block_create_from_header(OSKAR_CPU, hdr, status);
    amp = oskar_vis_amplitude(vis);
    xcorr = oskar_vis_block_cross_correlations_const(blk);

    /* Work out the number of blocks. */
    num_blocks = (num_times + max_times_per_block - 1) / max_times_per_block;
    for (i = 0; i < num_blocks; ++i)
    {
        int block_length, num_baselines, time_offset, total_baselines, t, c;

        /* Read the block. */
        oskar_vis_block_read(blk, hdr, h, i, status);
        num_baselines = oskar_vis_block_num_baselines(blk);
        block_length = oskar_vis_block_num_times(blk);

        /* Copy the baseline coordinate data. */
        time_offset = i * max_times_per_block * num_baselines;
        total_baselines = num_baselines * block_length;
        oskar_mem_copy_contents(oskar_vis_baseline_uu_metres(vis),
                oskar_vis_block_baseline_uu_metres_const(blk),
                time_offset, 0, total_baselines, status);
        oskar_mem_copy_contents(oskar_vis_baseline_vv_metres(vis),
                oskar_vis_block_baseline_vv_metres_const(blk),
                time_offset, 0, total_baselines, status);
        oskar_mem_copy_contents(oskar_vis_baseline_ww_metres(vis),
                oskar_vis_block_baseline_ww_metres_const(blk),
                time_offset, 0, total_baselines, status);

        /* Fill the array in the old dimension order. */
        for (t = 0; t < block_length; ++t)
        {
            for (c = 0; c < num_channels; ++c)
            {
                oskar_mem_copy_contents(amp, xcorr, num_baselines *
                        (c * num_times + i * max_times_per_block + t),
                        num_baselines * (t * num_channels + c),
                        num_baselines, status);
            }
        }
    }

    /* Clean up and return. */
    oskar_vis_block_free(blk, status);
    oskar_vis_header_free(hdr, status);
    return vis;
}