예제 #1
0
파일: util.c 프로젝트: Solaro/lalsuite
VARRAY *new_varray(int item_size)
{
VARRAY *v;
v=do_alloc(1, sizeof(*v));
v->item_size=item_size;
v->free=0;
v->size=100;
v->data=do_alloc(v->size, v->item_size);
return v;
}
예제 #2
0
SPARSE_CONV *new_sparse_conv(void)
{
SPARSE_CONV *sc;

sc=do_alloc(1, sizeof(*sc));

sc->free=0;
sc->size=40;

sc->bin=do_alloc(sc->size, sizeof(*sc->bin));
sc->data=do_alloc(sc->size, sizeof(*sc->data));

return(sc);
}
예제 #3
0
파일: testbget.c 프로젝트: FauxFaux/cyclone
int main() {
  struct Reap r[10];
  char names[10][10];
  int i=0, j=0;
  srand(100);
  for(i=0;i<10;i++) {
    sprintf(names[i], "reap%d", i);
    r[i].counter = 0;
    r[i].h = _new_reap(names[i]);
    r[i].p = NULL;
  }
  for(j=0;j<10;j++){
    printf("********************ROUND %d********************\n", j);
    for(i=0;i<10;i++){
      if(((rand() % 10) < 2) && r[i].counter > 20){
	printf("Freeing reap %d!!!!!!!!!!!!!!", i);
	_free_reap(&r[i].h);
	r[i].counter = -1;
      }
      if(r[i].counter >= 0)
	do_alloc(&r[i]);
    }
  }
  fprintf(stdout, "ok\n");
  return 0;
}
예제 #4
0
파일: tables.c 프로젝트: bonzini/qboot
void extract_acpi(void)
{
	int id = fw_cfg_file_id("etc/table-loader");
	int n = fw_cfg_file_size(id);
	struct loader_cmd script[n / sizeof(struct loader_cmd)];
	int i;

	if (!n)
		return;

	fw_cfg_read_file(id, script, n);

	for (i = 0; i < ARRAY_SIZE(script); i++) {
		struct loader_cmd *s = &script[i];
		switch(script[i].cmd) {
		case CMD_ALLOC:
			do_alloc(s->alloc.file, s->alloc.align, s->alloc.zone);
			break;
		case CMD_PTR:
			do_ptr(s->ptr.dest, s->ptr.src, s->ptr.offset, s->ptr.size);
			break;
		case CMD_CHECKSUM:
			do_checksum(s->checksum.file, s->checksum.offset,
				    s->checksum.start, s->checksum.len);
			break;
		case CMD_QUIT:
			return;
		default:
			panic();
		}
	}
}
예제 #5
0
파일: swapping01.c 프로젝트: bsbrp/ltp
int main(int argc, char *argv[])
{
    int lc;

    tst_parse_opts(argc, argv, NULL, NULL);

#if __WORDSIZE == 32
    tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
#endif

    setup();

    for (lc = 0; TEST_LOOPING(lc); lc++) {
        tst_count = 0;

        init_meminfo();

        switch (pid = fork()) {
        case -1:
            tst_brkm(TBROK | TERRNO, cleanup, "fork");
        case 0:
            do_alloc();
            exit(0);
        default:
            check_swapping();
        }
    }
    cleanup();
    tst_exit();
}
예제 #6
0
void expand_jobs(void)
{
JOB *p;
jobs_size=2*jobs_size+10;
p=do_alloc(jobs_size, sizeof(JOB));
if(jobs_free>0)memcpy(p, job, jobs_free*sizeof(JOB));
free(job);
job=p;
}
예제 #7
0
/* instead of having per-skypatch 

 we simply discard a SFTs which contribute less than a certain fraction of weight in each dataset */
