Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
The error is that "y1 redeclared as a different kind of symbol."
However *y1 is defined once and y1 is never defined only used either as y1[row] or to be passed in a function. Neither appear in the h file.

The code is first followed by the h file.

thanks

Code:
#include "p1640.h"

void changedir(char * object, char * date);
void get_memory(int rows, int cols);
char * makecuberoot(char * object, char* date);
char ** makedatasetlist( char *root, int num, int reads);
float * magnify(float *image, int rows, int cols,float magx, float magy);
FILE * makefilelist(char * object, char * date);
float *shift(float *image, int rows, int cols, float shiftx, float shifty);
float * slice(float * image);
void spline(float x[], float y[], int n, float yp1, float ypn, float y2[]);
void splint(float xa[], float ya[], float y2a[], int n, float x, float *y);
void splie2 (float x1a[], float x2a[], float **ya, int m, int n, float **y2a);
void splin2(float x1a[], float x2a[], float **ya, float **y2a, int m, int n, float r1, float r2, float *y);

float *x1, *x2, **y, **ys;
float  *ys1, *y1; 


int main (int argc, const char * argv[]) 
{ 
	float * magedimag, *image,  *icube; 
	int slice;
    float magx, magy;
//	int start_row, end_row, start_col, end_col; 
	int slicedelta, width, firstset, lastset,reads ;
//	char *cube;
	FILE *filelist;
	int i, j, quad, firstslice,lastslice;
	float maxmag;
	float *tmpimage;
	char** datasetlist, *cuberoot;
   
    
    get_memory(reduced_size, reduced_size);
	maxmag = 230;
	
	if (argc != 8)
	{
		printf("input object, date, ring separation, ring width, number of first and last dataset, and number of reads on the command line\n");
		return(0);
	}
	slicedelta = atoi(argv[3]);
	width = atoi(argv[4]);
	firstset = atoi(argv[5]);
	lastset = atoi(argv[6]);
	reads = atoi(argv[7]);
	
    tmpimage = (float *) calloc(imagesize, sizeof(float));
    
    cuberoot = makecuberoot((char*)argv[1],(char*)argv[2]); 
	changedir((char*)argv[1],(char*)argv[2]);	
		
	firstslice = 1 + slicedelta;
	lastslice = waves - slicedelta;
	
	system ( "rm -f magtest.fits");
	for (i = firstset; i <= lastset; i = i + 100)
	{	 
        datasetlist = 	makedatasetlist(cuberoot, i, reads); 
        for (j = 0; j < reads - 1; j = j+ 100)
        {
            printf("%s\n", datasetlist[j]);
            if ( (icube = load_simple_fits_float_data(datasetlist[j], &naxis, naxes, &ndatas) ) == NULL) 
            {
                (void) stderr, fprintf(stderr, "main: load_simple_fits_float_data %s failed\n", datasetlist[j]);
                return 0; 
            }
            naxis = 2;
            for (slice = firstslice; slice <= lastslice; slice += slice + 100)
            {
                memcpy(tmpimage, icube + (slice - firstslice)*imagesize, sizeof(float)*imagesize);
                for (magx = 176; magx <= maxmag; magx += 1000)
                {
                    magx = magx/175;
                    magedimag = magnify(tmpimage,175 ,175,  magx, magx);
                    naxes[0] = 175*magx;
                    naxes[1] = 175*magx;
                    write_simple_fits_float_data("magtest.fits", naxis, naxes, magedimag);
                }
            } //end of slice
        } // end j
          
    }
	
    free (magedimag);
	free (image);
	free (icube);
	//free (cube);
	

	
	return(0);
}


#define fpsize 2048
#define lenslets_size  250
#define imagesize (lenslets_size*lenslets_size)
#define centersize  407
#define ctrpixel 125
#define ctrradius 10
#define low_res 25
#define high_res 67
#define magnifyfpfactor 3
#define pixelsperlenset 10.568  
 //lenslet rotation 
#define sinr .322 
#define cosr .947

#define reduced_size  175

#define mag 10.568
#define waves 23

#define no 0
#define yes 1
//#define psfdir	"/extract/psfs/"
#define psfdir "/proj1640_pipeline-debug5/library/laser/psf/"
#define psf24dir "/data/psfs24/"

#define psf30dir "/data/psfs30/"
#define psfalldir "/proj1640_pipeline-debug5/library/laser/psfall/"
#define mapdir  "/data/maps25/"

#define data "/DATA/"
#define filtersize  15
#define fwhm1 5
#define fwhm2 16
#define processed_data "/data/processed/"

#define sizeofcube lenslets_size*lenslets_size*waves

#define MAXAXES   3     

#include "/cfitsio/include/fitsio.h"
#include "/cfitsio/include/fitsio2.h"
#include "/cfitsio/include/longnam.h"
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <sys/dir.h>
#include <sys/param.h>





