int main(int argc, char *argv[]) { int i, n, HaveSpace, pos_hsym; int F_Convention, Last_F_Convention; int F_ListTable, F_CIF; int F_XYZ, F_AllXYZ, F_Maple; int F_Space, F_Shelx, F_Schakal; int F_hklList; int F_Standard, F_UnitCell; int F_Verbose, F_Verify, F_ClearError; T_LatticeConstants LatConA, LatConB; char *cp, xtrac; const char *SgName; const T_TabSgName *tsgn; T_SgInfo SpgrInfo[2], BC_SgInfo, *SgInfo; int nSgList, iSgList; T_SgList SgList[2]; T_RTMx *CBMx, *InvCBMx; T_RTMx CCBMx, CInvCBMx; /* Macintosh extras (Courtesy Jon Tischler <*****@*****.**>) */ #ifdef __THINK__ console_options.nrows = CONSOLE_LINES; console_options.ncols = CONSOLE_COLUMNS; console_options.title = "\psgInfo version 1.0.1"; #endif #ifdef __MWERKS__ SIOUXSettings.autocloseonquit = false; SIOUXSettings.asktosaveonclose = true; SIOUXSettings.columns = CONSOLE_COLUMNS; SIOUXSettings.rows = CONSOLE_LINES; #endif #if defined(__THINK__) || defined(__MWERKS__) argc = ccommand(&argv); #endif nSgList = 0; F_Convention = 'A'; Last_F_Convention = 0; F_ListTable = 0; F_CIF = 0; F_XYZ = 0; F_AllXYZ = 0; F_Maple = 0; F_Space = 0; F_Shelx = 0; F_Schakal = 0; F_hklList = 0; F_Standard = 0; F_UnitCell = 0; F_Verbose = 0; F_Verify = 0; F_ClearError = 0; for (i = 1; i < argc; i++) { if (str_icmp(argv[i], "-Hall") == 0) { F_Convention = 'H'; Last_F_Convention = 0; } else if (str_icmp(argv[i], "-VolA") == 0) { F_Convention = 'A'; Last_F_Convention = 'A'; } else if ( str_icmp(argv[i], "-VolI") == 0 || str_icmp(argv[i], "-Vol1") == 0) { F_Convention = 'I'; Last_F_Convention = 'I'; } else if (str_ibegin(argv[i], "-ListTable") == 0) { cp = argv[i] + 10; if (*cp == '\0') F_ListTable = -1; else if (*cp++ == '=') { n = sscanf(cp, "%d%c", &F_ListTable, &xtrac); if (n != 1 || F_ListTable < 1 || F_ListTable > 230) usage(); } else usage(); } else if (str_icmp(argv[i], "-CIF") == 0) F_CIF = 1; else if (str_icmp(argv[i], "-XYZ") == 0) F_XYZ = 1; else if (str_icmp(argv[i], "-AllXYZ") == 0) F_AllXYZ = 1; else if (str_icmp(argv[i], "-Maple") == 0) F_Maple = 1; else if (str_icmp(argv[i], "-Space") == 0) F_Space = 1; else if (str_icmp(argv[i], "-Shelx") == 0) F_Shelx = 1; else if (str_icmp(argv[i], "-Schakal") == 0) F_Schakal = 1; else if (str_icmp(argv[i], "-hklList") == 0) F_hklList = 1; else if (str_icmp(argv[i], "-Standard") == 0) F_Standard = 1; else if (str_ibegin(argv[i], "-UnitCell=") == 0) { F_UnitCell = sscanf(&argv[i][10], "%lf%lf%lf%lf%lf%lf", &LatConA.a, &LatConA.b, &LatConA.c, &LatConA.alpha, &LatConA.beta, &LatConA.gamma); if (F_UnitCell < 1) usage(); if (F_UnitCell > 3) LatConA.alpha *= PIover180; if (F_UnitCell > 4) LatConA.beta *= PIover180; if (F_UnitCell > 5) LatConA.gamma *= PIover180; } else if (str_icmp(argv[i], "-v") == 0) F_Verbose = 1; else if (str_icmp(argv[i], "-Verify") == 0) F_Verify = 1; else if (str_icmp(argv[i], "-ClearError") == 0) F_ClearError = 1; else if (nSgList < 2) { SgName = argv[i]; while (*SgName == ' ' || *SgName == '\t') SgName++; if (F_Convention == 'H' && isdigit(*SgName)) SgList[nSgList].Convention = 'A'; else SgList[nSgList].Convention = F_Convention; SgList[nSgList].SgName = SgName; SgList[nSgList].InpTSgN = NULL; SgList[nSgList].RefTSgN = NULL; nSgList++; } else usage(); } if (F_ListTable) { ListTabSgName(F_ListTable, Last_F_Convention, stdout); PrintClearSgError(1, 0); putc('\n', stdout); } if (F_CIF) { ListCIF(stdout); PrintClearSgError(1, 0); putc('\n', stdout); } if (nSgList == 0) { if (F_ListTable == 0 && F_CIF == 0) usage(); else exit(0); } if (F_Space == 0) { putc('#', stdout); for (i = 0; i < argc; i++) { putc(' ', stdout); HaveSpace = 0; if (i) { for (n = 0; argv[i][n]; n++) { if (isspace(argv[i][n])) { HaveSpace = 1; break; } } } if (HaveSpace == 0) fprintf(stdout, "%s", argv[i]); else { putc('"', stdout); for (n = 0; argv[i][n]; n++) if (argv[i][n] == '"') putc('+', stdout); else putc(argv[i][n], stdout); putc('"', stdout); } } putc('\n', stdout); } BC_SgInfo.MaxList = 0; BC_SgInfo.ListSeitzMx = NULL; BC_SgInfo.ListRotMxInfo = NULL; for (iSgList = 0; iSgList < nSgList; iSgList++) { if (iSgList) putc('\n', stdout); if (nSgList > 1 || F_Standard) fprintf(stdout, "Setting %c:\n\n", "AB"[iSgList]); SgInfo = &SpgrInfo[iSgList]; SgInfo->MaxList = 192; SgInfo->ListSeitzMx = malloc(SgInfo->MaxList * sizeof (*SgInfo->ListSeitzMx)); if (SgInfo->ListSeitzMx == NULL) NotEnoughCore(); #ifndef No_ListRotMxInfo SgInfo->ListRotMxInfo = malloc(SgInfo->MaxList * sizeof (*SgInfo->ListRotMxInfo)); if (SgInfo->ListRotMxInfo == NULL) NotEnoughCore(); #else SgInfo->ListRotMxInfo = NULL; #endif F_Convention = SgList[iSgList].Convention; SgName = SgList[iSgList].SgName; tsgn = NULL; if (F_Convention == 'A' || F_Convention == 'I') { tsgn = FindTabSgNameEntry(SgName, F_Convention); if (tsgn == NULL) { PrintClearSgError(1, 0); progerror("Error: Unknown Space Group Symbol"); } if (F_Space == 0) { fprintf(stdout, "Space Group "); PrintTabSgNameEntry(tsgn, 0, 0, stdout); putc('\n', stdout); } SgName = tsgn->HallSymbol; } SgList[iSgList].InpTSgN = tsgn; InitSgInfo(SgInfo); SgInfo->TabSgName = tsgn; if (tsgn) SgInfo->GenOption = 1; pos_hsym = ParseHallSymbol(SgName, SgInfo); if (SgError != NULL) { fprintf(stdout, " %s\n", SgName); for (i = 0; i < pos_hsym; i++) putc('-', stdout); fprintf(stdout, "---^\n"); fprintf(stdout, "%s\n", SgError); exit(1); } if (CompleteSgInfo(SgInfo) != 0) PrintClearSgError(F_ClearError, 1); if (tsgn == NULL && F_Space == 0) { if (SgInfo->TabSgName) { fprintf(stdout, "Space Group "); PrintTabSgNameEntry(SgInfo->TabSgName, 0, 0, stdout); putc('\n', stdout); } else fprintf(stdout, "Hall Symbol %s\n", SgInfo->HallSymbol); } PrintClearSgError(F_ClearError, 0); #if USE_GS_SI if (Try_GS_si(SgInfo) < 0) #else if (Set_si(SgInfo) < 0) #endif PrintClearSgError(F_ClearError, 1); if (F_Space == 0) { ListSgInfo(SgInfo, F_XYZ, F_Verbose, stdout); PrintClearSgError(F_ClearError, 0); } if (F_AllXYZ) { PutAllXYZ(SgInfo, stdout); PrintClearSgError(F_ClearError, 0); } if (F_Maple) { PutMaple(SgInfo, stdout); PrintClearSgError(F_ClearError, 0); } if (F_Space) { PutSpaceSymFile(SgInfo, stdout); PrintClearSgError(F_ClearError, 0); } if (F_Shelx) { PutShelx(SgInfo, stdout); PrintClearSgError(F_ClearError, 0); } if (F_Schakal) { PutSchakal(SgInfo, stdout); PrintClearSgError(F_ClearError, 0); } if (F_hklList) { Simple_hklList(SgInfo, 4, 4, 4, F_Verbose); PrintClearSgError(F_ClearError, 0); } if (nSgList > 1 || F_Standard) { CBMx = &SgList[iSgList].CBMx; InvCBMx = &SgList[iSgList].InvCBMx; SgList[iSgList].RefTSgN = FindReferenceSpaceGroup(SgInfo, CBMx, InvCBMx); PrintClearSgError(F_ClearError, 0); if (SgList[iSgList].RefTSgN) { if (F_Verbose || F_Verify) { fprintf(stdout, "Change of Basis => Reference Setting "); PrintTabSgNameEntry(SgList[iSgList].RefTSgN, 0, 0, stdout); putc('\n', stdout); ShowCBMx(CBMx, InvCBMx, F_Maple); PrintClearSgError(F_ClearError, 0); } if (F_Verify) { if (BC_SgInfo.MaxList == 0) { BC_SgInfo.MaxList = 192; BC_SgInfo.ListSeitzMx = malloc(BC_SgInfo.MaxList * sizeof (*BC_SgInfo.ListSeitzMx)); if (BC_SgInfo.ListSeitzMx == NULL) NotEnoughCore(); BC_SgInfo.ListRotMxInfo = malloc(BC_SgInfo.MaxList * sizeof (*BC_SgInfo.ListRotMxInfo)); if (BC_SgInfo.ListRotMxInfo == NULL) NotEnoughCore(); } InitSgInfo(&BC_SgInfo); if (TransformSgInfo(SgInfo, CBMx, InvCBMx, &BC_SgInfo) == 0) CompleteSgInfo(&BC_SgInfo); if (SgError) { PrintClearSgError(F_ClearError, 0); SgList[iSgList].RefTSgN = NULL; } else if (BC_SgInfo.TabSgName != SgList[iSgList].RefTSgN) { fprintf(stdout, "Hall Symbol %s\n", BC_SgInfo.HallSymbol); SetSgError("Verify Error: Wrong CBMx/InvCBMx"); PrintClearSgError(F_ClearError, 0); SgList[iSgList].RefTSgN = NULL; } else fprintf(stdout, "Verify O.K.\n\n"); } } tsgn = SgList[iSgList].RefTSgN; if (tsgn && F_Standard && nSgList == 1) { if (Last_F_Convention == 'A' || Last_F_Convention == 'I') SgList[nSgList].Convention = Last_F_Convention; else SgList[nSgList].Convention = 'A'; SgList[nSgList].SgName = SchoenfliesSymbols[tsgn->SgNumber]; SgList[nSgList].InpTSgN = NULL; SgList[nSgList].RefTSgN = NULL; nSgList++; } } } if ( nSgList == 2 && SgList[0].RefTSgN && SgList[1].RefTSgN && SgList[0].RefTSgN->SgNumber == SgList[1].RefTSgN->SgNumber) { putc('\n', stdout); fprintf(stdout, "Change of Basis Setting A -> Setting B:\n"); RTMxMultiply( &CCBMx, &SgList[1].InvCBMx, &SgList[0].CBMx, CRBF, CRBF * CTBF); RTMxMultiply(&CInvCBMx, &SgList[0].InvCBMx, &SgList[1].CBMx, CRBF, CRBF * CTBF); for (i = 0; i < 12; i++) { if ( CCBMx.a[i] % CRBF) break; if (CInvCBMx.a[i] % CRBF) break; CCBMx.a[i] /= CRBF; CInvCBMx.a[i] /= CRBF; } if (i < 12) { SetSgError("Internal Error: Can't combine CBMx's"); PrintClearSgError(1, 1); } else { ShowCBMx(&CCBMx, &CInvCBMx, F_Maple); PrintClearSgError(F_ClearError, 0); if (F_Verify) { InitSgInfo(&BC_SgInfo); if (TransformSgInfo(&SpgrInfo[0], &CCBMx, &CInvCBMx, &BC_SgInfo) == 0) CompleteSgInfo(&BC_SgInfo); if (SgError) PrintClearSgError(F_ClearError, 1); else if (strcmp(SpgrInfo[1].HallSymbol, BC_SgInfo.HallSymbol) != 0) { fprintf(stdout, "Hall Symbol %s\n", SpgrInfo[1].HallSymbol); fprintf(stdout, "Hall Symbol %s\n", BC_SgInfo.HallSymbol); SetSgError("Verify Error: Wrong CBMx/InvCBMx"); PrintClearSgError(F_ClearError, 1); } else fprintf(stdout, "Verify O.K.\n"); } if (F_UnitCell) { putc('\n', stdout); if (TransformLatticeConstants(&LatConA, F_UnitCell, &LatConB, &SpgrInfo[0], CInvCBMx.s.R) != 0) PrintClearSgError(0, 1); fprintf(stdout, "Setting A UnitCell %.6g %.6g %.6g %.6g %.6g %.6g\n", LatConA.a, LatConA.b, LatConA.c, LatConA.alpha / PIover180, LatConA.beta / PIover180, LatConA.gamma / PIover180); fprintf(stdout, "Setting B UnitCell %.6g %.6g %.6g %.6g %.6g %.6g\n", LatConB.a, LatConB.b, LatConB.c, LatConB.alpha / PIover180, LatConB.beta / PIover180, LatConB.gamma / PIover180); } } putc('\n', stdout); } exit(0); /* old VAX didn't like "return 0;" */ return 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]); } }