//ldis2007 - Linux equivalent of Dis2002.exe - CJC - 8/28/2007 //Developed with gcc on ubuntu 6.06 //choose subfolder, load support files, choose 2 db entries, gen html report, extensions #include #include #include #include //#define mxc = 260 char CMA[2] = ",";//allow extra byte for null terminator /*....0....+....0....+....0....+....0....+....0....+....0....+....0....+*/ char QS[2];char qt ='"';//QS[0]=qt;<--put in main()//(char) 34; char CRLF[4] = "\n\r";char ATPRS[8];//char *ATPRS="0.085/kwh"; char FE1[100];//FF1 seems to be a keyword! char FF2[100],FF3[100],FF4[100],FF5[100];//font face char TD1[100],TD2[100],TD3[100],TD4[100],TD5[100],TD6[100];//table data char TR1[100],TR2[100],TR3[100];//table row color char CK[800][800];char DB[800][800]; char str1[800],str2[800],temp2[40],temp3[40],hd1[5],hd2[9],hd3[7],he1[5],he2[9],he3[7]; char buf1[2];char rec3[80]; char FIL1[40],FIL2[40],FIL3[40],FIL4[40],FIL5[40]; char zero[2]="0";char TXT1S[78]; int i,j,k,SW = 1,count=0,I17=17,I41=41,debug=0; int COL,C00,C01,C02,C03,C04,C05,C06,C07,C08,C09,C10,C11; float PRICE,SCAL,SCA2,SCA3,KWH,TA[6],TB[260];double x,y,z; float A1[260],B1[260],C1[260],D1[260],E1[260],F1[260],G1[260],H1[260]; float A2[260],B2[260],C2[260],D2[260],E2[260],F2[260],G2[260],H2[260]; float A3[260],B3[260],C3[260],D3[260],E3[260],F3[260],G3[260],H3[260]; float A4[260],B4[260],C4[260],D4[260],E4[260],F4[260],G4[260],H4[260]; // chan, kwdem, lcum, hcum, amp, lcum, hcum, ser float BK[260],PF[260],LV[260],AL[260],AH[260]; FILE *fil1,*fil2,*fil3,*fil4,*fil5; struct{char h1[4];char h2[8];char h3[6]; char s01[41];char s02[41];char s03[41];char s04[41]; char s05[41];char s06[41];char s07[41];char s08[41]; char s09[41];char s10[41];char s11[41];char s12[41]; char s13[41];char s14[41];char s15[41];char s16[41];} dbln; struct{char c1[1];char n1[2];char c2[1];char n2[3]; char c3[1];char n3[5];char c4[1];char n4[5]; char c5[1];char n5[3];char c6[1];char n6[5]; char c7[1];char n7[5];char c8[1];char n8[5];} segm; // As if C was too bloated, itoa() was omitted from ANSI C. //itoa(Year,temp2,10); const char *itoa(int n, char *string, int m){//itoa(Hour,temp3,10); sprintf(string, "%d", n);return string;} const char *ftoa(float n, char *string, int m){//ftoa(PRICE,ATPRS,10); sprintf(string, "%.2f", n);return string;} //const char *frmt(char *string0, char *string, int m){//frmt(temp3,temp3,2); //strcpy(string,string0);strcat(string,"x"); //return string;} //double pow(double, double); /* Begin main program */ int main(int argc, char *argv[]){ // while(--argc>0) printf((argc>1)?"%s ":"%s\n",++argv); QS[0]=qt;debug=0; strcpy(hd1,argv[1]);//printf(" hd1 = %s\n", hd1);//causes seg fault if arg not present if(debug==1)printf("strlen hd1 = %d\n", strlen(hd1)); if(strlen(hd1)!=4){strcpy(hd1,"mm01");printf("Fixed hd1 = %s\n", hd1);}; if(strlen(hd1)!=4){printf("%s\n Invalid subfolder - s/b like mm01. ");exit(EXIT_FAILURE);}; if(debug==1)printf("\n\r subfolder ok "); //microdat global data strcpy(FIL1,hd1);strcat(FIL1,"/microdat.txt");//printf("\n\rFIL1 %s ",FIL1); fil1=fopen(FIL1,"r");//printf("\n fopen fil1= %d",fil1); k=fscanf(fil1,"%f",&SCAL);//str1);SCAL=atof(str1);printf("\n\r%s ",str1); k=fscanf(fil1,"%f",&SCA2); k=fscanf(fil1,"%f",&PRICE); k=fscanf(fil1,"%d",&COL); k=fscanf(fil1,"%d %d %d %d",&C00,&C01,&C02,&C03); k=fscanf(fil1,"%d %d %d %d",&C04,&C05,&C06,&C07); k=fscanf(fil1,"%d %d ",&C08,&C09,&C10,&C11); //printf("\n%f ",SCAL);printf("\n%f ",SCA2);printf("\n%f ",PRICE);printf("\n%d ",COL); //printf("\n%d %d %d %d ",C00,C01,C02,C03); //printf("\n%d %d %d %d ",C04,C05,C06,C07); //printf("\n%d %d %d %d ",C08,C09,C10,C11); fclose(fil1); //text line strcpy(FIL4,hd1);strcat(FIL4,"/micro.txt");//printf("\n\rFIL4 %s ",FIL4); fil4=fopen(FIL4,"r"); fgets( TXT1S, 70, fil4);//printf("\n\r%s ",TXT1S); fclose(fil4); if(debug==1)printf("\n\r micro dat,txt ok "); //ctdat strcpy(FIL2,hd1);strcat(FIL2,"/ctdat.txt");//printf("\n\rFIL2 %s ",FIL2); fil2=fopen(FIL2,"r"); i=0;while(i<16){ fgets(str1,26,fil2);strcpy(CK[i],str1);//printf("\n\r%s ",CK[i]); fgets(str1,02,fil2);//strcpy(QS,str1);//printf("\n\rstr1=%s ",str1);//eat" fgets(str1,05,fil2);BK[i]=atof(str1);//printf("\n\rstr1=%s ",str1); fgets(str1,02,fil2);//printf("\n\rstr1=%s ",str1);//eat, fgets(str1,05,fil2);PF[i]=atof(str1);//printf("\n\rstr1=%s ",str1); fgets(str1,02,fil2);//printf("\n\rstr1=%s ",str1);//eat, fgets(str1,04,fil2);LV[i]=atof(str1);//printf("\n\rstr1=%s ",str1); fgets(str1,02,fil2);//printf("\n\rstr1=%s ",str1);//eat, fgets(str1,04,fil2);AL[i]=atof(str1);//printf("\n\rstr1=%s ",str1); fgets(str1,02,fil2);//printf("\n\rstr1=%s ",str1);//eat, fgets(str1,04,fil2);AH[i]=atof(str1);//printf("\n\rstr1=%s ",str1); fgets(str1,25,fil2);//printf("\n\rstr1=%s ",str1);//end at . fgets(str1,25,fil2);//printf("\n\rstr1=%s ",str1);//end of line (appears as blank) if(debug==1)printf("\n\r%f ",BK[i]); i++;} if(debug==1)printf("\n\r");/*flush*/ fclose(fil2); if(debug==1)printf("\n\r ct dat ok ");//exit(EXIT_SUCCESS); //mmdb1 - 674 bytes, hdr 18 bytes //mm0120020909131542,01,010,38979,00028,010,38979,00028,10000, 15 more groups mMII //....+....1....+....2....+....3....+....4....+....5....+....6....+....7 strcpy(FIL5,hd1);strcat(FIL5,"/mmdb1.txt");if(debug==1)printf("\n\rFIL5 %s ",FIL5); fil5=fopen(FIL5,"r");//exit(EXIT_SUCCESS); // 676->679 for Vista compatibility while (fgets(DB[count], 679, fil5) != NULL) count++;//read to eof, count and save all in DB[] if(debug==1)printf("\n\r count %d ",count);printf("\n\r"); fclose(fil5);i=count-1; if(debug==1)printf("\n\r database loaded to DB"); //exit(EXIT_SUCCESS); //extract calc data: latest DB->dbln->16x{->segm->A1-H1[i] strcpy(dbln.h1,DB[i]);//copies latest saved record into struct if(debug==1)printf("\n\r%s",dbln.h1);//print all up to null strncpy(temp3,dbln.h1,4); if(strcmp(hd1,temp3)!=0){printf("\n\r%s %s",hd1,dbln.h1);printf("\n\r mmdb1 file folder mismatch");exit(EXIT_FAILURE);}; strncpy(hd1,dbln.h1,4);strncpy(hd2,dbln.h2,8);strncpy(hd3,dbln.h3,6);//header data j=1;strncpy(segm.c1,dbln.s01,I41);//Copy first n characters of first segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=2;strncpy(segm.c1,dbln.s02,I41);//Copy first n characters of second segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=3;strncpy(segm.c1,dbln.s03,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=4;strncpy(segm.c1,dbln.s04,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);if(debug==1)printf("\n\r .n5 %s",temp3); E1[j]=atof(temp3);if(debug==1)printf("\n\r atof %f",E1[j]); strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); if(debug==1)printf("\n\r% f",A1[j]); if(debug==1)printf("\n\r%f",B1[j]);if(debug==1)printf("\n\r%f",C1[j]); if(debug==1)printf("\n\r%f",D1[j]);if(debug==1)printf("\n\r%f",E1[j]); j=5;strncpy(segm.c1,dbln.s05,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=6;strncpy(segm.c1,dbln.s06,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=7;strncpy(segm.c1,dbln.s07,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=8;strncpy(segm.c1,dbln.s08,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=9;strncpy(segm.c1,dbln.s09,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=10;strncpy(segm.c1,dbln.s10,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=11;strncpy(segm.c1,dbln.s11,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=12;strncpy(segm.c1,dbln.s12,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=13;strncpy(segm.c1,dbln.s13,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=14;strncpy(segm.c1,dbln.s14,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=15;strncpy(segm.c1,dbln.s15,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); j=16;strncpy(segm.c1,dbln.s16,I41);//Copy first n characters of segment //printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A1[j]=atof(temp3);strncpy(temp3,segm.n2,3);B1[j]=atof(temp3); strncpy(temp3,segm.n3,5);C1[j]=atof(temp3);strncpy(temp3,segm.n4,5);D1[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E1[j]=atof(temp3);strncpy(temp3,segm.n6,5);F1[j]=atof(temp3); strncpy(temp3,segm.n7,5);G1[j]=atof(temp3);strncpy(temp3,segm.n8,5);H1[j]=atof(temp3); if(debug==1)printf("\n\r%f",H1[j]);if(debug==1)printf("\n\r%s",temp3); if(debug==1)printf("\n\r latest line extracted"); //extract calc data: prev DB->dbln->16x{->segm->A2-H2[i] strcpy(dbln.h1,DB[i-1]);//copies latest saved record into struct if(debug==1)printf("\n\r%s",dbln.h1);//print all up to null j=1;strncpy(segm.c1,dbln.s01,I41);//Copy first n characters of first segment strncpy(he1,dbln.h1,4);strncpy(he2,dbln.h2,8);strncpy(he3,dbln.h3,6);//header data if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=2;strncpy(segm.c1,dbln.s02,I41);//Copy first n characters of second segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=3;strncpy(segm.c1,dbln.s03,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=4;strncpy(segm.c1,dbln.s04,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=5;strncpy(segm.c1,dbln.s05,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=6;strncpy(segm.c1,dbln.s06,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=7;strncpy(segm.c1,dbln.s07,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=8;strncpy(segm.c1,dbln.s08,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=9;strncpy(segm.c1,dbln.s09,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=10;strncpy(segm.c1,dbln.s10,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=11;strncpy(segm.c1,dbln.s11,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=12;strncpy(segm.c1,dbln.s12,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=13;strncpy(segm.c1,dbln.s13,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=14;strncpy(segm.c1,dbln.s14,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=15;strncpy(segm.c1,dbln.s15,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); j=16;strncpy(segm.c1,dbln.s16,I41);//Copy first n characters of segment if(debug==1)printf("\n\r%s",segm.c1);//print all up to null strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n1,2);A2[j]=atof(temp3);strncpy(temp3,segm.n2,3);B2[j]=atof(temp3); strncpy(temp3,segm.n3,5);C2[j]=atof(temp3);strncpy(temp3,segm.n4,5);D2[j]=atof(temp3); strncpy(temp3," ",5);//we need to clear temp3 before shorter length use! strncpy(temp3,segm.n5,3);E2[j]=atof(temp3);strncpy(temp3,segm.n6,5);F2[j]=atof(temp3); strncpy(temp3,segm.n7,5);G2[j]=atof(temp3);strncpy(temp3,segm.n8,5);H2[j]=atof(temp3); if(debug==1)printf("\n\r older line extracted"); if(debug==1)printf("\n\r pre calc delta"); //pre calc delta j=1;while(j");strcat(FE1,temp2); strcat(FF2,"#ff0000");strcat(FF2,temp2);strcat(FF3,"#0000ff");strcat(FF3,temp2); strcat(FF4,"#00dd00");strcat(FF4,temp2);strcat(FF5,"#ffffff");strcat(FF5,temp2); strcpy(TD1,""); strcat(TD2,"left");strcat(TD2,QS);strcat(TD2," Colspan = 7>"); strcat(TD3,"right");strcat(TD3,QS);strcat(TD3," Colspan = 4>"); strcat(TD4,"right");strcat(TD4,QS);strcat(TD4," Colspan = 1>"); strcat(TD5,"center");strcat(TD5,QS);strcat(TD5," Colspan = 1>"); strcat(TD6,"left");strcat(TD6,QS);strcat(TD6," Colspan = 1>"); fputs("microMETER",fil3);fputs(CRLF,fil3); //' //Print #1, "" fputs("",fil3);fputs(CRLF,fil3); fputs("",fil3);fputs("",fil3);fputs(CRLF,fil3); //1st fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs(TXT1S,fil3);fputs("",fil3);//TD2 Colspan = 7 fputs(TD2,fil3);fputs(FE1,fil3);fputs(hd1,fil3);fputs(" from ",fil3); fputs(he2,fil3);fputs(" at ",fil3);fputs(he3,fil3);fputs(" to ",fil3); fputs(hd2,fil3);fputs(" at ",fil3);fputs(hd3,fil3);fputs("",fil3); fputs(TD3,fil3);fputs(FE1,fil3);fputs("microMETER lDisplay 2007 v1.0",fil3);fputs("",fil3); fputs(CRLF,fil3); //2nd fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("channel and circuit name",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("amperes",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("kva",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF5,fil3);fputs("kwh",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF5,fil3);fputs("kvah",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF5,fil3);fputs("kvarh",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF3,fil3);fputs("$ cost",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("%",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF2,fil3);fputs("alarm",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("demand",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF4,fil3);fputs("X10(tm)",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("power",fil3);fputs("",fil3); fputs(CRLF,fil3); //3rd fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("(true power)",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("watts/volts",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("kw dem",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF5,fil3);fputs("used",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF5,fil3);fputs("",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF5,fil3);fputs("",fil3);fputs("",fil3); //ATPRS=ftoa(PRICE);itoa(Hour,temp3,10); ftoa(PRICE/100.0,ATPRS,10); fputs(TD1,fil3);fputs(FE1,fil3);fputs(ATPRS,fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("of total",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FF2,fil3);fputs("limits",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("graph",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("control",fil3);fputs("",fil3); fputs(TD1,fil3);fputs(FE1,fil3);fputs("factor",fil3);fputs("",fil3); fputs(CRLF,fil3); //calc detail //CK BK[260],PF[260],LV[260],AL[260],AH[260];detail line follows: //ckt name amperes kva kwh kvah kvarh $ cost % alarm demand X10(tm) pf //A1 CK E4 B4 C4 F4 calc calc tcalc F1 html rsv calc j=1;while(j",fil3); //fputs(TD4,fil3);ftoa(A1[j],temp3,10);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3); fputs(TD6,fil3);fputs(FE1,fil3);fputs(CK[j-1],fil3);fputs("",fil3); fputs(TD4,fil3);ftoa(E4[j],temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//a fputs(TD4,fil3);ftoa(B4[j],temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//kw fputs(TD4,fil3);ftoa(C4[j],temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//kwh if(F4[j]",fil3);//kvah x=(C4[j]*C4[j])-(F4[j]*F4[j]);if(x<0)x=0;//impossible but make sure y=pow(x,.5);//sqrt of smallest square //y=sqrt(x);//sqrt of smallest square - use: gcc ldis2007.c -lm -> still getting 0.0 use g++ fputs(TD4,fil3);ftoa(y,temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);// y=PRICE * C4[j] / 100.0; fputs(TD4,fil3);ftoa(y,temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);// y=0;if(C4[0]>0)y= C4[j] / C4[0] * 100.0; fputs(TD4,fil3);ftoa(y,temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);// strcpy(temp3," "); if(AH[j-1]<255 && E1[j]>AH[j-1])strcpy(temp3,"H"); if(AL[j-1]>000 && E1[j]",fil3);//alarm strcpy(temp3," "); fputs(TD5,fil3);temp3;fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//dem gr strcpy(temp3," "); fputs(TD5,fil3);temp3;fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//x10 y=0;if(F4[j]>0)y= C4[j] / F4[j]; fputs(TD4,fil3);ftoa(y,temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//pf fputs("",fil3);fputs(CRLF,fil3); j++;} //totals line j=0;// Vista dddddd header aaaaaa fputs("",fil3); fputs(TD6,fil3);fputs(FE1,fil3);fputs("totals",fil3);fputs("",fil3); fputs(TD4,fil3);ftoa(E4[j],temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//a fputs(TD4,fil3);ftoa(B4[j],temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//kw fputs(TD4,fil3);ftoa(C4[j],temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//kwh if(F4[j]",fil3);//kvah x=(C4[j]*C4[j])-(F4[j]*F4[j]);if(x<0)x=0;//impossible but make sure y=pow(x,.5);//sqrt of smallest square //y=sqrt(x);//sqrt of smallest square - use: gcc ldis2007.c -lm -> still getting 0.0 fputs(TD4,fil3);ftoa(y,temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);// y=PRICE * C4[j] / 100.0; fputs(TD4,fil3);ftoa(y,temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);// y=0;if(C4[0]>0)y= C4[j] / C4[0] * 100.0; fputs(TD4,fil3);ftoa(y,temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);// strcpy(temp3," "); // if(AH[j-1]<255 && E1[j]>AH[j-1])strcpy(temp3,"H"); // if(AL[j-1]>000 && E1[j]",fil3);//alarm strcpy(temp3," "); fputs(TD5,fil3);temp3;fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//dem gr strcpy(temp3," "); fputs(TD5,fil3);temp3;fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//x10 y=0;if(F4[j]>0)y= C4[j] / F4[j]; fputs(TD4,fil3);ftoa(y,temp3,5);fputs(FE1,fil3);fputs(temp3,fil3);fputs("",fil3);//pf fputs("",fil3);fputs(CRLF,fil3); if(debug==1)printf("\n\r end report\n\r"); //end report fputs("",fil3);fputs("",fil3);fputs("
",fil3); fputs("",fil3);fputs("",fil3); fclose(fil3); exit(EXIT_SUCCESS); }