[fitsbits] exceeding buffer limit?
Louis Giglio
giglio at hades.gsfc.nasa.gov
Wed Jul 24 11:49:18 EDT 2002
You've opened the file twice and used the same "fitsfile" structure each time:
> fits_create_file(&fptr, filename, &status);
^^^^^
> sprintf(filename, "snapshot%05d", snapshot_count/snapshot_period);
> fits_open_file(&fptr, filename, READWRITE, &status);
^^^^^
Later on you only close one of them, although I suspect because "fptr" is
clobbered the second time the file is opened that you'll get a different error
message (or a core dump) if you call fits_close_file() again. I think
removing the call to fits_open_file() will fix the problem.
Why are you opening the file twice anyway? Perhaps I'm just missing something
obvious.
Cheers,
Louis
On 22 Jul 2002, Atakan Gurkan wrote:
> Date: 22 Jul 2002 18:33:27 -0700
> From: Atakan Gurkan <hatokan at yahoo.com>
> To: fitsbits at donar.cv.nrao.edu
> Newsgroups: sci.astro.fits
> Subject: [fitsbits] exceeding buffer limit?
>
> 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
Louis Giglio
Science Systems and Applications, Inc.
NASA/GSFC Code 923
Greenbelt, MD 20771
(301) 614-6698
giglio at hades.gsfc.nasa.gov
More information about the fitsbits
mailing list