int hms2degs_batch(char *inname, char *outname) { int no_error = 1; /* Flag set to 0 on error */ int nlines,ncol; /* Number of lines and columns in the input file */ double alphadeg; /* RA in decimal format */ double deltadeg; /* Dec in decimal format */ char line[MAXC]; /* General string for reading input */ char newname[MAXC]; /* New name for output file */ Skypos skypos; /* First sky position entered */ FILE *ifp=NULL; /* Optional input file */ FILE *ofp=NULL; /* Optional output file */ /* * Open the input file */ if(!(ifp = open_readfile(inname))) { fprintf(stderr,"ERROR: calc_skypos.\n"); return 1; } /* * Open the output file if one is desired */ if(outname == NULL) { printf("\nEnter name of output file if one is desired or\n"); printf("just hit return for no output file: [no output file] "); fgets(line,MAXC,stdin); if(line[0] != '\n') { while(sscanf(line,"%s",newname) != 1) { fprintf(stderr,"ERROR: Bad input. Enter filename again: "); fgets(line,MAXC,stdin); } if(!(ofp = open_writefile(newname))) no_error = 0; } } else { if(!(ofp = open_writefile(outname))) no_error = 0; } /* * Count the number of lines in the input file */ if(no_error) { if((nlines = n_lines(ifp,'!')) == 0) { fprintf(stderr,"ERROR. %s has no valid data lines.\n",inname); no_error = 0; } else { printf("\nRead %d lines from %s\n",nlines,inname); rewind(ifp); } } /* * Print out header */ if(ofp) { fprintf(ofp,"# Object alpha delta \n"); fprintf(ofp,"#---------- ---------- -----------\n"); } else { printf("\n Object alpha delta \n"); printf("---------- ----------- -----------\n"); } /* * Now cycle through the input file, reading in a pair of coordinates * for each line and calculating the offset between them. */ while(fgets(line, MAXC, ifp) != NULL && no_error) { if(line[0] != '!' && line[0] != '#') { ncol = sscanf(line,"%s %d %d %lf %d %d %lf", skypos.label,&skypos.hr,&skypos.min,&skypos.sec, &skypos.deg,&skypos.amin,&skypos.asec); if(ncol != 7) { fprintf(stderr,"\n"); fprintf(stderr,"ERROR. Bad input file format.\n"); fprintf(stderr,"This program requires the following format:\n"); fprintf(stderr," label rahr ramin rasec decdeg decmin decsec.\n"); fprintf(stderr,"Found %d columns instead of the expected 7\n",ncol); fprintf(stderr,"The line causing the error was %s\n",line); fprintf(stderr,"\n"); no_error = 0; } if(no_error) { /* * Convert to decimal degrees */ spos2deg(skypos,&alphadeg,&deltadeg); /* * Print out the offsets */ if(ofp) fprintf(ofp,"%-12s %11.7f %11.7f\n",skypos.label,alphadeg,deltadeg); else printf("%-12s %11.7f %11.7f\n",skypos.label,alphadeg,deltadeg); } } } /* * Clean up and exit */ if(ifp) fclose(ifp); if(ofp) fclose(ofp); if(no_error) { printf("\nExiting program hms2degs.c\n\n"); return 0; } else { fprintf(stderr,"ERROR: hms2degs_batch\n"); return 1; } }
int main(int argc, char *argv[]) { int i; /* Looping variable */ int no_error=1; /* Flag set to 0 on error */ int nlines=0; /* Number of data lines in lens input file */ int ncompos; /* Number of points in composite curve */ int flagbad=1; /* Flag set to 1 for bad day flagging */ int errtype=0; /* 1 ==> include fracrms in errors */ int ndeg; /* Degree of fitting function */ int nbad[N08]; /* Number of bad days in bad day file */ int shiftind; /* Curve excluded from composite */ float fracrms; /* Fractional rms scatter in 1634/1635 ratio */ float tmin,tmax; /* Min and max times used for fit */ float meanrms; /* RMS about mean for residual curve */ float bestlag; /* Lag giving lowest reduced chisq */ float mean[N08]; /* Means of the 4 light curves */ float *flat=NULL; /* "Flat field" light curve */ float *a=NULL; /* Coefficients of fitting function */ char line[MAXC]; /* General string for reading input */ char lensfile[MAXC]; /* Input file name for 1608 data */ char calfile[MAXC]; /* Input file name for 1634 and 1635 data */ Fluxrec *fl08[N08]={NULL}; /* Raw 1608 light curves */ Fluxrec *ff08[N08]={NULL}; /* Flat-fielded 1608 light curves */ Fluxrec *fl34=NULL; /* 1634 light curve */ Fluxrec *fl35=NULL; /* 1635 light curve */ Fluxrec *compos=NULL; /* Composite curve created from 3 light curves */ FILE *lfp=NULL; /* 1608 data file pointer */ FILE *cfp=NULL; /* 1634/1635 data file pointer */ /* * Check input line */ if(argc < 3) { fprintf(stderr,"\nUsage: fit_1_to_3 [1608 filename] [1634/1635 filename]"); fprintf(stderr,"\n\n"); return 1; } /* * Open 1608 and secondary calibrator files. */ strcpy(lensfile,argv[1]); strcpy(calfile,argv[2]); if(!(lfp = open_readfile(lensfile))) no_error = 0; if(!(cfp = open_readfile(calfile))) no_error = 0; /* * First count the number of data input lines in order to set * sizes of arrays. */ if(no_error) nlines = n_lines(lfp,'#'); if(nlines == 0) no_error = 0; else if(nlines != n_lines(cfp,'#')) { fprintf(stderr, "ERROR. Number of lines in lens and cal files don't match.\n"); no_error = 0; } else { printf("\n%d data lines in lens and cal input files.\n\n",nlines); rewind(lfp); rewind(cfp); } /* * Allocate arrays */ if(no_error) for(i=0; i<N08; i++) { if(!(fl08[i] = new_fluxrec(nlines))) no_error = 0; } if(no_error) if(!(fl34 = new_fluxrec(nlines))) no_error = 0; if(no_error) if(!(fl35 = new_fluxrec(nlines))) no_error = 0; /* * Read in data */ if(no_error) if(read_data(fl34,fl35,fl08,nlines,lfp,cfp)) no_error = 0; /* * See if bad-day flagging is requested */ if(no_error) { printf("Flag bad days? (1/0) [%d] ",flagbad); fgets(line,MAXC,stdin); if(line[0] != '\n') { while(sscanf(line,"%d",&flagbad) != 1 || flagbad < 0) { fprintf(stderr,"ERROR: bad input. Enter value again: "); fgets(line,MAXC,stdin); } } } /* * Flag bad days, if requested */ if(flagbad && no_error) { if(flag_bad(fl34,fl35,fl08,nlines,&flagbad,"badday.list",nbad)) { no_error = 0; } else { if(flagbad == 2) printf("Bad days flagged: %d %d %d %d\n",nbad[0],nbad[1],nbad[2], nbad[3]); else printf("Bad days flagged: %d\n",nbad[0]); } } /* * Make the "flat field" curve */ if(no_error) if(!(flat = make_flat(fl34,fl35,nlines))) no_error = 0; /* * Set error determination */ if(no_error) { printf("\nEnter choice of error determination\n"); printf(" 0. RMS noise in map only\n"); printf(" 1. Include fractional RMS from 1634/1635 ratio\n"); printf("Choice? [%d] ",errtype); fgets(line,MAXC,stdin); if(line[0] != '\n') { while(sscanf(line,"%d",&errtype) != 1 || errtype < 0) { fprintf(stderr,"ERROR: Bad input. Enter new value: "); fgets(line,MAXC,stdin); } } } /* * Calculate fractional error in 1634/1635 flux ratio */ if(no_error) { if(errtype == 0) fracrms = 0.0; else if(ratio_err(fl34,fl35,nlines,&fracrms)) no_error = 0; } /* * Flat field the 1608 light curves */ if(no_error) { for(i=0; i<N08; i++) { if(!(ff08[i] = flat_field(fl08[i],flat,nlines,fracrms,NULL,0))) no_error = 0; } } /* * Set the curve means to their default values */ mean[0] = AMEAN; mean[1] = BMEAN; mean[2] = CMEAN; mean[3] = DMEAN; /* * Create the three-curve composite */ if(no_error) if(!(compos = compos_3(ff08,nlines,nbad,&ncompos,&shiftind))) no_error = 0; /* * Get tmin and tmax from compos, which is easy since it is sorted */ if(no_error) { tmin = compos[0].day; tmax = compos[ncompos-1].day; printf("tmin = %6.2f, tmax = %6.2f\n",tmin,tmax); } /* * Open the plot */ if(no_error) plot_open(1.5); /* * Fit a function to the composite curve */ if(no_error) if(!(a = fit_compos(compos,ncompos,&ndeg))) no_error = 0; /* * Summarize results */ printf("\nUsing a fit of degree %d\n",ndeg); /* * Find and plot residuals */ if(no_error) if(plot_resid(compos,ncompos,a,ndeg+1,&meanrms)) no_error = 0; /* * Now shift the free curve in steps along the composite curve and * create a new composite curve from the free + old composite. * Calculate a reduced chisq at each step by comparing the new composite * with the fitted function. */ if(no_error) if(find_best_shift(ff08[shiftind],nlines,a,ndeg+1,meanrms,1.0,tmin,tmax, &bestlag)) no_error = 1; /* * Plot out best fit */ if(no_error) if(plot_best_shift(ff08[shiftind],nlines,mean[shiftind],a,ndeg+1, tmin,tmax,bestlag)) no_error = 0; /* * Clean up */ if(no_error) printf("\nCleaning up\n\n"); plot_close(); a = del_array(a); fl34 = del_fluxrec(fl34); fl35 = del_fluxrec(fl35); compos = del_fluxrec(compos); for(i=0; i<4; i++) { fl08[i] = del_fluxrec(fl08[i]); ff08[i] = del_fluxrec(ff08[i]); } flat = del_array(flat); if(lfp) fclose(lfp); if(cfp) fclose(cfp); if(no_error) return 0; else { fprintf(stderr,"ERROR: Exiting program\n"); return 1; } }
static int process_file(char *fname,struct contig *ctg,int block_size,int fmt,u_int64_t *number,struct lk_compress *lkc) { int i,k,err,sz,nn; FILE *fptr; string *s; tokens *tok; void *tbuf; char *p,*p1; struct match m; struct contig *c; count *ct; u_int32_t x,x1; s=0; tok=0; tbuf=0; err=0; nn=(fmt==GEM_FMT?1:0); fptr=open_readfile(fname,&i,lkc); if(!fptr) return -1; printf("Reading matches file '%s'\n",fname); while(!err) { s=fget_string(fptr,s,&tbuf); if(!s->len) break; tok=tokenize(get_cstring(s),'\t',tok); if(tok->n_tok>=4+nn) { p=tok->toks[2+nn]; i=0; if(!isdigit(*p)) continue; while(*p && !err) { k=(int)strtol(p,&p1,10); i+=k; if(i>1) break; if(*p1) { if(*p1!=':' && *p1!='+') err=5; else p1++; } p=p1; if(!k && i) break; } if(err) { fprintf(stderr,"Bad format for match number column '%s'\n",tok->toks[3]); err=0; continue; } else if(i==1) { p=parse_match(tok->toks[3+nn],fmt,&m); if(!p) { /* err=10;*/ fprintf(stderr,"Bad format for match\n"); continue; } else { if(*number) { (*number)--; if(!(*number)) { err=1; break; } } HASH_FIND_STR(ctg,m.ctg,c); if(c) { sz=strlen(tok->toks[1]); ct=c->counts; x=m.pos-1; if(block_size>1) { if(m.orientation) { for(i=0; i<sz; i++) { if(x<c->size) { x1=x/block_size; x1*=block_size; if(ct[x1]<MAX_COUNT) ct[x1]++; } if(!x) break; x--; } } else { for(i=0; i<sz && x<c->size; i++) { x1=x/block_size; x1*=block_size; if(ct[x1]<MAX_COUNT) ct[x1]++; x++; } } } else { if(m.orientation) { for(i=0; i<sz; i++) { if(x<c->size) { if(ct[x]<MAX_COUNT) ct[x]++; } if(!x) break; x--; } } else { for(i=0; i<sz && x<c->size; i++) { if(ct[x]<MAX_COUNT) ct[x]++; x++; } } } if((ct=c->tcounts)) { x=m.pos-1; if(block_size>1) { if(m.orientation) { for(i=0; i<sz; i++) { if(x<c->tsize) { x1=x/block_size; x1*=block_size; if(ct[x1]<MAX_COUNT) ct[x1]++; } if(!x) break; x--; } } else { for(i=0; i<sz && x<c->tsize; i++) { x1=x/block_size; x1*=block_size; if(ct[x1]<MAX_COUNT) ct[x1]++; x++; } } } else { if(m.orientation) { for(i=0; i<sz; i++) { if(x<c->tsize) { if(ct[x]<MAX_COUNT) ct[x]++; } if(!x) break; x--; } } else { for(i=0; i<sz && x<c->tsize; i++) { if(ct[x]<MAX_COUNT) ct[x]++; x++; } } } } } } } } } fclose(fptr); if(s) free_string(s); if(tok) free_tokens(tok); if(tbuf) free_fget_buffer(&tbuf); signal(SIGCHLD,SIG_DFL); while(waitpid(-1,&i,WNOHANG)>0); return err; }
static void *read_det_cov(void *vd) { int i,err; FILE *fptr; string *s; tokens *tok; void *tbuf; char *p,*p1,cc,*fname; struct contig *c,*ctg; struct tdc_par *tp; count *ct,ct1,ct2; struct lk_compress *lkc; u_int32_t x; tp=vd; ctg=tp->ctg; lkc=tp->lkc; while((fname=get_input_file())) { s=0; tok=0; tbuf=0; err=0; fptr=open_readfile(fname,&i,lkc); if(!fptr) return 0; printf("Reading detailed coverage file '%s'\n",fname); c=0; ct=0; x=0; while(!err) { s=fget_string(fptr,s,&tbuf); if(!s->len) break; tok=tokenize(get_cstring(s),'\t',tok); if(tok->n_tok==2) { p=tok->toks[0]; if(*p=='>') { if(!c || strcmp(c->name,p+1)) { HASH_FIND_STR(ctg,p+1,c); } if(c) { p=tok->toks[1]; x=strtoul(p,&p1,10)-1; if(p==p1 || *p1) { err=10; fprintf(stderr,"(a) Bad file format\n"); } ct=c->counts; } } } else if(c) { if(tok->n_tok!=1) { fprintf(stderr,"(b) Bad file format\n"); err=-1; } p=tok->toks[0]; while(x<c->size && (cc=*p++)) { if(cc>=33 && cc<=125) { cc-=33; ct1=(count)cc; } else if(cc==126) { ct1=(count)strtoul(p,&p1,16); p=p1+1; } else { fprintf(stderr,"(c) Bad file format (%d) '%s'\n",cc,tok->toks[0]); err=-1; } if(!err) { pthread_mutex_lock(&c->mut); ct2=ct[x]; if(ct2<MAX_COUNT) { if(MAX_COUNT-ct2<ct1) ct[x]=MAX_COUNT; else ct[x]=ct2+ct1; } pthread_mutex_unlock(&c->mut); x++; } } } } fclose(fptr); if(s) free_string(s); if(tok) free_tokens(tok); if(tbuf) free_fget_buffer(&tbuf); signal(SIGCHLD,SIG_DFL); while(waitpid(-1,&i,WNOHANG)>0); } return 0; }
int setup_file(Image *image, Setup *setup, char *inname) { int no_error=1; /* Flag set to 0 on error */ float *contptr; /* Pointer to navigate setup->cont */ char keyword[MAXC]; /* Keyword at the beginning of each input line */ char line[MAXC]; /* General string for reading input */ char *cptr; /* Pointer to navigate line (for reading title) */ char *tptr; /* Pointer to navigate setup->title (for writing title) */ Pos *startptr; /* Pointer to starting positions of line segments */ Pos *endptr; /* Pointer to starting positions of line segments */ Labinfo *labptr; /* Pointer to navigate setup->intlabs */ Labinfo *circptr; /* Pointer to navigate setup->circle */ FILE *ifp=NULL; /* Input file pointer */ /* * Open input file */ if(!(ifp = open_readfile(inname))) { fprintf(stderr,"ERROR: setup_file.\n"); return 1; } /* * Read input from setup file. For quantities like the contour levels * and image labels that need to be put in arrays, count the number * of array members first. */ printf("\nReading setup info from file %s\n",inname); while(fgets(line,MAXC,ifp) != NULL && no_error) { if(line[0] >= 32 && line[0] != '#') { switch(read_setup_line(line,keyword)) { case SETUPERR: no_error = 0; break; case AXISCENT: if(sscanf(line,"%s %f %f",keyword,&setup->axcentx,&setup->axcenty) != 3) { fprintf(stderr,"ERROR: setup_file. Bad input for axiscent.\n"); fprintf(stderr," Axes will be centered in center of image.\n"); setup->axcentset = FALSE; } else setup->axcentset = TRUE; break; case BORDER: if(sscanf(line,"%s %d",keyword,&setup->border) != 2 && (setup->border < 0 || setup->border > 1)) { fprintf(stderr,"ERROR: setup_file. Bad input for border\n"); fprintf(stderr,"Taking border = 1\n"); setup->border = TRUE; } break; case CIRCLE: if(setup->ncircle == UNSET) setup->ncircle = 1; else setup->ncircle++; break; case CMUL: if(sscanf(line,"%s %f",keyword,&setup->cmul) != 2) { fprintf(stderr,"ERROR: setup_file. Bad input for cmul\n"); fprintf(stderr,"Taking cmul = 1.0\n"); setup->cmul = 1.0; } break; case COMPASS: if(sscanf(line,"%s %d",keyword,&setup->drawcompass) != 2 && (setup->drawcompass < 0 || setup->drawcompass > 1)) { fprintf(stderr,"ERROR: setup_file. Bad input for compass\n"); fprintf(stderr,"Taking compass = 0\n"); setup->drawcompass = FALSE; } break; case CONT: setup->docontour = TRUE; if(setup->ncont == UNSET) setup->ncont = 1; else setup->ncont++; break; case DRAW: if(setup->ndraw == UNSET) setup->ndraw = 1; else setup->ndraw++; break; case FRANGE: if(sscanf(line,"%s %f %f",keyword,&setup->lo,&setup->hi) != 3) { fprintf(stderr,"ERROR: setup_file. Bad input for frange\n"); setup->lo = 0.0; setup->hi = 0.0; } break; case IMCENT: if(sscanf(line,"%s %f %f",keyword,&setup->centx,&setup->centy) != 3) { fprintf(stderr,"ERROR: setup_file. Bad input for imcent.\n"); fprintf(stderr," Setting imcent to half of image size.\n"); setup->centx = setup->xsize / 2.0; setup->centy = setup->ysize / 2.0; setup->centset = TRUE; } else if(setup->centx < 1.0 || setup->centx > 1.0*image->nx) { fprintf(stderr,"ERROR: setup_file. Bad x value of imcent.\n"); fprintf(stderr," Setting x value to half of xsize.\n"); setup->centx = setup->xsize / 2.0; setup->centset = TRUE; } else if(setup->centy < 1.0 || setup->centy > 1.0*image->ny) { fprintf(stderr,"ERROR: setup_file. Bad y value of imcent.\n"); fprintf(stderr," Setting y value to half of ysize.\n"); setup->centy = setup->ysize / 2.0; setup->centset = TRUE; } else setup->centset = TRUE; break; case IMSIZE: if(sscanf(line,"%s %d %d",keyword,&setup->xsize,&setup->ysize) != 3) { fprintf(stderr,"ERROR: setup_file. Bad input for imsize.\n"); fprintf(stderr," Setting imsize to full image size.\n"); setup->xsize = image->nx; setup->ysize = image->ny; setup->sizeset = TRUE; } else { sprintf(line,"%d %d",setup->xsize,setup->ysize); if(check_imsize(image,setup,line,0)) { fprintf(stderr,"ERROR: setup_file.\n"); no_error = 0; } else setup->sizeset = TRUE; } break; case LAB: setup->dolabel = TRUE; if(setup->nintlab == UNSET) setup->nintlab = 1; else setup->nintlab++; break; case LABH: if(sscanf(line,"%s %f",keyword,&setup->labheight) != 2) { fprintf(stderr,"ERROR: setup_file. Bad input for labh\n"); fprintf(stderr,"Taking labh = 2.0\n"); setup->labheight = 2.0; } break; case LABW: if(sscanf(line,"%s %d",keyword,&setup->labwidth) != 2) { fprintf(stderr,"ERROR: setup_file. Bad input for labw\n"); fprintf(stderr,"Taking labw = 10\n"); setup->labwidth = 10; } break; case LWEIGHT: if(sscanf(line,"%s %d",keyword,&setup->lweight) != 2) { fprintf(stderr,"ERROR: setup_file. Bad input for lweight\n"); fprintf(stderr,"Taking lweight = 1\n"); setup->lweight = 1; } break; case MARK: if(sscanf(line,"%s %f %f",keyword,&setup->markx,&setup->marky) != 3) { fprintf(stderr,"ERROR: setup_file. Bad input -- marker position\n"); fprintf(stderr,"No marker will be drawn.\n"); setup->drawmarker = FALSE; } else { setup->drawmarker = TRUE; } break; case NOCONTOUR: setup->docontour = FALSE; break; case NOLABEL: setup->dolabel = FALSE; break; case PIXSCALE: if(sscanf(line,"%s %f",keyword,&setup->pixscale) != 2) { fprintf(stderr,"ERROR: setup_file. Bad input for pixel scale.\n"); setup->pixscale = 0.0; setup->pixset = UNSET; } else { setup->pixset = TRUE; } break; case PLOTWFPC: if(sscanf(line,"%s %d",keyword,&setup->plotwfpc) != 2 && setup->plotwfpc < 0) { fprintf(stderr,"ERROR: setup_file. Bad input for plotwfpc\n"); fprintf(stderr,"Taking plotwfpc = 0 (no overlay)\n"); setup->plotwfpc = 0; } break; case SLITMASK: if(sscanf(line,"%s %s",keyword,setup->slitfile) != 2) { fprintf(stderr,"ERROR: setup_file. Bad input for slitmask name\n"); sprintf(setup->slitfile,"#"); } break; case TITLE: if((cptr = strstr(line,"title")) == NULL && (cptr = strstr(line,"TITLE")) == NULL) fprintf(stderr,"ERROR: Title keyword not found in title line\n"); else { cptr += 6; while(*cptr == ' ') cptr++; tptr = setup->title; while(*cptr != '\n' && *cptr != '\0') { *tptr = *cptr; cptr++; tptr++; } *tptr = '\0'; } break; case TRANS: if(sscanf(line,"%s %d",keyword,&setup->trans) != 2 && (setup->trans < 0 || setup->trans > 2)) { fprintf(stderr,"ERROR: setup_file. Bad input for trans\n"); fprintf(stderr,"Taking trans = 0 (linear scaling)\n"); setup->trans = 0; } break; default: printf("***WARNING: Not yet taking file info for keyword %s.\n", keyword); } } } /* * Allocate arrays */ if(no_error && setup->ncont != UNSET) { if(!(setup->cont = new_array(setup->ncont,1))) no_error = 0; else { printf(" setup_file: Found %d contours in setup file.\n", setup->ncont); contptr = setup->cont; } } if(no_error && setup->nintlab != UNSET) { if(!(setup->intlabs = new_labinfo(setup->nintlab))) no_error = 0; else { printf(" setup_file: Found %d internal labels in setup file.\n", setup->nintlab); labptr = setup->intlabs; } } if(no_error && setup->ncircle != UNSET) { if(!(setup->circle = new_labinfo(setup->ncircle))) no_error = 0; else { printf(" setup_file: Found %d circle positions in setup file.\n", setup->ncircle); circptr = setup->circle; } } if(no_error && setup->ndraw != UNSET) { if(!(setup->drawstart = new_pos(setup->ndraw,1))) no_error = 0; else startptr = setup->drawstart; if(!(setup->drawend = new_pos(setup->ndraw,1))) no_error = 0; else endptr = setup->drawend; } /* * Fill the arrays and get other info */ rewind(ifp); while(fgets(line,MAXC,ifp) != NULL && no_error) { if(line[0] > 32 && line[0] != '#') { switch(read_setup_line(line,keyword)) { case SETUPERR: no_error = 0; break; case CIRCLE: switch(sscanf(line,"%s %f %f %f %s",keyword,&circptr->x,&circptr->y, &circptr->size,circptr->text)) { case 4: strcpy(circptr->text,""); circptr++; break; case 5: circptr++; break; default: no_error = 0; } break; case CONT: if(sscanf(line,"%s %f",keyword,contptr) != 2) no_error = 0; else { *contptr *= setup->cmul; contptr++; } break; case DRAW: if(sscanf(line,"%s %lf %lf %lf %lf",keyword,&startptr->x,&startptr->y, &endptr->x,&endptr->y) != 5) no_error = 0; else { startptr++; endptr++; } break; case LAB: if(sscanf(line,"%s %f %f %s",keyword,&labptr->x,&labptr->y, labptr->text) != 4) no_error = 0; else { labptr++; } break; default: break; } } } /* * Clean up and exit */ if(ifp) fclose(ifp); if(no_error) return 0; else { fprintf(stderr,"ERROR: setup_file\n"); return 1; } }