wrapper for c version

Hi,

I wrote a wrapper to call the program from C. Most of the functionality isn't set yet, but it's useful as a work around. It runs it with a ub factor of 5 and sets all the other options to the defaults. You can easily add more functionality yourself:

/* Wrapper interface for the real version */
void HMETIS_PartRecursive (int nvtxs, int nhedges, int *vwgts, int *eptr,
int *eind, int *hewgts, int nparts, int ubfactor,
int *options, int *part, int *edgecut) {
char cmd[100];
char ind[10];
char tline[100];
int i, j;
FILE * fid;

strcpy(cmd, "./hmetis2.0pre1 c.net "); j = 13;
itoa(nparts, ind);
strcat(cmd, ind);

fid = fopen("c.net", "w");

/* number of hyperedges, number of vertices */
fprintf(fid, "%d %d\n", nhedges, nvtxs);

i = 0; j = 0;
while (i <= nhedges) {
j = eptr[i];
while (j < eptr[i+1])
fprintf(fid, "%d ", (eind[j++]+1));
fprintf(fid, "\n");
++i;
}

fclose(fid);

/* Last integer is the ubfactor */
printf("running command %s ...\n", cmd);
system(cmd);

strcpy(cmd, "c.net.part.\0");
itoa(nparts, ind);
strcat(cmd, ind);
fid = fopen(cmd, "r");

i = 0;
printf("reading results from %s ...\n", cmd);
while (!feof(fid)) {
fgets(tline, 100, fid);
if (tline != NULL)
part[i++] = atoi(tline);
}
fclose(fid);

return;

}

/* From Kernighan and Ritchie, pg 62 */
/* reverse: reverse string s in place */
void reverse(char s[])
{
int c, i, j;

for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
}

/* From Kernighan and Ritchie, pg 64 */
void itoa(int n, char s[])
{
int i, sign;

if ((sign = n) < 0) /* record sign */
n = -n; /* make n positive */
i = 0;
do { /* generate digits in reverse order */
s[i++] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}