This is Unofficial EPICS BASE Doxygen Site
makeBpt.c File Reference
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include "dbDefs.h"
#include "ellLib.h"
#include "cvtTable.h"
+ Include dependency graph for makeBpt.c:

Go to the source code of this file.

Classes

struct  brkCreateInfo
 
struct  brkInt
 
struct  dataList
 

Macros

#define MAX_LINE_SIZE   160
 
#define MAX_BREAKS   100
 

Typedefs

typedef struct brkInt brkInt
 
typedef struct dataList dataList
 

Functions

int main (int argc, char **argv)
 

Variables

struct brkCreateInfo brkCreateInfo
 
brkInt brkint [MAX_BREAKS]
 

Macro Definition Documentation

#define MAX_BREAKS   100

Definition at line 28 of file makeBpt.c.

#define MAX_LINE_SIZE   160

Definition at line 27 of file makeBpt.c.

Typedef Documentation

typedef struct brkInt brkInt
typedef struct dataList dataList

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 79 of file makeBpt.c.

80 {
81  char *pbeg;
82  char *pend;
83  double value;
84  char *pname = NULL;
85  dataList *phead;
86  dataList *pdataList;
87  dataList *pnext;
88  double *pdata;
89  long ndata;
90  int nBreak,n;
91  size_t len;
92  char *outFilename;
93  char *pext;
94  FILE *outFile;
95  FILE *inFile;
96  char *plastSlash;
97 
98 
99  if(argc<2) {
100  fprintf(stderr,"usage: makeBpt file.data [outfile]\n");
101  exit(-1);
102  }
103  if (argc==2) {
104  plastSlash = strrchr(argv[1],'/');
105  plastSlash = (plastSlash ? plastSlash+1 : argv[1]);
106  outFilename = calloc(1,strlen(plastSlash)+2);
107  if(!outFilename) {
108  fprintf(stderr,"calloc failed\n");
109  exit(-1);
110  }
111  strcpy(outFilename,plastSlash);
112  pext = strstr(outFilename,".data");
113  if(!pext) {
114  fprintf(stderr,"Input file MUST have .data extension\n");
115  exit(-1);
116  }
117  strcpy(pext,".dbd");
118  } else {
119  outFilename = calloc(1,strlen(argv[2])+1);
120  if(!outFilename) {
121  fprintf(stderr,"calloc failed\n");
122  exit(-1);
123  }
124  strcpy(outFilename,argv[2]);
125  }
126  inFile = fopen(argv[1],"r");
127  if(!inFile) {
128  fprintf(stderr,"Error opening %s\n",argv[1]);
129  exit(-1);
130  }
131  outFile = fopen(outFilename,"w");
132  if(!outFile) {
133  fprintf(stderr,"Error opening %s\n",outFilename);
134  exit(-1);
135  }
136  while(fgets(inbuf,MAX_LINE_SIZE,inFile)) {
137  linenum++;
138  pbeg = inbuf;
139  while(isspace((int)*pbeg) && *pbeg!= '\0') pbeg++;
140  if(*pbeg == '!' || *pbeg == '\0') continue;
141  while(*pbeg!='"' && *pbeg!= '\0') pbeg++;
142  if(*pbeg!='"' ) errExit("Illegal Header");
143  pbeg++; pend = pbeg;
144  while(*pend!='"' && *pend!= '\0') pend++;
145  if(*pend!='"') errExit("Illegal Header");
146  len = pend - pbeg;
147  if(len<=1) errExit("Illegal Header");
148  pname = calloc(len+1,sizeof(char));
149  if(!pname) {
150  fprintf(stderr,"calloc failed while processing line %d\n",linenum);
151  exit(-1);
152  }
153  strncpy(pname,pbeg,len);
154  pname[len]='\0';
155  pbeg = pend + 1;
156  if(getNumber(&pbeg,&value)) errExit("Illegal Header");
157  brkCreateInfo.engLow = value;
158  if(getNumber(&pbeg,&value)) errExit("Illegal Header");
159  brkCreateInfo.rawLow = value;
160  if(getNumber(&pbeg,&value)) errExit("Illegal Header");
161  brkCreateInfo.engHigh = value;
162  if(getNumber(&pbeg,&value)) errExit("Illegal Header");
163  brkCreateInfo.rawHigh = value;
164  if(getNumber(&pbeg,&value)) errExit("Illegal Header");
165  brkCreateInfo.accuracy = value;
166  if(getNumber(&pbeg,&value)) errExit("Illegal Header");
167  brkCreateInfo.tblEngFirst = value;
168  if(getNumber(&pbeg,&value)) errExit("Illegal Header");
169  brkCreateInfo.tblEngLast = value;
170  if(getNumber(&pbeg,&value)) errExit("Illegal Header");
171  brkCreateInfo.tblEngDelta = value;
172  goto got_header;
173  }
174  errExit("Illegal Header");
175 got_header:
176  phead = pnext = 0;
177  ndata = 0;
178  errno = 0;
179  while(fgets(inbuf,MAX_LINE_SIZE,inFile)) {
180  double value;
181 
182  linenum++;
183  pbeg = inbuf;
184  while(!getNumber(&pbeg,&value)) {
185  ndata++;
186  pdataList = (dataList *)calloc(1,sizeof(dataList));
187  if(!pdataList) {
188  fprintf(stderr,"calloc failed (after header)"
189  " while processing line %d\n",linenum);
190  exit(-1);
191  }
192  if(!phead)
193  phead = pdataList;
194  else
195  pnext->next = pdataList;
196  pdataList->value = value;
197  pnext = pdataList;
198  }
199  }
200  if(!pname) {
201  errExit("create_break failed: no name specified\n");
202  }
203  brkCreateInfo.nTable = ndata;
204  pdata = (double *)calloc(brkCreateInfo.nTable,sizeof(double));
205  if(!pdata) {
206  fprintf(stderr,"calloc failed for table length %ld\n",brkCreateInfo.nTable);
207  exit(-1);
208  }
209  pnext = phead;
210  for(n=0; n<brkCreateInfo.nTable; n++) {
211  pdata[n] = pnext->value;
212  pdataList = pnext;
213  pnext = pnext->next;
214  free((void *)pdataList);
215  }
216  brkCreateInfo.pTable = pdata;
217  if(create_break(&brkCreateInfo,&brkint[0],MAX_BREAKS,&nBreak))
218  errExit("create_break failed\n");
219  fprintf(outFile,"breaktable(%s) {\n",pname);
220  for(n=0; n<nBreak; n++) {
221  fprintf(outFile,"\t%f %f\n",brkint[n].raw,brkint[n].eng);
222  }
223  fprintf(outFile,"}\n");
224  fclose(inFile);
225  fclose(outFile);
226  return(0);
227 }
double tblEngFirst
Definition: makeBpt.c:35
Definition: link.h:174
#define MAX_BREAKS
Definition: makeBpt.c:28
double tblEngDelta
Definition: makeBpt.c:37
double accuracy
Definition: makeBpt.c:34
double rawLow
Definition: makeBpt.c:32
long nTable
Definition: makeBpt.c:38
#define NULL
Definition: catime.c:38
#define MAX_LINE_SIZE
Definition: makeBpt.c:27
double engHigh
Definition: makeBpt.c:31
double engLow
Definition: makeBpt.c:30
double rawHigh
Definition: makeBpt.c:33
struct dataList * next
Definition: makeBpt.c:57
double value
Definition: makeBpt.c:58
double * pTable
Definition: makeBpt.c:40
#define stderr
Definition: epicsStdio.h:32
const std::string pname
double tblEngLast
Definition: makeBpt.c:36
brkInt brkint[MAX_BREAKS]
Definition: makeBpt.c:49

Variable Documentation

brkInt brkint[MAX_BREAKS]

Definition at line 49 of file makeBpt.c.