void assign_cutoff_veto(void)
{
int i,k,m;
WEIGHT_INFO *w;
double total_weight, accum_weight, a;
DATASET *d;

w=do_alloc(nsegments, sizeof(*w));
m=0;
total_weight=0.0;
for(k=0;k<d_free;k++) {
	d=&(datasets[k]);
	for(i=0;i<d->free;i++) {
		if(d->sft_veto[i] && d->sft_veto[i]!=3)continue;

		w[m].dataset=k;
		w[m].segment=i;
		a=d->expTMedians[i]*d->weight;
		total_weight+=a;
		w[m].weight=a;
		m++;
		}
	}

if(m<1) {
	fprintf(stderr, "No clean SFTs found, skipping veto\n");
	fprintf(LOG, "No clean SFTs found, skipping veto\n");
	return;
	}

//fprintf(stderr, "%d %d\n", m, nsegments);
qsort(w, m, sizeof(*w), weight_cmp);
//fprintf(stderr, "%g %g %g ... %g %g %g\n", w[0].weight, w[1].weight, w[2].weight, w[m-3].weight, w[m-2].weight, w[m-1].weight);accum_weight=0;

accum_weight=0;
for(i=0;i<m;i++) {
	accum_weight+=w[i].weight;
	if(accum_weight>args_info.weight_cutoff_fraction_arg*total_weight)break;
	datasets[w[i].dataset].sft_veto[w[i].segment]=3;
	}
accum_weight-=w[i].weight;
fprintf(stderr, "Vetoed %d sfts (out of %d, %f ratio) with %g weight out of %g total weight (%f fraction)\n",
	i, nsegments, (i*1.0)/nsegments, accum_weight, total_weight, accum_weight/total_weight);
fprintf(LOG, "Vetoed %d sfts (out of %d, %f ratio) with %g weight out of %g total weight (%f fraction)\n",
	i, nsegments, (i*1.0)/nsegments,  accum_weight, total_weight, accum_weight/total_weight);

for(k=0;k<d_free;k++) {
	d=&(datasets[k]);
	m=0;
	for(i=0;i<d->free;i++) {
		if(d->sft_veto[i])continue;
		m++;
		}
	fprintf(stderr, "Dataset %s has %d clean sfts (%f ratio)\n", d->name, m, (1.0*m)/d->free);
	}
free(w);
}
예제 #8
0
SEGMENT_INFO *find_segments(double gps_start, double gps_end, int veto_mask, int *count)
{
SEGMENT_INFO *r, *p;
int length=(gps_end-gps_start)/450+1; /* this is enough for two ifos */
int i, k;
DATASET *d;

*count=0;
r=do_alloc(length, sizeof(*r));

for(k=0;k<d_free;k++) {
	d=&(datasets[k]);

	for(i=0;i<d->free;i++) {
		if(d->sft_veto[i] & ~veto_mask)continue;
		if(d->gps[i]<gps_start)continue;
		if(d->gps[i]>=gps_end)continue;

		if(*count>=length) {
			length*=2;
			p=do_alloc(length, sizeof(*p));
			if(*count>0)memcpy(p, r, (*count) * sizeof(*p));
			free(r);
			r=p;
			}

		r[*count].gps=d->gps[i];
		r[*count].detector_velocity[0]=d->detector_velocity[3*i];
		r[*count].detector_velocity[1]=d->detector_velocity[3*i+1];
		r[*count].detector_velocity[2]=d->detector_velocity[3*i+2];
		r[*count].coherence_time=d->coherence_time;
		r[*count].dataset=k;
		r[*count].segment=i;
		r[*count].f_plus=NAN;
		r[*count].f_cross=NAN;
		r[*count].bin_shift=NAN;
		r[*count].diff_bin_shift=NAN;

		(*count)++;
		}
	}
return(r);
}
예제 #9
0
static void
new_quote(Quote * q, const char *s)
{
    DPRINTF(("new_quote(%s=\"%s\")\n", whichQuote(q), s));

    q->used = strlen(s);
    q->text = do_alloc(q->text, q->used, &(q->have));
    if (q->text != 0)
	strcpy(q->text, s);
}
예제 #10
0
파일: filters.c 프로젝트: ricksladkey/vile
/*
 * The flt_bfr_*() functions are used for managing a possibly multi-line buffer
 * that will be written as one attributed region.
 */
