PatrickT

Dr. Patrick T

2108 Reputation

18 Badges

16 years, 301 days

MaplePrimes Activity


These are replies submitted by PatrickT

@acer 

thanks a lot, acer, sounds very promising, I'll try this as soon as I get a chance (there's an insanely busy week ahead),

Patrick.

@acer 

thanks a lot, acer, sounds very promising, I'll try this as soon as I get a chance (there's an insanely busy week ahead),

Patrick.

@FeX141 

did you have a line like i:=4; somewhere in your worksheet?  ;-)

@Christopher2222 

On the topic of passwords I remember reading Feynman's account of his story with cracking safes. As I don't have the reference handy, I quickly googled and found this quote from a book by James Gleick on Feynman, summarizing quite well what I remember Feynman himself had written,

People are predictable.
     They tend to leave safes unlocked.
     They tend to leave their combinations at factory settings such as 25-0-25.
     They tend to write down the combinations, often on the edge of their desk drawers.
     They tend to choose birthdays and other easily remembered numbers.
     This last insight alone made an enormous difference. Of the 8,000 effective possible combinations, Feynman figured that only 162 worked as dates. The first number was a month from 1 to 12 — given the margin of error, that meant he need try just three possibilities, 0, 5, and 10. For a day from 1 to 31 he needed six; for a year from 1900 to the present, just nine. He could try 3 x 6 x 9 combinations in minutes. He also discovered that it took just a few inexplicable successes to make a safecracker's reputation.

http://www.mikepope.com/blog/AddComment.aspx?blogid=2291

It would be nice to be able to export several plots arranged in an Array, as high-resolution postscript...

http://www.mapleprimes.com/questions/36802-Arrayplot#comment63786

 

At a leisurely pace, I've done some casual research, and found this to be a great source:

http://www.jaapsch.net/puzzles/

for the 3X3 case, there is only one magic square, so in a way that makes it less versatile than the Sudoku game where the objective is, less ambitiously, to fill the 9 squares with the 9 digits 1-9. However, as I have discovered (but is known to just about everyone), the centers of the Rubik's cube rotate as the side pieces are moved around, so that solving for all 6 magic squares with the numbers in upright position (say the middle row being "9" "5" "1" as opposed to "9" "un" "1", where "un" represents the digit "5" sideways) is actually more challenging than the standard cube.

I was going to baptize this new game the Sudokube, but that was done long ago by someone else.

There are variants of the Sudokube in which the center pieces are not necessarily the digit 5 and where filling all 6 faces with non-repeated digits is good enough to solve the puzzle. Much more like the Sudoku than like the magic square.

If instead of writing numbers on the faces you wrote symbols like the ones on the face of a die (singular for dice yes), then the orientation would not matter anymore. I also think it would be prettier. I haven't seen one like that, so I'm going to make one.

You can arrange the numbers on the cubelets in such a way as to make it easier or harder to solve, for instance if you have edge pieces with the same number on both edges or if you have corner pieces with the same numbers on them. (I think)

I wonder how quickly the speed cubers could solve those, without colors as a visual aide, should be a lot harder even if mathematically equivalent. The present record is under 10 seconds by the way. And blindfolded it's under a minute, for the 3X3X3.

I average about 10 minutes on the 2X2X2...

While the number of possible magic squares in the 3X3 cube is unique (apart from trivial symmetries), the 4X4 cube has a total of 880 possible magic squares. Does that make the 4X4X4 cube easier to solve than the 3X3X3?

This seems to be an area that hasn't been thoroughly researched yet. Once in a while a new algorithm is discovered that improves solving speed.

@Kamel Boughrara 

This thread, towards the end, discusses the benefit of using bat file,

http://www.mapleprimes.com/questions/126316-Automatic-Execution

scroll down to:

http://www.mapleprimes.com/questions/126316-Automatic-Execution#comment126450

but it can be tedious:

http://www.mapleprimes.com/questions/126316-Automatic-Execution#comment126635

 

