[fitsbits] exceeding buffer limit?
Atakan Gurkan
hatokan at yahoo.com
Mon Jul 22 21:33:27 EDT 2002
Hi,
I am using FITS format to take snapshots for a program.However, I can
only write 40 files. This is suspicious because NIOBUF is 40, but I am
closing the files each time I finish writing them. My subroutine that
deals with snapshots looks like this:
void take_snapshot(struct star *s, struct cluster c, struct code_par
cp){
static int snapshot_count = 0;
int snapshot_period = 3;
fitsfile *fptr;
int status;
long firstrow, firstelem;
int tfields; /* table will have n columns */
long nrows;
char extname[] = "CLUSTER_STARS"; /* extension name */
char filename[128];
char *ttype[] = { "Mass"};
char *tform[] = { "1D"};
char *tunit[] = { "Nbody"};
double *mass;
unsigned long i, N;
snapshot_count++;
if ( (snapshot_count%snapshot_period) ){
return;
}
printf("taking snapshot %05d\n", snapshot_count/snapshot_period);
N = c.NSTAR;
mass = malloc((N+2)*sizeof(double));
for(i=0; i<=N+1; i++){
mass[i] = s[i].m;
}
status = 0;
tfields = 4;
nrows = N+2;
sprintf(filename, "!snapshot%05d", snapshot_count/snapshot_period);
fits_create_file(&fptr, filename, &status);
sprintf(filename, "snapshot%05d", snapshot_count/snapshot_period);
fits_open_file(&fptr, filename, READWRITE, &status);
fits_create_tbl(fptr, BINARY_TBL, nrows, tfields, ttype, tform,
tunit, extname, &status);
fits_update_key(fptr, TLONG, "NSTAR", &(N),
"No of Stars", &status);
firstrow = 1; /* first row in table to write */
firstelem = 1; /* first element in row (ignored in ASCII tables) */
fits_write_col(fptr, TDOUBLE, 1, firstrow, firstelem, nrows, mass,
&status);
free(mass);
fits_close_file(fptr, &status);
printerror(status);
}
I removed a few lines to make it shorter.
printerror() is from cookbook.c
it dies with the message:
FITSIO status = 115: NULL input pointer
failed to create new file (already exists?):
snapshot00040
I would really appreciate if someone could provide some insight.
Thank you,
Atakan Gurkan
More information about the fitsbits
mailing list