void
flt_bfr_append(const char *text, int length)
{
    flt_bfr_text = do_alloc(flt_bfr_text, flt_bfr_used + (size_t) length, &flt_bfr_size);
    if (flt_bfr_text != 0) {
	strncpy(flt_bfr_text + flt_bfr_used, text, (size_t) length);
	flt_bfr_used += (unsigned) length;
    } else {
	CannotAllocate("flt_bfr_append");
    }
}
예제 #11
0
void init_jobs(void)
{
jobs_free=0;
jobs_size=100;
job=do_alloc(jobs_size, sizeof(JOB));
jobs_submitted=0;
jobs_done=0;
next_job_to_do=0;
thread_mutex_init(&jobs_mutex);
thread_cond_init(&wait_for_more_jobs_condition);
thread_cond_init(&all_done_condition);
}
예제 #12
0
void* myalloc(size_t len)
{
	ALIGN8(len);
	size_t i = ind(len);
	if (i != MEM_SIZ_LARGE)
	{
		return do_alloc(i);
	}
	else
	{
		return do_alloc_large(len);
	}
}
예제 #13
0
void put_partial_power_sum_F(SUMMING_CONTEXT *ctx, PARTIAL_POWER_SUM_F *pps)
{
PARTIAL_POWER_SUM_F ** p;

if(ctx->pps_pool_free>=ctx->pps_pool_size) {
	ctx->pps_pool_size*=2;
	p=do_alloc(ctx->pps_pool_size, sizeof(*ctx->partial_power_sum_pool));
	memcpy(p, ctx->partial_power_sum_pool, ctx->pps_pool_free*sizeof(*ctx->partial_power_sum_pool));
	free(ctx->partial_power_sum_pool);
	ctx->partial_power_sum_pool=p;
	}
ctx->partial_power_sum_pool[ctx->pps_pool_free]=pps;
ctx->pps_pool_free++;
}
예제 #14
0
int main(int argc, char *argv[])
{
FILE *fin;
int i;
float a;

LOG=stderr;

if(argc<7){
	fprintf(stderr, "\nUsage: %s mode resolution lower_cut upper_cut file.dat skymap.png\n", argv[0]);
	fprintf(stderr, "\tmodes: plain, log10\n");
	fprintf(stderr, "\tcutoff: number or \"auto\"\n\n");
	return -1;
	}
resolution=atof(argv[2]);

fin=fopen(argv[5], "r");
if(fin==NULL){
	perror("Cannot read file:");
	return -1;
	}

grid=make_sin_theta_grid(resolution);

data=do_alloc(grid->npoints, sizeof(*data));
fread(data, sizeof(*data), grid->npoints, fin);
fprintf(stderr, "%g %g %g %g\n", data[0], data[1], data[2], data[3]);

if(!strcasecmp(argv[1], "log10")){
	for(i=0;i<grid->npoints;i++)data[i]=log10(data[i]);
	}

if(strcasecmp(argv[3], "auto")){
	a=atof(argv[3]);
	for(i=0;i<grid->npoints;i++)
		if(data[i]<=a)data[i]=a;
	}

if(strcasecmp(argv[4], "auto")){
	a=atof(argv[4]);
	for(i=0;i<grid->npoints;i++)
		if(data[i]>=a)data[i]=a;
	}

pic=make_RGBPic(grid->max_n_ra+140, grid->max_n_dec);
plot_grid_f(pic, grid, data, 1);

RGBPic_dump_png(argv[6], pic);
return 0;
}
예제 #15
0
파일: util.c 프로젝트: Solaro/lalsuite
int varray_add(VARRAY *v, void *item)
{
if(v->free>=v->size) {
	void *p;
	v->size=2*v->size+10;
	p=do_alloc(v->size, v->item_size);
	if(v->free>0)memcpy(p, v->data, v->free*v->item_size);
	if(v->data!=NULL)free(v->data);
	v->data=p;
	}
memcpy(& ((((char *)(v->data))[v->free*v->item_size])), item, v->item_size);
v->free++;
return(v->free-1);
}
예제 #16
0
void add_suppress_region(double line1, double line2, int N)
{
LINE_SUPPRESS_REGION *p;
if(sl_free>=sl_size){
	sl_size=2*sl_size+10;
	p=do_alloc(sl_size, sizeof(*p));
	if(sl_free>0)memcpy(p, suppress_lines, sl_free*sizeof(*suppress_lines));
	if(suppress_lines!=NULL)free(suppress_lines);
	suppress_lines=p;
	}
suppress_lines[sl_free].line1=line1;
suppress_lines[sl_free].line2=line2;
suppress_lines[sl_free].N=N;
sl_free++;
}
예제 #17
0
REAL8 sum_r8_squares(REAL8 *array, long count)
{
int i,c;
REAL8 *squares, a;
squares=do_alloc(count, sizeof(*squares));
for(i=0;i<count;i++)squares[i]=array[i]*array[i];
qsort(squares, count, sizeof(*squares), c_r8);
c=count;
while(c>1){
	for(i=0;(i+2)<=c;i+=2){
		squares[i>>1]=squares[i]+squares[i+1];
		}
	if(c & 1){
		squares[(c>>1)]=squares[c-1];
		c=(c>>1)+1;
		} else {
예제 #18
0
파일: swapping01.c 프로젝트: sathnaga/ltp
static void test_swapping(void)
{
#if __WORDSIZE == 32
	tst_brk(TCONF, "test is not designed for 32-bit system.");
#endif

	init_meminfo();

	switch (pid = SAFE_FORK()) {
		case 0:
			do_alloc();
			exit(0);
		default:
			check_swapping();
	}
}
예제 #19
0
void init_threads(int mt)
{
max_threads=mt-1;
if(max_threads<0) {
	max_threads=cpu_count()-1;
	}
if(max_threads<0) max_threads=0;

thread_id=do_alloc(max_threads, sizeof(*thread_id));
num_threads=0;
threads_started=0;
thread_cond_init(&thread_not_needed);
thread_mutex_init(&thread_num_mutex);
set_concurrency(1);
fprintf(stderr, "maximum threads: %d\n", max_threads+1);
fprintf(LOG, "maximum threads: %d\n", max_threads+1);
}
예제 #20
0
void log_extremes_viterbi(SUMMING_CONTEXT *ctx, int pi, POWER_SUM **ps, int count)
{
int i,j,k,m,r, lm;
POINT_STATS pst;
POWER_SUM_STATS *stats;
float *tmp;
float *tmp2a, *tmp2b, *tmp_min_weight, *tmp_max_weight;
float *p1, *p2, *p3, *p4, *p5;
float min_weight, max_weight, inv_weight, weight, *total_weight;
int fshift_count=args_info.nfshift_arg; /* number of frequency offsets */
int shift;
long tmp_stride=(useful_bins+(ALIGNMENT-1)) & (~(ALIGNMENT-1));
long tmp_size;

if(args_info.filter_lines_arg) {
	/* To fix this we would need to pass and process per-frequency weight arrays. This needs to be done carefully to maintain efficiency 
	 * The code will work as is if this is disabled, using an approximation to true weight. 
	 * But the checks that enough weight was accumulated to compute power will not work */
	fprintf(stderr, "*** ERROR: viterbi filtering is incompatible with filter-lines=1\n");
	exit(-1);
	}

	/* size of tmp array */
tmp_size=args_info.nchunks_arg*veto_free*fshift_count*tmp_stride*sizeof(float);
	/* size of tmp2 arrays */
tmp_size+=2*(tmp_stride*fshift_count)*sizeof(float);
	/* size of stats array */
tmp_size+=nei*count*sizeof(*stats)+ALIGNMENT;
	/* sizes of tmp_min_weight and tmp_max_weight arrays */
tmp_size+=2*args_info.nchunks_arg*veto_free*fshift_count*sizeof(float)+2*ALIGNMENT;
	/* sizes of total_weight array */
tmp_size+=fshift_count*sizeof(float)+2*ALIGNMENT;

if(ctx->log_extremes_pstats_scratch_size<tmp_size) {
	free(ctx->log_extremes_pstats_scratch);

	ctx->log_extremes_pstats_scratch_size=tmp_size;

	ctx->log_extremes_pstats_scratch=do_alloc(1, tmp_size);
	
	p1=(float *)ctx->log_extremes_pstats_scratch;
	PRAGMA_IVDEP
	for(i=0;i<(ctx->log_extremes_pstats_scratch_size/sizeof(*p1));i++)p1[i]=NAN;
	
	fprintf(stderr, "Expanded log_extremes_pstats_scratch to %f MB nchunks=%d veto_free=%d count=%d nei=%d\n", ctx->log_extremes_pstats_scratch_size*1e-6, args_info.nchunks_arg, veto_free, count, nei);
	}
예제 #21
0
void add_fake_data_command(int command, double phase, double frequency, double amplitude)
{
FAKE_DATA_COMMAND *p;
int i;
if(fake_data_free>=fake_data_size){
	fake_data_size=2*fake_data_size+10;
	p=do_alloc(fake_data_size, sizeof(FAKE_DATA_COMMAND));
	if(fake_data_free>0)memcpy(p, fake_data, fake_data_free*sizeof(FAKE_DATA_COMMAND));
	if(fake_data!=NULL)free(fake_data);
	fake_data=p;
	}
i=fake_data_free;
fake_data_free++;
fake_data[i].command=command;
fake_data[i].phase=phase;
fake_data[i].frequency=frequency;
fake_data[i].amplitude=amplitude;
}
예제 #22
0
void* buddy_alloc(buddy_t* pb, size_t size)
{
	int ind = size_parse(size);
	if (ind == -1)
	{
		fprintf(stderr, "wrong alloc size: %d\n", size);
		return NULL;
	}

	node_t** ppn = do_alloc(pb, ind);
	if (!ppn)
	{
		fprintf(stderr, "not enough free space\n");
		return NULL;
	}
	else
	{
		return (*ppn)->addr;
	}
}
예제 #23
0
void create_segments(EXTREME_INFO ***out_ei, int *out_nei)
{
int i, k, m, nei;
EXTREME_INFO **ei;
ei=do_alloc(args_info.nchunks_arg*(args_info.nchunks_arg+1)*(veto_free+1)/2, sizeof(*ei));

fprintf(LOG, "nchunks: %d\n", args_info.nchunks_arg);
fprintf(LOG, "nchunks refinement: %d\n", args_info.nchunks_refinement_arg);
fprintf(LOG, "min nchunks: %d\n", args_info.min_nchunks_arg);
fprintf(LOG, "veto_free: %d\n", veto_free);

nei=0;

for(i=0;i<args_info.nchunks_arg;i+=args_info.nchunks_refinement_arg)
	for(k=0;k< args_info.nchunks_arg-i;k+=args_info.nchunks_refinement_arg) {
		if(k+1<args_info.min_nchunks_arg)continue;
		
		for(m=-1;m<veto_free;m++) {
			if(m<0) {
				if((veto_free<=1) && args_info.split_ifos_arg)continue; /* if there is only one detector no reason to compute "all" twice */
				snprintf(s, 19999, "%d_%d_all", i/args_info.nchunks_refinement_arg, (i+k)/args_info.nchunks_refinement_arg);
				} else {
				if(!args_info.split_ifos_arg)continue; /* combine data from all detectors */
				snprintf(s, 19999, "%d_%d_%s", i/args_info.nchunks_refinement_arg, (i+k)/args_info.nchunks_refinement_arg, veto_info[m].name);
				}
			ei[nei]=allocate_extreme_info(s);
			ei[nei]->first_chunk=i;
			ei[nei]->last_chunk=i+k;
			ei[nei]->veto_num=m;
			nei++;
			}
		}

*out_nei=nei;
*out_ei=ei;
}
예제 #24
0
파일: filters.c 프로젝트: ricksladkey/vile
/*
 * Find the first occurrence of a file in the canonical search list:
 *	the current directory
 *	the home directory
 *	vile's subdirectory of the home directory
 *	the vile library-directory
 *
 * On Unix we look for file/directory names with a "." prefixed since that
 * hides them.
 */
static FILE *
OpenKeywords(const char *table_name)
{
#define OPEN_IT(p) if ((fp = fopen(p, "r")) != 0) { \
			VERBOSE(1,("Opened %s", p)); return fp; } else { \
			VERBOSE(2,("..skip %s", p)); }
#define FIND_IT(p) sprintf p; OPEN_IT(str_keyword_name)

    static char suffix[] = KEYFILE_SUFFIX;

    FILE *fp;
    const char *path;
    size_t need;
    char myLeaf[20];

    need = sizeof(suffix) + strlen(table_name) + 2;
    str_keyword_file = do_alloc(str_keyword_file, need, &len_keyword_file);
    if (str_keyword_file == 0) {
	CannotAllocate("OpenKeywords");
	return 0;
    }
    sprintf(str_keyword_file, "%s%s", table_name, suffix);

    if (strchr(str_keyword_file, PATHSEP) != 0) {
	OPEN_IT(str_keyword_file);
    }

    if ((path = home_dir()) == 0)
	path = "";

    need = strlen(path)
	+ strlen(str_keyword_file)
	+ 20;

    str_keyword_name = do_alloc(str_keyword_name, need, &len_keyword_name);
    if (str_keyword_name == 0) {
	CannotAllocate("OpenKeywords");
	return 0;
    }

    FIND_IT((str_keyword_name, "%s%c%s%s", PATHDOT, PATHSEP, DOT_TO_HIDE_IT, str_keyword_file));
    FIND_IT((str_keyword_name, "%s%c%s%s", path, PATHSEP, DOT_TO_HIDE_IT, str_keyword_file));
    sprintf(myLeaf, "%s%s%c", DOT_TO_HIDE_IT, MY_NAME, PATHSEP);

    FIND_IT((str_keyword_name, "%s%c%s%s", path, PATHSEP, myLeaf, str_keyword_file));

    path = vile_getenv("VILE_STARTUP_PATH");
#ifdef VILE_STARTUP_PATH
    if (path == 0)
	path = VILE_STARTUP_PATH;
#endif
    if (path != 0) {
	int n = 0, m;

	need = strlen(path) + strlen(str_keyword_file) + 2;
	str_keyword_name = do_alloc(str_keyword_name, need, &len_keyword_name);
	if (str_keyword_name == 0) {
	    CannotAllocate("OpenKeywords");
	    return 0;
	}
	while (path[n] != 0) {
	    for (m = n; path[m] != 0 && path[m] != PATHCHR; m++)
		/*LOOP */ ;
	    FIND_IT((str_keyword_name, "%.*s%c%s", m - n, path + n, PATHSEP, str_keyword_file));
	    if (path[m])
		n = m + 1;
	    else
		n = m;
	}
    }

    return 0;
}
예제 #25
0
static void* do_alloc(size_t i)
{
	node_t* pn = heap->index[i];
	node_t* prev = NULL;

	while (pn)
	{
		if (pn->stat == MEM_STAT_FREE)
		{
			if (prev)
			{
				void* ret = pn->addr;
				node_t* newNode = get_free_node();
				prev->next = newNode;
				newNode->addr = ret;
				newNode->stat = MEM_STAT_USED;
				newNode->len = indsiz[i];
				newNode->next = pn;
				pn->addr = (void*)((size_t)pn->addr + indsiz[i]);
				pn->len -= indsiz[i];
				if (pn->len == 0)
				{
					newNode->next = pn->next;
					pn->next = heap->free_node;
					heap->free_node = pn;
					merge(prev);
				}
				return ret;
			}
			else
			{
				node_t* tmp = get_free_node();
				tmp->addr = pn->addr;
				tmp->len = indsiz[i];
				tmp->next = pn;
				tmp->stat = MEM_STAT_USED;
				pn->addr = (void*)((size_t)pn->addr + indsiz[i]);
				pn->len -= indsiz[i];
				heap->index[i] = tmp;
				if (pn->len == 0)
				{
					tmp->next = pn->next;
					pn->next = heap->free_node;
					heap->free_node = pn;
					merge(tmp);
				}
				return tmp->addr;
			}
		}
		else if (pn->next)
		{
			prev = pn;
			pn = pn->next;
		}
		else
		{
			expand_heap(i);
			return do_alloc(i);
		}
	}
	expand_heap(i);
	return do_alloc(i);
}
예제 #26
0
void add_frame_file(char *filename, double TStart, double TEnd)
{
char *p;
FrFile *ff;
FrVect *vect;
frame_file *fdata;
/* check that sample storage has been allocated */
if(data==NULL){
	fprintf(stderr, "** You must use DURATION and SAMPLES_PER_SECOND commands before FRAME_FILES\n");
	exit(-1);
	}

/* remove leading whitespace */
while((*filename==' ')||(*filename=='\t'))filename++;
/* break at first newline */
for(p=filename;*p;p++)if(*p=='\n'){*p=0; break; }
/* remove trailing whitespace */
while((*p==' ')||(*p=='\t')){
	*p=0;
	if(p==filename)break;
	p--;
	}

fprintf(stderr,"Adding frame file \"%s\"\n", filename);
if(files_free>=files_size){
	files_size=2*files_size+10;
	/* reuse p.. we do not care it is the wrong type, void * is sufficient */
	p=(char *)do_alloc(files_size, sizeof(frame_file));
	if(files_free>0)memcpy(p, files, files_free*sizeof(frame_file));
	if(files!=NULL)free(files);
	files=(frame_file *)p;
	}
fdata=&(files[files_free]);
fdata->name=strdup(filename);
fault_file(filename);
ff=FrFileINew(filename);
if(ff==NULL){
	fprintf(stderr,"** Error opening \"%s\" for reading frame fdata\n", filename);
	return;
	}
if(TStart<0)TStart=FrFileITStart(ff);
if(TEnd<0)TEnd=FrFileITEnd(ff);
fprintf(stderr,"Opened frame file \"%s\" start=%f end=%f\n", filename, TStart, TEnd);
if((TStart > TEnd) || (TStart < 0)){
	fprintf(stderr, "** TStart > TEnd || TStart < 0 on file %s\n", filename);
	FrFileIEnd(ff);
	return;
	}
/*  This does not appear to work - vect returns bogus values for start time.
if(TStart < gps_start)TStart=gps_start;
if(TEnd > gps_end)TEnd=gps_end;
*/
/* ok, file is opened and we _are_ able to read from it.. 
   validate the entry and read the fdata */
files_free++;
fdata->gps_start=llrint(TStart);
fdata->gps_end=llrint(TEnd);
errno=0;
vect=FrFileIGetV(ff, channel, TStart, TEnd-TStart);
if((vect==NULL)||(errno!=0)){
	fprintf(stderr,"** Could not find data for channel \"%s\" [%.10lg,%.10lg] in file \"%s\" (errno=%s)\n", channel, TStart, TEnd, filename, strerror(errno));
	} else {
	/* print_vect_trends(vect, 0, 16384); */
	assimilate_data(vect);
	FrVectFree(vect);
	}
FrFileIEnd(ff);
}
예제 #27
0
파일: alloc.hpp 프로젝트: FsThatOne/VOne
inline MemRef Allocator::alloc(size_t size)
{
    return do_alloc(size);
}
예제 #28
0
int main(int argc, char *argv[])
{
long i;
double window_sum;
LALStatus status={level:0, statusPtr: NULL};
PassBandParamStruc filterpar;
REAL4TimeSeries chan; /* must zero the f0 field */

fprintf(stderr,"make_sft_op version %s\n", MAKE_SFT_VERSION);
fprintf(stderr,"Using frame library %s\n", FrLibVersionF());
fprintf(stderr,"Using LAL version %s\n", LAL_VERSION);


yylex();

if(freq_start<0)freq_start=0;
if(freq_stop<0)freq_stop=total_samples;

/* post_init various subsystems */

post_init_response_files();
post_init_alpha_beta();

/* print settings */
print_settings(stderr);

/* start processing data */
print_data_stats();
print_data(file_debug1, "debug 1");

verify_loaded_data();

generate_fake_data();

linear_interpolate_gaps();
print_data(file_debug2, "debug 2");

/* this is a hack, but it significantly reduces memory footprint */
td_data=do_alloc(1,sizeof(*td_data));
td_data->length=total_samples;
td_data->data=data;

/* setup structure to hold input for Butterworth filter */
chan.data=NULL;
strncpy(chan.name,channel,LALNameLength);
chan.f0=0;
chan.name[LALNameLength-1]=0; /* make sure it is null-terminated */
chan.deltaT=1.0/samples_per_second;
chan.epoch.gpsSeconds=gps_start; /* no need */
chan.epoch.gpsNanoSeconds=0;

if(trace_power){
	fprintf(stderr, "Input data total power=%.*g\n",
		precision, sum_r4_squares(data, total_samples)/samples_per_second);
	}

if(!bypass_highpass_filter && (highpass_filter_f>0) && (highpass_filter_a>0)){
	fprintf(stderr,"Applying high pass filter, f=%g a=%g order=%d\n",
		highpass_filter_f, highpass_filter_a, highpass_filter_order);
	/* Setup Butterworth filter */
	filterpar.name="Butterworth High Pass";
	filterpar.nMax=highpass_filter_order;
	filterpar.f2=highpass_filter_f;
	filterpar.a2=highpass_filter_a;
	/* values that are 'not given' = out of range */
	filterpar.f1=-1.0;
	filterpar.a1=-1.0;
	
	/* REAL4Sequence is the same as REAL4Vector - according to lal/Datatypes.h */
	chan.data=(REAL4Sequence *)td_data;
	LALDButterworthREAL4TimeSeries(&status, &chan, &filterpar);
	TESTSTATUS(&status);

	if(trace_power){
		fprintf(stderr, "After highpass filter total power=%.*g\n",
			precision, sum_r4_squares(data, total_samples)/samples_per_second);
		}
	}
	
if(!bypass_lowpass_filter && (lowpass_filter_f>0) && (lowpass_filter_a > 0)){
	fprintf(stderr,"Applying low pass filter, f=%g a=%g order=%d\n",
		lowpass_filter_f, lowpass_filter_a, lowpass_filter_order);
	/* Setup Butterworth filter */
	filterpar.name="Butterworth Low Pass";
	filterpar.nMax=lowpass_filter_order;
	filterpar.f1=lowpass_filter_f;
	filterpar.a1=lowpass_filter_a;
	/* values that are 'not given' = out of range */
	/* why 2*nsamples ? LAL used to have a bug in it where
	   the pairs were sorted before deciding whether the filter 
	   is lowpass or highpass. Therefore, we need to specify a 
	   large, out of range, frequency f so that we get a low-pass filter.
	   The maximum frequency is Nyquist, hence 2*nsamples is definitely out of range */
	filterpar.f2=2*total_samples;
	filterpar.a2=-1.0;
		/* REAL4Sequence is the same as REAL4Vector - according to lal/Datatypes.h */
	chan.data=(REAL4Sequence *)td_data;
	LALDButterworthREAL4TimeSeries(&status, &chan, &filterpar);
	TESTSTATUS(&status);

	if(trace_power){
		fprintf(stderr, "After lowpass filter total power=%.*g\n",
			precision, sum_r4_squares(data, total_samples)/samples_per_second);
		}
	}

if(!bypass_first_window){
	fprintf(stderr,"Applying Hann window to input data\n");
	for(i=0;i<total_samples;i++)data[i]*=0.5*(1.0-cos((2.0*M_PI*i)/total_samples));
	window_sum=0.5;
	} else {
	window_sum=1.0;
	}

if(trace_power){
	fprintf(stderr, "After windowing total power=%.*g\n",
		precision, sum_r4_squares(data, total_samples)/samples_per_second);
	}

for(i=0;i<3;i++){
	fprintf(stderr,"Allocating phi[%ld]\n", i);
	LALCCreateVector(&status, &(phi[i]), freq_stop-freq_start);
	TESTSTATUS(&status);
	}

compute_test_fft(td_data, phi, 3, freq_start, freq_stop);

/* now free td_data to conserve space */
free(td_data->data);
data=NULL;
free(td_data);
td_data=NULL;

LALCCreateVector(&status, &pgram, freq_stop-freq_start);
TESTSTATUS(&status);

compute_calibrated_periodogram3(phi, freq_start, freq_stop, pgram, window_sum);

print_COMPLEX8Vector(pgram, output_sft, "CALIBRATED FREQUENCY DOMAIN DATA", output_mode, 0, freq_stop-freq_start);

if(output_power!=NULL){
	/* we need more space */
	for(i=0;i<3;i++){
		LALCDestroyVector(&status, &(phi[i]));
		TESTSTATUS(&status);
		}
	LALSCreateVector(&status, &power, freq_stop-freq_start);
	TESTSTATUS(&status);
	for(i=0;i<freq_stop-freq_start;i++)
		power->data[i]=(pgram->data[i].re*pgram->data[i].re+pgram->data[i].im*pgram->data[i].im);
	print_REAL4Vector(power, output_power, "CALIBRATED POWER", output_mode, 0, freq_stop-freq_start);
	}

/* we do not destroy large vectors when we are done unless we need
  to allocate a lot of space again. This reduces run time 
  of the program */
return 0;
}
예제 #29
0
SUMMING_CONTEXT *create_summing_context(void)
{
SUMMING_CONTEXT *ctx;

ctx=do_alloc(1, sizeof(*ctx));
memset(ctx, 0, sizeof(*ctx));

fprintf(stderr, "Averaging mode: %s\n", args_info.averaging_mode_arg);
fprintf(stderr, "SSE: %d\n", args_info.sse_arg);
fprintf(LOG, "Averaging mode: %s\n", args_info.averaging_mode_arg);
fprintf(LOG, "SSE: %d\n", args_info.sse_arg);

ctx->diff_shift_granularity=0; 

#define MODE(a)	(args_info.sse_arg ? (sse_ ## a) : (a) )

/* default values appropriate for particular averaging mode */
if(!strcasecmp(args_info.averaging_mode_arg, "matched")) {
	ctx->get_uncached_power_sum=MODE(get_uncached_matched_power_sum);
	ctx->accumulate_power_sum_cached=accumulate_power_sum_cached1;
	ctx->accumulate_power_sums=accumulate_power_sums_sidereal_step;

	ctx->cache_granularity=8;
	ctx->sidereal_group_count=24;
	ctx->summing_step=864000; /* ten days */
	} else
if(!strcasecmp(args_info.averaging_mode_arg, "single_bin_loose")) {
	fprintf(LOG, "single_bin_loose: only tested with delta of pi/2 and pi/5\n");
	fprintf(stderr, "single_bin_loose: only tested with delta of pi/2 and pi/5\n");
	ctx->get_uncached_power_sum=MODE(get_uncached_loose_single_bin_partial_power_sum);
	ctx->accumulate_power_sum_cached=accumulate_power_sum_cached_diff;
	ctx->accumulate_power_sums=accumulate_single_bin_loose_power_sums_sidereal_step;

	ctx->cache_granularity=8; /* TODO: find actual value from experiment */
	ctx->diff_shift_granularity=8192*8; 
	ctx->sidereal_group_count=12;
	ctx->summing_step=86400*3; /* three days */
	ctx->time_group_count=3;
	ctx->cross_terms_present=args_info.compute_cross_terms_arg;
	} else
if(!strcasecmp(args_info.averaging_mode_arg, "matched_loose")) {
	fprintf(LOG, "**** WARNING matched_loose: this experimental code has not been reviewed yet.\n");
	fprintf(stderr, "**** WARNING matched_loose: this experimental code has not been reviewed yet.\n");
	ctx->get_uncached_power_sum=get_uncached_loose_matched_partial_power_sum;
	ctx->accumulate_power_sum_cached=accumulate_power_sum_cached_diff;
	ctx->accumulate_power_sums=accumulate_matched_loose_power_sums_sidereal_step;

	ctx->cache_granularity=8; /* TODO: find actual value from experiment */
	ctx->diff_shift_granularity=8192*8; 
	ctx->sidereal_group_count=12;
	ctx->summing_step=86400*3; /* three days */
	ctx->time_group_count=3;
	ctx->cross_terms_present=args_info.compute_cross_terms_arg;
	} else
if(!strcasecmp(args_info.averaging_mode_arg, "3") || !strcasecmp(args_info.averaging_mode_arg, "three")) {
	fprintf(stderr, "PowerFlux2 does not support 3-bin mode\n");
	exit(-1);
	} else
if(!strcasecmp(args_info.averaging_mode_arg, "1") || !strcasecmp(args_info.averaging_mode_arg, "one")) {
	ctx->get_uncached_power_sum=MODE(get_uncached_single_bin_power_sum);
	ctx->accumulate_power_sum_cached=accumulate_power_sum_cached1;
	ctx->accumulate_power_sums=accumulate_power_sums_sidereal_step;

	ctx->cache_granularity=1;
	ctx->sidereal_group_count=24;
	ctx->summing_step=864000; /* ten days */
	} else {
	fprintf(stderr, "Unrecognized averaging mode: %s\n", args_info.averaging_mode_arg);
	exit(-1);
	}

/* apply command line overrides */
if(args_info.cache_granularity_given) {
	ctx->cache_granularity=args_info.cache_granularity_arg;
	if(ctx->cache_granularity<1) {
		fprintf(stderr, "*** ERROR: cache granularity must be positive\n");
		fprintf(LOG, "*** ERROR: cache granularity must be positive\n");
		exit(-1);
		}
	}

if(args_info.summing_step_given) {
	ctx->summing_step=args_info.summing_step_arg;
	}

if(args_info.sidereal_group_count_given) {
	ctx->sidereal_group_count=args_info.sidereal_group_count_arg;
	if(ctx->sidereal_group_count<1) {
		fprintf(stderr, "*** ERROR: sidereal_group_count must be positive\n");
		fprintf(LOG, "*** ERROR: sidereal_group_count must be positive\n");
		exit(-1);
		}
	}

if(args_info.time_group_count_given) {
	ctx->time_group_count=args_info.time_group_count_arg;
	if(ctx->time_group_count<1) {
		fprintf(stderr, "*** ERROR: time_group_count must be positive\n");
		fprintf(LOG, "*** ERROR: time_group_count must be positive\n");
		exit(-1);
		}
	}
	
ctx->inv_cache_granularity=1.0/ctx->cache_granularity;
ctx->half_inv_cache_granularity=0.5/ctx->cache_granularity;
ctx->inv_diff_shift_granularity=1.0/ctx->diff_shift_granularity;
ctx->half_inv_diff_shift_granularity=0.5/ctx->diff_shift_granularity;

fprintf(LOG, "summing_step: %g\n", ctx->summing_step);
fprintf(LOG, "cache_granularity: %d\n", ctx->cache_granularity);
fprintf(LOG, "diff_shift_granularity: %d\n", ctx->diff_shift_granularity);
fprintf(LOG, "sidereal_group_count: %d\n", ctx->sidereal_group_count);
fprintf(LOG, "time_group_count: %d\n", ctx->time_group_count);
fprintf(LOG, "phase_mismatch: %g\n", args_info.phase_mismatch_arg);
fprintf(LOG, "cross_terms_present: %d\n", ctx->cross_terms_present);

allocate_simple_cache(ctx);

ctx->loose_first_half_count=-1;


return(ctx);
}
예제 #30
0
EXTREME_INFO * allocate_extreme_info(char *name)
{
EXTREME_INFO *ei;
int i;

ei=do_alloc(1, sizeof(*ei));
memset(ei, 0, sizeof(*ei));

ei->name=strdup(name);

thread_mutex_init(&(ei->mutex));

if(args_info.compute_skymaps_arg) {
	ei->ul_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->ul_freq_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->circ_ul_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->circ_ul_freq_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->snr_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->snr_ul_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->snr_freq_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->max_weight_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->min_weight_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->weight_loss_fraction_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	ei->ks_skymap=do_alloc(patch_grid->npoints, sizeof(float));
	}

ei->band_info=do_alloc(fine_grid->nbands, sizeof(*ei->band_info));
memset(ei->band_info, 0, fine_grid->nbands*sizeof(*ei->band_info));

ei->band_valid_count=do_alloc(fine_grid->nbands, sizeof(*ei->band_valid_count));
ei->band_masked_count=do_alloc(fine_grid->nbands, sizeof(*ei->band_masked_count));
memset(ei->band_valid_count, 0, fine_grid->nbands*sizeof(*ei->band_valid_count));
memset(ei->band_masked_count, 0, fine_grid->nbands*sizeof(*ei->band_masked_count));

for(i=0;i<fine_grid->nbands;i++) {
	ei->band_info[i].max_weight=-1;
	}

return ei;
}