+u32 get_reject_graph(info *my_info,d3_lattice *d3_l,char *file,u32 *graph) {
+ double a,b;
+ int i,j,k;
+ int fd;
+ char buf[32],*p;
+ unsigned char *flag;
+ u32 max;
+
+ max=0;
+ if((fd=open(file,O_RDONLY))<0)
+ {
+ puts("cannot open file to calculate rejection graph");
+ return -1;
+ }
+ if((flag=(unsigned char *)malloc(d3_l->max_z))==NULL)
+ {
+ puts("cannot malloc flag memory for rejection graph");
+ return -1;
+ }
+ memset(flag,0,d3_l->max_z);
+ memset(graph,0,d3_l->max_z*sizeof(u32));
+ /* get fixpoints */
+ k=1;
+ while(k)
+ {
+ for(i=0;i<32;i++)
+ {
+ k=read(fd,&buf[i],1);
+ if((buf[i]=='\n')||(k==0)) break;
+ }
+ if(k)
+ {
+ p=strtok(buf," ");
+ a=atof(p)/10; /* nm */
+ p=strtok(NULL," ");
+ b=atof(p);
+ if(a>d3_l->max_z*CELL_LENGTH) k=0;
+ else
+ {
+ graph[(int)(a/CELL_LENGTH)]=(int)(URAND_MAX*b);
+ flag[(int)(a/CELL_LENGTH)]=1;
+ }
+ }
+ }
+ /* do (linear) interpolation here! */
+ i=0;
+ a=0;
+ while(i<d3_l->max_z)
+ {
+ /* graph[0] is 0! */
+ j=i;
+ i++;
+ while(flag[i]==0&&i<d3_l->max_z) i++;
+ for(k=j+1;k<i;k++) graph[k]=(int)((k-j)*((int)graph[i]-(int)graph[j])/(i-j))+graph[j];
+ if(graph[i]>max) max=graph[i];
+ }
+
+ free(flag);
+
+ // printf("debug: (interpolated c profile)\n");
+ // for(i=0;i<d3_l->max_z;i++) printf("%d %d\n",i,graph[i]);
+
+ return max;
+}
+