/* Teltro Data Convertor binary->text */ #include #include #include #include #include /* Open files mode=0 open inputfile. mode=1 open outputfile (text mode). */ FILE *OpenFileFun(char *fname, int mode) { FILE *opf; if (mode==0){ if ((opf=fopen(fname,"rb"))==NULL){ printf("Can't open %s\n",fname); exit(1); } else return opf; } else { if ((opf=fopen(fname,"wt"))==NULL){ printf("Can't create %s\n",fname); exit(1); } else return opf; } } /* Read data file */ long ReadData(FILE *fp, int nr, char *ort, int yoff) { char fst=0, snd=0; int bs=0; short hh =0, ll=0, x=0; long xx=0; if (strncmp(ort, "LSB", 3)==0) bs = 0; else bs= 1; if (nr==2){ fread(&fst, 1, 1, fp); fread(&snd, 1, 1, fp); if (bs==0){ ll = fst; ll = ll&0x00ff; hh = snd; hh = hh<< 8; hh = hh&0xff00; } else { ll = snd; ll = ll&0x00ff; hh = fst; hh = hh<< 8; hh = hh&0xff00; } x = (hh + ll); xx = (long) x; } else { fread(&fst, 1, 1, fp); xx = (long) fst; } return xx; } /* check output file permission. */ char *OutFileName(char *oname) { int cflag=0, sflag=0; do{ if (access(oname, F_OK)!=-1){ printf("%s already exist.\n",oname); printf("Overwrite ? (Y/other) "); rewind(stdin); cflag=getchar(); if (cflag=='y'||cflag=='Y'){ if (access(oname, W_OK)==-1){ printf("permission deny about %s. \n",oname); exit(1); } else sflag=1; } else { printf("new file name = ? "); scanf("%s", oname); } } else sflag=1; } while(sflag==0); return oname; } int main(int argc, char *argv[]) /* Labo data -> text */ { FILE *fpi, *fpo, *fpl; char name1[256]; char name2[256]; char name3[256]; long data1=0; int i=0,j=0,k=0,nro=0,fnum=0,kk=0; int byenr=0, bitnr=0, ptoff=0, yyy=3; unsigned int nrpt=0; double xincr=0, xzero=0, ymult=0, yzero=0, yoff=0; double xn=0, yn=0; char encdg[15]; char bnfmt[15]; char bytort[15]; char wfid[128]; char ptfmt[15]; char xunit[15]; char yunit[15]; char cblock[25]; char xketa[25]; if (argc<2) { printf("data file name = ? "); scanf("%s",name1); fnum=1; } else fnum=argc-1; for(kk=0; kk1){ strcpy(name1, argv[kk+1]); } fpi=OpenFileFun(name1,0); // strcpy(name2, name1); strcat(name2,".txt"); sprintf(name2, "%s.txt\0", name1); // strcpy(name3, name1); strcat(name3,".hed"); sprintf(name3, "%s.hed\0", name1); // strcpy(name2,OutFileName(name2)); sprintf(name2, "%s\0", OutFileName(name2)); // strcpy(name3,OutFileName(name3)); sprintf(name3, "%s\0", OutFileName(name3)); fpo=OpenFileFun(name2,1); fpl=OpenFileFun(name3,1); fscanf(fpi, ":WFMPRE:"); fscanf(fpi, "BYT_NR %d;", &byenr); fprintf(fpl, "BYT_NR = %d\n", byenr); fscanf(fpi, "BIT_NR %d;", &bitnr); fprintf(fpl, "BIT_NR = %d\n", bitnr); fscanf(fpi, "ENCDG %[^;]%*s", &encdg); fprintf(fpl, "ENCDG = %s\n", encdg); fscanf(fpi, "%[^;]%*s", &bnfmt); fprintf(fpl, "BN_FMT = %s\n", bnfmt); fscanf(fpi, "%[^;]%*s", &bytort); fprintf(fpl, "BYT_OR = %s\n", bytort); printf("%s", bytort); getchar(); fscanf(fpi, "%u%*s", &nrpt); fprintf(fpl, "NR_PT = %u\n", nrpt); fscanf(fpi, "%[^;]%*s", &wfid); fprintf(fpl, "WFID = %s\n", wfid); fscanf(fpi, "%[^;]%*s", &ptfmt); fprintf(fpl, "PT_FMT = %s\n", ptfmt); fscanf(fpi, "%lf%*s", &xincr); fprintf(fpl, "XINCR = %lg\n", xincr); fscanf(fpi, "%d%*s", &ptoff); fprintf(fpl, "PT_OFF = %d\n", ptoff); fscanf(fpi, "%lf%*s", &xzero); fprintf(fpl, "XZERO = %lg\n", xzero); fscanf(fpi, "%[^;]%*s", &xunit); fprintf(fpl, "XUNIT = %s\n", xunit); fscanf(fpi, "%lf%*s", &ymult); fprintf(fpl, "YMULT = %lg\n", ymult); fscanf(fpi, "%lf%*s", &yzero); fprintf(fpl, "YZERO = %lg\n", yzero); fscanf(fpi, "%lf%*s", &yoff); fprintf(fpl, "YOFF = %lg\n", yoff); fscanf(fpi, "%[^;]%*s", &yunit); fprintf(fpl, "YUNIT = %s\n", yunit); fscanf(fpi, " #"); fgets(xketa, 2, fpi); yyy=atoi(xketa); fprintf(fpl, "YYY = %u\n", yyy); fgets(cblock, yyy+1,fpi); fprintf(fpl, "CBLOCK = %s\n", cblock); printf("Convert %s to ASCII.\n", name1); printf("Number of data is %d.\n", nrpt); printf("Please hit hey ! \n"); rewind(stdin); getchar(); for (j=0; j