Пример #1
0
void GenericSortNULLVector(ADTErr(*SortFunc)(Vector* _vec))
{
	Vector* vec = NULL; 
	
	SortFunc(vec);
	printf("SortNULLVector..................OK\n");
}
	void RenderSetSorted::AddRenderNodeSolution(RenderNode *nodePtr)
	{
		static bool added = false;
		if(!added)
		{
			PrintConsole::GetReference().AddSolution(L"ED2", "Sorting & Hierarchy", Float3(1.0f, 0.0f, 0.0f), 
				L"RenderSetSorted::AddRenderNodeSolution");
			added = true;
		}

		RenderShape *pShape = (RenderShape *)nodePtr;
		// Empty list
		if (0 == headPtr)
		{
			tailPtr = pShape;
			tailPtr->SetNext(0);
			headPtr = pShape;
		}
		else
		{
			RenderShape *pPrevious = 0;
			RenderShape *pCurrent = (RenderShape *)headPtr;

			// Check if this node is first
			if(!SortFunc(pCurrent, pShape))
			{
				pPrevious = pCurrent;
				pCurrent = (RenderShape *)pCurrent->GetNext();

				// Find where this node goes
				while(pCurrent && !SortFunc(pCurrent, pShape))
				{
					pPrevious = pCurrent;
					pCurrent = (RenderShape *)pCurrent->GetNext();
				}
				pPrevious->SetNext(pShape);
			}
			else
				headPtr = pShape;
			pShape->SetNext(pCurrent);
			if(!pCurrent)
				tailPtr = pShape;
		}
	}