@Kamel Boughrara 

This thread, towards the end, discusses the benefit of using bat file,

http://www.mapleprimes.com/questions/126316-Automatic-Execution

scroll down to:

http://www.mapleprimes.com/questions/126316-Automatic-Execution#comment126450

but it can be tedious:

http://www.mapleprimes.com/questions/126316-Automatic-Execution#comment126635

 

this issue:

http://www.mapleprimes.com/posts/100884-Precision-And-Plot-Drivers

has not been fixed as of Maple 15, might it be for Maple 17?

Edit: and here another issue:

http://www.mapleprimes.com/questions/129168-Bug-In-The-Plot-Function

 

 

 

The discussion above continued elsewhere and reached a happy ending:

http://www.mapleprimes.com/questions/129009-How-To-Remove-Floatundefined-From

Below are example plots to illustrate what can be achieved:

The plot exported as png/jpeg with plotsetup/standard (eps doesn't work, note how the labels are cropped):

The plot exported as eps with plotsetup/classic (a screenshot converted to jpeg):

The plot above tweaked by editing the content of the postscript file (a screenshot):

 

The tweak allows me to control the thickness of the axes, of the lines, and of the pointplot symbol separately. It also allows me to control the font type and size of the axes, of the labels, and of the title, separately. I couldn't find a practical way to control the ticks however.

Thanks Joe,

your help has been invaluable. These regular expressions have a regularity that is difficult to grasp. I would not have got very far without your examples. The help page on Regular expressions was, well, regular, but I learned more from your examples. I came across this page, which clarified a thing or two, http://www.regular-expressions.info/charclass.html, but by and large the whole business of these regexps (allow me to use the jargon) remains a mystery to me.

I got most of what I wanted to work. But I had to work hard. Consider, for instance,

    (\2610.01) dup 0 stringbbox 1156

I believe I had to write this to catch it:

    str := StringTools:-RegSubs("(\n\\(\\\\[0-9]+.[0-9]+\\)) (dup 0 stringbbox [0-9]+)"
        = "\\1 Label \\3", str);

You had warned me, it takes some tricky escaping and backslashing and whathaveyou. I was quite surprised when the 4 backslashes worked, wow. But is it art? ;-)

In the process, I have learned a bit about postscript.

I have managed to produce 3D postscript images that look much better than the jpegs. By tweaking the fonts and the thickness of the axes and of the lines, I've been able to make them very nearly consistent in look and feel. The fonts don't look quite as sharp though. But that's really because the 2D postscript images obtained by the standard gui are excellent. Looking inside the postscript file is interesting: the 2D standard gui postscript plot driver produces files that contain font definitions and lots of other things, very well organized and easy to understand, while the 3D classic gui postscript plot driver produces files that are quite minimal and harder to understand.

I really hope Maple 16 will surprise me with a rewritten 3d postscript plot driver!

My image now has gone down from 11,226,123 bytes to 295,443 bytes! Quite an achievement. And considering that I have a few hundred, the gain in space is non-negligeable too!

It would have been good to control the thickness of the plot lines and of the boxed axis separately, as they are currently all controlled by the "medium" keyword. It's not completely impossible to do, but it's very plot-specific, so I haven't bothered.

I'm quite satisfied with the results. Thanks a lot for your help and guidance. I enjoyed the learning process too.

For the record, here are the revised procedures I have used to produce and fix the plots. Step 1: CleanPlot (see above). Step 2 : MakeMPL (see above). Step 3 : FixMPL (see below). Step 4: MakeEPS (see above). Step 5: EditEPS (see below).


FixMPL := proc( mplfile :: string )
    description "cmaple can only handle orientation = [theta,phi], if a third option is given, orientation = [theta,phi,psi], cmaple may fail to produce an eps";
    uses FT = FileTools, ST = StringTools;
    local str;
    str := FT:-Text:-ReadFile(mplfile);
    fclose(mplfile);
    str := ST:-RegSubs("(ORIENTATION\\([0-9.+-]+,[0-9.+-]+),[0-9.+-]+\\)"="\\1)",str);
    FT:-Text:-WriteString(mplfile, str);
    fclose(mplfile);
end proc:



EditEPS := proc( epsfile :: string
    , { thin :: posint := 10 } # defined by cmaple
    , { medium :: posint := 20 } # defined by cmaple
    , { thick :: posint := 30 } # defined by cmaple
    , { [SymbolThickness,symbolthickness] :: posint := 50 }
    , { [CurvesThickness,curvesthickness] :: posint := 33 }
    , { [AxesThickness,axesthickness] :: posint := 16 }
    , { [Margin,margin] :: integer := 10 }
    , { [DrawBorder,drawborder] :: string := "false" }
    , { [BoundaryThickness,BorderThickness,boundarythickness,borderthickness] :: integer := 20 }
    , { [DefaultFontType,defaultfonttype] :: string := "Times-Roman" }
    , { [DefaultFontScale,defaultfontscale] :: posint := 120 }
    , { [DefaultTitleFontType,defaulttitlefonttype] :: string := "Times-Roman-Bold" }
    , { [DefaultTitleFontScale,defaulttitlefontscale] :: posint := 220 }
    , { [AxisLabelFontType,labelfont] :: string := "Times-Italic" }
    , { [AxisLabelFontScale,labelscale] :: posint := 180 }
    , { [TickLabelFontType,tickfont] :: string := "Times-Roman" }
    , { [TickLabelFontScale,tickscale] :: posint := 140 }
    , { ext :: string := ".eps" }
    , { dir :: string := cat(currentdir(),kernelopts(dirsep)) }
    )
    local str, llx, lly, urx, ury, all, bb, regex;
    uses FT = FileTools, ST = StringTools;
    ### Modify the generated postscript file    
    str := FT:-Text:-ReadFile(cat(dir,convert(epsfile,string),ext));
    fclose(cat(dir,convert(epsfile,string),ext));
    if is(ST:-Search("Patrick",str)=0) then
        str := ST:-RegSubs("Creator: Maple" = "Creator: Maple with cmaple and Patrick", str);
    else
        error("plot already fixed! re-run MakeEPS to create and edit a new postscript file");
    end if;
    # cmaple assigns keyword "thin" to axis tickmark thickness
    str := ST:-RegSubs("\n/thin ([0-9]+) def" = sprintf("\n/thin %d def", thin), str);
    # cmaple assigns keyword "medium" to both curves thickness and axis line thickness
    str := ST:-RegSubs("\n/medium ([0-9]+) def" = sprintf("\n/medium %d def", medium), str);
    # cmaple defines but does not use keyword "thick"
    str := ST:-RegSubs("\n/thick ([0-9]+) def" = sprintf("\n/thick %d def", thick), str);    
    # new keyword "SymbolThickness" has been mapped to the lines that create the point symbol, if any
    str := ST:-RegSubs("(\n/thick ([0-9]+) def\n)" = sprintf("\\1/SymbolThickness %d def\n/CurvesThickness %d def\n/AxesThickness %d def\n", SymbolThickness, CurvesThickness, AxesThickness), str);
      # keyword "DrawBorder" may be set to true or false
    str := ST:-RegSubs("drawborder true def" = sprintf("drawborder %s def",DrawBorder), str);
       str := ST:-RegSubs("drawborder false def" = sprintf("drawborder %s def",DrawBorder), str);
    # keyword "BoundaryThickness" controls border thickness, if any
    str := ST:-RegSubs("\n/boundarythick ([0-9]+) def" = sprintf("\n/boundarythick %d def", BoundaryThickness), str);
    # replace the default Helvetica font by the Times font and "embed" it
    str := ST:-RegSubs("(IncludeResource: font) (Helvetica)" = "\\1 Times", str);
    str := ST:-RegSubs("(DocumentNeededResources: font) (Helvetica)" = "\\1 Times", str);
    # Define /TickLabelFont and /AxisLabelFont
    # A typical default set-up produced by cmaple is:
          # /defaultTitleFont {/Helvetica findfont 256 scalefont setfont} def
          # /defaultFont {/Helvetica findfont 156 scalefont setfont} def
          # new keywords "DefaultFontType", "DefaultFontScale",
          # new keywords "AxisLabelFontType", "AxisLabelFontScale",
          # new keywords "TickLabelFontType", "TickLabelFontScale"
    # first step, define AxisLabelFont and TickLabelFont
    str := ST:-RegSubs("(\n/defaultFont {/Helvetica findfont ([0-9]+) scalefont setfont} def\n)"     
      = sprintf("\\1/AxisLabelFont {\/%s findfont %d scalefont setfont} def\n/TickLabelFont {\/%s findfont %d scalefont setfont} def\n"
        , AxisLabelFontType, AxisLabelFontScale, TickLabelFontType, TickLabelFontScale), str);
    # second step, set defaultTitleFont and defaultFont
    str := ST:-RegSubs(    "(\n/defaultTitleFont) ({/Helvetica) (findfont) ([0-9]+) (scalefont setfont} def\n/defaultFont) ({/Helvetica) (findfont) ([0-9]+) (scalefont setfont} def\n)"     
      = sprintf("\\1 {\/%s \\3 %d \\5 {\/%s \\7 %d \\9"    
        , DefaultTitleFontType, DefaultTitleFontScale, DefaultFontType, DefaultFontScale), str);    
       # Set TickLabelFont and /AxisLabelFont (tedious tweaking, may be plot-specific)
    str := StringTools:-RegSubs("(\n\\([^)]+\\)) (dup 0 stringbbox [0-9]+)"
        = "\\1 AxisLabelFont \\2", str);
    str := StringTools:-RegSubs("(\n\\([0-9]+\\)) (AxisLabelFont) (dup 0 stringbbox [0-9]+)"
        = "\\1 TickLabelFont \\3", str);    
    str := StringTools:-RegSubs("(\n\\([0-9]+.[0-9]+\\)) (AxisLabelFont) (dup 0 stringbbox [0-9]+)"
        = "\\1 TickLabelFont \\3", str);    
    str := StringTools:-RegSubs("(\n\\(\\\\[0-9]+\\)) (AxisLabelFont) (dup 0 stringbbox [0-9]+)"
        = "\\1 TickLabelFont \\3", str);
    str := StringTools:-RegSubs("(\n\\(\\\\[0-9]+.[0-9]+\\)) (AxisLabelFont) (dup 0 stringbbox [0-9]+)"
        = "\\1 TickLabelFont \\3", str);
    # Adjust thickness of the CURVES (plot-specific)
        #    A typical layout:
        #    \n medium setlinewidth
        #    \n[] 0 setdash defaultFont
        #    \n 1 0.0980392 0.188235 C
        #    \n medium setlinewidth
    str := ST:-RegSubs("(1 [0-9]+.[0-9]+ [0-9]+.[0-9]+ C\n)(medium) (setlinewidth)"
        = "\\1CurvesThickness \\3", str);
    # Adjust thickness of the AXES (plot-specific)
        #    A typical layout:
        #    NP 2854 480 m 2854 500 l
        #    S
        #    medium setlinewidth
        #    NP 500 1234 m 2854 500 l
        #    S
