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,(cpl_size)nexten);
00095 if (im == NULL) {
00096 cpl_msg_error(fctid,"Unable to load %s[%" CPL_SIZE_FORMAT "] -- %s\n",
00097 cpl_frame_get_filename(frame),(cpl_size)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,(cpl_size)(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
00610
00611
00612 extern int vircam_fits_set_error(vir_fits *p, int status) {
00613
00614
00615
00616 if (p == NULL)
00617 return(0);
00618
00619
00620
00621 if (status == VIR_OK)
00622 return(0);
00623
00624
00625
00626 p->status = status;
00627
00628
00629
00630 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00631 cpl_msg_error("","%s",cpl_error_get_message());
00632 cpl_error_reset();
00633 }
00634
00635
00636
00637 if (status == VIR_FATAL)
00638 return(1);
00639 else
00640 return(0);
00641 }
00642
00643
00666
00667
00668 extern void vircam_fits_set_filename(vir_fits *p, char *fname) {
00669
00670
00671
00672 if (p == NULL || fname == NULL)
00673 return;
00674
00675
00676
00677 freespace(p->fname);
00678 p->fname = cpl_strdup(fname);
00679 }
00680
00681
00708
00709
00710 extern vir_fits *vircam_fits_wrap(cpl_image *im, vir_fits *model,
00711 cpl_propertylist *phu,
00712 cpl_propertylist *ehu) {
00713 vir_fits *p;
00714
00715
00716
00717 if (im == NULL)
00718 return(NULL);
00719
00720
00721
00722 p = cpl_malloc(sizeof(vir_fits));
00723
00724
00725
00726 p->image = im;
00727 p->nexten = -1;
00728 if (phu != NULL)
00729 p->phu = cpl_propertylist_duplicate(phu);
00730 else if (model != NULL)
00731 p->phu = cpl_propertylist_duplicate(vircam_fits_get_phu(model));
00732 else
00733 p->phu = NULL;
00734 if (ehu != NULL)
00735 p->ehu = cpl_propertylist_duplicate(ehu);
00736 else if (model != NULL)
00737 p->ehu = cpl_propertylist_duplicate(vircam_fits_get_ehu(model));
00738 else
00739 p->ehu = NULL;
00740 p->fname = NULL;
00741 p->status = VIR_OK;
00742 p->extname = NULL;
00743 p->fullname = NULL;
00744
00745
00746
00747 return(p);
00748 }
00749
00764
00765
00766 extern void vircam_fits_unwrap(vir_fits *p) {
00767
00768
00769
00770 if (p == NULL)
00771 return;
00772
00773
00774
00775 freepropertylist(p->phu);
00776 freepropertylist(p->ehu);
00777 freespace(p->fname);
00778 freespace(p->extname);
00779 freespace(p->fullname);
00780 cpl_free(p);
00781 }
00782
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860