#include #include #include #include #include #include "../utilities/nrutil.h" void ReadRunParam( char file[], char *OutFile, char *PointFile, char *EdgeFile, int *N, int *D, int *Q, int *cycles, float *Tmin, float *Tmax, float *dT, int *t_updp, float *SWfract, float *th_MIN, float *th_MAX, float *dth, int *NS, int *writeLabels, int *writeClusters) { FILE *in; if( (in = fopen(file,"r")) == NULL) nrerror("ReadRunParam >>> Input file not found\n"); fscanf(in, "%s %s %s", OutFile,PointFile,EdgeFile); fscanf(in, "%d %d %d", N, D, Q); fscanf(in, "%d %f", cycles, SWfract); fscanf(in, "%f %f %f", Tmin, Tmax, dT); fscanf(in, "%d", t_updp); fscanf(in, "%f %f %f", th_MIN,th_MAX,dth); fscanf(in, "%d", NS); fscanf(in, "%d %d", writeLabels, writeClusters); if (*D == 0 && *writeClusters != 0){ fprintf(stderr,"WARNING: writeCluster has set to 0 because D = 0\n"); *writeClusters = 0; } fclose(in); } void ShowParameters( char *OutFile, char *PointFile, char *EdgeFile, int N, int D, int Q, int cyc, float Tmin, float Tmax, float dT, int t_updp, float SWfract, float th_MIN, float th_MAX, float dth, int NS, int writeLabels, int writeClusters) { int nT; printf("Files: %s %s %s\n", PointFile, OutFile, EdgeFile); printf("N: %d D: %d Q: %d\n", N,D,Q); printf("cyc: %d SWfract:%4.2f\n", cyc,SWfract); if (t_updp == 1) nT = (int)( (Tmax-Tmin)/dT + 1.5 ); else if (t_updp == 0) nT = (int)((log(Tmax)-log(Tmin))/log(dT) + 1.5); else nrerror("invalid t_updp value \n"); printf("Tmin: %f Tmax: %f dT: %f --> nT = %d\n",Tmin, Tmax, dT, nT); printf("th_MIN = %f th_MAX = %f dth = %f\n", th_MIN,th_MAX,dth); printf("NS: %d\n", NS); printf("wrClus: %d wrLab: %d\n\n", writeLabels,writeClusters); } /* -------------------------------------------------------------------- */ /* print out the parameters of the present run */ /* -------------------------------------------------------------------- */ void PrintParameters( char *name, int N, int D, int Q, int cyc, float SWfract, float ChD, float Jmed, float nn, float th_MIN, float th_MAX, float Tc) { float T4,Tmf; FILE *out; char file[80]; T4 = exp(-0.50) / (4 * log(1. + sqrt((float) Q))); Tmf = exp(-0.50) * (Q-2) / ( 2.0 * (Q-1.) * log(Q-1.)); strcpy(file,name); strcat(file,".param"); out = fopen(file, "a"); fprintf(out,"\n\n\n# Basic Parameters of this run:\n"); fprintf(out,"# N : %d\n", N); fprintf(out,"# D : %d\n", D); fprintf(out,"# Q : %d\n", Q); fprintf(out,"# th_MIN : %f\n", th_MIN); fprintf(out,"# th_MAX : %f\n", th_MAX); fprintf(out,"# chD : %f\n", ChD); fprintf(out,"# Jmed : %f\n", Jmed); fprintf(out,"# SWfract : %f\n", SWfract); fprintf(out,"# cyc : %d\n\n", cyc); fprintf(out,"# << K >> : %f\n", nn); fprintf(out,"# T0_4 : %f\n", T4); fprintf(out,"# T0_mf : %f\n", Tmf); fprintf(out,"# Tc_J_4 : %f\n", Tc); fprintf(out,"# Tc_J_mf : %f\n\n\n", Tc * Tmf/T4); fclose(out); return; } /* -------------------------------------------------------------------- */ /* The averaged sizes of the SW-clusters are printed out to a file */ /* Es igual a PrintSizes, salvo que el array Size es de distinto tipo */ /* tmbien nb es de != tipo */ /* -------------------------------------------------------------------- */ void PrintAverages(char name[], char ext[], int NS, int nT, float T, float Jmed, float nb, float *Size) { int i; FILE *out; char file[80]; strcpy(file,name); strcat(file,ext); out = fopen(file , "a"); fprintf(out,"%3d ", nT); fprintf(out,"%8.5f ", T); fprintf(out,"%8.5f ", T/Jmed); fprintf(out,"%6.3f ", nb ); for(i = 0; i < NS; i++) fprintf(out, "%6.1f ",Size[i] ); fprintf(out,"\n"); fclose(out); printf("%s: ",ext); printf("%8.5f ", T); printf("%8.3f ", nb ); for(i = 0; i < NS; i++) printf("%5.0f ",Size[i] ); printf("\n"); } /* -------------------------------------------------------------------- */ /* Prints the size and its standard error */ /* -------------------------------------------------------------------- */ void PrintBoth(char name[], char ext[], float T, float Jmed, float *Size1, float *Size2, int NS) { int i; FILE *out; char file[80]; strcpy(file,name); strcat(file,ext); out = fopen(file , "a"); fprintf(out,"%8.5f ", T); fprintf(out,"%8.5f ", T/Jmed); for(i = 0; i < NS; i++) fprintf(out, "%6.1f %6.1f ",Size1[i], sqrt(Size2[i]) ); fprintf(out,"\n"); fclose(out); } /* -------------------------------------------------------------------- */ /* The sizes of the SW-clusters are printed out to a file */ /* -------------------------------------------------------------------- */ void PrintSizes(char name[], char ext[], int NS, int nT, float T, float Jmed, int nc, unsigned short *Size) { int i; FILE *out; char file[80]; strcpy(file,name); strcat(file,ext); out = fopen(file , "a"); fprintf(out,"%3d ", nT); fprintf(out,"%8.5f ", T); fprintf(out,"%8.5f ", T/Jmed); fprintf(out,"%5d ", nc ); for(i = 0; i < NS; i++) fprintf(out, "%5d ",Size[i] ); fprintf(out,"\n"); fclose(out); printf("%s: ",ext); printf("%8.5f ", T); printf("%5d ", nc ); for(i = 0; i < NS; i++) printf("%5d ",Size[i] ); printf("\n"); } /* ---------------------------------------------------------------------- */ /* The classified points belonging to the first NW clusters are written */ /* down */ /* ---------------------------------------------------------------------- */ void WriteClusters( char NameIn[], int N, int D, unsigned short *Block, int NW, char File[], int nT, char thr[]) { char NameOut[80]; char label[3]; char TempNum[3]; char nw; int i,d; float **X; FILE *out, *in; if (NW > 99) { printf("\n WriteClusters >>> WARNING: \n"); printf(" It was assumed NW = 99, while NW = %d\n\n",NW); NW = 99; } for(i = 0; i < 80; i++) NameOut[i] = NULL; in = fopen(NameIn,"r"); if (in == NULL) nrerror("WriteClusters >>> File Not Found"); X = matrix(0,(long)(D-1),0,(long)(N-1)); for (i = 0; i < N; i++) for(d = 0; d < D; d++) fscanf(in,"%f",&X[d][i]); fclose(in); TempNum[0] = '0' + (nT / 10); TempNum[1] = '0' + (nT % 10); TempNum[2] = NULL; for(nw = 0; nw < NW; nw++){ strcpy(NameOut,File); label[0] = '0' + ((nw+1) / 10); label[1] = '0' + ((nw+1) % 10); label[2] = NULL; strcat(NameOut,".c"); strcat(NameOut,label); strcat(NameOut,".T"); strcat(NameOut,TempNum); strcat(NameOut,thr); strcat(NameOut,".class"); out = fopen(NameOut, "w"); for(i = 0; i < N; i++) if(Block[i] == nw){ for(d = 0; d < D; d++) fprintf(out, "%f ", X[d][i]); fprintf(out, "\n"); } fclose(out); } strcpy(NameOut,File); strcat(NameOut,".c__"); strcat(NameOut,".T"); strcat(NameOut,TempNum); strcat(NameOut,thr); strcat(NameOut,".class"); out = fopen(NameOut, "w"); for(i = 0; i < N; i++) if(Block[i] >= nw){ for(d = 0; d < D; d++) fprintf(out, "%f ", X[d][i]); fprintf(out, "\n"); } fclose(out); free_matrix(X,0,(long)(D-1),0,(long)(N-1)); } /* ---------------------------------------------------------------------- */ /* A file with the label of each point is written down. */ /* ---------------------------------------------------------------------- */ void WriteLables( int N, unsigned short *Block, char File[], char extension[], int nT) { char NameOut[80]; char NameIn[80]; char TempNum[3]; int i; FILE *out; for(i = 0; i < 80; i++) NameIn[i] = NameOut[i] = NULL; strcpy(NameOut,File); TempNum[0] = '0' + (nT / 10); TempNum[1] = '0' + (nT % 10); TempNum[2] = NULL; strcat(NameOut,".T"); strcat(NameOut,TempNum); strcat(NameOut,extension); strcat(NameOut,".lab"); out = fopen(NameOut, "w"); for(i = 0; i < N; i++){ fprintf(out, " %4d\n", Block[i]); } fclose(out); } /* MY ADDITION!! */ void WriteLables1( int N, unsigned short *Block, unsigned short *Size, int NW, char File[], char extension[], int nT) { char NameOut[80]; char NameIn[80]; char TempNum[3]; int i; char nw; FILE *out; if (NW > 99) { printf("\n WriteLables1 >>> WARNING: \n"); printf(" It was assumed NW = 99, while NW = %d\n\n",NW); NW = 99; } for(i = 0; i < 80; i++) NameIn[i] = NameOut[i] = NULL; strcpy(NameOut,File); TempNum[0] = '0' + (nT / 10); TempNum[1] = '0' + (nT % 10); TempNum[2] = NULL; strcat(NameOut,".T"); strcat(NameOut,TempNum); strcat(NameOut,extension); strcat(NameOut,".lab"); out = fopen(NameOut, "w"); for(nw = 0; nw < NW; nw++){ fprintf(out, " %5d", Size[nw]); for(i = 0; i < N; i++) if(Block[i] == nw) fprintf(out, " %d", i); fprintf(out, " \n"); } fclose(out); } /* ---------------------------------------------------------------------- */ /* Reads Input data */ /* It is assumed that the data is composed of N D-dimensional input */ /* and their t-dimensional target vectors (t can be zero). */ /* Their are organized in a table of N lines, each one composed by D+t */ /* float numbers. */ /* */ /* input: */ /* - N: number of input vectors */ /* - D: dimensionality of the input vectors */ /* - t: dimensionality of the target value (is trates as dummy) */ /* - file: the data file */ /* output */ /* -X[D][N] */ /* ---------------------------------------------------------------------- */ void ReadData(char file[], int D, int N, float **X) { int i, d; FILE *in; in = fopen(file, "r"); if(in == NULL) nrerror("ReadData >>> file not found (r)"); for (i = 0; i < N; i++) for(d = 0; d < D; d++) fscanf(in,"%f",&X[d][i]); fclose(in); } /* -------------------------------------------------------------------- */ /* The magnetization and the calculated susceptibilities are printed */ /* to a file */ /* -------------------------------------------------------------------- */ void PrintMagnet(char name[], int nT, float T, float Jmed, float M, float xi[2]) { int i; FILE *out; char file[80]; strcpy(file,name); strcat(file,".mag"); out = fopen(file, "a"); fprintf(out,"%3d ", nT); fprintf(out,"%8.5f ", T); fprintf(out,"%8.5f ", T/Jmed); fprintf(out,"%8.6f ", M); for(i = 0; i < 2; i++) fprintf(out, "%8.6f ",xi[i] ); fprintf(out,"\n"); fclose(out); } /* -------------------------------------------------------------------- */ /* The magnetization and the calculated susceptibilities are printed */ /* to a file */ /* -------------------------------------------------------------------- */ void PrintMagnet2(char name[], float T, float M1, float M2, float XI_ht) { FILE *out; char file[80]; strcpy(file,name); strcat(file,".mag"); out = fopen(file, "a"); fprintf(out,"%8.5f ", T); fprintf(out,"%8.6f %8.6f",M1,M2); fprintf(out," %8.6f\n",XI_ht); fclose(out); } /* -------------------------------------------------------------------- */ /* The magnetization and the calculated susceptibilities are printed */ /* to a file */ /* -------------------------------------------------------------------- */ void PrintMagnet3(char name[], float T, float M1, float M2, float M_001, float M_002, float M_091, float M_092) { FILE *out; char file[80]; strcpy(file,name); strcat(file,".mag"); out = fopen(file, "a"); fprintf(out,"%8.5f ", T); fprintf(out,"%8.6f %8.6f ",M1,M2); fprintf(out,"%8.6f %8.6f ",M_001,M_002); fprintf(out,"%8.6f %8.6f\n",M_091,M_092); fclose(out); } /* -------------------------------------------------------------------- */ /* The Energy and its variance are printed to a file */ /* -------------------------------------------------------------------- */ void PrintEnergy(char name[], int nT, float T, float Jmed, float Ener[2]) { int i; FILE *out; char file[80]; strcpy(file,name); strcat(file,".ener"); out = fopen(file, "a"); fprintf(out,"%3d ", nT); fprintf(out,"%8.5f ", T); fprintf(out,"%8.5f ", T/Jmed); for(i = 0; i < 2; i++) fprintf(out, "%8.6f ",Ener[i] ); fprintf(out,"\n"); fclose(out); } /* -------------------------------------------------------------------- */ /* The averaged sizes of the SW-clusters (nc1), its variance (nc2) as */ /* well as the average number of frozen bonds (nb1) ant its variance */ /* (nb2) are printed to a file . */ /* -------------------------------------------------------------------- */ void PrintSWaverages(char name[], char ext[], int NS, int nT, float T, int N, float nb1, float nb2, float nc1, float nc2) { FILE *out; char file[80]; strcpy(file,name); strcat(file,ext); out = fopen(file, "a"); fprintf(out,"%3d ", nT); fprintf(out,"%8.5f ", T); fprintf(out,"%6.3f ", nc1); fprintf(out,"%6.3f ", nc2); fprintf(out,"%6.3f ", nb1); fprintf(out,"%6.3f\n" , nb2); fclose(out); return; } /* ----------------------------------------------------------------------- */ /* the two-point correlatoin is printed */ /* ----------------------------------------------------------------------- */ void PrintCorrN(int N, unsigned short **CorrN, unsigned short **NK, int ncy) { int i,j,k; FILE *fp; fp = fopen("correlation.out","w"); for(i = 0; i < N; i++) for(k = 0; (j = NK[i][k]) != USHRT_MAX; k++) fprintf(fp," %f\n", (float)CorrN[i][k] / (float)ncy); fclose(fp); return; }