1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
|
/* $Id: vmtable.h,v 1.2 2013-03-25 11:43:04 cgarcia Exp $
*
* This file is part of the VIMOS Pipeline
* Copyright (C) 2002-2004 European Southern Observatory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* $Author: cgarcia $
* $Date: 2013-03-25 11:43:04 $
* $Revision: 1.2 $
* $Name: not supported by cvs2svn $
*/
#ifndef VM_TABLE_H
#define VM_TABLE_H
#include <fitsio.h>
#include <pilmacros.h>
#include <vmtypes.h>
PIL_BEGIN_DECLS
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
defines of strings for tables
Description:
The following string are defined for use with VimosTables
Values:
VM_EMPTY_TABLE_STRING string with name of empty table
Updates:
03 Nov 98: Created (TAO)
--------------------------------------------------------------------------------
*/
#define VM_EMPTY_TABLE_STRING "Empty Table"
/* Length of the string containing the name of a VimosDescriptor */
#define VM_DESC_LENGTH 81
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
union VimosDescValue
Description:
VimosDescValue is the union that underlies the VimosDescriptors. Each
VimosDescriptor has a pointer to a VimosDescValue that stores the value of
the VimosDescriptor.
Layout:
int i use value as int
VimosBool b use value as VimosBool
float f use value as float
double d use value as double
char *s use value as *char. Note that if a VimosDescriptor is
destructed using deleteDesctructor, and the type of the
value stored in the VimosDescriptor is VM_STRING, the
memory pointed to by s is freed.
Updates:
03 Nov 98: Created (TAO)
--------------------------------------------------------------------------------
*/
typedef union _VIMOS_DESC_VAL_
{
int i;
VimosBool b;
float f;
double d;
char *s;
int *iar;
float *far;
double *dar;
} VimosDescValue;
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
union VimosColumnValue
Description:
VimosColumnValue is the union that underlies the VimosColumn in the
VimosTables. Each VimosColumn has a pointer to a VimosColumnValue that
stores the array of the column. The destructor
deleteColumnValue(VimosColumnValue *cVal) frees the memory used as the
array in the ColumnValue.
Layout:
void *p generic pointer
int *iArray use as array of ints
float *fArray use as array of floats
double *dArray use as array of doubles
char **sArray use as array of Strings
Updates:
03 Nov 98: Created (TAO)
04 Feb 99: String array added
--------------------------------------------------------------------------------
*/
typedef union _VIMOS_COLUMN_VALUE_
{
void *p;
int *iArray;
float *fArray;
double *dArray;
char *cArray;
char **sArray;
} VimosColumnValue;
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
struct VimosDescriptor
Description:
Name-value-comment triplet to be used to store descriptors from a table
or an image. VimosDescriptor is built as a linked list.
Layout:
VimosVarType descType Type of value stored in the descriptor. Only
VM_INT, VM_BOOL, VM_FLOAT, VM_DOUBLE or
VM_STRING are allowed.
char *descName Name of the descriptor
VimosDescValue *descValue Pointer to the VimosDescValue containing the
value
char *descComment Comment associated to the descriptor
VimosDescriptor *prev Link for linked list
VimosDescriptor *next Link for linked list
Updates:
03 Nov 98: Created (TAO)
07 Jan 00: Added the comment field (MS)
--------------------------------------------------------------------------------
*/
typedef struct _VIMOS_DESCRIPTOR_
{
VimosVarType descType;
char *descName;
int len;
VimosDescValue *descValue;
char *descComment;
struct _VIMOS_DESCRIPTOR_ *prev;
struct _VIMOS_DESCRIPTOR_ *next;
} VimosDescriptor;
typedef struct _VIMOS_COLUMN_
{
VimosVarType colType;
char *colName;
int len;
VimosColumnValue *colValue;
struct _VIMOS_COLUMN_ *prev;
struct _VIMOS_COLUMN_ *next;
} VimosColumn;
typedef struct _VIMOS_TABLE_
{
char name[VM_DESC_LENGTH];
VimosDescriptor *descs;
int numColumns;
VimosColumn *cols;
fitsfile *fptr;
} VimosTable;
/* Constructor of VimosDescValue */
VimosDescValue *newDescValue();
/* Desctructor of VimosDescValue */
void deleteDescValue(VimosDescValue *dValue);
/* Constructor of VimosDescriptor */
VimosDescriptor *newDescriptor();
/* Desctructor of VimosDescriptor
Deletes a single descriptor (does NOT traverse the linked list)
Updates:
11 Nov 98: added handling of VM_STRING for descriptor value (TAO)
*/
void deleteDescriptor(VimosDescriptor *vDesc);
/* Desctructor of VimosDescriptor
Deletes a single descriptors in a linked list
*/
void deleteAllDescriptors(VimosDescriptor *vDesc);
/*
* The next one is an extension of deleteDescriptor (in vimosTable.c).
* Tipically a descriptor belongs to a linked list, and just deleting
* it would leave the list broken: the gap should be filled, and the
* previous descriptor should point directly to the next (and the
* next to the previous). The extracted descriptor is then deleted
* using deleteDescriptor. To simplify the operation, a findDescriptor
* is also called, and vDesc may just point to any point of the list
* coming before the descriptor to be removed, that can therefore be
* specified by name. Returns the number of descs removed.
*/
int removeDescriptor(VimosDescriptor **vDesc, const char *dscName);
/*
* Descriptors containing the given substring are searched in the
* list. When a match is found the descriptor is removed from the
* list. The character "*" (with its usual meaning) must be used at
* the beginning and/or at the end of the substring, if it is not
* used the substring is interpreted as an entire descriptor name.
* Returns the number of descriptors deleted.
*/
int deleteSetOfDescriptors (VimosDescriptor **desc, char *substring);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VimosDescriptor *newStringDescriptor(const char *name, const char *value,
conts char *comment)
Description:
Allocates a new VimosDescriptor of type VM_STRING with name *name
and sets the value to *value and the comment to *comment.
Input:
const char *name
String with the name of the new Descriptor
const char *value
String with the value of the new Descriptor
const char *comment
String with the comment of the new Descriptor
Return Value (success):
Pointer to the new Descriptor
Return Value (error)
NULL
Updates:
18 Nov 98: Created (TAO)
07 Jan 00: Added comment field (MS)
13 Jun 00: Return NULL on error instead of exiting (Maura)
--------------------------------------------------------------------------------
*/
VimosDescriptor *newStringDescriptor(const char *name, const char *value,
const char *comment);
VimosDescriptor *newIntDescriptor(const char *name, int value,
const char *comment);
VimosDescriptor *newFloatDescriptor(const char *name, float value,
const char *comment);
VimosDescriptor *newBoolDescriptor(const char *name, VimosBool value,
const char *comment);
VimosDescriptor *newDoubleDescriptor(const char *name, double value,
const char *comment);
VimosDescriptor *newIntArrayDescriptor(const char *name, int *value,
const char *comment, int len);
VimosDescriptor *newFloatArrayDescriptor(const char *name, float *value,
const char *comment, int len);
VimosDescriptor *newDoubleArrayDescriptor(const char *name, double *value,
const char *comment, int len);
/* Constructor of VimosColumnValue */
VimosColumnValue *newColumnValue();
/* Desctructor of VimosColumnValue */
void deleteColumnValue(VimosColumnValue *vColVal);
/* Constructor of VimosColumn */
VimosColumn *newColumn();
VimosColumn *newIntColumn(int size, const char *name);
VimosColumn *newFloatColumn(int size, const char *name);
VimosColumn *newDoubleColumn(int size, const char *name);
VimosColumn *newCharacterColumn(int size, const char *name);
VimosColumn *newStringColumn(int size, const char *name);
/* Desctructor of VimosColumn */
void deleteColumn(VimosColumn *vCol);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VimosTable *newTable()
Description:
Allocates a new VimosTable. The pointers in the table are set to NULL, the
field numColumns is set to 0, and the name of the table is set to
CM_EMPTY_TABLE_STRING.
Return Value (success):
Pointer to the new table
Return Value (error)
NULL
Updates:
04 Nov 98: Created (TAO)
09 Nov 98: Added field colLength (TAO)
13 Jun 00: Return NULL on error instead of exiting (Maura)
21 Aug 00: Change field colLength to numColumns (CI)
--------------------------------------------------------------------------------
*/
VimosTable *newTable();
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void deleteAllColumns(VimosTable *table)
Description:
Removes all columns from a VimosTable
Return Value:
void
Updates:
09 Nov 98: Created (TAO)
--------------------------------------------------------------------------------
*/
void deleteAllColumns(VimosTable *table);
void deleteTable(VimosTable *table);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VimosDescriptor *copyDescriptor(VimosDescriptor *desc)
Description:
Allocates a new VimosDescriptor and copies the value of the input descriptor
into the new descriptor. The links prev and next of the new copy are set to
NULL.
Return Value (success):
Pointer to newly created copy of input descriptor
Return Value (error):
Null
Updates:
10 Nov 98: Created (TAO)
13 Jun 00: Return NULL on error instead of exiting (Maura)
--------------------------------------------------------------------------------
*/
VimosDescriptor *copyOfDescriptor(VimosDescriptor *desc);
VimosBool copyTableDescriptors(VimosTable *inTable, VimosTable *outTable);
VimosBool copyAllDescriptors(VimosDescriptor *inDesc,
VimosDescriptor **outDesc);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VimosBool addDesc2Table(VimosTable *table, VimosDescriptor *desc)
Description:
Add a descriptor to the linked list of descriptors of the Table
Input:
VimosTable *table
Table to add descriptor to
VimosDescriptor *desc
descriptor to be added
Return Value (succes):
VM_TRUE
Return Value (error):
VM_FALSE
Updates:
18 Nov 98: Created (TAO)
13 Jun 00: Return VimosBool instead of void (Maura)
--------------------------------------------------------------------------------
*/
VimosBool addDesc2Table(VimosDescriptor *desc, VimosTable *table);
VimosBool addDesc2Desc(VimosDescriptor *inDesc, VimosDescriptor **outDesc);
/* Get a pointer to the descriptor with name name */
VimosDescriptor *findDescriptor(VimosDescriptor *vDesc, const char *name);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int getDescriptorLength(VimosDescriptor *desc, const char *name)
Description:
get the length of the data of the Descriptor
Input:
VimosDescriptor *desc
Descriptor to search for descriptor
const char *name
Name of descriptor to search for
Return Value:
void
Updates:
29 Apr 99: Created (TAO)
--------------------------------------------------------------------------------
*/
int getDescriptorLength(VimosDescriptor *desc, const char *name);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VimosBool readStringDescriptor(VimosDescriptor *desc, const char *name,
char *sVal, char *comment)
Description:
Searches *desc for a decriptor with name name and returns the value of that
descriptor, if it exists and is of the right type, and the associated
comment.
Input:
VimosDescriptor *desc
Descriptor to be searched
const char *name
Name of the descriptor to search for
int len (for array versions):
maximum length of array to read
Output:
VimosBool *bVal
int *iVal
float *fVal
double *dVal
char *sVal
Pointer to the variable where the value should be written in
For Array versions:
pointer to existing array of length len
char *comment
Return Value (success):
VM_TRUE
Return Value (error):
VM_FALSE
Updates:
24 Nov 98: Created (TAO)
07 Jan 00: Added comment field (MS)
--------------------------------------------------------------------------------
*/
VimosBool readBoolDescriptor(VimosDescriptor *desc, const char *name,
VimosBool *bVal, char *comment);
VimosBool readIntDescriptor(VimosDescriptor *desc, const char *name,
int *iVal, char *comment);
VimosBool readFloatDescriptor(VimosDescriptor *desc, const char *name,
float *fVal, char *comment);
VimosBool readDoubleDescriptor(VimosDescriptor *desc, const char *name,
double *dVal, char *comment);
VimosBool readStringDescriptor(VimosDescriptor *desc, const char *name,
char *sVal, char *comment);
VimosBool readIntArrayDescriptor(VimosDescriptor *desc, const char *name,
int *iVal, char *comment, int len);
VimosBool readFloatArrayDescriptor(VimosDescriptor *desc, const char *name,
float *fVal, char *comment, int len);
VimosBool readDoubleArrayDescriptor(VimosDescriptor *desc, const char *name,
double *dVal, char *comment, int len);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VimosBool readStringDescFromTable(VimosTable *table, const char *name
char *sVal, char *comment)
Description:
Searches *table for a decriptor with name name and returns the value of that
descriptor, if it exists and is of the right type.
Input:
VimosTable *table
Table to be searched
const char *name
Name of the descriptor to search for
Output:
VimosBool *bVal
int *iVal
float *fVal
double *dVal
char *sVal
Pointer to the variable where the value should be written in
char *comment
Return Value (success):
VM_TRUE
Return Value (error):
VM_FALSE
Updates:
11 Nov 98: Created (TAO)
24 Nov 98: Implemented in terms of read<type>Descriptor (TAO)
07 Jan 00: Added comment field (MS)
--------------------------------------------------------------------------------
*/
VimosBool readBoolDescFromTable(VimosTable *table, const char *name,
VimosBool *bVal, char *comment);
VimosBool readIntDescFromTable(VimosTable *table, const char *name,
int *iVal, char *comment);
VimosBool readFloatDescFromTable(VimosTable *table, const char *name,
float *fVal, char *comment);
VimosBool readDoubleDescFromTable(VimosTable *table, const char *name,
double *dVal, char *comment);
VimosBool readStringDescFromTable(VimosTable *table, const char *name,
char *sVal, char *comment);
VimosBool readIntArrayDescFromTable(VimosTable *table, const char *name,
int *iVal, char *comment, int len);
VimosBool readFloatArrayDescFromTable(VimosTable *table, const char *name,
float *fVal, char *comment, int len);
VimosBool readDoubleArrayDescFromTable(VimosTable *table, const char *name,
double *dVal, char *comment, int len);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VimosBool writeIntDescriptor(VimosDescriptor **desc, const char *name
int value, const char *comment)
VimosBool writeFloatDescriptor(VimosDescriptor **desc, const char *name
float value, const char *comment)
VimosBool writeDoubleDescriptor(VimosDescriptor **desc, const char *name
double value, const char *comment)
VimosBool writeStringDescriptor(VimosDescriptor **desc, const char *name
const char *value, const char *comment)
Description:
Writes a descriptor with name name, value value, and comment comment
to the list pointed to by *desc. If a descriptor of name name already
exists, the value of this one is overwritten, if it does not exist, or it
exists and has the wrong type, a new descriptor is created and appended
to the list.
Input:
VimosDescriptor **desc
Descriptor to be searched
const char *name
Name of the descriptor to search for
Input:
int value
float value
double value
const char *value
Value of descriptor
const char *comment
comment field of the descriptor
Return Value (succes):
VM_TRUE
Return Value (error):
VM_FALSE
Updates:
24 Nov 98: Created (TAO)
07 Jan 00: Added comment field (MS)
13 Jun 00: Return VimosBool instead of void (Maura)
--------------------------------------------------------------------------------
*/
VimosBool writeIntDescriptor(VimosDescriptor **desc, const char *name,
int value, const char *comment);
VimosBool writeFloatDescriptor(VimosDescriptor **desc, const char *name,
float value, const char *comment);
VimosBool writeDoubleDescriptor(VimosDescriptor **desc, const char *name,
double value, const char *comment);
VimosBool writeStringDescriptor(VimosDescriptor **desc, const char *name,
const char *value, const char *comment);
VimosBool copyFromHeaderToHeader(VimosDescriptor *fromDesc, const char *inName,
VimosDescriptor **toDesc, const char *outName);
VimosBool insertDescriptor(VimosDescriptor **desc, const char *name,
VimosDescriptor *newDesc, int before);
VimosBool insertIntDescriptor(VimosDescriptor **desc, const char *name,
int value, const char *comment, const char *refName, int before);
VimosBool insertFloatDescriptor(VimosDescriptor **desc, const char *name,
float value, const char *comment, const char *refName, int before);
VimosBool insertDoubleDescriptor(VimosDescriptor **desc, const char *name,
double value, const char *comment, const char *refName, int before);
VimosBool insertStringDescriptor(VimosDescriptor **desc, const char *name,
const char *value, const char *comment, const char *refName, int before);
/* Get a pointer to the Column with name name
*/
VimosColumn *findColumn(VimosColumn *vCol, const char *name);
/* Get a pointer to the descrpitor with name name in a VimosTable
*/
VimosDescriptor *findDescInTab(VimosTable *table, const char *name);
/* Get a pointer to the column with name name in a VimosTable
*/
VimosColumn *findColInTab(VimosTable *table, const char *name);
VimosBool insertHistoryDescriptor(VimosDescriptor **desc, const char *name,
const char *value, const char *comment);
VimosDescriptor *vimosDscFind(VimosDescriptor *, const char *);
int vimosDscCopy(VimosDescriptor **, VimosDescriptor *, const char *,
const char *);
int vimosDscErase(VimosDescriptor **, const char *);
int colGetSize(VimosColumn *);
int colSetName(VimosColumn *, const char *);
char **colGetStringData(VimosColumn *);
int *colGetIntData(VimosColumn *);
float *colGetFloatData(VimosColumn *);
double *colGetDoubleData(VimosColumn *);
int tblGetSize(VimosTable *table, const char *name);
char **tblGetStringData(VimosTable *, const char *);
int *tblGetIntData(VimosTable *, const char *);
float *tblGetFloatData(VimosTable *, const char *);
double *tblGetDoubleData(VimosTable *, const char *);
int tblSetStringValue(VimosTable *, const char *, unsigned int,
const char *);
int tblSetIntValue(VimosTable *, const char *, unsigned int, int);
int tblSetFloatValue(VimosTable *, const char *, unsigned int, float);
int tblSetDoubleValue(VimosTable *, const char *, unsigned int, double);
VimosColumn *tblCopyColumn(VimosTable *, const char *);
VimosColumn *tblRemoveColumn(VimosTable *, const char *);
int tblAppendColumn(VimosTable *, VimosColumn *);
/* FITS file should be open, and correct extension already selected,
before using this function!!! */
VimosBool readDescsFromFitsTable(VimosDescriptor **desc, fitsfile *tableID);
/* FITS should exist and be open, and correct extension already
selected, before using this function!!! */
VimosBool writeDescsToFitsTable(VimosDescriptor *desc, fitsfile *tableID);
/*
* Create a disk table FITS file from structure VimosTable
*/
VimosBool createFitsTable(char *filename, VimosTable *, const char *tableType);
/*
* Open a Fits Table
*/
VimosTable *openOldFitsTable(const char *tableName, int flag);
/*
* read a Fits Table
*/
VimosBool readFitsTable(VimosTable *, fitsfile *tableID);
VimosBool writeFitsTable(VimosTable *table, fitsfile *fptr);
/*
* Close a Fits table
*/
VimosBool closeFitsTable (VimosTable *table, int flag);
int copyToPrimary(char *fileName, const char *keyName);
PIL_END_DECLS
#endif /* VM_TABLE_H */
|