Changeset 3520
- Timestamp:
- Mar 27, 2005, 4:39:46 PM (21 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 1 added
- 12 edited
-
gastro2/Makefile (modified) (1 diff)
-
gastro2/include/gastro2.h (modified) (3 diffs)
-
gastro2/src/gstars2.c (modified) (4 diffs)
-
gastro2/src/rfits.c (modified) (2 diffs)
-
gastro2/src/rtext.c (modified) (3 diffs)
-
mosastro/Makefile (modified) (1 diff)
-
mosastro/include/mosastro.h (modified) (3 diffs)
-
mosastro/src/ConvertMatch.c (added)
-
mosastro/src/mkobs.c (modified) (3 diffs)
-
mosastro/src/mkstandards.c (modified) (4 diffs)
-
mosastro/src/rfits.c (modified) (2 diffs)
-
mosastro/src/wfits.c (modified) (2 diffs)
-
mosastro/src/wstars.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/gastro2/Makefile
r3413 r3520 14 14 # 15 15 INCS = -I$(INC) -I$(LINC) -I$(XINC) 16 LIBS = -L$(LLIB) -l FITS -lsocket -lnsl -lohana-lm16 LIBS = -L$(LLIB) -lohana -lFITS -lsocket -lnsl -lm 17 17 CFLAGS = -o $*.$(ARCH).o $(INCS) 18 18 CCFLAGS = $(INCS) $(LIBS) -
trunk/Ohana/src/gastro2/include/gastro2.h
r3466 r3520 12 12 } StarData; 13 13 14 # if (0) 14 15 typedef struct { 15 16 float X; … … 26 27 char dummy[3]; 27 28 } Stars; 29 # endif 28 30 29 31 typedef struct { … … 134 136 double lweight, size; 135 137 } Graphdata; 138 139 StarData *rtext (FILE *f, int *nstars); 140 StarData *rfits (FILE *f, int *nstars); 136 141 137 142 GSCdata *gptolemy (char *fullpath, int *Nstars); -
trunk/Ohana/src/gastro2/src/gstars2.c
r3466 r3520 1 1 # include "gastro2.h" 2 StarData *rtext (char *filename, Header *header, int *nstars);3 StarData *rfits (char *filename, Header *header, int *nstars);4 2 5 3 void gstars (char *filename, CmpCatalog *Target) { … … 8 6 char line[80]; 9 7 double det; 10 int NX, NY, FoundAstrom, extend;8 int NX, NY, Nskip, FoundAstrom, extend; 11 9 StarData *stars; 10 FILE *f; 12 11 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"); 15 16 exit (1); 16 17 } 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 17 25 NX = Target[0].header.Naxis[0]; 18 26 NY = Target[0].header.Naxis[1]; … … 115 123 Target[0].Area = fabs (NX*NY*Target[0].coords.cdelt1*Target[0].coords.cdelt2*det); 116 124 125 /* read from FITS table or from text table */ 117 126 extend = FALSE; 118 127 fits_scan (&Target[0].header, "EXTEND", "%t", 1, &extend); 119 128 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); 121 132 } 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); 123 139 } 140 fclose (f); 124 141 125 142 stars = remove_clumps (stars, &Nstars, NX, NY); … … 143 160 /* 144 161 145 load cmp file FITS header162 load cmp file FITS header 146 163 147 extract needed data from header:148 - NX, NY?149 - coords164 extract needed data from header: 165 - NX, NY? 166 - coords 150 167 151 load stellar photometry168 load stellar photometry 152 169 153 sort stars by mag170 sort stars by mag 154 171 155 filter & limit numbers172 filter & limit numbers 156 173 157 find luminosity function slope, area?174 find luminosity function slope, area? 158 175 159 176 */ -
trunk/Ohana/src/gastro2/src/rfits.c
r3413 r3520 1 1 # include "gastro2.h" 2 int ConvertStars (Stars *data, int size, int nitems);3 2 4 StarData *rfits ( char *filename, Header *header, int *nstars) {3 StarData *rfits (FILE *f, int *nstars) { 5 4 6 int i, N, Nx, Ny, Nstars; 7 FILE *f; 5 int i, N, Nstars; 8 6 Matrix matrix; 9 7 Header theader; 10 8 FTable table; 11 S tars*stars;9 SMPData *stars; 12 10 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);21 11 22 12 /* init & load in table data */ 23 13 table.header = &theader; 24 if (!fits_fread_matrix (f, &matrix, header)) goto escape;25 14 if (!fits_fread_ftable (f, &table, "SMPFILE")) goto escape; 26 15 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); 34 17 35 18 ALLOCATE (stardata, StarData, Nstars); … … 63 46 exit (1); 64 47 } 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 linux78 # define BYTE_SWAP79 # endif80 81 # ifdef sid82 # define BYTE_SWAP83 # endif84 85 # ifdef dec86 # define BYTE_SWAP87 # endif88 89 # define STARS_SIZE 4490 91 int ConvertStars (Stars *data, int size, int nitems) {92 93 int i;94 unsigned char *byte, tmp;95 96 # ifdef BYTE_SWAP97 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 # else119 return (TRUE);120 # endif121 }122 -
trunk/Ohana/src/gastro2/src/rtext.c
r3413 r3520 5 5 # define BLOCK 1000 6 6 7 StarData *rtext ( char *filename, Header *header, int *nstars) {7 StarData *rtext (FILE *f, int *nstars) { 8 8 9 9 FILE *f; … … 13 13 StarData *stars; 14 14 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; 22 16 ALLOCATE (stars, StarData, MAX (NSTARS, 1)); 23 17 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);32 18 33 19 N = Nstars = 0; … … 52 38 } 53 39 free (buffer); 54 fclose (f);55 40 56 41 if (Nstars != NSTARS) { -
trunk/Ohana/src/mosastro/Makefile
r3466 r3520 61 61 $(SRC)/wfits.$(ARCH).o \ 62 62 $(SRC)/rtext.$(ARCH).o \ 63 $(SRC)/Convert Stars.$(ARCH).o \63 $(SRC)/ConvertMatch.$(ARCH).o \ 64 64 $(SRC)/SaveResiduals.$(ARCH).o 65 65 -
trunk/Ohana/src/mosastro/include/mosastro.h
r3466 r3520 58 58 } Gradients; 59 59 60 # if (0) 60 61 typedef struct { 61 62 float X; … … 72 73 char dummy[3]; 73 74 } Stars; 75 # endif 74 76 75 77 typedef struct { … … 197 199 int mkpolyterm (int n, int m); 198 200 void 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); 201 void wstars (char *filename, SMPData *stars, int Nstars, Header *header); 201 202 int rfits (Chip *mychip); 202 203 int rtext (Chip *mychip); 203 void wfits (char *filename, S tars*stars, int Nstars, Header *header);204 void wfits (char *filename, SMPData *stars, int Nstars, Header *header); 204 205 int ConvertMatch (MatchData *data, int size, int nitems); -
trunk/Ohana/src/mosastro/src/mkobs.c
r3323 r3520 10 10 Coords map, coords; 11 11 StarData *refcat; 12 S tars*stars;12 SMPData *stars; 13 13 Header *header; 14 14 … … 73 73 Nstars = 0; 74 74 NSTARS = 1000; 75 ALLOCATE (stars, S tars, NSTARS);75 ALLOCATE (stars, SMPData, NSTARS); 76 76 77 77 /* find catalog stars on chip */ … … 98 98 if (Nstars >= NSTARS) { 99 99 NSTARS += 1000; 100 REALLOCATE (stars, S tars, NSTARS);100 REALLOCATE (stars, SMPData, NSTARS); 101 101 } 102 102 } -
trunk/Ohana/src/mosastro/src/mkstandards.c
r3323 r3520 12 12 Header *header; 13 13 Coords coords; 14 S tars*stars;14 SMPData *stars; 15 15 16 16 Random = FALSE; … … 50 50 init_random (); 51 51 52 ALLOCATE (stars, S tars, Nstars);52 ALLOCATE (stars, SMPData, Nstars); 53 53 for (i = 0; i < Nstars; i++) { 54 54 x = 2*dX*drand48(); … … 64 64 Nstars = 0; 65 65 NSTARS = 1000; 66 ALLOCATE (stars, S tars, NSTARS);66 ALLOCATE (stars, SMPData, NSTARS); 67 67 68 68 for (x = 0; x < 2*dX; x += DX) { … … 75 75 if (Nstars >= NSTARS) { 76 76 NSTARS += 1000; 77 REALLOCATE (stars, S tars, NSTARS);77 REALLOCATE (stars, SMPData, NSTARS); 78 78 } 79 79 } -
trunk/Ohana/src/mosastro/src/rfits.c
r3466 r3520 3 3 int rfits (Chip *mychip) { 4 4 5 int i, Nx , Ny;5 int i, Nx; 6 6 FILE *f; 7 7 FTable table; 8 S tars*stars;8 SMPData *stars; 9 9 10 10 /* open file for stars */ … … 30 30 } 31 31 32 /* convert to internal format */ 33 stars = (Stars *) table.buffer; 32 stars = fits_table_get_SMPData (&table, &mychip[0].Nstars); 34 33 fits_scan (table.header, "NAXIS1", "%d", 1, &Nx); 35 fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);36 mychip[0].Nstars = Ny;37 34 38 35 /* save raw data for output */ 39 36 mychip[0].FITS = TRUE; 40 37 mychip[0].buffer = (char *) stars; 41 mychip[0].Nbuffer = Nx* Ny;38 mychip[0].Nbuffer = Nx*mychip[0].Nstars; 42 39 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); 53 42 fits_free_matrix (&mychip[0].matrix); 54 43 fits_free_table (&table); -
trunk/Ohana/src/mosastro/src/wfits.c
r3466 r3520 1 1 # include "mosastro.h" 2 2 3 void wfits (char *filename, S tars*stars, int Nstars, Header *header) {3 void wfits (char *filename, SMPData *stars, int Nstars, Header *header) { 4 4 5 5 Matrix matrix; … … 18 18 fits_create_matrix (header, &matrix); 19 19 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); 42 22 43 23 fits_write_header (filename, header); -
trunk/Ohana/src/mosastro/src/wstars.c
r3416 r3520 7 7 8 8 if (data[0].FITS) { 9 wfits (filename, (S tars*) data[0].buffer, data[0].Nstars, &data[0].header);9 wfits (filename, (SMPData *) data[0].buffer, data[0].Nstars, &data[0].header); 10 10 } else { 11 11 … … 22 22 } 23 23 24 void wstars (char *filename, S tars*stars, int Nstars, Header *header) {24 void wstars (char *filename, SMPData *stars, int Nstars, Header *header) { 25 25 26 26 int i, Nchar;
Note:
See TracChangeset
for help on using the changeset viewer.