Пример #3
0
void GenericSortEmptyVector(ADTErr(*SortFunc)(Vector* _vec))
{
	Vector* vec = NULL; 
	
	vec = VectorCreate(100, 100);
	
	SortFunc(vec);
	printf("SortEmptyVector..................OK\n");
	
	VectorDestroy(vec);
}
Пример #4
0
void MassiveGenericSortTestWithNegatives(ADTErr(*SortFunc)(Vector* _vec))
{
	int vectorSize, i, j;
	int num1, num2;
	Vector* vec;
	srand(time(NULL));
	
	for(j = 0; j < RUNS; j++)
	{
		
		vectorSize = rand() % MAX_VECTOR_SIZE;

		vec = VectorCreate(vectorSize, 100);
		

		for(i = 0; i < vectorSize; i++)
		{
			i % 2 == 0 ? VectorAdd(vec, rand() % MAX_NUMBER) : VectorAdd(vec, - rand() % MAX_NUMBER);
		}

		SortFunc(vec);

		VectorDelete(vec, &num1);

		for(i = 0; i < vectorSize - 1; i++)
		{
			VectorDelete(vec, &num2);
			if(num2 > num1)
			{
				printf("MassiveSortTestWithNegatives..................FAIL\n");
				VectorDestroy(vec);
				return;
			}
			num1 = num2;
		}

		VectorDestroy(vec);
	}

	printf("MassiveSortTestWithNegatives..................OK\n");
}
Пример #5
0
void SimpleGenericSort(ADTErr(*SortFunc)(Vector* _vec))
{
	Vector* vec; 
	int a;
	
	vec = VectorCreate(100, 100);
	
	VectorAdd(vec, 46);
	VectorAdd(vec, 2);
	VectorAdd(vec, 83);
	VectorAdd(vec, 41);
	VectorAdd(vec, 102);
	VectorAdd(vec, 5);
	VectorAdd(vec, 17);
	VectorAdd(vec, 31);
	VectorAdd(vec, 64);
	VectorAdd(vec, 49);
	VectorAdd(vec, 18);

	/*VectorPrint(vec);*/

	SortFunc(vec);
	
	/*VectorPrint(vec);*/
	
	VectorDelete(vec, &a);
	
	if(a == 102)
	{
		printf("SimpleSort..................OK\n");
	}	
	else
	{
		printf("SimpleSort..................FAIL\n");
	}
	
	VectorDestroy(vec);
}
Пример #6
0
void SimpleGenericSortForSingleMember(ADTErr(*SortFunc)(Vector* _vec))
{
	Vector* vec; 
	int a;
	
	vec = VectorCreate(100, 100);
	
	VectorAdd(vec, 5);

	SortFunc(vec);
	
	VectorDelete(vec, &a);
	
	if(a == 5)
	{
		printf("SimpleSortForSingleMember..................OK\n");
	}	
	else
	{
		printf("SimpleSortForSingleMember..................FAIL\n");
	}
	
	VectorDestroy(vec);
}
Пример #7
0
int main (int argc, char *argv[]){
	if (argc != 2){
		printf("Give a parameter file.\n");
		exit(1);
	}
	int SpaceGrp;
	double LatC[6], wl, Lsd, MaxRingRad;
	char *ParamFN;
    FILE *fileParam;
    ParamFN = argv[1];
    char aline[1000];
    fileParam = fopen(ParamFN,"r");
    char *str, dummy[1000];
    int LowNr;
    while (fgets(aline,1000,fileParam)!=NULL){
        str = "SpaceGroup ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %d", dummy, &SpaceGrp);
            continue;
        }
        str = "LatticeConstant ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf %lf %lf %lf %lf %lf", dummy, &LatC[0],
					&LatC[1], &LatC[2], &LatC[3], &LatC[4], &LatC[5]);
            continue;
        }
        str = "LatticeParameter ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf %lf %lf %lf %lf %lf", dummy, &LatC[0],
					&LatC[1], &LatC[2], &LatC[3], &LatC[4], &LatC[5]);
            continue;
        }
        str = "Wavelength ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf", dummy, &wl);
            continue;
        }
        str = "Lsd ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf", dummy, &Lsd);
            continue;
        }
        str = "MaxRingRad ";
        LowNr = strncmp(aline,str,strlen(str));
        if (LowNr==0){
            sscanf(aline,"%s %lf", dummy, &MaxRingRad);
            continue;
        }
	}
	printf("%f %f %f %d %f %f %f %f %f %f\n",wl,Lsd,MaxRingRad,SpaceGrp,LatC[0],LatC[1],LatC[2],LatC[3],LatC[4],LatC[5]);
	int h, k, l, iList, restriction, M, i, j;
	int Minh, Mink, Minl;
	int CCMx_PL[9], deterCCMx_LP = 0;
	double Epsilon = 0.0001;
	int Families[50000][3];
	T_SgInfo *SgInfo;
	char SgName[200]; 
	int F_Convention='A';
	const T_TabSgName *tsgn; 
	
	printf("Generating hkl's\n");
	if((SgInfo = (T_SgInfo *)malloc(sizeof(T_SgInfo)))==NULL){
		printf("Unable to allocate SgInfo\n");
		printf("Aborting\n");
		exit(1);
	}
	SgInfo->GenOption = 0;
	SgInfo->MaxList   = 192;
	if((SgInfo->ListSeitzMx = (T_RTMx*)malloc(SgInfo->MaxList * sizeof(T_RTMx)))==NULL){
		printf("Unable to allocate (SgInfo.ListSeitzMx\n");
		printf("Aborting\n");
		exit(1);
	}
	SgInfo->ListRotMxInfo = NULL;
	InitSgInfo(SgInfo);
	sprintf(SgName,"%d",SpaceGrp);
	tsgn = FindTabSgNameEntry(SgName, F_Convention);
	if (tsgn == NULL){
		printf("Error: Unknown Space Group Symbol\n");
		printf("Aborting\n");
		exit(1);
	}
	sprintf(SgName,"%s",tsgn->HallSymbol);
	SgInfo->TabSgName = tsgn;
	if (tsgn) SgInfo->GenOption = 1;
	{
		int pos_hsym;
		pos_hsym = ParseHallSymbol(SgName, SgInfo);
		
		if (SgError != NULL) {
			printf("Error: Unknown Space Group Symbol\n");
			printf("Aborting\n");
			exit(1);
		}
	}
	if(CompleteSgInfo(SgInfo)!=0) {
		printf("Error in Complete\n");
		printf("Aborting\n");
		exit(1);
	}
	if (SgInfo->LatticeInfo->Code != 'P')
	{
		deterCCMx_LP = deterRotMx(SgInfo->CCMx_LP);
		InverseRotMx(SgInfo->CCMx_LP, CCMx_PL);
		if (deterCCMx_LP < 1) {
			printf("deterCMM failed.\n");
			return 0;
		}
	}
	int Maxh, Maxk, Maxl;
	int nrFilled=0;
	Maxh = 10;
	Maxk = 10;
	Maxl = 10;
	SetListMin_hkl(SgInfo, Maxk, Maxl, &Minh, &Mink, &Minl);
	printf("Will go from %d to %d in h; %d to %d in k; %d to %d in l.\n",Minh, Maxh, Mink, Maxk, Minl, Maxl);
	for (h = Minh; h <= Maxh; h++){
		for (k = Mink; k <= Maxk; k++){
			for (l = Minl; l <= Maxl; l++){
				if (h==0 && k==0 && l==0){
					continue;
				}
				iList = IsSysAbsent_hkl(SgInfo, h, k, l, &restriction);
				if (SgError != NULL) {
					printf("IsSysAbsent_hkl failed.\n");
					return 0;
				}
				if (iList == 0){
					if ((iList = IsSuppressed_hkl(SgInfo, Minh, Mink, Minl,
						Maxk, Maxl, h, k, l)) != 0) {/* Suppressed reflections */
					} else {
						//printf("New plane.\n");
						T_Eq_hkl Eq_hkl;
						M = BuildEq_hkl(SgInfo, &Eq_hkl, h, k, l);
						if (SgError != NULL){
							return 0;
						}
						for (i=0;i<Eq_hkl.N;i++){
							for (j=-1;j<=1;j+=2){
								//printf("%d %d %d\n",Eq_hkl.h[i]*j,Eq_hkl.k[i]*j,Eq_hkl.l[i]*j);
								Families[nrFilled][0] = Eq_hkl.h[i]*j;
								Families[nrFilled][1] = Eq_hkl.k[i]*j;
								Families[nrFilled][2] = Eq_hkl.l[i]*j;
								nrFilled++;
							}
						}
					}
				}
			}
		}
	}
	int AreDuplicates[50000];
	double **UniquePlanes;
	UniquePlanes = allocMatrix(50000,3);
	for (i=0;i<50000;i++) AreDuplicates[i] = 0;
	int nrPlanes=0;
	for (i=0;i<nrFilled-1;i++){
		if (AreDuplicates[i] == 1){
			continue;
		}
		for (j=i+1;j<nrFilled;j++){
			if (Families[i][0] == Families[j][0] && 
				Families[i][1] == Families[j][1] && 
				Families[i][2] == Families[j][2] &&
				AreDuplicates[j] == 0){
					AreDuplicates[j] = 1;
			}
		}
		UniquePlanes[nrPlanes][0] = (double)Families[i][0];
		UniquePlanes[nrPlanes][1] = (double)Families[i][1];
		UniquePlanes[nrPlanes][2] = (double)Families[i][2];
		nrPlanes++;
	}
	double **hkls;
	hkls = allocMatrix(nrPlanes,12);
	CorrectHKLsLatC(LatC,UniquePlanes,nrPlanes,hkls);
	SortFunc(nrPlanes,11,hkls,3,-1);
	double DsMin = wl/(2*sind((atand(MaxRingRad/Lsd))/2));
	for (i=0;i<nrPlanes;i++){
		if (hkls[i][3] < DsMin){
			nrPlanes = i;
			break;
		}
	}
	int RingNr = 1;
	double DsTemp = hkls[0][3];
	hkls[0][4] = 1;
	hkls[0][8] = asind(wl/(2*(hkls[0][3])));
	hkls[0][9] = hkls[0][8]*2;
	hkls[0][10] = Lsd*tand(hkls[0][9]);
	for (i=1;i<nrPlanes;i++){
		if (fabs(hkls[i][3] - DsTemp) < Epsilon){
			hkls[i][4] = RingNr;
		}else{
			DsTemp = hkls[i][3];
			RingNr++;
			hkls[i][4] = RingNr;
		}
		hkls[i][8] = asind(wl/(2*(hkls[i][3])));
		hkls[i][9] = hkls[i][8]*2;
		hkls[i][10] = Lsd*tand(hkls[i][9]);
	}
	char *fn = "hkls.csv";
	FILE *fp;
	fp = fopen(fn,"w");
	fprintf(fp,"h k l D-spacing RingNr\n");
	for (i=0;i<nrPlanes;i++){
		fprintf(fp,"%.0f %.0f %.0f %f %.0f %f %f %f %f %f %f\n",hkls[i][0],
			hkls[i][1],hkls[i][2],hkls[i][3],hkls[i][4],
			hkls[i][5],hkls[i][6],hkls[i][7],hkls[i][8],
			hkls[i][9],hkls[i][10]);
	}
}
Пример #8
0
static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM)
{
	intlist *a = (intlist*)lParam1;
	intlist *b = (intlist*)lParam2;
	return SortFunc(registeredExtraIcons[a->data[0] - 1], registeredExtraIcons[b->data[0] - 1]);
}