00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033
00034 #include <stdio.h>
00035 #include <math.h>
00036 #include <string.h>
00037
00038 #include <cpl.h>
00039 #include "vircam_utils.h"
00040 #include "vircam_tfits.h"
00041
00055
00076
00077
00078 extern vir_tfits *vircam_tfits_load(cpl_frame *table, int nexten) {
00079 vir_tfits *p;
00080 cpl_table *tab;
00081 int nf;
00082 const char *fctid = "vircam_tfits_load";
00083
00084
00085
00086 if (table == NULL)
00087 return(NULL);
00088
00089
00090
00091 tab = cpl_table_load(cpl_frame_get_filename(table),nexten,0);
00092 if (tab == NULL) {
00093 cpl_msg_error(fctid,"Unable to load %s -- %s\n",
00094 cpl_frame_get_filename(table),cpl_error_get_message());
00095 cpl_error_reset();
00096 return(NULL);
00097 }
00098
00099
00100
00101 p = cpl_malloc(sizeof(vir_tfits));
00102
00103
00104
00105 p->table = tab;
00106 p->nexten = nexten;
00107 p->phu = NULL;
00108 p->ehu = NULL;
00109 p->fname = cpl_strdup(cpl_frame_get_filename(table));
00110 p->status = VIR_OK;
00111
00112
00113
00114 (void)vircam_tfits_get_ehu(p);
00115 if (cpl_propertylist_has(p->ehu,"EXTNAME")) {
00116 p->extname = cpl_strdup(cpl_propertylist_get_string(p->ehu,"EXTNAME"));
00117 } else {
00118 nf = 11 + (int)log10((double)nexten);
00119 p->extname = cpl_malloc(nf);
00120 (void)snprintf(p->extname,nf,"DET1.CHIP%d",nexten);
00121 }
00122 nf = strlen(p->extname) + strlen(p->fname) + 3;
00123 p->fullname = cpl_malloc(nf);
00124 (void)snprintf(p->fullname,nf,"%s[%s]",p->fname,p->extname);
00125
00126
00127
00128 return(p);
00129 }
00130
00131
00150
00151
00152 extern vir_tfits *vircam_tfits_extract(vir_tfits *in) {
00153 vir_tfits *p;
00154
00155
00156
00157 if (in == NULL)
00158 return(NULL);
00159
00160
00161
00162 p = cpl_malloc(sizeof(vir_tfits));
00163
00164
00165
00166 p->table = cpl_table_extract_selected(vircam_tfits_get_table(in));
00167 p->nexten = vircam_tfits_get_nexten(in);
00168 p->phu = NULL;
00169 p->ehu = NULL;
00170 p->fname = cpl_strdup(vircam_tfits_get_filename(in));
00171
00172
00173
00174 return(p);
00175 }
00176
00177
00198
00199
00200 extern vir_tfits **vircam_tfits_load_list(cpl_frameset *f, int exten) {
00201 int i;
00202 vir_tfits **p;
00203
00204
00205
00206 if (f == NULL)
00207 return(NULL);
00208
00209
00210
00211 p = cpl_malloc(cpl_frameset_get_size(f)*sizeof(vir_tfits *));
00212
00213
00214
00215 for (i = 0; i < cpl_frameset_get_size(f); i++) {
00216 p[i] = vircam_tfits_load(cpl_frameset_get_frame(f,i),exten);
00217 if (p[i] == NULL) {
00218 vircam_tfits_delete_list(p,i-1);
00219 return(NULL);
00220 }
00221 }
00222
00223
00224
00225 return(p);
00226 }
00227
00228
00243
00244
00245 extern void vircam_tfits_delete(vir_tfits *p) {
00246
00247
00248
00249 if (p == NULL)
00250 return;
00251
00252
00253
00254 freetable(p->table);
00255 freepropertylist(p->phu);
00256 freepropertylist(p->ehu);
00257 freespace(p->fname);
00258 freespace(p->extname);
00259 freespace(p->fullname);
00260 cpl_free(p);
00261 }
00262
00263
00280
00281
00282 extern void vircam_tfits_delete_list(vir_tfits **p, int n) {
00283 int i;
00284
00285
00286
00287 if (p == NULL)
00288 return;
00289
00290
00291
00292 for (i = 0; i < n; i++)
00293 vircam_tfits_delete(p[i]);
00294 freespace(p);
00295 }
00296
00297
00315
00316
00317 extern cpl_table *vircam_tfits_get_table(vir_tfits *p) {
00318
00319
00320
00321 if (p == NULL)
00322 return(NULL);
00323
00324
00325
00326 return(p->table);
00327 }
00328
00329
00348
00349
00350 extern int vircam_tfits_get_nexten(vir_tfits *p) {
00351
00352
00353
00354 if (p == NULL)
00355 return(-1);
00356
00357
00358
00359 return(p->nexten);
00360 }
00361
00362
00383
00384
00385 extern cpl_propertylist *vircam_tfits_get_phu(vir_tfits *p) {
00386
00387
00388
00389 if (p == NULL)
00390 return(NULL);
00391
00392
00393
00394 if (p->phu == NULL)
00395 p->phu = cpl_propertylist_load(p->fname,0);
00396
00397
00398
00399 return(p->phu);
00400 }
00401
00402
00424
00425
00426 extern cpl_propertylist *vircam_tfits_get_ehu(vir_tfits *p) {
00427
00428
00429
00430 if (p == NULL)
00431 return(NULL);
00432
00433
00434
00435 if (p->ehu == NULL)
00436 p->ehu = cpl_propertylist_load(p->fname,p->nexten);
00437
00438
00439
00440 return(p->ehu);
00441 }
00442
00443
00461
00462
00463 extern char *vircam_tfits_get_filename(vir_tfits *p) {
00464
00465
00466
00467 if (p == NULL)
00468 return(NULL);
00469
00470
00471
00472 return(p->fname);
00473 }
00474
00475
00495
00496
00497 extern char *vircam_tfits_get_fullname(vir_tfits *p) {
00498
00499
00500
00501 if (p == NULL)
00502 return(NULL);
00503
00504
00505
00506 return(p->fullname);
00507 }
00508
00509
00526
00527
00528 extern int vircam_tfits_get_status(vir_tfits *p) {
00529
00530
00531
00532 if (p == NULL)
00533 return(VIR_FATAL);
00534
00535
00536
00537 return(p->status);
00538 }
00539
00540
00562
00563
00564 extern int vircam_tfits_set_error(vir_tfits *p, int status) {
00565
00566
00567
00568 if (p == NULL)
00569 return(0);
00570
00571
00572
00573 if (status == VIR_OK)
00574 return(0);
00575
00576
00577
00578 p->status = status;
00579
00580
00581
00582 cpl_error_reset();
00583 if (status == VIR_FATAL)
00584 return(1);
00585 else
00586 return(0);
00587 }
00588
00589
00616
00617
00618 extern vir_tfits *vircam_tfits_wrap(cpl_table *tab, vir_tfits *model,
00619 cpl_propertylist *phu,
00620 cpl_propertylist *ehu) {
00621 vir_tfits *p;
00622
00623
00624
00625 if (tab == NULL)
00626 return(NULL);
00627
00628
00629
00630 p = cpl_malloc(sizeof(vir_tfits));
00631
00632
00633
00634 p->table = tab;
00635 p->nexten = -1;
00636 if (phu != NULL)
00637 p->phu = phu;
00638 else if (model != NULL)
00639 p->phu = cpl_propertylist_duplicate(vircam_tfits_get_phu(model));
00640 else
00641 p->phu = NULL;
00642 if (ehu != NULL)
00643 p->ehu = ehu;
00644 else if (model != NULL)
00645 p->ehu = cpl_propertylist_duplicate(vircam_tfits_get_ehu(model));
00646 else
00647 p->ehu = NULL;
00648 p->fname = NULL;
00649 p->status = VIR_OK;
00650 p->extname = NULL;
00651 p->fullname = NULL;
00652
00653
00654
00655 return(p);
00656 }
00657
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703