Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: Re: st: RE: RE: Plots: save, log, ...


From   "David Harrison" <david.harrison@icnarc.org>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: Re: st: RE: RE: Plots: save, log, ...
Date   Tue, 16 May 2006 13:23:41 +0100

I missed some of the earlier posts on this thread being off Statalist
for a few days, but as far as I can see no-one has mentioned the program
-log2html- available from SSC (-ssc describe log2html-). This makes use
of an undocumented command -log html- to convert smcl log files to html.


As smcl files cannot contain graphics, this does not quite answer your
question, but it is a pretty straightforward process to get around this.
First, I write two new little commands: -htmlgph1- and -htmlgph2-.

-htmlgph1- exports a graph and writes the line of html to include it...

prog htmlgph1
    syntax anything(name=filename id="filename") [, htmlopts(string) *]
    qui graph export `filename', `options'
    local filename `filename'
    display as text `"<img src="`filename'" `htmlopts'>"
end

Now when log2html is run, it cleverly converts the "<" and ">" to "&lt;"
and "&gt;", so we need to change them back...

prog htmlgph2
    syntax anything(name=filename id="filename")
    tempfile f1 f2
    tempname h1 h2
    copy `filename' `f1'
    file open `h1' using `f1', read
    file open `h2' using `f2', write
    file read `h1' newline
    while r(eof)==0 {
        if substr(`"`newline'"',1,12)=="&lt;img src=" {
            local newline : subinstr local newline "&lt;" "<", all
            local newline : subinstr local newline "&gt;" ">", all
        }
        file write `h2' `"`newline'"' _n
        file read `h1' newline
    }
    file close `h1'
    file close `h2'
    copy `f2' `filename', replace
end

So now the process is:
1. Log your output in a smcl log
2. Whenever you want a graph included in the log, export it with
-htmlgph1- instead of -graph export-
3. When you have finished, run -log2html- to convert the smcl file to
html
4. Run -htmlgph2- once to make the final corrections to the html file
You now have an html log file including graphics!

E.g.

cd c:\temp\log2html
sysuse auto
log using test
sum price mpg
scatter price mpg
htmlgph1 graph1.wmf, htmlopts(width=100%)
log close
log2html test
htmlgph2 test.html

Hope this helps

David

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index