forked from MarkWalker/Cyclic-Modelling
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move profile/filter read/write routines to separate file.
- Loading branch information
Showing
5 changed files
with
96 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters