Changeset 5234
- Timestamp:
- Oct 7, 2005, 6:33:25 AM (21 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 13 edited
-
addstar/doc/Changes.txt (modified) (1 diff)
-
addstar/doc/notes.txt (modified) (1 diff)
-
addstar/include/addstar.h (modified) (2 diffs)
-
addstar/src/args.c (modified) (2 diffs)
-
addstar/src/build_links.c (modified) (4 diffs)
-
addstar/src/find_matches.c (modified) (12 diffs)
-
addstar/src/find_matches_closest.c (modified) (11 diffs)
-
addstar/src/gcatalog.c (modified) (2 diffs)
-
addstar/src/mkcatalog.c (modified) (1 diff)
-
addstar/src/wcatalog.c (modified) (1 diff)
-
libohana/include/dvo.h (modified) (5 diffs)
-
libohana/src/dvo_catalog.c (modified) (1 diff)
-
libohana/src/dvo_catalog_split.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/doc/Changes.txt
r5229 r5234 1 2 2005.10.06 3 split / nosort / update 4 I have added a few new concepts to addstar recently: split 5 catalog files, nosort for the measurement table, and 6 update-only. 7 8 split mode 9 10 The split mode is quite straightforeward. In this mode, each 11 catalog is represented by a set of four files: *.cpt, *.cpm, 12 *.cpn, *.cps. Each file contains only one FITS table of the 13 data, along with basic header and empty matrix. Having 14 individual tables for each component of the database lets me 15 add entries without re-writing the entire table. This should 16 save on I/O operations in the long run. 17 18 The first file contains the table of averages, and is the file 19 normally identified in the table lookup functions. The header 20 of this file contains the names of the other table files 21 (paths relative to the directory containing the cpt file). 22 The names and extensions are specified in 'mkcatalog.c'; all 23 other functions use the defined filename references, rather 24 than expecting a naming convention. 25 26 The additional files contain the measures (cpm), missings 27 (cpn), and secfilt (cps) elements of the catalog tables. 28 29 To facilitate the handling of the additional filenames, file 30 pointers, and headers, Catalog was extended to include 31 pointers to the measure, missing, and secfilt files as 32 additional catalogs. When the data are loaded into memory, 33 these catalogs are locked (as usual), and file information is 34 stored in the individual Catalog entries; the data segements 35 are all loaded into the main catalog pointers (eg, measures 36 are loaded into catalog[0].measure, rather than 37 catalog[0].measure_catalog[0].measure). 38 39 The function 'load_catalog' auto-recognizes the SPLIT format 40 by looking for the header keyword MEASURE, identifying the 41 file containing the measures. The identification of the RAW 42 format and the SPLIT format are not cross-checked: if the 43 NAXIS keyword is set to 2, the file is assumed to be RAW, even 44 if the MEASURE keyword is present. Careful with this (though 45 there is no reason the main matrix should be used in a basic 46 database table). 47 48 nosort 49 50 the nosort option by itself provides a minor processing 51 speed-up by deferring the re-sorting of the measurement table 52 until after multiple addstar processes are run. addstar 53 should not require the measurements to be sorted, so this step 54 can be safetly deferred if only addstars are being performed. 55 the other DVO operations require the sorted table, so the sort 56 must be performed before they are run (either as part of the 57 catalog load, not implemented yet, or with a call to addstar 58 without the -nosort option set. the real goal of the nosort 59 option is to enable the -update concept in addstar, in which 60 only the new rows are written out; this will only work if 61 addstar can handle unsorted measures. 62 63 the nosort option required the addition of a 'sorted' element 64 in the Catalog structure to track if the data are sorted or 65 not. On load, this flag is set based on the value of the 66 header keyword SORTED; if the data is sorted during addstar, 67 the flag is appropriately set, otherwise it is set FALSE be 68 default. 69 70 The nosort option requires a function which can generate the 71 'next_meas' link sequence based on the measure table. there 72 is now a function called 'build_meas_link' which generates a 73 correct link list; there is also the pair of functions 74 'init_meas_links' and'init_miss_links' to generate the links 75 in the event that the table is sorted (should be must 76 quicker). 77 78 The 'missing' table is problematic: the LONEOS and ELIXIR 79 formats do not carry an averef entry, thus they do not have 80 enough information to define the links based only on the 81 missing table. This means we are forced to write out a sorted 82 missing table; the nosort option is invalid for the missing 83 table. One future upgrade path is to add the averef entry to 84 the PANSTARRS format and then only require the missing table 85 to be sorted if the format is old and does not support 86 -nosort. (Note also that, for the moment, the missing table 87 has only a single valid format). 88 89 In the process of defining the nosort option, I also cleaned 90 up a bit the find_matches functions to use clearer functions 91 for the links. 92 93 update 94 95 The 'update' process in principle allows addstar to 96 substantially reduce the amount of I/O it needs to perform by 97 only requiring addstar to write out new measures and new 98 average/secfilt entries. 99 100 The 'missing' table is problematic: since the format does not 101 support the 'nosort' option, it is not possible to use update 102 with the missing table. This means we are forced to write out 103 a complete, sorted missing table. This is currently 104 implemented in update_catalog_split by simply writing out the 105 complete missing table. In fact, this choice is still flawed 106 because the average table, since it is not written out in full 107 each time, is inconsistent with the missing table: the Nn 108 entries for each average, which identifies the number of 109 missing entries, are not updated. In practice, this means 110 that the -update option forces the use of the -missed option, 111 though at the moment, this is not forced or checked in any 112 way. 113 114 Note that the 'missed' table contains duplicate information 115 and can, in principle, be completely regenerated at any time. 116 This should be an addstar option: to re-construct the missing 117 table, potentially with constraints on the images which are 118 searched for matches. 1 119 2 120 2005.10.04 -
trunk/Ohana/src/addstar/doc/notes.txt
r5229 r5234 1 1 2 - measure <-> average matches and reordering 2 2005.10.06 3 3 4 next[i] = i + 1 5 6 7 8 4 I am getting seg faults from find_matches_closest, apparently related to the 5 partial Measure load. They occur when trying to realloc secfilt. I 6 tried to debug using the ohana_allocate stuff, but it causes 7 problems because fitsio does not fall under the ohana memory 8 system. This is fairly bad; I should probably deal with that issue 9 before pursuing the other stuff. Do I have to make libfits depend 10 on libohana, in which case I should probably split off libdvo from 11 libohana. That is probably not a bad plan in any case... 9 12 10 13 2005.03.07 : notes related to new version of addstar -
trunk/Ohana/src/addstar/include/addstar.h
r5229 r5234 103 103 int ONLY_MATCH; 104 104 int CLOSEST; 105 int REORDER; 105 106 int NOSORT; 107 int UPDATE; 106 108 107 109 int MODE; … … 190 192 int add_miss_link (Average *average, int *next, int Nmissing); 191 193 int *build_measure_links (Average *average, int Naverage, Measure *measure, int Nmeasure); 192 Measure * reorder_measure (Average *average, int Naverage, Measure *measure, int Nmeasure, int *next);193 Missing * reorder_missing (Average *average, int Naverage, Missing *missing, int Nmissing, int *next_miss);194 Measure *sort_measure (Average *average, int Naverage, Measure *measure, int Nmeasure, int *next); 195 Missing *sort_missing (Average *average, int Naverage, Missing *missing, int Nmissing, int *next_miss); 194 196 195 197 /** -
trunk/Ohana/src/addstar/src/args.c
r5229 r5234 23 23 fprintf (stderr, " -replace : replace time/photcode measurements (no duplication)\n"); 24 24 fprintf (stderr, " -closest : use closest-star algorith\n"); 25 fprintf (stderr, " -nosort : don't re-sort the measure entries (improves speed)\n"); 26 fprintf (stderr, " -update : only update the new rows (foreces -nosort)\n"); 25 27 fprintf (stderr, " -image : only insert image data\n"); 26 28 fprintf (stderr, " -cal : perform zero-point calibration\n"); … … 151 153 remove_argument (N, &argc, argv); 152 154 } 153 /* only add new rows (-update) or re-write complete measure table */ 154 REORDER = TRUE; 155 156 /* don't re-sort the measure sequence */ 157 NOSORT = FALSE; 158 if ((N = get_argument (argc, argv, "-nosort"))) { 159 NOSORT = TRUE; 160 remove_argument (N, &argc, argv); 161 } 162 /* only add new rows (-update) or re-write complete measure table (forces -nosort) */ 163 UPDATE = FALSE; 155 164 if ((N = get_argument (argc, argv, "-update"))) { 156 REORDER = FALSE; 157 remove_argument (N, &argc, argv); 158 } 165 UPDATE = TRUE; 166 NOSORT = TRUE; 167 remove_argument (N, &argc, argv); 168 } 169 159 170 /* only add image potion to image table */ 160 171 ONLY_IMAGES = FALSE; -
trunk/Ohana/src/addstar/src/build_links.c
r5229 r5234 1 1 # include "addstar.h" 2 2 3 /* build the initial links assuming the table is re-ordered */3 /* build the initial links assuming the table is sorted */ 4 4 int *init_measure_links (Average *average, int Naverage, Measure *measure, int Nmeasure) { 5 5 … … 23 23 } 24 24 25 /* build the initial links assuming the table is re-ordered */25 /* build the initial links assuming the table is sorted */ 26 26 int *init_missing_links (Average *average, int Naverage, Missing *missing, int Nmissing) { 27 27 … … 94 94 m = next[m]; 95 95 } 96 if (m == Nm) continue; 97 next[m] = Nm; 96 if (m == Nm) { 97 average[averef].Nm = k + 1; 98 } else { 99 average[averef].Nm = k + 2; 100 next[m] = Nm; 101 } 98 102 } 99 103 return (next); 100 104 } 101 105 102 /* Missing does not carry enough information to recons ruct the links106 /* Missing does not carry enough information to reconstruct the links 103 107 we must always save the missing table, if it exists */ 104 108 105 Measure * reorder_measure (Average *average, int Naverage, Measure *measure, int Nmeasure, int *next) {109 Measure *sort_measure (Average *average, int Naverage, Measure *measure, int Nmeasure, int *next) { 106 110 107 111 int i, k, n, N; … … 124 128 } 125 129 126 Missing * reorder_missing (Average *average, int Naverage, Missing *missing, int Nmissing, int *next) {130 Missing *sort_missing (Average *average, int Naverage, Missing *missing, int Nmissing, int *next) { 127 131 128 132 int i, k, n, N; -
trunk/Ohana/src/addstar/src/find_matches.c
r5229 r5234 8 8 float dX, dY, dR; 9 9 int *N1, *N2, *next_meas, *next_miss; 10 int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch ;10 int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch, offset; 11 11 Coords tcoords; 12 12 int Nsecfilt, Nsec; … … 41 41 NMEAS = Nmeas = catalog[0].Nmeasure; 42 42 NMISS = Nmiss = catalog[0].Nmissing; 43 offset = catalog[0].Nmeas_off; 43 44 44 45 /* project onto rectilinear grid with 1 arcsec pixels */ … … 76 77 77 78 /* set up pointers for linked list of measure, missing */ 78 if (catalog[0]. ordered) {79 if (catalog[0].sorted) { 79 80 next_meas = init_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas); 80 81 } else { … … 82 83 } 83 84 next_miss = init_missing_links (catalog[0].average, Nave, catalog[0].missing, Nmiss); 84 /* missing MUST be written ordered, or not at all */85 /* missing MUST be written 'sorted', or not at all */ 85 86 86 87 /* choose a radius for matches */ … … 142 143 catalog[0].measure[Nmeas].Mcal_PS = image[0].Mcal_PS; 143 144 catalog[0].measure[Nmeas].t = image[0].tzero + 1e-4*stars[N].Y*image[0].trate; /* trate is in 0.1 msec / row */ 144 catalog[0].measure[Nmeas].averef = n; 145 catalog[0].measure[Nmeas].averef = n; /* this must be an absolute sequence number, if partial average is loaded */ 145 146 catalog[0].measure[Nmeas].source = stars[N].code; /* photcode */ 146 147 catalog[0].measure[Nmeas].dophot = stars[N].dophot; … … 159 160 Mval = (Nsec == -1) ? &catalog[0].average[n].M_PS : &catalog[0].secfilt[n*Nsecfilt+Nsec].M_PS; 160 161 if (*Mval == NO_MAG) *Mval = Mcat; 162 /* in UPDATE mode, this value is not saved; use relphot to recalculate */ 161 163 162 164 /* adds the measurement to the calibration if appropriate color terms are found */ … … 184 186 catalog[0].found[n] = Nmeas; 185 187 } 188 /* Nm is updated, but not written out in -update mode (for existing entries) 189 Nm is recalculated in build_meas_links if loaded table is not sorted */ 186 190 catalog[0].average[n].Nm ++; 187 191 Nmeas ++; 188 192 189 update_coords (&catalog[0].average[n], &catalog[0].measure[0], next_meas); 193 if (!UPDATE) { 194 /* in UPDATE mode, newly calculated coordinates are not saved */ 195 update_coords (&catalog[0].average[n], &catalog[0].measure[0], next_meas); 196 } 190 197 } 191 198 i++; … … 217 224 218 225 /* incorporate unmatched image stars, if this star is in field of this catalog */ 226 /* these new entries are all written out in UPDATE mode */ 219 227 for (i = 0; (i < Nstars) && !ONLY_MATCH; i++) { 220 228 /* make sure there is space for next entry */ … … 245 253 catalog[0].average[Nave].Xm = NO_MAG; 246 254 catalog[0].average[Nave].Xg = NO_MAG; 247 catalog[0].average[Nave].offset = Nmeas ;255 catalog[0].average[Nave].offset = Nmeas + offset; /* this needs to be an absolute reference */ 248 256 catalog[0].average[Nave].missing = -1; 249 257 catalog[0].average[Nave].code = 0; … … 261 269 catalog[0].measure[Nmeas].Mcal_PS = image[0].Mcal_PS; 262 270 catalog[0].measure[Nmeas].t = image[0].tzero + 1e-4*stars[N].Y*image[0].trate; /* trate is in 0.1 msec / row */ 263 catalog[0].measure[Nmeas].averef = Nave; 271 catalog[0].measure[Nmeas].averef = Nave; /* XXX EAM : must be absolute Nave if partial read */ 264 272 catalog[0].measure[Nmeas].source = stars[N].code; /* photcode */ 265 273 catalog[0].measure[Nmeas].dophot = stars[N].dophot; … … 296 304 } 297 305 306 /* next[Nmeas] should always be -1 in this context (it is always the only 307 measurement for the star) */ 298 308 stars[N].found = Nmeas; 299 309 next_meas[Nmeas] = -1; … … 316 326 } */ 317 327 318 if (REORDER) { 319 catalog[0].measure = reorder_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas); 320 catalog[0].ordered = TRUE; 328 if (NOSORT) { 329 catalog[0].sorted = FALSE; 321 330 } else { 322 catalog[0].ordered = FALSE; 323 } 324 catalog[0].missing = reorder_missing (catalog[0].average, Nave, catalog[0].missing, Nmiss, next_miss); 331 catalog[0].sorted = TRUE; 332 catalog[0].measure = sort_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas); 333 } 334 catalog[0].missing = sort_missing (catalog[0].average, Nave, catalog[0].missing, Nmiss, next_miss); 325 335 /* missing is REQUIRED to be sorted */ 326 336 -
trunk/Ohana/src/addstar/src/find_matches_closest.c
r5229 r5234 3 3 void find_matches_closest (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap) { 4 4 5 int i, j, n, N, J ;5 int i, j, n, N, J, Jmin; 6 6 double X, Y, RADIUS, RADIUS2, Rmin, secz; 7 7 float *X1, *Y1, *X2, *Y2; 8 8 float dX, dY, dR; 9 9 int *N1, *N2, *next_meas, *next_miss; 10 int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch, Jmin;10 int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch, offset; 11 11 Coords tcoords; 12 12 int Nsecfilt, Nsec; … … 41 41 NMEAS = Nmeas = catalog[0].Nmeasure; 42 42 NMISS = Nmiss = catalog[0].Nmissing; 43 offset = catalog[0].Nmeas_off; 43 44 44 45 /* project onto rectilinear grid with 1 arcsec pixels */ … … 76 77 77 78 /* set up pointers for linked list of measure, missing */ 78 if (catalog[0]. ordered) {79 if (catalog[0].sorted) { 79 80 next_meas = init_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas); 80 81 } else { … … 82 83 } 83 84 next_miss = init_missing_links (catalog[0].average, Nave, catalog[0].missing, Nmiss); 84 /* missing MUST be written ordered, or not at all */85 /* missing MUST be written 'sorted', or not at all */ 85 86 86 87 /* choose a radius for matches */ … … 174 175 Mval = (Nsec == -1) ? &catalog[0].average[n].M_PS : &catalog[0].secfilt[n*Nsecfilt+Nsec].M_PS; 175 176 if (*Mval == NO_MAG) *Mval = Mcat; 177 /* in UPDATE mode, this value is not saved; use relphot to recalculate */ 176 178 177 179 /* adds the measurement to the calibration if appropriate color terms are found */ … … 183 185 /* if we choose to calculate RA,DEC averages, see update_coords.c */ 184 186 187 /* Nm is updated, but not written out in -update mode (for existing entries) 188 Nm is recalculated in build_meas_links if loaded table is not sorted */ 185 189 stars[N].found = Nmeas; 186 190 catalog[0].found[n] = Nmeas; … … 189 193 i++; 190 194 } 195 196 ohana_memcheck (0); 191 197 192 198 /** add reference for undetected catalog stars **/ … … 215 221 216 222 /** incorporate unmatched image stars, if this star is in field of this catalog **/ 223 /* these new entries are all written out in UPDATE mode */ 217 224 for (i = 0; (i < Nstars) && !ONLY_MATCH; i++) { 218 225 /* make sure there is space for next entry */ … … 243 250 catalog[0].average[Nave].Xm = NO_MAG; 244 251 catalog[0].average[Nave].Xg = NO_MAG; 245 catalog[0].average[Nave].offset = Nmeas ;252 catalog[0].average[Nave].offset = Nmeas + offset; 246 253 catalog[0].average[Nave].missing = -1; 247 254 catalog[0].average[Nave].code = 0; … … 316 323 } */ 317 324 318 if (REORDER) { 319 catalog[0].measure = reorder_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas); 320 catalog[0].ordered = TRUE; 325 if (NOSORT) { 326 catalog[0].sorted = FALSE; 321 327 } else { 322 catalog[0].ordered = FALSE; 323 } 324 catalog[0].missing = reorder_missing (catalog[0].average, Nave, catalog[0].missing, Nmiss, next_miss); 328 catalog[0].sorted = TRUE; 329 catalog[0].measure = sort_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas); 330 } 331 catalog[0].missing = sort_missing (catalog[0].average, Nave, catalog[0].missing, Nmiss, next_miss); 325 332 /* missing is REQUIRED to be sorted */ 326 333 … … 342 349 gettimeofday (&stop, NULL); 343 350 dtime = DTIME (stop, start); 344 fprintf (stderr, " match time % 8.3f sec for %5d stars, %6d average\n", dtime, Nstars, Nave);351 fprintf (stderr, " match time %9.4f sec for %5d stars, %6d average\n", dtime, Nstars, Nave); 345 352 346 353 return; -
trunk/Ohana/src/addstar/src/gcatalog.c
r5229 r5234 9 9 10 10 /* read catalog header */ 11 mode = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF; 11 if (UPDATE) { 12 mode = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF; 13 } else { 14 mode = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF; 15 } 12 16 if (!load_catalog (catalog, mode, VERBOSE)) { 13 17 fprintf (stderr, "ERROR: failure loading catalog\n"); … … 16 20 17 21 /* should this be moved into save_catalog?? */ 18 status = fits_scan (&catalog[0].header, " ORDERED", "%t", 1, &catalog[0].ordered);19 if (!status) catalog[0]. ordered = TRUE;22 status = fits_scan (&catalog[0].header, "SORTED", "%t", 1, &catalog[0].sorted); 23 if (!status) catalog[0].sorted = TRUE; 20 24 /* XXX EAM - is this a good choice? should the default be 'FALSE'? */ 21 25 -
trunk/Ohana/src/addstar/src/mkcatalog.c
r5229 r5234 111 111 ALLOCATE (catalog[0].secfilt, SecFilt, 1); 112 112 catalog[0].Naverage = catalog[0].Nmeasure = catalog[0].Nmissing = 0; 113 catalog[0].Nave_disk = catalog[0].Nmeas_disk = catalog[0].Nmiss_disk = 0; 114 catalog[0].Nmeas_off = 0; 113 115 catalog[0].Nsecfilt = GetPhotcodeNsecfilt (); 114 116 -
trunk/Ohana/src/addstar/src/wcatalog.c
r5229 r5234 7 7 8 8 /* should this be moved into save_catalog?? */ 9 fits_modify (&catalog[0].header, " ORDERED", "%t", 1, catalog[0].ordered);9 fits_modify (&catalog[0].header, "SORTED", "%t", 1, catalog[0].sorted); 10 10 11 if (!save_catalog (catalog, VERBOSE)) { 12 fprintf (stderr, "ERROR: failure saving catalog\n"); 13 exit (1); 11 if (UPDATE) { 12 if (!update_catalog (catalog, VERBOSE)) { 13 fprintf (stderr, "ERROR: failure updating catalog\n"); 14 exit (1); 15 } 16 } else { 17 if (!save_catalog (catalog, VERBOSE)) { 18 fprintf (stderr, "ERROR: failure saving catalog\n"); 19 exit (1); 20 } 14 21 } 15 22 -
trunk/Ohana/src/libohana/include/dvo.h
r5228 r5234 24 24 25 25 /* catalog values to be loaded */ 26 # define LOAD_AVES 0x01 27 # define LOAD_MEAS 0x02 28 # define LOAD_MISS 0x04 29 # define LOAD_SECF 0x08 26 # define LOAD_AVES 0x01 27 # define LOAD_MEAS 0x02 28 # define LOAD_MISS 0x04 29 # define LOAD_SECF 0x08 30 # define LOAD_MEAS_META 0x10 30 31 31 32 /* invalid mag value */ … … 128 129 Missing *missing; 129 130 SecFilt *secfilt; 130 int Naverage, Nmeasure, Nmissing, Nsecfilt; 131 int Naverage, Nmeasure, Nmissing, Nsecfilt; /* current number of each component */ 132 int Nave_disk, Nmeas_disk, Nmiss_disk; /* number of component on disk */ 133 int Nmeas_off; /* dist seq of first loaded data value */ 134 /* note the different counting for Nsecfilt */ 131 135 132 136 /* pointers to split data files */ … … 139 143 int catmode; /* storage mode (raw, mef, split, mysql) */ 140 144 int catformat; /* storage format (elixir, panstarrs, etc) */ 141 int ordered; /* is measure table average-ordered? */145 int sorted; /* is measure table average-sorted? */ 142 146 143 147 /* pointers for data manipulation */ … … 177 181 int load_catalog (Catalog *catalog, char mode, int VERBOSE); 178 182 int save_catalog (Catalog *catalog, char VERBOSE); 183 int update_catalog (Catalog *catalog, char VERBOSE); 179 184 180 185 int FindMosaicForImage (Image *images, int Nimages, int entry); … … 291 296 int load_catalog_split (Catalog *catalog, char mode, int VERBOSE); 292 297 int save_catalog_split (Catalog *catalog, char VERBOSE); 298 int update_catalog_split (Catalog *catalog, char VERBOSE); 293 299 294 300 /*** DVO image db I/O Functions ***/ -
trunk/Ohana/src/libohana/src/dvo_catalog.c
r5228 r5234 110 110 break; 111 111 case DVO_MODE_SPLIT: 112 update_catalog_split (catalog, VERBOSE); 112 /* new file needs to use save_catalog_split */ 113 if (catalog[0].Nave_disk == 0) { 114 save_catalog_split (catalog, VERBOSE); 115 } else { 116 update_catalog_split (catalog, VERBOSE); 117 } 113 118 break; 114 119 default: -
trunk/Ohana/src/libohana/src/dvo_catalog_split.c
r5228 r5234 65 65 66 66 measure = NULL; 67 68 /* (Full Load) */ 67 69 if (mode & LOAD_MEAS) { 68 70 ALLOCATE (measure, Catalog, 1); … … 104 106 fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeasure); 105 107 } 106 fits_free_header (&header); 107 fits_free_matrix (&matrix); 108 catalog[0].Nmeas_off = 0; 109 fits_free_header (&header); 110 fits_free_matrix (&matrix); 111 } 112 113 /* (Meta Load) */ 114 if (mode & LOAD_MEAS_META) { 115 ALLOCATE (measure, Catalog, 1); 116 117 /* get split filename from main header (paths relative to cpt file) */ 118 if (!fits_scan (&catalog[0].header, "MEASURE", "%s", 1, string)) return (FALSE); 119 ALLOCATE (measure[0].filename, char, strlen(path) + strlen(string) + 2); 120 sprintf (measure[0].filename, "%s/%s", path, string); 121 122 /* lock & open catalog file */ 123 if (lock_catalog (measure, catalog[0].lockmode) != 1) { 124 fprintf (stderr, "cannot access measure file %s\n", measure[0].filename); 125 exit (2); 126 } 127 128 /* read PHU */ 129 if (!fits_load_header (measure[0].f, &measure[0].header)) { 130 if (VERBOSE) fprintf (stderr, "catalog file does not exist: %s\n", measure[0].filename); 131 return (FALSE); 132 } 133 134 /* set up the table size information */ 135 catalog[0].Nmeasure = 0; /* no rows loaded */ 136 catalog[0].Nmeas_off = Nmeasure; /* start of new entries */ 108 137 } 109 138 catalog[0].measure_catalog = measure; … … 203 232 catalog[0].secfilt_catalog = secfilt; 204 233 234 /* save the current number so we can do partial updates */ 235 catalog[0].Nave_disk = Naverage; 236 catalog[0].Nmeas_disk = Nmeasure; 237 catalog[0].Nmiss_disk = Nmissing; 238 205 239 return (TRUE); 206 240 } … … 275 309 measure = catalog[0].measure_catalog; 276 310 311 /* XXX EAM : warn about this condition; add code to handle? */ 312 if (catalog[0].Nmeas_off != 0) { 313 fprintf (stderr, "WARNING: LOAD_MEAS_META mixed with save??\n"); 314 fprintf (stderr, "WARNING: this should not be allowed to happen!\n"); 315 } 316 277 317 /* rewind file pointers and truncate (file is still open) */ 278 318 fseek (measure[0].f, 0, SEEK_SET); … … 394 434 int update_catalog_split (Catalog *catalog, char VERBOSE) { 395 435 396 int Nitems; 436 int i, Nx, Ny, Nlines; 437 int Nitems, Nskip, Nout, Ndisk, Nstart; 397 438 Matrix matrix; 398 439 Header header; 399 440 FTable ftable; 441 VTable vtable; 400 442 Catalog *measure, *missing, *secfilt; 401 443 402 444 ftable.header = &header; 445 vtable.header = &header; 403 446 404 447 if (catalog[0].Naverage == 0) { … … 409 452 /* make sure header is consistent with data */ 410 453 fits_modify (&catalog[0].header, "NSTARS", "%d", 1, catalog[0].Naverage); 411 fits_modify (&catalog[0].header, "NMEAS", "%d", 1, catalog[0].Nmeasure );454 fits_modify (&catalog[0].header, "NMEAS", "%d", 1, catalog[0].Nmeasure + catalog[0].Nmeas_off); 412 455 fits_modify (&catalog[0].header, "NMISS", "%d", 1, catalog[0].Nmissing); 413 456 fits_modify (&catalog[0].header, "NSECFILT", "%d", 1, catalog[0].Nsecfilt); … … 424 467 } 425 468 426 /* in split mode, we can save only part of the data */427 428 469 /*** Average Table ***/ 429 470 430 471 if (catalog[0].average != NULL) { 431 ftruncate (fileno (catalog[0].f), catalog[0].header.size); 432 433 /* this is probably a NOP, do I have to keep it in? */ 434 fits_create_matrix (&catalog[0].header, &matrix); 435 if (!fits_fwrite_matrix (catalog[0].f, &matrix)) { 436 fprintf (stderr, "can't write primary matrix"); 437 return (FALSE); 438 } 439 fits_free_matrix (&matrix); 472 473 /* skip past matrix (already at end of header) */ 474 Nskip = fits_matrix_size (&catalog[0].header); 475 fseek (catalog[0].f, Nskip, SEEK_CUR); 476 477 /* how many lines to write out? */ 478 Nout = catalog[0].Naverage - catalog[0].Nave_disk; 440 479 441 480 /* write out Average table (convert to FITS table format) */ 442 481 AverageToFtable (&ftable, catalog[0].average, catalog[0].Naverage, catalog[0].catformat); 482 /* convert only output rows to vtable */ 483 fits_table_to_vtable (&ftable, &vtable, catalog[0].Nave_disk, Nout); 484 443 485 if (!fits_fwrite_Theader (catalog[0].f, &header)) { 444 486 fprintf (stderr, "can't write table header"); 445 487 return (FALSE); 446 488 } 447 if (!fits_fwrite_table (catalog[0].f, &ftable)) { 448 fprintf (stderr, "can't write table data"); 449 return (FALSE); 450 } 489 if (!fits_fwrite_vtable (catalog[0].f, &vtable)) { 490 fprintf (stderr, "can't write table data"); 491 return (FALSE); 492 } 493 fits_free_vtable (&vtable); 451 494 fits_free_table (&ftable); 452 495 fits_free_header (&header); … … 459 502 measure = catalog[0].measure_catalog; 460 503 461 /* rewind file pointers and truncate (file is still open) */ 462 fseek (measure[0].f, 0, SEEK_SET); 463 ftruncate (fileno (measure[0].f), 0); 464 465 /* write table PHU header */ 466 if (!fits_fwrite_header (measure[0].f, &measure[0].header)) { 467 fprintf (stderr, "can't write primary header"); 468 return (FALSE); 469 } 470 471 /* this is probably a NOP, do I have to keep it in? */ 472 fits_create_matrix (&measure[0].header, &matrix); 473 if (!fits_fwrite_matrix (measure[0].f, &matrix)) { 474 fprintf (stderr, "can't write primary matrix"); 475 return (FALSE); 476 } 477 fits_free_matrix (&matrix); 478 479 /* write out Measure table (convert to FITS table format) */ 480 MeasureToFtable (&ftable, catalog[0].measure, catalog[0].Nmeasure, catalog[0].catformat); 504 /* skip past PHU header and matrix */ 505 Nskip = measure[0].header.size + fits_matrix_size (&measure[0].header); 506 fseek (measure[0].f, Nskip, SEEK_SET); 507 508 Ndisk = catalog[0].Nmeas_disk; 509 Nstart = catalog[0].Nmeas_disk - catalog[0].Nmeas_off; /* where is first new line? */ 510 Nout = catalog[0].Nmeasure - Nstart; /* how many lines to write out? */ 511 Nlines = catalog[0].Nmeasure + catalog[0].Nmeas_off; /* how many lines total in file */ 512 513 /* convert to output format FITS table (only rows for output : 0 - Nout) */ 514 MeasureToFtable (&ftable, &catalog[0].measure[Nstart], Nout, catalog[0].catformat); 515 516 fits_scan (&header, "NAXIS1", "%d", 1, &Nx); 517 fits_scan (&header, "NAXIS2", "%d", 1, &Ny); 518 519 /* convert all output rows to vtable */ 520 ALLOCATE (vtable.row, int, MAX (1, Nout)); 521 ALLOCATE (vtable.buffer, char *, MAX (1, Nout)); 522 for (i = 0; i < Nout; i++) { 523 ALLOCATE (vtable.buffer[i], char, MAX (1, Nx)); 524 memcpy (vtable.buffer[i], &ftable.buffer[i*Nx], Nx); 525 vtable.row[i] = i + Ndisk; 526 } 527 528 /* modify vtable to represent full disk table */ 529 fits_modify (&header, "NAXIS2", "%d", 1, Nlines); 530 header.Naxis[1] = Nlines; 531 532 vtable.size = fits_matrix_size (&header); 533 vtable.Nrow = Nout; 534 vtable.pad = vtable.size - Nx*Ny; 535 481 536 if (!fits_fwrite_Theader (measure[0].f, &header)) { 482 537 fprintf (stderr, "can't write table header"); 483 538 return (FALSE); 484 539 } 485 if (!fits_fwrite_table (measure[0].f, &ftable)) { 486 fprintf (stderr, "can't write table data"); 487 return (FALSE); 488 } 540 if (!fits_fwrite_vtable (measure[0].f, &vtable)) { 541 fprintf (stderr, "can't write table data"); 542 return (FALSE); 543 } 544 fits_free_vtable (&vtable); 489 545 fits_free_table (&ftable); 490 546 fits_free_header (&header); … … 492 548 493 549 /*** Missing Table ***/ 550 /* missing table CANNOT be written unsorted, thus it is always written 551 out in full */ 494 552 495 553 if (catalog[0].missing != NULL) { … … 535 593 secfilt = catalog[0].secfilt_catalog; 536 594 537 /* rewind file pointers and truncate (file is still open) */ 538 fseek (secfilt[0].f, 0, SEEK_SET); 539 ftruncate (fileno (secfilt[0].f), 0); 540 541 /* write table PHU header */ 542 if (!fits_fwrite_header (secfilt[0].f, &secfilt[0].header)) { 543 fprintf (stderr, "can't write primary header"); 544 return (FALSE); 545 } 546 547 /* this is probably a NOP, do I have to keep it in? */ 548 fits_create_matrix (&secfilt[0].header, &matrix); 549 if (!fits_fwrite_matrix (secfilt[0].f, &matrix)) { 550 fprintf (stderr, "can't write primary matrix"); 551 return (FALSE); 552 } 553 fits_free_matrix (&matrix); 554 555 /* write out SecFilt table (convert to FITS table format) */ 595 /* skip past PHU header and matrix */ 596 Nskip = secfilt[0].header.size + fits_matrix_size (&secfilt[0].header); 597 fseek (secfilt[0].f, Nskip, SEEK_SET); 598 599 /* how many lines to write out? */ 600 Nout = catalog[0].Nsecfilt * (catalog[0].Naverage - catalog[0].Nave_disk); 601 Ndisk = catalog[0].Nsecfilt * catalog[0].Nave_disk; 602 603 /* convert to output format FITS table */ 556 604 Nitems = catalog[0].Naverage * catalog[0].Nsecfilt; 557 605 SecFiltToFtable (&ftable, catalog[0].secfilt, Nitems, catalog[0].catformat); 606 /* convert only output rows to vtable */ 607 fits_table_to_vtable (&ftable, &vtable, Ndisk, Nout); 608 558 609 if (!fits_fwrite_Theader (secfilt[0].f, &header)) { 559 610 fprintf (stderr, "can't write table header"); 560 611 return (FALSE); 561 612 } 562 if (!fits_fwrite_table (secfilt[0].f, &ftable)) { 563 fprintf (stderr, "can't write table data"); 564 return (FALSE); 565 } 613 if (!fits_fwrite_vtable (secfilt[0].f, &vtable)) { 614 fprintf (stderr, "can't write table data"); 615 return (FALSE); 616 } 617 fits_free_vtable (&vtable); 566 618 fits_free_table (&ftable); 567 619 fits_free_header (&header); … … 578 630 579 631 /* XXX EAM : this file needs work on the error exit conditions and memory leaks, esp under errors */ 632 633 /* XXX EAM : update is not efficient. MeasureToFtable should only 634 convert the new rows (Nmeas_disk to Nmeasure). the resulting 635 table represents the end rows of the vtable. we need to define 636 the vtable based on the ftable, but with Ny = Nmeasure */ 637
Note:
See TracChangeset
for help on using the changeset viewer.
