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
00039 #include "omega_utils.h"
00040 #include "omega_fits.h"
00041
00059
00082
00083
00084 extern omega_fits *omega_fits_load(const cpl_frame *inframe, cpl_type type,
00085 int extnum)
00086 {
00087 omega_fits *p;
00088 cpl_image *im;
00089 cpl_frame *fr;
00090 int nf;
00091
00092
00093
00094 if (inframe == NULL)
00095 return(NULL);
00096
00097
00098 fr = cpl_frame_duplicate(inframe);
00099
00100
00101 im = cpl_image_load(cpl_frame_get_filename(inframe),type,0,extnum);
00102 if (im == NULL) {
00103 cpl_msg_error(cpl_func,"Unable to load %s -- %s\n",
00104 cpl_frame_get_filename(inframe),cpl_error_get_message());
00105 return(NULL);
00106 }
00107
00108
00109
00110 p = cpl_malloc(sizeof(omega_fits));
00111
00112
00113
00114 p->frame = fr;
00115 p->image = im;
00116 p->extnum = extnum;
00117 p->phu = NULL;
00118 p->ehu = NULL;
00119 p->fname = cpl_strdup(cpl_frame_get_filename(inframe));
00120 p->status = 0;
00121
00122
00123
00124 (void)omega_fits_get_ehu(p);
00125 if (p->ehu == NULL)
00126 return(NULL);
00127 if (cpl_propertylist_has(p->ehu,"EXTNAME")) {
00128 p->extname = cpl_strdup(cpl_propertylist_get_string(p->ehu,"EXTNAME"));
00129 }
00130 else {
00131 nf = 11 + log10(extnum);
00132 p->extname = cpl_malloc(nf);
00133 (void)snprintf(p->extname,nf,"DET1.CHIP%d",extnum);
00134 }
00135 nf = strlen(p->extname) + strlen(p->fname) + 3;
00136 p->fullname = cpl_malloc(nf);
00137 (void)snprintf(p->fullname,nf,"%s[%s]",p->fname,p->extname);
00138
00139
00140
00141 return(p);
00142 }
00143
00144
00161
00162
00163 extern omega_fits *omega_fits_duplicate(omega_fits *in) {
00164 omega_fits *p;
00165
00166
00167
00168 if (in == NULL)
00169 return(NULL);
00170
00171
00172
00173 p = cpl_malloc(sizeof(omega_fits));
00174
00175
00176
00177 p->frame = cpl_frame_duplicate(in->frame);
00178 p->image = cpl_image_duplicate(in->image);
00179 p->phu = cpl_propertylist_duplicate(in->phu);
00180 p->ehu = cpl_propertylist_duplicate(in->ehu);
00181 p->fname = cpl_strdup(in->fname);
00182 p->extname = cpl_strdup(in->extname);
00183 p->fullname = cpl_strdup(in->fullname);
00184 p->extnum = in->extnum;
00185 p->status = in->status;
00186
00187
00188
00189 return(p);
00190 }
00191
00192
00193
00216
00217
00218 extern omega_fits **omega_fits_load_list(const cpl_frameset *f, cpl_type type,
00219 int exten) {
00220 int i;
00221 omega_fits **p;
00222
00223
00224
00225 if (f == NULL)
00226 return(NULL);
00227
00228
00229
00230 p = cpl_malloc(cpl_frameset_get_size(f)*sizeof(omega_fits *));
00231
00232
00233
00234 for (i = 0; i < cpl_frameset_get_size(f); i++) {
00235 p[i] = omega_fits_load(cpl_frameset_get_frame_const(f,i),type,exten);
00236 if (p[i] == NULL) {
00237 omega_fits_delete_list(p,i-1);
00238 return(NULL);
00239 }
00240 }
00241
00242
00243
00244 return(p);
00245 }
00246
00247
00262
00263
00264 extern void omega_fits_delete(omega_fits *p) {
00265
00266
00267
00268 if (p == NULL)
00269 return;
00270
00271
00272
00273 freeframe(p->frame);
00274 freeimage(p->image);
00275 freeplist(p->phu);
00276 freeplist(p->ehu);
00277 freespace(p->fname);
00278 freespace(p->extname);
00279 freespace(p->fullname);
00280 cpl_free(p);
00281 }
00282
00283
00300
00301
00302 extern void omega_fits_delete_list(omega_fits **p, int n) {
00303 int i;
00304
00305
00306
00307 if (p == NULL)
00308 return;
00309
00310
00311
00312 for (i = 0; i < n; i++)
00313 omega_fits_delete(p[i]);
00314
00315 freespace(p);
00316 }
00317
00318
00336
00337
00338 extern cpl_frame *omega_fits_get_frame(omega_fits *p) {
00339
00340
00341
00342 if (p == NULL)
00343 return(NULL);
00344
00345
00346
00347 return(p->frame);
00348 }
00349
00350
00368
00369
00370 extern cpl_image *omega_fits_get_image(omega_fits *p) {
00371
00372
00373
00374 if (p == NULL)
00375 return(NULL);
00376
00377
00378
00379 return(p->image);
00380 }
00381
00382
00401
00402
00403 extern int omega_fits_get_extnum(omega_fits *p) {
00404
00405
00406
00407 if (p == NULL)
00408 return(-1);
00409
00410
00411
00412 return(p->extnum);
00413 }
00414
00415
00435
00436
00437 extern cpl_propertylist *omega_fits_get_phu(omega_fits *p) {
00438
00439
00440
00441 if (p == NULL)
00442 return(NULL);
00443
00444
00445
00446 if (p->phu == NULL)
00447 p->phu = cpl_propertylist_load(p->fname,0);
00448
00449
00450
00451 return(p->phu);
00452 }
00453
00454
00476
00477
00478 extern cpl_propertylist *omega_fits_get_ehu(omega_fits *p)
00479 {
00480
00481
00482
00483 if (p == NULL){
00484 return(NULL);
00485 }
00486
00487
00488
00489 if (p->ehu == NULL) {
00490 p->ehu = cpl_propertylist_load(p->fname,p->extnum);
00491 }
00492
00493
00494
00495 return(p->ehu);
00496 }
00497
00498
00516
00517
00518 extern char *omega_fits_get_extname(omega_fits *p) {
00519
00520
00521
00522 if (p == NULL)
00523 return(NULL);
00524
00525
00526
00527 return(p->extname);
00528 }
00529
00530
00548
00549
00550 extern char *omega_fits_get_filename(omega_fits *p) {
00551
00552
00553
00554 if (p == NULL)
00555 return(NULL);
00556
00557
00558
00559 return(p->fname);
00560 }
00561
00562
00582
00583
00584 extern char *omega_fits_get_fullname(omega_fits *p) {
00585
00586
00587
00588 if (p == NULL)
00589 return(NULL);
00590
00591
00592
00593 return(p->fullname);
00594 }
00595
00596
00613
00614
00615 extern int omega_fits_get_status(omega_fits *p) {
00616
00617
00618
00619 if (p == NULL)
00620 return(-1);
00621
00622
00623
00624 return(p->status);
00625 }
00626
00627
00628
00650
00651
00652 extern int omega_fits_set_error(omega_fits *p, int status) {
00653
00654
00655
00656 if (p == NULL)
00657 return(0);
00658
00659
00660
00661 if (status == 0)
00662 return(0);
00663
00664
00665
00666 p->status = status;
00667
00668
00669
00670 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00671 cpl_msg_error("","%s",cpl_error_get_message());
00672 cpl_error_reset();
00673 }
00674
00675
00676
00677 if (status == -1)
00678 return(-1);
00679 else
00680 return(0);
00681 }
00682
00683
00706
00707
00708 extern void omega_fits_set_filename(omega_fits *p, char *fname) {
00709
00710
00711
00712 if (p == NULL || fname == NULL)
00713 return;
00714
00715
00716
00717 freespace(p->fname);
00718 p->fname = cpl_strdup(fname);
00719 }
00720
00721
00748
00749
00750 extern omega_fits *omega_fits_wrap(cpl_image *im, omega_fits *model,
00751 cpl_propertylist *phu,
00752 cpl_propertylist *ehu) {
00753 omega_fits *p;
00754
00755
00756
00757 if (im == NULL)
00758 return(NULL);
00759
00760
00761
00762 p = cpl_malloc(sizeof(omega_fits));
00763
00764
00765
00766 p->frame = NULL;
00767 p->image = im;
00768 p->extnum = -1;
00769 if (phu != NULL)
00770 p->phu = cpl_propertylist_duplicate(phu);
00771 else if (model != NULL)
00772 p->phu = cpl_propertylist_duplicate(omega_fits_get_phu(model));
00773 else
00774 p->phu = NULL;
00775 if (ehu != NULL)
00776 p->ehu = cpl_propertylist_duplicate(ehu);
00777 else if (model != NULL)
00778 p->ehu = cpl_propertylist_duplicate(omega_fits_get_ehu(model));
00779 else
00780 p->ehu = NULL;
00781 p->fname = NULL;
00782 p->status = 0;
00783 p->extname = NULL;
00784 p->fullname = NULL;
00785
00786
00787
00788 return(p);
00789 }
00790