#    str := ST:-RegSubs("(\nS\n)(medium setlinewidth\n)"
#        = "\\1AxesThickness setlinewidth\n", str);    
    str := ST:-RegSubs("(medium setlinewidth\n)(NP [0-9]+ [0-9]+ m [0-9]+ [0-9]+ l\n)"
        = "AxesThickness setlinewidth\n\\2", str);            
    # Adjust thickness of the SYMBOL (plot-specific)
        #    medium setlinewidth
        #        1 0.0980392 0.188235 C
        #    NP
        #    2991 2313 m
    str := ST:-RegSubs("(medium setlinewidth\n)(    1 [0-9]+.[0-9]+ [0-9]+.[0-9]+ C\n)(NP\n)([0-9]+ [0-9]+ m\)"
        = "SymbolThickness setlinewidth\n\\2\\3\\4", str);
        
    # Remove Postscript DSC error
    str := ST:-RegSubs("\n%%Pages:  ([0-9]+)" = "", str);
    # Adjust bounding box
    if margin <> 0 then
        regex := "(\n%%BoundingBox: )([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)";
        if not ST:-RegMatch(regex,str,'all,bb,llx,lly,urx,ury') then
            error "problem matching bounding box";
        end if;
        bb := map(parse,[llx,lly,urx,ury]);
        bb := bb + [-margin,-margin,+margin,+margin];
        str := ST:-RegSubs(regex = sprintf("\\1 %d %d %d %d", op(bb)), str);
    end if;
    # print to file the fixed eps
    FT:-Text:-WriteString(cat(dir,convert(epsfile,string),ext), str);
    fclose(cat(dir,convert(epsfile,string),ext));
