Changeset 33309
- Timestamp:
- Feb 20, 2012, 6:55:53 AM (14 years ago)
- Location:
- branches/eam_branches/ipp-20111122/Ohana/src
- Files:
-
- 1 added
- 8 edited
-
libfits/include/gfitsio.h (modified) (1 diff)
-
libfits/table/F_get_column.c (modified) (2 diffs)
-
opihi/cmd.data/read_vectors.c (modified) (1 diff)
-
opihi/dvo/mextract.c (modified) (3 diffs)
-
opihi/dvo/region_list.c (modified) (1 diff)
-
opihi/include/dvomath.h (modified) (2 diffs)
-
opihi/lib.shell/Makefile (modified) (1 diff)
-
opihi/lib.shell/VectorIO.c (added)
-
opihi/lib.shell/VectorOps.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/libfits/include/gfitsio.h
r33128 r33309 184 184 int gfits_get_bintable_column PROTO((Header *header, FTable *table, char *label, void **data)); 185 185 int gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval)); 186 int gfits_get_bintable_column_type_by_N PROTO((Header *header, int N, char *type, int *Nval)); 186 187 void *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol)); 187 188 int gfits_get_table_column PROTO((Header *header, FTable *table, char *label, void **data)); -
branches/eam_branches/ipp-20111122/Ohana/src/libfits/table/F_get_column.c
r31371 r33309 126 126 127 127 /***********************/ 128 int gfits_get_bintable_column_type_by_N (Header *header, int N, char *type, int *Nval) { 129 130 int Nbytes; 131 char field[80], format[80]; 132 133 assert (N > 0); 134 135 sprintf (field, "TFORM%d", N); 136 if (!gfits_scan (header, field, "%s", 1, format)) return FALSE; 137 if (!gfits_bintable_format (format, type, Nval, &Nbytes)) return (FALSE); 138 return (TRUE); 139 } 140 141 /***********************/ 128 142 int gfits_get_bintable_column_type (Header *header, char *label, char *type, int *Nval) { 129 143 130 int i, N, Nfields , Nbytes;131 char tlabel[80], field[80] , format[80];144 int i, N, Nfields; 145 char tlabel[80], field[80]; 132 146 133 147 if (label == (char *) NULL) return (FALSE); … … 144 158 N = i - 1; 145 159 146 sprintf (field, "TFORM%d", N); 147 gfits_scan (header, field, "%s", 1, format); 148 149 if (!gfits_bintable_format (format, type, Nval, &Nbytes)) return (FALSE); 160 if (!gfits_get_bintable_column_type_by_N (header, N, type, Nval)) return FALSE; 150 161 return (TRUE); 151 162 } -
branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.data/read_vectors.c
r33115 r33309 297 297 } 298 298 299 // XXX ReadAll needs: deal with Extnum vs Extname, save vectors, etc 300 // ReadAll = FALSE; 301 // if ((N = get_argument (argc, argv, "-all"))) { 302 // remove_argument (N, &argc, argv); 303 // ReadAll = atoi (extname); 304 // if (argc != 1) ESCAPE ("-all option cannot be mixed with selected field"); 305 // } 306 299 307 if (argc < 2) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ..."); 300 308 -
branches/eam_branches/ipp-20111122/Ohana/src/opihi/dvo/mextract.c
r33308 r33309 5 5 # define PARALLEL_SERIAL 0 6 6 # define MAX_PATH_LENGTH 1024 7 8 int HostTableLaunchJobs (HostTable *table, char *basecmd); 9 Vector **MergeVectors (Vector **vec, int *Nvec, Vector **invec, int Ninvec); 7 10 8 11 int mextract (int argc, char **argv) { … … 93 96 94 97 // load fields from file 95 // ReadVectorTables 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 96 118 return TRUE; 97 119 } … … 449 471 } 450 472 473 // take two arrays of vectors and merge equal named vectors. 474 // for ease, require that the order of the names match & number of vectors match 475 Vector **MergeVectors (Vector **vec, int *Nvec, Vector **invec, int Ninvec) { 476 477 int i, j; 478 479 if (vec == NULL) { 480 *Nvec = Ninvec; 481 return invec; 482 } 483 484 myAssert (*Nvec == Ninvec, "programming error (1)"); 485 486 for (i = 0; i < Ninvec; i++) { 487 myAssert (!strcmp(vec[i]->name, invec[i]->name), "programming error (2)"); 488 myAssert (vec[i]->type == invec[i]->type, "programming error (2)"); 489 490 if (vec[i]->type == OPIHI_FLT) { 491 REALLOCATE (vec[i]->elements.Flt, opihi_flt, vec[i]->Nelements + invec[i]->Nelements); 492 for (j = 0; j < invec[i]->Nelements; j++) { 493 vec[i]->elements.Flt[i+j] = vec[i]->elements.Flt[j]; 494 } 495 } else { 496 REALLOCATE (vec[i]->elements.Int, opihi_int, vec[i]->Nelements + invec[i]->Nelements); 497 for (j = 0; j < invec[i]->Nelements; j++) { 498 vec[i]->elements.Int[i+j] = vec[i]->elements.Int[j]; 499 } 500 } 501 vec[i]->Nelements += invec[i]->Nelements; 502 } 503 return vec; 504 } -
branches/eam_branches/ipp-20111122/Ohana/src/opihi/dvo/region_list.c
r31635 r33309 113 113 /* check for Region selection from display */ 114 114 if ((N = get_argument (*argc, argv, "-skyregion"))) { 115 if (N + 5>= *argc) {115 if (N + 4 >= *argc) { 116 116 gprint (GP_ERR, "USAGE: -skyregion (RA) (RA) (DEC) (DEC)\n"); 117 117 FreeSkyRegionSelection (selection); -
branches/eam_branches/ipp-20111122/Ohana/src/opihi/include/dvomath.h
r33308 r33309 111 111 112 112 /* vector handling */ 113 void InitVectors PROTO((void)); 114 void FreeVectors PROTO((void)); 113 115 Vector *InitVector PROTO((void)); 114 void InitVectors PROTO((void));116 void FreeVectorArray PROTO((Vector **vec, int Nvec)); 115 117 int CopyVector PROTO((Vector *out, Vector *in)); 116 118 int ResetVector PROTO((Vector *vec, char type, int Nelements)); … … 127 129 int ListVectors PROTO((void)); 128 130 Vector *SelectVector PROTO((char *name, int mode, int verbose)); 131 int AssignVector PROTO((Vector *vec, char *name, int mode, int verbose)); 132 133 /* vector IO functions */ 129 134 int WriteVectorTableFITS PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, char *format)); 135 Vector **ReadVectorTableFITS PROTO((char *filename, char *extname, int *Nvec)); 130 136 131 137 /* buffer handling */ -
branches/eam_branches/ipp-20111122/Ohana/src/opihi/lib.shell/Makefile
r31635 r33309 24 24 $(SDIR)/VariableOps.$(ARCH).o \ 25 25 $(SDIR)/VectorOps.$(ARCH).o \ 26 $(SDIR)/VectorIO.$(ARCH).o \ 26 27 $(SDIR)/check_stack.$(ARCH).o \ 27 28 $(SDIR)/command.$(ARCH).o \ -
branches/eam_branches/ipp-20111122/Ohana/src/opihi/lib.shell/VectorOps.c
r33308 r33309 15 15 16 16 // this function is NOT thread protected : it is only used in startup and/or shutdown 17 void FreeVectorArray (Vector **vec, int Nvec) { 18 19 int i; 20 21 if (!vec) return; 22 for (i = 0; i < Nvec; i++) { 23 if (!vec[i]) continue; 24 if (vec[i]->elements.Int) { 25 free (vec[i]->elements.Int); 26 } 27 free (vec[i]); 28 } 29 free (vec); 30 } 31 32 // this function is NOT thread protected : it is only used in startup and/or shutdown 17 33 void FreeVectors () { 18 19 int i; 20 21 for (i = 0; i < Nvectors; i++) { 22 if (vectors[i][0].elements.Int) { 23 free (vectors[i][0].elements.Int); 24 } 25 free (vectors[i]); 26 } 27 free (vectors); 34 FreeVectorArray (vectors, Nvectors); 28 35 } 29 36 … … 93 100 } 94 101 102 // Assign the given Vector to the internal array of vectors by name 103 int AssignVector (Vector *vec, char *name, int mode, int verbose) { 104 105 int i; 106 107 if (name == NULL) goto error; 108 if (ISNUM(name[0])) goto error; 109 if (IsBuffer(name)) goto error; 110 111 for (i = 0; (i < Nvectors) && (strcmp(vectors[i][0].name, name)); i++); 112 /* is a new vector */ 113 if (i == Nvectors) { 114 if (mode == OLDVECTOR) goto error; 115 pthread_mutex_lock (&mutex); 116 Nvectors ++; 117 REALLOCATE (vectors, Vector *, Nvectors); 118 vectors[i] = vec; 119 pthread_mutex_unlock (&mutex); 120 return TRUE; 121 } 122 /* is an old vector */ 123 if (mode == NEWVECTOR) goto error; 124 vectors[i] = vec; 125 return TRUE; 126 127 error: 128 if (verbose) gprint (GP_ERR, "invalid vector %s\n", name); 129 return FALSE; 130 } 131 95 132 /* delete by pointer */ 96 133 int DeleteVector (Vector *vec) { … … 287 324 return (TRUE); 288 325 } 289 290 // write a set of vectors to a FITS file291 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *format) {292 293 char *tformat = NULL;294 Header header;295 Matrix matrix;296 Header theader;297 FTable ftable;298 299 int j;300 FILE *f = NULL;301 302 /* open file for outuput */303 if (append) {304 f = fopen (filename, "a");305 } else {306 f = fopen (filename, "w");307 }308 if (f == (FILE *) NULL) {309 gprint (GP_ERR, "can't open file for write\n");310 return (FALSE);311 }312 313 if (!append) {314 gfits_init_header (&header);315 header.extend = TRUE;316 gfits_create_header (&header);317 gfits_create_matrix (&header, &matrix);318 }319 320 gfits_create_table_header (&theader, "BINTABLE", extname);321 322 ALLOCATE (tformat, char, 2*Nvec);323 if (format) {324 // the bintable format string can only define the byte-width of each field. valid output columns are currently:325 // B (char), I (16 bit short), J (32 bit int), E (32 bit float), D (64 bit double).326 // the format string is just the sequence of types, eg: LIIJEED327 // validate the format string328 char *ptr = format;329 for (j = 0; j < Nvec; j++) {330 while (*ptr && OHANA_WHITESPACE (*ptr)) ptr++;331 if (*ptr == 0) {332 gprint (GP_ERR, "error in binary table format %s (insufficient format chars)\n", format);333 goto escape;334 }335 if ((*ptr != 'B') && (*ptr != 'I') && (*ptr != 'J') && (*ptr != 'D') && (*ptr != 'E')) {336 gprint (GP_ERR, "error in binary table format %s: invalid character %c\n", format, *ptr);337 goto escape;338 }339 tformat[2*j + 0] = *ptr;340 tformat[2*j + 1] = 0; // a bit sleazy : use a 2xN string to store N 1-byte strings341 ptr ++;342 }343 while (*ptr && OHANA_WHITESPACE (*ptr)) ptr++;344 if (*ptr) {345 gprint (GP_ERR, "error in binary table format %s (extra characters in format)\n", format);346 goto escape;347 }348 } else {349 for (j = 0; j < Nvec; j++) {350 // if the format is not defined, just use the native byte-widths351 tformat[2*j + 0] = (vec[j][0].type == OPIHI_FLT) ? 'D' : 'J';352 tformat[2*j + 1] = 0;353 }354 }355 356 // define the columns of the table. XXX NOTE: we cannot have duplicate names in357 // output table (because the data goes to the named column below). need to enforce358 // this somehow359 for (j = 0; j < Nvec; j++) {360 gfits_define_bintable_column (&theader, &tformat[2*j], vec[j][0].name, NULL, NULL, 1.0, 0.0);361 }362 free (tformat);363 364 // generate the output array that carries the data365 gfits_create_table (&theader, &ftable);366 367 // add the vectors to the output array368 for (j = 0; j < Nvec; j++) {369 if (vec[j][0].type == OPIHI_FLT) {370 gfits_set_bintable_column_reformat (&theader, &ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements);371 } else {372 gfits_set_bintable_column_reformat (&theader, &ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements);373 }374 }375 376 if (!append) {377 gfits_fwrite_header (f, &header);378 gfits_fwrite_matrix (f, &matrix);379 gfits_free_header (&header);380 gfits_free_matrix (&matrix);381 }382 gfits_fwrite_Theader (f, &theader);383 gfits_fwrite_table (f, &ftable);384 385 gfits_free_header (&theader);386 gfits_free_table (&ftable);387 388 fclose (f);389 fflush (f);390 return (TRUE);391 392 escape:393 if (!append) {394 gfits_free_header (&header);395 gfits_free_matrix (&matrix);396 }397 gfits_free_header (&theader);398 gfits_free_table (&ftable);399 400 if (tformat) free (tformat);401 fclose (f);402 fflush (f);403 return (FALSE);404 }
Note:
See TracChangeset
for help on using the changeset viewer.
