diff --git a/src/deblend.c b/src/deblend.c index 30afc6a..b635279 100644 --- a/src/deblend.c +++ b/src/deblend.c @@ -60,14 +60,12 @@ int gatherup(objliststruct *, objliststruct *); static objliststruct *objlist=NULL; static short *son=NULL, *ok=NULL; -/******************************** deblend ********************************** -PURPOSE Divide a list of isophotal detections in several parts (deblending). -INPUT input objlist, - output objlist, -OUTPUT RETURN_OK if success, RETURN_ERROR otherwise (memory overflow). -NOTES Even if the object is not deblended, the output objlist threshold is - recomputed if a variable threshold is used. - ***/ +/******************************** deblend ************************************/ +/* +Divide a list of isophotal detections in several parts (deblending). +NOTE: Even if the object is not deblended, the output objlist threshold is + recomputed if a variable threshold is used. +*/ int deblend(objliststruct *objlistin, int l, objliststruct *objlistout, int deblend_nthresh, double deblend_mincont, int minarea) { @@ -122,7 +120,8 @@ int deblend(objliststruct *objlistin, int l, objliststruct *objlistout, /*--------- Build tree (bottom->up) */ if (objlist[k-1].nobj>=NSONMAX) { - status = RETURN_ERROR; + status = SEP_INTERNAL_ERROR; + sprintf(seperrdetail, "Deblending overflow (# sons >= NSONMAX)"); goto exit; } @@ -143,14 +142,16 @@ int deblend(objliststruct *objlistin, int l, objliststruct *objlistout, m = objlist[k].nobj - 1; if (m>=NSONMAX) { - status = RETURN_ERROR; + status = SEP_INTERNAL_ERROR; + sprintf(seperrdetail, + "Deblending overflow (# sons >= NSONMAX)"); goto exit; } if (h>=nbm-1) if (!(son = (short *) realloc(son,xn*NSONMAX*(nbm+=16)*sizeof(short)))) { - status = RETURN_ERROR; + status = MEMORY_ALLOC_ERROR; goto exit; } son[k-1+xn*(i+NSONMAX*(h++))] = (short)m; @@ -283,7 +284,7 @@ int gatherup(objliststruct *objlistin, objliststruct *objlistout) if (!(bmp = (char *)calloc(1, npix*sizeof(char)))) { bmp = NULL; - status = RETURN_ERROR; + status = MEMORY_ALLOC_ERROR; goto exit; } @@ -299,7 +300,7 @@ int gatherup(objliststruct *objlistin, objliststruct *objlistout) bmp[(PLIST(pixt,x)-xs) + (PLIST(pixt,y)-ys)*bmwidth] = '\1'; status = addobjdeep(i, objlistin, objlistout); - if (status == RETURN_ERROR) + if (status != RETURN_OK) goto exit; n[i] = objlistout->nobj - 1; @@ -316,7 +317,7 @@ int gatherup(objliststruct *objlistin, objliststruct *objlistout) if (!(pixelout=(pliststruct *)realloc(objlistout->plist, (objlistout->npix + npix)*plistsize))) { - status = RETURN_ERROR; + status = MEMORY_ALLOC_ERROR; goto exit; } @@ -362,7 +363,7 @@ int gatherup(objliststruct *objlistin, objliststruct *objlistout) objlistout->npix = k; if (!(objlistout->plist = (pliststruct *)realloc(pixelout, objlistout->npix*plistsize))) - status = GATHERUP_MEMORY_ERROR; + status = MEMORY_ALLOC_ERROR; exit: free(bmp); @@ -396,9 +397,9 @@ int belong(int corenb, objliststruct *coreobjlist, } -/******************************** createsubmap ******************************* -PURPOSE Create pixel-index submap for deblending. -OUTPUT RETURN_OK if success, RETURN_ERROR otherwise (memory overflow). +/******************************** createsubmap *******************************/ +/* +Create pixel-index submap for deblending. */ int *createsubmap(objliststruct *objlist, int no, int *subx, int *suby, int *subw, int *subh) diff --git a/src/extract.c b/src/extract.c index 8840945..8f14da4 100644 --- a/src/extract.c +++ b/src/extract.c @@ -147,7 +147,7 @@ int extractobj(PIXTYPE *im, PIXTYPE *var, int w, int h, plistinit(conv, var); if (!(pixel = objlist.plist = malloc(nposize=MEMORY_PIXSTACK*plistsize))) { - status = MEMORY_PIXSTACK_ERROR; + status = MEMORY_ALLOC_ERROR; goto exit; } @@ -264,13 +264,13 @@ int extractobj(PIXTYPE *im, PIXTYPE *var, int w, int h, sprintf(seperrdetail, "Pixel stack overflow at position %d,%d.", xl+1, yl+1); - status = PIXSTACK_OVERFLOW_ERROR; + status = SEP_INTERNAL_ERROR; goto exit; /* NOTE: The above error was originally just a warning. with the change to an error, the following code in this - if block is never executed. TODO: should this just - be a warning (or nothing?) + if block is never executed. + TODO: should this just be a warning (or nothing?) */ /* loop over pixels in row to find largest object */ @@ -290,14 +290,9 @@ int extractobj(PIXTYPE *im, PIXTYPE *var, int w, int h, if (info[j].pixnb>maxpixnb) maxpixnb = (victim = &info[j])->pixnb; - if (!maxpixnb) + if ((!maxpixnb) || (maxpixnb <= 1)) { - status = RETURN_ERROR; - goto exit; - } - if (maxpixnb <= 1) - { - status = PIXSTACK_OVERFLOW_ERROR; + status = SEP_INTERNAL_ERROR; goto exit; } freeinfo.firstpix = PLIST(pixel+victim->firstpix, nextpix); @@ -533,18 +528,21 @@ int sortit(infostruct *info, objliststruct *objlist, int minarea, if (!(obj.flag & OBJ_OVERFLOW)) { - if (deblend(objlist, 0, &objlistout, deblend_nthresh, deblend_mincont, - minarea) == RETURN_OK) - objlist2 = &objlistout; + status = deblend(objlist, 0, &objlistout, deblend_nthresh, + deblend_mincont, minarea); + if (status == RETURN_OK) + { + objlist2 = &objlistout; + } else { + /* formerly, this wasn't a fatal error, so a flag was set for + the object and we continued. I'm leaving the flag-setting here + in case we want to change this to a non-fatal error in the + future, but currently the flag setting is irrelevant. */ objlist2 = objlist; for (i=0; inobj; i++) objlist2->obj[i].flag |= OBJ_DOVERFLOW; - sprintf(seperrdetail, - "Deblending overflow for detection at %.0f,%.0f", - obj.mx+1, obj.my+1); - status = DEBLEND_OVERFLOW_ERROR; goto exit; } } @@ -632,7 +630,7 @@ int addobjdeep(int objnb, objliststruct *objl1, objliststruct *objl2) earlyexit: objl2->nobj--; objl2->npix = fp; - return RETURN_ERROR; + return MEMORY_ALLOC_ERROR; } diff --git a/src/lutz.c b/src/lutz.c index bfbff39..a4e7a19 100644 --- a/src/lutz.c +++ b/src/lutz.c @@ -167,7 +167,7 @@ int lutz(pliststruct *plistin, if (!(obj=objlist->obj=(objstruct *)malloc(nobjm*sizeof(objstruct)))) { - out = RETURN_ERROR; + out = MEMORY_ALLOC_ERROR; plist = NULL; /* To avoid gcc -Wall warnings */ goto exit_lutz; } @@ -177,7 +177,7 @@ int lutz(pliststruct *plistin, if (!(objlist->plist = (pliststruct *)malloc((eny-sty)*(enx-stx)*plistsize))) { - out = RETURN_ERROR; + out = MEMORY_ALLOC_ERROR; plist = NULL; /* To avoid gcc -Wall warnings */ goto exit_lutz; } @@ -293,7 +293,7 @@ int lutz(pliststruct *plistin, realloc(obj, (nobjm+=nobjm/2)* sizeof(objstruct)))) { - out = RETURN_ERROR; + out = MEMORY_ALLOC_ERROR; goto exit_lutz; } lutzsort(&info[co], objlist); @@ -342,7 +342,7 @@ int lutz(pliststruct *plistin, { if (!(objlist->obj= (objstruct *)realloc(obj, objlist->nobj*sizeof(objstruct)))) - out = LUTZ_REALLOC_ERROR; + out = MEMORY_ALLOC_ERROR; } else { @@ -353,7 +353,7 @@ int lutz(pliststruct *plistin, if (cn && out == RETURN_OK) { if (!(objlist->plist=(pliststruct *)realloc(plist,cn))) - out = LUTZ_REALLOC_ERROR; + out = MEMORY_ALLOC_ERROR; } else { diff --git a/src/sep.h b/src/sep.h index 882a46e..83702c1 100644 --- a/src/sep.h +++ b/src/sep.h @@ -41,7 +41,7 @@ *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #define SEP_VERSION "0.1.0" -#define SEP_DATE "2014-04-25" +#define SEP_DATE "2014-05-11" /*------------------------- global typedefs ---------------------------------*/ @@ -49,19 +49,8 @@ typedef float PIXTYPE; /* type of image arrays */ /*-------------------- error codes & messages -------------------------------*/ #define RETURN_OK 0 -#define RETURN_ERROR (-1) /* general unspecified error */ -#define MEMORY_PIXSTACK_ERROR 1 -#define PIXSTACK_OVERFLOW_ERROR 2 -#define MEMORY_CLEAN_ERROR 4 -#define NO_CLEAN_OBJ_ERROR 5 /* Internal Error: no CLEAN object to - remove in subcleanobj()*/ -#define LUTZ_REALLOC_ERROR 6 /* problem with mem. realloc. in lutz() */ -#define GATHERUP_MEMORY_ERROR 7 /* Not enough memory to update pixel list in - gatherup()" */ -#define MEMORY_ALLOC_ERROR 8 /* Could not allocate memory for.. */ -#define DEBLEND_OVERFLOW_ERROR 9 -#define CLEAN_OVERFLOW_ERROR 10 -#define SEP_INTERNAL_ERROR 11 +#define SEP_INTERNAL_ERROR 1 +#define MEMORY_ALLOC_ERROR 2 void seperrmsg(int status, char *errtext); char seperrdetail[512]; diff --git a/src/util.c b/src/util.c index 029eb9f..84f711a 100644 --- a/src/util.c +++ b/src/util.c @@ -90,7 +90,7 @@ float fqmedian(float *ra, int n) error status value. The message may be up to 60 characters long, plus the terminating null character. */ -void sep_errmsg(int status, char *errtext) +void seperrmsg(int status, char *errtext) { errtext[0] = '\0'; switch (status) @@ -98,36 +98,12 @@ void sep_errmsg(int status, char *errtext) case RETURN_OK: strcpy(errtext, "OK - no error"); break; - case RETURN_ERROR: - strcpy(errtext, "unspecified error"); - break; - case MEMORY_PIXSTACK_ERROR: - strcpy(errtext, "memory pixel stack error"); - break; - case PIXSTACK_OVERFLOW_ERROR: - strcpy(errtext, "pixel stack overflow error"); - break; - case MEMORY_CLEAN_ERROR: - strcpy(errtext, "memory clean error"); - break; - case NO_CLEAN_OBJ_ERROR: - strcpy(errtext, "internal error: no object to remove in subcleanobj"); - break; - case LUTZ_REALLOC_ERROR: - strcpy(errtext, "internal error: problem with memory realloc in lutz"); - break; - case GATHERUP_MEMORY_ERROR: - strcpy(errtext, "not enough memory to update pixel list in gatherup"); + case SEP_INTERNAL_ERROR: + strcpy(errtext, "SEP internal error"); break; case MEMORY_ALLOC_ERROR: strcpy(errtext, "memory allocation"); break; - case DEBLEND_OVERFLOW_ERROR: - strcpy(errtext, "deblend overflow"); - break; - case CLEAN_OVERFLOW_ERROR: - strcpy(errtext, "clean overflow"); - break; default: strcpy(errtext, "unknown error status"); break;