IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3520


Ignore:
Timestamp:
Mar 27, 2005, 4:39:46 PM (21 years ago)
Author:
eugene
Message:

converted to autocode SMPData

Location:
trunk/Ohana/src
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/gastro2/Makefile

    r3413 r3520  
    1414
    1515INCS    =       -I$(INC) -I$(LINC) -I$(XINC)
    16 LIBS    =       -L$(LLIB) -lFITS -lsocket -lnsl -lohana -lm
     16LIBS    =       -L$(LLIB) -lohana -lFITS -lsocket -lnsl -lm
    1717CFLAGS  =       -o $*.$(ARCH).o $(INCS)
    1818CCFLAGS =       $(INCS) $(LIBS)
  • trunk/Ohana/src/gastro2/include/gastro2.h

    r3466 r3520  
    1212} StarData;
    1313
     14# if (0)
    1415typedef struct {
    1516  float X;
     
    2627  char  dummy[3];
    2728} Stars;
     29# endif
    2830
    2931typedef struct {
     
    134136  double lweight, size;
    135137} Graphdata;
     138
     139StarData *rtext (FILE *f, int *nstars);
     140StarData *rfits (FILE *f, int *nstars);
    136141
    137142GSCdata  *gptolemy (char *fullpath, int *Nstars);
  • trunk/Ohana/src/gastro2/src/gstars2.c

    r3466 r3520  
    11# include "gastro2.h"
    2 StarData *rtext (char *filename, Header *header, int *nstars);
    3 StarData *rfits (char *filename, Header *header, int *nstars);
    42
    53void gstars (char *filename, CmpCatalog *Target) {
     
    86  char line[80];
    97  double det;
    10   int NX, NY, FoundAstrom, extend;
     8  int NX, NY, Nskip, FoundAstrom, extend;
    119  StarData *stars;
     10  FILE *f;
    1211
    13   if (!fits_read_header (filename, &Target[0].header)) {
    14     fprintf (stderr, "ERROR: can't load image header\n");
     12  /* open file for stars */
     13  f = fopen (filename, "r");
     14  if (f == NULL) {
     15    fprintf (stderr, "ERROR: can't open file to load stars\n");
    1516    exit (1);
    1617  }
     18  if (!fits_fread_header (f, &Target[0].header)) {
     19    fprintf (stderr, "ERROR: can't read image header\n");
     20    exit (1);
     21  }
     22  /* this line should not be needed */
     23  fseek (f, Target[0].header.size, SEEK_SET);
     24
    1725  NX = Target[0].header.Naxis[0];
    1826  NY = Target[0].header.Naxis[1];
     
    115123  Target[0].Area = fabs (NX*NY*Target[0].coords.cdelt1*Target[0].coords.cdelt2*det);
    116124
     125  /* read from FITS table or from text table */
    117126  extend = FALSE;
    118127  fits_scan (&Target[0].header, "EXTEND",  "%t", 1, &extend);
    119128  if (extend) {
    120     stars = rfits (filename, &Target[0].header, &Nstars);
     129    Nskip = fits_matrix_size (&Target[0].header);
     130    fseek (f, Nskip, SEEK_CUR);
     131    stars = rfits (f, &Nstars);
    121132  } else {
    122     stars = rtext (filename, &Target[0].header, &Nstars);
     133    /* allocate space for stars */
     134    if (!fits_scan (&Target[0].header, "NSTARS", "%d", 1, &Nstars)) {
     135      fprintf (stderr, "ERROR: failed to find NSTARS\n");
     136      exit (1);
     137    }
     138    stars = rtext (f, &Nstars);
    123139  }
     140  fclose (f);
    124141
    125142  stars = remove_clumps (stars, &Nstars, NX, NY);
     
    143160/*
    144161
    145    load cmp file FITS header
     162load cmp file FITS header
    146163
    147    extract needed data from header:
    148    - NX, NY?
    149    - coords
     164extract needed data from header:
     165- NX, NY?
     166- coords
    150167   
    151    load stellar photometry
     168load stellar photometry
    152169
    153    sort stars by mag
     170sort stars by mag
    154171
    155    filter & limit numbers
     172filter & limit numbers
    156173
    157    find luminosity function slope, area?
     174find luminosity function slope, area?
    158175
    159176*/
  • trunk/Ohana/src/gastro2/src/rfits.c

    r3413 r3520  
    11# include "gastro2.h"
    2 int ConvertStars (Stars *data, int size, int nitems);
    32
    4 StarData *rfits (char *filename, Header *header, int *nstars) {
     3StarData *rfits (FILE *f, int *nstars) {
    54
    6   int i, N, Nx, Ny, Nstars;
    7   FILE *f;
     5  int i, N, Nstars;
    86  Matrix matrix;
    97  Header theader;
    108  FTable table;
    11   Stars *stars;
     9  SMPData *stars;
    1210  StarData *stardata;
    13 
    14   /* open file for stars */
    15   f = fopen (filename, "r");
    16   if (f == NULL) {
    17     fprintf (stderr, "ERROR: can't open file to load stars\n");
    18     exit (1);
    19   }
    20   fseek (f, header[0].size, SEEK_SET);
    2111
    2212  /* init & load in table data */
    2313  table.header   = &theader;
    24   if (!fits_fread_matrix (f, &matrix, header))          goto escape;
    2514  if (!fits_fread_ftable (f, &table, "SMPFILE")) goto escape;
    2615
    27   /* convert to internal format */
    28   stars = (Stars *) table.buffer;
    29   fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
    30   fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
    31   Nstars = Ny;
    32 
    33   if (!ConvertStars (stars, sizeof (Stars), Nstars)) goto escape;
     16  stars = fits_table_get_SMPData (&table, &Nstars);
    3417
    3518  ALLOCATE (stardata, StarData, Nstars);
     
    6346  exit (1);
    6447}
    65 
    66 # define SWAP_BYTE(X) \
    67   tmp = byte[X+0]; byte[X+0] = byte[X+1]; byte[X+1] = tmp;
    68 # define SWAP_WORD(X) \
    69   tmp = byte[X+0]; byte[X+0] = byte[X+3]; byte[X+3] = tmp; \
    70   tmp = byte[X+1]; byte[X+1] = byte[X+2]; byte[X+2] = tmp;
    71 # define SWAP_DBLE(X) \
    72   tmp = byte[X+0]; byte[X+0] = byte[X+7]; byte[X+7] = tmp; \
    73   tmp = byte[X+1]; byte[X+1] = byte[X+6]; byte[X+6] = tmp; \
    74   tmp = byte[X+2]; byte[X+2] = byte[X+5]; byte[X+5] = tmp; \
    75   tmp = byte[X+3]; byte[X+3] = byte[X+4]; byte[X+4] = tmp;
    76 
    77 # ifdef linux
    78 # define BYTE_SWAP
    79 # endif
    80 
    81 # ifdef sid
    82 # define BYTE_SWAP
    83 # endif
    84 
    85 # ifdef dec
    86 # define BYTE_SWAP
    87 # endif
    88 
    89 # define STARS_SIZE 44
    90 
    91 int ConvertStars (Stars *data, int size, int nitems) {
    92 
    93   int i;
    94   unsigned char *byte, tmp;
    95 
    96 # ifdef BYTE_SWAP
    97 
    98   if (size != STARS_SIZE) {
    99     fprintf (stderr, "mismatch in type sizes (Stars) %d vs %d\n", size, STARS_SIZE);
    100     return (FALSE);
    101   }
    102 
    103   byte = (char *) data;
    104   for (i = 0; i < nitems; i++, byte += size) {
    105     SWAP_WORD (0);   /* R */
    106     SWAP_WORD (4);   /* Y */
    107     SWAP_WORD (8);   /* M */
    108     SWAP_WORD (12);  /* dM */
    109     SWAP_WORD (16);  /* Mgal */
    110     SWAP_WORD (20);  /* Map */
    111     SWAP_WORD (24);  /* sky */
    112     SWAP_WORD (28);  /* fx */
    113     SWAP_WORD (32);  /* fy */
    114     SWAP_WORD (36);  /* df */
    115   }
    116   return (TRUE);
    117 
    118 # else
    119   return (TRUE);
    120 # endif 
    121 }
    122 
  • trunk/Ohana/src/gastro2/src/rtext.c

    r3413 r3520  
    55# define BLOCK 1000
    66
    7 StarData *rtext (char *filename, Header *header, int *nstars) {
     7StarData *rtext (FILE *f, int *nstars) {
    88
    99  FILE *f;
     
    1313  StarData *stars;
    1414
    15   /* allocate space for stars */
    16   NSTARS = -1;
    17   fits_scan (header, "NSTARS", "%d", 1, &NSTARS);
    18   if (NSTARS == -1) {
    19     fprintf (stderr, "ERROR: failed to find NSTARS\n");
    20     exit (1);
    21   }
     15  NSTARS = *nstars;
    2216  ALLOCATE (stars, StarData, MAX (NSTARS, 1));
    2317  Nbytes = NSTARS*BYTES_STAR;
    24 
    25   /* open file for stars */
    26   f = fopen (filename, "r");
    27   if (f == NULL) {
    28     fprintf (stderr, "ERROR: can't open file to load stars\n");
    29     exit (1);
    30   }
    31   fseek (f, header[0].size, SEEK_SET);
    3218
    3319  N = Nstars = 0;
     
    5238  }
    5339  free (buffer);
    54   fclose (f);
    5540 
    5641  if (Nstars != NSTARS) {
  • trunk/Ohana/src/mosastro/Makefile

    r3466 r3520  
    6161$(SRC)/wfits.$(ARCH).o \
    6262$(SRC)/rtext.$(ARCH).o \
    63 $(SRC)/ConvertStars.$(ARCH).o \
     63$(SRC)/ConvertMatch.$(ARCH).o \
    6464$(SRC)/SaveResiduals.$(ARCH).o
    6565
  • trunk/Ohana/src/mosastro/include/mosastro.h

    r3466 r3520  
    5858} Gradients;
    5959
     60# if (0)
    6061typedef struct {
    6162  float X;
     
    7273  char  dummy[3];
    7374} Stars;
     75# endif
    7476
    7577typedef struct {
     
    197199int mkpolyterm (int n, int m);
    198200void wchip (char *filename, Chip *data);
    199 void wstars (char *filename, Stars *stars, int Nstars, Header *header);
    200 int ConvertStars (Stars *data, int size, int nitems);
     201void wstars (char *filename, SMPData *stars, int Nstars, Header *header);
    201202int rfits (Chip *mychip);
    202203int rtext (Chip *mychip);
    203 void wfits (char *filename, Stars *stars, int Nstars, Header *header);
     204void wfits (char *filename, SMPData *stars, int Nstars, Header *header);
    204205int ConvertMatch (MatchData *data, int size, int nitems);
  • trunk/Ohana/src/mosastro/src/mkobs.c

    r3323 r3520  
    1010  Coords map, coords;
    1111  StarData *refcat;
    12   Stars *stars;
     12  SMPData *stars;
    1313  Header *header;
    1414
     
    7373      Nstars = 0;
    7474      NSTARS = 1000;
    75       ALLOCATE (stars, Stars, NSTARS);
     75      ALLOCATE (stars, SMPData, NSTARS);
    7676
    7777      /* find catalog stars on chip */
     
    9898        if (Nstars >= NSTARS) {
    9999          NSTARS += 1000;
    100           REALLOCATE (stars, Stars, NSTARS);
     100          REALLOCATE (stars, SMPData, NSTARS);
    101101        }
    102102      }
  • trunk/Ohana/src/mosastro/src/mkstandards.c

    r3323 r3520  
    1212  Header *header;
    1313  Coords coords;
    14   Stars *stars;
     14  SMPData *stars;
    1515
    1616  Random = FALSE;
     
    5050    init_random ();
    5151
    52     ALLOCATE (stars, Stars, Nstars);
     52    ALLOCATE (stars, SMPData, Nstars);
    5353    for (i = 0; i < Nstars; i++) {
    5454      x = 2*dX*drand48();
     
    6464    Nstars = 0;
    6565    NSTARS = 1000;
    66     ALLOCATE (stars, Stars, NSTARS);
     66    ALLOCATE (stars, SMPData, NSTARS);
    6767
    6868    for (x = 0; x < 2*dX; x += DX) {
     
    7575        if (Nstars >= NSTARS) {
    7676          NSTARS += 1000;
    77           REALLOCATE (stars, Stars, NSTARS);
     77          REALLOCATE (stars, SMPData, NSTARS);
    7878        }
    7979      }
  • trunk/Ohana/src/mosastro/src/rfits.c

    r3466 r3520  
    33int rfits (Chip *mychip) {
    44
    5   int i, Nx, Ny;
     5  int i, Nx;
    66  FILE *f;
    77  FTable table;
    8   Stars *stars;
     8  SMPData *stars;
    99
    1010  /* open file for stars */
     
    3030  }
    3131
    32   /* convert to internal format */
    33   stars = (Stars *) table.buffer;
     32  stars = fits_table_get_SMPData (&table, &mychip[0].Nstars);
    3433  fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
    35   fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
    36   mychip[0].Nstars = Ny;
    3734
    3835  /* save raw data for output */
    3936  mychip[0].FITS = TRUE;
    4037  mychip[0].buffer = (char *) stars;
    41   mychip[0].Nbuffer = Nx*Ny;
     38  mychip[0].Nbuffer = Nx*mychip[0].Nstars;
    4239
    43   if (Ny < 5) {
    44     fprintf (stderr, "Too few stars for reliable solution, only %d\n", Ny);
    45     fits_free_matrix (&mychip[0].matrix);
    46     fits_free_table (&table);
    47     fclose (f);
    48     return (FALSE);
    49   }
    50 
    51   if (!ConvertStars (stars, sizeof (Stars), mychip[0].Nstars)) {
    52     fprintf (stderr, "conversion error\n");
     40  if (mychip[0].Nstars < 5) {
     41    fprintf (stderr, "Too few stars for reliable solution, only %d\n", mychip[0].Nstars);
    5342    fits_free_matrix (&mychip[0].matrix);
    5443    fits_free_table (&table);
  • trunk/Ohana/src/mosastro/src/wfits.c

    r3466 r3520  
    11# include "mosastro.h"
    22
    3 void wfits (char *filename, Stars *stars, int Nstars, Header *header) {
     3void wfits (char *filename, SMPData *stars, int Nstars, Header *header) {
    44
    55  Matrix matrix;
     
    1818  fits_create_matrix (header, &matrix);
    1919   
    20   /* create bintable header */
    21   fits_create_table_header (&theader, "BINTABLE", "SMPFILE");
    22 
    23   /* define bintable layout */
    24   fits_define_bintable_column (&theader, "E",    "X_PIX",      "x coord",              "pixels",                         1.0, 0.0);
    25   fits_define_bintable_column (&theader, "E",    "Y_PIX",      "y coord",              "pixels",                         1.0, 0.0);
    26   fits_define_bintable_column (&theader, "E",    "MAG_RAW",    "inst mags",            "mags",                           1.0, 0.0);
    27   fits_define_bintable_column (&theader, "E",    "MAG_ERR",    "inst mag error",       "mags",                           1.0, 0.0);
    28   fits_define_bintable_column (&theader, "E",    "MAG_GAL",    "galaxy mag",           "mags",                           1.0, 0.0);
    29   fits_define_bintable_column (&theader, "E",    "MAG_AP",     "aperture mag",         "mags",                           1.0, 0.0);
    30   fits_define_bintable_column (&theader, "E",    "LOG_SKY",    "log-10 of sky",        "mags",                           1.0, 0.0);
    31   fits_define_bintable_column (&theader, "E",    "FWHM_X",     "semi-major",           "mags",                           1.0, 0.0);
    32   fits_define_bintable_column (&theader, "E",    "FWHM_Y",     "semi-minor",           "mags",                           1.0, 0.0);
    33   fits_define_bintable_column (&theader, "E",    "THETA",      "ellipse angle",        "mags",                           1.0, 0.0);
    34   fits_define_bintable_column (&theader, "B",    "DOPHOT",     "dophot type",          "",                              1.0, 0.0);
    35   fits_define_bintable_column (&theader, "3A",   "DUMMY",      "padding",              "",                              1.0, 0.0);
    36 
    37   /* create table, add data values */
    38   fits_create_table (&theader, &table);
    39 
    40   ConvertStars (stars, sizeof (Stars), Nstars);
    41   fits_add_rows (&table, (char *) stars, Nstars, sizeof (Stars));
     20  table.header = &theader;
     21  fits_table_set_SMPData (&table, stars, Nstars);
    4222
    4323  fits_write_header  (filename, header);
  • trunk/Ohana/src/mosastro/src/wstars.c

    r3416 r3520  
    77
    88  if (data[0].FITS) {
    9     wfits (filename, (Stars *) data[0].buffer, data[0].Nstars, &data[0].header);
     9    wfits (filename, (SMPData *) data[0].buffer, data[0].Nstars, &data[0].header);
    1010  } else {
    1111
     
    2222}
    2323
    24 void wstars (char *filename, Stars *stars, int Nstars, Header *header) {
     24void wstars (char *filename, SMPData *stars, int Nstars, Header *header) {
    2525 
    2626  int i, Nchar;
Note: See TracChangeset for help on using the changeset viewer.