示例#1
0
int dv_WriteGRD(Var* s, char* filename, int force, char* title, char* task)
{
	struct iom_iheader h;
	int status;

	if (V_TYPE(s) != ID_VAL) {
		sprintf(error_buf, "Var is not a value: %s", V_NAME(s));
		parse_error(NULL);
		return 0;
	}

	if (GetBands(V_SIZE(s), V_ORG(s)) != 1) {
		parse_error("Cannot write GRD files with more than 1 band");
		return 0;
	}

	var2iom_iheader(s, &h);
	status = iom_WriteGRD(filename, V_DATA(s), &h, force, title, task);
	iom_cleanup_iheader(&h);

	if (status == 0) {
		parse_error("Writing of GRD file %s failed.\n", filename);
	}

	return (status == 1);
}
示例#2
0
文件: ff_fft.c 项目: robwink/davinci
Var* ff_fft(vfuncptr func, Var* arg)
{
	Var *real = NULL, *img = NULL;
	double* data;
	int i, j, n, x, y, z;
	COMPLEX *in, *out;

	Alist alist[4];
	alist[0]      = make_alist("real", ID_VAL, NULL, &real);
	alist[1]      = make_alist("img", ID_VAL, NULL, &img);
	alist[2].name = NULL;

	if (parse_args(func, arg, alist) == 0) return (NULL);

	if (real == NULL && img == NULL) {
		parse_error("%s: No real or imaginary objects specified\n", func->name);
		return (NULL);
	}
	x = GetSamples(V_SIZE(real), V_ORG(real));
	y = GetLines(V_SIZE(real), V_ORG(real));
	z = GetBands(V_SIZE(real), V_ORG(real));

	if (img == NULL && x == 2) {
		n   = y * z;
		in  = (COMPLEX*)calloc(n, sizeof(COMPLEX));
		out = (COMPLEX*)calloc(n, sizeof(COMPLEX));
		for (i = 0; i < y; i++) {
			for (j = 0; j < z; j++) {
				in[i].re = extract_double(real, cpos(0, i, j, real));
				in[i].im = extract_double(real, cpos(1, i, j, real));
			}
		}
	} else {
		n   = V_DSIZE(real);
		in  = (COMPLEX*)calloc(n, sizeof(COMPLEX));
		out = (COMPLEX*)calloc(n, sizeof(COMPLEX));
		for (i = 0; i < n; i++) {
			in[i].re = extract_double(real, i);
			in[i].im = (img == NULL ? 0.0 : extract_double(img, i));
		}
	}

	if (func->fdata == (void*)1) {
		fft(in, n, out);
	} else {
		rft(in, n, out);
	}

	data = (double*)calloc(n * 2, sizeof(double));

	for (i = 0; i < n; i++) {
		data[i * 2]     = out[i].re;
		data[i * 2 + 1] = out[i].im;
	}
	return (newVal(BSQ, 2, n, 1, DV_DOUBLE, data));
}
示例#3
0
		void ProcessVector(float *input)
		{
			//Add the FFT to the total
			for (unsigned int i = 0; i < m_vector_length; i++){
				m_buffer[i] += input[i];
			}
			m_count++; //increment the total
			
			if (m_avg_size == m_count){ //we've averaged over the number we intended to
				double freqs[m_vector_length]; //for convenience
				float bands0[m_vector_length]; //bands in order of frequency
				float bands1[m_vector_length]; //fine window bands
				float bands2[m_vector_length]; //coarse window bands
				
				Rearrange(bands0, freqs, m_centre_freq_1, m_bandwidth0); //organise the buffer into a convenient order (saves to bands0)
				GetBands(bands0, bands1, m_bandwidth1); //apply the fine window (saves to bands1)
				GetBands(bands0, bands2, m_bandwidth2); //apply the coarse window (saves to bands2)
				PrintSignals(freqs, bands1, bands2);
				
				m_count = 0; //next time, we're starting from scratch - so note this
				ZeroBuffer(); //get ready to start again
				
				m_wait_count++; //we've just done another listen
				if (m_time/(m_bandwidth0/(double)(m_vector_length * m_avg_size)) <= m_wait_count){ //if we should move to the next frequency
					while (true) { //keep moving to the next frequency until we get to one we can listen on (copes with holes in the tunable range)
						if (m_centre_freq_2 <= m_centre_freq_1){ //we reached the end!
							//do something to end the scan
							fprintf(stderr, "[*] Finished scanning\n"); //say we're exiting
							exit(0); //TODO: This probably isn't the right thing, but it'll do for now
						}
						
						m_centre_freq_1 += m_step; //calculate the frequency we should change to
						double actual = m_source->set_center_freq(m_centre_freq_1); //change frequency
						if ((m_centre_freq_1 - actual < 10.0) && (actual - m_centre_freq_1 < 10.0)){ //success
							break; //so stop changing frequency
						}
					}
					m_wait_count = 0; //new frequency - we've listenned 0 times on it
				}
			}
		}