Hello there
I am having a problem with trying to draw a curve through the data points on my graph.
I can do it with cpgdraw fine, since it runs within the while loop. However, attempting to use cpgdraw with multiple data sets results in the code drawing lines between them, which obviously leads to a very messy and nonsensical graph.
When trying with cpgline though i get these errors:
electro.c:43: warning: passing argument 2 of `cpgline` makes pointer from integer without a cast
electro.c:43: error: incompatible type for argument 3 of `cpgline`
Unfortunately, my university was not very good at teaching us c properly and so me (and the other students) are learning on the fly which as you can imagine leads to issues like these which are probably simple but just escape me.
Code:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <cpgplot.h>
#define MAX 50
#define FILENAMELENMAX 100
struct EMinfo {
int position, angle1, angle2, angle3, angle4, angle5, angle6;
float voltage1, voltage2, voltage3, volatge4, voltage5, voltage6; };
int main()
{
struct EMinfo data[MAX];
int cnt;
char datafile [FILENAMELENMAX];
FILE *f;
int xmin, xmax;
float ymin, ymax;
printf("Please input data file location\n");
scanf("%s", datafile );
f = fopen(datafile,"r");
cnt = 0;
xmax = 90;
xmin = 20;
ymax = 2;
ymin = 0;
cpgbeg(0, "?", 1, 1);
cpgenv(xmin, xmax, ymin, ymax, 0, 1);
cpglab("Angle /o", "Voltage /mV", "Transmitted intensity as a function of angle for Sand");
while(!feof(f) && cnt < MAX){
fscanf(f, "%d %g %d %g\n", &data[cnt].angle1, &data[cnt].voltage1, &data[cnt].angle2, &data[cnt].voltage2);
printf("anglewIR = %d, voltagewIR = %g, angledIR = %d, voltagedIR = %g\n", data[cnt].angle1, data[cnt].voltage1, data[cnt].angle2, data[cnt].voltage2);
cpgline(50, data[cnt].angle1, data[cnt].voltage1);
data[cnt].position = cnt;
cnt++;
}
cpgend();
fclose(f);
printf("Read %d records from the data file\n", cnt);
}
Any help is greatly appreciated, you might have to treat me like a complete idiot with c though