tissue.c
/* Build the entire model, writing slab-by-slab to the output file. */
Build the entire model, writing slab-by-slab to the output file.
Build the entire model writing slab - by - slab to the output file .
long buildmodel (FILE *output, FILE *template, FILE *avlrand, FILE *adprand,
		real delta, material *bgval, material *ctval,
		material *avlval, material *adpval) {
	cplx *kslab, *contrast, *k, *nk, kbg;
	real *rstore, *r, *lr, *nr;
	long npx, i, nx, ny, nz;
	int size[3], nsize[3];
	kbg = wavenum(bgval->c, bgval->a, bgval->c);
	fread (size, sizeof(int), 3, template);
	fread (nsize, sizeof(int), 3, avlrand);
	if (!PTEQ(nsize,size)) {
		fprintf (stderr, "ERROR: alveolar and template sizes do not agree.\n");
		return 0;
	}
	fread (nsize, sizeof(int), 3, adprand);
	if (!PTEQ(nsize,size)) {
		fprintf (stderr, "ERROR: adipose and template sizes do not agree.\n");
		return 0;
	}
	fwrite (size, sizeof(int), 3, output);
	nx = size[0]; ny = size[1]; nz = size[2];
	npx = nx * ny;
	fprintf (stderr, "Grid size is %ld x %ld x %ld.\n", nx, ny, nz);
	rstore = malloc (3 * npx * sizeof(real));
	kslab = malloc (3 * npx * sizeof(cplx));
	contrast = kslab + 2 * npx;
	k = kslab;
	nk = kslab + npx;
	lr = NULL;
	r = rstore;
	nr = rstore + npx;
	modelslab (k, r, template, avlrand, adprand, npx, bgval,
			ctval, avlval, adpval);
	for (i = 1; i < nz; ++i) {
		if (!(i % 10)) fprintf (stderr, "Building model for slab %ld\n", i);
		modelslab (nk, nr, template, avlrand, adprand, npx, bgval,
				ctval, avlval, adpval);
		ctslab (contrast, k, r, lr, nr, kbg, nx, ny, delta);
		fwrite (contrast, sizeof(cplx), npx, output);
		k = kslab + (i % 2) * npx;
		nk = kslab + ((i + 1) % 2) * npx;
		lr = rstore + ((i - 1) % 3) * npx;
		r = rstore + (i % 3) * npx;
		nr = rstore + ((i + 1) % 3) * npx;
	}
	ctslab (contrast, k, r, lr, NULL, kbg, nx, ny, delta);
	fwrite (contrast, sizeof(cplx), npx, output);
	free (kslab);
	free (rstore);
	return npx;
}
long buildmodel ( FILE * output , FILE * template , FILE * avlrand , FILE * adprand , real delta , material * bgval , material * ctval , material * avlval , material * adpval ) { cplx * kslab , * contrast , * k , * nk , kbg ; real * rstore , * r , * lr , * nr ; long npx , i , nx , ny , nz ; int size [ 3 ] , nsize [ 3 ] ; kbg = wavenum ( bgval -> c , bgval -> a , bgval -> c ) ; fread ( size , sizeof ( int ) , 3 , template ) ; fread ( nsize , sizeof ( int ) , 3 , avlrand ) ; if ( ! PTEQ ( nsize , size ) ) { fprintf ( stderr , " \n " ) ; return 0 ; } fread ( nsize , sizeof ( int ) , 3 , adprand ) ; if ( ! PTEQ ( nsize , size ) ) { fprintf ( stderr , " \n " ) ; return 0 ; } fwrite ( size , sizeof ( int ) , 3 , output ) ; nx = size [ 0 ] ; ny = size [ 1 ] ; nz = size [ 2 ] ; npx = nx * ny ; fprintf ( stderr , " \n " , nx , ny , nz ) ; rstore = malloc ( 3 * npx * sizeof ( real ) ) ; kslab = malloc ( 3 * npx * sizeof ( cplx ) ) ; contrast = kslab + 2 * npx ; k = kslab ; nk = kslab + npx ; lr = NULL ; r = rstore ; nr = rstore + npx ; modelslab ( k , r , template , avlrand , adprand , npx , bgval , ctval , avlval , adpval ) ; for ( i = 1 ; i < nz ; ++ i ) { if ( ! ( i % 10 ) ) fprintf ( stderr , " \n " , i ) ; modelslab ( nk , nr , template , avlrand , adprand , npx , bgval , ctval , avlval , adpval ) ; ctslab ( contrast , k , r , lr , nr , kbg , nx , ny , delta ) ; fwrite ( contrast , sizeof ( cplx ) , npx , output ) ; k = kslab + ( i % 2 ) * npx ; nk = kslab + ( ( i + 1 ) % 2 ) * npx ; lr = rstore + ( ( i - 1 ) % 3 ) * npx ; r = rstore + ( i % 3 ) * npx ; nr = rstore + ( ( i + 1 ) % 3 ) * npx ; } ctslab ( contrast , k , r , lr , NULL , kbg , nx , ny , delta ) ; fwrite ( contrast , sizeof ( cplx ) , npx , output ) ; free ( kslab ) ; free ( rstore ) ; return npx ; }
Build the entire model, writing slab-by-slab to the output file.
Build the entire model writing slab - by - slab to the output file .
/* Build the backgroudn wave number. */ /* Read the size of each of the model grids. */ /* Write the size of the model grid to the contrast output. */ /* Allocate the arrays used for storage. */ /* Point to the data stores. */ /* Build the model slab for the first plane. */ /* Read the next slab of the material. */ /* Build and write the contrast for the previously-read slab. */ /* Update the media pointers. */ /* Build and write out the last slab. */