end proc:



Thanks Joe,

your help has been invaluable. These regular expressions have a regularity that is difficult to grasp. I would not have got very far without your examples. The help page on Regular expressions was, well, regular, but I learned more from your examples. I came across this page, which clarified a thing or two, http://www.regular-expressions.info/charclass.html, but by and large the whole business of these regexps (allow me to use the jargon) remains a mystery to me.

I got most of what I wanted to work. But I had to work hard. Consider, for instance,

    (\2610.01) dup 0 stringbbox 1156

I believe I had to write this to catch it:

    str := StringTools:-RegSubs("(\n\\(\\\\[0-9]+.[0-9]+\\)) (dup 0 stringbbox [0-9]+)"
        = "\\1 Label \\3", str);

You had warned me, it takes some tricky escaping and backslashing and whathaveyou. I was quite surprised when the 4 backslashes worked, wow. But is it art? ;-)

In the process, I have learned a bit about postscript.

I have managed to produce 3D postscript images that look much better than the jpegs. By tweaking the fonts and the thickness of the axes and of the lines, I've been able to make them very nearly consistent in look and feel. The fonts don't look quite as sharp though. But that's really because the 2D postscript images obtained by the standard gui are excellent. Looking inside the postscript file is interesting: the 2D standard gui postscript plot driver produces files that contain font definitions and lots of other things, very well organized and easy to understand, while the 3D classic gui postscript plot driver produces files that are quite minimal and harder to understand.

I really hope Maple 16 will surprise me with a rewritten 3d postscript plot driver!

My image now has gone down from 11,226,123 bytes to 295,443 bytes! Quite an achievement. And considering that I have a few hundred, the gain in space is non-negligeable too!

It would have been good to control the thickness of the plot lines and of the boxed axis separately, as they are currently all controlled by the "medium" keyword. It's not completely impossible to do, but it's very plot-specific, so I haven't bothered.

I'm quite satisfied with the results. Thanks a lot for your help and guidance. I enjoyed the learning process too.

For the record, here are the revised procedures I have used to produce and fix the plots. Step 1: CleanPlot (see above). Step 2 : MakeMPL (see above). Step 3 : FixMPL (see below). Step 4: MakeEPS (see above). Step 5: EditEPS (see below).


FixMPL := proc( mplfile :: string )
    description "cmaple can only handle orientation = [theta,phi], if a third option is given, orientation = [theta,phi,psi], cmaple may fail to produce an eps";
    uses FT = FileTools, ST = StringTools;
    local str;
    str := FT:-Text:-ReadFile(mplfile);
    fclose(mplfile);
    str := ST:-RegSubs("(ORIENTATION\\([0-9.+-]+,[0-9.+-]+),[0-9.+-]+\\)"="\\1)",str);
    FT:-Text:-WriteString(mplfile, str);
    fclose(mplfile);
end proc:



