#include #include #include #include int main(int argc, char *argv[]) { // can handle up to a 8 column, 100000 line array int iter=0, nfound=0, s=0, Nc=8, len=100000, buflen=100, end, i, j ; // for the read file section char buffer[buflen], tempbuf[buflen], *junk; // a variable for the strings we read in int counter = 1, reclength, start,recordnum, totalrecs, counter2, working; double temper, x[Nc][len] ; FILE *inputfile; // a pointer to the input file /* set up the initial array , here reading from the file your pointing to in invocation */ FILE *outputfile; // a pointer to the output file inputfile = fopen(argv[1], "r"); // open input file // Before going on, make sure the input file opened properly if(inputfile != NULL) { outputfile = fopen(argv[3], "w"); // open output file // INPUT SECTION read the header; Nc (number of columns) // first, then totalrecs fgets(buffer, buflen, inputfile); Nc=atoi(buffer); fgets(buffer, buflen, inputfile); totalrecs=(int)strtod(buffer, &junk); //printf("number of columns of data is %5i and number of recs in this file is %5i\n", Nc, totalrecs); recordnum=atoi(argv[2]); /*here second argument is where to start reading input file */ if(recordnum<0){ printf("negative record request"); exit(1); }; if(recordnum>totalrecs){ printf("request is beyond EOF!"); exit(1); }; //PREPROCESSOR //start=(2*Nv+2)*recordnum; // starting line to read start=recordnum; end=totalrecs-start; //END OF PREPROCESSOR counter=0; // travel to start while(counter < start) { fgets(buffer, buflen, inputfile); counter++; } printf(" Initial record requested %5i\n",recordnum); // READ FROM START counter=0; //reset counter i=0; while (counter < end){ fgets(buffer, buflen, inputfile); counter2=0; j=0; i=0; while (buffer[i] != '\0') { if (buffer[i]==' ') { tempbuf[j]='\0'; if (j != 0) { x[counter2][counter]=strtod(tempbuf, &junk); //printf("%.18e\n", x[counter2][counter]); counter2++; j=0; } } else { tempbuf[j]=buffer[i]; j++; } i++; } if (j !=0) { tempbuf[j]='\0'; x[counter2][counter]=strtod(tempbuf, &junk); //printf("%.18e\n", x[counter2][counter]); counter2++; j=0; } else {} counter++; // THESE NEXT LINES ARE FOR TESTING THE READIN..POSTPROCESSING /* if (x[counter]*x[counter]+y[counter]*y[counter]+lambda*lambda > rtf0*rtf0) { mask[counter]=0.; }else(mask[counter]=1.0); */ // END OF POST PROCESSING THE READ. } // close the file fclose(inputfile); } else (printf("Error opening input file.\n")); // MAIN PROCESSING PROGRAM GOES HERE! // END OF MAIN PROCESSING PROGRAM //Write out to the data file section counter=0; while (counter< end) { //working=sprintf(buffer, 100, "%d", x[1][counter]); fprintf(outputfile, "%8.3f\n", x[1][counter]); counter++; } fclose(outputfile); //end of writeout section return 0; }