Exemplo n.º 1
0
bool writeFITS(char *filename, IMAGE *fits){
	if(!filename || !fits) return FALSE;
	int w = fits->width, h = fits->height;
	long naxes[2] = {w, h};
	size_t sz = w * h;
	fitsfile *fp;
	TRYFITS(fits_create_file, &fp, filename);
	if(fitsstatus) return FALSE;
	TRYFITS(fits_create_img, fp, fits->dtype, 2, naxes);
	if(fitsstatus) return FALSE;
	if(fits->keylist){ // there's keys
		KeyList *records = fits->keylist;
		while(records){
			char *rec = records->record;
			records = records->next;
			if(strncmp(rec, "SIMPLE", 6) == 0 || strncmp(rec, "EXTEND", 6) == 0) // key "file does conform ..."
				continue;
				// comment of obligatory key in FITS head
			else if(strncmp(rec, "COMMENT   FITS", 14) == 0 || strncmp(rec, "COMMENT   and Astrophysics", 26) == 0)
				continue;
			else if(strncmp(rec, "NAXIS", 5) == 0 || strncmp(rec, "BITPIX", 6) == 0) // NAXIS, NAXISxxx, BITPIX
				continue;
			FITSFUN(fits_write_record, fp, rec);
		//	DBG("write key: %s", rec);
		}
	}
	//fits->lasthdu = 1;
	//FITSFUN(fits_write_record, fp, "COMMENT  modified by simple test routine");
	TRYFITS(fits_write_img, fp, TDOUBLE, 1, sz, fits->data);
	if(fitsstatus) return FALSE;
	if(fits->tables && !G.deltabs) table_write(fits, fp);
	TRYFITS(fits_close_file, fp);
	return TRUE;
}
Exemplo n.º 2
0
/*
 * perform some basic tests
 */
static	void	io_test(table_t *tab_p)
{
  int		ret, bucket_n, entry_n;
  table_t	*tab2_p;
  
  (void)printf("Performing I/O tests:\n");
  (void)fflush(stdout);
  
#if 0
  {
    long	key, data;
    (void)table_clear(tab_p);
    key = 1;
    data = 2;
    (void)table_insert(tab_p, &key, sizeof(key), &data, sizeof(data), NULL, 0);
    key = 3;
    data = 4;
    (void)table_insert(tab_p, &key, sizeof(key), &data, sizeof(data), NULL, 0);
    key = 5;
    data = 6;
    (void)table_insert(tab_p, &key, sizeof(key), &data, sizeof(data), NULL, 0);
    (void)table_adjust(tab_p, 0);
    dump_table(tab_p);
  }
#endif
  
  ret = table_info(tab_p, &bucket_n, &entry_n);
  if (ret != TABLE_ERROR_NONE) {
    (void)fprintf(stderr, "could not get info of table: %s\n",
		  table_strerror(ret));
    exit(1);
  }
  (void)printf("Table we are writing has %d buckets and %d entries\n",
	       bucket_n, entry_n);
  
  /*
   * dump the table to disk
   */
  int pmode = 0640;
#ifdef win32
  pmode = _S_IREAD | _S_IWRITE;
#endif
  (void)unlink(TABLE_FILE);
  ret = table_write(tab_p, TABLE_FILE, pmode);
  if (ret != TABLE_ERROR_NONE) {
    (void)fprintf(stderr, "could not write table to '%s': %s\n",
		  TABLE_FILE, table_strerror(ret));
    exit(1);
  }
  
#if 0
  dump_table(tab_p);
#endif
  
  /*
   * now read back in the table
   */
  tab2_p = table_read(TABLE_FILE, &ret);
  if (tab2_p == NULL) {
    (void)fprintf(stderr, "could not read in file '%s': %s\n",
		  TABLE_FILE, table_strerror(ret));
    exit(1);
  }
  
  (void)printf("Testing table-read...\n");
  if (test_eq(tab_p, tab2_p, 0)) {
    (void)printf("  equal.\n");
  }
  else {
    (void)printf("  NOT equal.\n");
  }
  
  ret = table_free(tab2_p);
  if (ret != TABLE_ERROR_NONE) {
    (void)fprintf(stderr, "could not free read table: %s\n",
		  table_strerror(ret));
    exit(1);
  }
  
  /*
   * mmap in the table
   */
  tab2_p = table_mmap(TABLE_FILE, &ret);
  if (tab2_p == NULL) {
    (void)fprintf(stderr, "could not mmap file '%s': %s\n",
		  TABLE_FILE, table_strerror(ret));
    exit(1);
  }
  
  (void)printf("Testing table-mmap...\n");
  if (test_eq(tab2_p, tab_p, 0)) {
    (void)printf("  equal.\n");
  }
  else {
    (void)printf("  NOT equal.\n");
  }
  
  ret = table_munmap(tab2_p);
  if (ret != TABLE_ERROR_NONE) {
    (void)fprintf(stderr, "could not munmap file '%s': %s\n",
		  TABLE_FILE, table_strerror(ret));
    exit(1);
  }
}