EditEPS := proc( epsfile :: string
    , { thin :: posint := 10 } # defined by cmaple
    , { medium :: posint := 20 } # defined by cmaple
    , { thick :: posint := 30 } # defined by cmaple
    , { [SymbolThickness,symbolthickness] :: posint := 50 }
    , { [CurvesThickness,curvesthickness] :: posint := 33 }
    , { [AxesThickness,axesthickness] :: posint := 16 }
    , { [Margin,margin] :: integer := 10 }
    , { [DrawBorder,drawborder] :: string := "false" }
    , { [BoundaryThickness,BorderThickness,boundarythickness,borderthickness] :: integer := 20 }
    , { [DefaultFontType,defaultfonttype] :: string := "Times-Roman" }
    , { [DefaultFontScale,defaultfontscale] :: posint := 120 }
    , { [DefaultTitleFontType,defaulttitlefonttype] :: string := "Times-Roman-Bold" }
    , { [DefaultTitleFontScale,defaulttitlefontscale] :: posint := 220 }
    , { [AxisLabelFontType,labelfont] :: string := "Times-Italic" }
    , { [AxisLabelFontScale,labelscale] :: posint := 180 }
    , { [TickLabelFontType,tickfont] :: string := "Times-Roman" }
    , { [TickLabelFontScale,tickscale] :: posint := 140 }
    , { ext :: string := ".eps" }
    , { dir :: string := cat(currentdir(),kernelopts(dirsep)) }
    )
    local str, llx, lly, urx, ury, all, bb, regex;
    uses FT = FileTools, ST = StringTools;
    ### Modify the generated postscript file    
    str := FT:-Text:-ReadFile(cat(dir,convert(epsfile,string),ext));
    fclose(cat(dir,convert(epsfile,string),ext));
    if is(ST:-Search("Patrick",str)=0) then
        str := ST:-RegSubs("Creator: Maple" = "Creator: Maple with cmaple and Patrick", str);
    else
        error("plot already fixed! re-run MakeEPS to create and edit a new postscript file");
    end if;
    # cmaple assigns keyword "thin" to axis tickmark thickness
    str := ST:-RegSubs("\n/thin ([0-9]+) def" = sprintf("\n/thin %d def", thin), str);
    # cmaple assigns keyword "medium" to both curves thickness and axis line thickness
    str := ST:-RegSubs("\n/medium ([0-9]+) def" = sprintf("\n/medium %d def", medium), str);
    # cmaple defines but does not use keyword "thick"
    str := ST:-RegSubs("\n/thick ([0-9]+) def" = sprintf("\n/thick %d def", thick), str);    
    # new keyword "SymbolThickness" has been mapped to the lines that create the point symbol, if any
    str := ST:-RegSubs("(\n/thick ([0-9]+) def\n)" = sprintf("\\1/SymbolThickness %d def\n/CurvesThickness %d def\n/AxesThickness %d def\n", SymbolThickness, CurvesThickness, AxesThickness), str);
      # keyword "DrawBorder" may be set to true or false
    str := ST:-RegSubs("drawborder true def" = sprintf("drawborder %s def",DrawBorder), str);
       str := ST:-RegSubs("drawborder false def" = sprintf("drawborder %s def",DrawBorder), str);
    # keyword "BoundaryThickness" controls border thickness, if any
    str := ST:-RegSubs("\n/boundarythick ([0-9]+) def" = sprintf("\n/boundarythick %d def", BoundaryThickness), str);
    # replace the default Helvetica font by the Times font and "embed" it
    str := ST:-RegSubs("(IncludeResource: font) (Helvetica)" = "\\1 Times", str);
    str := ST:-RegSubs("(DocumentNeededResources: font) (Helvetica)" = "\\1 Times", str);
    # Define /TickLabelFont and /AxisLabelFont
    # A typical default set-up produced by cmaple is:
          # /defaultTitleFont {/Helvetica findfont 256 scalefont setfont} def
          # /defaultFont {/Helvetica findfont 156 scalefont setfont} def
          # new keywords "DefaultFontType", "DefaultFontScale",
          # new keywords "AxisLabelFontType", "AxisLabelFontScale",
          # new keywords "TickLabelFontType", "TickLabelFontScale"
    # first step, define AxisLabelFont and TickLabelFont
    str := ST:-RegSubs("(\n/defaultFont {/Helvetica findfont ([0-9]+) scalefont setfont} def\n)"     
      = sprintf("\\1/AxisLabelFont {\/%s findfont %d scalefont setfont} def\n/TickLabelFont {\/%s findfont %d scalefont setfont} def\n"
        , AxisLabelFontType, AxisLabelFontScale, TickLabelFontType, TickLabelFontScale), str);
    # second step, set defaultTitleFont and defaultFont
    str := ST:-RegSubs(    "(\n/defaultTitleFont) ({/Helvetica) (findfont) ([0-9]+) (scalefont setfont} def\n/defaultFont) ({/Helvetica) (findfont) ([0-9]+) (scalefont setfont} def\n)"     
      = sprintf("\\1 {\/%s \\3 %d \\5 {\/%s \\7 %d \\9"    
        , DefaultTitleFontType, DefaultTitleFontScale, DefaultFontType, DefaultFontScale), str);    
       # Set TickLabelFont and /AxisLabelFont (tedious tweaking, may be plot-specific)
    str := StringTools:-RegSubs("(\n\\([^)]+\\)) (dup 0 stringbbox [0-9]+)"
        = "\\1 AxisLabelFont \\2", str);
    str := StringTools:-RegSubs("(\n\\([0-9]+\\)) (AxisLabelFont) (dup 0 stringbbox [0-9]+)"
        = "\\1 TickLabelFont \\3", str);    
    str := StringTools:-RegSubs("(\n\\([0-9]+.[0-9]+\\)) (AxisLabelFont) (dup 0 stringbbox [0-9]+)"
        = "\\1 TickLabelFont \\3", str);    
    str := StringTools:-RegSubs("(\n\\(\\\\[0-9]+\\)) (AxisLabelFont) (dup 0 stringbbox [0-9]+)"
        = "\\1 TickLabelFont \\3", str);
    str := StringTools:-RegSubs("(\n\\(\\\\[0-9]+.[0-9]+\\)) (AxisLabelFont) (dup 0 stringbbox [0-9]+)"
        = "\\1 TickLabelFont \\3", str);
    # Adjust thickness of the CURVES (plot-specific)
        #    A typical layout:
        #    \n medium setlinewidth
        #    \n[] 0 setdash defaultFont
        #    \n 1 0.0980392 0.188235 C
        #    \n medium setlinewidth
    str := ST:-RegSubs("(1 [0-9]+.[0-9]+ [0-9]+.[0-9]+ C\n)(medium) (setlinewidth)"
        = "\\1CurvesThickness \\3", str);
    # Adjust thickness of the AXES (plot-specific)
        #    A typical layout:
        #    NP 2854 480 m 2854 500 l
        #    S
        #    medium setlinewidth
        #    NP 500 1234 m 2854 500 l
        #    S
