Ejemplo n.º 1
0
void		*ft_realloc(t_zone *all, void *ptr, t_zone *current, size_t size)
{
	int						new_type;
	int						ret;

	if (size < SMALL_N)
		new_type = TINY;
	else if (size < SMALL_M)
		new_type = SMALL;
	else
		new_type = LARGE;
	if (new_type == current->type)
	{
		ret = found_inter(ptr, current);
		if (new_type == TINY)
			ret = ret / SMALL_N;
		else if (new_type == SMALL)
			ret = ret / SMALL_M;
		else
			ret = 0;
		all->total = all->total - current->size[ret] + size;
		current->size[ret] = size;
		return (ptr);
	}
	else
		return (new_zone(all, ptr, current, size));
}
Ejemplo n.º 2
0
static void read_xyz (BINARYIO *bf)
{
    int i, k, n, nk, nz, np, nmax;
    int *indices, *iblank;
    void *xyz;
    VERTEX *verts;

    /* get number of grid blocks */

    if (mblock) {
        bf_getints (bf, 1, &nZones);
        if (nZones < 1 || nZones > 100000) {
            fprintf (stderr, "found %d blocks\n", nZones);
            fprintf (stderr, "file type and/or format is probably incorrect\n");
            bf_close (bf);
            exit (1);
        }
    }
    else
        nZones = 1;
    printf ("reading %d grid blocks\n", nZones);

    /* read indices for grids */

    indices = (int *) malloc (3 * nZones * sizeof(int));
    if (NULL == indices)
        FATAL ("read_xyz", "malloc failed for grid indices");
    bf_getints (bf, 3 * nZones, indices);

    /* create zone structures */

    Zones = new_zone (nZones);
    for (nmax = 0, nz = 0; nz < nZones; nz++) {
        Zones[nz].type = CGNS_ENUMV(Structured);
        for (np = 1, n = 0; n < 3; n++) {
            nk = indices[3 * nz + n];
            Zones[nz].dim[n] = nk;
            np *= nk;
        }
        Zones[nz].vertflags = 7;
        Zones[nz].datatype = is_double ? CGNS_ENUMV(RealDouble) : CGNS_ENUMV(RealSingle);
        Zones[nz].nverts = np;
        Zones[nz].verts = new_vertex (np);
        nk = whole ? (int)Zones[nz].nverts : (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
        if (nmax < nk) nmax = nk;
    }

    free (indices);

    if (is_double)
        xyz = (void *) malloc (3 * nmax * sizeof(double));
    else
        xyz = (void *) malloc (3 * nmax * sizeof(float));
    if (NULL == xyz)
        FATAL ("read_xyz", "malloc failed for coordinate working array");
    if (has_iblank) {
        iblank = (int *) malloc (nmax * sizeof(int));
        if (NULL == iblank)
            FATAL ("read_xyz", "malloc failed for iblank array");
    }
    else
        use_iblank = 0;

    /* read the grid blocks */

    for (nz = 0; nz < nZones; nz++) {
        printf ("reading block %d grid %dx%dx%d ...", nz+1,
            (int)Zones[nz].dim[0], (int)Zones[nz].dim[1],
            (int)Zones[nz].dim[2]);
        fflush (stdout);
        if (whole) {
            np = (int)Zones[nz].nverts;
            nk = 1;
        }
        else {
            np = (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
            nk = (int)Zones[nz].dim[2];
        }
        verts = Zones[nz].verts;
        for (k = 0; k < nk; k++) {
            if (is_double)
                bf_getdoubles (bf, 3 * np, xyz);
            else
                bf_getfloats (bf, 3 * np, xyz);
            if (has_iblank)
                bf_getints (bf, np, iblank);
            if (is_double) {
                for (i = 0, n = 0; n < np; n++, i++)
                    verts[n].x = ((double *)xyz)[i];
                for (n = 0; n < np; n++, i++)
                    verts[n].y = ((double *)xyz)[i];
                for (n = 0; n < np; n++, i++)
                    verts[n].z = ((double *)xyz)[i];
            }
            else {
                for (i = 0, n = 0; n < np; n++, i++)
                    verts[n].x = ((float *)xyz)[i];
                for (n = 0; n < np; n++, i++)
                    verts[n].y = ((float *)xyz)[i];
                for (n = 0; n < np; n++, i++)
                    verts[n].z = ((float *)xyz)[i];
            }
            for (n = 0; n < np; n++, verts++)
                verts->id = use_iblank ? iblank[n] : 1;
        }
        puts (" done");
    }

    free (xyz);
    if (has_iblank) free (iblank);
}