Mac memcpy

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
What's wrong? I am not copying from dbuf to dbufs.

The values printed out for dbufs[i - 1] are all zeros.
Code:
		memcpy(dbufs[i-1],dbuf,SIZEOFFOCPL);
		printf("%d %d %d\n", i, dbuf[FOCPLWIDTH *2000 + 1200], dbufs[i - 1][FOCPLWIDTH *2000 + 1200]);
Code:
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "pcxp.h"
#include "sys/types.h"

#define STATUS 1
#define reject 1.5


int main(int argc, char *argv[])  //arvg[1] = type; arvg[2] = half the number of reads, arvg[3] = image number, [4] = 1640 frame number (from main computer) . 
	// argv[5] object argv[6] date

{
	int image = 1, reads = 1, findnew = 1, m, row, col; 
	fitsfile *fptr, *fptw;
	char * keyval, *comment, *fn1, *fn2, *fn3,  *expdirectory, *frame, *outputdir, *filename, *readsX2, *junk, *filesize, *maindirectory;
	int status = 0, i, intkeyval = 0, datfile = 0;
	char *nullstr = NULL;
	float  *ybuf, *yybuf, *xybuf, inttime_total, inttime_total2, nullval;
	double  fowlertime, inttime_sd;
	float   *obuf;
	int **dbufs,*dbuf;
	float *crefpixels, *inttime, taketime;
	
	int bzero = 0, bitpix = 16;

	int  anynull;
	char * findfile, *tmp,  *lastfile;
	
	long naxes[4];
	long naxis;
	int ndatas, no_reads;
	 
	
//	if (argc != 7)
//		{
//		fprintf(stderr,"wrong number of  arguments");
//		return(99);
//		}
//	printf("%s %s %s %s %s\n", argv[1],argv[2], argv[3], argv[4], argv[6]);
	
//	fitsfile = (fitsfile *) calloc(1, sizeof(fitsfile));
	dbuf = (int*) calloc(SIZEOFFOCPL, sizeof(int));
	obuf = (float*) calloc(SIZEOFFOCPL, sizeof(float));
	crefpixels =( float*) calloc(FOCPLWIDTH,sizeof(float));
	inttime =( float*) calloc(no_reads,sizeof(float));
	dbufs = (int**) calloc(no_reads, sizeof(int*));
	for(i = 0; i < no_reads; i++)
		dbufs[i] = (int *) calloc(SIZEOFFOCPL, sizeof (int));
	
	tmp = (char*) calloc(5,sizeof (char));
	findfile = (char*) calloc(250,sizeof (char));
	maindirectory = (char*) calloc(250,sizeof (char));
	expdirectory = (char*) calloc(250,sizeof (char));
	lastfile = (char*) calloc(250,sizeof (char));
	filename = (char*) calloc(250,sizeof (char));
	readsX2 = (char*) calloc(25,sizeof (char));
	junk = (char*) calloc(25,sizeof (char));
	filesize = (char*) calloc(25,sizeof (char));
	comment = (char*) calloc(128,sizeof (char));
	
	outputdir = (char*) calloc(250,sizeof (char));
	frame = (char*) calloc(5,sizeof (char));
	fn1 = (char*) calloc(250,sizeof (char));
	fn2 = (char*) calloc(250,sizeof (char));
	fn3 = (char*) calloc(250,sizeof (char));
	
	ybuf = (float*) calloc(SIZEOFFOCPL,sizeof(float));
	yybuf = (float*) calloc(SIZEOFFOCPL,sizeof(float));
	xybuf = (float*) calloc(SIZEOFFOCPL,sizeof(float));

//	strcpy(filename, "/Users/doug/NewPipe/Cal_Frames/DarkFrames/frame_00002_Dark.fits");
//	if( (dbuf = load_simple_fits_float_data( filename,  &naxis,  naxes, &ndatas)) == 0)
//		printf("Couldn't open slope file %s\n", filename);
	strcpy(maindirectory, "/Users/doug/CRClean/Cal_Frames/DarkFrames/20120611000023/H2RG_R01_M");
	no_reads = 64;
	for (i = 1; i < no_reads + 1; i++)
		{
		strcpy(fn1, maindirectory);
		sprintf(tmp, "%02d", i);
		strcat(fn1, tmp);
		strcat(fn1, "_N01.fits");
		
	//	if( (obuf = load_simple_fits_float_data( fn1,  &naxis,  naxes, &ndatas)) == 0)
	//		printf("Couldn't open file %s\n", fn1);
			
	//		printf("%f\n", obuf[10333]);
		if (fits_open_file(&fptr, fn1, READONLY, &status))
			printf("Couldn't open file %s %d \n", fn1, status);
	//		else
	//		printf("opened file %s %d \n", fn1, status);
		fits_read_img(fptr, TINT, (long)1,SIZEOFFOCPL, &nullval, dbuf, &anynull, &status);
		fits_read_key_flt(fptr, "INTTIME", &taketime,comment, &status);
		
		memcpy(dbufs[i-1],dbuf,SIZEOFFOCPL);
		printf("%d %d %d\n", i, dbuf[FOCPLWIDTH *2000 + 1200], dbufs[i - 1][FOCPLWIDTH *2000 + 1200]);

		inttime[i - 1] = taketime;
		inttime_total += taketime;
		inttime_total2 += taketime*taketime;;

		
	/*	for (col = 0; col < SIZEOFFOCPL; col ++)
					crefpixels[col] = 0;
		for(row = 0; (row < 4) || (row > 2043 && row < 2048); row++ )
			for(col = 3; col <2044; col++)
				crefpixels[col] += dbufs[i][row*FOCPLWIDTH + col];
			for (row = 0; row < 2048; row ++)
				for (col = 0;  col < 2048; col ++)
					dbufs[i][row*2048 + col] -= crefpixels[col];
	*/		
		}
		
//	for(i = 0; i< no_reads; i++)
//		printf("%d %d\n", i, dbufs[i][FOCPLWIDTH *2000 + 1200]);
	inttime_sd = (double)(inttime_total2 - inttime_total/(2*no_reads));

	for (row = 0; row < FOCPLWIDTH; row ++)
		for (col = 0;  col < FOCPLWIDTH; col ++)
		{	
			for (i = 0; i < no_reads; i++)
					{
					ybuf[row*2048 + col] += (float)dbufs[i][row*2048 + col];
					yybuf[row*2048 + col] += (float)dbufs[i][row*2048 + col]*dbufs[i][row*2048 + col];
					xybuf[row*2048 + col] += (float)dbufs[i][row*2048 + col]*inttime[i];
							//			printf("%f %f\n",ybuf[row*2048 + col], inttime_total );
					}
				
		obuf[row*2048 + col] = (xybuf[row*2048 + col] - ybuf[row*2048 + col]*inttime_total/(2*no_reads))/(inttime_total2 - inttime_total*inttime_total/(2*no_reads));
		}
	naxis = 2;
	naxes[0] = naxes[1] = FOCPLWIDTH;
	write_simple_fits_float_data("/Users/doug/CRClean/dark.fits",  naxis, naxes, obuf);
	

return(1640);
}
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
fixed the error where no_reads is used before initializing but that didn't help

----------

Got it.

Thanks
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
Nope. It was a stupid error. Look at memory allocation and compare with memcpy.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.