1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
* ctr2mtv.c - program to convert from contour-format data to plotmtv format
*/
#include <stdio.h>
#include <strings.h>
#include "CNplot.h"
static CNdslistptr dslisthead=NULL;
static CNdslistptr dslisttail=NULL;
static void usage();
static void read_ctrdata();
main(argc,argv)
int argc;
char **argv;
{
char progname[CN_MAXCHAR];
char outfile [CN_MAXCHAR];
char datafile[CN_MAXCHAR];
int xdrbinary=CN_FALSE;
int binary =CN_FALSE;
int FILEFOUND=CN_FALSE;
int i;
/* Initialize */
(void) strcpy(outfile ,"plot.mtv");
(void) strcpy(progname,argv[0]);
/* Parse the line first */
for (i=1; i<argc; i++) {
if (strncmp(argv[i],"-b",2) == 0) { /* binary data */
binary = CN_TRUE;
continue;
}
if (strcmp(argv[i],"-o") == 0) { /* output file */
if (++i >= argc) usage(progname);
(void) strcpy(outfile,argv[i]);
continue;
}
if (argv[i][0] != '-' && argv[i][0] != '=') { /* input file */
FILEFOUND = CN_TRUE;
(void) strcpy(datafile,argv[i]);
(void) fprintf(stdout,
"\nReading contour data from \"%s\"...\n",datafile);
read_ctrdata(datafile);
}
}
/* Serious syntax error */
if (!FILEFOUND) {
usage(progname);
(void) fprintf(stderr,"%s: Datafile has not been specified!\n",progname);
exit(-1);
}
/* If no datasets found */
if (dslisthead == NULL) {
(void) fprintf(stderr,"%s: Error! No data available!\n",progname);
exit(-1);
}
/* Message */
(void) fprintf(stdout,
"Writing %d datasets to \"%s\" in %s MTVDAT format...\n",
CNcount_dslists(dslisthead, dslisttail),
outfile, ((binary) ? "BINARY" : "ASCII"));
/*
* Print the data
*/
CNwrite_plotmtv(outfile,(FILE *)NULL,CN_FILE,
(CNdatasetptr) NULL, (CNdatasetptr) NULL,
&dslisthead,&dslisttail,binary,xdrbinary,0);
/* Stop */
(void) fprintf(stdout,"\n%s : Done!\n",progname);
exit(0);
}
/*
* Print out valid command line options
*/
static void usage(progname)
char *progname;
{
(void) fprintf(stderr,"%s [-b] [-o outfile] contourfile1 contourfile2...\n",progname);
exit(-1);
}
/*
* Read the datafile in contour format
*/
static void read_ctrdata(filename)
char *filename;
{
CNdatasetptr dptr;
/* Read the data from a file */
dptr = CNread_contour(filename,(FILE *)NULL,CN_FILE,
CN_FALSE, CN_FALSE,
CN_NONE, 0, 1, 0);
/* Add the dataset to the list */
if (dptr)
(void) CNinsert_dslist(&dslisthead, &dslisttail, dptr);
}
|