#    str := ST:-RegSubs("(\nS\n)(medium setlinewidth\n)"
#        = "\\1AxesThickness setlinewidth\n", str);    
    str := ST:-RegSubs("(medium setlinewidth\n)(NP [0-9]+ [0-9]+ m [0-9]+ [0-9]+ l\n)"
        = "AxesThickness setlinewidth\n\\2", str);            
    # Adjust thickness of the SYMBOL (plot-specific)
        #    medium setlinewidth
        #        1 0.0980392 0.188235 C
        #    NP
        #    2991 2313 m
    str := ST:-RegSubs("(medium setlinewidth\n)(    1 [0-9]+.[0-9]+ [0-9]+.[0-9]+ C\n)(NP\n)([0-9]+ [0-9]+ m\)"
        = "SymbolThickness setlinewidth\n\\2\\3\\4", str);
        
    # Remove Postscript DSC error
    str := ST:-RegSubs("\n%%Pages:  ([0-9]+)" = "", str);
    # Adjust bounding box
    if margin <> 0 then
        regex := "(\n%%BoundingBox: )([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)";
        if not ST:-RegMatch(regex,str,'all,bb,llx,lly,urx,ury') then
            error "problem matching bounding box";
        end if;
        bb := map(parse,[llx,lly,urx,ury]);
        bb := bb + [-margin,-margin,+margin,+margin];
        str := ST:-RegSubs(regex = sprintf("\\1 %d %d %d %d", op(bb)), str);
    end if;
    # print to file the fixed eps
    FT:-Text:-WriteString(cat(dir,convert(epsfile,string),ext), str);
    fclose(cat(dir,convert(epsfile,string),ext));
