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_fits.h"
00041
00055
00078
00079
00080 extern vir_fits *vircam_fits_load(cpl_frame *frame, cpl_type type,
00081 int nexten) {
00082 vir_fits *p;
00083 cpl_image *im;
00084 int nf;
00085 const char *fctid = "vircam_fits_load";
00086
00087
00088
00089 if (frame == NULL)
00090 return(NULL);
00091
00092
00093
00094 im = cpl_image_load(cpl_frame_get_filename(frame),type,0,nexten);
00095 if (im == NULL) {
00096 cpl_msg_error(fctid,"Unable to load %s[%d] -- %s\n",
00097 cpl_frame_get_filename(frame),nexten,
00098 cpl_error_get_message());
00099 cpl_error_reset();
00100 return(NULL);
00101 }
00102
00103
00104
00105 p = cpl_malloc(sizeof(vir_fits));
00106
00107
00108
00109 p->image = im;
00110 p->nexten = nexten;
00111 p->phu = NULL;
00112 p->ehu = NULL;
00113 p->fname = cpl_strdup(cpl_frame_get_filename(frame));
00114 p->status = VIR_OK;
00115
00116
00117
00118 (void)vircam_fits_get_ehu(p);
00119 if (p->ehu == NULL)
00120 return(NULL);
00121 if (cpl_propertylist_has(p->ehu,"EXTNAME")) {
00122 p->extname = cpl_strdup(cpl_propertylist_get_string(p->ehu,"EXTNAME"));
00123 } else {
00124 nf = 11 + (int)log10((double)nexten);
00125 p->extname = cpl_malloc(nf);
00126 (void)snprintf(p->extname,nf,"DET1.CHIP%d",nexten);
00127 }
00128 nf = strlen(p->extname) + strlen(p->fname) + 3;
00129 p->fullname = cpl_malloc(nf);
00130 (void)snprintf(p->fullname,nf,"%s[%s]",p->fname,p->extname);
00131
00132
00133
00134 return(p);
00135 }
00136
00137
00154
00155
00156 extern vir_fits *vircam_fits_duplicate(vir_fits *in) {
00157 vir_fits *p;
00158
00159
00160
00161 if (in == NULL)
00162 return(NULL);
00163
00164
00165
00166 p = cpl_malloc(sizeof(vir_fits));
00167
00168
00169
00170 p->image = cpl_image_duplicate(in->image);
00171 if (in->phu != NULL)
00172 p->phu = cpl_propertylist_duplicate(in->phu);
00173 else
00174 p->phu = NULL;
00175 if (in->ehu != NULL)
00176 p->ehu = cpl_propertylist_duplicate(in->ehu);
00177 else
00178 p->ehu = NULL;
00179 p->fname = cpl_strdup(in->fname);
00180 p->extname = cpl_strdup(in->extname);
00181 p->fullname = cpl_strdup(in->fullname);
00182 p->nexten = in->nexten;
00183 p->status = in->status;
00184
00185
00186
00187 return(p);
00188 }
00189
00190
00191
00214
00215
00216 extern vir_fits **vircam_fits_load_list(cpl_frameset *f, cpl_type type,
00217 int exten) {
00218 int i;
00219 vir_fits **p;
00220
00221
00222
00223 if (f == NULL)
00224 return(NULL);
00225
00226
00227
00228 p = cpl_malloc(cpl_frameset_get_size(f)*sizeof(vir_fits *));
00229
00230
00231
00232 for (i = 0; i < cpl_frameset_get_size(f); i++) {
00233 p[i] = vircam_fits_load(cpl_frameset_get_frame(f,i),type,exten);
00234 if (p[i] == NULL) {
00235 vircam_fits_delete_list(p,i-1);
00236 return(NULL);
00237 }
00238 }
00239
00240
00241
00242 return(p);
00243 }
00244
00245
00260
00261
00262 extern void vircam_fits_delete(vir_fits *p) {
00263
00264
00265
00266 if (p == NULL)
00267 return;
00268
00269
00270
00271 freeimage(p->image);
00272 freepropertylist(p->phu);
00273 freepropertylist(p->ehu);
00274 freespace(p->fname);
00275 freespace(p->extname);
00276 freespace(p->fullname);
00277 cpl_free(p);
00278 }
00279
00280
00297
00298
00299 extern void vircam_fits_delete_list(vir_fits **p, int n) {
00300 int i;
00301
00302
00303
00304 if (p == NULL)
00305 return;
00306
00307
00308
00309 for (i = 0; i < n; i++)
00310 vircam_fits_delete(p[i]);
00311 freespace(p);
00312 }
00313
00314
00332
00333
00334 extern cpl_image *vircam_fits_get_image(vir_fits *p) {
00335
00336
00337
00338 if (p == NULL)
00339 return(NULL);
00340
00341
00342
00343 return(p->image);
00344 }
00345
00346
00365
00366
00367 extern int vircam_fits_get_nexten(vir_fits *p) {
00368
00369
00370
00371 if (p == NULL)
00372 return(-1);
00373
00374
00375
00376 return(p->nexten);
00377 }
00378
00379
00399
00400
00401 extern cpl_propertylist *vircam_fits_get_phu(vir_fits *p) {
00402
00403
00404
00405 if (p == NULL)
00406 return(NULL);
00407
00408
00409
00410 if (p->phu == NULL)
00411 p->phu = cpl_propertylist_load(p->fname,0);
00412
00413
00414
00415 return(p->phu);
00416 }
00417
00418
00440
00441
00442 extern cpl_propertylist *vircam_fits_get_ehu(vir_fits *p) {
00443
00444
00445
00446 if (p == NULL)
00447 return(NULL);
00448
00449
00450
00451 if (p->ehu == NULL)
00452 p->ehu = cpl_propertylist_load(p->fname,p->nexten);
00453
00454
00455
00456 return(p->ehu);
00457 }
00458
00459
00477
00478
00479 extern char *vircam_fits_get_extname(vir_fits *p) {
00480
00481
00482
00483 if (p == NULL)
00484 return(NULL);
00485
00486
00487
00488 return(p->extname);
00489 }
00490
00491
00509
00510
00511 extern char *vircam_fits_get_filename(vir_fits *p) {
00512
00513
00514
00515 if (p == NULL)
00516 return(NULL);
00517
00518
00519
00520 return(p->fname);
00521 }
00522
00523
00543
00544
00545 extern char *vircam_fits_get_fullname(vir_fits *p) {
00546
00547
00548
00549 if (p == NULL)
00550 return(NULL);
00551
00552
00553
00554 return(p->fullname);
00555 }
00556
00557
00574
00575
00576 extern int vircam_fits_get_status(vir_fits *p) {
00577
00578
00579
00580 if (p == NULL)
00581 return(VIR_FATAL);
00582
00583
00584
00585 return(p->status);
00586 }
00587
00588
00589
00611
00612
00613 extern int vircam_fits_set_error(vir_fits *p, int status) {
00614
00615
00616
00617 if (p == NULL)
00618 return(0);
00619
00620
00621
00622 if (status == VIR_OK)
00623 return(0);
00624
00625
00626
00627 p->status = status;
00628
00629
00630
00631 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00632 cpl_msg_error("","%s",cpl_error_get_message());
00633 cpl_error_reset();
00634 }
00635
00636
00637
00638 if (status == VIR_FATAL)
00639 return(1);
00640 else
00641 return(0);
00642 }
00643
00644
00671
00672
00673 extern vir_fits *vircam_fits_wrap(cpl_image *im, vir_fits *model,
00674 cpl_propertylist *phu,
00675 cpl_propertylist *ehu) {
00676 vir_fits *p;
00677
00678
00679
00680 if (im == NULL)
00681 return(NULL);
00682
00683
00684
00685 p = cpl_malloc(sizeof(vir_fits));
00686
00687
00688
00689 p->image = im;
00690 p->nexten = -1;
00691 if (phu != NULL)
00692 p->phu = cpl_propertylist_duplicate(phu);
00693 else if (model != NULL)
00694 p->phu = cpl_propertylist_duplicate(vircam_fits_get_phu(model));
00695 else
00696 p->phu = NULL;
00697 if (ehu != NULL)
00698 p->ehu = cpl_propertylist_duplicate(ehu);
00699 else if (model != NULL)
00700 p->ehu = cpl_propertylist_duplicate(vircam_fits_get_ehu(model));
00701 else
00702 p->ehu = NULL;
00703 p->fname = NULL;
00704 p->status = VIR_OK;
00705 p->extname = NULL;
00706 p->fullname = NULL;
00707
00708
00709
00710 return(p);
00711 }
00712
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778