home *** CD-ROM | disk | FTP | other *** search
- /* t2f.c - program to convert text file to binary file for tdp */
-
- #include <stdio.h>
- #include "ffp.h"
- #define MAXLINE 80
-
- main(argc,argv)
- char *argv[];
- int argc;
- {
- int i, nx, ny, debug;
- char line[80];
- FFP zd;
- FILE *f_in, *f_out, *fopen();
-
- if (argc<4) {
- printf("usage: t2f nx ny file");
- printf(" where nx(ny) is the number of columns(rows) in the data");
- printf(" array to be written. 'file' is the name of a text file");
- printf(" containing nx*ny lines. The lines must start with a");
- printf(" number (which is the data to be written in binary)\n");
- exit(1);
- }
- debug = argc>4;
- nx = atoi(argv[1]); ny = atoi(argv[2]);
-
- f_in= fopen(argv[3],"r");
- if (!f_in)
- {printf("can't open input file\n"); exit(1);}
-
- f_out = fopen("t2f.out","w");
- if (!f_out)
- {printf("can't open output file\n"); exit(1);}
-
- (void)fwrite((char *)&nx,4,1,f_out);
- (void)fwrite((char *)&ny,4,1,f_out);
- if (debug) printf("%d\t%d\n", nx, ny);
-
- for (i=0; i<nx*ny; i++) {
- (void)fgets(line, MAXLINE, f_in);
- zd = atoFFP(line);
- if (debug) printf("%f\t", zd);
- (void)fwrite((char *)&zd,4,1,f_out);
- }
- printf("%d floats written to t2f.out\n", i);
-
- fclose(f_in);
- fclose(f_out);
- return(0);
- }
-