added trim collision file parser
authorhackbard <hackbard>
Tue, 14 Sep 2004 14:06:01 +0000 (14:06 +0000)
committerhackbard <hackbard>
Tue, 14 Sep 2004 14:06:01 +0000 (14:06 +0000)
.cvsignore
parse_trim_collision.c [new file with mode: 0644]

index 0d8585c..209faf8 100644 (file)
@@ -5,3 +5,5 @@ nlsop.*
 conv_fg_tif
 Makefile
 nlsop-*
 conv_fg_tif
 Makefile
 nlsop-*
+parse_trim_collision
+ft
diff --git a/parse_trim_collision.c b/parse_trim_collision.c
new file mode 100644 (file)
index 0000000..ea59d6b
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * parse srim 2003.26 collision data 
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ * this may just work with srim 2003.26 and 180keV c+ -> si,
+ * not quite sure though! :)
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define MAXION 5000
+#define MAXZ 233
+
+typedef struct s_z {
+       int cell_hits_from_ions;
+       int total_hits;
+       double energy;
+} t_z;
+
+int main(int argc,char **argv) {
+
+       int fd,ion,i,j;
+       int z,skipped;
+       float en;
+       t_z Z[MAXZ];
+       unsigned char hit[MAXZ];
+       char buf[256],*p,value[6],value2[10];
+
+       i=0;
+
+       if(argc!=2) return 0;
+       
+       printf("opening file %s ...\n",argv[1]);
+       if((fd=open(argv[1],O_RDONLY))<0) {
+               printf("unable to open file %s\n",argv[1]);
+               return 0;
+       }
+
+       ion=1;
+       skipped=0;
+       for(i=0;i<MAXZ;i++) {
+               Z[i].cell_hits_from_ions=0;
+               Z[i].total_hits=0;
+               Z[i].energy=0;
+       }
+       memset(hit,0,MAXZ);
+
+       while(1) {
+
+               /* read line */
+               i=0;
+               memset(buf,0,256);
+               while(1) {
+                       j=read(fd,&buf[i],1);
+                       if(j<=0) {
+                               close(fd);
+                               for(i=0;i<MAXZ;i++) 
+                                       printf("%d %d %f %d\n",i*3,Z[i].total_hits,
+                                                               Z[i].energy,
+                                                               Z[i].cell_hits_from_ions);
+                               printf("skipped = %d\n",skipped);
+                               return 1;
+                       }
+                       if(buf[i]=='\n') break;
+                       i++;
+               }
+
+               /* parse line */
+               if((buf[0]=='³')&&(buf[1]!='=')) {
+                       p=strtok(buf,"³");
+                       value[0]=p[0];
+                       value[1]=p[1];
+                       value[2]=p[2];
+                       value[3]=p[3];
+                       value[4]=p[4];
+                       value[5]='\0';
+                       p=strtok(NULL,"³");
+                       value2[0]=p[0];
+                       value2[1]=p[1];
+                       value2[2]='.';
+                       value2[3]=p[3];
+                       value2[4]=p[4];
+                       value2[5]=p[5];
+                       value2[6]=p[6];
+                       value2[7]=p[7];
+                       value2[8]=p[8];
+                       value2[9]='\0';
+                       en=atof(value2);
+                       p=strtok(NULL,"³");
+                       value2[0]=p[0];
+                       value2[1]=p[1];
+                       value2[2]=p[2];
+                       value2[3]=p[3];
+                       value2[4]=p[4];
+                       value2[5]='.';
+                       value2[6]=p[6];
+                       value2[7]=p[7];
+                       value2[8]=p[8];
+                       value2[9]=p[9];
+                       value2[10]='\0';
+                       z=(int)(atof(value2)/30.);
+                       if(z>232) skipped+=1;
+                       else {
+                               Z[z].energy+=en;
+                               Z[z].total_hits+=1;
+                               hit[z]=1;
+                       }
+                       if(ion!=atoi(value)) {
+                               /* new ion */
+                               for(i=0;i<MAXZ;i++) Z[i].cell_hits_from_ions+=hit[i];
+                               memset(hit,0,MAXZ);
+                               ion=atoi(value);
+                       }
+                       // printf("%d %d %f %d\n",z*3,Z[z].total_hits,
+                       //      Z[z].energy,Z[z].cell_hits_from_ions);
+                       // return 0;
+               }
+
+
+       }
+       return 0;
+}