#include #include #include #define flt float void stop_on_error(const char *msg, int error_num) { printf(" %s\n",msg); printf(" Stopping Program!\n"); exit(error_num); } int f_read_hdr(FILE *infile,int expected_bytes) { int number_in_rec; return 0; if ((fread(&number_in_rec,sizeof(int),1,infile)) != 1) \ stop_on_error(" Error reading input file!",2); if (number_in_rec < expected_bytes) \ stop_on_error(" Less than expected amount of data in record in input file!",3); } main() { int ni,nj,nk,ntot,i,j,ii; flt *func,*xy,x,y,dx,dy,xrange=1.,yrange=1.; flt fmin,fmax; char answer[256],cmd[256]; char infile_name[256]; FILE *infile; char plotfile_name[256]="gnuplot_plotfile"; FILE *plotfile; char cmdfile_name[256]="gnuplot_commandfile"; FILE *cmdfile; printf(" This program will convert a Plot3D\n"); printf(" file into a pair of files suitable for use with GNUplot\n"); printf(" \n"); #ifdef NOT printf(" It will also optionally use GNUplot to plot the files.\n"); #endif /* Open the output files for write access */ if ( (plotfile=fopen(plotfile_name,"w+")) == NULL) \ stop_on_error("Error trying to open the output plotting file!",10); if ( (cmdfile=fopen(cmdfile_name,"w+")) == NULL) \ stop_on_error("Error trying to open the output command file!",11); printf("\n Please Enter the Plot3D format input file name: "); scanf("%s",infile_name); if ( (infile=fopen(infile_name,"r")) == NULL) \ stop_on_error("Error trying to open the input file!",1); /* Read the header for the input file */ /* f_read_hdr(infile,3*sizeof(int)); fread(&ni,sizeof(int),1,infile); fread(&ni,sizeof(int),1,infile); fread(&nj,sizeof(int),1,infile); fread(&nk,sizeof(int),1,infile); f_read_hdr(infile,3*sizeof(int)); */ fscanf(infile,"%d",&ni); fscanf(infile,"%d",&nj); nk=1; /*fscanf(infile,"%d",&nk);*/ printf("\n Dimensions of input file: NI:%6.0d NJ:%6.0d NK:%6.0d\n",ni,nj,nk); ntot = ni*nj*nk; func = (flt *)malloc(sizeof(flt)*ntot); xy = (flt *)malloc(sizeof(flt)*ntot*2); /* Read the function from the input file */ /* f_read_hdr(infile,ntot*sizeof(flt)); fread(func,sizeof(flt),ntot,infile); f_read_hdr(infile,ntot*sizeof(flt)); */ ii = 0; fmin=(1e10); fmax=(-1e10); for (j=0; j fmax)fmax=func[ii]; ii++; } } printf("%g %g\n",fmin,fmax); /* Calculate an X and Y array */ dx = xrange/((flt)(ni-1)); dy = yrange/((flt)(nj-1)); for (j=0; j