Skip to content

Commit

Permalink
Move profile/filter read/write routines to separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
demorest committed Aug 14, 2012
1 parent 1898f3d commit 86d894b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -24,4 +24,4 @@ install: all
cp -f $(PROGS1) $(LOCAL)/bin;

filter_profile: filter_profile.o merit_functions.o model_cyclic.o \
cyclic_utils.o $(FILEIO_OBJ)
filter_fileio.o cyclic_utils.o $(FILEIO_OBJ)
54 changes: 0 additions & 54 deletions cyclic_utils.c
Expand Up @@ -343,60 +343,6 @@ double filter_ms_difference(struct filter_time *f1,
return(sum);
}

void write_profile(const char *fname, struct profile_phase *p) {
FILE *f = fopen(fname, "w");
int i;
for (i=0; i<p->nphase; i++) {
fprintf(f,"%.7e %.7e\n",
(double)i/(double)p->nphase, p->data[i]);
}
fclose(f);
}

void write_fprofile(const char *fname, struct profile_harm *p) {
FILE *f = fopen(fname, "a");
int i;
for (i=0; i<p->nharm; i++) {
fprintf(f,"%d %.7e %.7e\n",
i, creal(p->data[i]), cimag(p->data[i]));
}
fprintf(f,"\n\n");
fclose(f);
}

void write_filter(const char *fname, struct filter_time *h) {
FILE *f = fopen(fname, "a");
int i;
for (i=0; i<h->nlag; i++) {
fprintf(f,"%d %.7e %.7e\n",
i, creal(h->data[i]), cimag(h->data[i]));
}
fprintf(f,"\n\n");
fclose(f);
}

void write_filter_freq(const char *fname, struct filter_freq *h) {
FILE *f = fopen(fname, "a");
int i;
for (i=0; i<h->nchan; i++) {
fprintf(f,"%d %.7e %.7e\n",
i, creal(h->data[i]), cimag(h->data[i]));
}
fprintf(f,"\n\n");
fclose(f);
}

void read_profile(const char *fname, struct profile_phase *pp) {
FILE *f = fopen(fname, "r");
int i;
float ptmp, dtmp;
for (i=0; i<pp->nphase; i++) {
fscanf(f,"%f %f", &ptmp, &dtmp);
pp->data[i] = dtmp;
}
fclose(f);
}

int maximum_cs1(const CS *cs) {
/* Routine added by MAW 13/07/2011 */
/* Returns the channel having the largest absolute value */
Expand Down
67 changes: 67 additions & 0 deletions filter_fileio.c
@@ -0,0 +1,67 @@
/* filter_fileio.c
*
* Routines to read/write filter funcs and profiles.
* Split off from cyclic_utils.c, PBD 2012/08/14.
*/
#include <math.h>
#include <stdlib.h>
#include <complex.h>
#include <fftw3.h>

#include "cyclic_utils.h"
#include "filter_fileio.h"

void write_profile(const char *fname, struct profile_phase *p) {
FILE *f = fopen(fname, "w");
int i;
for (i=0; i<p->nphase; i++) {
fprintf(f,"%.7e %.7e\n",
(double)i/(double)p->nphase, p->data[i]);
}
fclose(f);
}

void write_fprofile(const char *fname, struct profile_harm *p) {
FILE *f = fopen(fname, "a");
int i;
for (i=0; i<p->nharm; i++) {
fprintf(f,"%d %.7e %.7e\n",
i, creal(p->data[i]), cimag(p->data[i]));
}
fprintf(f,"\n\n");
fclose(f);
}

void write_filter(const char *fname, struct filter_time *h) {
FILE *f = fopen(fname, "a");
int i;
for (i=0; i<h->nlag; i++) {
fprintf(f,"%d %.7e %.7e\n",
i, creal(h->data[i]), cimag(h->data[i]));
}
fprintf(f,"\n\n");
fclose(f);
}

void write_filter_freq(const char *fname, struct filter_freq *h) {
FILE *f = fopen(fname, "a");
int i;
for (i=0; i<h->nchan; i++) {
fprintf(f,"%d %.7e %.7e\n",
i, creal(h->data[i]), cimag(h->data[i]));
}
fprintf(f,"\n\n");
fclose(f);
}

void read_profile(const char *fname, struct profile_phase *pp) {
FILE *f = fopen(fname, "r");
int i;
float ptmp, dtmp;
for (i=0; i<pp->nphase; i++) {
fscanf(f,"%f %f", &ptmp, &dtmp);
pp->data[i] = dtmp;
}
fclose(f);
}

23 changes: 23 additions & 0 deletions filter_fileio.h
@@ -0,0 +1,23 @@
/* filter_fileio.h
* simple funcs for reading/writing profile and filter data.
*/

#ifndef _FILTER_FILEIO_H
#define _FILTER_FILEIO_H

#include <math.h>
#include <complex.h>
#include <fftw3.h>

#include "cyclic_utils.h"

/* Output simple text-based versions of various quantities */
void write_profile(const char *fname, struct profile_phase *p);
void write_fprofile(const char *fname, struct profile_harm *p);
void write_filter(const char *fname, struct filter_time *h);
void write_filter_freq(const char *fname, struct filter_freq *h);

/* Read in the pulse profile */
void read_profile(const char *fname, struct profile_phase *pp);

#endif
5 changes: 5 additions & 0 deletions filter_profile.c
Expand Up @@ -33,6 +33,7 @@

#include "cyclic_utils.h"
#include "cyclic_fileio.h"
#include "filter_fileio.h"
#include "model_cyclic.h"
#include "merit_functions.h"

Expand Down Expand Up @@ -484,6 +485,8 @@ int main(int argc, char *argv[]) {
for (ic=0; ic<hf.nchan; ic++) {
optimised_filters[isub-1][ic]=hf.data[ic];
}

// TODO output each filter, and dynamic spectrum here

/* Get optimised profile, given filter, for this sub-int */
int iprof = 0;
Expand All @@ -492,6 +495,8 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "Error in optimise_profile.\n");
exit(1);
}

// TODO output profiles here?

/* Convert profile(harmonic) to profile(phase) */
ph.data[0] = 0.0 + I * 0.0;
Expand Down

0 comments on commit 86d894b

Please sign in to comment.