Changeset 40400
- Timestamp:
- Apr 19, 2018, 4:00:59 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/avperiodogram.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/avperiodogram.c
r40398 r40400 2 2 # define MIN_VAR 1e-8 3 3 # define NPERIODS 50 4 5 /* basic outline of the code: 6 7 * parse optional arguments 8 * -parallel : launch parallel jobs [below is called for non-parallel or for dvo_client 9 10 * parse optional -where-measure clause 11 * 12 13 */ 4 14 5 15 typedef struct { … … 17 27 int avperiodogram (int argc, char **argv) { 18 28 29 # if (0) 30 19 31 int N, next, Nfields; 20 32 … … 25 37 SkyRegionSelection *selection = NULL; 26 38 39 // **** parse the optional arguments **** 27 40 if ((N = get_argument (argc, argv, "-h"))) goto help; 28 41 if ((N = get_argument (argc, argv, "--help"))) goto help; … … 45 58 PARALLEL = TRUE; 46 59 } 60 61 // parse skyregion options. NOTE: this is stripped off in parallel operation and always 62 // defined for the client via the -skyregion option. The dvo_client parses this 63 // argument in the main program, before it is passed to the command (like mextract) 64 if ((selection = SetRegionSelection (&argc, argv)) == NULL) { 65 print_error(); 66 goto escape; 67 } 68 69 /* load region corresponding to selection above */ 70 if ((skylist = SelectRegions (selection)) == NULL) goto escape; 71 72 // **** launch parallel / remote jobs **** 73 // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results 74 if (PARALLEL && !HOST_ID) { 75 // XXX this is not going to work : the measure args will have been stripped off 76 int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, 0, VERBOSE); 77 78 dbFreeFields (fields, Nfields); 79 dbFreeStack (stack, Nstack); 80 free (stack); 81 FreeSkyRegionSelection (selection); 82 dvo_catalog_free (&catalog); 83 84 return status; 85 } 86 87 // NOTE: optional arguments below are parsed after the possible remote call so they are also passed to the dvo_client 47 88 48 89 if ((N = get_argument (argc, argv, "-min-period"))) { … … 92 133 ALLOCATE (mvalues, dbValue, Nmfields); 93 134 94 // XXX : I've removed -parallel-local : see avextract for an example 135 // use remote tables, but not dvo_client.. 136 int PARALLEL_LOCAL = FALSE; 137 HostTable *table = NULL; 138 if ((N = get_argument (argc, argv, "-parallel-local"))) { 139 remove_argument (N, &argc, argv); 140 PARALLEL_LOCAL = TRUE; 141 142 char *CATDIR = GetCATDIR(); 143 if (!CATDIR) { 144 gprint (GP_ERR, "CATDIR is not set\n"); 145 return FALSE; 146 } 147 SkyTable *sky = GetSkyTable(); 148 if (!sky) { 149 gprint (GP_ERR, "failed to load sky table for database\n"); 150 return FALSE; 151 } 152 table = HostTableLoad (CATDIR, sky->hosts); 153 if (!table) { 154 gprint (GP_ERR, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR); 155 return FALSE; 156 } 157 } 95 158 96 159 Catalog catalog; … … 101 164 int Nsecfilt = GetPhotcodeNsecfilt (); 102 165 103 // parse skyregion options. NOTE: this is stripped off in parallel operation and always104 // defined for the client via the -skyregion option. The dvo_client parses this105 // argument in the main program, before it is passed to the command (like mextract)106 if ((selection = SetRegionSelection (&argc, argv)) == NULL) {107 print_error();108 goto escape;109 }110 111 166 // init locally static variables (time refs) 112 167 dbExtractAveragesInit (); 113 168 114 // command-line is of the form: avperiodogram where (field op value)... 169 // command-line is of the form: avperiodogram (output) where (field op value)... 170 if (argc < 2) goto help; 171 char *output = strcreate (argv[1]); 115 172 116 173 // examine line for 'where' or 'match to'. 'match to' is forbidden 117 int state = dbCmdlineConditions (argc, argv, 1, &next);174 int state = dbCmdlineConditions (argc, argv, 2, &next); 118 175 if (state == DVO_DB_CMDLINE_ERROR) goto escape; 119 176 if (state == DVO_DB_CMDLINE_IS_MATCH) goto escape; // not allowed for avperiodogram … … 140 197 ALLOCATE (values, dbValue, Nfields); 141 198 142 /* load region corresponding to selection above */143 if ((skylist = SelectRegions (selection)) == NULL) goto escape;144 145 // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results146 if (PARALLEL && !HOST_ID) {147 int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, 0, VERBOSE);148 149 dbFreeFields (fields, Nfields);150 dbFreeStack (stack, Nstack);151 free (stack);152 FreeSkyRegionSelection (selection);153 dvo_catalog_free (&catalog);154 155 return status;156 }157 158 199 // grab data from all selected sky regions 159 200 struct sigaction *old_sigaction = SetInterrupt(); … … 180 221 } 181 222 dvo_catalog_unlock (&catalog); 223 224 // we save the results in a single FITS file, one extension per object 225 FILE *foutput = NULL; 226 if (RESULT_FILE) { 227 foutput = fopen (RESULT_FILE, "w"); 228 } else { 229 foutput = fopen (output, "w"); 230 } 231 232 // generate the PHU and write to disk 233 Header header; 234 Matrix matrix; 235 gfits_init_header (&header); 236 gfits_init_matrix (&matrix); 237 header.extend = TRUE; 238 gfits_create_header (&header); 239 gfits_create_matrix (&header, &matrix); 240 gfits_fwrite_header (foutput, &header); 241 gfits_fwrite_matrix (foutput, &matrix); 242 gfits_free_header (&header); 243 gfits_free_matrix (&matrix); 182 244 183 245 // Scan the catalog for objects which match the WHERE clause … … 236 298 237 299 PeriodogramResult *result = periodogram_fm_raw (time, mag, dmag, Npts); 238 // XXX write the periodogram result to a file 300 301 PeriodogramResultSave (result, extname, foutput); 239 302 PeriodogramResultFree (result); 240 303 } 304 305 fclose (foutput); 306 fflush (foutput); 307 241 308 dvo_catalog_free (&catalog); 242 309 } … … 261 328 return (FALSE); 262 329 330 263 331 help: 264 gprint (GP_ERR, "USAGE: avperiodogram where (expression) -where-measure (expression)\n"); 332 333 # endif 334 gprint (GP_ERR, "USAGE: avperiodogram (output) where (expression) -where-measure (expression)\n"); 265 335 gprint (GP_ERR, " the where (expression) is a boolean to limit the objects analysed based on average properties\n"); 266 336 gprint (GP_ERR, " NOTE: the optional -where-measure (expression) MUST come after the average where expression\n"); 267 337 return (FALSE); 338 339 268 340 } 269 341 … … 397 469 return; 398 470 } 471 472 /* 473 474 // write the period and power vectors to an extension in this output file 475 void PeriodogramResultFree (PeriodogramResult *result, char *extname, FILE *foutput) { 476 477 // generate a binary table 478 Header outheader; 479 FTable outtable; 480 gfits_init_header (&outheader); 481 gfits_init_table (&outtable); 482 outtable.header = &outheader; 483 484 // XXX add some metadata to the header to identify the object 485 // extname should be related to the object IDs 486 gfits_create_table_header (&outheader, "BINTABLE", extname); 487 488 gfits_define_bintable_column (&outheader, "D", "PERIOD", NULL, NULL, 1.0, 0.0); 489 gfits_define_bintable_column (&outheader, "D", "POWER", NULL, NULL, 1.0, 0.0); 490 491 gfits_create_table (theader, ftable); 492 493 gfits_set_bintable_column (&outheader, &outtable, "PERIOD", result->period, result->Nperiods); 494 gfits_set_bintable_column (&outheader, &outtable, "POWER", result->power, result->Nperiods); 495 496 // write the actual table data 497 gfits_fwrite_Theader (foutput, &outheader); 498 gfits_fwrite_table (foutput, &outtable); 499 500 gfits_free_header (&outheader); 501 gfits_free_table (&outtable); 502 } 503 504 */
Note:
See TracChangeset
for help on using the changeset viewer.
