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 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include <string.h>
00037 #include <math.h>
00038 #include "omega_utils.h"
00039 #include "omega_dfs.h"
00040 #include "omega_pfits.h"
00041
00042 #define MAXNAMESZ 4096
00043
00058
00066
00067 const char * omega_get_license(void)
00068 {
00069 const char * omega_license =
00070 "This file is part of the OMEGA Instrument Pipeline\n"
00071 "Copyright (C) 2002,2003 European Southern Observatory\n"
00072 "\n"
00073 "This program is free software; you can redistribute it and/or modify\n"
00074 "it under the terms of the GNU General Public License as published by\n"
00075 "the Free Software Foundation; either version 2 of the License, or\n"
00076 "(at your option) any later version.\n"
00077 "\n"
00078 "This program is distributed in the hope that it will be useful,\n"
00079 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00080 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00081 "GNU General Public License for more details.\n"
00082 "\n"
00083 "You should have received a copy of the GNU General Public License\n"
00084 "along with this program; if not, write to the Free Software\n"
00085 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, \n"
00086 "MA 02111-1307 USA" ;
00087 return omega_license ;
00088 }
00089
00090
00105
00106 FILE * oc_paf_print_header(
00107 char * filename,
00108 char * paf_id,
00109 char * paf_desc)
00110 {
00111 FILE * paf ;
00112
00113 if ((paf=fopen(filename, "w"))==NULL) return NULL ;
00114 fprintf(paf, "PAF.HDR.START ;# start of header\n");
00115 fprintf(paf, "PAF.TYPE \"pipeline product\" ;\n");
00116 fprintf(paf, "PAF.ID \"%s\"\n", paf_id);
00117 fprintf(paf, "PAF.NAME \"%s\"\n", filename);
00118 fprintf(paf, "PAF.DESC \"%s\"\n", paf_desc);
00119 fprintf(paf, "PAF.CHCK.CHECKSUM \"\"\n");
00120 fprintf(paf, "PAF.HDR.END ;# end of header\n");
00121 fprintf(paf, "\n");
00122 return paf ;
00123 }
00124
00125
00157
00158 char * omega_get_root_name(const char * filename)
00159 {
00160 static char path[MAXNAMESZ+1];
00161 char * lastdot ;
00162
00163 if (strlen(filename)>MAXNAMESZ) return NULL ;
00164 memset(path, MAXNAMESZ, 0);
00165 strcpy(path, filename);
00166 lastdot = strrchr(path, '.');
00167 if (lastdot == NULL) return path ;
00168 if ((!strcmp(lastdot, ".fits")) || (!strcmp(lastdot, ".FITS")) ||
00169 (!strcmp(lastdot, ".paf")) || (!strcmp(lastdot, ".PAF")) ||
00170 (!strcmp(lastdot, ".dat")) || (!strcmp(lastdot, ".DAT")) ||
00171 (!strcmp(lastdot, ".txt")) || (!strcmp(lastdot, ".TXT")) ||
00172 (!strcmp(lastdot, ".tfits")) || (!strcmp(lastdot, ".TFITS")) ||
00173 (!strcmp(lastdot, ".ascii")) || (!strcmp(lastdot, ".ASCII")))
00174 {
00175 lastdot[0] = (char)0;
00176 }
00177 return path ;
00178 }
00179
00180
00204
00205
00206 extern int omega_compare_tags(const cpl_frame *frame1, const cpl_frame *frame2) {
00207 char *v1,*v2;
00208
00209
00210
00211 if (frame1 == NULL || frame2 == NULL)
00212 return(-1);
00213
00214
00215
00216 if ((v1 = (char *)cpl_frame_get_tag(frame1)) == NULL)
00217 return(-1);
00218 if ((v2 = (char *)cpl_frame_get_tag(frame2)) == NULL)
00219 return(-1);
00220
00221
00222
00223 if (strcmp(v1,v2))
00224 return(0);
00225 else
00226 return(1);
00227 }
00228
00229
00255
00256
00257 extern cpl_frameset *omega_frameset_subgroup(cpl_frameset *frameset,
00258 cpl_size *labels, cpl_size nlab,
00259 const char *tag) {
00260 cpl_size i;
00261 cpl_frameset *cur_set,*ret_set;
00262 cpl_frame *cur_frame;
00263 char *cur_tag;
00264
00265 ret_set = NULL;
00266 for (i = 0; i < nlab; i++) {
00267 cur_set = cpl_frameset_extract(frameset,labels,i);
00268 if (cur_set == NULL)
00269 break;
00270 cur_frame = cpl_frameset_get_frame(cur_set,0);
00271 cur_tag = (char *)cpl_frame_get_tag(cur_frame);
00272 if (!strcmp(cur_tag,tag)) {
00273 ret_set = cur_set;
00274 break;
00275 }
00276 cpl_frameset_delete(cur_set);
00277 }
00278 return(ret_set);
00279 }
00280
00281
00303
00304
00305 extern void omega_exten_range(int inexten, int *out1, int *out2) {
00306
00307 if(inexten == -1){
00308 *out1 = 1;
00309 *out2 = 32;
00310 }
00311 else if (inexten == 0) {
00312 *out1 = 0;
00313 *out2 = 0;
00314 } else {
00315 *out1 = inexten;
00316 *out2 = inexten;
00317 }
00318
00319 return;
00320 }
00321
00322
00346
00347
00348 extern void omega_extensions(const cpl_frame *frame, int inexten, int *out1, int *out2)
00349 {
00350
00351 if(inexten == -1){
00352
00353 *out1 = 1;
00354
00355 *out2 = cpl_fits_count_extensions(cpl_frame_get_filename(frame));
00356 }
00357 else if (inexten == 0) {
00358
00359 *out1 = 0;
00360 *out2 = 0;
00361 } else {
00362
00363 *out1 = inexten;
00364 *out2 = inexten;
00365 }
00366
00367 return;
00368 }
00369
00370
00371
00392
00393 int omega_compare_reference(const cpl_image *master, const cpl_frame *refframe,
00394 int ext, cpl_stats **diffstats)
00395 {
00396
00397 cpl_image *refimage = NULL;
00398 cpl_image *diff = NULL;
00399
00400 if ((master == NULL) || (refframe == NULL)){
00401 cpl_msg_warning(cpl_func,"NULL input");
00402 return -1;
00403 }
00404
00405 refimage = cpl_image_load(cpl_frame_get_filename(refframe),CPL_TYPE_FLOAT,0, ext);
00406 if (refimage == NULL){
00407 cpl_msg_warning(cpl_func,"Cannot load reference image");
00408 return -1;
00409 }
00410
00411 diff = cpl_image_subtract_create(master, refimage);
00412 *diffstats = cpl_stats_new_from_image(diff,CPL_STATS_ALL);
00413 if (*diffstats == NULL){
00414 freeimage(diff);
00415 freeimage(refimage);
00416 cpl_msg_warning(cpl_func,"Cannot calculate statistics of difference image");
00417 return -1;
00418 }
00419
00420
00421 return 0;
00422 }
00423
00424
00446 char * omega_get_pathname(const char * filename)
00447 {
00448
00449 static char path[MAXNAMESZ];
00450 char *last_slash;
00451
00452 if (strlen(filename)>MAXNAMESZ) return NULL ;
00453 strcpy(path, filename);
00454
00455 last_slash = path != NULL ? strrchr (path, '/') : NULL;
00456
00457 if (last_slash == path)
00458
00459
00460 ++last_slash;
00461 else if (last_slash != NULL && last_slash[1] == '\0')
00462
00463 last_slash = memchr (path, last_slash - path, '/');
00464
00465 if (last_slash != NULL)
00466
00467 last_slash[0] = '\0';
00468 else
00469
00470
00471
00472 strcpy(path, ".");
00473
00474 return path;
00475
00476
00477 }
00478
00479
00487
00488 cpl_frame *omega_product_frame(const char *filename, const char *tag, cpl_frame_type type)
00489 {
00490 cpl_frame *frame;
00491
00492 if ((filename == NULL) || (tag == NULL)){
00493 return NULL;
00494 }
00495
00496 frame = cpl_frame_new();
00497 cpl_frame_set_filename(frame, filename);
00498 cpl_frame_set_tag(frame, tag);
00499 cpl_frame_set_type(frame, type);
00500 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
00501 cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL);
00502
00503 return frame;
00504
00505 }
00506
00507
00521
00522 int omega_save_dummy(cpl_frameset *set, cpl_parameterlist *parlist, cpl_frame_type type,
00523 cpl_type_bpp bitpix, const char *outfile, const cpl_propertylist *plist,
00524 const char *recipe, cpl_frame *product_frame)
00525 {
00526 int naxis1 = 2046;
00527 int naxis2 = 4098;
00528 const char delkeys[] = "^(ORIGIN|TELESCOPE|INSTRUME|OBJECT|RA|DEC|EPOCH|EQUINOX|RADECSYS|DATE-OBS|" \
00529 "MJD-OBS|UTC|LST|PI-COI|OBSERVER|PIPEFILE)$";
00530 cpl_image *image = NULL;
00531 cpl_table *table = NULL;
00532 cpl_propertylist *list = NULL;
00533
00534
00535
00536
00537 list = cpl_propertylist_duplicate(plist);
00538
00539 if (cpl_dfs_setup_product_header(list, product_frame, set, parlist,
00540 recipe,PIPEID,DICID,NULL) != CPL_ERROR_NONE) {
00541
00542 cpl_msg_warning(cpl_func, "Problem in the extension header of product DFS-compliance") ;
00543 }
00544
00545
00546 cpl_propertylist_erase_regexp(list, delkeys, 0);
00547
00548
00549 if(type == CPL_FRAME_TYPE_IMAGE){
00550 image = cpl_image_new(naxis1, naxis2, CPL_TYPE_FLOAT);
00551 if (cpl_image_save(image,outfile,bitpix,list,
00552 CPL_IO_EXTEND) != CPL_ERROR_NONE) {
00553 cpl_msg_error(cpl_func,"Cannot save product %s", cpl_error_get_message());
00554 freeimage(image);
00555 freeplist(list);
00556 return -1;
00557 }
00558 freeimage(image);
00559 }
00560 else {
00561 table = cpl_table_new(1);
00562 if (cpl_table_save(table, NULL, list,outfile, CPL_IO_EXTEND) != CPL_ERROR_NONE) {
00563 cpl_msg_error(cpl_func, "Cannot save the extension table");
00564 freetable(table);
00565 freeplist(list);
00566 return -1;
00567 }
00568 freetable(table);
00569 }
00570
00571 freeplist(list);
00572
00573 return 0;
00574 }
00575
00576
00589
00590 int omega_save_primary(cpl_frameset *set, const cpl_parameterlist *parlist,
00591 const char *outfile, const char *recipe, const cpl_propertylist *plist,
00592 cpl_frame *product_frame, const cpl_frame *inherit)
00593 {
00594
00595 cpl_propertylist *pplist;
00596
00597
00598 if(plist == NULL)
00599 pplist = cpl_propertylist_new();
00600 else
00601 pplist = cpl_propertylist_duplicate(plist);
00602
00603
00604 if (cpl_dfs_setup_product_header(pplist, product_frame, set, parlist,
00605 recipe,PIPEID,DICID,inherit) != CPL_ERROR_NONE) {
00606
00607 cpl_msg_debug(cpl_func, "Problem in the main header of product DFS-compliance") ;
00608 }
00609
00610
00611
00612
00613
00614 cpl_propertylist_erase_regexp(pplist,REM_PRIM_KEYS,0);
00615
00616
00617 if (cpl_propertylist_save(pplist,outfile,CPL_IO_DEFAULT) != CPL_ERROR_NONE){
00618 freeplist(pplist);
00619 return -1;
00620 }
00621
00622 freeplist(pplist);
00623 cpl_frameset_insert(set,product_frame);
00624
00625 return 0;
00626 }
00627
00628
00636
00637 cpl_image *omega_smooth_image(cpl_image *in, int size)
00638 {
00639
00640 int i,nx, ny, type;
00641 cpl_matrix *kernel;
00642 cpl_mask *mask;
00643 cpl_image *out;
00644
00645 if (in == NULL)
00646 return NULL;
00647
00648
00649
00650
00651 nx = cpl_image_get_size_x(in);
00652 ny = cpl_image_get_size_y(in);
00653 type = cpl_image_get_type(in);
00654
00655 kernel = cpl_matrix_new(size, size);
00656
00657
00658 cpl_matrix_delete(kernel);
00659
00660
00661
00662 mask = cpl_mask_new(size, size);
00663 for (i = 0; i < size; ++i) {
00664 int j = 0;
00665 for (j = 0; j < size; j++)
00666 {
00667 cpl_mask_set(mask, i + 1, j + 1, CPL_BINARY_1);
00668 }
00669
00670 }
00671
00672 out = cpl_image_new(nx, ny, type);
00673 if(cpl_image_filter_mask(out, in, mask, CPL_FILTER_AVERAGE, CPL_BORDER_FILTER)
00674 != CPL_ERROR_NONE){
00675 cpl_msg_debug(cpl_func,"Cannot filter image. %s", cpl_error_get_message());
00676 freeimage(out);
00677 freemask(mask);
00678 return NULL;
00679 }
00680
00681
00682 freemask(mask);
00683 return (out);
00684
00685 }
00686
00687
00699
00700 char *omega_create_name(const char *instrument, const char *name, const char *suffix)
00701 {
00702 char *outname;
00703 const char *end = "fits";
00704
00705 if(instrument == NULL || name == NULL){
00706 return NULL;
00707 }
00708 if(suffix == NULL)
00709 suffix = end;
00710
00711 sprintf(outname, "%s_%s.%s", instrument, name, suffix);
00712
00713 return outname;
00714 }
00715
00726 int omega_biascor(cpl_image *image, const cpl_image *bias)
00727 {
00728
00729 if((image == NULL) || (bias == NULL))
00730 return -1;
00731
00732
00733 if(cpl_image_subtract(image, bias) != CPL_ERROR_NONE){
00734 return -1;
00735 }
00736
00737
00738 return 0;
00739 }
00740
00751 const char * omega_get_extension_chipid(int ext)
00752 {
00753
00754 const char *chipid;
00755
00756 switch (ext){
00757 case 1:
00758 chipid = "ESO_CCD_#65";
00759 break;
00760 case 2:
00761 chipid = "ESO_CCD_#66";
00762 break;
00763 case 3:
00764 chipid = "ESO_CCD_#67";
00765 break;
00766 case 4:
00767 chipid = "ESO_CCD_#68";
00768 break;
00769 case 5:
00770 chipid = "ESO_CCD_#73";
00771 break;
00772 case 6:
00773 chipid = "ESO_CCD_#74";
00774 break;
00775 case 7:
00776 chipid = "ESO_CCD_#75";
00777 break;
00778 case 8:
00779 chipid = "ESO_CCD_#76";
00780 break;
00781 case 9:
00782 chipid = "ESO_CCD_#81";
00783 break;
00784 case 10:
00785 chipid = "ESO_CCD_#82";
00786 break;
00787 case 11:
00788 chipid = "ESO_CCD_#83";
00789 break;
00790 case 12:
00791 chipid = "ESO_CCD_#84";
00792 break;
00793 case 13:
00794 chipid = "ESO_CCD_#89";
00795 break;
00796 case 14:
00797 chipid = "ESO_CCD_#90";
00798 break;
00799 case 15:
00800 chipid = "ESO_CCD_#91";
00801 break;
00802 case 16:
00803 chipid = "ESO_CCD_#92";
00804 break;
00805 case 17:
00806 chipid = "ESO_CCD_#69";
00807 break;
00808 case 18:
00809 chipid = "ESO_CCD_#70";
00810 break;
00811 case 19:
00812 chipid = "ESO_CCD_#71";
00813 break;
00814 case 20:
00815 chipid = "ESO_CCD_#72";
00816 break;
00817 case 21:
00818 chipid = "ESO_CCD_#77";
00819 break;
00820 case 22:
00821 chipid = "ESO_CCD_#78";
00822 break;
00823 case 23:
00824 chipid = "ESO_CCD_#79";
00825 break;
00826 case 24:
00827 chipid = "ESO_CCD_#80";
00828 break;
00829 case 25:
00830 chipid = "ESO_CCD_#85";
00831 break;
00832 case 26:
00833 chipid = "ESO_CCD_#86";
00834 break;
00835 case 27:
00836 chipid = "ESO_CCD_#87";
00837 break;
00838 case 28:
00839 chipid = "ESO_CCD_#88";
00840 break;
00841 case 29:
00842 chipid = "ESO_CCD_#93";
00843 break;
00844 case 30:
00845 chipid = "ESO_CCD_#94";
00846 break;
00847 case 31:
00848 chipid = "ESO_CCD_#95";
00849 break;
00850 case 32:
00851 chipid = "ESO_CCD_#96";
00852 break;
00853 default:
00854 cpl_msg_warning(cpl_func,"Unable to find CHIP ID for extension %d",ext);
00855 chipid = NULL;
00856 break;
00857 }
00858
00859 return chipid;
00860 }
00861
00871 int omega_get_chip_orientation(int ext)
00872 {
00873
00874 int orient = 1;
00875
00876 if(((ext >= 1) && (ext <= 8)) || ((ext >=17) && (ext <= 24)))
00877 orient = 1;
00878 else if(((ext >= 9) && (ext <=16)) || ((ext >= 25) && (ext <= 32)))
00879 orient = 2;
00880 else
00881 cpl_msg_warning(cpl_func,"Unable to get chip orientation. Using default 1");
00882
00883
00884 return orient;
00885 }
00886
00905 int omega_save_image(const cpl_image *img,cpl_frameset *set,const cpl_parameterlist *pars,
00906 cpl_propertylist *alist, const cpl_propertylist *qclist,cpl_type_bpp bpp,
00907 const char *name, const char *recipe, cpl_frame *frame,
00908 const cpl_frame *inherit, int isfirst)
00909 {
00910
00911 cpl_propertylist *plist;
00912
00913 if((img == NULL) || (set == NULL) || (pars == NULL) ||
00914 (name == NULL) || (frame == NULL))
00915 return -1;
00916
00917 if(isfirst){
00918
00919 if(omega_save_primary(set,pars,name,recipe,NULL,frame,inherit) == -1){
00920 cpl_msg_error(cpl_func,"Cannot save primary header of product");
00921 return -1;
00922 }
00923 }
00924
00925
00926 plist = cpl_propertylist_new();
00927
00928 if(alist != NULL)
00929 omega_pfits_update_header(plist,alist);
00930
00931
00932 if (cpl_dfs_setup_product_header(plist, frame, set, pars,
00933 recipe,PIPEID,DICID,inherit) != CPL_ERROR_NONE) {
00934 cpl_msg_warning(cpl_func, "Unable to setup extension header of %s. %s",name,
00935 cpl_error_get_message()) ;
00936 }
00937
00938
00939 cpl_propertylist_erase_regexp(plist, REM_EXT_KEYS, 0);
00940
00941
00942 if(qclist != NULL)
00943 cpl_propertylist_append(plist, qclist);
00944
00945
00946 if (cpl_image_save(img,name,bpp,plist,CPL_IO_EXTEND) != CPL_ERROR_NONE) {
00947 cpl_msg_error(cpl_func,"Cannot save product. %s", cpl_error_get_message());
00948 freeplist(plist);
00949 return -1;
00950 }
00951
00952 freeplist(plist);
00953
00954 return 0;
00955
00956 }
00957
00976 int omega_save_table(const cpl_table *tbl,cpl_frameset *set,const cpl_parameterlist *pars,
00977 cpl_propertylist *alist, const cpl_propertylist *qclist,const char *name,
00978 const char *recipe, cpl_frame *frame,const cpl_frame *inherit, int isfirst)
00979 {
00980
00981 cpl_propertylist *plist;
00982
00983 if((tbl == NULL) || (set == NULL) || (pars == NULL) ||
00984 (name == NULL) || (frame == NULL))
00985 return -1;
00986
00987 if(isfirst){
00988
00989 if(omega_save_primary(set,pars,name,recipe,NULL,frame,inherit) == -1){
00990 cpl_msg_error(cpl_func,"Cannot save primary header of product");
00991 return -1;
00992 }
00993 }
00994
00995
00996 plist = cpl_propertylist_new();
00997
00998 if(alist != NULL)
00999 omega_pfits_update_header(plist,alist);
01000
01001
01002 if (cpl_dfs_setup_product_header(plist, frame, set, pars,
01003 recipe,PIPEID,DICID,inherit) != CPL_ERROR_NONE) {
01004
01005 cpl_msg_warning(cpl_func, "Unable to setup extension header of %s. %s",name,
01006 cpl_error_get_message()) ;
01007 }
01008
01009
01010 cpl_propertylist_erase_regexp(plist, REM_EXT_KEYS, 0);
01011
01012
01013 if(qclist != NULL)
01014 cpl_propertylist_append(plist, qclist);
01015
01016
01017 if (cpl_table_save(tbl,NULL,plist,name,CPL_IO_EXTEND) != CPL_ERROR_NONE) {
01018 cpl_msg_error(cpl_func,"Cannot save product. %s", cpl_error_get_message());
01019 freeplist(plist);
01020 return -1;
01021 }
01022
01023 freeplist(plist);
01024
01025 return 0;
01026 }
01027
01045 int omega_save_fits(omega_fits *scifits,cpl_frameset *set, const cpl_parameterlist *pars,
01046 const cpl_propertylist *qclist, cpl_type_bpp bpp,const char *name,
01047 const char *recipe,cpl_frame *product_frame, const cpl_frame *inherit,
01048 const int isfirst)
01049 {
01050
01051 cpl_propertylist *plist;
01052
01053 if((scifits == NULL) || (set == NULL) || (pars == NULL) ||
01054 (name == NULL) || (product_frame == NULL))
01055 return -1;
01056
01057
01058 if(isfirst){
01059
01060 plist = cpl_propertylist_duplicate(omega_fits_get_phu(scifits));
01061
01062 if(omega_save_primary(set,pars,name,recipe,plist,product_frame,inherit) == -1){
01063 cpl_msg_error(cpl_func,"Cannot save primary header of product");
01064 freeplist(plist);
01065 return -1;
01066 }
01067
01068 freeplist(plist);
01069 }
01070
01071
01072 plist = cpl_propertylist_duplicate(omega_fits_get_ehu(scifits));
01073
01074
01075 if (cpl_dfs_setup_product_header(plist, product_frame, set, pars,
01076 recipe,PIPEID,DICID,inherit) != CPL_ERROR_NONE) {
01077
01078 cpl_msg_warning(cpl_func, "Unable to setup extension header of %s. %s",name,
01079 cpl_error_get_message()) ;
01080 }
01081
01082
01083 cpl_propertylist_erase_regexp(plist, REM_EXT_KEYS, 0);
01084
01085
01086 if(qclist != NULL)
01087 cpl_propertylist_append(plist, qclist);
01088
01089
01090 if (cpl_image_save(omega_fits_get_image(scifits),name,bpp,
01091 plist,CPL_IO_EXTEND) != CPL_ERROR_NONE) {
01092 cpl_msg_error(cpl_func,"Cannot save product %s. %s", name, cpl_error_get_message());
01093 freeplist(plist);
01094 return -1;
01095 }
01096
01097 freeplist(plist);
01098
01099 return 0;
01100 }
01101
01102 cpl_error_code omega_get_pixelscale(cpl_propertylist *plist,
01103 double * pixscale_x, double * pixscale_y){
01104
01105 double cd11= 0.;
01106 double cd12= 0.;
01107 double cd21= 0.;
01108 double cd22= 0.;
01109
01110 if(cpl_propertylist_has(plist,"CD1_1") &&
01111 cpl_propertylist_has(plist,"CD1_2") &&
01112 cpl_propertylist_has(plist,"CD2_1") &&
01113 cpl_propertylist_has(plist,"CD2_2")){
01114 cd11= cpl_propertylist_get_double(plist, "CD1_1");
01115 cd12= cpl_propertylist_get_double(plist, "CD1_2");
01116 cd21= cpl_propertylist_get_double(plist, "CD2_1");
01117 cd22= cpl_propertylist_get_double(plist, "CD2_2");
01118 }
01119 else{
01120 cpl_error_set_message(cpl_func,CPL_ERROR_DATA_NOT_FOUND, "CD matrix not"
01121 " complete. Pixel scale can not be computed");
01122 return cpl_error_get_code();
01123 }
01124
01125 *pixscale_x = sqrt (cd11*cd11 + cd21*cd21);
01126 *pixscale_y = sqrt (cd12*cd12 + cd22*cd22);
01127
01128 cpl_msg_debug(cpl_func,"Pixelscale "
01129 "x: %g y: %g",*pixscale_x, *pixscale_y);
01130
01131 return cpl_error_get_code();
01132
01133 }
01134
01146 cpl_error_code omega_get_wcsshift(cpl_propertylist * wcslist1,
01147 cpl_propertylist * wcslist2, double * xshift, double * yshift){
01148
01149 cpl_wcs * wcs1=NULL;
01150 cpl_wcs * wcs2=NULL;
01151
01152 wcs1=cpl_wcs_new_from_propertylist(wcslist1);
01153 wcs2=cpl_wcs_new_from_propertylist(wcslist2);
01154
01155 if(wcs1 == NULL || wcs2 == NULL )
01156 {
01157 cpl_msg_warning(cpl_func, "WCS informations missing - assuming no shift "
01158 "of the x and y coordinate");
01159 *xshift=0;
01160 *yshift=0;
01161 cpl_msg_debug(cpl_func, "Coordinateshift: xshif=%g, yshift=%g",
01162 *xshift,*yshift);
01163 cpl_wcs_delete(wcs1);
01164 cpl_wcs_delete(wcs2);
01165 return cpl_error_get_code();
01166 }
01167 else{
01168 *xshift=cpl_array_get(cpl_wcs_get_crpix(wcs1),0,NULL) -
01169 cpl_array_get(cpl_wcs_get_crpix(wcs2),0,NULL);
01170 *yshift=cpl_array_get(cpl_wcs_get_crpix(wcs1),1,NULL) -
01171 cpl_array_get(cpl_wcs_get_crpix(wcs2),1,NULL);
01172 }
01173
01174 cpl_wcs_delete(wcs1);
01175 cpl_wcs_delete(wcs2);
01176
01177 cpl_msg_debug(cpl_func, "Coordinateshift: xshif=%g, yshift=%g",
01178 *xshift,*yshift);
01179
01180 return cpl_error_get_code();
01181 }
01182