Changeset 29938 for trunk/Ohana/src/dvomerge
- Timestamp:
- Dec 5, 2010, 10:04:42 PM (16 years ago)
- Location:
- trunk/Ohana/src/dvomerge
- Files:
-
- 12 edited
- 19 copied
-
Makefile (modified) (2 diffs)
-
doc (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/doc )
-
doc/notes.txt (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/doc/notes.txt )
-
include/dvomerge.h (modified) (4 diffs)
-
src/ImageOps.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/ImageOps.c )
-
src/LoadCatalog.c (modified) (1 diff)
-
src/LoadImages.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/LoadImages.c )
-
src/ReadDeleteList.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/ReadDeleteList.c )
-
src/args.c (modified) (2 diffs)
-
src/dvo_image_merge_dbs.c (modified) (1 diff)
-
src/dvoconvert.c (modified) (4 diffs)
-
src/dvomerge.c (modified) (2 diffs)
-
src/dvomergeContinue.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeContinue.c )
-
src/dvomergeContinue_threaded.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeContinue_threaded.c )
-
src/dvomergeCreate.c (modified) (10 diffs)
-
src/dvomergeFromList.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeFromList.c )
-
src/dvomergeImageIDs.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeImageIDs.c )
-
src/dvomergeUpdate.c (modified) (11 diffs)
-
src/dvomergeUpdate_threaded.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c )
-
src/dvorepair.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepair.c )
-
src/dvorepairCPT.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairCPT.c )
-
src/dvorepairDeleteImageList.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairDeleteImageList.c )
-
src/dvorepairFixCPT.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairFixCPT.c )
-
src/dvorepairFixImages.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairFixImages.c )
-
src/dvorepairFixTables.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairFixTables.c )
-
src/dvorepairImageVsMeasure.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairImageVsMeasure.c )
-
src/dvorepairImagesVsMeasures.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairImagesVsMeasures.c )
-
src/dvoverify.c (modified) (1 diff)
-
src/help.c (modified) (6 diffs)
-
src/match_image.c (copied) (copied from branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/match_image.c )
-
src/merge_catalogs_old.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/dvomerge/Makefile
r29001 r29938 22 22 all: dvomerge dvoconvert dvosecfilt 23 23 24 # $(SRC)/dvomergeContinue.$(ARCH).o 25 24 26 DVOMERGE = \ 25 27 $(SRC)/dvomerge.$(ARCH).o \ 26 28 $(SRC)/dvomergeUpdate.$(ARCH).o \ 27 29 $(SRC)/dvomergeCreate.$(ARCH).o \ 30 $(SRC)/dvomergeUpdate_threaded.$(ARCH).o \ 31 $(SRC)/dvomergeFromList.$(ARCH).o \ 32 $(SRC)/dvomergeImageIDs.$(ARCH).o \ 28 33 $(SRC)/dvo_image_merge_dbs.$(ARCH).o \ 29 34 $(SRC)/SetSignals.$(ARCH).o \ … … 70 75 $(BIN)/dvosecfilt.$(ARCH) : $(DVOSECFILT) 71 76 72 INSTALL = dvomerge dvoconvert dvosecfilt 77 DVOREPAIR = \ 78 $(SRC)/dvorepair.$(ARCH).o \ 79 $(SRC)/dvorepairFixCPT.$(ARCH).o \ 80 $(SRC)/dvorepairImagesVsMeasures.$(ARCH).o \ 81 $(SRC)/dvorepairDeleteImageList.$(ARCH).o \ 82 $(SRC)/dvorepairFixImages.$(ARCH).o \ 83 $(SRC)/psps_ids.$(ARCH).o \ 84 $(SRC)/LoadImages.$(ARCH).o \ 85 $(SRC)/ReadDeleteList.$(ARCH).o \ 86 $(SRC)/match_image.$(ARCH).o \ 87 $(SRC)/help.$(ARCH).o \ 88 $(SRC)/ImageOps.$(ARCH).o 89 90 $(DVOREPAIR) : $(INC)/dvomerge.h 91 92 $(BIN)/dvorepair.$(ARCH) : $(DVOREPAIR) 93 94 DVOVERIFY = \ 95 $(SRC)/dvoverify.$(ARCH).o 96 97 $(DVOVERIFY) : $(INC)/dvomerge.h 98 99 $(BIN)/dvoverify.$(ARCH) : $(DVOVERIFY) 100 101 INSTALL = dvomerge dvoconvert dvosecfilt dvorepair dvoverify 73 102 74 103 # dependancy rules for binary code ######################### -
trunk/Ohana/src/dvomerge/include/dvomerge.h
r29001 r29938 17 17 # include <glob.h> 18 18 19 # define myAbort(MSG) { fprintf (stderr, "%s\n", MSG); abort(); } 20 # define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } } 21 19 22 int VERBOSE; 20 23 char CATDIR[256]; … … 25 28 float RADIUS; 26 29 int SKY_DEPTH; 30 int NTHREADS; 27 31 char *ALTERNATE_PHOTCODE_FILE; 28 32 … … 65 69 SkyList *SkyTablePopulatedList_old PROTO((SkyTable *sky, off_t Ns, off_t Ne)); 66 70 67 int LoadCatalog PROTO((Catalog *catalog, SkyRegion *region, char *filename, char *mode ));71 int LoadCatalog PROTO((Catalog *catalog, SkyRegion *region, char *filename, char *mode, int Nsecfilt)); 68 72 69 73 int merge_catalogs_new PROTO((SkyRegion *region, Catalog *output, Catalog *input, int *secflitMap)); … … 86 90 off_t dvo_map_image_ID PROTO((IDmapType *IDmap, off_t oldID)); 87 91 int dvo_update_image_IDs PROTO((IDmapType *IDmap, Catalog *catalog)); 92 93 // dvorepair prototypes 94 Image *LoadImages PROTO((FITS_DB *db, char *filename, off_t *Nimage)); 95 Image *MatchImage PROTO((Image *image, off_t Nimage, unsigned int time, short int source, unsigned int imageID)); 96 off_t match_image PROTO((Image *image, off_t Nimage, unsigned int T, short int S)); 97 98 int SaveImages PROTO((FITS_DB *oldDB, char *filename, Image *imagesOut, off_t Nout)); 99 100 int dvorepairFixCPT PROTO((int argc, char **argv)); 101 int dvorepairImagesVsMeasures PROTO((int argc, char **argv)); 102 int dvorepairDeleteImageList PROTO((int argc, char **argv)); 103 int dvorepairFixImages PROTO((int argc, char **argv)); 104 105 int *ReadDeleteList PROTO((char *filename, int *nindex)); 106 int RepairTableCPT PROTO((char *cptFilenameSrc, char *cptFilenameTgt, char *cpsFilenameSrc, char *cpsFilenameTgt, Measure *measure, off_t Nmeasure, Image *image, off_t Nimage, char catformat)); 107 void dvorepair_help PROTO((int argc, char **argv)); 108 109 off_t getTgtIndex PROTO((e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt)); 110 void SortTgtByTimes PROTO((e_time *S, off_t *I, short *C, off_t N)); 111 int dvo_image_match_dbs PROTO((IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src)); 112 int dvomergeImagesGetMap PROTO((IDmapType *IDmap, char *input, char *output)); 113 int dvomergeFromList PROTO((int argc, char **argv)); 114 int dvomergeUpdate_threaded PROTO((int argc, char **argv)); -
trunk/Ohana/src/dvomerge/src/LoadCatalog.c
r28329 r29938 1 1 # include "dvomerge.h" 2 2 3 int LoadCatalog (Catalog *catalog, SkyRegion *region, char *filename, char *mode ) {3 int LoadCatalog (Catalog *catalog, SkyRegion *region, char *filename, char *mode, int Nsecfilt) { 4 4 5 5 // set the parameters which guide catalog open/load/create 6 6 catalog[0].filename = filename; 7 catalog[0].Nsecfilt = GetPhotcodeNsecfilt ();7 catalog[0].Nsecfilt = Nsecfilt; 8 8 9 9 // always load all of the data (if any exists) -
trunk/Ohana/src/dvomerge/src/args.c
r29001 r29938 15 15 remove_argument (N, argc, argv); 16 16 ALTERNATE_PHOTCODE_FILE = strdup(argv[N]); 17 remove_argument (N, argc, argv); 18 } 19 20 NTHREADS = 0; 21 if ((N = get_argument (*argc, argv, "-threads"))) { 22 remove_argument (N, argc, argv); 23 NTHREADS = MAX(0, atoi(argv[N])); 17 24 remove_argument (N, argc, argv); 18 25 } … … 36 43 } 37 44 38 if ((*argc != 6) && (*argc != 4)) dvomerge_usage();45 if ((*argc < 4) || (*argc > 6)) dvomerge_usage(); 39 46 return TRUE; 40 47 } -
trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c
r29001 r29938 2 2 3 3 void sort_IDmap (IDmapType *IDmap); 4 5 off_t getTgtIndex (e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt) { 6 7 // use bisection to find the starting entry by time 8 9 off_t Nlo, Nhi, N; 10 11 // find the last TGT before start 12 Nlo = 0; Nhi = NimagesTgt; 13 while (Nhi - Nlo > 10) { 14 N = 0.5*(Nlo + Nhi); 15 if (TgtTimes[N] < start) { 16 Nlo = MAX(N, 0); 17 } else { 18 Nhi = MIN(N + 1, NimagesTgt); 19 } 20 } 21 22 // check for the matched mosaic starting from Nlo 23 // we may have to go much beyond Nlo since stop is not sorted 24 // can we use a sorted version of stop to check when we are beyond the valid range?? 25 for (N = Nlo; N < NimagesTgt; N++) { 26 if (TgtTimes[N] < start) continue; 27 if (TgtTimes[N] > stop) return (-1); 28 if (TgtCodes[N] != photcode) continue; 29 return (TgtIndex[N]); 30 } 31 return (-1); 32 } 33 34 // sort two times vectors and an index by first time vector 35 void SortTgtByTimes (e_time *S, off_t *I, short *C, off_t N) { 36 37 # define SWAPFUNC(A,B){ e_time tmp_t; off_t tmp_i; short tmp_c; \ 38 tmp_t = S[A]; S[A] = S[B]; S[B] = tmp_t; \ 39 tmp_i = I[A]; I[A] = I[B]; I[B] = tmp_i; \ 40 tmp_c = C[A]; C[A] = C[B]; C[B] = tmp_c; \ 41 } 42 # define COMPARE(A,B)(S[A] < S[B]) 43 44 OHANA_SORT (N, COMPARE, SWAPFUNC); 45 46 # undef SWAPFUNC 47 # undef COMPARE 48 49 } 50 51 // we have two tables; 'tgt' contains some exposures from 'src' : find them and match a map 52 int dvo_image_match_dbs (IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src) { 53 54 Image *imagesSrc, *imagesTgt; 55 off_t NimagesSrc, NimagesTgt; 56 off_t iSrc, iTgt; 57 off_t *TgtIndex; 58 e_time *TgtTimes; 59 short *TgtCodes; 60 61 imagesSrc = gfits_table_get_Image (&src[0].ftable, &NimagesSrc, &src[0].swapped); 62 if (!imagesSrc) { 63 fprintf (stderr, "ERROR: failed to read images from src\n"); 64 exit (2); 65 } 66 67 imagesTgt = gfits_table_get_Image (&tgt[0].ftable, &NimagesTgt, &tgt[0].swapped); 68 if (!imagesTgt) { 69 fprintf (stderr, "ERROR: failed to read images from tgt\n"); 70 exit (2); 71 } 72 73 ALLOCATE (IDmap->old, off_t, NimagesSrc); 74 ALLOCATE (IDmap->new, off_t, NimagesSrc); 75 IDmap->Nmap = NimagesSrc; 76 77 // match by time and photcode 78 ALLOCATE (TgtIndex, off_t, NimagesTgt); 79 ALLOCATE (TgtTimes, e_time, NimagesTgt); 80 ALLOCATE (TgtCodes, short, NimagesTgt); 81 82 // save the Index, Times, Codes for all TGT images 83 for (iTgt = 0; iTgt < NimagesTgt; iTgt++) { 84 TgtIndex[iTgt] = iTgt; 85 TgtTimes[iTgt] = imagesTgt[iTgt].tzero; 86 TgtCodes[iTgt] = imagesTgt[iTgt].photcode; 87 } 88 89 // sort the index, start, and stop by the start times: 90 SortTgtByTimes (TgtTimes, TgtIndex, TgtCodes, NimagesTgt); 91 92 for (iSrc = 0; iSrc < NimagesSrc; iSrc++) { 93 iTgt = getTgtIndex (imagesSrc[iSrc].tzero, imagesSrc[iSrc].tzero + (int) imagesSrc[iSrc].exptime, imagesSrc[iSrc].photcode, TgtIndex, TgtTimes, TgtCodes, NimagesTgt); 94 if (iTgt < 0) Shutdown ("failure to match images: %s\n", imagesSrc[iSrc].name); 95 IDmap[0].old[iSrc] = imagesSrc[iSrc].imageID; 96 IDmap[0].new[iSrc] = imagesTgt[iTgt].imageID; 97 } 98 99 FREE(TgtIndex); 100 FREE(TgtTimes); 101 FREE(TgtCodes); 102 103 // sort IDmap->old,new on the basis of IDmap->old: 104 sort_IDmap (IDmap); 105 106 return TRUE; 107 } 4 108 5 109 // merge db2 into db1 -
trunk/Ohana/src/dvomerge/src/dvoconvert.c
r29001 r29938 6 6 char filename[256], *input, *output; 7 7 8 int depth ;8 int depth, Nsecfilt; 9 9 off_t i, j, Ns, Ne; 10 10 SkyTable *outsky, *insky; … … 32 32 exit (1); 33 33 } 34 Nsecfilt = GetPhotcodeNsecfilt(); 35 34 36 // save the photcodes in the output catdir 35 37 sprintf (filename, "%s/Photcodes.dat", output); … … 67 69 68 70 // load / create output catalog 69 LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w" );71 LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w", Nsecfilt); 70 72 71 73 // combine only tables at equal or larger depth … … 77 79 78 80 // load input catalog 79 LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r" );81 LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r", Nsecfilt); 80 82 81 83 // skip empty input catalogs -
trunk/Ohana/src/dvomerge/src/dvomerge.c
r28327 r29938 8 8 dvomerge_args (&argc, argv); 9 9 10 // XXX require both inputs to be sorted? 11 12 if (argc == 6) dvomergeCreate (argc, argv); 13 if (argc == 4) dvomergeUpdate (argc, argv); 10 if (argc == 6) { 11 if (!strcasecmp (argv[2], "and")) { 12 dvomergeCreate (argc, argv); 13 } else { 14 dvomergeFromList (argc, argv); 15 } 16 } 17 if ((argc == 4) || (argc == 5)) { 18 if (NTHREADS) { 19 dvomergeUpdate_threaded (argc, argv); 20 } else { 21 dvomergeUpdate (argc, argv); 22 } 23 } 14 24 dvomerge_usage(); 15 25 exit (2); // cannot reach here. … … 18 28 /* we have two possible modes of operation: 19 29 20 Create : dvomerge (in1) and (in2) to (out) -- create a new db from two input dbs 21 Update : dvomerge (in) into (out) -- merge a new db into an existing db 30 Create : dvomerge (in1) and (in2) to (out) -- create a new db from two input dbs 31 Update : dvomerge (in) into (out) -- merge a new db into an existing db 32 Continue : dvomerge (in) into (out) continue -- merge a new db into an existing db 22 33 23 34 */ -
trunk/Ohana/src/dvomerge/src/dvomergeCreate.c
r28855 r29938 15 15 char *input1, *input2, *output; 16 16 IDmapType IDmap1, IDmap2; 17 int NsecfiltInput1, NsecfiltInput2, NsecfiltOutput; 17 18 18 19 if (strcasecmp (argv[2], "and")) dvomerge_usage(); … … 39 40 } 40 41 input1Photcodes = GetPhotcodeTable(); 42 NsecfiltInput1 = GetPhotcodeNsecfilt(); 41 43 42 44 // Read the input2 photcodes … … 48 50 } 49 51 input2Photcodes = GetPhotcodeTable(); 52 NsecfiltInput2 = GetPhotcodeNsecfilt(); 50 53 51 54 if (ALTERNATE_PHOTCODE_FILE) { … … 60 63 } 61 64 outputPhotcodes = GetPhotcodeTable(); 65 NsecfiltOutput = GetPhotcodeNsecfilt(); 62 66 63 67 secfiltMap1 = GetSecFiltMap(outputPhotcodes, input1Photcodes); … … 74 78 outputPhotcodes = input1Photcodes; 75 79 codesFilename = filename1; 80 NsecfiltOutput = NsecfiltInput1; 76 81 // secfitMap1 can remain NULL since input1 defines the set of codes 77 82 } … … 84 89 } 85 90 91 // trigger any dependencies, if any 92 SetPhotcodeTable(NULL); 93 86 94 // save the output photcodes in the output catdir 87 SetPhotcodeTable(outputPhotcodes);95 // SetPhotcodeTable(outputPhotcodes); 88 96 sprintf (filename, "%s/Photcodes.dat", output); 89 97 if (!check_file_access (filename, TRUE, TRUE, VERBOSE)) { … … 121 129 if (VERBOSE) fprintf (stderr, "output: %s\n", outsky[0].regions[i].name); 122 130 123 if (outputPhotcodes) {124 SetPhotcodeTable(outputPhotcodes);125 }131 // if (outputPhotcodes) { 132 // SetPhotcodeTable(outputPhotcodes); 133 // } 126 134 // load / create output catalog 127 LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w" );128 129 if (input1Photcodes) {130 SetPhotcodeTable(input1Photcodes);131 }135 LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w", NsecfiltOutput); 136 137 // if (input1Photcodes) { 138 // SetPhotcodeTable(input1Photcodes); 139 // } 132 140 // combine only tables at equal or larger depth 133 141 … … 138 146 139 147 // load input catalog (1) 140 LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r" );148 LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r", NsecfiltInput1); 141 149 142 150 // skip empty input catalogs … … 153 161 SkyListFree (inlist); 154 162 155 if (input2Photcodes) {156 SetPhotcodeTable(input2Photcodes);157 }163 // if (input2Photcodes) { 164 // SetPhotcodeTable(input2Photcodes); 165 // } 158 166 159 167 // load in all of the tables from input2 for this region … … 163 171 164 172 // load input catalog (2) 165 LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r" );173 LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r", NsecfiltInput2); 166 174 167 175 // skip empty input catalogs -
trunk/Ohana/src/dvomerge/src/dvomergeUpdate.c
r29001 r29938 3 3 int dvomergeUpdate (int argc, char **argv) { 4 4 5 int depth ;5 int depth, CONTINUE; 6 6 off_t i, j, Ns, Ne; 7 7 SkyTable *outsky, *insky; … … 13 13 PhotCodeData *outputPhotcodes; 14 14 int *secfiltMap = NULL; 15 int NsecfiltInput, NsecfiltOutput; 15 16 17 double dtime; 18 struct timeval start, stop; 19 gettimeofday (&start, NULL); 20 21 CONTINUE = FALSE; 16 22 if (strcasecmp (argv[2], "into")) dvomerge_usage(); 23 if (argc == 5) { 24 if (strcasecmp (argv[4], "continue")) dvomerge_usage(); 25 CONTINUE = TRUE; 26 } 17 27 18 28 input = argv[1]; … … 31 41 } 32 42 inputPhotcodes = GetPhotcodeTable(); 43 NsecfiltInput = GetPhotcodeNsecfilt(); 33 44 34 45 // since we are merging the input db into the output db, the output defines the photcode … … 41 52 42 53 outputPhotcodes = GetPhotcodeTable(); 54 NsecfiltOutput = GetPhotcodeNsecfilt(); 43 55 44 56 secfiltMap = GetSecFiltMap(outputPhotcodes, inputPhotcodes); … … 50 62 fprintf(stderr, "%s not found using photcodes from %s/Photcodes.dat\n", filename, input); 51 63 outputPhotcodes = inputPhotcodes; 64 NsecfiltOutput = NsecfiltInput; 65 52 66 if (!check_dir_access (output, VERBOSE)) { 53 67 fprintf (stderr, "error creating output database directory %s\n", output); … … 61 75 } 62 76 63 dvomergeImagesUpdate (&IDmap, input, output); 77 if (CONTINUE) { 78 // need to determine the mapping from the input to the output images 79 dvomergeImagesGetMap (&IDmap, input, output); 80 } else { 81 dvomergeImagesUpdate (&IDmap, input, output); 82 } 64 83 65 84 // load the sky table for the existing database … … 85 104 depth = inlist[0].regions[Ns][0].depth; 86 105 106 SetPhotcodeTable(NULL); 107 87 108 // loop over the populated input regions 88 109 for (i = 0; i < inlist[0].Nregions; i++) { … … 90 111 if (VERBOSE) fprintf (stderr, "input: %s\n", inlist[0].regions[i][0].name); 91 112 92 SetPhotcodeTable(inputPhotcodes);93 113 // load / create output catalog (if catalog does not exist, it will be created) 94 LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r" );114 LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r", NsecfiltInput); 95 115 // skip empty input catalogs 96 116 if (!incatalog.Naves_disk) { … … 111 131 112 132 // load input catalog 113 SetPhotcodeTable(outputPhotcodes); 114 LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w"); 133 LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w", NsecfiltOutput); 115 134 116 135 dvo_update_image_IDs (&IDmap, &incatalog); … … 121 140 // if we receive a signal which would cause us to exit, wait until the full catalog is written 122 141 SetProtect (TRUE); 123 dvo_catalog_save (&outcatalog, VERBOSE); 142 if (!dvo_catalog_save (&outcatalog, VERBOSE)) { 143 fprintf (stderr, "ERROR: failed to save catalog %s\n", outlist[0].filename[j]); 144 exit (1); 145 } 124 146 SetProtect (FALSE); 125 147 … … 143 165 } 144 166 167 gettimeofday (&stop, NULL); 168 dtime = DTIME (stop, start); 169 fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime); 170 145 171 exit (0); 146 172 } 147 148 /*** update the image table ***/149 int dvomergeImagesUpdate (IDmapType *IDmap, char *input, char *output) {150 151 FITS_DB inDB;152 FITS_DB outDB;153 int status;154 155 /*** load input1/Images.dat ***/156 sprintf (ImageCat, "%s/Images.dat", input);157 inDB.mode = dvo_catalog_catmode (CATMODE);158 inDB.format = dvo_catalog_catformat (CATFORMAT);159 status = dvo_image_lock (&inDB, ImageCat, 3600.0, LCK_XCLD); // shorter timeout?160 if (!status) Shutdown ("ERROR: failure to lock image catalog %s", inDB.filename);161 162 // load the image table163 if (inDB.dbstate == LCK_EMPTY) {164 // Shutdown ("can't find input image catalog %s", inDB.filename);165 IDmap->Nmap = 0;166 return TRUE;167 }168 if (!dvo_image_load (&inDB, VERBOSE, TRUE)) {169 Shutdown ("can't read input image catalog %s", inDB.filename);170 }171 172 /*** load output/Images.dat ***/173 sprintf (ImageCat, "%s/Images.dat", output);174 outDB.mode = dvo_catalog_catmode (CATMODE);175 outDB.format = dvo_catalog_catformat (CATFORMAT);176 status = dvo_image_lock (&outDB, ImageCat, 3600.0, LCK_XCLD); // shorter timeout?177 if (!status) Shutdown ("ERROR: failure to lock image catalog %s", outDB.filename);178 179 /* load the image table */180 if (outDB.dbstate == LCK_EMPTY) {181 dvo_image_create (&outDB, GetZeroPoint());182 } else {183 if (!dvo_image_load (&outDB, VERBOSE, TRUE)) {184 Shutdown ("can't read output image catalog %s", outDB.filename);185 }186 }187 188 // convert database table to internal structure & add to output image db189 dvo_image_merge_dbs(IDmap, &outDB, &inDB);190 dvo_image_unlock (&inDB); // unlock input191 192 SetProtect (TRUE);193 dvo_image_save (&outDB, VERBOSE);194 SetProtect (FALSE);195 dvo_image_unlock (&outDB); // unlock output196 197 return TRUE;198 } -
trunk/Ohana/src/dvomerge/src/dvoverify.c
r29001 r29938 8 8 */ 9 9 10 int VerifyTableFile (char *filename); 11 12 # define DEBUG 0 13 10 14 int main (int argc, char **argv) { 11 15 12 char filename[ 256], *input, *output;13 14 int depth;15 off_t i , j, Ns, Ne;16 SkyTable * outsky, *insky;16 char filename[1024]; 17 18 int N, Nbad; 19 off_t i; 20 SkyTable *insky; 17 21 SkyList *inlist; 18 Catalog incatalog, outcatalog; 19 20 SetSignals (); 21 dvoconvert_help (argc, argv); 22 ConfigInit (&argc, argv); 23 dvoconvert_args (&argc, argv); 24 25 if (strcasecmp (argv[2], "to")) dvoconvert_usage(); 26 input = argv[1]; 27 output = argv[3]; 28 29 // load input images, save to output images 30 dvoConvert_copy_images (input, output); 31 32 // copy photcode table 33 { 34 // the first input defines the photcode table & db layout 35 sprintf (filename, "%s/Photcodes.dat", input); 36 if (!LoadPhotcodes (filename, NULL, FALSE)) { 37 fprintf (stderr, "error loading photcode table %s\n", filename); 38 exit (1); 39 } 40 // save the photcodes in the output catdir 41 sprintf (filename, "%s/Photcodes.dat", output); 42 if (!check_file_access (filename, TRUE, TRUE, VERBOSE)) { 43 fprintf (stderr, "error creating output catdir %s\n", output); 44 exit (1); 45 } 46 if (!SavePhotcodesFITS (filename)) { 47 fprintf (stderr, "error saving photcode table %s\n", filename); 48 exit (1); 49 } 50 } 51 52 // copy skytable 53 { 54 // load the sky table for the existing database 55 insky = SkyTableLoadOptimal (input, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE); 56 SkyTableSetFilenames (insky, input, "cpt"); 57 58 // generate an output table populated at the desired depth 59 // XXX force this to match the input? 60 outsky = SkyTableLoadOptimal (output, NULL, GSCFILE, TRUE, SKY_DEPTH, VERBOSE); 61 SkyTableSetFilenames (outsky, output, "cpt"); 62 63 SkyTablePopulatedRange (&Ns, &Ne, insky, 0); 64 depth = insky[0].regions[Ns].depth; 65 // XXX this seems to imply that insky is a uniform depth... 66 } 67 68 // loop over all input catalogs, save to output catalogs 69 // loop over the populatable output regions 70 for (i = 0; i < outsky[0].Nregions; i++) { 71 if (!outsky[0].regions[i].table) continue; 72 if (VERBOSE) fprintf (stderr, "output: %s\n", outsky[0].regions[i].name); 73 74 // load / create output catalog 75 LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w"); 76 77 // combine only tables at equal or larger depth 78 79 // load in all of the tables from input for this region 80 inlist = SkyListByBounds (insky, depth, outsky[0].regions[i].Rmin, outsky[0].regions[i].Rmax, outsky[0].regions[i].Dmin, outsky[0].regions[i].Dmax); 81 for (j = 0; j < inlist[0].Nregions; j++) { 82 if (VERBOSE) fprintf (stderr, "input : %s\n", inlist[0].regions[j][0].name); 83 84 // load input catalog 85 LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r"); 86 87 // skip empty input catalogs 88 if (!incatalog.Naves_disk) { 89 dvo_catalog_unlock (&incatalog); 90 dvo_catalog_free (&incatalog); 91 continue; 92 } 93 merge_catalogs_new (&outsky[0].regions[i], &outcatalog, &incatalog); 94 dvo_catalog_unlock (&incatalog); 95 dvo_catalog_free (&incatalog); 96 } 97 SkyListFree (inlist); 98 99 outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF; 100 dvo_catalog_save (&outcatalog, VERBOSE); 101 dvo_catalog_unlock (&outcatalog); 102 dvo_catalog_free (&outcatalog); 103 } 104 105 // save the output sky table copy 106 sprintf (filename, "%s/SkyTable.fits", output); 107 check_file_access (filename, TRUE, TRUE, VERBOSE); 108 if (!SkyTableSave (outsky, filename)) { 109 fprintf (stderr, "ERROR: failed to save sky table for %s\n", output); 22 SkyRegion UserPatch; 23 // Catalog catalog; 24 25 // restrict to a portion of the sky 26 UserPatch.Rmin = 0; 27 UserPatch.Rmax = 360; 28 UserPatch.Dmin = -90; 29 UserPatch.Dmax = +90; 30 if ((N = get_argument (argc, argv, "-region"))) { 31 remove_argument (N, &argc, argv); 32 UserPatch.Rmin = atof (argv[N]); 33 remove_argument (N, &argc, argv); 34 UserPatch.Rmax = atof (argv[N]); 35 remove_argument (N, &argc, argv); 36 UserPatch.Dmin = atof (argv[N]); 37 remove_argument (N, &argc, argv); 38 UserPatch.Dmax = atof (argv[N]); 39 remove_argument (N, &argc, argv); 40 } 41 42 if (argc != 2) { 43 fprintf (stderr, "USAGE: dvoverify (catdir) [-region Rmin Rmax Dmin Dmax]\n"); 44 fprintf (stderr, " catdir : database of interest\n"); 45 exit (2); 46 } 47 48 char *catdir = argv[1]; 49 50 Nbad = 0; 51 52 // XXX make this step optional 53 if (1) { 54 // check the photcode table 55 sprintf (filename, "%s/Photcodes.dat", catdir); 56 if (!VerifyTableFile (filename)) { 57 Nbad ++; 58 } 59 60 // check the skytable 61 sprintf (filename, "%s/SkyTable.fits", catdir); 62 if (!VerifyTableFile (filename)) { 63 Nbad ++; 64 } 65 66 // check the image table 67 sprintf (filename, "%s/Images.dat", catdir); 68 if (!VerifyTableFile (filename)) { 69 Nbad ++; 70 } 71 } 72 73 // load the sky table for the existing database 74 insky = SkyTableLoadOptimal (catdir, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE); 75 myAssert(insky, "can't read SkyTable"); 76 SkyTableSetFilenames (insky, catdir, "cpt"); 77 inlist = SkyListByPatch (insky, -1, &UserPatch); 78 79 // loop over all catalogs, save to output catalogs 80 for (i = 0; i < inlist[0].Nregions; i++) { 81 if (!inlist[0].regions[i][0].table) continue; 82 83 if (i % 1000 == 0) fprintf (stderr, "."); 84 85 sprintf (filename, "%s/%s.cpt", catdir, inlist[0].regions[i][0].name); 86 if (!VerifyTableFile (filename)) { 87 Nbad ++; 88 } 89 90 sprintf (filename, "%s/%s.cps", catdir, inlist[0].regions[i][0].name); 91 if (!VerifyTableFile (filename)) { 92 Nbad ++; 93 } 94 95 sprintf (filename, "%s/%s.cpm", catdir, inlist[0].regions[i][0].name); 96 if (!VerifyTableFile (filename)) { 97 Nbad ++; 98 } 99 } 100 101 if (Nbad > 0) { 102 fprintf (stderr, "ERROR: %d files are bad\n", Nbad); 110 103 exit (1); 111 104 } 112 105 106 fprintf (stderr, "SUCCESS: no files are bad\n"); 113 107 exit (0); 114 108 } 115 109 116 int dvoConvert_copy_images (char *input, char *output) { 117 118 FITS_DB inDB; 119 FITS_DB outDB; 120 int status; 121 122 Image *images; 123 off_t Nimages; 124 off_t ID; 125 126 /*** load output/Images.dat ***/ 127 sprintf (ImageCat, "%s/Images.dat", output); 128 outDB.mode = dvo_catalog_catmode (CATMODE); 129 outDB.format = dvo_catalog_catformat (CATFORMAT); 130 status = dvo_image_lock (&outDB, ImageCat, 3600.0, LCK_XCLD); // shorter timeout? 131 if (!status) Shutdown ("ERROR: failure to lock image catalog %s", outDB.filename); 132 133 // output image table should not already exist 134 if (outDB.dbstate != LCK_EMPTY) { 135 Shutdown ("ERROR: image table %s already exists", outDB.filename); 136 } 137 dvo_image_create (&outDB, GetZeroPoint()); 138 139 /*** load input/Images.dat ***/ 140 sprintf (ImageCat, "%s/Images.dat", input); 141 // inDB.mode = dvo_catalog_catmode (CATMODE); 142 // inDB.format = dvo_catalog_catformat (CATFORMAT); 143 status = dvo_image_lock (&inDB, ImageCat, 3600.0, LCK_XCLD); // shorter timeout? 144 if (!status) Shutdown ("ERROR: failure to lock image catalog %s", inDB.filename); 145 146 // load the image table 147 if (inDB.dbstate == LCK_EMPTY) { 148 Shutdown ("can't find input image catalog %s", inDB.filename); 149 } 150 if (!dvo_image_load (&inDB, VERBOSE, TRUE)) { 151 Shutdown ("can't read input image catalog %s", inDB.filename); 152 } 153 154 // convert the raw image table to Image type (byteswap if needed) 155 images = gfits_table_get_Image (&inDB.ftable, &Nimages, &inDB.swapped); 156 if (!images) { 157 fprintf (stderr, "ERROR: failed to read images\n"); 158 exit (2); 159 } 160 161 // update additional metadata 162 gfits_scan (&inDB.header, "IMAGEID", OFF_T_FMT, 1, &ID); 163 gfits_modify (&outDB.header, "NIMAGES", OFF_T_FMT, 1, Nimages); 164 gfits_modify (&outDB.header, "IMAGEID", OFF_T_FMT, 1, ID); 165 166 // copy input rows to output table 167 gfits_add_rows (&outDB.ftable, (char *) images, Nimages, sizeof(Image)); 168 169 // write out the image table to disk 170 SetProtect (TRUE); 171 dvo_image_save (&outDB, VERBOSE); 172 SetProtect (FALSE); 173 dvo_image_unlock (&outDB); // unlock output 174 dvo_image_unlock (&inDB); // unlock input1 175 110 // is this file a consistent FITS file? 111 int VerifyTableFile (char *filename) { 112 113 int status; 114 off_t Nbytes; 115 Header header; 116 117 struct stat fileStats; 118 FILE *file; 119 120 // does the file exist? 121 status = stat (filename, &fileStats); 122 if (status) { 123 // some error accessing the file. there is only one acceptable error: file not found 124 switch (errno) { 125 case ENOENT: 126 if (DEBUG) fprintf (stderr, "file does not exist, skipping %s\n", filename); 127 return TRUE; 128 case ENOMEM: 129 fprintf (stderr, "Out of memory: %s\n", filename); 130 return TRUE; 131 case EACCES: 132 fprintf (stderr, "Permission error on %s\n", filename); 133 return FALSE; 134 case EFAULT: 135 fprintf (stderr, "Bad address: %s\n", filename); 136 return FALSE; 137 case ELOOP: 138 fprintf (stderr, "Too many symbolic links encountered while traversing the path: %s\n", filename); 139 return FALSE; 140 case ENAMETOOLONG: 141 fprintf (stderr, "File name too long: %s\n", filename); 142 return FALSE; 143 case ENOTDIR: 144 fprintf (stderr, "A component of the path is not a directory: %s\n", filename); 145 return FALSE; 146 case EOVERFLOW: 147 fprintf (stderr, "file too large for program version: %s\n", filename); 148 return FALSE; 149 default: 150 fprintf (stderr, "unknown error: %s\n", filename); 151 return FALSE; 152 } 153 } 154 155 // does it have any data? 156 if (fileStats.st_size == 0) { 157 fprintf (stderr, "file is empty: %s\n", filename); 158 return FALSE; 159 } 160 161 // can we open it? 162 file = fopen(filename, "r"); 163 if (!file) { 164 fprintf (stderr, "unable to open valid file: %s\n", filename); 165 return FALSE; 166 } 167 168 // scan all extentions 169 Nbytes = 0; 170 if (DEBUG) fprintf (stderr, "sizes: ("OFF_T_FMT" vs "OFF_T_FMT")\n", Nbytes, fileStats.st_size); 171 while (Nbytes < fileStats.st_size) { 172 173 // Check on the PHU 174 if (!gfits_fread_header (file, &header)) { 175 fprintf (stderr, "unable to read PHU header for %s\n", filename); 176 fclose(file); 177 return (FALSE); 178 } 179 180 // move to TBL header 181 Nbytes += header.datasize + gfits_data_size (&header); 182 if (DEBUG) fprintf (stderr, "sizes: ("OFF_T_FMT" vs "OFF_T_FMT")\n", Nbytes, fileStats.st_size); 183 if (Nbytes > fileStats.st_size) { 184 fprintf (stderr, "file is short ("OFF_T_FMT" vs "OFF_T_FMT"): %s\n", Nbytes, fileStats.st_size, filename); 185 gfits_free_header(&header); 186 fclose (file); 187 return FALSE; 188 } 189 gfits_free_header(&header); 190 191 status = fseeko (file, Nbytes, SEEK_SET); 192 if (status) { 193 switch (errno) { 194 case EBADF: 195 fprintf (stderr, "something wrong with file handle: %s\n", filename); 196 fclose (file); 197 return FALSE; 198 case EINVAL: 199 fprintf (stderr, "invalid offset: %s\n", filename); 200 fclose (file); 201 return FALSE; 202 default: 203 fprintf (stderr, "other error in fseeko: %s\n", filename); 204 fclose (file); 205 return FALSE; 206 } 207 } 208 } 209 if (DEBUG) fprintf (stderr, "file is good: %s\n", filename); 210 fclose (file); 176 211 return TRUE; 177 212 } 213 214 // gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow); 215 // gfits_scan(&cpmHeaderTBL, "NAXIS2", "%d", 1, &Nrows); 216 217 -
trunk/Ohana/src/dvomerge/src/help.c
r29001 r29938 4 4 fprintf (stderr, "USAGE: dvomerge (input1) and (input2) to (output)\n"); 5 5 fprintf (stderr, " OR: dvomerge (input) into (output)\n"); 6 fprintf (stderr, " OR: dvomerge (input) into (output) continue\n"); 7 fprintf (stderr, " OR: dvomerge (input) into (output) from (list)\n"); 6 8 fprintf (stderr, " [-region Rmin Rmax Dmin Dmax]\n"); 7 9 exit (2); … … 17 19 void dvosecfilt_usage(void) { 18 20 19 fprintf (stderr, "USAGE: dvosecfilt ( input) -photcodes (photcodes.txt)\n");21 fprintf (stderr, "USAGE: dvosecfilt (catdir) (Nsecfilt)\n"); 20 22 21 23 exit (2); … … 33 35 fprintf (stderr, "USAGE\n"); 34 36 fprintf (stderr, " dvomerge (input1) and (input2) to (output)\n"); 35 fprintf (stderr, " dvomerge (input) into (output)\n\n"); 37 fprintf (stderr, " dvomerge (input) into (output)\n"); 38 fprintf (stderr, " dvomerge (input) into (output) continue\n\n"); 39 fprintf (stderr, " dvomerge (input) into (output) from (list)\n\n"); 36 40 fprintf (stderr, " merge DVO databases\n"); 37 41 fprintf (stderr, " optional flags:\n"); … … 39 43 fprintf (stderr, " -help : this list\n"); 40 44 fprintf (stderr, " -h : this list\n\n"); 45 fprintf (stderr, " -region Rmin Rmax Dmin Dmax : region to merge\n\n"); 41 46 exit (2); 42 47 } … … 75 80 76 81 fprintf (stderr, "USAGE\n"); 77 fprintf (stderr, " dvosecfilt ( input) (Nsecfilt)\n\n");82 fprintf (stderr, " dvosecfilt (catdir) (Nsecfilt)\n\n"); 78 83 79 fprintf (stderr, " change number of secfilt entries in photcode table (updates secfilt tables only)\n"); 84 fprintf (stderr, " change number of secfilt entries in photcode table (updates secfilt tables (cps), NSECFILT in cpt files)\n"); 85 fprintf (stderr, " NOTE: the user must change the photcode table to reflect the change (use photcode-table -export / -import)\n"); 80 86 81 87 fprintf (stderr, " optional flags:\n"); … … 86 92 } 87 93 94 void dvorepair_help (int argc, char **argv) { 95 96 /* check for help request */ 97 if (!argv) goto show_help; 98 if (get_argument (argc, argv, "-help")) goto show_help; 99 if (get_argument (argc, argv, "-h")) goto show_help; 100 if (argc < 2) goto show_help; 101 return; 102 103 show_help: 104 105 fprintf (stderr, "USAGE\n"); 106 fprintf (stderr, " dvorepair -fix-cpt (images) (rootlist) - regenerate cpt & cps files from the cpm files\n"); 107 fprintf (stderr, " dvorepair -images-vs-measures (catdir) (Ntol) - find images with too many missing detections\n"); 108 fprintf (stderr, " dvorepair -delete-image-list (catdir) (deleteList) - delete a set of images based on image IDs (output from -images-vs-measures)\n"); 109 fprintf (stderr, " dvorepair -fix-images (catdir) (deleteList) - delete a set of images based on image IDs (output from -images-vs-measures)\n"); 110 fprintf (stderr, "\n"); 111 112 fprintf (stderr, " optional flags:\n"); 113 fprintf (stderr, " -help : this list\n"); 114 fprintf (stderr, " -h : this list\n\n"); 115 exit (2); 116 } 117 -
trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c
r29181 r29938 28 28 unsigned int objID, catID; 29 29 Coords tcoords; 30 30 31 31 // struct timeval start, stop; 32 32 // gettimeofday (&start, (void *) NULL); … … 240 240 } else { 241 241 for (k = 0; k < NsecfiltIn; k++) { 242 if (secfiltMap[k] < 0) continue; // skip secfilt entries from input that are not in the output 243 242 244 // index for this entry in output's secfilt list 243 245 int outputIndex = n * NsecfiltOut + secfiltMap[k]; … … 254 256 i++; 255 257 } 256 // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars \n", dtime, Nstars, Nave);258 // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars ("OFF_T_FMT" meas)\n", dtime, Nstars, Nave, Nmeas); 257 259 258 260 /** incorporate unmatched image stars, if this star is in field of this catalog **/
Note:
See TracChangeset
for help on using the changeset viewer.
