From: hackbard Date: Thu, 6 Oct 2005 11:09:40 +0000 (+0000) Subject: improved c-prof/pressure output (bmp and plot) X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=746ec2616b99b7462bd4c7835bea2998213415fd;p=physik%2Fnlsop.git improved c-prof/pressure output (bmp and plot) --- diff --git a/nlsop.c b/nlsop.c index 146c4ee..88818e8 100644 --- a/nlsop.c +++ b/nlsop.c @@ -283,7 +283,7 @@ int calc_pressure(d3_lattice *d3_l,int range) } } } - *(unsigned char *)(d3_l->v_ptr+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)=(unsigned char)(count*255/max); + *((unsigned int *)(d3_l->v_ptr)+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)=(count*500/max); } } } @@ -318,7 +318,6 @@ int write_ac_distr(d3_lattice *d3_l,int ac_distr) char file[32]; int si_count; - si_count=d3_l->max_x*d3_l->max_y*SI_PER_VOLUME; if(ac_distr==1) strcpy(file,"carbon_in_av.plot"); if(ac_distr==2) strcpy(file,"carbon_in_cv.plot"); if(ac_distr==3) strcpy(file,"carbon.plot"); @@ -333,23 +332,43 @@ int write_ac_distr(d3_lattice *d3_l,int ac_distr) for(z=0;zmax_z;z++) { count=0; + si_count=0; for(x=0;xmax_x;x++) { for(y=0;ymax_y;y++) { offset=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; if(ac_distr==1) - if(*(d3_l->status+offset)&AMORPH) count+=*(d3_l->extra+offset); + if(*(d3_l->status+offset)&AMORPH) + { + count+=*(d3_l->extra+offset); + si_count+=1; + } if(ac_distr==2) - if(!(*(d3_l->status+offset)&AMORPH)) count+=*(d3_l->extra+offset); - if(ac_distr==3) count+=*(d3_l->extra+offset); + if(!(*(d3_l->status+offset)&AMORPH)) + { + count+=*(d3_l->extra+offset); + si_count+=1; + } + if(ac_distr==3) + { + count+=*(d3_l->extra+offset); + si_count+=1; + } if(ac_distr==4) if(*(d3_l->status+offset)&AMORPH) count+=1; } } + si_count*=SI_PER_VOLUME; if(ac_distr==4) dprintf(fd,"%d %d\n",z*CELL_LENGTH,count); #ifdef ATPROZ - else dprintf(fd,"%d %f\n",z*CELL_LENGTH,100.0*count/si_count); + else + { + if(si_count) + dprintf(fd,"%d %f\n",z*CELL_LENGTH,100.0*count/(si_count+count)); + else + dprintf(fd,"%d 0\n",z*CELL_LENGTH); + } #else else dprintf(fd,"%d %d\n",z*CELL_LENGTH,count/(d3_l->max_x*d3_l->max_y)); #endif @@ -416,7 +435,7 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max) } if(window==7) { - sprintf(bmpfile,"x-z_a_cdistr_%d.bmp",y); + sprintf(bmpfile,"x-z_pressure_%d.bmp",y); foo=3*d3_l->max_x; size=(foo+(4-foo%4))*d3_l->max_z; height=d3_l->max_z; @@ -424,7 +443,7 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max) } if(window==8) { - sprintf(bmpfile,"y-z_a_cdistr_%d.bmp",x); + sprintf(bmpfile,"y-z_pressure_%d.bmp",x); foo=3*d3_l->max_y; size=(foo+(4-foo%4))*d3_l->max_z; height=d3_l->max_z; @@ -432,7 +451,7 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max) } if(window==9) { - sprintf(bmpfile,"x-y_a_cdistr_%d.bmp",z); + sprintf(bmpfile,"x-y_pressure_%d.bmp",z); foo=3*d3_l->max_x; size=(foo+(4-foo%4))*d3_l->max_y; height=d3_l->max_y; @@ -594,7 +613,8 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max) { sum=*(d3_l->extra+i+y*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y); sum=sum*255/max; - memset(buf,(unsigned char)sum,3); + memset(buf+1,(unsigned char)sum,2); + buf[0]=0xff; if(write(fd,buf,3)<3) { puts("failed writing rgb values to bmp file"); @@ -620,7 +640,8 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max) { sum=*(d3_l->extra+x+i*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y); sum=sum*255/max; - memset(buf,(unsigned char)sum,3); + memset(buf+1,(unsigned char)sum,2); + buf[0]=0xff; if(write(fd,buf,3)<3) { puts("failed writing rgb values to bmp file"); @@ -646,7 +667,8 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max) { sum=*(d3_l->extra+i+(d3_l->max_y-j-1)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y); sum=sum*255/max; - memset(buf,(unsigned char)sum,3); + memset(buf+1,(unsigned char)sum,2); + buf[0]=0xff; if(write(fd,buf,3)<3) { puts("failed writing rgb values to bmp file"); @@ -670,10 +692,15 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max) { for(i=0;imax_x;i++) { - if(*(d3_l->status+i+y*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y)&RED) sum=*(d3_l->extra+i+y*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y); - else sum=0; - sum=sum*255/max; - memset(buf,(unsigned char)sum,3); + sum=*((unsigned int *)(d3_l->v_ptr)+i+y*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y); + buf[0]=0; + if(sum<=255) { + buf[1]=0; + buf[2]=sum; + } else { + buf[1]=(sum-255); + buf[2]=0xff; + } if(write(fd,buf,3)<3) { puts("failed writing rgb values to bmp file"); @@ -697,10 +724,15 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max) { for(i=0;imax_x;i++) { - if(*(d3_l->status+x+i*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y)&RED) sum=*(d3_l->extra+x+i*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y); - else sum=0; - sum=sum*255/max; - memset(buf,(unsigned char)sum,3); + sum=*((unsigned int *)(d3_l->v_ptr)+x+i*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y); + buf[0]=0; + if(sum<=255) { + buf[1]=0; + buf[2]=sum; + } else { + buf[1]=(sum-255); + buf[2]=0xff; + } if(write(fd,buf,3)<3) { puts("failed writing rgb values to bmp file"); @@ -724,10 +756,16 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max) { for(i=0;imax_x;i++) { - if(*(d3_l->status+i+(d3_l->max_y-j-1)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&RED) sum=*(d3_l->extra+i+(d3_l->max_y-j-1)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y); - else sum=0; - sum=sum*255/max; - memset(buf,(unsigned char)sum,3); + sum=*((unsigned int *)(d3_l->v_ptr)+i+(d3_l->max_y-j-1)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y); + buf[0]=0; + if(sum<=255) { + buf[1]=0; + buf[2]=sum; + } else { + buf[1]=(sum-255); + buf[2]=0xff; + } + printf("sum = %d => r: %02x g: %02x b: %02x\n",sum,buf[2],buf[1],buf[0]); if(write(fd,buf,3)<3) { puts("failed writing rgb values to bmp file"); @@ -1500,7 +1538,7 @@ int main(int argc,char **argv) #ifdef USE_DFB_API /* allocating buffer for pressure values */ printf("allocating buffer for preassure values ..."); - if((d3_l.v_ptr=malloc(d3_l.max_x*d3_l.max_y*d3_l.max_z*sizeof(unsigned char)))==NULL) + if((d3_l.v_ptr=malloc(d3_l.max_x*d3_l.max_y*d3_l.max_z*sizeof(unsigned int)))==NULL) { puts("cannot allocate buffer for pressure values"); return -1;