float * opencube (char *av);
float * makefilter();
long naxis;
long naxes[MAXAXES];
int ndatas;
int row, col,fpcol, fprow;



void ludcmp( float **a, int n, int *indx, float *d);
void lubksb(float **a, int n, int *indx, float b[]);
void inverse(float  **a, float **b, int N);
float ** MatrixMult(float **a, float **b, int N);
float ABAT(float **a, float *b, int n);

int findlaserspots(char * infile, char * outfile);
int makelaserpsf(char * spotfile, char *infile, char * outfile);
int centroidpsfs (char * spotfile, char * psffile);
void makefilters(int* fpcols, int* fprows,float ** spots, int col, int row);
//char *laserdirectory, *cmd1, *codedirectory,*psfdirectory,*darkdirectory, *infile1, *outfile1, *spotfile1, *spotsdirectory ;
//char  *cmd2,  *infile2, *outfile2, *spotfile2 ;



//void spline(float x[], float y[], int n, float yp1, float ypn, float y2[]);
//void splint(float xa[], float ya[], float y2a[], int n, float x, float *y);
//void splie2 (float x1a[], float x2a[], float **ya, int m, int n, float **y2a);
//void splin2(float x1a[], float x2a[], float **ya, float **y2a, int m, int n, float x1, float x2, float *y);


float * load_simple_fits_float_data(char *fn, long *naxis, long *naxes, int *ndatas);
int write_simple_fits_float_data(char *fn, long naxis, long *naxes, float *dbuf);
static void printerror(const char *msg, int status);


float * load_simple_fits_float_data(char *fn, long *naxis, long *naxes, int *ndatas)
{
	int DEBUG = 0;
    fitsfile   *fptr;        /* fits ptr    */
    int        status=0;
    long       nelem;
	
    char       cmnt[128];
	
    float      nullval = 0.0;    /* fits arcanum */
    int        anynull = 0;    /* fits arcanum */
	
	
    const char        *axisname[7] = { "NAXIS1",  "NAXIS2",  "NAXIS3",  
		"NAXIS4",  "NAXIS5",  "NAXIS6",  "NAXIS7" };
    int        i;
    float      *ldbuf;        /* local space */
	if(DEBUG)
		printf("%s\n", "0");	

	
    /* Open fits file... */
    if (fits_open_file(&fptr, fn, READONLY, &status)) {
        printerror("load_simple_fits_float_data: fits_open_file: ", status);
        return NULL;
    }
	if(DEBUG)
		printf("%s\n", "A");	
    /* get a few keywords */
	
    /* find image dimensionality */
    if (fits_read_key(fptr, TLONG, "NAXIS", naxis, cmnt, &status)) {
        printerror("load_simple_fits_float_data: fits_read_key: NAXIS", status);
        return NULL;
    }
    /*(void) fprintf(stderr, "    NAXIS = %d\n", (int) *naxis);*/
	if(DEBUG)
		printf("%s\n", "B");
	
    /* find image size for as many axes as exist */
    for (i=0, nelem=1; i<*naxis; i++) {
        if (fits_read_key(fptr, TLONG, axisname[i], naxes+i, cmnt, &status)) {
			printerror("load_simple_fits_float_data: fits_read_key:",
					   status);
			return NULL;
        }
        /*(void) fprintf(stderr, "    %s = %d\n", axisname[i],  (int) naxes[i]);*/
        nelem *= naxes[i];
    }
    
	if(DEBUG)
		printf("%s\n", "b");
	if (*naxis > MAXAXES) {
        /*(void) fprintf(stderr, "    %d axes > allowable dimensionality (%d)\n", (int) *naxis, MAXAXES);*/
        return NULL;
	}
	
	if(DEBUG)
		printf("%s\n", "C");
	
    /* (void) fprintf(stderr, "    There are %d pixels in %s, %d * %d is %d\n", (int)nelem, fn,
	 (int)naxes[0], (int)naxes[1],  (int)(naxes[0] * naxes[1])); */
	
	
    /* allocate zeroed space for data in the buffer ptr ldbuf */
    if ((ldbuf = (float *) calloc(nelem, sizeof(float))) == NULL) {
        (void) fprintf(stderr, "load_simple_fits_float_data: Out of mem for ldbuf\n");
        return NULL;
    }
	if(DEBUG)
		printf("%s\n","D");
	if (fits_read_img(fptr, TFLOAT, (long)1, nelem, &nullval,
					  ldbuf, &anynull, &status)) {
        printerror("load_simple_fits_float_data: fits_read_image:",
				   status);
        return NULL;
    }
	if(DEBUG)
		printf("%s\n", "E");
	
    /* close the table */
    if (fits_close_file(fptr, &status)) {
        printerror("load_simple_fits_float_data: fits_close_file: ", status);
        return NULL;
    }
	
	*ndatas = (int)nelem;
	if(DEBUG)
		printf("%s\n", "F\n");
	
    return ldbuf;
}

