GLYLIB
0.3.0b
|
00001 // Function written by B. Lachele Foley, 2007 00002 #include <mylib.h> 00003 #include <AMBER/amber_coords.h> 00004 /*********************** crdsnaps(const char cstop, const char cscrd) *******************/ 00005 int crdsnaps(const char *cstop,const char *cscrd,int csdot){ 00006 int csa=0,csnat=0,csnsnp=0,csstat=0,cssig=0; 00007 char cstst[501]; 00008 double csEa=0,csEb=0,csEc=0; 00009 FILE *CST,*CSC; 00010 00011 // Probe top file for number of atoms 00012 CST=myfopen(cstop,"r"); 00013 csstat=fscanf(CST,"%s",cstst); 00014 if(csstat!=1) mywhine("Error reading topology file"); 00015 //printf("cstst is >>>%s<<<\n",cstst); 00016 while(csstat==1){ 00017 //printf("\t in loop cstst is >>>%s<<<\n",cstst); 00018 if(strcmp(cstst,"POINTERS")==0){ 00019 csstat=fscanf(CST,"%s",cstst); 00020 //printf("cstst is >>>%s<<<\n",cstst); 00021 if(csstat!=1) mywhine("Error reading topology file"); 00022 csstat=fscanf(CST,"%d",&csnat); 00023 //printf("csnat is >>>%d<<<\n",csnat); 00024 if(csstat!=1) mywhine("Error reading number of atoms in topology file."); 00025 //break; 00026 } 00027 if(strcmp(cstst,"BOX_DIMENSIONS")==0) csnat++; 00028 //if(csnat!=0) break; 00029 csstat=fscanf(CST,"%s",cstst); 00030 } 00031 if(csnat==0) mywhine("Got zero for number of atoms."); 00032 //printf("crdsnaps after CST loop\n"); 00033 fclose(CST); 00034 //printf("crdsnaps after close CST\n"); 00035 // Probe crd file for total number of snapshots 00036 //printf("crdsnaps opening CSC\n"); 00037 CSC=myfopen(cscrd,"r"); 00038 //printf("crdsnaps fgets CSC\n"); 00039 fgets(cstst,201,CSC); 00040 //printf("cstst is >>>%s<<<\n",cstst); 00041 if(cstst==NULL) mywhine("Error reading coordinate file."); 00042 //if(strlen(cstst)==0) mywhine("Error reading coordinate file."); 00043 //printf("cstst about to fscanf \n"); 00044 csstat=fscanf(CSC,"%lf %lf %lf",&csEa,&csEb,&csEc);; 00045 //printf("cstst after fscanf csstat is >>>%d<<<\n",csstat); 00046 // START HERE -- fix this for loop structure 00047 printf(" "); 00048 while(csstat==3){ 00049 csa=1; 00050 while(csa<csnat){ 00051 csstat=fscanf(CSC,"%lf %lf %lf",&csEa,&csEb,&csEc); 00052 //printf("csa is %d; csnat is %d, csstat is %d\n",csa,csnat,csstat); 00053 if(csstat!=3) break; 00054 csa++; 00055 //switch(cssig){ 00056 //case 0: printf("\b-"); 00057 //cssig=1; 00058 //break; 00059 //case 1: printf("\b\\"); 00060 //cssig=2; 00061 //break; 00062 //case 2: printf("\b|"); 00063 //cssig=3; 00064 //break; 00065 //case 3: printf("\b/"); 00066 //cssig=0; 00067 //break; 00068 //default: mywhine("something wrong in cssig in crdsnaps.c"); 00069 //} 00070 } 00071 if(csa==csnat){csnsnp++;} 00072 else if (csa!=1){mywhine("Mismatch between NATOMs in top and crd files.\n\ 00073 \tPerhaps there is a mismatch between BOX info in crd and top."); } 00074 //printf("csa is %d; csnat is %d; csnsnp is %d\n",csa,csnat,csnsnp); 00075 csstat=fscanf(CSC,"%lf %lf %lf",&csEa,&csEb,&csEc); 00076 if((csnsnp%csdot)==0){printf("%d ",csnsnp);} 00077 switch(cssig){ 00078 case 0: printf("\b-"); 00079 cssig=1; 00080 break; 00081 case 1: printf("\b\\"); 00082 cssig=2; 00083 break; 00084 case 2: printf("\b|"); 00085 cssig=3; 00086 break; 00087 case 3: printf("\b/"); 00088 cssig=0; 00089 break; 00090 default: mywhine("something wrong in cssig in crdsnaps.c"); 00091 } 00092 //printf("csstat is %d\n",csstat); 00093 } 00094 printf("\n"); 00095 return csnsnp; 00096 }