Exemplo n.º 1
0
//TODO Add header
void Image::output_global_image(std::string dir, std::string prefix) {
		
	// Create global image
	double g_image[parameters.npixels[0]][parameters.npixels[1]];
		
	//Could be reduced to a single MPI_Reduce call to improve speed if needed
	for (int i = 0; i < parameters.npixels[0]; i++) {
		para::global_sum(image[i], g_image[i], parameters.npixels[1]);
	}
	
	if (para::get_process_rank() == 0) {
		std::ofstream fout;
		std::string fname = construct_filename(dir, prefix, true);
		fout.open(fname.c_str());
		if (fout.good()) {
			for (int j = 0; j < parameters.npixels[1]; j++) {
				for (int i = 0; i < parameters.npixels[0]; i++) {
					fout << i << "\t" << j << "\t" << g_image[i][j] << "\n";
				}
			}
			fout.close();
		} else {
			logs::err << "Could not open output file: " << fname << "\n";
		}
	}
	
}
static void new_text_file(oskar_BeamPattern* h, int data_product_type,
        int stokes_in, int stokes_out, int i_station, int time_average,
        int channel_average, int* status)
{
    int i;
    char* name;
    FILE* f;
    if (*status) return;

    /* Check polarisation type is possible. */
    if ((stokes_in > I || stokes_out > I) && h->pol_mode != OSKAR_POL_MODE_FULL)
        return;

    /* Construct the filename. */
    name = construct_filename(h, data_product_type, stokes_in, stokes_out,
            i_station, time_average, channel_average, "txt");

    /* Open the file. */
    f = fopen(name, "w");
    if (!f)
    {
        *status = OSKAR_ERR_FILE_IO;
        free(name);
        return;
    }
    if (i_station >= 0)
        fprintf(f, "# Beam pixel list for station %d\n",
                h->station_ids[i_station]);
    else
        fprintf(f, "# Beam pixel list for telescope (interferometer)\n");
    fprintf(f, "# Filename is '%s'\n", name);
    fprintf(f, "# Dimension order (slowest to fastest) is:\n");
    if (h->average_single_axis != 'T')
        fprintf(f, "#     [pixel chunk], [time], [channel], [pixel index]\n");
    else
        fprintf(f, "#     [pixel chunk], [channel], [time], [pixel index]\n");
    fprintf(f, "# Number of pixel chunks: %d\n", h->num_chunks);
    fprintf(f, "# Number of times (output): %d\n",
            time_average ? 1 : h->num_time_steps);
    fprintf(f, "# Number of channels (output): %d\n",
            channel_average ? 1 : h->num_channels);
    fprintf(f, "# Maximum pixel chunk size: %d\n", h->max_chunk_size);
    fprintf(f, "# Total number of pixels: %d\n", h->num_pixels);
    i = data_product_index(h, data_product_type, stokes_in, stokes_out,
            i_station, time_average, channel_average);
    h->data_products[i].text_file = f;
    free(name);
}
Exemplo n.º 3
0
//x axes is inner loop so a 1D array of pixel values can be reshaped more easily
void Image::output_local_image(std::string dir, std::string prefix) {
	std::ofstream fout;
	std::string fname = construct_filename(dir, prefix, false);
			
	fout.open(fname.c_str());
	if (fout.good()) {
		for (int j = 0; j < parameters.npixels[1]; j++) {
			for (int i = 0; i < parameters.npixels[0]; i++) {
				fout << i << "\t" << j << "\t" << image[i][j] << "\n";
			}				
		}
		fout.close();
	} else {
		logs::err << "Could not open output file " << fname << "\n";
	}		
}
Exemplo n.º 4
0
RSI::RSI(vector<int> prices, int d, string file, int index_1)
	      : duration(d), index(index_1){
	stock = 0;
	asset = 0.0;
	average = 0.0;
	total_trade = 0;
	int start = index_1 - duration;
	construct_filename(file);
	vector<int>::iterator it = prices.begin();
	it = it + start;
	for(int i = 0; i < duration; i++){
		past_Price.push_back(*it);
		it++;
	}
	close = prices.at(index);	
	calc_RS();
	calc_RSI();
}
static void new_fits_file(oskar_BeamPattern* h, int data_product_type,
        int stokes_in, int stokes_out, int i_station, int time_average,
        int channel_average, int* status)
{
    int i, horizon_mode;
    char* name;
    fitsfile* f;
    if (*status) return;

    /* Check polarisation type is possible. */
    if ((stokes_in > I || stokes_out > I) && h->pol_mode != OSKAR_POL_MODE_FULL)
        return;

    /* Construct the filename. */
    name = construct_filename(h, data_product_type, stokes_in, stokes_out,
            i_station, time_average, channel_average, "fits");

    /* Open the file. */
    horizon_mode = h->coord_frame_type == 'H';
    f = create_fits_file(name, h->prec, h->width, h->height,
            (time_average ? 1 : h->num_time_steps),
            (channel_average ? 1 : h->num_channels),
            h->phase_centre_deg, h->fov_deg, h->time_start_mjd_utc,
            h->time_inc_sec, h->freq_start_hz, h->freq_inc_hz,
            horizon_mode, h->settings_log, h->settings_log_length, status);
    if (!f || *status)
    {
        *status = OSKAR_ERR_FILE_IO;
        free(name);
        return;
    }
    i = data_product_index(h, data_product_type, stokes_in, stokes_out,
            i_station, time_average, channel_average);
    h->data_products[i].fits_file = f;
    free(name);
}
Exemplo n.º 6
0
/**
 * duplicate new filename based on base_name and add extension if necessary
*/
char * duplicate_filename( const char * base_name, const char * defext ) {
	if ( strrchr( base_name, '.' ) == NULL )
		return construct_filename( base_name, defext ) ;
	else
		return strdup( base_name ) ;
}