Skip to content

Commit

Permalink
v0.1.0-ish
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarbary committed May 12, 2014
1 parent 486ff95 commit c50bd15
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 83 deletions.
37 changes: 19 additions & 18 deletions src/deblend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 17 additions & 19 deletions src/extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 */
Expand All @@ -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);
Expand Down Expand Up @@ -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; i<objlist2->nobj; 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;
}
}
Expand Down Expand Up @@ -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;
}


Expand Down
10 changes: 5 additions & 5 deletions src/lutz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand Down
17 changes: 3 additions & 14 deletions src/sep.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,16 @@
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#define SEP_VERSION "0.1.0"
#define SEP_DATE "2014-04-25"
#define SEP_DATE "2014-05-11"

/*------------------------- global typedefs ---------------------------------*/

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];
Expand Down
30 changes: 3 additions & 27 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,44 +90,20 @@ 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)
{
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;
Expand Down

0 comments on commit c50bd15

Please sign in to comment.