#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main()
{
	char fileout[50], fileout2[50], num[40];
	ofstream stream3,stream4;
        FILE *runname;

        // reading run number from file
        runname = fopen("/srv/www/cgi-bin/ongoingscanch","r");
        fscanf (runname, "%s\n", &num);
        fclose(runname);

        strcpy(fileout,"/srv/www/htdocs/dqm2/");
        strcat(fileout,num);
	strcat(fileout,"f_s.html");

	//cout << fileout << endl;

	stream3.open(fileout);

	//Writing into the file

	stream3 << " <html> " << endl;
	stream3 << " <head> " << endl;
	stream3 << " <meta http-equiv=""Content-Type""  " << endl;
	stream3 << " content=""text/html; charset=iso-8859-1"">  " << endl;
	stream3 << " <title>Run " << num << " </title> " << endl;
	stream3 << " </head>  " << endl;

	stream3 << "  <frameset rows=""15%,85%"" frameborder=""no""> " << endl;
	stream3 << " <frame src=""http://cms904cr1/cgi-bin/dqm2""> " << endl;
	stream3 << " <frame src=""http://cms904cr1/dqm2/"<< num <<".html""> " << endl;
	stream3 << "</frameset> " << endl;
	stream3 << "</html>"  << endl;
	stream3.close();


        strcpy(fileout2,"/srv/www/htdocs/dqm2/");
        strcat(fileout2,num);
	strcat(fileout2,".html");
        //cout << "file :" << fileout2 << endl;

	stream4.open(fileout2);

	stream4 << "<html> " << endl;

	stream4 << "<head> " << endl;
	stream4 << "<meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1""> " << endl;
	stream4 << "<title>Run " << num << " </title> " << endl;
	stream4 << "</head> " << endl;

	stream4 << "<body> " << endl;
	stream4 << "<p align=""center"">&nbsp;</p> " << endl;
	stream4 << "<div align=""center""><center> " << endl;
	stream4 << "<table border=""0""> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station1A.gif"" alt=""A run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station1B.gif"" alt=""B run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station1C.gif"" alt=""C run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station1A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station1B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station1C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station2A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station2B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station2C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station2A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station2B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station2C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station3A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station3B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station3C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station3A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station3B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station3C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station4A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station4B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station4C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station4A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station4B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station4C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station5A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station5B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station5C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station5A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station5B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station5C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station6A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station6B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station6C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station6A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station6B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station6C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station7A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station7B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station7C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station7A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station7B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station7C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station8A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station8B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station8C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station8A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station8B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station8C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station9A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station9B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station9C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station9A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station9B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station9C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4 << "<tr> " << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station10A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station10B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/hvscan_" << num << "_station10C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station10A.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station01B.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << " <td><img src=""http://cms904cr1/dqm2/plot/csizehvscan_" << num << "_station10C.gif"" alt=""run_not_yet_analyzed"" width=""1200"" height=""720"">" << endl;
    stream4 << "</tr> " << endl;

    stream4.close();

}
