00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024
00025
00026
00027
00028
00029
00030 #include "irplib_framelist.h"
00031 #include "irplib_utils.h"
00032 #include <cpl.h>
00033
00034 #include <stdio.h>
00035 #include <string.h>
00036 #include <sys/types.h>
00037 #include <regex.h>
00038 #include <math.h>
00039 #include <assert.h>
00040
00041
00042
00043
00044
00045
00046
00047 struct _irplib_framelist_ {
00048 int size;
00049 cpl_frame ** frame;
00050 cpl_propertylist ** propertylist;
00051
00052 };
00053
00054
00055
00056
00057
00058
00059 static void irplib_framelist_set_size(irplib_framelist *)
00060 #if defined __GNUC__ && __GNUC__ >= 4
00061 __attribute__((nonnull))
00062 #endif
00063 ;
00064
00065 static cpl_boolean irplib_property_equal(const cpl_propertylist *,
00066 const cpl_propertylist *,
00067 const char *, cpl_type, double,
00068 char **, char **)
00069 #if defined __GNUC__ && __GNUC__ >= 4
00070 __attribute__((nonnull))
00071 #endif
00072 ;
00073
00074
00153
00154
00157
00158
00159
00160
00161
00169
00170 irplib_framelist * irplib_framelist_new(void)
00171 {
00172
00173 return (irplib_framelist *) cpl_calloc(1, sizeof(irplib_framelist));
00174
00175 }
00176
00177
00182
00183 void irplib_framelist_delete(irplib_framelist * self)
00184 {
00185
00186 irplib_framelist_empty(self);
00187 cpl_free(self);
00188 }
00189
00190
00191
00200
00201 irplib_framelist * irplib_framelist_cast(const cpl_frameset * frameset)
00202 {
00203
00204 irplib_framelist * self;
00205 int i;
00206
00207
00208 cpl_ensure(frameset != NULL, CPL_ERROR_NULL_INPUT, NULL);
00209
00210
00211 self = irplib_framelist_new();
00212
00213 for (i = 0; i < cpl_frameset_get_size(frameset); i++)
00214 {
00215 const cpl_frame * frame = cpl_frameset_get_position_const(frameset, i);
00216
00217 cpl_frame * copy = cpl_frame_duplicate(frame);
00218
00219 const cpl_error_code error = irplib_framelist_set(self, copy, i);
00220
00221 assert(error == CPL_ERROR_NONE);
00222
00223 }
00224
00225 assert(self->size == cpl_frameset_get_size(frameset));
00226
00227 return self;
00228
00229 }
00230
00231
00232
00241
00242 cpl_frameset * irplib_frameset_cast(const irplib_framelist * self)
00243 {
00244
00245 cpl_frameset * new;
00246 int i;
00247
00248 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
00249
00250
00251 new = cpl_frameset_new();
00252
00253 for (i = 0; i < self->size; i++) {
00254 cpl_frame * frame = cpl_frame_duplicate(self->frame[i]);
00255 const cpl_error_code error = cpl_frameset_insert(new, frame);
00256
00257 assert(error == CPL_ERROR_NONE);
00258
00259 }
00260
00261 assert(self->size == cpl_frameset_get_size(new));
00262
00263 return new;
00264
00265 }
00266
00267
00268
00280
00281 irplib_framelist * irplib_framelist_extract(const irplib_framelist * self,
00282 const char * tag)
00283 {
00284
00285 irplib_framelist * new;
00286 int i, newsize;
00287
00288
00289 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
00290 cpl_ensure(tag != NULL, CPL_ERROR_NULL_INPUT, NULL);
00291
00292 new = irplib_framelist_new();
00293 newsize = 0;
00294
00295 for (i = 0; i < self->size; i++) {
00296 const cpl_frame * frame = self->frame[i];
00297 const char * ftag = cpl_frame_get_tag(frame);
00298 cpl_frame * copy;
00299 cpl_error_code error;
00300
00301 if (ftag == NULL) {
00302
00303 irplib_framelist_delete(new);
00304 cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, NULL);
00305 }
00306
00307 if (strcmp(tag, ftag)) continue;
00308
00309 copy = cpl_frame_duplicate(frame);
00310
00311 error = irplib_framelist_set(new, copy, newsize);
00312 assert(error == CPL_ERROR_NONE);
00313
00314 if (self->propertylist[i] != NULL) new->propertylist[newsize]
00315 = cpl_propertylist_duplicate(self->propertylist[i]);
00316
00317 newsize++;
00318 }
00319
00320 assert( newsize == new->size );
00321
00322 if (newsize == 0) {
00323 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00324 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
00325 "The list of %d frame(s) has no frames "
00326 "with tag: %s", self->size, tag);
00327 #else
00328 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
00329 "The list of frame(s) has no frames "
00330 "with the given tag");
00331 #endif
00332 irplib_framelist_delete(new);
00333 new = NULL;
00334 }
00335
00336 return new;
00337
00338 }
00339
00340
00350
00351 irplib_framelist * irplib_framelist_extract_regexp(const irplib_framelist* self,
00352 const char * regexp,
00353 cpl_boolean invert)
00354 {
00355
00356 irplib_framelist * new;
00357 int error;
00358 int i, newsize;
00359 const int xor_val = (invert == CPL_FALSE ? 0 : 1);
00360 regex_t re;
00361
00362
00363 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
00364 cpl_ensure(regexp != NULL, CPL_ERROR_NULL_INPUT, NULL);
00365
00366 error = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB);
00367 cpl_ensure(!error, CPL_ERROR_ILLEGAL_INPUT, NULL);
00368
00369 new = irplib_framelist_new();
00370 newsize = 0;
00371
00372 for (i = 0; i < self->size; i++) {
00373 const cpl_frame * frame = self->frame[i];
00374 const char * tag = cpl_frame_get_tag(frame);
00375 cpl_frame * copy;
00376
00377 if (tag == NULL) {
00378
00379 irplib_framelist_delete(new);
00380 regfree(&re);
00381 cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, NULL);
00382 }
00383
00384 if ((regexec(&re, tag, (size_t)0, NULL, 0) == REG_NOMATCH ? 1 : 0)
00385 ^ xor_val) continue;
00386
00387 copy = cpl_frame_duplicate(frame);
00388
00389 error = (int)irplib_framelist_set(new, copy, newsize);
00390 assert(error == CPL_ERROR_NONE);
00391
00392 if (self->propertylist[i] != NULL) new->propertylist[newsize]
00393 = cpl_propertylist_duplicate(self->propertylist[i]);
00394
00395 newsize++;
00396
00397 }
00398
00399 regfree(&re);
00400
00401 assert( newsize == new->size );
00402
00403 if (newsize == 0) {
00404 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00405 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
00406 "The list of %d frame(s) has no frames "
00407 "that match: %s", self->size, regexp);
00408 #else
00409 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
00410 "The list of frames has no frames "
00411 "that match the regular expression");
00412 #endif
00413 irplib_framelist_delete(new);
00414 new = NULL;
00415 }
00416
00417 return new;
00418 }
00419
00420
00421
00428
00429 int irplib_framelist_get_size(const irplib_framelist * self)
00430 {
00431
00432 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1);
00433
00434 return self->size;
00435
00436 }
00437
00438
00446
00447 cpl_frame * irplib_framelist_get(irplib_framelist * self, int pos)
00448 {
00449 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
00450 return (cpl_frame *)irplib_framelist_get_const(self, pos);
00451 IRPLIB_DIAG_PRAGMA_POP;
00452 }
00453
00454
00455
00463
00464 const cpl_frame * irplib_framelist_get_const(const irplib_framelist * self,
00465 int pos)
00466 {
00467
00468 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
00469 cpl_ensure(pos >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
00470 cpl_ensure(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
00471
00472 return self->frame[pos];
00473
00474 }
00475
00476
00477
00486
00487 cpl_error_code irplib_framelist_set_propertylist(irplib_framelist * self,
00488 int pos,
00489 const cpl_propertylist * list)
00490 {
00491
00492 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00493 cpl_ensure_code(list != NULL, CPL_ERROR_NULL_INPUT);
00494 cpl_ensure_code(pos >= 0, CPL_ERROR_ILLEGAL_INPUT);
00495 cpl_ensure_code(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
00496
00497 cpl_propertylist_delete(self->propertylist[pos]);
00498
00499 self->propertylist[pos] = cpl_propertylist_duplicate(list);
00500
00501 cpl_ensure_code(self->propertylist[pos] != NULL, cpl_error_get_code());
00502
00503 return CPL_ERROR_NONE;
00504
00505 }
00506
00507
00508
00519
00520 cpl_propertylist * irplib_framelist_get_propertylist(irplib_framelist * self,
00521 int pos)
00522 {
00523
00524 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
00525 return (cpl_propertylist *)irplib_framelist_get_propertylist_const(self,
00526 pos);
00527 IRPLIB_DIAG_PRAGMA_POP;
00528 }
00529
00530
00531
00542
00543 const cpl_propertylist * irplib_framelist_get_propertylist_const(
00544 const irplib_framelist * self,
00545 int pos)
00546 {
00547 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
00548 cpl_ensure(pos >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
00549 cpl_ensure(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
00550
00551 cpl_ensure(self->propertylist[pos] != NULL,
00552 CPL_ERROR_DATA_NOT_FOUND, NULL);
00553
00554 return self->propertylist[pos];
00555
00556 }
00557
00558
00559
00573
00574 cpl_error_code irplib_framelist_load_propertylist(irplib_framelist * self,
00575 int pos, int ind,
00576 const char * regexp,
00577 cpl_boolean invert)
00578 {
00579
00580 const char * filename;
00581
00582
00583 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00584 cpl_ensure_code(regexp != NULL, CPL_ERROR_NULL_INPUT);
00585 cpl_ensure_code(pos >= 0, CPL_ERROR_ILLEGAL_INPUT);
00586 cpl_ensure_code(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
00587
00588 filename = cpl_frame_get_filename(self->frame[pos]);
00589
00590 cpl_ensure_code(filename != NULL, cpl_error_get_code());
00591
00592 cpl_propertylist_delete(self->propertylist[pos]);
00593
00594 self->propertylist[pos] = cpl_propertylist_load_regexp(filename, ind,
00595 regexp,
00596 invert ? 1 : 0);
00597
00598 if (self->propertylist[pos] == NULL) {
00599 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00600 return cpl_error_set_message(cpl_func, cpl_error_get_code(), "Could "
00601 "not load FITS header from '%s' using "
00602 "regexp '%s'", filename, regexp);
00603 #else
00604 return cpl_error_set_message(cpl_func, cpl_error_get_code(),
00605 "Could not load FITS header");
00606 #endif
00607 }
00608
00609 return CPL_ERROR_NONE;
00610
00611 }
00612
00613
00614
00628
00629 cpl_error_code irplib_framelist_load_propertylist_all(irplib_framelist * self,
00630 int ind,
00631 const char * regexp,
00632 cpl_boolean invert)
00633 {
00634
00635 int nprops = 0;
00636 int nfiles = 0;
00637 int i;
00638
00639 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00640 cpl_ensure_code(regexp != NULL, CPL_ERROR_NULL_INPUT);
00641
00642 for (i=0; i < self->size; i++) {
00643 if (self->propertylist[i] == NULL)
00644 cpl_ensure_code(!irplib_framelist_load_propertylist(self, i,
00645 ind,
00646 regexp,
00647 invert),
00648 cpl_error_get_code());
00649
00650
00651 nprops += cpl_propertylist_get_size(self->propertylist[i]);
00652 nfiles++;
00653 }
00654
00655 cpl_msg_info(cpl_func, "List of %d frames has %d properties", nfiles,
00656 nprops);
00657
00658 return CPL_ERROR_NONE;
00659
00660 }
00661
00662
00663
00664
00672
00673 cpl_error_code irplib_framelist_set_tag_all(irplib_framelist * self,
00674 const char * tag)
00675 {
00676
00677 int i;
00678
00679 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00680 cpl_ensure_code(tag != NULL, CPL_ERROR_NULL_INPUT);
00681
00682 for (i=0; i < self->size; i++)
00683 cpl_ensure_code(!cpl_frame_set_tag(self->frame[i], tag),
00684 cpl_error_get_code());
00685
00686 return CPL_ERROR_NONE;
00687 }
00688
00689
00690
00704
00705 cpl_error_code irplib_framelist_set(irplib_framelist * self, cpl_frame * frame,
00706 int pos)
00707 {
00708
00709 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00710 cpl_ensure_code(frame != NULL, CPL_ERROR_NULL_INPUT);
00711 cpl_ensure_code(pos >= 0, CPL_ERROR_ILLEGAL_INPUT);
00712
00713 if (pos == self->size) {
00714
00715 self->size++;
00716
00717 irplib_framelist_set_size(self);
00718
00719 } else {
00720
00721 cpl_ensure_code(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
00722
00723 cpl_frame_delete(self->frame[pos]);
00724 cpl_propertylist_delete(self->propertylist[pos]);
00725 }
00726
00727 self->frame[pos] = frame;
00728 self->propertylist[pos] = NULL;
00729
00730 return CPL_ERROR_NONE;
00731
00732 }
00733
00734
00743
00744 cpl_error_code irplib_framelist_erase(irplib_framelist * self, int pos)
00745 {
00746
00747 int i;
00748
00749 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00750 cpl_ensure_code(pos >= 0, CPL_ERROR_ILLEGAL_INPUT);
00751 cpl_ensure_code(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
00752
00753
00754
00755 cpl_frame_delete(self->frame[pos]);
00756 cpl_propertylist_delete(self->propertylist[pos]);
00757
00758
00759 for (i = pos+1; i < self->size; i++) {
00760
00761 self->frame[i-1] = self->frame[i];
00762
00763 self->propertylist[i-1] = self->propertylist[i];
00764
00765 }
00766
00767 self->size--;
00768
00769 irplib_framelist_set_size(self);
00770
00771 return CPL_ERROR_NONE;
00772
00773 }
00774
00775
00776
00777
00793
00794 cpl_frame * irplib_framelist_unset(irplib_framelist * self, int pos,
00795 cpl_propertylist ** plist)
00796
00797 {
00798 cpl_frame * frame;
00799 int i;
00800
00801
00802 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
00803 cpl_ensure(pos >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
00804 cpl_ensure(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
00805
00806
00807 frame = self->frame[pos];
00808
00809 if (plist != NULL)
00810 *plist = self->propertylist[pos];
00811 else
00812 cpl_propertylist_delete(self->propertylist[pos]);
00813
00814
00815
00816 for (i = pos+1; i < self->size; i++) {
00817
00818 self->frame[i-1] = self->frame[i];
00819
00820 self->propertylist[i-1] = self->propertylist[i];
00821
00822 }
00823
00824 self->size--;
00825
00826 irplib_framelist_set_size(self);
00827
00828 return frame;
00829
00830 }
00831
00832
00839
00840 void irplib_framelist_empty(irplib_framelist * self)
00841 {
00842
00843 if (self != NULL) {
00844
00845
00846 while (self->size > 0) {
00847 self->size--;
00848 cpl_frame_delete(self->frame[self->size]);
00849 cpl_propertylist_delete(self->propertylist[self->size]);
00850
00851 }
00852
00853
00854 irplib_framelist_set_size(self);
00855
00856 }
00857 }
00858
00859
00860
00861
00899
00900 cpl_error_code irplib_framelist_contains(const irplib_framelist * self,
00901 const char * key, cpl_type type,
00902 cpl_boolean is_equal, double fp_tol)
00903 {
00904
00905 char * value_0;
00906 char * value_i;
00907 cpl_type type_0 = CPL_TYPE_INVALID;
00908 int i, ifirst = -1;
00909
00910
00911 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00912 cpl_ensure_code(key != NULL, CPL_ERROR_NULL_INPUT);
00913 cpl_ensure_code(fp_tol >= 0.0, CPL_ERROR_ILLEGAL_INPUT);
00914
00915 for (i=0; i < self->size; i++) {
00916 cpl_type type_i;
00917
00918
00919 if (self->propertylist[i] == NULL) continue;
00920 if (ifirst < 0) ifirst = i;
00921
00922 type_i = cpl_propertylist_get_type(self->propertylist[i], key);
00923
00924 if (type_i == CPL_TYPE_INVALID) {
00925 if (type == CPL_TYPE_INVALID)
00926 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00927 cpl_error_set_message(cpl_func, cpl_error_get_code(), "FITS "
00928 "key '%s' is missing from file %s", key,
00929 cpl_frame_get_filename(self->frame[i]));
00930 else
00931 cpl_error_set_message(cpl_func, cpl_error_get_code(),
00932 "FITS key '%s' [%s] is missing from file "
00933 "%s", key, cpl_type_get_name(type),
00934 cpl_frame_get_filename(self->frame[i]));
00935 #else
00936 cpl_error_set_message(cpl_func, cpl_error_get_code(),
00937 "A FITS key is missing from a file");
00938 else
00939 cpl_error_set_message(cpl_func, cpl_error_get_code(),
00940 "A FITS key is missing from a file");
00941 #endif
00942 return cpl_error_get_code();
00943 }
00944
00945 if (type != CPL_TYPE_INVALID && type_i != type) {
00946 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00947 return cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
00948 "FITS key '%s' has type %s instead of "
00949 "%s in file %s", key,
00950 cpl_type_get_name(type_i),
00951 cpl_type_get_name(type),
00952 cpl_frame_get_filename(self->frame[i]));
00953 #else
00954 return cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
00955 "A FITS key had an unexpected type");
00956 #endif
00957
00958 }
00959
00960 if (!is_equal) continue;
00961
00962 if (type_0 == CPL_TYPE_INVALID) {
00963 type_0 = type_i;
00964 continue;
00965 }
00966
00967 if (type_i != type_0) {
00968 assert( type == CPL_TYPE_INVALID );
00969 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00970 return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH,
00971 "FITS key '%s' has different types "
00972 "(%s <=> %s) in files %s and %s", key,
00973 cpl_type_get_name(type_0),
00974 cpl_type_get_name(type_i),
00975 cpl_frame_get_filename(self->frame[0]),
00976 cpl_frame_get_filename(self->frame[i]));
00977 #else
00978 return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH,
00979 "A FITS key has different types in "
00980 "two files");
00981 #endif
00982 }
00983
00984 if (irplib_property_equal(self->propertylist[ifirst],
00985 self->propertylist[i],
00986 key, type_0, fp_tol, &value_0, &value_i))
00987 continue;
00988
00989 if ((type_0 == CPL_TYPE_FLOAT || type_0 == CPL_TYPE_DOUBLE)
00990 && fp_tol > 0.0) {
00991 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00992 cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, "FITS"
00993 " key '%s' [%s] has values that differ by "
00994 "more than %g (%s <=> %s) in files %s and %s",
00995 key, cpl_type_get_name(type_0), fp_tol,
00996 value_0, value_i,
00997 cpl_frame_get_filename(self->frame[0]),
00998 cpl_frame_get_filename(self->frame[i]));
00999 #else
01000 cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, "A "
01001 "FITS key has values that differ by more "
01002 "than the allowed tolerance in two file");
01003 #endif
01004 } else {
01005 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
01006 cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT,
01007 "FITS key '%s' [%s] has different values "
01008 "(%s <=> %s) in files %s and %s", key,
01009 cpl_type_get_name(type_0),
01010 value_0, value_i,
01011 cpl_frame_get_filename(self->frame[0]),
01012 cpl_frame_get_filename(self->frame[i]));
01013 #else
01014 cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, "A "
01015 "FITS key has different values in two files");
01016 #endif
01017 }
01018 cpl_free(value_0);
01019 cpl_free(value_i);
01020
01021 return cpl_error_get_code();
01022 }
01023
01024 return CPL_ERROR_NONE;
01025
01026 }
01027
01028
01029
01042
01043 cpl_imagelist * irplib_imagelist_load_framelist(const irplib_framelist * self,
01044 cpl_type pixeltype,
01045 int planenum,
01046 int extnum)
01047 {
01048
01049 cpl_imagelist * list = NULL;
01050 cpl_image * image = NULL;
01051 int i;
01052
01053
01054 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
01055 cpl_ensure(extnum >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
01056 cpl_ensure(planenum >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
01057
01058 list = cpl_imagelist_new();
01059
01060 for (i=0; i < self->size; i++, image = NULL) {
01061 const char * filename = cpl_frame_get_filename(self->frame[i]);
01062 cpl_error_code error;
01063
01064 if (filename == NULL) break;
01065
01066 image = cpl_image_load(filename, pixeltype, planenum, extnum);
01067 if (image == NULL) {
01068 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
01069 (void)cpl_error_set_message(cpl_func, cpl_error_get_code(),
01070 "Could not load FITS-image from plane "
01071 "%d in extension %d in file %s",
01072 planenum, extnum, filename);
01073 #else
01074 (void)cpl_error_set_message(cpl_func, cpl_error_get_code(),
01075 "Could not load FITS-image");
01076 #endif
01077 break;
01078 }
01079
01080 error = cpl_imagelist_set(list, image, i);
01081 assert(error == CPL_ERROR_NONE);
01082 }
01083
01084 cpl_image_delete(image);
01085
01086 if (cpl_imagelist_get_size(list) != self->size) {
01087 cpl_imagelist_delete(list);
01088 list = NULL;
01089 assert(cpl_error_get_code() != CPL_ERROR_NONE);
01090 }
01091
01092 return list;
01093
01094 }
01095
01096
01100
01112
01113 static void irplib_framelist_set_size(irplib_framelist * self)
01114 {
01115
01116
01117 assert( self != NULL);
01118
01119 if (self->size == 0) {
01120
01121 cpl_free(self->frame);
01122 cpl_free(self->propertylist);
01123 self->frame = NULL;
01124 self->propertylist = NULL;
01125 } else {
01126
01127
01128 self->frame = cpl_realloc(self->frame, self->size * sizeof(cpl_frame*));
01129 self->propertylist =
01130 cpl_realloc(self->propertylist,
01131 self->size * sizeof(cpl_propertylist*));
01132 }
01133
01134 }
01135
01136
01160
01161 static cpl_boolean irplib_property_equal(const cpl_propertylist * self,
01162 const cpl_propertylist * other,
01163 const char * key, cpl_type type,
01164 double fp_tol,
01165 char ** sstring, char ** ostring)
01166 {
01167
01168 cpl_boolean equal;
01169
01170
01171 assert(self != NULL);
01172 assert(other != NULL);
01173 assert(key != NULL);
01174 assert(sstring != NULL);
01175 assert(ostring != NULL);
01176
01177
01178 assert(cpl_propertylist_get_type(other, key) == type);
01179 assert(fp_tol >= 0.0);
01180
01181 if (self == other) return CPL_TRUE;
01182
01183 switch (type) {
01184
01185 case CPL_TYPE_CHAR: {
01186 const char svalue = cpl_propertylist_get_char(self, key);
01187 const char ovalue = cpl_propertylist_get_char(other, key);
01188
01189 equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
01190 if (!equal) {
01191 *sstring = cpl_sprintf("%c", svalue);
01192 *ostring = cpl_sprintf("%c", ovalue);
01193 }
01194 break;
01195 }
01196
01197 case CPL_TYPE_BOOL: {
01198 const int svalue = cpl_propertylist_get_bool(self, key);
01199 const int ovalue = cpl_propertylist_get_bool(other, key);
01200
01201 equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
01202 if (!equal) {
01203 *sstring = cpl_strdup(svalue == 0 ? "F" : "T");
01204 *ostring = cpl_strdup(ovalue == 0 ? "F" : "T");
01205 }
01206 break;
01207 }
01208
01209 case CPL_TYPE_INT: {
01210 const int svalue = cpl_propertylist_get_int(self, key);
01211 const int ovalue = cpl_propertylist_get_int(other, key);
01212
01213 equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
01214 if (!equal) {
01215 *sstring = cpl_sprintf("%d", svalue);
01216 *ostring = cpl_sprintf("%d", ovalue);
01217 }
01218 break;
01219 }
01220
01221 case CPL_TYPE_LONG: {
01222 const long svalue = cpl_propertylist_get_long(self, key);
01223 const long ovalue = cpl_propertylist_get_long(other, key);
01224
01225 equal = svalue == ovalue ? CPL_TRUE : CPL_FALSE;
01226 if (!equal) {
01227 *sstring = cpl_sprintf("%ld", svalue);
01228 *ostring = cpl_sprintf("%ld", ovalue);
01229 }
01230 break;
01231 }
01232
01233 case CPL_TYPE_FLOAT: {
01234 const double svalue = (double)cpl_propertylist_get_float(self, key);
01235 const double ovalue = (double)cpl_propertylist_get_float(other, key);
01236
01237 equal = (fabs(svalue - ovalue) <= fp_tol) ? CPL_TRUE : CPL_FALSE;
01238 if (!equal) {
01239 *sstring = cpl_sprintf("%f", svalue);
01240 *ostring = cpl_sprintf("%f", ovalue);
01241 }
01242 break;
01243 }
01244
01245 case CPL_TYPE_DOUBLE: {
01246 const double svalue = cpl_propertylist_get_double(self, key);
01247 const double ovalue = cpl_propertylist_get_double(other, key);
01248
01249 equal = (fabs(svalue - ovalue) <= fp_tol) ? CPL_TRUE : CPL_FALSE;
01250 if (!equal) {
01251 *sstring = cpl_sprintf("%g", svalue);
01252 *ostring = cpl_sprintf("%g", ovalue);
01253 }
01254 break;
01255 }
01256 case CPL_TYPE_STRING: {
01257 const char * svalue = cpl_propertylist_get_string(self, key);
01258 const char * ovalue = cpl_propertylist_get_string(other, key);
01259
01260 equal = strcmp(svalue, ovalue) == 0 ? CPL_TRUE : CPL_FALSE;
01261 if (!equal) {
01262 *sstring = cpl_strdup(svalue);
01263 *ostring = cpl_strdup(ovalue);
01264 }
01265 break;
01266 }
01267 default:
01268
01269 assert( 0 );
01270
01271 equal = CPL_FALSE;
01272
01273 }
01274
01275 if (!equal) {
01276 assert( *sstring != NULL );
01277 assert( *ostring != NULL );
01278 }
01279
01280 return equal;
01281
01282 }