From 4445feb92cc182029c0039e0363af41f10225863 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 7 Jun 2011 16:10:40 +0200 Subject: Parser for linear combinations of x and y for fs and ss Conflicts: src/detector.c src/peaks.c --- src/detector.c | 234 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 199 insertions(+), 35 deletions(-) (limited to 'src/detector.c') diff --git a/src/detector.c b/src/detector.c index e201c454..4648ff3a 100644 --- a/src/detector.c +++ b/src/detector.c @@ -32,7 +32,7 @@ static int atob(const char *a) return atoi(a); } - +/* No longer used. See dir_conv() static int dir_conv(const char *a, double *sx, double *sy) { if ( strcmp(a, "-x") == 0 ) { @@ -60,9 +60,152 @@ static int dir_conv(const char *a, double *sx, double *sy) return 0; } return 1; +} */ + +/* Not necessary!!! I can remove white space earlier */ +/*static void remove_white_space(char * str ) { + int nl, i=0, j=0; + char **bits; + + n1 = assplode(*a, " \t", &bits, ASSPLODE_NONE); + + for(i = 0; i < strlen(bits); i++ ) { + for (ii = 0; ii < strlen(bits[0]); ii++){ + str[j] = bits[i][ii]; + j++; + } + } + +} */ + +static int dir_conv_extract_coeff(const char *a, int *sign, int *axis, double *coeff) +{ + int len; + len = strlen(a); + int index = 1; + char tempstr[len]; + double test=0.0; + int i=0; + + for (i=0;i 2) { + + if (index == 0 ) { + strncpy(tempstr,a,len-2); + } else { + strncpy(tempstr,a+1,len-2); + } + + /*for ( i = 0; i clen_from = NULL; } + p->clen += p->coffset; + } } @@ -421,7 +566,9 @@ static int parse_field_for_panel(struct panel *panel, const char *key, panel->clen = v; panel->clen_from = NULL; } - + + } else if ( strcmp(key, "coffset") == 0) { + panel->coffset = atof(val); } else if ( strcmp(key, "res") == 0 ) { panel->res = atof(val); } else if ( strcmp(key, "peak_sep") == 0 ) { @@ -523,6 +670,7 @@ struct detector *get_detector_geometry(const char *filename) struct detector *det; char *rval; char **bits; + char variable[128]; int i; int reject = 0; int x, y, max_fs, max_ss; @@ -536,6 +684,11 @@ struct detector *get_detector_geometry(const char *filename) return NULL; } + variable[0] = '\0'; + /*for (i=0;i<128;i++){ + variable[i] = 'a'; + } */ + det->n_panels = 0; det->panels = NULL; det->n_bad = 0; @@ -552,6 +705,7 @@ struct detector *get_detector_geometry(const char *filename) det->defaults.cnx = NAN; det->defaults.cny = NAN; det->defaults.clen = -1.0; + det->defaults.coffset = 0.0; det->defaults.res = -1.0; det->defaults.badrow = '-'; det->defaults.no_index = 0; @@ -585,12 +739,23 @@ struct detector *get_detector_geometry(const char *filename) continue; } + + /* remove the blank spaces from the input */ + strcpy(variable,bits[2]); + if (n1 > 3) { + //strcat(bits[2]," "); + for (i=3; in_panels == -1 ) { @@ -743,7 +909,8 @@ out: double d; p = &det->panels[i]; - + //printf("p->fsx*p->ssy %g ; p->fsx %g; p->ssy %g ;\n",p->fsx*p->ssy,p->fsx,p->ssy ); + //printf("p->fsy*p->ssx %g ; p->fsy %g; p->ssx %g ;\n",p->fsy*p->ssx,p->fsy,p->ssx ); if ( p->fsx*p->ssy == p->ssx*p->fsy ) { ERROR("Panel %i transformation singular.\n", i); reject = 1; @@ -995,8 +1162,7 @@ int write_detector_geometry(const char *filename, struct detector *det) for ( pi=0; pin_panels; pi++) { - char coord; - char sign; + char signx,signy; p = &(det->panels[pi]); @@ -1013,38 +1179,36 @@ int write_detector_geometry(const char *filename, struct detector *det) /* FIXME: The following is sketchy, but it will work for now. * We need to generalise the parser in detector.c */ - if ( p->fsx != 0 ) { - if ( p->fsx > 0 ) { - sign='+'; - } else { - sign='-'; - } - coord = 'x'; + + if ( p->fsx >= 0 ) { + signx='+'; } else { - if ( p->fsy > 0 ) { - sign='+'; - } else { - sign='-'; - } - coord = 'y'; + signx=' '; } - fprintf(fh, "%s/fs = %C%C\n", p->name, sign, coord); - if (p->ssx != 0){ - if ( p->ssx > 0 ) { - sign='+'; - } else { - sign='-'; - } - coord = 'x'; + + + if ( p->fsy >= 0 ) { + signy='+'; } else { - if ( p->ssy > 0 ) { - sign='+'; - } else { - sign='-'; - } - coord = 'y'; + signy=' '; } - fprintf(fh, "%s/ss = %C%C\n", p->name, sign, coord); + + fprintf(fh, "%s/fs = %C%fx%C%fy\n", p->name, signx, p->fsx,signy, p->fsy); + + if ( p->ssx >= 0 ) { + signx='+'; + } else { + signx=' '; + } + + if ( p->ssy >= 0 ) { + signy='+'; + } else { + signy=' '; + } + + fprintf(fh, "%s/ss = %C%fx%C%fy\n", p->name, signx,p->ssx,signy,p->ssy); + fprintf(fh, "%s/corner_x = %g\n", p->name, p->cnx); fprintf(fh, "%s/corner_y = %g\n", p->name, p->cny); fprintf(fh, "%s/no_index = %d\n", p->name, p->no_index); -- cgit v1.2.3