11.07.2014 Views

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

280 APPENDIX B. PROGRAM LISTINGS<br />

/*<br />

ParseImpedance.c<br />

By Andrew Botros, 2001-2004<br />

Modified by Paul Dickens, 2005, 2006<br />

Listing B.19: ParseImpedance.c<br />

ParseImpedance.c reads an acoustic impedance spectra file <strong>and</strong><br />

returns a Vector <strong>of</strong> Vectors <strong>of</strong> Points. Refer to ParseImpedance.h for<br />

interface details.<br />

*/<br />

#include <br />

#include <br />

#include <br />

#include "Vector.h"<br />

#include "Point.h"<br />

#include "ParseImpedance.h"<br />

int parseImpedanceFile(Vector filev, char* filename) {<br />

FILE* fp;<br />

char* line = (char*)malloc(BUFSIZ*size<strong>of</strong>(char));<br />

char* delimiters = " \t";<br />

char* token;<br />

int* midi;<br />

double x;<br />

Point p;<br />

Vector seriesVector;<br />

int series;<br />

/* open data file <strong>and</strong> indicate any error */<br />

if((fp = fopen(filename, "r")) == NULL) {<br />

fprintf(stderr, "Cannot open file %s\n", filename);<br />

return 0;<br />

}<br />

/* parse midi line <strong>and</strong> add midi numbers to Vector */<br />

fgets(line, BUFSIZ, fp);<br />

token = strtok(line, delimiters);<br />

while((token != NULL) && (token != "\n")) {<br />

seriesVector = createVector();<br />

midi = (int*)malloc(size<strong>of</strong>(char));<br />

*midi = atoi(token);<br />

addElement(seriesVector, midi);<br />

addElement(filev, seriesVector);<br />

token = strtok(NULL, delimiters);<br />

}<br />

/* parse each line <strong>and</strong> add points to Vector */<br />

while(fgets(line, BUFSIZ, fp) != NULL) {<br />

/* Parse x value */<br />

token = strtok(line, delimiters);<br />

if(token != NULL)<br />

x = at<strong>of</strong>(token);<br />

else {<br />

fprintf(stderr, "File %s is invalid\n", filename);<br />

return 0;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!