- Timestamp:
- Feb 20, 2012, 3:07:22 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/opihi/dvo/mextract.c
r33309 r33313 2 2 3 3 # define DEBUG 1 4 # define PARALLEL_MANUAL 14 # define PARALLEL_MANUAL 0 5 5 # define PARALLEL_SERIAL 0 6 6 # define MAX_PATH_LENGTH 1024 … … 8 8 int HostTableLaunchJobs (HostTable *table, char *basecmd); 9 9 Vector **MergeVectors (Vector **vec, int *Nvec, Vector **invec, int Ninvec); 10 int HostTableParallelOps (int argc, char **argv, char *ResultFile); 10 11 11 12 int mextract (int argc, char **argv) { … … 56 57 } 57 58 58 // XXX not yet thought through (where are these set?) 59 // init here so free in 'escape' block does not crash 60 dvo_catalog_init (&catalog, TRUE); 61 62 // parse skyregion options. NOTE: this is stripped off in parallel operation and always 63 // defined for the client via the -skyregion option. The dvo_client parses this 64 // argument in the main program, before it is passed to the command (like mextract) 65 if ((selection = SetRegionSelection (&argc, argv)) == NULL) goto escape; 66 67 // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results 59 68 if (PARALLEL && !HOST_ID) { 60 // load the list of hosts 61 SkyTable *sky = GetSkyTable(); 62 if (!sky) return FALSE; 63 64 char *CATDIR = GetCATDIR (); 65 if (!CATDIR) return FALSE; 66 67 HostTable *table = HostTableLoad (CATDIR, sky->hosts); 68 if (!table) { 69 fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR); 70 return FALSE; 71 } 72 73 // other things I need to append? 74 char *basecmd = paste_args (argc, argv); 75 double Rmin, Rmax, Dmin, Dmax; 76 get_skyregion (&Rmin, &Rmax, &Dmin, &Dmax); 77 78 char tmp; 79 char *command = NULL; 80 int length = snprintf (&tmp, 0, "%s -D CATDIR %s -skyregion %f %f %f %f", basecmd, CATDIR, Rmin, Rmax, Dmin, Dmax); 81 82 ALLOCATE (command, char, length); 83 snprintf (command, length, "%s -D CATDIR %s -skyregion %f %f %f %f", basecmd, CATDIR, Rmin, Rmax, Dmin, Dmax); 84 85 // launch this command remotely 86 HostTableLaunchJobs (table, command); 87 free (command); 88 89 if (PARALLEL_MANUAL) { 90 fprintf (stderr, "run the relphot_client commands above. when these are done, hit return\n"); 91 getchar(); 92 } 93 if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) { 94 HostTableWaitJobs (table, __FILE__, __LINE__); 95 } 96 97 // load fields from file 98 int Nvec = 0; 99 Vector **vec = NULL; 100 for (i = 0; i < table->Nhosts; i++) { 101 char resultFile[MAX_PATH_LENGTH]; 102 snprintf (resultFile, MAX_PATH_LENGTH, "%s/dvo.results.fits", table->hosts[i].pathname); 103 104 int Ninvec = 0; 105 Vector **invec = ReadVectorTableFITS (resultFile, "MEXTRACT", &Ninvec); 106 107 vec = MergeVectors (vec, &Nvec, invec, Ninvec); 108 if (vec != invec) { 109 FreeVectorArray (invec, Ninvec); 110 } 111 } 112 113 for (i = 0; i < Nvec; i++) { 114 AssignVector (vec[i], vec[i]->name, ANYVECTOR, TRUE); 115 } 116 free (vec); 117 118 return TRUE; 119 } 120 121 dvo_catalog_init (&catalog, TRUE); 69 // not all parallel ops need to set the region selection... 70 if (!SetSkyRegions (selection)) goto escape; 71 72 int status = HostTableParallelOps (argc, argv, ResultFile); 73 return status; 74 } 122 75 123 76 /* load photcode information */ … … 127 80 // init locally static variables (time refs) 128 81 dbExtractMeasuresInit(); 129 130 // parse skyregion options131 if ((selection = SetRegionSelection (&argc, argv)) == NULL) goto escape;132 82 133 83 // command-line is of the form: avextract field,field, field [where (field op value)...] … … 174 124 for (i = 0; !loadImages && (i < Nfields); i++) { 175 125 if (!MEASURE_HAS_XCCD) { 176 // I'm keeping this code because it gives a way of hand ing dvo dbs that don't have126 // I'm keeping this code because it gives a way of handling dvo dbs that don't have 177 127 // measure.xccd if we need it 178 128 if (fields[i].ID == MEAS_XCCD) loadImages = TRUE; … … 279 229 280 230 for (n = 0; n < Nreturn; n++) { 281 ResetVector (vec[n], fields[n].type, MAX(0,Npts)); 282 } 283 231 ResetVector (vec[n], fields[n].type, Npts); 232 } 233 234 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere) 284 235 if (ResultFile) { 285 // write vectors to a table 286 // char *resultFile? 287 int status = WriteVectorTableFITS (ResultFile, "MEXTRACT", vec, Nreturn, FALSE, NULL); 236 int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nreturn, FALSE, NULL); 288 237 if (!status) goto escape; 289 238 } … … 443 392 444 393 char command[1024]; 445 snprintf (command, 1024, " %s -result %s -hostID %d -hostdir %s", basecmd, resultFile, table->hosts[i].hostID, table->hosts[i].pathname);446 447 fprintf (stderr, "command: %s\n", command);394 snprintf (command, 1024, "dvo_client %s -result %s -hostID %d -hostdir %s", basecmd, resultFile, table->hosts[i].hostID, table->hosts[i].pathname); 395 396 if (DEBUG || PARALLEL_MANUAL) fprintf (stderr, "command: %s\n", command); 448 397 449 398 if (PARALLEL_MANUAL) { … … 488 437 myAssert (vec[i]->type == invec[i]->type, "programming error (2)"); 489 438 439 int N = vec[i]->Nelements; 490 440 if (vec[i]->type == OPIHI_FLT) { 491 441 REALLOCATE (vec[i]->elements.Flt, opihi_flt, vec[i]->Nelements + invec[i]->Nelements); 492 442 for (j = 0; j < invec[i]->Nelements; j++) { 493 vec[i]->elements.Flt[ i+j] =vec[i]->elements.Flt[j];443 vec[i]->elements.Flt[N+j] = invec[i]->elements.Flt[j]; 494 444 } 495 445 } else { 496 446 REALLOCATE (vec[i]->elements.Int, opihi_int, vec[i]->Nelements + invec[i]->Nelements); 497 447 for (j = 0; j < invec[i]->Nelements; j++) { 498 vec[i]->elements.Int[ i+j] =vec[i]->elements.Int[j];448 vec[i]->elements.Int[N+j] = invec[i]->elements.Int[j]; 499 449 } 500 450 } … … 503 453 return vec; 504 454 } 455 456 int HostTableParallelOps (int argc, char **argv, char *ResultFile) { 457 458 int i; 459 460 // load the list of hosts 461 SkyTable *sky = GetSkyTable(); 462 if (!sky) return FALSE; 463 464 char *tmppath = GetCATDIR (); 465 if (!tmppath) return FALSE; 466 467 char *CATDIR = abspath (tmppath, MAX_PATH_LENGTH); 468 if (!CATDIR) return FALSE; 469 470 HostTable *table = HostTableLoad (CATDIR, sky->hosts); 471 if (!table) { 472 fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR); 473 return FALSE; 474 } 475 476 // other things I need to append? 477 char *basecmd = paste_args (argc, argv); 478 479 // determine the sky region 480 double Rmin, Rmax, Dmin, Dmax; 481 get_skyregion (&Rmin, &Rmax, &Dmin, &Dmax); 482 483 // determine time reference and format 484 char *TimeRef = get_variable ("TIMEREF"); 485 if (!TimeRef) return FALSE; 486 487 char *TimeFormat = get_variable ("TIMEFORMAT"); 488 if (!TimeFormat) return FALSE; 489 490 char tmp; 491 char *command = NULL; 492 int length = snprintf (&tmp, 0, "%s -D CATDIR %s -time %s %s -skyregion %f %f %f %f", basecmd, CATDIR, TimeRef, TimeFormat, Rmin, Rmax, Dmin, Dmax); 493 494 ALLOCATE (command, char, length); 495 snprintf (command, length, "%s -D CATDIR %s -time %s %s -skyregion %f %f %f %f", basecmd, CATDIR, TimeRef, TimeFormat, Rmin, Rmax, Dmin, Dmax); 496 497 // launch this command remotely 498 HostTableLaunchJobs (table, command); 499 free (command); 500 501 if (PARALLEL_MANUAL) { 502 fprintf (stderr, "run the relphot_client commands above. when these are done, hit return\n"); 503 getchar(); 504 } 505 if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) { 506 HostTableWaitJobs (table, __FILE__, __LINE__); 507 } 508 509 // load fields from file 510 int Nvec = 0; 511 Vector **vec = NULL; 512 for (i = 0; i < table->Nhosts; i++) { 513 char resultFile[MAX_PATH_LENGTH]; 514 snprintf (resultFile, MAX_PATH_LENGTH, "%s/dvo.results.fits", table->hosts[i].pathname); 515 516 int Ninvec = 0; 517 Vector **invec = ReadVectorTableFITS (resultFile, "RESULT", &Ninvec); 518 519 vec = MergeVectors (vec, &Nvec, invec, Ninvec); 520 if (vec != invec) { 521 FreeVectorArray (invec, Ninvec); 522 } 523 } 524 525 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere) 526 if (ResultFile) { 527 int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, NULL); 528 if (!status) return FALSE; 529 } 530 531 for (i = 0; i < Nvec; i++) { 532 AssignVector (vec[i], vec[i]->name, ANYVECTOR, TRUE); 533 } 534 free (vec); 535 536 return TRUE; 537 }
Note:
See TracChangeset
for help on using the changeset viewer.
