Jordan Glassman <> writes:
>> Though for some reason you decided not to post the code.
>> Still, your loss...
>>
>
> My loss? Here it is...
Yes. I can now tell you how to get it to work (but
comp.unix.programmer is still the better place).
> #include <stdio.h>
> #include <stdlib.h>
> #include <time.h>
> #include <math.h>
> #include <curses.h>
curses programs can't usually have their put redirected (ask in
c.u.p for when and why).
> #include <unistd.h> // ANSI C???
No, not ANSI C.
<snip>
> void seed(void){
>
> struct tm *mt;
> int i;
> time_t t;
> char timestr[3];
>
> t=time(NULL);
> mt=localtime(&t);
> strftime(timestr,3,"%S",mt);
>
> srand(atoi(timestr));
>
> }
The comp.lang.c FAQ has some advice seeding rand().
http://c-faq.com/lib/srand.html
> void printlattice(int (*m)[N]){
>
> int i,j;
>
> /* system("clear"); */
> move(0,0);
Comment this out. You don't need the curses functionality (at least
not yet). If you do more with it in future versions, it may be worth
the price of losing output re-direction.
> for(i=0;i<N;i++){
> putchar('\n');
> for(j=0;j<N;j++){
> if(m[i][j]==1)printf(" 1");
> else printf(" -1");
> }
> }
>
> putchar('\n');
> }
>
> void ising(int (*m)[N],double beta){
>
> int i,j,k;
> double energy,moment;
> double summe,summm,summe2,summm2;
> int numsteps=0;
> double sum_nn,sums;
> double deltaH;
> double sum_nnn;
> int n2=N*N;
> double half=NITERS/2;
>
> k=0;
>
> energy=moment=0.0;
> summe=summm=summe2=summm2=0.0;
>
> // pick a site randomly
>
> for(i=0;i<N;i++){
> for(j=0;j<N;j++){
> moment += m[i][j];
> energy -= 2*m[i][j]*(m[(i+1)%N][j]+m[i][(j+1)%N]+m[(i+1)%N][(j
> +1)%N]/5);
> }
> }
>
> for(k=0;k<NITERS;k++){
>
> i=rand()%N;
> j=rand()%N;
>
> sum_nn=m[i][((j+1)%N)]+m[i][((j-1+N)%N)]+m[((i+1)%N)][j]+m[((i-1+N)
> %N)][j];
> sum_nnn=(m[((i+1)%N)][((j+1)%N)]+m[((i-1+N)%N)][((j-1+N)%N)]
> +m[((i-1+N)%N)][((j+1)%N)]+m[((i+1)%N)][((j-1+N)%N)])/5;
> sums=sum_nn+sum_nnn;
> deltaH=m[i][j]*sums;
> if((exp(-1.3*deltaH*beta))>((float)rand()/(float)RAND_MAX) ||
> (deltaH < 0) ){
> energy += 2*deltaH;
> moment -= 2*m[i][j];
> m[i][j] *= -1;
> }
>
> if(k>half){
> summe+=energy;
> summe2+=energy*energy;
> summm+=moment;
> summm2+=moment*moment;
> }
>
> /* if(k>10000){
> k=0;
> putchar('\n');
> printf("E=%f m=%f",(energy/n2),(moment/n2));
> printlattice(m);
> sleep(1);
> } */
>
> }
>
> summe /= half;
> summe2 /= half;
> summm /= half;
> summm2 /= half;
>
> printf("B=%4.2f E=%8.4f m=%8.4f Cv=%5.2f Chi=%5.2f\n",beta,(energy/
> n2),(moment/n2),(summe2-summe*summe)/n2,(summm2-summm*summm)/n2);
Add:
fflush(stdout);
to be sure to get what data you have written so far. I did not wait for
the program to finish -- if you do there is no need to call fflush.
--
Ben.