Пример #1
0
readpar()
{
    init_read_par() ;
    readparam( TWMC ) ;
    readparam( USER ) ;
    process_readpar() ;
}
Пример #2
0
readParFile()
{
    init_read_par() ;
    readparam( PART ) ;
    readparam( USER ) ;
    process_readpar() ;
}
Пример #3
0
/* This function returns 1 on success, and 0 on failure
*/
int readParams(char *datFileName) {
	int printFlag = 1;
	char title[128], parStr[128], *str;
	int gCount,i,Nkind;  
	char unitCellFile[64];
	atom *tempCell;

	if (!parOpen(datFileName)) {
		printf("Could not open data input file %s\n",datFileName);
		return 0;
	}
	resetParamFile();
	while(readparam("crystal:",parStr,0)) nGrains++;  
	resetParamFile();
	while(readparam("amorph:",parStr,0)) nGrains++;  
	resetParamFile();
	while(readparam("special:",parStr,0)) nGrains++;  
	printf("Found data for %d grain(s) (crystalline frame work and amorphous)\n",nGrains);
	if (nGrains == 0) return 0;

	grains = (grainBox *)malloc(nGrains*sizeof(grainBox));
	/* Now we will loop through all the grains and lok for the necessary 
	* data for each grain 
	*/
	if (readparam("box:",parStr,1)) {
		sscanf(parStr,"%lf %lf %lf",&(superCell.ax),&(superCell.by),&(superCell.cz));
	}
	else {
		printf("Size of super cell box not defined - exit!\n");
		exit(0);
	} 

	/* reset the input file and advance to the next crystal row */
	resetParamFile();
	/*
	readparam("crystal:",parStr,0);
	grains[0].name = (char *)malloc(NAME_BUF_LEN);
	strcpy(grains[0].name,parStr);
	grains[0].nplanes = 0;
	grains[0].planes = NULL;
	*/
	gCount = -1;
	/* We will look for the following tokens:
	* tilt: tiltx,tilty,tiltz;
	* translation: shiftx shifty shiftz
	* plane: vectX vectY vectZ pointX pointY pointZ
	*/
	while (readNextParam(title,parStr)) {
		// printf("%s\n",parStr);
		/* if we found a new crystal ... */
		if (strncmp(title,"crystal:",8) == 0) {
			gCount++;
			grains[gCount].name = (char *)malloc(NAME_BUF_LEN);
			grains[gCount].amorphFlag = 0;
			grains[gCount].density = 0;
			grains[gCount].rmin = 0;
			grains[gCount].rFactor = 1.0;
			grains[gCount].sphereRadius = 0;
			/* first we want to extract crystal name and file name for
			* unit cell data file from this one line
			*/
			strcpy(grains[gCount].name,parStr);
			str = strnext(parStr," \t");
			if (str != NULL) {
				grains[gCount].name[str-parStr-1]='\0';
				// printf("%s, name: %s\n",parStr,grains[gCount].name);
				//str = strnext(str," \t");
				//if (str != NULL) {
				strcpy(unitCellFile,str);
				if ((str = strchr(unitCellFile,' ')) != NULL)
					*str = '\0';
				if ((str = strchr(unitCellFile,'\t')) != NULL)
					*str = '\0';
			}
			else {
				printf("Error: no unit cell data file specified for crystal %s\n",
					grains[gCount].name);
				return 0;       
			}

			// sscanf(parStr,"%s %s",grains[gCount].name,unitCellFile);
			grains[gCount].nplanes = 0;
			grains[gCount].planes = NULL;
			muls->nCellX = 1;
			muls->nCellY = 1;
			muls->nCellZ = 1;
			muls->ctiltx = 0;
			muls->ctilty = 0;
			muls->ctiltz = 0;

			muls->tds = 0;
			tempCell = readUnitCell(&(grains[gCount].natoms), unitCellFile, muls, 0);
			if (tempCell == NULL) {
				printf("Error reading unit cell data - exit!\n");
				exit(0);
			}

			/*****************************************************
			* Test code
			*
			printf("ax: %g, by: %g, cz: %g\n",muls->ax,muls->by,muls->c);
			for (i=0;i<grains[gCount].natoms;i++) {
			printf("%d: %d (%g,%g,%g)\n",i,tempCell[i].Znum,tempCell[i].x,tempCell[i].y,tempCell[i].z);
			}
			*
			*****************************************************/
			grains[gCount].unitCell = (atom *)malloc(grains[gCount].natoms*sizeof(atom));
			memcpy(grains[gCount].unitCell,tempCell,grains[gCount].natoms*sizeof(atom));

			grains[gCount].alpha = muls->cAlpha;
			grains[gCount].beta  = muls->cBeta;
			grains[gCount].gamma = muls->cGamma;
			grains[gCount].ax = muls->ax;
			grains[gCount].by = muls->by;
			grains[gCount].cz = muls->c;
		}
		/***************************************************
		* amorphous stuff
		*/
		else if (strncmp(title,"amorph:",7) == 0) {
			gCount++;
			grains[gCount].name = (char *)malloc(NAME_BUF_LEN);
			grains[gCount].amorphFlag = AMORPHOUS;
			grains[gCount].density = 0;
			grains[gCount].rmin = 1000;      
			grains[gCount].rFactor = 1.2;
			grains[gCount].sphereRadius = 0;
			/* first we want to extract crystal name and file name for
			* unit cell data file from this one line
			*/
			strcpy(grains[gCount].name,parStr);
			str = strnext(parStr," \t");
			if (str != NULL) {
				grains[gCount].name[str-parStr-1]='\0';
				// printf("%s, name: %s\n",parStr,grains[gCount].name);
				//str = strnext(str," \t");
				//if (str != NULL) {
				strcpy(unitCellFile,str);
				if ((str = strchr(unitCellFile,' ')) != NULL)
					*str = '\0';
				if ((str = strchr(unitCellFile,'\t')) != NULL)
					*str = '\0';
			}
			else {
				printf("Error: no unit cell data file specified for crystal %s\n",
					grains[gCount].name);
				return 0;       
			}

			// sscanf(parStr,"%s %s",grains[gCount].name,unitCellFile);
			grains[gCount].nplanes = 0;
			grains[gCount].planes = NULL;
			muls->nCellX = 1;
			muls->nCellY = 1;
			muls->nCellZ = 1;
			muls->ctiltx = 0;
			muls->ctilty = 0;
			tempCell = readUnitCell(&(grains[gCount].natoms), unitCellFile, muls, 0);
			grains[gCount].unitCell = (atom *)malloc(grains[gCount].natoms * sizeof(atom));
			memcpy(grains[gCount].unitCell, tempCell, grains[gCount].natoms * sizeof(atom));
			grains[gCount].alpha = 0;
			grains[gCount].beta  = 0;
			grains[gCount].gamma = 0;
			grains[gCount].ax = 0;
			grains[gCount].by = 0;
			grains[gCount].cz = 0;
		}
		/***************************************************
		* code for specially distributed amorphous stuff
		*/
		else if (strncmp(title,"special:",8) == 0) {
			gCount++;
			grains[gCount].name = (char *)malloc(NAME_BUF_LEN);
			grains[gCount].amorphFlag = SPECIAL_GRAIN;
			grains[gCount].density = 0;
			grains[gCount].rmin = 1000;      
			grains[gCount].rFactor = 1.2;
			grains[gCount].sphereRadius = 0;
			/* first we want to extract crystal name and file name for
			* unit cell data file from this one line
			*/
			strcpy(grains[gCount].name,parStr);  // name of this grain
			// don't need cfg input file
			grains[gCount].natoms = 0;
			grains[gCount].unitCell = NULL;
			// sscanf(parStr,"%s %s",grains[gCount].name,unitCellFile);
			grains[gCount].nplanes = 0;
			grains[gCount].planes = NULL;
			grains[gCount].alpha = 0;
			grains[gCount].beta  = 0;
			grains[gCount].gamma = 0;
			grains[gCount].ax = 0;
			grains[gCount].by = 0;
			grains[gCount].cz = 0;
		}  // end of "special"
		/* if we found tilt data */
		else if (gCount >= 0) { 
			if (strncmp(title,"tilt:",5) == 0) {
				sscanf(parStr,"%lf %lf %lf",&(grains[gCount].tiltx),
					&(grains[gCount].tilty),&(grains[gCount].tiltz));
				if (strstr(parStr,"degree") != NULL) {
					grains[gCount].tiltx *= PI180;
					grains[gCount].tilty *= PI180;
					grains[gCount].tiltz *= PI180;
				}
			}
			/* assign density */
			else if (strncmp(title,"density:",8) == 0) {
				sscanf(parStr,"%lf",&(grains[gCount].density));
				grains[gCount].rmin = pow(sqrt(15.0/144.0)/grains[gCount].density,1.0/3.0);
			}
			/* assign density factor */
			else if (strncmp(title,"rmin:",5) == 0) {
				sscanf(parStr,"%lf",&(grains[gCount].rmin));
				grains[gCount].density = sqrt(15.0/144)*pow(grains[gCount].rmin,3);
			}
			else if (strncmp(title,"r-factor:",9) == 0) {
				sscanf(parStr,"%lf",&(grains[gCount].rFactor));
			}
			/* if we found shift data */
			else if (strncmp(title,"translation:",12) == 0) {
				sscanf(parStr,"%lf %lf %lf",&(grains[gCount].shiftx),
					&(grains[gCount].shifty),&(grains[gCount].shiftz));    
			}
			else if (strncmp(title,"sphere:",7) == 0) {
				sscanf(parStr,"%lf %lf %lf %lf",&(grains[gCount].sphereRadius),
					&(grains[gCount].sphereX),&(grains[gCount].sphereY),&(grains[gCount].sphereZ));    
			}
			/* if we found a new plane for this crystal */
			else if (strncmp(title,"plane:",6) == 0) {
				grains[gCount].nplanes++;
				grains[gCount].planes = (plane *) realloc(grains[gCount].planes,
					grains[gCount].nplanes*sizeof(plane));
				if (grains[gCount].planes == NULL) {
					printf("Sorry, could not allocate memory for new plane\n");
					return 0;
				}
				sscanf(parStr,"%lf %lf %lf %lf %lf %lf %lf %lf %lf",
					&(grains[gCount].planes[grains[gCount].nplanes-1].pointX), 
					&(grains[gCount].planes[grains[gCount].nplanes-1].pointY), 
					&(grains[gCount].planes[grains[gCount].nplanes-1].pointZ),
					&(grains[gCount].planes[grains[gCount].nplanes-1].vect1X), 
					&(grains[gCount].planes[grains[gCount].nplanes-1].vect1Y), 
					&(grains[gCount].planes[grains[gCount].nplanes-1].vect1Z), 
					&(grains[gCount].planes[grains[gCount].nplanes-1].vect2X), 
					&(grains[gCount].planes[grains[gCount].nplanes-1].vect2Y), 
					&(grains[gCount].planes[grains[gCount].nplanes-1].vect2Z));
				crossProduct(&(grains[gCount].planes[grains[gCount].nplanes-1].vect1X),
					&(grains[gCount].planes[grains[gCount].nplanes-1].vect2X),
					&(grains[gCount].planes[grains[gCount].nplanes-1].normX));
			} /* end of if plane ... */
			else if (strncmp(title,"atom:",5) == 0) {
				grains[gCount].natoms++;
				grains[gCount].unitCell = (atom *)realloc(grains[gCount].unitCell,
					grains[gCount].natoms*sizeof(atom));
				// Now read Znum, r (->z), and count (->y)
				sscanf(parStr,"%d %f %d %f",&(grains[gCount].unitCell[grains[gCount].natoms-1].Znum),
					&(grains[gCount].unitCell[grains[gCount].natoms-1].z),&Nkind,
					&(grains[gCount].unitCell[grains[gCount].natoms-1].y));

				// assign number of atoms directly, if specified in input file
				if (Nkind > 0) grains[gCount].unitCell[grains[gCount].natoms-1].y = (float)Nkind;
				for (i=0;i<muls->atomKinds;i++) 	
					if (muls->Znums[i] == grains[gCount].unitCell[grains[gCount].natoms-1].Znum) break;
				if (i == muls->atomKinds) {
					muls->atomKinds++;
					muls->Znums = (int *) realloc(muls->Znums,muls->atomKinds*sizeof(int));
					muls->Znums[i] = grains[gCount].unitCell[grains[gCount].natoms-1].Znum;
				}
			} /* end of if "atom:" */
		} /* end of if gCount >=0 */
	}
	parClose();
	if (printFlag) showData();
	return 1;
}