Package: pgplot5
Version: 5.2.2-8
Severity: normal
Can you tell me what's wrong compiling/linking the attached source?
Yours,
Gürkan
-------- Original Message --------
Subject: Re: cpgplot
Date: Fri, 7 Dec 2007 14:03:41 +0100 (CET)
From: Katarina Kovac <[EMAIL PROTECTED]>
To: Gürkan Sengün <[EMAIL PROTECTED]>
CC: ISG Department Physik <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
Hi Guerkan
I have done the following
gcc -c plotslice_v2.c
and then
f77 -o plotslice_v2 plotslice_v2.o -lcpgplot -lpgplot -lX11 -lgcc -lm
Katarina
p.s. the code is in the attachment
On Fri, 7 Dec 2007, Gürkan Sengün wrote:
Hi Katarina
How do you compiler your program?
When you say ldd yourprogram does it list pgplot?
Can you add -lpgplot to your compile line?
Yours,
Guerkan
> this is one of the pgplot webpages:
>
> http://www.astro.caltech.edu/~tjp/pgplot/
>
> and how to call it from C
>
> http://www.astro.caltech.edu/~tjp/pgplot/cbinding.html;
>
> if I do everything as in the webpage, I'm getting these errors:
>
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_set_text'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_set_IHDR'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_set_tRNS'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_create_write_struct'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_write_row'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_write_info'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_set_PLTE'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_write_end'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_create_info_struct'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_destroy_write_struct'
> /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/libpgplot.so: undefined
> refere
> nce to `png_init_io'
> collect2: ld returned 1 exit status
> Thanks
> Katarina
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "cpgplot.h"
void nrerror(char error_text[]);
float *vector(long nl, long nh);
int *ivector(long nl, long nh);
double *dvector(long nl, long nh);
float **matrix(long nrl, long nrh, long ncl, long nch);
double min(double x, double y);
double max(double x, double y);
void palett(int type, float contra, float bright);
void fiddle();
void free_vector(float *v, long nl, long nh);
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch);
int getline(char *line, int max);
int readfortranrecord(FILE *infile, char *fmt, ...);
int main(int argc, char *argv[]) {
FILE *infile;
char ctmp[20],*infilename,axis,square;
int npoints,i,j;
float *fr,*xselect,*yselect,dummy,low,up;
float xsquare,ysquare,xsquarear[5],ysquarear[5],squaresize,
xline[2],yline[2],boxsize,simboxsize,*rtmp,r[1000][2],ftmp,*sptype;
long ldummy,npart,nearly,nlate,counter;
float *x,*y,*z,*xearly,*yearly,*xlate,*ylate,*ra,*dec;
float *red,deltaz;
int *class;
int nsel,narc;
float redsharc,*xsel,*ysel;
float hcsize,xmin,xmax,ymin,ymax,deltax,deltay,ramin,ramax,*xarc,*yarc,
phi0,phi1,pi,twopi,dec0,phimark,deltared,redmark,deltaphi;
float dec0ngp,dec0sgp;
float rauplimngp,ralowlimngp,rauplimsgp,ralowlimsgp;
/* Initialize variables */
hcsize=11.; /* Size of hardcopies in cm (along longest axis) */
// redsharc=.175; /* Max redshift to be plotted */
redsharc=.22;
pi=3.1415927;
twopi=2.*pi;
if (argc!=2) {
printf("Usage: plotslicesoutharcsmall particles.dat\n");
exit(1);
}
infilename=*++argv;
/* Load particle data from file. */
infile=fopen(infilename,"r");
fscanf(infile,"%ld\n",&npoints);
printf("npoints: %ld\n",npoints);
x=vector(0,npoints-1);
y=vector(0,npoints-1);
z=vector(0,npoints-1);
sptype=vector(0,npoints-1);
ra=vector(0,npoints-1);
dec=vector(0,npoints-1);
for (i=0l; i<npoints; i++)
fscanf(infile,"%f%f%f%f%f%f\n",&x[i],&y[i],&z[i],&sptype[i],&ra[i],&dec[i]);
fclose(infile);
printf("Ready.\n");
/* Open graphical device. */
printf("\n");
if (cpgbeg(0,"?",1,1) != 1)
exit(1);
cpgask(1);
xmin=-.3;
xmax=.3;
ymin=-.2;
ymax=.2;
deltax=xmax-xmin;
deltay=ymax-ymin;
cpgpap(hcsize,1.);
cpgslw(4.);
cpgpage();
cpgsvp(0.5-.4*deltax/deltay,.5+.4*deltax/deltay,0.1,.9);
cpgswin(xmin,xmax,ymin,ymax);
cpgbox("ut",0.,0,"",0.,0);
cpgslw(2.);
cpgsch(.75);
cpgpt(npoints,x,y,-1);
/* Construct arc */
rauplimngp=twopi*(14.+50./60.)/24.;
ralowlimngp=twopi*(10.-10./60.)/24.;
rauplimsgp=twopi*(3.+30./60.)/24.;
ralowlimsgp=twopi*(-2.-15./60.)/24.;
dec0ngp=twopi*-0.9394/360.;
dec0sgp=twopi*-29.1523/360.;
dec0=dec0sgp;
ramax=rauplimsgp;
ramin=ralowlimsgp;
phi0=-(ramax-ramin)*cos(dec0)/2.;
phi1=(ramax-ramin)*cos(dec0)/2.;
// deltaz=.001666666;
// redsharc=.11-.5*deltaz;
narc=2500;
xarc=vector(0,narc-1);
yarc=vector(0,narc-1);
for (i=0; i<narc; i++) {
xarc[i]=redsharc*cos(phi0+i*(phi1-phi0)/(narc-1.));
yarc[i]=redsharc*sin(phi0+i*(phi1-phi0)/(narc-1.));
}
cpgslw(4.);
cpgpt(narc,xarc,yarc,-1);
xline[0]=0.;
xline[1]=redsharc*cos(phi0);
yline[0]=0.;
yline[1]=redsharc*sin(phi0);
cpgline(2,xline,yline);
xline[0]=0.;
xline[1]=redsharc*cos(phi1);
yline[0]=0.;
yline[1]=redsharc*sin(phi1);
cpgline(2,xline,yline);
// redsharc=.11+.5*deltaz;
narc=2500;
xarc=vector(0,narc-1);
yarc=vector(0,narc-1);
for (i=0; i<narc; i++) {
xarc[i]=redsharc*cos(phi0+i*(phi1-phi0)/(narc-1.));
yarc[i]=redsharc*sin(phi0+i*(phi1-phi0)/(narc-1.));
}
cpgslw(4.);
cpgpt(narc,xarc,yarc,-1);
xline[0]=0.;
xline[1]=redsharc*cos(phi0);
yline[0]=0.;
yline[1]=redsharc*sin(phi0);
cpgline(2,xline,yline);
xline[0]=0.;
xline[1]=redsharc*cos(phi1);
yline[0]=0.;
yline[1]=redsharc*sin(phi1);
cpgline(2,xline,yline);
narc=2500;
xarc=vector(0,narc-1);
yarc=vector(0,narc-1);
for (i=0; i<narc; i++) {
xarc[i]=redsharc*cos(phi0+i*(phi1-phi0)/(narc-1.));
yarc[i]=redsharc*sin(phi0+i*(phi1-phi0)/(narc-1.));
}
cpgslw(4.);
cpgpt(narc,xarc,yarc,-1);
xline[0]=0.;
xline[1]=redsharc*cos(phi0);
yline[0]=0.;
yline[1]=redsharc*sin(phi0);
cpgline(2,xline,yline);
xline[0]=0.;
xline[1]=redsharc*cos(phi1);
yline[0]=0.;
yline[1]=redsharc*sin(phi1);
cpgline(2,xline,yline);
cpgslw(3.);
cpgsch(.8);
/* Construct tickmarks */
/* at 22h, 23h, 0h, 1h, 2h and 3h */
deltared=.003;
phimark=twopi*(22.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"22\\uh\\u");
phimark=twopi*(23.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"23\\uh\\u");
phimark=twopi*(24.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"0\\uh\\u");
phimark=twopi*(25.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"1\\uh\\u");
phimark=twopi*(26.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"2\\uh\\u");
phimark=twopi*(27.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"3\\uh\\u");
phimark=0.;
cpgptxt((redsharc+7.*deltared)*cos(phimark),
(redsharc+7.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"RA");
deltared=.003;
redmark=.05;
deltaphi=atan(deltared/redmark);
xline[0]=redmark*cos(phi1);
xline[1]=deltared/sin(deltaphi)*cos(phi1+deltaphi);
yline[0]=-redmark*sin(phi1);
yline[1]=-deltared/sin(deltaphi)*sin(phi1+deltaphi);
cpgline(2,xline,yline);
deltaphi=atan(2.*deltared/redmark);
cpgptxt(-.005+2.*deltared/sin(deltaphi)*cos(phi1+deltaphi),
-.005-2.*deltared/sin(deltaphi)*sin(phi1+deltaphi),
-360.*phi1/twopi,0.5,".05");
redmark=.1;
deltaphi=atan(deltared/redmark);
xline[0]=redmark*cos(phi1);
xline[1]=deltared/sin(deltaphi)*cos(phi1+deltaphi);
yline[0]=-redmark*sin(phi1);
yline[1]=-deltared/sin(deltaphi)*sin(phi1+deltaphi);
cpgline(2,xline,yline);
deltaphi=atan(2.*deltared/redmark);
cpgptxt(-.005+2.*deltared/sin(deltaphi)*cos(phi1+deltaphi),
-.005-2.*deltared/sin(deltaphi)*sin(phi1+deltaphi),
-360.*phi1/twopi,0.5,".10");
redmark=.15;
deltaphi=atan(deltared/redmark);
xline[0]=redmark*cos(phi1);
xline[1]=deltared/sin(deltaphi)*cos(phi1+deltaphi);
yline[0]=-redmark*sin(phi1);
yline[1]=-deltared/sin(deltaphi)*sin(phi1+deltaphi);
cpgline(2,xline,yline);
deltaphi=atan(2.*deltared/redmark);
cpgptxt(-.005+2.*deltared/sin(deltaphi)*cos(phi1+deltaphi),
-.005-2.*deltared/sin(deltaphi)*sin(phi1+deltaphi),
-360.*phi1/twopi,0.5,".15");
redmark=.2;
deltaphi=atan(deltared/redmark);
xline[0]=redmark*cos(phi1);
xline[1]=deltared/sin(deltaphi)*cos(phi1+deltaphi);
yline[0]=-redmark*sin(phi1);
yline[1]=-deltared/sin(deltaphi)*sin(phi1+deltaphi);
cpgline(2,xline,yline);
deltaphi=atan(2.*deltared/redmark);
cpgptxt(-.005+2.*deltared/sin(deltaphi)*cos(phi1+deltaphi),
-.005-2.*deltared/sin(deltaphi)*sin(phi1+deltaphi),
-360.*phi1/twopi,0.5,".20");
redmark=redsharc/2.;
deltaphi=atan(7.*deltared/redmark);
cpgptxt(7.*deltared/sin(deltaphi)*cos(phi1+deltaphi),
-.01-7.*deltared/sin(deltaphi)*sin(phi1+deltaphi),
-360.*phi1/twopi,0.5,"Redshift");
dec0=dec0ngp;
ramax=rauplimngp;
ramin=ralowlimngp;
phi0=-(ramax-ramin)*cos(dec0)/2.;
phi1=(ramax-ramin)*cos(dec0)/2.;
narc=2500;
xarc=vector(0,narc-1);
yarc=vector(0,narc-1);
for (i=0; i<narc; i++) {
xarc[i]=-redsharc*cos(phi0+i*(phi1-phi0)/(narc-1.));
yarc[i]=-redsharc*sin(phi0+i*(phi1-phi0)/(narc-1.));
}
cpgslw(4.);
cpgpt(narc,xarc,yarc,-1);
xline[0]=0.;
xline[1]=-redsharc*cos(phi0);
yline[0]=0.;
yline[1]=-redsharc*sin(phi0);
cpgline(2,xline,yline);
xline[0]=0.;
xline[1]=-redsharc*cos(phi1);
yline[0]=0.;
yline[1]=-redsharc*sin(phi1);
cpgline(2,xline,yline);
cpgslw(3.);
cpgsch(.8);
/* Construct tickmarks */
/* at 22h, 23h, 0h, 1h, 2h and 3h */
deltared=.003;
phimark=twopi*(22.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"10\\uh\\u");
phimark=twopi*(23.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"11\\uh\\u");
phimark=twopi*(24.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"12\\uh\\u");
phimark=twopi*(25.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"13\\uh\\u");
phimark=twopi*(26.-24.)/24.*cos(dec0)-(ramax+ramin)/2.*cos(dec0)-twopi;
xline[0]=(redsharc+deltared)*cos(phimark);
xline[1]=redsharc*cos(phimark);
yline[0]=(redsharc+deltared)*sin(phimark);
yline[1]=redsharc*sin(phimark);
cpgline(2,xline,yline);
cpgptxt((redsharc+2.*deltared)*cos(phimark),
(redsharc+2.*deltared)*sin(phimark),
270.+360.*phimark/twopi,0.5,"14\\uh\\u");
deltared=.003;
redmark=-.05;
deltaphi=atan(deltared/redmark);
xline[0]=redmark*cos(phi1);
xline[1]=deltared/sin(deltaphi)*cos(phi1-deltaphi);
yline[0]=-redmark*sin(phi1);
yline[1]=-deltared/sin(deltaphi)*sin(phi1-deltaphi);
cpgline(2,xline,yline);
deltaphi=atan(2.*deltared/redmark);
redmark=-.1;
deltaphi=atan(deltared/redmark);
xline[0]=redmark*cos(phi1);
xline[1]=deltared/sin(deltaphi)*cos(phi1-deltaphi);
yline[0]=-redmark*sin(phi1);
yline[1]=-deltared/sin(deltaphi)*sin(phi1-deltaphi);
cpgline(2,xline,yline);
deltaphi=atan(2.*deltared/redmark);
redmark=-.15;
deltaphi=atan(deltared/redmark);
xline[0]=redmark*cos(phi1);
xline[1]=deltared/sin(deltaphi)*cos(phi1-deltaphi);
yline[0]=-redmark*sin(phi1);
yline[1]=-deltared/sin(deltaphi)*sin(phi1-deltaphi);
cpgline(2,xline,yline);
deltaphi=atan(2.*deltared/redmark);
redmark=-.2;
deltaphi=atan(deltared/redmark);
xline[0]=redmark*cos(phi1);
xline[1]=deltared/sin(deltaphi)*cos(phi1-deltaphi);
yline[0]=-redmark*sin(phi1);
yline[1]=-deltared/sin(deltaphi)*sin(phi1-deltaphi);
cpgline(2,xline,yline);
deltaphi=atan(2.*deltared/redmark);
/* Close graphical device. */
cpgclos();
}
#define NR_END 1
#define FREE_ARG char*
void nrerror(char error_text[])
/* Numerical Recipes standard error handler */
{
fprintf(stderr,"Numerical Recipes run-time error...\n");
fprintf(stderr,"%s\n",error_text);
fprintf(stderr,"...now exiting to system...\n");
exit(1);
}
float *vector(long nl, long nh)
/* allocate a float vector with subscript range v[nl..nh] */
{
float *v;
v=(float *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float)));
if (!v) nrerror("allocation failure in vector()");
return v-nl+NR_END;
}
int *ivector(long nl, long nh)
/* allocate a integer vector with subscript range v[nl..nh] */
{
int *v;
v=(int *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(int)));
if (!v) nrerror("allocation failure in vector()");
return v-nl+NR_END;
}
double *dvector(long nl, long nh)
/* allocate a double vector with subscript range v[nl..nh] */
{
double *v;
v=(double *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(double)));
if (!v) nrerror("allocation failure in vector()");
return v-nl+NR_END;
}
float **matrix(long nrl, long nrh, long ncl, long nch)
/* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
{
long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
float **m;
/* allocate pointers to rows */
m=(float **) malloc((size_t)((nrow+NR_END)*sizeof(float*)));
if (!m) nrerror("allocation failure 1 in matrix()");
m += NR_END;
m -= nrl;
/* allocate rows and set pointers to them */
m[nrl]=(float *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float)));
if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
m[nrl] += NR_END;
m[nrl] -= ncl;
for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
/* return pointer to array of pointers to rows */
return m;
}
void free_vector(float *v, long nl, long nh)
/* free a float vector allocated with vector() */
{
free((FREE_ARG) (v+nl-NR_END));
}
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
/* free a float matrix allocated by matrix() */
{
free((FREE_ARG) (m[nrl]+ncl-NR_END));
free((FREE_ARG) (m+nrl-NR_END));
}
double min(double x, double y)
{
/* This function returns the smaller value of x and y. If x is equal to y,
then x is returned.
Written by Willem Schaap, June 1998 */
return(
x <= y ?
x
:
y
);
}
/*-----------------------------------------------------------------------*/
double max(double x, double y)
{
/* This function returns the larger value of x and y. If x is equal to y,
then x is returned.
Written by Willem Schaap, June 1998 */
return(
x >= y ?
x
:
y
);
}
void palett(int type, float contra, float bright) {
int i;
float light[256],red[256],green[256],blue[256];
FILE *infile;
/* Gray scale */
static float gl[2]={0.,1.};
static float gr[2]={0.,1.};
static float gg[2]={0.,1.};
static float gb[2]={0.,1.};
/* Rainbow */
static float rl[9]={-.5,0.,.17,.33,.5,.67,.83,1.,1.7};
static float rr[9]={0.,0.,0.,0.,.6,1.,1.,1.,1.};
static float rg[9]={0.,0.,0.,1.,1.,1.,.6,0.,1.};
static float rb[9]={0.,.3,.8,1.,.3,0.,0.,0.,1.};
/* Heat 2 */
static float h2l[5]={0.,.2,.6,.85,1.};
static float h2r[5]={0.,.5,1.,1.,1.};
static float h2g[5]={0.,0.,.5,1.,1.};
static float h2b[5]={0.,0.,0.,.3,1.};
/* Blue White */
static float bl[5]={0.,.25,.5,.75,1.};
static float br[5]={0.,0.,.5,.75,1.};
static float bg[5]={0.,0.,.5,.75,1.};
static float bb[5]={0.,.5,1.,1.,1.};
/* IDL Heat */
static float rrl[4]={0.,.6,.85,1.};
static float rrr[4]={0.,1.,1.,1.};
static float rrg[4]={0.,.33,.65,1.};
static float rrb[4]={0.,0.,0.,1.};
/* GIPSY Heat */
if (type==4) {
infile=fopen("/ray1/users/wschaap/C/lib/lut/heat.lut","r");
for (i=0; i<256; i++) {
light[i]=i/255.;
fscanf(infile,"%f %f %f",&red[i],&green[i],&blue[i]);
}
fclose(infile);
}
/* GIPSY Mousse */
if (type==7) {
infile=fopen("/ray1/users/wschaap/C/lib/lut/mousse.lut","r");
for (i=0; i<256; i++) {
light[i]=i/255.;
fscanf(infile,"%f %f %f",&red[i],&green[i],&blue[i]);
}
fclose(infile);
}
/* GIPSY Background */
if (type==8) {
infile=fopen("/ray1/users/wschaap/C/lib/lut/backgr.lut","r");
for (i=0; i<256; i++) {
light[i]=i/255.;
fscanf(infile,"%f %f %f",&red[i],&green[i],&blue[i]);
}
fclose(infile);
}
if (type==1) cpgctab(gl,gr,gg,gb,2,contra,bright);
if (type==6) cpgctab(rl,rr,rg,rb,9,contra,bright);
if (type==4) cpgctab(light,red,green,blue,256,contra,bright);
if (type==3) cpgctab(h2l,h2r,h2g,h2b,5,contra,bright);
if (type==5) cpgctab(bl,br,bg,bb,5,contra,bright);
if (type==7) cpgctab(light,red,green,blue,256,contra,bright);
if (type==8) cpgctab(light,red,green,blue,256,contra,bright);
if (type==2) cpgctab(rrl,rrr,rrg,rrb,4,contra,bright);
return;
}
/*-----------------------------------------------------------------------*/
void fiddle() {
int p,ier;
float contra,bright,x,y,sign,
x1,y1,x2,y2,b1,b2,c1,c2;
char ch;
printf("Use cursor to adjust color table:\n");
printf("Keys 1,2,3,4,5 select different palettes.\n");
printf("Key P cycles through available palettes.\n");
printf("Key F adjusts contrast and brightness, with ");
printf("cursor x position setting brightness [0.0-1.0]\n");
printf("and y position setting contrast [0.0-10.0].\n");
printf("Key C resets contrast=1.0, brightness=0.5\n");
printf("Key - reverses color palette.\n");
printf("Key X or right mouse button exits program.\n");
p=2;
contra=1.;
bright=.5;
x=.5;
y=1.;
sign=+1.;
cpgqwin(&x1,&x2,&y1,&y2);
b1=0.;
b2=1.;
c1=0.;
c2=10.;
cpgswin(b1,b2,c1,c2);
while (1) {
ier=cpgcurs(&x,&y,&ch);
if (ch==0 || ch=='x' || ch=='X') {
cpgswin(x1,x2,y1,y2);
break;
}
else if (ch=='f' || ch=='F') {
bright=max(b1,min(b2,x));
contra=max(c1,min(c2,y));
}
else if (ch=='c' || ch=='C') {
contra=1.;
y=1.;
bright=.5;
x=.5;
}
else if (ch=='-')
sign=-sign;
else if (ch=='1')
p=1;
else if (ch=='2')
p=2;
else if (ch=='3')
p=3;
else if (ch=='4')
;
else if (ch=='5')
p=5;
else if (ch=='6')
p=6;
else if (ch=='7')
;
else if (ch=='8')
;
else if (ch=='p' || ch=='P')
p=1+p%8;
palett(p,sign*contra,bright);
}
return;
}
int getline(char *line, int max) {
if (fgets(line, max, stdin) == NULL)
return 0;
else
return strlen(line);
}
#define MAXLEN 1000 /* maximum length of strings */
#define MAXARR 20 /* maximum array dimension is 10^20 */
int readfortranrecord(FILE *infile, char *fmt, ...)
{
/* The function readfortranrecord reads fortran unformatted data records.
Each function call reads one record of unformatted datafile.
The format of the data must be specified by the user in the
string fmt. This string may consists of the characters l, d, f
and s, each may be preceded by a positive integer or a slash.
l denotes a long integer, d a double, f a float and s a character
string. Notice that fortran integers correspond with C long integers.
A number before a letter denotes an array, so 2l denotes an array of
2 long integers. After the format string the corresponding pointer
arguments must be specified. A slash also denotes an array, but the
length of the array is then denoted by the value of a long argument.
Example: readfortranrecord(fortran.data, "5lld4fs10s/f", a, &b, &c,
d, e, f, &g, 16) reads a record of the file stream fortran.data.
This record must consist of an array of 5 long integers, a single
long integer, a single double, an array of 4 floats, a single string,
an array of 10 strings and an array of 16 floats(in this order).
The arguments may be defined by e.g. long int a[5], b; double c;
float d[4], char *e, **f, float g[16];
readfortranrecord returns the size of the record in bytes. On errors
zero is returned.
Written by Willem Schaap, June 1998. */
int arraylen, flag, index;
long int recordlength;
char *arraylength;
va_list ap;
arraylength = malloc(sizeof(char[MAXARR]));
/* Initialize variable argument list */
va_start(ap, fmt);
/* Read recordlength. In each record of fortran unformatted
datafiles the first and last entry are long ints containing the
length of the record in bytes */
fread(&recordlength, sizeof(long int), 1, infile);
/* Continue main loop until all variables specified in format have
been read */
while (*fmt)
{
/* Get arraylength if it has been specified. Convert it
to an integer. Test if arraylength is not too large. */
flag=0;
for (index = 0; isdigit(*fmt) && index < MAXARR; index++)
*arraylength++ = *fmt++;
if (index == MAXARR)
{
printf("Error: array size too large.\n");
return (0);
}
*arraylength = '\0';
arraylength -= index;
arraylen = atoi(arraylength);
if (!arraylen)
arraylen = 1;
if (*fmt=='/') {
fmt++;
flag=1;
}
switch (*fmt)
{
case 'f':
/* float */
{
/* Declare pointer q and let it point to the next argument
in the variable argument list */
float *q = va_arg(ap, float *);
if (flag)
arraylen = va_arg(ap, long);
fread(q, sizeof(float), arraylen, infile);
break;
}
case 'd':
/* double */
{
/* Declare pointer q and let it point to the next argument
in the variable argument list */
double *q = va_arg(ap, double *);
if (flag)
arraylen = va_arg(ap, long);
fread(q, sizeof(double), arraylen, infile);
break;
}
case 'l':
/* integer */
{
/* Declare pointer q and let it point to the next argument
in the variable argument list */
long int *q = va_arg(ap, long int *);
if (flag)
arraylen = va_arg(ap, long);
/* Read (array of) long int(s) */
fread(q, sizeof(long int), arraylen, infile);
break;
}
case 's':
/* string */
{
/* Declare pointer q and let it point to the next argument
in the variable argument list */
int index2 = 0;
char *q = va_arg(ap, char *);
if (flag)
arraylen = va_arg(ap, long);
do
{
fread(q, sizeof(char), arraylen, infile);
index2++;
}
while (*q);
q -= index2;
break;
}
default :
/* Error handling for unknown format specification */
{
printf("Format error. Character %c unknown.\n", *fmt);
return (0);
}
}
fmt++;
}
/* Read recordlength */
fread(&recordlength, sizeof(long int), 1, infile);
/* Deinitialize variable argumentlist */
va_end(ap);
return (recordlength);
}
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/