Hi everybody,
I have an input file called cond.inp
The file contains data in the form as follows:
Number:1 Species: first Concentration: 1.0e14 Density: 4.00 Molecular Weight: 1.0 Production Rate: 1.0 Saturation Vapor Pressure of material in the form Ps=exp(C-D/T)P: C=1.0 D=1.0 Surface Tension in the form A-BT(dyne/cm): A=1.0 B=0.0
Number:2 Species: second Concentration: 1.0e14 Density: 2.00 Molecular Weight: 1.0 Production Rate: 1.0 Saturation Vapor Pressure of material in the form Ps=exp(C-D/T)P: C=1.0 D=1.0 Surface Tension in the form A-BT(dyne/cm): A=1.0 B=0.0
Number:3 Species: third Concentration: 1.0e14 Density: 1.00 Molecular Weight: 1.0 Production Rate: 1.0 Saturation Vapor Pressure of material in the form Ps=exp(C-D/T)P: C=1.0 D=1.0 Surface Tension in the form A-BT(dyne/cm): A=1.0 B=0.0
Number:4 Species: fourth Concentration: 1.0e14 Density: 4.00 Molecular Weight: 1.0 Production Rate: 1.0 Saturation Vapor Pressure of material in the form Ps=exp(C-D/T)P: C=1.0 D=1.0 Surface Tension in the form A-BT(dyne/cm): A=1.0 B=0.0
As you can see there are a a number of lines that contains a series of names with values. Each line has the same format, although the length of the Species value is not set.
Could some please tell me how I can read the data into a series of arrays.
I have the following code and it works to some degree:
The code works for reading the first line of data. However I have tried to read the subsequent data in by repeating the Fscan statement seven times but the subsequent data values were not read by the code.Code://part of program that opens the required file FILE *fptr1; if((fptr1=fopen("cond.inp","r"))==NULL)//Opening the input file that contains property data for the aerosol material. { printf("Warning: Could not open file"); return(-1); } //Scanning the property data from the input file "cond.inp" fscanf(fptr1,"Number: %d Species: %c Concentration: %e Density: %lf Molecular Weight: %lf Production Rate: %lf Saturation Vapor Pressure: C=%lf D=%lf Surface Tension: A=%lf B=%lf ",&h,&conname[1],&conconc[1],&conrho[1],&conmw[1],&conprod[1],&C[1],&D[1],&A[1],&B[1]); fclose(fptr1);//Closing the main property data file.
Can I set up a loop to be repeated x number of times to read in the subsequent lines? (I will have to replace [1] by[h], where h is a number that changes from 1-7.
Also how do I read in the Species: as a series of characters (ie so the values first, second third etc are read not f, s, t etc)
Please help I am so sorry but I have searched through the faq and previous threads as well as the web but have not found an answer to my problem.
Many thanks,
Nick



LinkBack URL
About LinkBacks


