Next: distfapart.c- Random particle distribution Up: Appendix B- Computer Code Previous: genpart3d.c- 3-D particle generation


distfarand.c- Random pixel distribution of fly ash

#include <stdio.h>
#include <math.h>

/*###################################################################*/
/* Program distfarand                                                */
/* Purpose: To distribute fly ash phases randomly amongst particles  */
/* Programmer: Dale P. Bentz                                         */
/*                                                                   */
/*###################################################################*/

/* Define phase IDs */
#define FLYASH 25
#define C3A 35
#define CACL2 12
#define ASGID 14
#define CAS2ID 16
#define INERTID 18
#define POZZID 17
#define ANHYDRITE 20
#define SYSSIZE 100

int *seed;
#include "ran1.c"

main()
{
        FILE *infile,*outfile;
        char filein[80],fileout[80];
        int ix,iy,iz,valin,valout;
        float probasg,probcacl2,probsio2;
        float prph,probanh,probcas2,probc3a;
        int nseed;

        printf("Enter random number seed value (<0)\n");
        scanf("%d",&nseed);
        printf("%d\n",nseed);
        seed=(&nseed);

        printf("Enter name of file for input \n");
        scanf("%s",filein);
        printf("%s\n",filein);

        printf("Enter name of file for output \n");
        scanf("%s",fileout);
        printf("%s\n",fileout);

        /* Get user input for phase probabilities (volume fractions) */
        printf("Enter probability for fly ash to be aluminosilicate glass \n");
        scanf("%f",&probasg);
        printf("%f\n",probasg);
        printf("Enter probability for fly ash to be calcium aluminodisilicate \n");
        scanf("%f",&probcas2);
        printf("%f\n",probcas2);
        printf("Enter probability for fly ash to be tricalcium aluminate \n");
        scanf("%f",&probc3a);
        printf("%f\n",probc3a);
        printf("Enter probability for fly ash to be calcium chloride \n");
        scanf("%f",&probcacl2);
        printf("%f\n",probcacl2);
        printf("Enter probability for fly ash to be silica \n");
        scanf("%f",&probsio2);
        printf("%f\n",probsio2);
        printf("Enter probability for fly ash to be anhydrite \n");
        scanf("%f",&probanh);
        printf("%f\n",probanh);

        infile=fopen(filein,"r");
        outfile=fopen(fileout,"w");

        /* Convert to cumulative probabilties */
        /* Order must match that used in for loops below */
        probcacl2+=probasg;
        probsio2+=probcacl2;
        probcas2+=probsio2;
        probanh+=probcas2;
        probc3a+=probanh;
        /* Scan each pixel and convert all fly ash pixels to some */
        /* component phase */
        for(ix=0;ix<SYSSIZE;ix++){
        for(iy=0;iy<SYSSIZE;iy++){
        for(iz=0;iz<SYSSIZE;iz++){

                fscanf(infile,"%d",&valin);
                valout=valin;
                if(valin==FLYASH){
                        valout=INERTID;
                        prph=ran1(seed);
                        if(prph<probasg){
                                valout=ASGID;
                        }
                        else if(prph<probcacl2){
                                valout=CACL2;
                        }
                        else if(prph<probsio2){
                                valout=POZZID;
                        }
                        else if(prph<probcas2){
                                valout=CAS2ID;
                        }
                        else if(prph<probanh){
                                valout=ANHYDRITE;
                        }
                        else if(prph<probc3a){
                                valout=C3A;
                        }
                }

                fprintf(outfile,"%d\n",valout);
        }
        }
        }

        fclose(infile);
        fclose(outfile);
}



Next: distfapart.c- Random particle distribution Up: Appendix B- Computer Code Previous: genpart3d.c.- 3-D particle generation