int write_simple_fits_float_data(char *fn, long naxis, long *naxes, float *dbuf)
{
	
    fitsfile   *fptr;        /* fits ptr    */
    int        status=0;
    long       nelem;
    long       fpixel=1;
	
    char       cmnt[128];
	
	float       meaning = 42.0;
    int        i;
	
   // (void) printf("    NAXIS = %d\n", (int) naxis);
	nelem = 1;
	for (i=0; i<naxis; i++) {
		nelem *= naxes[i];
    	(void) printf("%d.", (int) naxes[i]);
	}
    (void) printf(" = %ld pixels\n", (long int) nelem);
	
	
	/* open up a fits file handle.. */
	if (fits_create_file(&fptr, fn, &status)) {
		printerror("write_simple_fits_float_data: fits_create_file: ", status);
		return -1; 
	}
	
	
    /* Create fits file... */
    if (fits_create_img(fptr, FLOAT_IMG, naxis, naxes, &status)) {
		printerror("write_simple_fits_float_data: fits_create_file: ", status);
		return -1; }
	
    /* set a keyword value for fun */
	strcpy(cmnt, "Life, the Universe and everything");
    if (fits_update_key(fptr, TFLOAT, "LUNVNVRT", &meaning, cmnt, &status)) {
        printerror("write_simple_fits_float_data: fits_update_key: NAXIS", status);
        return -1;
    }
	
	
    /* dump data to fits file */
    if (fits_write_img(fptr, TFLOAT, fpixel, nelem, dbuf, &status)) {
        printerror("write_simple_fits_float_data: fits_write_file: ", status);
        return -1;
    }
	
	
    /* close the fits file */
    if (fits_close_file(fptr, &status)) {
        printerror("write_simple_fits_float_data: fits_close_file: ", status);
        return -1;
    }
	return nelem;
	
}


static void printerror(const char *msg, int status) {
	
    if (status != 0) {
        fprintf(stderr, "%s ", msg);
        fits_report_error(stderr, status);
    }
}
 
I don't have the cfitsio libraries available, so i can't really test this. Why don't you try renaming y1 to my_y1 or something similar to see if there is a conflict with a symbol in the library?

-Lee
 
Thanks guys.

Sorry Lee. Next time I'll remember to comment out those lines.
 
Right-click on y1 in your source code and choose "Show Definition".

It seems you didn't show us _all_ header files, only the ones you thought we needed to see. As usual.
 
Why bother responding when I've already given the answer and yes I forgot the fits headers but nobody has been able to compile them anyway. Do you have the cfitsio library?
 
Why bother responding when I've already given the answer and yes I forgot the fits headers but nobody has been able to compile them anyway. Do you have the cfitsio library?

Just wondering if you will ever develop any problem-solving skills other than posting here. Or if you will ever at least develop the wish to develop any problem-solving skills.

As an example, did you _read_ my post? Did you find anything helpful in it? Anything that might help you the next time to solve a problem yourself instead of another inane post?

You started with an error message: "The error is that "y1 redeclared as a different kind of symbol."" Problem solving skill: Read the error message. Believe the error message. When the compiler says it is redeclared as a different kind of symbol, then it _is_ redeclared as a different kind of symbol. So what is the next thing you post? "However bla bla bla the compiler is wrong". No, it isn't. Don't argue with the compiler, you lose the argument every time and get nowhere. Trust the compiler.

If y1 is redeclared, it must be declared in another place than you thought. That's why I told you "right click on y1 and choose "Jump To Definitions"". Gets you straight into <math.h> to the declaration of five functions with names j0, j1, jn, y0 and y1.

But what is worse: When I compile this in XCode, the error message isn't just "y1 redeclared as a different kind of symbol". I get a red exclamation mark, and when I click on it it says "y1 redeclared as a different kind of symbol. Previous declaration of double y1 (double)". Do you have eyes to see? The compiler finds a problem, shoves the answer right into your face, and you can't see it because you think the compiler must be wrong.
 
Gnasher, I didn't get where I am today getting other people to solve my problems. And I certainly would love to know more about C code; It would probably be more efficient but given what's on my plate, I pick up knowledge where and when I can. Now I know about right clicking on errors. I did look to see where I was redefining y1. It didn't occur to be that I was redefining a fixed c variable. I am focused on reducing by iraf code that runs for several days into something, that I hope runs in under an hour. Then, and with a little luck, maybe I can solve the original data reduction problem I have. Then I may not have to look at c for another year by which time I will have forgotten a lot of what I know. Next month I have to modify a program I wrote 2 years ago in a language that I haven't used since. You think this is easy? Its not but I get it done, that's why I work with the best.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.