Changeset 6827
- Timestamp:
- Apr 10, 2006, 10:22:42 AM (20 years ago)
- Location:
- branches/rel10_ifa/psModules/src/astrom
- Files:
-
- 2 edited
-
pmFPAfile.c (modified) (11 diffs)
-
pmFPAfile.h (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c
r6821 r6827 7 7 #include "pmFPAview.h" 8 8 #include "pmFPAfile.h" 9 #include "pmFPACopy.h" 9 10 #include "pmFPARead.h" 10 11 #include "pmFPAWrite.h" … … 18 19 19 20 psFree (file->fpa); 21 psFree (file->readout); 20 22 psFree (file->names); 21 23 … … 46 48 47 49 file->phu = NULL; 50 file->readout = NULL; 48 51 file->header = NULL; 49 52 … … 94 97 95 98 pmFPAfile *file = pmFPAfileAlloc (); 99 100 // save the name of this pmFPAfile 101 file->name = psStringCopy (name); 102 96 103 file->filerule = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.RULE")); 97 104 file->filextra = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.XTRA")); … … 213 220 214 221 if (file->mode == PM_FPA_MODE_NONE) { 222 return false; 223 } 224 if (file->mode == PM_FPA_MODE_INTERNAL) { 215 225 return false; 216 226 } … … 350 360 pmFPAviewWriteObjects (view, file); 351 361 psTrace ("pmFPAfile", 5, "wrote object %s (fpa: %p)\n", file->filename, file->fpa); 362 break; 363 364 default: 365 fprintf (stderr, "warning: type mismatch\n"); 366 return false; 367 } 368 return true; 369 } 370 371 // create the data elements (headers, images) appropriate for this view 372 bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view) 373 { 374 if (file->mode != PM_FPA_MODE_WRITE) 375 return false; 376 377 // get the current depth 378 pmFPAdepth depth = pmFPAviewDepth (view); 379 380 // do we need to write this file? 381 if (depth != file->dataDepth) 382 return false; 383 384 // XXX is this a sufficient check to avoid creating elements? 385 if (file->src == NULL) 386 return false; 387 388 switch (file->type) { 389 case PM_FPA_FILE_IMAGE: 390 /* create a PHU for thie file, if it does not exist */ 391 pmFPAfileCopyView (file->src, file->fpa, view); 392 psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->filename, file->fpa); 393 break; 394 395 case PM_FPA_FILE_SX: 396 case PM_FPA_FILE_RAW: 397 case PM_FPA_FILE_OBJ: 398 case PM_FPA_FILE_CMP: 399 case PM_FPA_FILE_CMF: 352 400 break; 353 401 … … 409 457 if (place == PM_FPA_BEFORE) { 410 458 pmFPAfileRead (file, view); 459 pmFPAfileCreate (file, view); 411 460 } else { 412 461 pmFPAfileWrite (file, view); … … 418 467 } 419 468 469 // create a file with the given name, assign it type "INTERNAL", and supply it with an image 470 // of the requested dimensions. (image only, mask and weight are ignored) 471 pmReadout *pmFPAfileCreateInternal (psMetadata *files, char *name, int Nx, int Ny, int type) 472 { 473 pmReadout *readout = pmReadoutAlloc (NULL); 474 readout->image = psImageAlloc (Nx, Ny, type); 475 476 // I want an image from the 477 pmFPAfile *file = pmFPAfileAlloc(); 478 file->mode = PM_FPA_MODE_INTERNAL; 479 480 file->readout = readout; 481 psMetadataAddPtr (files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file); 482 psFree (file); 483 // we free this copy of file, but 'files' still has a copy 484 485 return (readout); 486 } 487 488 bool pmFPAfileDropInternal (psMetadata *files, char *name) 489 { 490 bool status; 491 492 pmFPAfile *file = psMetadataLookupPtr (&status, files, name); 493 if (file == NULL) 494 return false; 495 496 if (file->mode != PM_FPA_MODE_INTERNAL) 497 return false; 498 499 psMetadataRemoveKey (files, name); 500 return true; 501 } 502 420 503 // select the readout from the named pmFPAfile; if the named file does not exist, 421 // create an image of the requested dimensions (save this image and file?) 422 psImage *pmFPAfileReadoutImage (psMetadata *files, const pmFPAview *view, char *name, int Nx, int Ny, int type) 504 pmReadout *pmFPAfileThisReadout (psMetadata *files, const pmFPAview *view, const char *name) 423 505 { 424 506 bool status; 425 psImage *image = NULL; 426 427 // I want an image from the 507 428 508 pmFPAfile *file = psMetadataLookupPtr (&status, files, name); 429 if (file == NULL) { 430 // use Nx or Ny == 0 to avoid creating an image 431 if (Nx*Ny <= 0) { 432 return NULL; 433 } 434 image = psImageAlloc (Nx, Ny, type); 435 return (image); 436 } 437 438 // make an fpa consistent with this view 439 // save the image in the fpa 440 // save the fpa in the file 441 442 // inconsistent result: return NULL 509 if (file == NULL) 510 return NULL; 511 512 // internal files have the readout as a separate element: 513 if (file->mode == PM_FPA_MODE_INTERNAL) { 514 return file->readout; 515 } 516 443 517 pmReadout *readout = pmFPAviewThisReadout (view, file->fpa); 444 if (readout == NULL) { 445 return NULL; 446 } 447 448 // resize the existing readout??? this is wrong... 449 // need to allocate it if it does not exist... 450 image = psImageRecycle (readout->image, Nx, Ny, type); 451 psMemIncrRefCounter (image); 452 return (image); 518 return readout; 453 519 } 454 520 … … 649 715 } 650 716 717 // XXX this this function through, then finish 718 # if 0 651 719 // look for the given name on the argument list. 652 720 // returns the file (a view to the one saved on config->files) … … 734 802 return file; 735 803 } 804 # endif 736 805 737 806 // look for the given name on the argument list. … … 884 953 } 885 954 955 // given an already-opened fits file, write the components corresponding 956 // to the specified view 957 bool pmFPAfileCopyView (pmFPA *out, pmFPA *in, const pmFPAview *view) 958 { 959 // XXX how to we transmit the required binning factor? 960 // pmFPAWrite takes care of all PHUs as needed 961 if (view->chip == -1) { 962 pmFPACopy (out, in); 963 return true; 964 } 965 if (view->chip >= in->chips->n) { 966 return false; 967 } 968 pmChip *inChip = in->chips->data[view->chip]; 969 pmChip *outChip = out->chips->data[view->chip]; 970 971 if (view->cell == -1) { 972 pmChipCopy (outChip, inChip); 973 return true; 974 } 975 if (view->cell >= inChip->cells->n) { 976 return false; 977 } 978 pmCell *inCell = inChip->cells->data[view->cell]; 979 pmCell *outCell = outChip->cells->data[view->cell]; 980 981 if (view->readout == -1) { 982 pmCellCopy (outCell, inCell); 983 return true; 984 } 985 return false; 986 987 // XXX disable readout write for now 988 # if (0) 989 990 if (view->readout >= cell->readouts->n) { 991 return false; 992 } 993 pmReadout *readout = cell->readouts->data[view->readout]; 994 995 if (view->nRows == 0) { 996 pmReadoutWrite (readout, fits, NULL, NULL); 997 } else { 998 pmReadoutWriteSegment (readout, fits, view->nRows, view->iRows, NULL, NULL); 999 } 1000 return true; 1001 # endif 1002 } 1003 1004 // need to distinguish between a "copy structure" and a "copy data" 1005 // need to allow for binning when performing the "copy structure" -
branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h
r6819 r6827 7 7 * @author EAM, IfA 8 8 * 9 * @version $Revision: 1.1.2. 9$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-04- 08 20:13:03$9 * @version $Revision: 1.1.2.10 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-04-10 20:22:42 $ 11 11 * 12 12 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii … … 40 40 PM_FPA_MODE_READ, 41 41 PM_FPA_MODE_WRITE, 42 PM_FPA_MODE_INTERNAL, 42 43 } pmFPAfileMode; 43 44 … … 49 50 typedef struct 50 51 { 51 pmFPAdepth fileDepth; 52 pmFPAdepth dataDepth; 52 pmFPAfileMode mode; // is this file read, written, or only used internally? 53 pmFPAfileType type; // what type of data is read from / written to disk? 54 pmFPAfileState state; // have we opened the file, etc? 53 55 54 p sMetadata *phu;55 p sMetadata *header;56 pmFPAdepth fileDepth; // what depth in the FPA hierarchy represents a unique file? 57 pmFPAdepth dataDepth; // at what depth do we read/write the data segment? 56 58 57 pmFPA *fpa; 58 psFits *fits; 59 psMetadata *names; 59 pmFPA *fpa; // for I/O files, we carry a pointer to the complete fpa 60 psFits *fits; // for I/O files of fits type (IMAGE, CMP, CMF), we carry a file handle 60 61 61 char *filerule; 62 char *filextra; 63 char *extrule; 64 char *extxtra; 62 psMetadata *phu; // pointer (view) to the current phu header 63 psMetadata *header; // pointer (view) to the current hdu header 65 64 66 char *filename; 67 char *extname; 65 pmReadout *readout; // for internal files, we only carry a single readout 68 66 69 pmFPAfileType type; 70 pmFPAfileMode mode; 71 pmFPAfileState state; 67 psMetadata *names; // filenames supplied by the cmdline or detdb are saved here 68 69 char *filerule; // rule for constructing a filename when needed 70 char *filextra; // additional information used to define filenames (context dependent) 71 char *extrule; // rule for constructing an extension name when needed 72 char *extxtra; // additional information used to define extension names (context dependent) 73 74 char *name; // the name of the rule (useful for debugging / tracing) 75 char *filename; // the current name of an active file 76 char *extname; // the current name of an active file extension 77 78 // the following elements are used for WRITE-mode IMAGE-type pmFPAfiles to inform 79 // the creation of a new image based on an existing image 80 pmFPA *src; // if an output FPA, inherit from this FPA 81 int xBin; // desired binning in x direction 82 int yBin; // desired binning in y direction 72 83 } 73 84 pmFPAfile; … … 81 92 // load the pmFPAfile information from the camera configuration data, constructing the needed fpa structure 82 93 // XXX deprecate this function? 83 pmFPAfile *pmFPAfileConstruct (psMetadata *files, psMetadata *format, psMetadata *camera, char *name);94 // pmFPAfile *pmFPAfileConstruct (psMetadata *files, psMetadata *format, psMetadata *camera, char *name); 84 95 85 96 // open the real file corresponding to the given pmFPAfile appropriate to the current view … … 88 99 // read from the real file corresponding to the given pmFPAfile for the current view 89 100 bool pmFPAfileRead (pmFPAfile *file, const pmFPAview *view); 101 102 bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view); 90 103 91 104 // write to the real file corresponding to the given pmFPAfile for the current view … … 100 113 // return an image corresponding to the current readout, from the specified file. if the pmFPAfile does not 101 114 // exist, construct the image using the given size and type (save it in a pmFPAfile??) 102 psImage *pmFPAfileReadoutImage (psMetadata *files, const pmFPAview *view, char *name, int Nx, int Ny, int type); 115 // psImage *pmFPAfileReadoutImage (psMetadata *files, const pmFPAview *view, char *name, int Nx, int Ny, int type); 116 117 // select the readout from the named pmFPAfile; if the named file does not exist, 118 pmReadout *pmFPAfileThisReadout (psMetadata *files, const pmFPAview *view, const char *name); 119 120 // create a file with the given name, assign it type "INTERNAL", and supply it with an image 121 // of the requested dimensions. (image only, mask and weight are ignored) 122 pmReadout *pmFPAfileCreateInternal (psMetadata *files, char *name, int Nx, int Ny, int type); 123 124 // delete the INTERNAL file of the given name (if it exists) 125 bool pmFPAfileDropInternal (psMetadata *files, char *name); 103 126 104 127 // read an image into the current view … … 120 143 char *pmFPAfileNameFromRule (char *rule, pmFPAfile *file, const pmFPAview *view); 121 144 145 bool pmFPAfileCopyView (pmFPA *out, pmFPA *in, const pmFPAview *view); 146 122 147 # endif
Note:
See TracChangeset
for help on using the changeset viewer.