end proc:



 

Coincidentally, I was reading just last week Marcus Du Sautoy, The Number Mysteries, and there in Chapter 3, pages 127-134, of the 2010 London paperback edition, there's a nice discussion of the Lottery. It's a great book, by the way.

"But don't get addicted to consecutive numbers. You might think that 1 2 3 4 5 6 is a clever choice. After all, by now you will hopefully appreciate that this combination is as likely as any other (i.e. extremely unlikely!). If you won the jackpot with this combination, you'd hope to walk away with the whole pot. But apparently, over 10,000 people in the UK choose this combination each week ..."

Joe, if you've got time for this, I have some questions related to StringTools:-RegSubs. Hints would be more than enough.

I'm tweaking the postscript file to get a different font types for the axis labels and for the tick labels. Essentially, a workaround for plotoptions = "font=[Times,roman,10],labelfont=[Times,italic,10]", which should but does not work. It's not a big deal, but I think it can be done with StringTools:-RegSubs. I couldn't find much help in the help pages.

Here is a typical problem. Replace this string:

(4) dup 0 stringbbox 452 exch sub exch pop 2582 exch m show
(x) dup 0 stringbbox 908 exch sub exch pop 3800 exch m show


by this string:

(4) dup 0 stringbbox 452 exch sub exch pop 2582 exch m show
(x) TickLabelFont dup 0 stringbbox 908 exch sub exch pop 3800 exch m show
AxisLabelFont

If the numbers were fixed, I would do this:

str := ST:-RegSubs("exch m show\n(x) dup 0 stringbbox 908 exch sub exch pop 3800 exch m show\n" = "exch m show\n(x) TickLabelFont dup 0 stringbbox 908 exch sub exch pop 3800 exch m show\nAxisLabelFont", str);

But the numbers will vary, so I want to read numbers like 0, 908, 3800 on the left-hand side of RegSubs(lhs=rhs,str) and copy them onto the rhs. I got as far as this:

str := ST:-RegSubs("exch m show\n(([a-z])) dup ([0-9]+) stringbbox ([0-9]+) exch sub exch pop ([0-9]+) exch m show\n" = sprintf("exch m show\n(%d) TickLabelFont dup %d stringbbox %d exch sub exch pop %d exch m show defaultFont\n", ?? ), str);

I'm not sure about ([a-z]) as a replacement for x, that's a wild guess.

I don't quite understand how to copy the numbers on the lhs, so I used %d as a placeholder.

In the string above (x) stands for the axis label 'x'. Can the code be made to work for any label, e.g. for something with several words and spaces, e.g.: (the x coordinate).

Another problem I came across is how to replace ORIENTATION(45.,45.,0) by ORIENTATION(45.,45.), since classic accepts only 2 arguments for ORIENTATION, so again lhs=ORIENTATION(([0-9]+),([0-9]+),([0-9]+)), rhs=ORIENTATION(%d,%d) or something like that...

And how about dealing with square brackets? I can't see any of these in the help pages. If you've got a link to doc, that'd be plenty.

RegSubs("\n medium setlinewidth\n [] 0 setdash" ... doesn't work because of the []

First 20 21 22 23 24 25 26 Last Page 22 of 93