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 <math.h>
00037
00038 #include <string.h>
00039 #include <assert.h>
00040
00041 #include <cpl.h>
00042
00043 #include "irplib_utils.h"
00044
00045
00046
00047
00048
00049 #ifndef inline
00050 #define inline
00051 #endif
00052
00053
00054
00055
00056
00057 #if defined HAVE_ISNAN && HAVE_ISNAN != 0
00058 #if !defined isnan && defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 0
00059
00060
00061 int isnan(double);
00062 #endif
00063 #endif
00064
00065
00066
00067
00068
00069 inline static double irplib_data_get_double(const void *, cpl_type, int)
00070 #ifdef CPL_HAVE_GNUC_NONNULL
00071 __attribute__((nonnull))
00072 #endif
00073 ;
00074
00075 inline static void irplib_data_set_double(void *, cpl_type, int, double)
00076 #ifdef CPL_HAVE_GNUC_NONNULL
00077 __attribute__((nonnull))
00078 #endif
00079 ;
00080
00081
00085
00088 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE > CPL_VERSION(4, 8, 0)
00089
00110
00111 cpl_error_code irplib_dfs_save_image(cpl_frameset * allframes,
00112 const cpl_parameterlist * parlist,
00113 const cpl_frameset * usedframes,
00114 const cpl_image * image,
00115 cpl_type_bpp bpp,
00116 const char * recipe,
00117 const char * procat,
00118 const cpl_propertylist * applist,
00119 const char * remregexp,
00120 const char * pipe_id,
00121 const char * filename)
00122 {
00123 cpl_errorstate prestate = cpl_errorstate_get();
00124 cpl_propertylist * prolist = applist ? cpl_propertylist_duplicate(applist)
00125 : cpl_propertylist_new();
00126
00127 cpl_propertylist_append_string(prolist, CPL_DFS_PRO_CATG, procat);
00128
00129 cpl_dfs_save_image(allframes, NULL, parlist, usedframes, NULL, image, bpp,
00130 recipe, prolist, remregexp, pipe_id, filename);
00131
00132 cpl_propertylist_delete(prolist);
00133
00134 cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
00135
00136 return CPL_ERROR_NONE;
00137
00138 }
00139
00140
00157
00158 cpl_error_code
00159 irplib_dfs_save_propertylist(cpl_frameset * allframes,
00160 const cpl_parameterlist * parlist,
00161 const cpl_frameset * usedframes,
00162 const char * recipe,
00163 const char * procat,
00164 const cpl_propertylist * applist,
00165 const char * remregexp,
00166 const char * pipe_id,
00167 const char * filename)
00168 {
00169 cpl_errorstate prestate = cpl_errorstate_get();
00170 cpl_propertylist * prolist = applist ? cpl_propertylist_duplicate(applist)
00171 : cpl_propertylist_new();
00172
00173 cpl_propertylist_append_string(prolist, CPL_DFS_PRO_CATG, procat);
00174
00175 cpl_dfs_save_propertylist(allframes, NULL, parlist, usedframes, NULL,
00176 recipe, prolist, remregexp, pipe_id, filename);
00177
00178 cpl_propertylist_delete(prolist);
00179
00180 cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
00181
00182 return CPL_ERROR_NONE;
00183
00184 }
00185
00186
00205
00206 cpl_error_code irplib_dfs_save_imagelist(cpl_frameset * allframes,
00207 const cpl_parameterlist * parlist,
00208 const cpl_frameset * usedframes,
00209 const cpl_imagelist * imagelist,
00210 cpl_type_bpp bpp,
00211 const char * recipe,
00212 const char * procat,
00213 const cpl_propertylist * applist,
00214 const char * remregexp,
00215 const char * pipe_id,
00216 const char * filename)
00217 {
00218 cpl_errorstate prestate = cpl_errorstate_get();
00219 cpl_propertylist * prolist = applist ? cpl_propertylist_duplicate(applist)
00220 : cpl_propertylist_new();
00221
00222 cpl_propertylist_append_string(prolist, CPL_DFS_PRO_CATG, procat);
00223
00224 cpl_dfs_save_imagelist(allframes, NULL, parlist, usedframes, NULL,
00225 imagelist, bpp, recipe, prolist, remregexp, pipe_id,
00226 filename);
00227
00228 cpl_propertylist_delete(prolist);
00229
00230 cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
00231
00232 return CPL_ERROR_NONE;
00233 }
00234
00235
00253
00254 cpl_error_code irplib_dfs_save_table(cpl_frameset * allframes,
00255 const cpl_parameterlist * parlist,
00256 const cpl_frameset * usedframes,
00257 const cpl_table * table,
00258 const cpl_propertylist * tablelist,
00259 const char * recipe,
00260 const char * procat,
00261 const cpl_propertylist * applist,
00262 const char * remregexp,
00263 const char * pipe_id,
00264 const char * filename)
00265 {
00266
00267 cpl_errorstate prestate = cpl_errorstate_get();
00268 cpl_propertylist * prolist = applist ? cpl_propertylist_duplicate(applist)
00269 : cpl_propertylist_new();
00270
00271 cpl_propertylist_append_string(prolist, CPL_DFS_PRO_CATG, procat);
00272
00273 cpl_dfs_save_table(allframes, NULL, parlist, usedframes, NULL,
00274 table, tablelist, recipe, prolist, remregexp,
00275 pipe_id, filename);
00276
00277 cpl_propertylist_delete(prolist);
00278
00279 cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
00280
00281 return CPL_ERROR_NONE;
00282 }
00283
00284
00285 #endif
00286
00287
00342
00343 cpl_error_code irplib_image_split(const cpl_image * self,
00344 cpl_image * im_low,
00345 cpl_image * im_mid,
00346 cpl_image * im_high,
00347 double th_low,
00348 cpl_boolean isleq_low,
00349 double th_high,
00350 cpl_boolean isgeq_high,
00351 double alt_low,
00352 double alt_high,
00353 cpl_boolean isbad_low,
00354 cpl_boolean isbad_mid,
00355 cpl_boolean isbad_high)
00356 {
00357
00358 const void * selfdata = cpl_image_get_data_const(self);
00359
00360
00361
00362 const cpl_boolean hasbpm
00363 = cpl_image_count_rejected(self) ? CPL_TRUE : CPL_FALSE;
00364 const cpl_binary * selfbpm = hasbpm
00365 ? cpl_mask_get_data_const(cpl_image_get_bpm_const(self)) : NULL;
00366 const cpl_type selftype = cpl_image_get_type(self);
00367 const int nx = cpl_image_get_size_x(self);
00368 const int ny = cpl_image_get_size_y(self);
00369 const int npix = nx * ny;
00370 const cpl_boolean do_low = im_low != NULL;
00371 const cpl_boolean do_mid = im_mid != NULL;
00372 const cpl_boolean do_high = im_high != NULL;
00373 void * lowdata = NULL;
00374 void * middata = NULL;
00375 void * highdata = NULL;
00376 cpl_binary * lowbpm = NULL;
00377 cpl_binary * midbpm = NULL;
00378 cpl_binary * highbpm = NULL;
00379 const cpl_type lowtype
00380 = do_low ? cpl_image_get_type(im_low) : CPL_TYPE_INVALID;
00381 const cpl_type midtype
00382 = do_mid ? cpl_image_get_type(im_mid) : CPL_TYPE_INVALID;
00383 const cpl_type hightype
00384 = do_high ? cpl_image_get_type(im_high) : CPL_TYPE_INVALID;
00385 int i;
00386
00387
00388 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00389 cpl_ensure_code(do_low || do_mid || do_high, CPL_ERROR_NULL_INPUT);
00390 cpl_ensure_code(th_low <= th_high, CPL_ERROR_ILLEGAL_INPUT);
00391
00392 if (do_low) {
00393 cpl_ensure_code(cpl_image_get_size_x(im_low) == nx,
00394 CPL_ERROR_INCOMPATIBLE_INPUT);
00395 cpl_ensure_code(cpl_image_get_size_y(im_low) == ny,
00396 CPL_ERROR_INCOMPATIBLE_INPUT);
00397 lowdata = cpl_image_get_data(im_low);
00398 }
00399
00400 if (do_mid) {
00401 cpl_ensure_code(cpl_image_get_size_x(im_mid) == nx,
00402 CPL_ERROR_INCOMPATIBLE_INPUT);
00403 cpl_ensure_code(cpl_image_get_size_y(im_mid) == ny,
00404 CPL_ERROR_INCOMPATIBLE_INPUT);
00405 middata = cpl_image_get_data(im_mid);
00406 }
00407
00408 if (do_high) {
00409 cpl_ensure_code(cpl_image_get_size_x(im_high) == nx,
00410 CPL_ERROR_INCOMPATIBLE_INPUT);
00411 cpl_ensure_code(cpl_image_get_size_y(im_high) == ny,
00412 CPL_ERROR_INCOMPATIBLE_INPUT);
00413 highdata = cpl_image_get_data(im_high);
00414 }
00415
00416
00417
00418 for (i = 0; i < npix; i++) {
00419 const double value = irplib_data_get_double(selfdata, selftype, i);
00420 cpl_boolean isalt_low = do_low;
00421 cpl_boolean isalt_mid = do_mid;
00422 cpl_boolean isalt_high = do_high;
00423 cpl_boolean setbad_low = do_low;
00424 cpl_boolean setbad_mid = do_mid;
00425 cpl_boolean setbad_high = do_high;
00426 const void * setdata = NULL;
00427 double alt_mid = 0.0;
00428
00429 if (isleq_low ? value <= th_low : value < th_low) {
00430 if (do_low) {
00431 isalt_low = CPL_FALSE;
00432 irplib_data_set_double(lowdata, lowtype, i, value);
00433 setbad_low = hasbpm && selfbpm[i];
00434 setdata = lowdata;
00435 }
00436 alt_mid = alt_low;
00437 } else if (isgeq_high ? value >= th_high : value > th_high) {
00438 if (do_high) {
00439 isalt_high = CPL_FALSE;
00440 irplib_data_set_double(highdata, hightype, i, value);
00441 setbad_high = hasbpm && selfbpm[i];
00442 setdata = highdata;
00443 }
00444 alt_mid = alt_high;
00445 } else if (do_mid) {
00446 isalt_mid = CPL_FALSE;
00447 irplib_data_set_double(middata, midtype, i, value);
00448 setbad_mid = hasbpm && selfbpm[i];
00449 setdata = middata;
00450 }
00451
00452 if (isalt_low && lowdata != setdata) {
00453 irplib_data_set_double(lowdata, lowtype, i, alt_low);
00454 setbad_low = isbad_low;
00455 }
00456 if (isalt_mid && middata != setdata) {
00457 irplib_data_set_double(middata, midtype, i, alt_mid);
00458 setbad_mid = isbad_mid;
00459 }
00460 if (isalt_high && highdata != setdata) {
00461 irplib_data_set_double(highdata, hightype, i, alt_high);
00462 setbad_high = isbad_high;
00463 }
00464
00465 if (setbad_low) {
00466 if (lowbpm == NULL) lowbpm
00467 = cpl_mask_get_data(cpl_image_get_bpm(im_low));
00468 lowbpm[i] = CPL_BINARY_1;
00469 }
00470 if (setbad_mid) {
00471 if (midbpm == NULL) midbpm
00472 = cpl_mask_get_data(cpl_image_get_bpm(im_mid));
00473 midbpm[i] = CPL_BINARY_1;
00474 }
00475 if (setbad_high) {
00476 if (highbpm == NULL) highbpm
00477 = cpl_mask_get_data(cpl_image_get_bpm(im_high));
00478 highbpm[i] = CPL_BINARY_1;
00479 }
00480 }
00481
00482 return CPL_ERROR_NONE;
00483
00484 }
00485
00486
00487
00535
00536
00537 cpl_error_code
00538 irplib_dfs_table_convert(cpl_table * self,
00539 cpl_frameset * allframes,
00540 const cpl_frameset * useframes,
00541 int maxlinelen,
00542 char commentchar,
00543 const char * product_name,
00544 const char * procatg,
00545 const cpl_parameterlist * parlist,
00546 const char * recipe_name,
00547 const cpl_propertylist * mainlist,
00548 const cpl_propertylist * extlist,
00549 const char * remregexp,
00550 const char * instrume,
00551 const char * pipe_id,
00552 cpl_boolean (*table_set_row)
00553 (cpl_table *, const char *, int,
00554 const cpl_frame *,
00555 const cpl_parameterlist *),
00556 cpl_error_code (*table_check)
00557 (cpl_table *,
00558 const cpl_frameset *,
00559 const cpl_parameterlist *))
00560 {
00561
00562 const char * filename;
00563 cpl_propertylist * applist = NULL;
00564 cpl_errorstate prestate = cpl_errorstate_get();
00565 cpl_error_code error;
00566
00567 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00568 cpl_ensure_code(allframes != NULL, CPL_ERROR_NULL_INPUT);
00569 cpl_ensure_code(useframes != NULL, CPL_ERROR_NULL_INPUT);
00570 cpl_ensure_code(procatg != NULL, CPL_ERROR_NULL_INPUT);
00571 cpl_ensure_code(parlist != NULL, CPL_ERROR_NULL_INPUT);
00572 cpl_ensure_code(recipe_name != NULL, CPL_ERROR_NULL_INPUT);
00573 cpl_ensure_code(instrume != NULL, CPL_ERROR_NULL_INPUT);
00574 cpl_ensure_code(pipe_id != NULL, CPL_ERROR_NULL_INPUT);
00575
00576 cpl_ensure_code(!irplib_table_read_from_frameset(self, useframes,
00577 maxlinelen,
00578 commentchar,
00579 parlist,
00580 table_set_row),
00581 cpl_error_get_code());
00582
00583 if (table_check != NULL && (table_check(self, useframes, parlist) ||
00584 !cpl_errorstate_is_equal(prestate))) {
00585 return cpl_error_set_message(cpl_func, cpl_error_get_code(),
00586 "Consistency check of table failed");
00587 }
00588
00589 filename = product_name != NULL
00590 ? product_name : cpl_sprintf("%s" CPL_DFS_FITS, recipe_name);
00591
00592 applist = mainlist == NULL
00593 ? cpl_propertylist_new() : cpl_propertylist_duplicate(mainlist);
00594
00595 error = cpl_propertylist_append_string(applist, "INSTRUME", instrume);
00596
00597 if (!error)
00598 error = irplib_dfs_save_table(allframes, parlist, useframes, self,
00599 extlist, recipe_name, procatg, applist,
00600 remregexp, pipe_id, filename);
00601
00602 cpl_propertylist_delete(applist);
00603 if (filename != product_name) cpl_free((char*)filename);
00604
00605
00606 cpl_ensure_code(!error, error);
00607
00608 return CPL_ERROR_NONE;
00609
00610 }
00611
00612
00613
00614
00663
00664
00665 cpl_error_code
00666 irplib_table_read_from_frameset(cpl_table * self,
00667 const cpl_frameset * useframes,
00668 int maxlinelen,
00669 char commentchar,
00670 const cpl_parameterlist * parlist,
00671 cpl_boolean (*table_set_row)
00672 (cpl_table *, const char *, int,
00673 const cpl_frame *,
00674 const cpl_parameterlist *))
00675 {
00676
00677 const cpl_frame * rawframe;
00678 char * linebuffer = NULL;
00679 FILE * stream = NULL;
00680 int nfiles = 0;
00681 int nrow = cpl_table_get_nrow(self);
00682 int irow = 0;
00683 cpl_errorstate prestate = cpl_errorstate_get();
00684
00685 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00686 cpl_ensure_code(useframes != NULL, CPL_ERROR_NULL_INPUT);
00687 cpl_ensure_code(maxlinelen > 0, CPL_ERROR_ILLEGAL_INPUT);
00688 cpl_ensure_code(parlist != NULL, CPL_ERROR_NULL_INPUT);
00689 cpl_ensure_code(table_set_row != NULL, CPL_ERROR_NULL_INPUT);
00690
00691 linebuffer = cpl_malloc(maxlinelen);
00692
00693 for (rawframe = cpl_frameset_get_first_const(useframes);
00694 rawframe != NULL;
00695 rawframe = cpl_frameset_get_next_const(useframes), nfiles++) {
00696
00697 const char * rawfile = cpl_frame_get_filename(rawframe);
00698 const char * done;
00699 const int irowpre = irow;
00700 int iirow = 0;
00701 int ierror;
00702
00703 if (rawfile == NULL) break;
00704
00705 stream = fopen(rawfile, "r");
00706
00707 if (stream == NULL) {
00708 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00709 cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Could not "
00710 "open %s for reading", rawfile);
00711 #else
00712 cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Could not "
00713 "open file for reading");
00714 #endif
00715 break;
00716 }
00717
00718 for (;(done = fgets(linebuffer, maxlinelen, stream)) != NULL; iirow++) {
00719
00720 if (linebuffer[0] != commentchar) {
00721 cpl_boolean didset;
00722 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00723 const int prerow = irow;
00724 #endif
00725
00726 if (irow == nrow) {
00727 nrow += nrow ? nrow : 1;
00728 if (cpl_table_set_size(self, nrow)) break;
00729 }
00730
00731 didset = table_set_row(self, linebuffer, irow, rawframe,
00732 parlist);
00733 if (didset) irow++;
00734
00735 if (!cpl_errorstate_is_equal(prestate)) {
00736 if (didset)
00737 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00738 cpl_error_set_message(cpl_func, cpl_error_get_code(),
00739 "Failed to set table row %d "
00740 "using line %d from %d. file %s",
00741 1+prerow, iirow+1,
00742 nfiles+1, rawfile);
00743 else
00744 cpl_error_set_message(cpl_func, cpl_error_get_code(),
00745 "Failure with line %d from %d. "
00746 "file %s", iirow+1,
00747 nfiles+1, rawfile);
00748 #else
00749 cpl_error_set_message(cpl_func, cpl_error_get_code(),
00750 "Failed to set table row"
00751 "using catalogue line");
00752 else
00753 cpl_error_set_message(cpl_func, cpl_error_get_code(),
00754 "Failure with catalogue line");
00755 #endif
00756
00757 break;
00758 }
00759 }
00760 }
00761 if (done != NULL) break;
00762
00763 ierror = fclose(stream);
00764 stream = NULL;
00765 if (ierror) break;
00766
00767
00768 if (irow == irowpre)
00769 cpl_msg_warning(cpl_func, "No usable lines in the %d. file: %s",
00770 1+nfiles, rawfile);
00771 }
00772
00773 cpl_free(linebuffer);
00774 if (stream != NULL) fclose(stream);
00775
00776
00777 cpl_ensure_code(rawframe == NULL, cpl_error_get_code());
00778
00779 if (irow == 0) {
00780 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00781 return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
00782 "No usable lines in the %d input "
00783 "frame(s)", nfiles);
00784 #else
00785 return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
00786 "No usable lines in the input frame(s)");
00787 #endif
00788 }
00789
00790
00791 cpl_ensure_code(!cpl_table_set_size(self, irow), cpl_error_get_code());
00792
00793 return CPL_ERROR_NONE;
00794 }
00795
00796
00797
00798
00810
00811 void irplib_reset(void)
00812 {
00813 return;
00814 }
00815
00816
00823
00824 int irplib_compare_tags(
00825 cpl_frame * frame1,
00826 cpl_frame * frame2)
00827 {
00828 char * v1 ;
00829 char * v2 ;
00830
00831
00832 if (frame1==NULL || frame2==NULL) return -1 ;
00833
00834
00835 if ((v1 = (char*)cpl_frame_get_tag(frame1)) == NULL) return -1 ;
00836 if ((v2 = (char*)cpl_frame_get_tag(frame2)) == NULL) return -1 ;
00837
00838
00839 if (strcmp(v1, v2)) return 0 ;
00840 else return 1 ;
00841 }
00842
00843
00859
00860 const char * irplib_frameset_find_file(const cpl_frameset * self,
00861 const char * tag)
00862 {
00863 const cpl_frame * frame = cpl_frameset_find_const(self, tag);
00864
00865
00866 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
00867
00868 if (frame == NULL) return NULL;
00869
00870 if (cpl_frameset_find_const(self, NULL))
00871 cpl_msg_warning(cpl_func,
00872 "Frameset has more than one file with tag: %s",
00873 tag);
00874
00875 return cpl_frame_get_filename(frame);
00876
00877 }
00878
00879
00889
00890 cpl_frame * irplib_frameset_get_first_from_group(
00891 const cpl_frameset * self,
00892 cpl_frame_group group)
00893 {
00894 const cpl_frame * frame;
00895 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
00896
00897 for (frame = cpl_frameset_get_first_const(self); frame != NULL ;
00898 frame = cpl_frameset_get_next_const(self)) {
00899 if (cpl_frame_get_group(frame) == group) break;
00900 }
00901 return (cpl_frame*)frame;
00902 }
00903
00904
00923
00924 cpl_error_code irplib_apertures_find_max_flux(const cpl_apertures * self,
00925 int * ind, int nfind)
00926 {
00927 const int nsize = cpl_apertures_get_size(self);
00928 int ifind;
00929
00930
00931 cpl_ensure_code(nsize > 0, cpl_error_get_code());
00932 cpl_ensure_code(ind, CPL_ERROR_NULL_INPUT);
00933 cpl_ensure_code(nfind > 0, CPL_ERROR_ILLEGAL_INPUT);
00934 cpl_ensure_code(nfind <= nsize, CPL_ERROR_ILLEGAL_INPUT);
00935
00936 for (ifind=0; ifind < nfind; ifind++) {
00937 double maxflux = -1;
00938 int maxind = -1;
00939 int i;
00940 for (i=1; i <= nsize; i++) {
00941 int k;
00942
00943
00944 for (k=0; k < ifind; k++) if (ind[k] == i) break;
00945
00946 if (k == ifind) {
00947
00948 const double flux = cpl_apertures_get_flux(self, i);
00949
00950 if (maxind < 0 || flux > maxflux) {
00951 maxind = i;
00952 maxflux = flux;
00953 }
00954 }
00955 }
00956 ind[ifind] = maxind;
00957 }
00958
00959 return CPL_ERROR_NONE;
00960
00961 }
00962
00963
00967
00968 int irplib_isinf(double value)
00969 {
00970 #if defined HAVE_ISINF && HAVE_ISINF
00971 return isinf(value);
00972 #else
00973 return value != 0 && value == 2 * value;
00974 #endif
00975 }
00976
00977
00981
00982 int irplib_isnan(double value)
00983 {
00984 #if defined HAVE_ISNAN && HAVE_ISNAN
00985 return isnan(value);
00986 #else
00987 return value != value;
00988 #endif
00989 }
00990
00991
00992
00993
01004
01005 void irplib_errorstate_warning(unsigned self, unsigned first, unsigned last)
01006 {
01007
01008 const cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE;
01009 const unsigned newest = is_reverse ? first : last;
01010 const unsigned oldest = is_reverse ? last : first;
01011 const char * revmsg = is_reverse ? " in reverse order" : "";
01012
01013
01014 assert( oldest <= self );
01015 assert( newest >= self );
01016
01017 if (newest == 0) {
01018 cpl_msg_info(cpl_func, "No error(s) to dump");
01019 assert( oldest == 0);
01020 } else {
01021 assert( oldest > 0);
01022 assert( newest >= oldest);
01023 if (self == first) {
01024 if (oldest == 1) {
01025 cpl_msg_warning(cpl_func, "Dumping all %u error(s)%s:", newest,
01026 revmsg);
01027 } else {
01028 cpl_msg_warning(cpl_func, "Dumping the %u most recent error(s) "
01029 "out of a total of %u errors%s:",
01030 newest - oldest + 1, newest, revmsg);
01031 }
01032 cpl_msg_indent_more();
01033 }
01034
01035 cpl_msg_warning(cpl_func, "[%u/%u] '%s' (%u) at %s", self, newest,
01036 cpl_error_get_message(), cpl_error_get_code(),
01037 cpl_error_get_where());
01038
01039 if (self == last) cpl_msg_indent_less();
01040 }
01041 }
01042
01043
01046
01057
01058 inline static
01059 double irplib_data_get_double(const void * self, cpl_type type, int i)
01060 {
01061
01062 double value;
01063
01064
01065 switch (type) {
01066 case CPL_TYPE_FLOAT:
01067 {
01068 const float * pself = (const float*)self;
01069 value = (double)pself[i];
01070 break;
01071 }
01072 case CPL_TYPE_INT:
01073 {
01074 const int * pself = (const int*)self;
01075 value = (double)pself[i];
01076 break;
01077 }
01078 default:
01079 {
01080 const double * pself = (const double*)self;
01081 value = pself[i];
01082 break;
01083 }
01084 }
01085
01086 return value;
01087
01088 }
01089
01090
01091
01102
01103 inline static
01104 void irplib_data_set_double(void * self, cpl_type type, int i, double value)
01105 {
01106
01107 switch (type) {
01108 case CPL_TYPE_FLOAT:
01109 {
01110 float * pself = (float*)self;
01111 pself[i] = (float)value;
01112 break;
01113 }
01114 case CPL_TYPE_INT:
01115 {
01116 int * pself = (int*)self;
01117 pself[i] = (int)value;
01118 break;
01119 }
01120 default:
01121 {
01122 double * pself = (double*)self;
01123 pself[i] = value;
01124 break;
01125 }
01126 }
01127 }