* [cocci] Bug dans la parseur de coccinelle ?
@ 2026-11-12 10:34 picca
2026-11-12 10:40 ` Julia Lawall
0 siblings, 1 reply; 14+ messages in thread
From: picca @ 2026-11-12 10:34 UTC (permalink / raw)
To: cocci
Bonjour,
J'ai un fichiers qui ne parse pas, je fini avec cette erreur
bad: sprintf(datetime,"Date: %.2s-%.2s-%.2s time: %.2s:%.2s:%.2s",
bad: &INLINE[25],&INLINE[23],&INLINE[21],&INLINE[35],&INLINE[37],
bad: &INLINE[39]);
bad: if (NULL != fgets(INLINE,INLLEN,infile)) {;}
bad: if (NULL != fgets(INLINE,INLLEN,infile)) {;}
bad: sscanf(INLINE,"%8s%f %f %f
%f",dummy_name,&HMIL,&KMIL,&LMIL,&BETAIN);
bad: /*
bad: * First two characters must be spaces and beta shouldn't be zero
for
bad: * for correct beta read from header
bad: */
BAD:!!!!! if((strstr(INLINE, " ") != INLINE+9) || (BETAIN == 0.))
bad: {
bad: BETAIN = 0.;
bad: has_read_beta = false;
bad: }
bad: else
bad: {
bad: has_read_beta = true;
bad: }
bad:
bad: sprintf(DATATITLE,"%.40s",&INLINE[9]);
INLINE et une variable global de type
char INLINE[fix size] defini dans "ana.h".
J'aimerais savoir comment regler ce probleme de parsing ?
Merci
Frederic.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 10:34 [cocci] Bug dans la parseur de coccinelle ? picca
@ 2026-11-12 10:40 ` Julia Lawall
2026-11-12 10:47 ` picca
2026-11-12 14:51 ` picca
0 siblings, 2 replies; 14+ messages in thread
From: Julia Lawall @ 2026-11-12 10:40 UTC (permalink / raw)
To: picca; +Cc: cocci
On Thu, 12 Nov 2026, picca wrote:
> Bonjour,
>
> J'ai un fichiers qui ne parse pas, je fini avec cette erreur
>
> bad: sprintf(datetime,"Date: %.2s-%.2s-%.2s time: %.2s:%.2s:%.2s",
> bad: &INLINE[25],&INLINE[23],&INLINE[21],&INLINE[35],&INLINE[37],
> bad: &INLINE[39]);
> bad: if (NULL != fgets(INLINE,INLLEN,infile)) {;}
> bad: if (NULL != fgets(INLINE,INLLEN,infile)) {;}
> bad: sscanf(INLINE,"%8s%f %f %f %f",dummy_name,&HMIL,&KMIL,&LMIL,&BETAIN);
> bad: /*
> bad: * First two characters must be spaces and beta shouldn't be zero for
> bad: * for correct beta read from header
> bad: */
> BAD:!!!!! if((strstr(INLINE, " ") != INLINE+9) || (BETAIN == 0.))
> bad: {
> bad: BETAIN = 0.;
> bad: has_read_beta = false;
> bad: }
> bad: else
> bad: {
> bad: has_read_beta = true;
> bad: }
> bad:
> bad: sprintf(DATATITLE,"%.40s",&INLINE[9]);
>
>
> INLINE et une variable global de type
>
> char INLINE[fix size] defini dans "ana.h".
>
> J'aimerais savoir comment regler ce probleme de parsing ?
Could you send a complete file that illustrates the problem?
The parser has a lot of heuristics, and some are quite non-local, so it's
hard to see what the problem is from an extract.
Alternatively, if it's easier, could you retry after removing the
following line from standard.h:
#define INLINE inline
That looks problematic, but I'm not sure that that definition should be
applied if there is not another parsing error in your code.
julia
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 10:40 ` Julia Lawall
@ 2026-11-12 10:47 ` picca
2026-11-12 12:12 ` Victor Gambier
2026-11-12 12:36 ` Markus Elfring
2026-11-12 14:51 ` picca
1 sibling, 2 replies; 14+ messages in thread
From: picca @ 2026-11-12 10:47 UTC (permalink / raw)
To: Julia Lawall; +Cc: cocci
[-- Attachment #1: Type: text/plain, Size: 18 bytes --]
here it is
Fred
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ana.h --]
[-- Type: text/x-c; name=ana.h, Size: 14676 bytes --]
#pragma once
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "lsqfit.h"
#include "menu.h"
#include "PGmyplot.h"
/***************************************************************************/
/* global parameters */
/***************************************************************************/
#ifndef ANA
#define ANA
#endif /* ANA */
typedef double MATRIX[3][3];
#define DO3D /* Enable 3D plotting options yes/no */
#define INITFILE "ana_init.mac"
#define RAD 57.29577951
#define XYMINVAL 1e-10 /* Minimum accepted numerical value for spectrum
calculations. A smaller value can cause numerical
problems and is therefore ignored. */
#define MAX_DATA 5000 /* Maximum spectrum size */
#define TITINFLN 200 /* Length of Title and Info buffer for data */
#define MAX_SPECTRUM 5 /* Number of spectra */
#define DATACOLUMNS 25 /* Maximum number of data columns in a data file */
#define INIT 0 /* Flag in function call to denote initialization */
#define CALC 1 /* Flag in function call to denote calculation */
#define DERV 2 /* Flag to denote fitting with derivative calc. */
#define PEAK 3 /* Flag to denote peak integration */
#define GAUSIG2 2.77259/* 4*ln(2): for FWHM in Gaussian profiles */
#define GCONST2 1.06447/* 0.5*sqrt(PI/ln(2)): for peak integration */
#define TH_LENGTH 30 /* Length of titles in theory */
#define S_LENGTH 6 /* Length of short parameter name */
#define MAXPEAK 2 /* Maximum number of peaks in theory */
#define STEPSIZE 0.01 /* Normalizing step size in peak integration */
#define NLEVELING 4 /* # left and right background points to level a
spectrum */
/* ANA char INLINE[INLLEN]; /* Input buffer for general purposes */
ANA char STRING[INLLEN]; /* Another general in/output buffer */
/* data block parameters, to be allocated dynamically */
typedef struct /* spectrum structure */
{
float X[MAX_DATA]; /* x-values of spectrum */
float Y[MAX_DATA]; /* y-values of spectrum */
float E[MAX_DATA]; /* errors in y-values */
int NPNT; /* number of points in spectrum */
float MINY; /* minimum y-value in spectrum */
float MAXY; /* maximum y-value in spectrum */
char TITLE[TITLE_LENGTH+1]; /* title of spectrum */
} DATA_BLOCK ;
ANA DATA_BLOCK *DATA; /* allocated in main file */
/* dummy spectrum used for temporary storage during spectrum manipulation */
ANA float XD[MAX_DATA];
ANA float YD[MAX_DATA];
ANA float ED[MAX_DATA];
/* Parameters for reading files */
ANA int XCOL; /* Column number of x values*/
ANA int YCOL; /* Column number of y values*/
ANA int MCOL; /* Column number of monitor values*/
ANA int ECOL; /* Column number of error values */
ANA float MONITOR_NORM; /* Monitor normalization signal */
ANA int HEADER_LINES; /* Number of header lines in data file */
ANA char DATAFILE[FILENAME_MAX-128];/* Name of data file */
ANA int SOLID_CORR; /* Flag denoting solid-state detector correction */
ANA char YCOLNAME[10]; /* Name of y-column in SUPER file */
ANA char PATHNAME[50]; /* Pathname of SUPER file (needed in case of
automatic subdirectories */
ANA int NAUTOSUB; /* Number of scan files before next
subdirectory is opened for data files */
ANA int SPECTYPE; /* Flag denoting the type of Spec file */
#define ID03 0 /* ID03 geometry */
#define ID32 1 /* ID32 old (2 + 2 vertical) geometry */
#define DUBBLE 2
/* Stored data file parameters */
ANA char FILETYPE[15]; /* The most recently read in file type */
ANA int SCANNR; /* Scan number of data file */
ANA int READSPEC; /* Number of last spectrum read in */
ANA char DATATITLE[TITINFLN]; /* Line with title/comment of most recent data
file */
ANA char DATAINFO[TITINFLN]; /* Line with more info of most recent data
file */
ANA char XCOLNAME[50]; /* Title of x-axis read from data file */
ANA float HMIL; /* Miller index h of last spectrum read in */
ANA float KMIL; /* Miller index k of last spectrum read in */
ANA float LMIL; /* Miller index l of last spectrum read in */
ANA float DELTA; /* Delta angle of most recent scan read in */
ANA float BETAIN; /* Angle of incidence of last spectrum read in */
ANA float ALPHA; /* Rotary-table setting of last spectrum read in */
ANA float GAMMA; /* out-of-plane detector angle gamma */
/* Parameters for theoretical curves */
ANA struct /* Structure defining a theory */
{
char TITLE[TH_LENGTH +1]; /* Name of theory */
int NPAR; /* Number of parameters in theory */
float PAR[MAXPAR]; /* Parameter values */
float ERR[MAXPAR]; /* Errors in parameter values */
float MIN[MAXPAR]; /* Lower bound on parameter values */
float MAX[MAXPAR]; /* Upper bound on parameter values */
char NAME[MAXPAR][TH_LENGTH +1];/* Name of parameters */
char SHORT[MAXPAR][S_LENGTH +1];/* Short name of parameters */
bool FIX[MAXPAR]; /* TRUE if parameter fixed */
int NPEAK; /* Number of peaks in theory */
float PEAKINT[MAXPEAK]; /* Integrated peak intensity */
float PEAKERR[MAXPEAK]; /* Error in integrated peak intensity */
} TH;
/* Pointer to current theory */
ANA void (*F_PTR)(float x, float a[], float *y, float dyda[], int mode);
/* parameters for fitting */
ANA int FITSPEC; /* Spectrum number to be fitted */
ANA int FITOUTSP; /* Output spectrum number of fit */
ANA float WEIGHT[MAX_DATA]; /* Weight of data points */
ANA bool OUTFIT; /* Flag to determine whether fit results go
to file */
ANA FILE *FITFILE; /* Pointer to fit output file */
ANA char FFILENAME[FILENAME_MAX]; /* Name of fit output file */
ANA float CHISQR; /* Normalized chi square value of last fit */
ANA int WEIGHTMODE; /* Flag to denote mode of weighting in a
fit */
/* Numerical integration parameters*/
ANA int OUTINT; /* Flag denoting whether integration output
goes to a file or not */
ANA FILE *INTFILE; /* Pointer to integration output file */
ANA char IFILENAME[FILENAME_MAX]; /* Name of integration output file */
ANA int NBACK; /* # left and right points used for
background, these are not used in
numerical integration */
ANA int AUTO_BACK; /* Flag to denote automatic background
calculation */
ANA float T11,T12,T13; /* Matrix elements for hkl transformation on
output */
ANA float T21,T22,T23;
ANA float T31,T32,T33;
ANA enum { /* Flag denoting the scan type: */
rock, /* rocking (angular) scan */
sprd, /* specular rod (00L) rocking scan */
hkl /* Miller index (hkl) scan */
} SCANTYPE;
ANA float INT_RANGE; /* Numerical integration goes over INT_RANGE
times the FWHM of the fitted peak.
Ignored if 0 */
/* Correction parameters */
ANA float GAMMA_FIX; /* fixed out-of-plane detector angle gamma for SRS */
ANA bool LINEARGAMMA; /* Flag to denote whether gamma circle (on 6-circle
diffractometer) is implemented as linear table */
ANA int SCANSWRITTEN; /* number count of files written to int. file */
ANA int FITSWRITTEN; /* number count of fits written to fit file */
ANA float BEAMCOR; /* Flag to denote beamprofile correction */
ANA float VERSLIT; /* Vertical slit width of incoming beam */
ANA float HORSLIT; /* Horizontal slit width of incoming beam */
ANA float DSLIT; /* Width of in-plane detector slits */
ANA float HORBEAM; /* Horizontal FWHM of beam */
ANA float VERBEAM; /* Vertical FWHM of beam */
ANA float RADIUS; /* Sample radius (round samples) */
ANA float HPOLAR; /* Horizontal polarisation fraction in beam */
ANA float TRANSIN; /* Transmission of incoming beam */
ANA float TRANSOUT; /* Transmission of outgoing beam */
#define LIMIT 40 /* Half of maximum integration area over sample [mm] */
#define STEP_ANA 0.02 /* Area integration step size [mm] */
ANA int CORRECTMODE; /* Flag denoting type of correction factors used: */
#define NOCORRECT 0 /* - no corrections applied */
#define ZAXIS 1 /* - z-axis diffractometer */
#define TWOPTWO 2 /* - (2+2) -type diffractometer */
#define TWOPTHREE 3
#define REFROCK 4 /* - reflectivity rocking scan */
/* And some other parameters */
ANA bool DATARUN; /* Flag to denote auto plotting with extra header */
ANA bool LOOP; /* Flag to denote whether command loop mode in on */
ANA bool SHOWCOUNTER; /* Flag to denote the display of loop counter */
ANA char LOOP1[512]; /* First half of string to be repeated */
ANA char LOOP2[512]; /* Second half of string to be repeated */
ANA int LOOP_INCREMENT; /* Increment in loop counter */
/* Parameters for the lattice energy minimization */
typedef struct {
Rod rod;
Pgplot pg;
} Ana;
/***************************************************************************/
/* function prototypes */
/***************************************************************************/
/* in ana.c */
/* void auto_plot(void); */
/* void clear_data(void); */
/* char *get_init_fname(void); */
/* void initialize(void); */
/* void list_spectrum(Menu *menu); */
/* void plot(void); */
/* void plot_3d(void); */
/* void run_loop(void); */
/* void write_initmac(void); */
/* in correct.c */
void comp_cor(float *lorentz, float *polarization, float *intercept,
float *area, float *transmission);
/* void comp_cor_zaxis(float *lorentz, float *polarization, float *intercept, */
/* float *area, float *transmission); */
/* void comp_cor_refl(float *lorentz, float *polarization, float *intercept, */
/* float *area, float *transmission); */
/* void comp_cor_2p2or3(float *lorentz, float *polarization, float *intercept, */
/* float *area, float *transmission); */
void comp_cor_ridge(float beta_in, float *lorentz, float *polarization,
float *area, float *transmission);
/* float f_beam(float x, float z); */
/* float f_onsample(float x, float y); */
/* float f_detector(float x); */
/* in fit.c */
/* float fcn(float a[]); */
/* void model(double *y, int ipoint, int partial_flag); */
void fit(Ana *ana);
/* void ffit(Rod *rod, float x, float a[], float *y, float dyda[], int ma, */
/* int derivatives); */
/* void guess_fit(int nspec, float *background, float *slope, float *position, */
/* float *height, float *width); */
/* void guess_fit2(int nspec, float *bgr, float *ebgr, float *pos, float *epos, */
/* float *hgt, float *ehgt, float *wdt, float *ewdt); */
/* int set_anafitpar(void); */
/* in operate.c */
/* void add(void); */
/* void append(void); */
/* void auto_merge(void); */
/* void center(void); */
/* void cutoff(void); */
/* int delete_points(void); */
/* void despike(void); */
/* void differentiate(void); */
/* void divide(void); */
/* void fit_subtract(void); */
/* void integrate(void); */
/* void level(void); */
/* void lump(void); */
/* void merge(void); */
/* void multiply(void); */
void operate(Ana *ana);
/* void ref_integrate(void); */
/* void ref_to_f(void); */
/* void scale(void); */
/* void shift(void); */
/* void split(void); */
/* void sum(void); */
/* void wrap(void); */
/* void ylog10(void); */
/* in read.c */
/* void read_column(void); */
/* void read_ftascom(void); */
/* void read_spec(void); */
/* void read_srs(int version); */
/* void read_super(int old); */
void read_type(Ana *ana);
/* void read_xye(void); */
/* in set.c */
void set(Ana *ana);
/* void set_corrections(void); */
/* void set_fit(void); */
/* void set_general(void); */
/* void set_integrate(void); */
/* void set_read(void); */
/* void set_loop(void); */
/* in theory.c */
/* void gauss_double(float x, float a[], float *y, float dyda[], int mode); */
/* void gauss_lorentz(float x, float a[], float *y, float dyda[], int mode); */
/* void gauss_single(float x, float a[], float *y, float dyda[], int mode); */
/* void lorentz_gauss(float x, float a[], float *y, float dyda[], int mode); */
/* void lorentz_double(float x, float a[], float *y, float dyda[], int mode); */
/* void lorentz_single(float x, float a[], float *y, float dyda[], int mode); */
void power(float x, float a[], float *y, float dyda[], int mode);
/* void pseudo_voigt(float x, float a[], float *y, float dyda[], int mode); */
/* void slit(float x, float a[], float *y, float dyda[], int mode); */
void theory(Ana *ana);
void theory_type(Ana *ana);
/* in util.c */
void get_2inoutspec(Ana *ana, int *in_spec1, int *in_spec2, int *out_spec);
void get_in2outspec(Ana *ana, int *in_spec, int *out_spec1, int *out_spec2);
void get_inoutspec(Ana *ana, int *in_spec, int *out_spec);
void get_inspec(Ana *ana, int *in_spec);
/* void set_cursor(int horizontal, int vertical); */
/* double sqr(double value); */
void type_header(Ana *ana, int flag);
/***************************************************************************/
/* undefine some flags */
/***************************************************************************/
#undef ANA
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: ana_read.c --]
[-- Type: text/x-c; name=ana_read.c, Size: 38131 bytes --]
#include <ctype.h>
#include "ana.h"
#include "hkl/ccan/array_size/array_size.h"
static void read_column(Ana *ana)
/*
* Read file of 'column' type:
* - HEADER_LINES header lines
* - data lines with arbirary amount of columns, with
* XCOL the x-values
* YCOL the y-values
* ECOL the errors in y (no error if 0).
*/
{
char filename[FILENAME_MAX];
FILE *infile = NULL;
int i,in_spec = 0,npoints;
bool end_of_file,error_column;
float dummy[DATACOLUMNS];
int maxcolumn;
/* Get filename and open file, return if not successful */
get_token(&ana->rod.menu, filename,"Give filename (.dat): ");
add_extension(filename,"dat");
infile = fopen(filename, "r");
if(NULL == infile){
sprintf(STRING,"Failed to open file '%s'",filename);
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
return;
}
/* Get spectrum number where data has to be stored */
get_inspec(ana, &in_spec);
READSPEC = in_spec;
/* Skip header lines */
for(i = 0; i < HEADER_LINES; i++)
{
if(fgets(INLINE,INLLEN,infile) == NULL)
{
errtype(&ana->rod.menu, "ERROR, less than HEADER_LINES lines in file");
clear_command(&ana->rod.menu);
fclose(infile);
return;
}
}
/* Find maximum column number to be read in */
maxcolumn = XCOL;
if(YCOL > maxcolumn)
maxcolumn = YCOL;
if(ECOL > maxcolumn)
maxcolumn = ECOL;
if(ECOL != 0)
error_column = true;
else
error_column = false;
/* Read in spectrum */
npoints = 0;
end_of_file = false;
while((fgets(INLINE,INLLEN,infile) != NULL) && (!end_of_file))
{
/* Check whether enough data is read in */
if(sscanf(INLINE,"%f%f%f%f%f%f%f%f%f%f%f%f",
&dummy[0],&dummy[1],&dummy[2],&dummy[3],&dummy[4],&dummy[5],
&dummy[6],&dummy[7],&dummy[8],&dummy[9],&dummy[10],&dummy[11])
>= maxcolumn)
{
if(XCOL <= 0) /* Enumerate x-values */
DATA[in_spec].X[npoints] = (float) npoints+1;
else
DATA[in_spec].X[npoints] = dummy[XCOL-1];
DATA[in_spec].Y[npoints] = dummy[YCOL-1];
if(error_column)
DATA[in_spec].E[npoints] = dummy[ECOL-1];
else
DATA[in_spec].E[npoints] = 1;
npoints++;
}
else
{
end_of_file = true;
}
}
fclose(infile);
if(npoints == 0)
{
errtype(&ana->rod.menu, "No data in spectrum");
clear_command(&ana->rod.menu);
return;
}
DATA[in_spec].NPNT = npoints;
/* Find miniumum and maximum in spectrum */
DATA[in_spec].MINY = DATA[in_spec].Y[0];
DATA[in_spec].MAXY = DATA[in_spec].Y[0];
for(i = 1; i < npoints; i++)
{
if(DATA[in_spec].Y[i] < DATA[in_spec].MINY)
DATA[in_spec].MINY = DATA[in_spec].Y[i];
if(DATA[in_spec].Y[i] > DATA[in_spec].MAXY)
DATA[in_spec].MAXY = DATA[in_spec].Y[i];
}
/* Give spectrum a title */
sprintf(DATA[in_spec].TITLE,"%.*s",TITLE_LENGTH,filename);
sprintf(DATATITLE,"%.*s",TITINFLN-1,filename);
sprintf(STRING,"Range of x-axis: %10.6g to %10.6g\n",
DATA[in_spec].X[0],DATA[in_spec].X[DATA[in_spec].NPNT-1]);
type_line(&ana->rod.menu, STRING);
type_header(ana, 1);
}
static void read_ftascom(Ana *ana)
/*
* Read HASYLAB tascom file in single column format.
* We assume a z-axis mode.
*/
{
char filename[FILENAME_MAX],dummy_name[FILENAME_MAX],date[50],time[50];
FILE *infile;
int i,in_spec = 0,npoints;
bool end_of_file;
float dummy[DATACOLUMNS] = {0};
float dummyval;
float monitor[MAX_DATA];
int ncolumns,nheaders,xcol_save;
bool done;
char column_name[20];
char name[20][20];
float *x=NULL,*y=NULL,*e=NULL;
int digits;
/* Get filename and open file, return if not successful */
SCANNR = get_int(&ana->rod.menu, 1,"Scan number: ");
for(i=strlen(DATAFILE)-1, digits=5; i>=0; i--, digits--)
{
if(!isdigit(DATAFILE[i])) break;
}
snprintf(filename, sizeof(filename), "%s%0*d",DATAFILE,digits,SCANNR);
filename[FILENAME_MAX-1] = '\0';
add_extension(filename,"dat");
if((infile = fopen(filename,"r")) == NULL)
{
sprintf(STRING,"Failed to open file '%s'",filename);
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
return;
}
/* Extract a few things from the header */
/* First line contains # header lines + #columns */
if(NULL != fgets(INLINE,INLLEN,infile))
{
sscanf(INLINE,"%d %d",&nheaders,&ncolumns);
}
/* Now get date, time from second line */
if (NULL != fgets(INLINE,INLLEN,infile))
{
sscanf(INLINE," %s %s",&date[0],&time[0]);
snprintf(DATAINFO, TITINFLN, "%.60s Date: %s time: %s",filename,date,time);
sprintf(STRING, "Date: %s time: %s\n",date,time);
type_line(&ana->rod.menu, STRING);
}
/* skip blank line */
if (NULL != fgets(INLINE,INLLEN,infile))
{
/* no op */
}
/* Rest may contain something interesting */
ALPHA = BETAIN = DELTA = GAMMA = 0.;
for(i = 0; i < nheaders-ncolumns-2; i++)
{
if (NULL != fgets(INLINE,INLLEN,infile))
{
sscanf(INLINE,"%s = %f",&dummy_name[0],&dummyval);
string_toupper(dummy_name);
if(strcmp(dummy_name,"FTR") == 0) GAMMA = dummyval;
if(strcmp(dummy_name,"ALF") == 0) ALPHA = dummyval;
if(strcmp(dummy_name,"2TS") == 0) DELTA = dummyval;
if(strcmp(dummy_name,"H") == 0) HMIL = dummyval;
if(strcmp(dummy_name,"K") == 0) KMIL = dummyval;
if(strcmp(dummy_name,"L") == 0) LMIL = dummyval;
}
}
BETAIN = ALPHA; /* This is, of course, only correct for z-axis mode */
sprintf(STRING,"ALPHA=%.3f, DELTA=%.3f, GAMMA=%.3f\n",ALPHA,DELTA,GAMMA);
type_line(&ana->rod.menu, STRING);
/* Get the 'column' names */
for(i = 0; i < ncolumns; i++)
{
if (NULL != fgets(INLINE, INLLEN,infile))
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy(name[i], INLINE, ARRAY_SIZE(name[i]) - 1);
#pragma GCC diagnostic pop
name[i][ARRAY_SIZE(name[i]) - 1] = '\0';
string_tolower(name[i]);
}
}
sprintf(DATATITLE," "); /* No comments line here in HASYLAB */
xcol_save = XCOL;
if(XCOL < 0) /* Get name of x */
{
done = false;
while(!done)
{
if(!get_token(&ana->rod.menu, column_name,
"Give column name (type <return> for options): "))
{
for(i = 0; i < ncolumns; i++)
{
type_line(&ana->rod.menu, name[i]);
}
type_line(&ana->rod.menu, "\n");
}
else
{
string_tolower(column_name);
for(i = 0; i < ncolumns; i++)
{
if(strcmp(name[i],column_name) == 0)
{
XCOL = i+1;
done = true;
snprintf(XCOLNAME, ARRAY_SIZE(XCOLNAME),
"%.*s", (int)ARRAY_SIZE(name[i]), name[i]);
}
}
if(XCOL < 0)
{
errtype(&ana->rod.menu, "ERROR, no matching column name found");
clear_command(&ana->rod.menu);
fclose(infile);
XCOL = xcol_save;
return;
}
}
}
}
else if(XCOL > 0) /* Get column name of x */
{
sprintf(XCOLNAME,"%s",name[XCOL-1]);
}
else
{
sprintf(XCOLNAME,"x");
}
if(XCOL != 0) /* Put x name in graph */
{
sprintf(STRING,"x title %s break",XCOLNAME);
put_command(&ana->rod.menu, STRING);
plotxye(&ana->pg, &ana->rod.menu, x, y, e, 1);
}
/* Get column number of y values */
for(i = 0; i < ncolumns; i++)
if(strcmp(name[i],YCOLNAME) == 0)
YCOL = i+1;
/* Get column number of monitor values */
if(MCOL != 0)
{
for(i = 0; i < ncolumns; i++)
{
if(strcmp(name[i],"mon") == 0) MCOL = i+1;
}
}
/* Get spectrum number where data has to be stored */
get_inspec(ana, &in_spec);
READSPEC = in_spec;
/* Read in spectrum */
npoints = 0;
end_of_file = false;
while(!end_of_file)
{
for(i = 0; i < ncolumns; i++)
{
if(NULL == fgets(INLINE,INLLEN,infile))
{
end_of_file = true;
break;
}
sscanf(INLINE,"%f",&dummy[i]);
}
if(XCOL == 0) /* Enumerate x-values */
{
DATA[in_spec].X[npoints] = (float) npoints+1;
}
else
{
DATA[in_spec].X[npoints] = dummy[XCOL-1];
}
DATA[in_spec].Y[npoints] = dummy[YCOL-1];
if(MCOL != 0)
monitor[npoints] = dummy[MCOL-1];
npoints++;
if(npoints == MAX_DATA)
{
errtype(&ana->rod.menu, "ERROR, maximum number of data points exceeded");
break;
}
} /* end of while */
fclose(infile);
if(npoints == 0)
{
errtype(&ana->rod.menu, "No data in spectrum");
clear_command(&ana->rod.menu);
XCOL = xcol_save;
return;
}
DATA[in_spec].NPNT = npoints;
XCOL = xcol_save;
/* Calculate statistical error */
for(i = 0; i < npoints; i++) DATA[in_spec].E[i] = sqrt(DATA[in_spec].Y[i]);
/* if required, normalize on monitor signal */
if(MCOL != 0)
{
for(i = 0; i < npoints; i++)
{
if(monitor[i] < 1) monitor[i] = 1;
DATA[in_spec].Y[i] *= MONITOR_NORM/monitor[i];
DATA[in_spec].E[i] *= MONITOR_NORM/monitor[i];
}
}
/* Find miniumum and maximum in spectrum */
DATA[in_spec].MINY = DATA[in_spec].Y[0];
DATA[in_spec].MAXY = DATA[in_spec].Y[0];
for(i = 1; i < npoints; i++)
{
if(DATA[in_spec].Y[i] < DATA[in_spec].MINY)
DATA[in_spec].MINY = DATA[in_spec].Y[i];
if(DATA[in_spec].Y[i] > DATA[in_spec].MAXY)
DATA[in_spec].MAXY = DATA[in_spec].Y[i];
}
/* Give spectrum a title */
sprintf(DATA[in_spec].TITLE,"%.*s",TITLE_LENGTH,filename);
sprintf(STRING,"Range of x-axis: %10.6g to %10.6g\n",
DATA[in_spec].X[0],DATA[in_spec].X[DATA[in_spec].NPNT-1]);
type_line(&ana->rod.menu, STRING);
type_header(ana, 1);
}
/*
* Read scan from SPEC data file.
*/
static void read_spec(Ana *ana)
{
static int hcol,kcol,lcol;
char par[3];
FILE *infile;
int in_spec = 0;
bool found,end_of_scan;
bool done;
char date[40];
int i,scan;
float monitor[MAX_DATA];
float dummy[DATACOLUMNS];
int maxcolumn,npoints;
int ncolumns,xcol_save;
char column_name[40];
char name[DATACOLUMNS][40];
float *x=NULL,*y=NULL,*e=NULL;
/* femke */
bool femke;
/* Get scan number to be read in */
sprintf(STRING,"Scan number to be read in [%1d]: ",SCANNR);
SCANNR = get_int(&ana->rod.menu, SCANNR,STRING);
/*femke*/
if(SCANNR < 1)
{
SCANNR = -SCANNR;
femke = true;
}
else
femke = false;
/* Open SPEC file. */
if((infile = fopen(DATAFILE,"r")) == NULL)
{
sprintf(STRING,"Failed to open input file '%s'",DATAFILE);
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
return;
}
/* Search for correct scan number */
found = false;
while(!found)
{
if(NULL == fgets(INLINE,INLLEN,infile))
{
sprintf(STRING,"Scan %d not found in file '%s'",SCANNR,DATAFILE);
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
fclose(infile);
return;
}
sscanf(INLINE,"%3c %d",par,&scan);
if((par[0]=='#') && (par[1] == 'S') && (scan == SCANNR))
{
found = true;
}
}
/*
* We have found the correct scan number, now get the rest of the
* information.
*
* Get the date and time from the "#D" line.
*/
found = false;
while(!found)
{
if(NULL == fgets(INLINE,INLLEN,infile))
{
sprintf(STRING,"Error, no \"#D\" date line in scan");
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
fclose(infile);
return;
}
if ( !strncmp (INLINE, "#D", 2) )
{
sscanf(INLINE,"%3c %24c",par,date);
found = true;
}
}
date[24] = 0;
sprintf(STRING,"%s\n",date);
type_line(&ana->rod.menu, STRING);
/*
* Get the first six spec variables from the "#P0" line. They contain the
* angles needed for computation of Lorentz factor, polarization factor,
* area correction and cut-of-the-rod correction.
*/
DELTA = 0;
BETAIN = 0;
ALPHA = 0;
found = false;
while(!found)
{
if(NULL == fgets(INLINE,INLLEN,infile))
{
sprintf(STRING,"Error, no \"#P0\" line in scan");
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
fclose(infile);
return;
}
if( !strncmp(INLINE, "#P0", 3) )
{
sscanf(INLINE,"%3c%f%f%f%f%f%f%f",par,&dummy[0],&dummy[1],&dummy[2],
&dummy[3],&dummy[4],&dummy[5],&dummy[6]);
found = true;
}
}
if(SPECTYPE == ID03 || SPECTYPE == ID32)
{
DELTA = dummy[0];
ALPHA = dummy[4];
BETAIN = dummy[4]; /* Z-axis mode only !! */
GAMMA = dummy[5];
}
if(SPECTYPE == DUBBLE)
{
DELTA = dummy[1];
ALPHA = dummy[2];
GAMMA = dummy[0];
BETAIN = dummy[2];
}
/* femke: trick to get special specular data read in with correct
indices */
if(femke)
{
ALPHA = (ALPHA+GAMMA)/2;
GAMMA = ALPHA;
}
sprintf(STRING,"DELTA=%.3f, ALPHA=%.3f, GAMMA=%.3f, BETA_IN=%.3f\n",
DELTA,ALPHA,GAMMA,BETAIN);
type_line(&ana->rod.menu, STRING);
/* Read line with column names. Skip this line if the column number
of the x-values if given. If XCOL < 0, ask for name of column. */
found = false;
while(!found)
{
if(NULL == fgets(INLINE,INLLEN,infile))
{
sprintf(STRING,"Error, emtpy scan");
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
fclose(infile);
return;
}
if( !strncmp(INLINE, "#L", 2))
{
found = true;
static char *p = &INLINE[0];
/* SPEC column names are separated by double spaces,
thus replace all single spaces (that are part of column
name) by underscore */
for(i = 3; i < strlen(INLINE)-1; i++)
{
if( (p[i] == ' ')
&& (p[i-1] != ' ')
&& (p[i+1] != ' '))
p[i] = '_';
}
/* read column headers */
ncolumns = sscanf(INLINE,
"%3c %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
par,name[0],name[1],name[2],name[3],name[4],name[5],name[6],
name[7],name[8],name[9],name[10],name[11],name[12],name[13],
name[14],name[15],name[16],name[17],name[18]);
ncolumns -= 1; /* the first item doesn't count */
if(ncolumns >= DATACOLUMNS)
{
sprintf(STRING,"Too many data columns, only first %d used",
DATACOLUMNS);
errtype(&ana->rod.menu, STRING);
}
}
}
xcol_save = XCOL;
hcol = 0;
kcol = 0;
lcol = 0;
if(XCOL < 0)
{
done = false;
while(!done)
{
if(!get_token(&ana->rod.menu, column_name,
"Give column name (type <return> for options): "))
{
type_line(&ana->rod.menu, INLINE);
}
else
{
string_tolower(column_name);
for(i = 0; i < ncolumns; i++)
{
string_tolower(name[i]);
if(strcmp(name[i],column_name) == 0)
{
XCOL = i+1;
done = true;
snprintf(XCOLNAME, ARRAY_SIZE(XCOLNAME),
"%.*s", (int)(ARRAY_SIZE(name[i])), name[i]);
}
}
if(XCOL < 0)
{
errtype(&ana->rod.menu, "ERROR, no matching column name found");
clear_command(&ana->rod.menu);
fclose(infile);
return;
}
}
}
/* Assign x-column name to title of x-axis in plot */
sprintf(STRING,"x title %s break",XCOLNAME);
put_command(&ana->rod.menu, STRING);
plotxye(x,y,e,1);
}
for(i = 0; i < ncolumns; i++)
{
string_tolower(name[i]);
if(strcmp(name[i],YCOLNAME) == 0) YCOL = i+1;
if(strcmp(name[i],"h") == 0) hcol = i+1;
if(strcmp(name[i],"k") == 0) kcol = i+1;
if(strcmp(name[i],"l") == 0) lcol = i+1;
if(MCOL != 0)
{
if(!strcmp(name[i],"monitor") || !strcmp(name[i],"monitor1") ||
!strcmp(name[i],"ion_ch"))
MCOL = i+1;
}
}
/* Get spectrum number where data has to be stored */
get_inspec(ana, &in_spec);
READSPEC = in_spec;
/* Find maximum column number to be read in */
if(XCOL > YCOL)
maxcolumn = XCOL;
else
maxcolumn = YCOL;
/* Read data and compute statistical error in y-values */
npoints = 0;
HMIL = 0;
KMIL = 0;
LMIL = 0;
end_of_scan = false;
while((NULL != fgets(INLINE,INLLEN,infile)) && (!end_of_scan))
{
/* Check whether enough data is read in */
if(sscanf(INLINE,"%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f",
&dummy[0],&dummy[1],&dummy[2],&dummy[3],&dummy[4],&dummy[5],
&dummy[6],&dummy[7],&dummy[8],&dummy[9],&dummy[10],&dummy[11],
&dummy[12],&dummy[13],&dummy[14],&dummy[15],&dummy[16],&dummy[17],
&dummy[18]) >= maxcolumn)
{
if(XCOL == 0) /* Enumerate x-values */
DATA[in_spec].X[npoints] = (float) npoints+1;
else
DATA[in_spec].X[npoints] = dummy[XCOL-1];
DATA[in_spec].Y[npoints] = dummy[YCOL-1];
if(MCOL > 0)
monitor[npoints] = dummy[MCOL-1];
else
monitor[npoints] = MONITOR_NORM;
HMIL += dummy[hcol-1];
KMIL += dummy[kcol-1];
LMIL += dummy[lcol-1];
if(dummy[YCOL-1] < XYMINVAL)
DATA[in_spec].E[npoints] = 1.;
else
DATA[in_spec].E[npoints] = sqrt(dummy[YCOL-1]);
npoints++;
if(npoints >= MAX_DATA)
{
errtype(&ana->rod.menu, "Maximum number of data points exceeded");
break;
}
}
else
{
end_of_scan = true;
}
}
fclose(infile);
XCOL = xcol_save;
if(npoints == 0)
{
errtype(&ana->rod.menu, "No data in spectrum");
clear_command(&ana->rod.menu);
return;
}
DATA[in_spec].NPNT = npoints;
/* Make h, k, l and two-theta the average value */
HMIL = HMIL/npoints;
KMIL = KMIL/npoints;
LMIL = LMIL/npoints;
/* femke */
if(femke)
{
HMIL = 0.;
KMIL = 0.;
LMIL = 20.369*sin(GAMMA/RAD);
}
sprintf(STRING,"(hkl) = (%4.2f,%4.2f,%4.2f)\n",HMIL,KMIL,LMIL);
type_line(&ana->rod.menu, STRING);
/* If requested, normalize data */
if(MCOL != 0)
{
for(i = 0; i < npoints; i++)
{
if(monitor[i] < 1)
monitor[i] = 1;
DATA[in_spec].Y[i] *= MONITOR_NORM/monitor[i];
DATA[in_spec].E[i] *= MONITOR_NORM/monitor[i];
}
}
/* Find miniumum and maximum in spectrum */
DATA[in_spec].MINY = DATA[in_spec].Y[0];
DATA[in_spec].MAXY = DATA[in_spec].Y[0];
for(i = 1; i < npoints; i++)
{
if(DATA[in_spec].Y[i] < DATA[in_spec].MINY)
DATA[in_spec].MINY = DATA[in_spec].Y[i];
if(DATA[in_spec].Y[i] > DATA[in_spec].MAXY)
DATA[in_spec].MAXY = DATA[in_spec].Y[i];
}
/* Give spectrum a title */
sprintf(DATA[in_spec].TITLE,"%.*s #%1d",TITLE_LENGTH-7,DATAFILE,SCANNR);
sprintf(STRING,"Range of x-axis: %10.6g to %10.6g\n",DATA[in_spec].X[0],
DATA[in_spec].X[DATA[in_spec].NPNT-1]);
type_line(&ana->rod.menu, STRING);
type_header(ana, 1);
}
static void read_srs(Ana *ana, int version)
/*
* Read Daresbury SRS file.
* Since the file format is changing every now and then, the actions
* differ somewhat according to the version flag
* version 1 before 92
* version 2 starting 92
*/
{
static int maxcolumn;
char filename[FILENAME_MAX],dummy_name[FILENAME_MAX],datetime[50];
FILE *infile;
int i,in_spec = 0,npoints;
int end_of_file;
float dummy[DATACOLUMNS];
float monitor[MAX_DATA];
int done,ncolumns,xcol_save=0,timescan;
char column_name[20],name[20][20];
float *x=NULL,*y=NULL,*e=NULL;
char *spos;
char lastline[INLLEN];
int has_read_beta;
int digits;
/* Get filename and open file, return if not successful */
SCANNR = get_int(&ana->rod.menu, 1,"Scan number: ");
for(i=strlen(DATAFILE)-1, digits=5; i>=0; i--, digits--)
{
if(!isdigit(DATAFILE[i])) break;
}
sprintf(filename,"%s%0*d",DATAFILE,digits,SCANNR);
add_extension(filename,"dat");
if((infile = fopen(filename,"r")) == NULL)
{
sprintf(STRING,"Failed to open file '%s'",filename);
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
return;
}
/* Extract a few things from the header */
ALPHA = BETAIN = DELTA = 0.;
GAMMA = GAMMA_FIX; /* Can't be found in data file */
if (NULL != fgets(INLINE,INLLEN,infile)) {;}
if (NULL != fgets(INLINE,INLLEN,infile)) {;}
sprintf(DATAINFO,"%.*s Date: %.2s-%.2s-%.2s time: %.2s:%.2s:%.2s",
TITINFLN-40,filename,&INLINE[25],&INLINE[23],&INLINE[21],&INLINE[35],
&INLINE[37],&INLINE[39]);
sprintf(datetime,"Date: %.2s-%.2s-%.2s time: %.2s:%.2s:%.2s",
&INLINE[25],&INLINE[23],&INLINE[21],&INLINE[35],&INLINE[37],
&INLINE[39]);
if (NULL != fgets(INLINE,INLLEN,infile)) {;}
if (NULL != fgets(INLINE,INLLEN,infile)) {;}
sscanf(INLINE,"%8s%f %f %f %f",dummy_name,&HMIL,&KMIL,&LMIL,&BETAIN);
/*
* First two characters must be spaces and beta shouldn't be zero for
* for correct beta read from header
*/
if((strstr(INLINE, " ") != INLINE+9) || (BETAIN == 0.))
{
BETAIN = 0.;
has_read_beta = false;
}
else
{
has_read_beta = true;
}
sprintf(DATATITLE,"%.40s",&INLINE[9]);
if(version == 1) /* that's before '92 */
{
for(i = 0; i < 11; i++)
{
if (NULL != fgets(INLINE,INLLEN,infile)) {;}
}
if (NULL != fgets(INLINE,INLLEN,infile)) {;}
sscanf(INLINE,"%s%f",dummy_name,&DELTA);
for(i = 0; i < HEADER_LINES-16; i++)
{
if (NULL != fgets(INLINE,INLLEN,infile)) {;}
}
/* Since alpha and beta are not necessarily correct, ignore them
for the time being */
ALPHA = BETAIN = 0;
}
if(version == 2) /* this is after Gordon's great rewrite */
{
/* We're looking in for the magic keywords DELTA and BETA_IN
somewhere in the header ... */
ALPHA = DELTA = 0.; /* BETAIN should still be zero if not in header */
for(;;) /* loop until we find the start of data marker */
{
if (NULL != fgets(INLINE,INLLEN,infile)) {;} /* read a line from file */
string_toupper(INLINE); /* all char's -> uppercase */
if(strstr(INLINE, "--------------------") != NULL)
{
break; /* go and read data now */
}
if((spos=strstr(INLINE,"ALPHA")) != NULL)
{
sscanf(spos+5,"%f",&ALPHA); /* get alpha if you need it */
}
if((spos=strstr(INLINE,"DELTA")) != NULL)
{
sscanf(spos+5,"%f",&DELTA); /* get twotheta = delta */
}
if(((spos=strstr(INLINE,"BETA_IN")) != NULL) &&
(has_read_beta == false))
{
sscanf(spos+7,"%f",&BETAIN); /* get incoming angle */
}
if((spos=strstr(INLINE,"DETECTOR")) != NULL)
{
strcpy(lastline,INLINE); /* save this line for the headers */
}
} /* end of for loop */
sprintf(STRING,"DELTA=%.3f, ALPHA=%.3f, BETA_IN=%.3f\n",
DELTA,ALPHA,BETAIN);
type_line(&ana->rod.menu, STRING);
/* look for column headers */
if(version == 1)
{
rewind(infile);
for(i = 0; i < HEADER_LINES-1; i++)
if (NULL != fgets(INLINE,INLLEN,infile)) {;}
}
if(version == 2)
{
strcpy(INLINE,lastline); /* this still has the headers */
}
ncolumns = sscanf(INLINE,
" %s %s %s %s %s %s %s %s %s %s %s %s %s",
name[0],name[1],name[2],name[3],name[4],name[5],name[6],
name[7],name[8],name[9],name[10],name[11],name[12]);
for(i = 0; i < ncolumns; i++) string_tolower(name[i]);
xcol_save = XCOL;
if(XCOL < 0) /* Get name of x */
{
done = false;
while(!done)
{
if(!get_token(&ana->rod.menu, column_name,
"Give column name (type <return> for options): "))
{
type_line(&ana->rod.menu, INLINE);
}
else
{
string_tolower(column_name);
for(i = 0; i < ncolumns; i++)
{
if(strcmp(name[i],column_name) == 0)
{
XCOL = i+1;
done = true;
snprintf(XCOLNAME,ARRAY_SIZE(XCOLNAME), "%.*s",
(int)(ARRAY_SIZE(name[i])), name[i]);
}
}
if(XCOL < 0)
{
errtype(&ana->rod.menu, "ERROR, no matching column name found");
clear_command(&ana->rod.menu);
fclose(infile);
XCOL = xcol_save;
return;
}
}
}
}
else if(XCOL > 0) /* Get column name of x */
{
sprintf(XCOLNAME,"%s",name[XCOL-1]);
}
else
{
sprintf(XCOLNAME,"x");
}
if(XCOL != 0)
{
sprintf(STRING,"x title %s break",XCOLNAME);
put_command(&ana->rod.menu, STRING);
plotxye(x,y,e,1);
}
/* Get column number of y values */
for(i = 0; i < ncolumns; i++)
{
if(strcmp(name[i],YCOLNAME) == 0)
YCOL = i+1;
}
/* Get column number of monitor values */
if(MCOL != 0)
{
for(i = 0; i < ncolumns; i++)
{
if(strcmp(name[i],"monitor") == 0)
MCOL = i+1;
}
}
}
if(strcmp(XCOLNAME,"time") == 0)
timescan = true;
else
timescan = false;
sprintf(STRING,"%s\n",datetime);
type_line(&ana->rod.menu, STRING);
sprintf(STRING,"Title: %s\n",DATATITLE);
type_line(&ana->rod.menu, STRING);
/* Get spectrum number where data has to be stored */
get_inspec(ana, &in_spec);
READSPEC = in_spec;
/* Find maximum column number to be read in */
maxcolumn = XCOL;
if(YCOL > maxcolumn)
maxcolumn = YCOL;
if(MCOL > maxcolumn)
maxcolumn = MCOL;
/* Read in spectrum */
npoints = 0;
end_of_file = false;
while((fgets(INLINE,INLLEN,infile) != NULL) && (!end_of_file))
{
/* Check whether enough data is read in */
if(sscanf(INLINE,"%f%f%f%f%f%f%f%f%f%f%f%f",
&dummy[0],&dummy[1],&dummy[2],&dummy[3],&dummy[4],&dummy[5],
&dummy[6],&dummy[7],&dummy[8],&dummy[9],&dummy[10],&dummy[11])
>= maxcolumn)
{
if(XCOL == 0) /* Enumerate x-values */
{
DATA[in_spec].X[npoints] = (float) npoints+1;
}
else
{
if(npoints && timescan == true) /* cumulate X column if */
{ /* in time scan mode */
DATA[in_spec].X[npoints] = DATA[in_spec].X[npoints-1] +
dummy[XCOL-1];
}
else
{
DATA[in_spec].X[npoints] = dummy[XCOL-1];
}
}
DATA[in_spec].Y[npoints] = dummy[YCOL-1];
if(MCOL != 0)
monitor[npoints] = dummy[MCOL-1];
npoints++;
if(npoints == MAX_DATA)
{
errtype(&ana->rod.menu, "ERROR, maximum number of data points exceeded");
break;
}
}
else
{
end_of_file = true;
}
} /* end of while */
fclose(infile);
if(npoints == 0)
{
errtype(&ana->rod.menu, "No data in spectrum");
clear_command(&ana->rod.menu);
XCOL = xcol_save;
return;
}
DATA[in_spec].NPNT = npoints;
XCOL = xcol_save;
/* If required, do the solid-state detector correction */
if(SOLID_CORR)
for(i = 0; i < npoints; i++)
DATA[in_spec].Y[i] -= 1;
/* Calculate statistical error */
for(i = 0; i < npoints; i++)
DATA[in_spec].E[i] = sqrt(DATA[in_spec].Y[i]);
/* if required, normalize on monitor signal */
if(MCOL != 0)
{
for(i = 0; i < npoints; i++)
{
if(monitor[i] < 1) monitor[i] = 1;
DATA[in_spec].Y[i] *= MONITOR_NORM/monitor[i];
DATA[in_spec].E[i] *= MONITOR_NORM/monitor[i];
}
}
/* Find miniumum and maximum in spectrum */
DATA[in_spec].MINY = DATA[in_spec].Y[0];
DATA[in_spec].MAXY = DATA[in_spec].Y[0];
for(i = 1; i < npoints; i++)
{
if(DATA[in_spec].Y[i] < DATA[in_spec].MINY)
DATA[in_spec].MINY = DATA[in_spec].Y[i];
if(DATA[in_spec].Y[i] > DATA[in_spec].MAXY)
DATA[in_spec].MAXY = DATA[in_spec].Y[i];
}
/* Give spectrum a title */
sprintf(DATA[in_spec].TITLE,"%.*s",TITLE_LENGTH,filename);
sprintf(STRING,"Range of x-axis: %10.6g to %10.6g\n",
DATA[in_spec].X[0],DATA[in_spec].X[DATA[in_spec].NPNT-1]);
type_line(&ana->rod.menu, STRING);
type_header(ana, 1);
}
static void read_super(Ana *ana, int old)
/*
* Read scan from SUPER file. There are two modes:
* - old = true old style: large file with many scans
* - old = false new style: file with one scan
*/
{
static int hcol,kcol,lcol,tthcol,alpcol,betcol;
char filename[FILENAME_MAX];
FILE *infile = NULL;
int in_spec = 0;
bool found = false,end_of_scan;
bool done;
char hatch,date[21];
int i,scan;
float monitor;
float dummy[DATACOLUMNS];
int maxcolumn,npoints;
float norm_corr;
int ncolumns,xcol_save;
char column_name[20],name[20][20];
float *x=NULL,*y=NULL,*e=NULL;
/* Get scan number to be read in */
sprintf(STRING,"Scan number to be read in [%1d]: ",SCANNR);
SCANNR = get_int(&ana->rod.menu, SCANNR,STRING);
/* Open SUPER file. Different for the two modes */
if(old) /* Old style SUPER file */
{
if((infile = fopen(DATAFILE,"r")) == NULL)
{
sprintf(STRING,"Failed to open input file '%s'",DATAFILE);
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
return;
}
}
else /* New style SUPER file */
{
/* Scannumbers > 999 get the extra digit as part of the filename */
if(SCANNR/1000 > 0)
{
if(NAUTOSUB > 0)
sprintf(filename,"%s%1d\\%s%1d.%03d",PATHNAME,SCANNR/NAUTOSUB,
DATAFILE,SCANNR/1000,SCANNR%1000);
else
sprintf(filename,"%s%1d.%03d",DATAFILE,SCANNR/1000,SCANNR%1000);
}
else
{
if(NAUTOSUB > 0)
sprintf(filename,"%s%1d\\%s.%03d",PATHNAME,SCANNR/NAUTOSUB,
DATAFILE,SCANNR%1000);
else
sprintf(filename,"%s.%03d",DATAFILE,SCANNR%1000);
}
if((infile = fopen(filename,"r")) == NULL)
{
sprintf(STRING,"Failed to open input file '%s'",filename);
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
return;
}
}
/* Search for correct scan number */
while(!found)
{
if(fgets(INLINE,INLLEN,infile) == NULL)
{
if(old)
sprintf(STRING,"Scan not found in file '%s'",DATAFILE);
else
sprintf(STRING,"Scan not found in file '%s'",filename);
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
fclose(infile);
return;
}
sscanf(INLINE,"%c%d",&hatch,&scan);
if((hatch == '#') && (scan == SCANNR))
{
found = true;
sscanf(INLINE,"%80[^=]%*c%f%*6c%20c",STRING,&monitor,date);
}
else if(hatch == '>')
{
/* Remove newline character at the end */
i = strlen(INLINE) < TITINFLN ? strlen(INLINE) : TITINFLN;
sprintf(DATATITLE,"%.*s",i-1,INLINE);
}
}
/* Read line with column names. Skip this line if the column number
of the x-values if given. If XCOL < 0, ask for name of column. */
if(fgets(INLINE,INLLEN,infile) == NULL)
{
errtype(&ana->rod.menu, "Error, empty spectrum");
clear_command(&ana->rod.menu);
fclose(infile);
return;
}
xcol_save = XCOL;
if(XCOL < 0)
{
hcol = 0;
kcol = 0;
lcol = 0;
tthcol = 0;
done = false;
while(!done)
{
if(!get_token(&ana->rod.menu, column_name,
"Give column name (type <return> for options): "))
{
type_line(&ana->rod.menu, INLINE);
}
else
{
string_tolower(column_name);
ncolumns = sscanf(INLINE,
"%s %s %s %s %s %s %s %s %s %s %s %s %s",
name[0],name[1],name[2],name[3],name[4],name[5],name[6],
name[7],name[8],name[9],name[10],name[11],name[12]);
for(i = 0; i < ncolumns; i++)
{
string_tolower(name[i]);
if(strcmp(name[i],column_name) == 0)
{
XCOL = i+1;
done = true;
snprintf(XCOLNAME, ARRAY_SIZE(XCOLNAME),
"%.*s", (int)(ARRAY_SIZE(name[i])), name[i]);
}
if(strcmp(name[i],YCOLNAME) == 0) YCOL = i+1;
if(strcmp(name[i],"h") == 0) hcol = i+1;
if(strcmp(name[i],"k") == 0) kcol = i+1;
if(strcmp(name[i],"l") == 0) lcol = i+1;
if(strcmp(name[i],"tth") == 0) tthcol = i+1;
if(strcmp(name[i],"bet") == 0) betcol = i+1;
if(strcmp(name[i],"mcr") == 0) alpcol = i+1;
}
if(XCOL < 0)
{
errtype(&ana->rod.menu, "ERROR, no matching column name found");
clear_command(&ana->rod.menu);
fclose(infile);
return;
}
}
}
sprintf(STRING,"x title %s break",XCOLNAME);
put_command(&ana->rod.menu, STRING);
plotxye(&ana->pg, &ana->rod.menu, x, y, e, 1);
}
/* Get spectrum number where data has to be stored */
get_inspec(ana, &in_spec);
READSPEC = in_spec;
/* Display some information about the file */
DATATITLE[0] = ' ';
sprintf(STRING,"Title: %s\n",DATATITLE);
type_line(&ana->rod.menu, STRING);
date[20] = '\0';
sprintf(STRING,"Creation date: %s\n",date);
type_line(&ana->rod.menu, STRING);
/* Find maximum column number to be read in */
if(XCOL > YCOL)
maxcolumn = XCOL;
else
maxcolumn = YCOL;
/* Read data and compute statistical error in y-values */
npoints = 0;
HMIL = 0;
KMIL = 0;
LMIL = 0;
DELTA = 0;
BETAIN = 0;
ALPHA = 0;
end_of_scan = false;
while((fgets(INLINE,INLLEN,infile) != NULL) && (!end_of_scan))
{
/* Check whether enough data is read in */
if(sscanf(INLINE,"%f%f%f%f%f%f%f%f%f%f%f%f",
&dummy[0],&dummy[1],&dummy[2],&dummy[3],&dummy[4],&dummy[5],
&dummy[6],&dummy[7],&dummy[8],&dummy[9],&dummy[10],&dummy[11])
>= maxcolumn)
{
if(XCOL == 0) /* Enumerate x-values */
DATA[in_spec].X[npoints] = (float) npoints+1;
else
DATA[in_spec].X[npoints] = dummy[XCOL-1];
DATA[in_spec].Y[npoints] = dummy[YCOL-1];
HMIL += dummy[hcol-1];
KMIL += dummy[kcol-1];
LMIL += dummy[lcol-1];
DELTA += dummy[tthcol-1];
if(betcol != 0) BETAIN += dummy[betcol-1];
if(alpcol != 0) ALPHA += dummy[alpcol-1];
if(dummy[YCOL-1] < XYMINVAL)
{
DATA[in_spec].E[npoints] = 1.;
}
else
{
DATA[in_spec].E[npoints] = sqrt(dummy[YCOL-1]);
}
npoints++;
}
else
{
end_of_scan = true;
}
}
fclose(infile);
XCOL = xcol_save;
if(npoints == 0)
{
errtype(&ana->rod.menu, "No data in spectrum");
clear_command(&ana->rod.menu);
return;
}
DATA[in_spec].NPNT = npoints;
/* Make h, k, l and two-theta the average value */
HMIL = HMIL/npoints;
KMIL = KMIL/npoints;
LMIL = LMIL/npoints;
DELTA = DELTA/npoints;
BETAIN = BETAIN/npoints;
ALPHA = ALPHA/npoints;
sprintf(STRING,"(hkl) = (%4.2f,%4.2f,%4.2f)\n",HMIL,KMIL,LMIL);
type_line(&ana->rod.menu, STRING);
/* If requested, normalize data */
if((MCOL != 0) && (monitor > 0.1))
{
norm_corr = MONITOR_NORM/monitor;
for(i = 0; i < npoints; i++)
{
DATA[in_spec].Y[i] *= norm_corr;
DATA[in_spec].E[i] *= norm_corr;
}
}
/* Find miniumum and maximum in spectrum */
DATA[in_spec].MINY = DATA[in_spec].Y[0];
DATA[in_spec].MAXY = DATA[in_spec].Y[0];
for(i = 1; i < npoints; i++)
{
if(DATA[in_spec].Y[i] < DATA[in_spec].MINY)
DATA[in_spec].MINY = DATA[in_spec].Y[i];
if(DATA[in_spec].Y[i] > DATA[in_spec].MAXY)
DATA[in_spec].MAXY = DATA[in_spec].Y[i];
}
/* Give spectrum a title */
if(old)
sprintf(DATA[in_spec].TITLE,"%.*s #%1d",TITLE_LENGTH-7,DATAFILE,SCANNR);
else
sprintf(DATA[in_spec].TITLE,"%.*s",TITLE_LENGTH,filename);
sprintf(STRING,"Range of x-axis: %10.6g to %10.6g\n",
DATA[in_spec].X[0],DATA[in_spec].X[DATA[in_spec].NPNT-1]);
type_line(&ana->rod.menu, STRING);
type_header(ana, 1);
}
static void read_xye(Ana *ana)
/*
* Read xye file:
* - one comment line
* - data line with x and y values, and optionally an error in third column.
*/
{
char filename[FILENAME_MAX];
FILE *infile;
int i,in_spec = 0,items,npoints;
bool error_column,end_of_file;
float x,y,e;
/* Get filename and open file, return if not successful */
get_token(&ana->rod.menu, filename,"Give filename (.dat): ");
add_extension(filename,"dat");
if((infile = fopen(filename,"r")) == NULL)
{
sprintf(STRING,"Failed to open file '%s'",filename);
errtype(&ana->rod.menu, STRING);
clear_command(&ana->rod.menu);
return;
}
/* Get spectrum number where data has to be stored */
get_inspec(ana, &in_spec);
READSPEC = in_spec;
/* Type comments */
if(fgets(INLINE,INLLEN,infile) == NULL)
{
errtype(&ana->rod.menu, "ERROR, file is empty");
fclose(infile);
clear_command(&ana->rod.menu);
return;
}
else
{
type_line(&ana->rod.menu, INLINE);
sprintf(DATATITLE,"%.*s",TITINFLN-1,INLINE);
}
/* Find out if there is an error column in file */
if(fgets(INLINE,INLLEN,infile) == NULL)
{
errtype(&ana->rod.menu, "ERROR, file is empty");
fclose(infile);
clear_command(&ana->rod.menu);
return;
}
items = sscanf(INLINE,"%f%f%f",&x,&y,&e);
if(items == 3)
{
error_column = true;
DATA[in_spec].X[0] = x;
DATA[in_spec].Y[0] = y;
DATA[in_spec].E[0] = e;
}
else if(items == 2)
{
error_column = false;
DATA[in_spec].X[0] = x;
DATA[in_spec].Y[0] = y;
DATA[in_spec].E[0] = 1;
}
else
{
errtype(&ana->rod.menu, "ERROR, when reading file");
fclose(infile);
clear_command(&ana->rod.menu);
return;
}
npoints = 1;
end_of_file = false;
while((fgets(INLINE,INLLEN,infile) != NULL) && (!end_of_file))
{
if(error_column) /* read in three values */
{
if(sscanf(INLINE,"%f%f%f",&x,&y,&e) == 3)
{
DATA[in_spec].X[npoints] = x;
DATA[in_spec].Y[npoints] = y;
DATA[in_spec].E[npoints] = e;
npoints++;
}
else
{
end_of_file = true;
}
}
else /* read in two values */
{
if(sscanf(INLINE,"%f%f",&x,&y) == 2)
{
DATA[in_spec].X[npoints] = x;
DATA[in_spec].Y[npoints] = y;
DATA[in_spec].E[npoints] = 1;
npoints++;
}
else
{
end_of_file = true;
}
}
}
fclose(infile);
if(npoints == 0)
{
errtype(&ana->rod.menu, "No data in spectrum");
clear_command(&ana->rod.menu);
return;
}
DATA[in_spec].NPNT = npoints;
/* Find miniumum and maximum in spectrum */
DATA[in_spec].MINY = DATA[in_spec].Y[0];
DATA[in_spec].MAXY = DATA[in_spec].Y[0];
for(i = 1; i < npoints; i++)
{
if(DATA[in_spec].Y[i] < DATA[in_spec].MINY)
DATA[in_spec].MINY = DATA[in_spec].Y[i];
if(DATA[in_spec].Y[i] > DATA[in_spec].MAXY)
DATA[in_spec].MAXY = DATA[in_spec].Y[i];
}
/* Give spectrum a title */
sprintf(DATA[in_spec].TITLE,"%.*s",TITLE_LENGTH,filename);
sprintf(STRING,"Range of x-axis: %10.6g to %10.6g\n",
DATA[in_spec].X[0],DATA[in_spec].X[DATA[in_spec].NPNT-1]);
type_line(&ana->rod.menu, STRING);
type_header(ana, 1);
}
void read_type(Ana *ana)
/*
* Get type of file to be read in.
*/
{
/* define read_type_menu */
static struct MENU read_type_menu[] =
{
{"srs", 2, 1, "SRS data file"},
{"spec", 2, 6, "SPEC data file"},
{"super", 2, 2, "Super data file (single scan)"},
{"osuper", 1, 3, "Old super scan (in bigdata file)"},
{"xye", 1, 4, "File with x y (and opt. error) columns"},
{"column", 1, 5, "File with arbitrary amount of columns"},
{"ftascom", 1, 7, "Single column tascom data file"},
{"help", 1, 20, "Display menu"},
{"return", 1, 21, "Return to main menu"},
};
/* number of commands in read_type menu */
int read_type_length = sizeof(read_type_menu) / sizeof(read_type_menu[0]);
bool stop = false,old;
char token[100];
while(!stop)
{
type_header(ana, 0);
if(!get_token(&ana->rod.menu, token,"File type: "))
return;
switch(cmnd_match(&ana->rod.menu, token,read_type_menu,read_type_length))
{
case -1:
break;
case 0:
break;
case 1:
sprintf(FILETYPE,"srs");
read_srs(ana, 2);
return;
case 2:
old = false;
sprintf(FILETYPE,"super");
read_super(ana, old);
return;
case 3:
old = true;
sprintf(FILETYPE,"osuper");
read_super(ana, old);
return;
case 4:
sprintf(FILETYPE,"xye");
read_xye(ana);
return;
case 5:
sprintf(FILETYPE,"column");
read_column(ana);
return;
case 6:
sprintf(FILETYPE,"spec");
read_spec(ana);
return;
case 7:
sprintf(FILETYPE,"ftascom");
read_ftascom(ana);
return;
case 20:
list_menu(&ana->rod.menu, "FILE TYPES",read_type_menu,read_type_length);
break;
case 21:
stop = true;
}
}
}
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: refactoring.cocci --]
[-- Type: text/x-c; name=refactoring.cocci, Size: 8010 bytes --]
@ana@
@@
#include "ana.h"
@depends on ana@
expression a,b,c,d;
@@
- plotxye(a, b, c, d)
+ plotxye(&ana->pg, &ana->rod.menu, a, b, c, d)
@depends on ana@
expression a,b,c,d,e;
@@
- plotxye(pg, a, b, c, d, e)
+ plotxye(&ana->pg, a, b, c, d, e)
@depends on ana@
expression a,b,c,d,e;
@@
- plotxye(a, menu, b, c, d, e)
+ plotxye(a, &ana->rod.menu, b, c, d, e)
@depends on ana@
expression a,b,c,d;
@@
- plot3dcurve(a, b, c, d)
+ plot3dcurve(&ana->pg, &ana->rod.menu, a, b, c, d)
@@
expression a,b,c,d;
@@
- plot3dcurve(a, b, c, d)
+ plot3dcurve(pg, menu, a, b, c, d)
@@
@@
- TMP_AXIS
+ pg->TMP_AXIS
@@
@@
- TMP_XLOWERSC
+ pg->TMP_XLOWERSC
@@
@@
- TMP_XUPPERSC
+ pg->TMP_XUPPERSC
@@
@@
- TMP_YLOWERSC
+ pg->TMP_YLOWERSC
@@
@@
- TMP_YUPPERSC
+ pg->TMP_YUPPERSC
@@
@@
- TMP_AUTOX
+ pg->TMP_AUTOX
@@
@@
- TMP_AUTOY
+ pg->TMP_AUTOY
@@
@@
- TMP_XLOGSC
+ pg->TMP_XLOGSC
@@
@@
- TMP_YLOGSC
+ pg->TMP_YLOGSC
@@
@@
- ZFORCE
+ pg->ZFORCE
@@
@@
- TMP_ZFORCE
+ pg->TMP_ZFORCE
@@
@@
-TMP_XTICK
+pg->TMP_XTICK
@@
@@
-TMP_XSUBTICK
+pg->TMP_XSUBTICK
@@
@@
-XFORMAT
+pg->XFORMAT
@@
@@
-TMP_XFORMAT
+pg->TMP_XFORMAT
@@
@@
-TMP_YTICK
+pg->TMP_YTICK
@@
@@
-TMP_YSUBTICK
+pg->TMP_YSUBTICK
@@
@@
-YFORMAT
+pg->YFORMAT
@@
@@
-TMP_YFORMAT
+pg->TMP_YFORMAT
@@
@@
-TMP_XLABEL
+ pg->TMP_XLABEL
@@
@@
-TMP_XLABSTRING
+pg->TMP_XLABSTRING
@@
@@
-TMP_XLABPOINTER
+pg->TMP_XLABPOINTER
@@
@@
-TMP_YLABSTRING
+pg->TMP_YLABSTRING
@@
@@
-TMP_YLABPOINTER
+pg->TMP_YLABPOINTER
@@
@@
-TMP_YLABEL
+pg->TMP_YLABEL
@@
@@
-TMP_ZLOWERSC
+pg->TMP_ZLOWERSC
@@
@@
-TMP_ZUPPERSC
+pg->TMP_ZUPPERSC
@@
@@
-TMP_AUTOZ
+pg->TMP_AUTOZ
@@
@@
-TMP_ZTICK
+pg->TMP_ZTICK
@@
@@
-TMP_ZTITLE
+pg->TMP_ZTITLE
@@
@@
-TMP_XTITLE
+pg->TMP_XTITLE
@@
@@
-TMP_YTITLE
+pg->TMP_YTITLE
@@
@@
-TMP_PTITLE
+pg->TMP_PTITLE
@@
@@
-TMP_NFONTS
+pg->TMP_NFONTS
@@
@@
-TMP_FONTNAME
+pg->TMP_FONTNAME
@@
@@
-TMP_DEFFONT
+pg->TMP_DEFFONT
@@
@@
-TMP_FONTFILL
+pg->TMP_FONTFILL
@@
@@
-TMP_CURVESTYLE
+pg->TMP_CURVESTYLE
@@
@@
-TMP_LINESTYLE
+pg->TMP_LINESTYLE
@@
@@
-TMP_CURVETHICKNESS
+pg->TMP_CURVETHICKNESS
@@
@@
-TMP_LINETHICKNESS
+pg->TMP_LINETHICKNESS
@@
@@
-TMP_SYMSTYLE
+pg->TMP_SYMSTYLE
@@
@@
-TMP_SYMSIZE
+pg->TMP_SYMSIZE
@@
@@
-LINETYPE
+pg->LINETYPE
@@
@@
-TMP_LINETYPE
+pg->TMP_LINETYPE
@@
@@
-TMP_COLBACK
+pg->TMP_COLBACK
@@
@@
-TMP_COLAXES
+pg->TMP_COLAXES
@@
@@
-TMP_COLCURVE
+pg->TMP_COLCURVE
@@
expression a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;
@@
- aplot(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r)
+ aplot(pg, menu, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r)
@@
expression a,b,c,d,e,f,g,h,i,j,k;
@@
- plotcon(a, b, c, d, e, f, g, h, i, j, k)
+ plotcon(pg, menu, a, b, c, d, e, f, g, h, i, j, k)
@@
expression a,b,c,d;
@@
- plotxye(a, b, c, d)
+ plotxye(pg, menu, a, b, c, d)
@@
expression a, b, c, d, e, f;
@@
- my_cpgenv(a, b, c, d, e, f)
+ my_cpgenv(pg, menu, a, b, c, d, e, f)
@@
expression a, b, c;
@@
- get_dstring(a, b, c)
+ get_dstring(menu, a, b, c)
@@
expression a,b,c,d;
@@
- list_menus(a, b, c, d)
+ list_menus(menu, a, b, c, d)
@@
@@
- popconfig()
+ popconfig(pg)
@@
@@
- pushconfig()
+ pushconfig(pg)
@@
expression a;
@@
- put_command(a)
+ put_command(menu, a)
@@
@@
- load_fonts()
+ load_fonts(pg, menu)
@@
@@
- set_default()
+ set_default(pg)
@@
@@
- set_color()
+ set_color(pg, menu)
@@
@@
- set_layout()
+ set_layout(pg, menu)
@@
@@
- clear_command()
+ clear_command(menu)
@@
@@
- set_text()
+ set_text(pg, menu)
@@
@@
- get_plot_init_name()
+ get_plot_init_name(pg)
@@
@@
- list_par()
+ list_par(pg, menu)
@@
@@
- run_macro()
+ run_macro(menu)
@@
@@
- write_plotmac()
+ write_plotmac(pg, menu)
@@
@@
- drawing()
+ drawing(pg, menu)
@@
expression a,b;
@@
- yesno(a, b)
+ yesno(menu, a, b)
@@
expression a,b;
@@
- get_token(a, b)
+ get_token(menu, a, b)
@@
expression a,b;
@@
- get_string(a, b)
+ get_string(menu, a, b)
@@
expression a;
@@
- set_axis(a)
+ set_axis(pg, menu, a)
@@
@@
-xmin
+pg->xmin
@@
@@
-eptr
+pg->eptr
@@
@@
-xmax
+pg->xmax
@@
@@
-ymin
+pg->ymin
@@
@@
-ymax
+pg->ymax
@@
@@
-zmin
+pg->zmin
@@
@@
-zmax
+pg->zmax
@@
@@
-X
+X_CURRENT
@@
@@
-Y
+Y_CURRENT
@@
@@
-Z
+Z_CURRENT
@@
@@
-X_DEVICE
+pg->X_DEVICE
@@
@@
-PLOT_CURSORPOINTS
+pg->PLOT_CURSORPOINTS
@@
@@
-PLOT_ROWS
+pg->PLOT_ROWS
@@
@@
-PLOT_CURSORNPOINTS
+pg->PLOT_CURSORNPOINTS
@@
@@
-PS_DEVICE
+pg->PS_DEVICE
@@
@@
-psfilnam
+pg->psfilnam
@@
@@
-xptr
+pg->xptr
@@
@@
-yptr
+pg->yptr
@@
@@
-H_Y
+pg->H_Y
@@
@@
-NPLOTS
+pg->NPLOTS
@@
@@
-AXIS
+pg->AXIS
@@
@@
-DEF_ININAME
+pg->DEF_ININAME
@@
@@
-COLTEXT
+pg->COLTEXT
@@
@@
-NXSKIP
+pg->NXSKIP
@@
@@
-NYSKIP
+pg->NYSKIP
@@
@@
-XLABEL
+pg->XLABEL
@@
@@
-XLABSTRING
+pg->XLABSTRING
@@
@@
-XLABPOINTER
+pg->XLABPOINTER
@@
@@
-YLABEL
+pg->YLABEL
@@
@@
-YLABSTRING
+pg->XLABSTRING
@@
@@
-YLABPOINTER
+pg->YLABPOINTER
@@
@@
-XLOWERSC
+pg->XLOWERSC
@@
@@
-XUPPERSC
+pg->XUPPERSC
@@
@@
-YLOWERSC
+pg->YLOWERSC
@@
@@
-YUPPERSC
+pg->YUPPERSC
@@
@@
-ZLOWERSC
+pg->ZLOWERSC
@@
@@
-ZUPPERSC
+pg->ZUPPERSC
@@
@@
-PLOT_DEV
+pg->PLOT_DEV
@@
@@
-AUTOX
+pg->AUTOX
@@
@@
-AUTOY
+pg->AUTOY
@@
@@
-AUTOZ
+pg->AUTOZ
@@
@@
-XLOGSC
+pg->XLOGSC
@@
@@
-YLOGSC
+pg->YLOGSC
@@
@@
-XTICK
+pg->XTICK
@@
@@
-XSUBTICK
+pg->XSUBTICK
@@
@@
-YTICK
+pg->YTICK
@@
@@
-YSUBTICK
+pg->YSUBTICK
@@
@@
-ZTICK
+pg->ZTICK
@@
@@
-ZSUBTICK
+pg->ZSUBTICK
@@
@@
-XTITLE
+pg->XTITLE
@@
@@
-YTITLE
+pg->YTITLE
@@
@@
-ZTITLE
+pg->ZTITLE
@@
@@
-PTITLE
+pg->PTITLE
@@
@@
-NFONTS
+pg->NFONTS
@@
@@
-FONTNAME
+pg->FONTNAME
@@
@@
-DEFFONT
+pg->DEFFONT
@@
@@
-FONTFILL
+pg->FONTFILL
@@
@@
-CURVESTYLE
+pg->CURVESTYLE
@@
@@
-LINETHICKNESS
+pg->LINETHICKNESS
@@
@@
-H_HEIGHT
+pg->H_HEIGHT
@@
@@
-AXNAMSIZE
+pg->AXNAMSIZE
@@
@@
-AXNUMSIZE
+pg->AXNUMSIZE
@@
@@
-TITLESIZE
+pg->TITLESIZE
@@
@@
-TEXTSIZE
+pg->TEXTSIZE
@@
@@
-XBOX
+pg->XBOX
@@
@@
-YBOX
+pg->YBOX
@@
@@
-ZBOX
+pg->ZBOX
@@
@@
-XVIEW
+pg->XVIEW
@@
@@
-YVIEW
+pg->YVIEW
@@
@@
-ZVIEW
+pg->ZVIEW
@@
@@
-PAGEROT
+pg->PAGEROT
@@
@@
-PLOTWIDTH
+pg->PLOTWIDTH
@@
@@
-PLOTHEIGHT
+pg->PLOTHEIGHT
@@
@@
-XLENGTH
+pg->XLENGTH
@@
@@
-YLENGTH
+pg->YLENGTH
@@
@@
-AXESPAR
+pg->AXESPAR
@@
@@
-GRIDPAR
+pg->GRIDPAR
@@
@@
-SUBGRIDPAR
+pg->SUBGRIDPAR
@@
@@
-FRAMEPAR
+pg->SUBGRIDPAR
@@
@@
- TMP_COLTEXT
+ pg->TMP_COLTEXT
@@
@@
- TMP_BACK_COLOR
+ pg->TMP_BACK_COLOR
@@
@@
- TMP_H_Y
+ pg->TMP_H_Y
@@
@@
- TMP_CURVE_COLOR
+ pg->TMP_CURVE_COLOR
@@
@@
- TMP_AX_COLOR
+ pg->TMP_AX_COLOR
@@
@@
- TMP_TEXT_COLOR
+ pg->TMP_TEXT_COLOR
@@
@@
- TMP_H_HEIGHT
+ pg->TMP_H_HEIGHT
@@
@@
- TMP_H_OFFSET
+ pg->TMP_H_OFFSET
@@
@@
- TMP_PLOTWIDTH
+ pg->TMP_PLOTWIDTH
@@
@@
- TMP_PLOTHEIGHT
+ pg->TMP_PLOTHEIGHT
@@
@@
- TMP_XLENGTH
+ pg->TMP_XLENGTH
@@
@@
- TMP_YLENGTH
+ pg->TMP_YLENGTH
@@
@@
- TMP_AXESPAR
+ pg->TMP_AXESPAR
@@
@@
- TMP_AXESCHAR
+ pg->TMP_AXESCHAR
@@
@@
- TMP_FRAMEPAR
+ pg->TMP_FRAMEPAR
@@
@@
- TMP_GRIDPAR
+ pg->TMP_GRIDPAR
@@
@@
- TMP_SUBGRIDPAR
+ pg->TMP_SUBGRIDPAR
@@
@@
- TMP_PAGEROT
+ pg->TMP_PAGEROT
@@
@@
- TMP_XBOX
+ pg->TMP_XBOX
@@
@@
- TMP_YBOX
+ pg->TMP_YBOX
@@
@@
- TMP_ZBOX
+ pg->TMP_ZBOX
@@
@@
- TMP_XVIEW
+ pg->TMP_XVIEW
@@
@@
- TMP_YVIEW
+ pg->TMP_YVIEW
@@
@@
- TMP_ZVIEW
+ pg->TMP_ZVIEW
@@
@@
- TMP_NXSKIP
+ pg->TMP_NXSKIP
@@
@@
- TMP_NYSKIP
+ pg->TMP_NYSKIP
@@
@@
- TMP_AXNAMSIZE
+ pg->TMP_AXNAMSIZE
@@
@@
- TMP_AXNUMSIZE
+ pg->TMP_AXNUMSIZE
@@
@@
- TMP_TITLESIZE
+ pg->TMP_TITLESIZE
@@
@@
- TMP_TEXTSIZE
+ pg->TMP_TEXTSIZE
@@
@@
- TMP_X_TEXT
+ pg->TMP_X_TEXT
@@
@@
- TMP_Y_TEXT
+ pg->TMP_Y_TEXT
@@
@@
- TMP_MULTIPLOT
+ pg->TMP_MULTIPLOT
@@
@@
- TMP_PLOT_ROWS
+ pg->TMP_PLOT_ROWS
@@
@@
- TMP_PLOT_COLUMNS
+ pg->TMP_PLOT_COLUMNS
@@
@@
- TMP_FIRST_MULTI
+ pg->TMP_FIRST_MULTI
@@
@@
- TMP_XSHIFTT
+ pg->TMP_XSHIFTT
@@
@@
- TMP_YSHIFTT
+ pg->TMP_YSHIFTT
@@
@@
- CURVE_COLOR
+ pg->CURVE_COLOR
@@
@@
- H_OFFSET
+ pg->H_OFFSET
@@
@@
- AXESCHAR
+ pg->AXESCHAR
@@
@@
- X_TEXT
+ pg->X_TEXT
@@
@@
- Y_TEXT
+ pg->Y_TEXT
@@
@@
- MULTIPLOT
+ pg->MULTIPLOT
@@
@@
- FIRST_MULTI
+ pg->FIRST_MULTI
@@
@@
- XSHIFTT
+ pg->XSHIFTT
@@
@@
- YSHIFTT
+ pg->YSHIFTT
@@
@@
- TMP_pg
+ pg
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 10:47 ` picca
@ 2026-11-12 12:12 ` Victor Gambier
2026-11-12 12:26 ` picca
2026-11-12 12:36 ` Markus Elfring
1 sibling, 1 reply; 14+ messages in thread
From: Victor Gambier @ 2026-11-12 12:12 UTC (permalink / raw)
To: picca, Julia Lawall; +Cc: cocci
Thanks. What command are you running to get this error?
Victor
On 11/12/26 11:47, picca wrote:
> here it is
>
> Fred
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 12:12 ` Victor Gambier
@ 2026-11-12 12:26 ` picca
2026-11-12 12:29 ` Victor Gambier
0 siblings, 1 reply; 14+ messages in thread
From: picca @ 2026-11-12 12:26 UTC (permalink / raw)
To: Victor Gambier; +Cc: Julia Lawall, cocci
Le 2026-11-12 13:12, Victor Gambier a écrit :
> Thanks. What command are you running to get this error?
>
> Victor
>
> On 11/12/26 11:47, picca wrote:
>> here it is
>>
>> Fred
>>
spatch --in-place --sp-file reffactoring.cocci ana_read.c
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 12:26 ` picca
@ 2026-11-12 12:29 ` Victor Gambier
2026-11-12 12:36 ` picca
2026-11-12 14:10 ` picca
0 siblings, 2 replies; 14+ messages in thread
From: Victor Gambier @ 2026-11-12 12:29 UTC (permalink / raw)
To: picca; +Cc: Julia Lawall, cocci
Thank you. I cannot reproduce the error. Could you send me the file
"hkl/ccan/array_size/array_size.h", as well as the output of `spatch
--version`?
Victor
On 11/12/26 13:26, picca wrote:
> Le 2026-11-12 13:12, Victor Gambier a écrit :
>> Thanks. What command are you running to get this error?
>>
>> Victor
>>
>> On 11/12/26 11:47, picca wrote:
>>> here it is
>>>
>>> Fred
>>>
>
>
> spatch --in-place --sp-file reffactoring.cocci ana_read.c
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 12:29 ` Victor Gambier
@ 2026-11-12 12:36 ` picca
2026-11-12 14:10 ` picca
1 sibling, 0 replies; 14+ messages in thread
From: picca @ 2026-11-12 12:36 UTC (permalink / raw)
To: Victor Gambier; +Cc: Julia Lawall, cocci
[-- Attachment #1: Type: text/plain, Size: 608 bytes --]
Le 2026-11-12 13:29, Victor Gambier a écrit :
> Thank you. I cannot reproduce the error. Could you send me the file
> "hkl/ccan/array_size/array_size.h", as well as the output of `spatch
> --version`?
>
> Victor
here it is :)
$ spatch --version
spatch version 1.3 compiled with OCaml version 5.3.0
Flags passed to the configure script: --prefix=/usr --sysconfdir=/etc
--libdir=/usr/lib --enable-ocaml --enable-python --with-python=python3
--enable-opt
OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: Str
Debian stable.
I will test on Debian unstable also
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: array_size.h --]
[-- Type: text/x-c; name=array_size.h, Size: 907 bytes --]
/* CC0 (Public domain) - see LICENSE file for details */
#ifndef CCAN_ARRAY_SIZE_H
#define CCAN_ARRAY_SIZE_H
#include <hkl/ccan/ccan_config.h>
#include <hkl/ccan/build_assert/build_assert.h>
/**
* ARRAY_SIZE - get the number of elements in a visible array
* @arr: the array whose size you want.
*
* This does not work on pointers, or arrays declared as [], or
* function parameters. With correct compiler support, such usage
* will cause a build error (see build_assert).
*/
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr))
#if HAVE_BUILTIN_TYPES_COMPATIBLE_P && HAVE_TYPEOF
/* Two gcc extensions.
* &a[0] degrades to a pointer: a different type from an array */
#define _array_size_chk(arr) \
BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \
typeof(&(arr)[0])))
#else
#define _array_size_chk(arr) 0
#endif
#endif /* CCAN_ALIGNOF_H */
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 10:47 ` picca
2026-11-12 12:12 ` Victor Gambier
@ 2026-11-12 12:36 ` Markus Elfring
2026-11-12 12:41 ` picca
1 sibling, 1 reply; 14+ messages in thread
From: Markus Elfring @ 2026-11-12 12:36 UTC (permalink / raw)
To: Frédéric-Emmanuel Picca, cocci; +Cc: Julia Lawall, Victor Gambier
> here it is
Are the attached source files and the mentioned SmPL script stored in a public development repository?
Regards,
Markus
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 12:36 ` Markus Elfring
@ 2026-11-12 12:41 ` picca
0 siblings, 0 replies; 14+ messages in thread
From: picca @ 2026-11-12 12:41 UTC (permalink / raw)
To: Markus Elfring; +Cc: cocci, Julia Lawall, Victor Gambier
Le 2026-11-12 13:36, Markus Elfring a écrit :
>> here it is
>
> Are the attached source files and the mentioned SmPL script stored in a
> public development repository?
>
> Regards,
> Markus
Yes here
http://repo.or.cz/hkl
take the pu-anarod branch and look under the anarod directory
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 12:29 ` Victor Gambier
2026-11-12 12:36 ` picca
@ 2026-11-12 14:10 ` picca
2026-11-12 14:43 ` Julia Lawall
2026-11-12 14:44 ` Julia Lawall
1 sibling, 2 replies; 14+ messages in thread
From: picca @ 2026-11-12 14:10 UTC (permalink / raw)
To: Victor Gambier; +Cc: Julia Lawall, cocci
Le 2026-11-12 13:29, Victor Gambier a écrit :
> Thank you. I cannot reproduce the error. Could you send me the file
> "hkl/ccan/array_size/array_size.h", as well as the output of `spatch
> --version`?
>
> Victor
>
If I rename the INLINE global variable into -> inlines, the error goes
away.
capital letters issue ?
Fred
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 14:10 ` picca
@ 2026-11-12 14:43 ` Julia Lawall
2026-11-12 14:44 ` Julia Lawall
1 sibling, 0 replies; 14+ messages in thread
From: Julia Lawall @ 2026-11-12 14:43 UTC (permalink / raw)
To: picca; +Cc: Victor Gambier, cocci
[-- Attachment #1: Type: text/plain, Size: 437 bytes --]
On Thu, 12 Nov 2026, picca wrote:
> Le 2026-11-12 13:29, Victor Gambier a écrit :
> > Thank you. I cannot reproduce the error. Could you send me the file
> > "hkl/ccan/array_size/array_size.h", as well as the output of `spatch
> > --version`?
> >
> > Victor
> >
>
> If I rename the INLINE global variable into -> inlines, the error goes away.
>
> capital letters issue ?
I doubt it. But try what I suggested with standard.h
julia
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 14:10 ` picca
2026-11-12 14:43 ` Julia Lawall
@ 2026-11-12 14:44 ` Julia Lawall
1 sibling, 0 replies; 14+ messages in thread
From: Julia Lawall @ 2026-11-12 14:44 UTC (permalink / raw)
To: picca; +Cc: Victor Gambier, cocci
[-- Attachment #1: Type: text/plain, Size: 404 bytes --]
On Thu, 12 Nov 2026, picca wrote:
> Le 2026-11-12 13:29, Victor Gambier a écrit :
> > Thank you. I cannot reproduce the error. Could you send me the file
> > "hkl/ccan/array_size/array_size.h", as well as the output of `spatch
> > --version`?
> >
> > Victor
> >
>
> If I rename the INLINE global variable into -> inlines, the error goes away.
>
> capital letters issue ?
At least try INLINES
julia
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 10:40 ` Julia Lawall
2026-11-12 10:47 ` picca
@ 2026-11-12 14:51 ` picca
2026-11-12 14:55 ` Julia Lawall
1 sibling, 1 reply; 14+ messages in thread
From: picca @ 2026-11-12 14:51 UTC (permalink / raw)
To: Julia Lawall; +Cc: cocci
> Alternatively, if it's easier, could you retry after removing the
> following line from standard.h:
>
> #define INLINE inline
>
> That looks problematic, but I'm not sure that that definition should be
> applied if there is not another parsing error in your code.
>
> julia
It works without this INLINE
-----------------------------------------------------------------------
Finished
-----------------------------------------------------------------------
diff =
--- ana_read.c
+++ /tmp/cocci-output-2311372-3e6202-ana_read.c
@@ -646,7 +646,7 @@ static void read_spec(Ana *ana)
sprintf(STRING,"x title %s break",XCOLNAME);
put_command(&ana->rod.menu, STRING);
- plotxye(x,y,e,1);
+ plotxye(&ana->pg, &ana->rod.menu, x, y, e, 1);
}
for(i = 0; i < ncolumns; i++)
@@ -988,7 +988,7 @@ static void read_srs(Ana *ana, int versi
{
sprintf(STRING,"x title %s break",XCOLNAME);
put_command(&ana->rod.menu, STRING);
- plotxye(x,y,e,1);
+ plotxye(&ana->pg, &ana->rod.menu, x, y, e, 1);
}
/* Get column number of y values */
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [cocci] Bug dans la parseur de coccinelle ?
2026-11-12 14:51 ` picca
@ 2026-11-12 14:55 ` Julia Lawall
0 siblings, 0 replies; 14+ messages in thread
From: Julia Lawall @ 2026-11-12 14:55 UTC (permalink / raw)
To: picca; +Cc: cocci
On Thu, 12 Nov 2026, picca wrote:
> > Alternatively, if it's easier, could you retry after removing the
> > following line from standard.h:
> >
> > #define INLINE inline
> >
> > That looks problematic, but I'm not sure that that definition should be
> > applied if there is not another parsing error in your code.
> >
> > julia
>
> It works without this INLINE
Thanks for the feedback, which is very helpful.
I will try to fix it.
julia
>
> -----------------------------------------------------------------------
> Finished
> -----------------------------------------------------------------------
> diff =
> --- ana_read.c
> +++ /tmp/cocci-output-2311372-3e6202-ana_read.c
> @@ -646,7 +646,7 @@ static void read_spec(Ana *ana)
>
> sprintf(STRING,"x title %s break",XCOLNAME);
> put_command(&ana->rod.menu, STRING);
> - plotxye(x,y,e,1);
> + plotxye(&ana->pg, &ana->rod.menu, x, y, e, 1);
> }
>
> for(i = 0; i < ncolumns; i++)
> @@ -988,7 +988,7 @@ static void read_srs(Ana *ana, int versi
> {
> sprintf(STRING,"x title %s break",XCOLNAME);
> put_command(&ana->rod.menu, STRING);
> - plotxye(x,y,e,1);
> + plotxye(&ana->pg, &ana->rod.menu, x, y, e, 1);
> }
>
> /* Get column number of y values */
>
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-11-12 14:56 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 10:34 [cocci] Bug dans la parseur de coccinelle ? picca
2026-11-12 10:40 ` Julia Lawall
2026-11-12 10:47 ` picca
2026-11-12 12:12 ` Victor Gambier
2026-11-12 12:26 ` picca
2026-11-12 12:29 ` Victor Gambier
2026-11-12 12:36 ` picca
2026-11-12 14:10 ` picca
2026-11-12 14:43 ` Julia Lawall
2026-11-12 14:44 ` Julia Lawall
2026-11-12 12:36 ` Markus Elfring
2026-11-12 12:41 ` picca
2026-11-12 14:51 ` picca
2026-11-12 14:55 ` Julia Lawall
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.