Changeset 1619 for trunk


Ignore:
Timestamp:
Nov 25, 2009, 10:40:35 AM (15 years ago)
Author:
dkearney
Message:

updating python objects api with example code, fixes for tcl objects api

Location:
trunk/examples/objects/api
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/objects/api/python/library

    r1610 r1619  
    2525    Notes: None
    2626    Code Example:
     27    {{{
     28        lib = Rappture.Library()
     29    }}}
    2730
    2831Rappture.Library(lib2)
     
    3336    Notes: None
    3437    Code Example:
     38    {{{
     39        lib2 = Rappture.Library()
     40        lib = Rappture.Library(lib2)
     41    }}}
    3542
    3643lib.loadXml(xmltext)
     
    4350    Notes: None
    4451    Code Example:
     52    {{{
     53        xmltext = """
     54            <?xml version="1.0"?>
     55            <run>
     56                <tool>
     57                    <about>Press Simulate to view results.</about>
     58                    <command>@tool/fermi @driver</command>
     59                </tool>
     60                <input>
     61                    <number id=\"temperature\">
     62                        <about>
     63                            <label>Ambient temperature</label>
     64                            <description>Temperature of the environment.</description>
     65                        </about>
     66                        <units>K</units>
     67                        <min>0K</min>
     68                        <max>500K</max>
     69                        <default>300K</default>
     70                    </number>
     71                </input>
     72            </run>"""
     73        lib = Rappture.Library()
     74        lib.loadXml(xmltext)
     75    }}}
    4576
    4677lib.loadFile(filename)
     
    5586    Notes: None
    5687    Code Example:
     88    {{{
     89        data = """
     90            <?xml version="1.0"?>
     91            <run>
     92                <tool>
     93                    <about>Press Simulate to view results.</about>
     94                    <command>@tool/fermi @driver</command>
     95                </tool>
     96                <input>
     97                    <number id=\"temperature\">
     98                        <about>
     99                            <label>Ambient temperature</label>
     100                            <description>Temperature of the environment.</description>
     101                        </about>
     102                        <units>K</units>
     103                        <min>0K</min>
     104                        <max>500K</max>
     105                        <default>300K</default>
     106                    </number>
     107                </input>
     108            </run>
     109        """
     110
     111        filename = "driver1234.xml"
     112        fp = open(filename,"w")
     113        fp.write(data)
     114        fp.close()
     115        lib = Rappture.Library()
     116        lib.loadFile(filename)
     117    }}}
    57118
    58119lib.value(key[, ...])
     
    72133            function's argument list.
    73134    Code Example:
     135    {{{
     136        data = """
     137            <?xml version="1.0"?>
     138            <run>
     139                <tool>
     140                    <about>Press Simulate to view results.</about>
     141                    <command>@tool/fermi @driver</command>
     142                </tool>
     143                <input>
     144                    <number id="temperature">
     145                        <about>
     146                            <label>Ambient temperature</label>
     147                            <description>Temperature of the environment.</description>
     148                        </about>
     149                        <units>K</units>
     150                        <min>0K</min>
     151                        <max>500K</max>
     152                        <default>300K</default>
     153                    </number>
     154                </input>
     155            </run>
     156        """
     157
     158        lib = Rappture::Library()
     159        lib.loadXml(data)
     160        temp = lib.value("temperature","units=F")
     161        print "temp = %s\n" % (temp)
     162        # temp = 80.33
     163    }}}
    74164
    75165lib.diff(lib2)
     
    80170    Notes: None
    81171    Code Example:
     172    {{{
     173        data1 = """
     174            <?xml version="1.0"?>
     175            <run>
     176                <tool>
     177                    <about>Press Simulate to view results.</about>
     178                    <command>@tool/fermi @driver</command>
     179                </tool>
     180                <input>
     181                    <number id="temperature">
     182                        <about>
     183                            <label>Ambient temperature</label>
     184                            <description>Temperature of the environment.</description>
     185                        </about>
     186                        <units>K</units>
     187                        <min>0K</min>
     188                        <max>500K</max>
     189                        <default>300K</default>
     190                    </number>
     191                    <number id="forel">
     192                        <about>
     193                            <label>Forel</label>
     194                            <description>Environment</description>
     195                        </about>
     196                        <units>cm</units>
     197                        <min>4cm</min>
     198                        <max>183cm</max>
     199                        <default>72cm</default>
     200                    </number>
     201                    <integer id="toops">
     202                        <about>
     203                            <label>Toops</label>
     204                            <description>Icks hafra doec weple</description>
     205                        </about>
     206                        <default>33</default>
     207                    </integer>
     208                </input>
     209            </run>
     210        """
     211
     212        data2 = """
     213            <?xml version="1.0"?>
     214            <run>
     215                <tool>
     216                    <about>Press Simulate to view results.</about>
     217                    <command>@tool/fermi @driver</command>
     218                </tool>
     219                <input>
     220                    <integer id="toops">
     221                        <about>
     222                            <label>Toops</label>
     223                            <description>Icks hafra doec weple</description>
     224                        </about>
     225                        <default>33</default>
     226                    </integer>
     227                    <number id="Ef">
     228                        <about>
     229                            <label>Fermi Level</label>
     230                            <description>Energy at center of distribution.</description>
     231                        </about>
     232                        <units>eV</units>
     233                        <min>-10eV</min>
     234                        <max>10eV</max>
     235                        <default>0eV</default>
     236                    </number>
     237                    <number id="forel">
     238                        <about>
     239                            <label>Forel</label>
     240                            <description>Environment</description>
     241                        </about>
     242                        <units>cm</units>
     243                        <min>4cm</min>
     244                        <max>183cm</max>
     245                        <default>109cm</default>
     246                    </number>
     247                </input>
     248            </run>
     249        """
     250
     251        lib1 = Rappture::Library()
     252        lib1.loadXml(data1)
     253
     254        lib2 = Rappture::Library()
     255        lib2.loadXml(data2)
     256
     257        diffs = lib1.diff(lib2)
     258        # - input.number(temperature) 300K
     259        # c input.number(forel) 72cm 109cm
     260        # + input.number(Ef)  0eV
     261    }}}
    82262
    83263lib.remove(key)
     
    88268    Notes: The object is removed and it's memory is deleted
    89269    Code Example:
     270    {{{
     271        data = """
     272            <?xml version="1.0"?>
     273            <run>
     274                <tool>
     275                    <about>Press Simulate to view results.</about>
     276                    <command>@tool/fermi @driver</command>
     277                </tool>
     278                <input>
     279                    <number id="temperature">
     280                        <about>
     281                            <label>Ambient temperature</label>
     282                            <description>Temperature of the environment.</description>
     283                        </about>
     284                        <units>K</units>
     285                        <min>0K</min>
     286                        <max>500K</max>
     287                        <default>300K</default>
     288                    </number>
     289                    <number id="Ef">
     290                        <about>
     291                            <label>Fermi Level</label>
     292                            <description>Energy at center of distribution.</description>
     293                        </about>
     294                        <units>eV</units>
     295                        <min>-10eV</min>
     296                        <max>10eV</max>
     297                        <default>0eV</default>
     298                    </number>
     299                </input>
     300            </run>
     301        """
     302
     303        lib = Rappture::Library()
     304        lib.loadXml(data)
     305        lib.remove("Ef")
     306        print lib.xml()
     307
     308        # <?xml version="1.0"?>
     309        # <run>
     310        #     <tool>
     311        #         <about>Press Simulate to view results.</about>
     312        #         <command>@tool/fermi @driver</command>
     313        #     </tool>
     314        #     <input>
     315        #         <number id="temperature">
     316        #             <about>
     317        #                 <label>Ambient temperature</label>
     318        #                 <description>Temperature of the environment.</description>
     319        #             </about>
     320        #             <units>K</units>
     321        #             <min>0K</min>
     322        #             <max>500K</max>
     323        #             <default>300K</default>
     324        #         </number>
     325        #     </input>
     326        # </run>
     327    }}}
    90328
    91329lib.xml()
     
    96334    Notes: user is responsible for free'ing returned memory?
    97335    Code Example:
     336    {{{
     337        data = """
     338            <?xml version="1.0"?>
     339            <run>
     340                <tool>
     341                    <about>Press Simulate to view results.</about>
     342                    <command>@tool/fermi @driver</command>
     343                </tool>
     344                <input>
     345                    <number id="temperature">
     346                        <about>
     347                            <label>Ambient temperature</label>
     348                            <description>Temperature of the environment.</description>
     349                        </about>
     350                        <units>K</units>
     351                        <min>0K</min>
     352                        <max>500K</max>
     353                        <default>300K</default>
     354                    </number>
     355                </input>
     356            </run>
     357        """
     358
     359        lib = Rappture::Library()
     360        lib.loadXml(data)
     361        print lib.xml()
     362
     363        # <?xml version="1.0"?>
     364        # <run>
     365        #     <tool>
     366        #         <about>Press Simulate to view results.</about>
     367        #         <command>@tool/fermi @driver</command>
     368        #     </tool>
     369        #     <input>
     370        #         <number id="temperature">
     371        #             <about>
     372        #                 <label>Ambient temperature</label>
     373        #                 <description>Temperature of the environment.</description>
     374        #             </about>
     375        #             <units>K</units>
     376        #             <min>0K</min>
     377        #             <max>500K</max>
     378        #             <default>300K</default>
     379        #         </number>
     380        #     </input>
     381        # </run>
     382    }}}
    98383
    99384lib.outcome()
     
    103388    Notes: None
    104389    Code Example:
     390    {{{
     391        data = """
     392            <?xml version="1.0"?>
     393            <run>
     394                <tool>
     395                    <about>Press Simulate to view results.</about>
     396                    <command>@tool/fermi @driver</command>
     397                </tool>
     398                <input>
     399                    <number id=\"temperature\">
     400                        <about>
     401                            <label>Ambient temperature</label>
     402                            <description>Temperature of the environment.</description>
     403                        </about>
     404                        <units>K</units>
     405                        <min>0K</min>
     406                        <max>500K</max>
     407                        <default>300K</default>
     408                    </number>
     409                </input>
     410            </run>
     411        """
     412
     413        lib = Rappture::Library()
     414        lib.loadXml(data)
     415        if (lib.error() != 0) {
     416            print "there was an error while loading xml data"
     417            outcome = lib.outcome()
     418            sys.stderr.write(outcome.context())
     419            sys.stderr.write(outcome.remark())
     420        }
     421    }}}
    105422
    106423lib.error()
     
    110427    Notes: None
    111428    Code Example:
     429    {{{
     430        data = """
     431            <?xml version="1.0"?>
     432            <run>
     433                <tool>
     434                    <about>Press Simulate to view results.</about>
     435                    <command>@tool/fermi @driver</command>
     436                </tool>
     437                <input>
     438                    <number id="temperature">
     439                        <about>
     440                            <label>Ambient temperature</label>
     441                            <description>Temperature of the environment.</description>
     442                        </about>
     443                        <units>K</units>
     444                        <min>0K</min>
     445                        <max>500K</max>
     446                        <default>300K</default>
     447                    </number>
     448                </input>
     449            </run>
     450        """
     451
     452        lib = Rappture::Library()
     453        lib.loadXml(data)
     454        if (lib.error() != 0) {
     455            print "there was an error while loading xml data"
     456            outcome = lib.outcome()
     457            sys.stderr.write(outcome.context())
     458            sys.stderr.write(outcome.remark())
     459        }
     460    }}}
    112461
    113462lib.result(status)
     
    121470            signal.
    122471    Code Example:
     472    {{{
     473        data = """
     474            <?xml version="1.0"?>
     475            <run>
     476                <tool>
     477                    <about>Press Simulate to view results.</about>
     478                    <command>@tool/fermi @driver</command>
     479                </tool>
     480                <input>
     481                    <number id="temperature">
     482                        <about>
     483                            <label>Ambient temperature</label>
     484                            <description>Temperature of the environment.</description>
     485                        </about>
     486                        <units>K</units>
     487                        <min>0K</min>
     488                        <max>500K</max>
     489                        <default>300K</default>
     490                    </number>
     491                </input>
     492            </run>
     493        """
     494
     495        lib = Rappture::Library()
     496        lib.loadXml(data)
     497        lib.result()
     498        # internal xml objects free'd
     499        # driver file written to disk
     500        # =RAPPTURE-RUN=>driver1234.xml signal sent to stdout
     501    }}}
    123502
    124503lib.contains()
     
    130509    Notes: None
    131510    Code Example:
     511    {{{
     512        data = """
     513            <?xml version=\"1.0\"?>
     514            <run>
     515                <tool>
     516                    <about>Press Simulate to view results.</about>
     517                    <command>@tool/fermi @driver</command>
     518                </tool>
     519                <input>
     520                    <number id=\"temperature\">
     521                        <about>
     522                            <label>Ambient temperature</label>
     523                            <description>Temperature of the environment.</description>
     524                        </about>
     525                        <units>K</units>
     526                        <min>0K</min>
     527                        <max>500K</max>
     528                        <default>300K</default>
     529                    </number>
     530                    <number id=\"Ef\">
     531                        <about>
     532                            <label>Fermi Level</label>
     533                            <description>Energy at center of distribution.</description>
     534                        </about>
     535                        <units>eV</units>
     536                        <min>-10eV</min>
     537                        <max>10eV</max>
     538                        <default>0eV</default>
     539                    </number>
     540                </input>
     541            </run>
     542        """
     543
     544        lib = Rappture::Library()
     545        lib.loadXml(data)
     546        xmlObjs = lib.contains()
     547        len xmlObjs
     548        # 2
     549        # xmlObjs contains objects (pointers or copies of objects?)
     550        print xmlObjs
     551        # ::Rappture::Number ::Rappture::Number
     552        foreach obj in xmlObjs {
     553            obj.vvalue()
     554        }
     555        # 300
     556        # 0
     557    }}}
  • trunk/examples/objects/api/python/number

    r1610 r1619  
    4646    Notes: input arguments are used to construct the number object
    4747    Code Example:
     48    {{{
     49        n1 = Rappture.Number()
     50        n2 = Rappture.Number("temperature","K",300)
     51        n3 = Rappture.Number("temperature",units="K",300,min=0,max=500,
     52                                 label="Ambiant Temperature",
     53                                 desc="Temperature of the environment")
     54    }}}
    4855
    4956Rappture.Number(numObj)
     
    5461    Notes: None
    5562    Code Example:
     63    {{{
     64        n1 = Rappture.Number()
     65        n2 = Rappture.Number(n1)
     66    }}}
    5667
    5768
     
    6677           val, if provided, is used to set the object name
    6778    Code Example:
     79    {{{
     80        n = Rappture.Number()
     81        n.name()
     82        # ""
     83        n.name("temperature")
     84        n.name()
     85        # "temperature"
     86    }}}
    6887
    6988n.path([val])
     
    7796           val, if provided, is used to set the object path
    7897    Code Example:
     98    {{{
     99        n = Rappture.Number()
     100        n.path()
     101        # ""
     102        n.path("input")
     103        n.path()
     104        # "input"
     105    }}}
    79106
    80107n.label([val])
     
    87114           val, if provided, is used to set the object label
    88115    Code Example:
     116    {{{
     117        n = Rappture.Number()
     118        n.label()
     119        # ""
     120        n.label("Ambiant temperature")
     121        n.label()
     122        # "Ambiant temperature"
     123    }}}
    89124
    90125n.desc([val])
     
    99134           val, if provided, is used to set the object description
    100135    Code Example:
     136    {{{
     137        n = Rappture.Number()
     138        n.desc()
     139        # ""
     140        n.desc("Temperature of the environment")
     141        n.desc()
     142        # "Temperature of the environment"
     143    }}}
    101144
    102145n.hints([val])
     
    109152           val, if provided, is used to set the object hints
    110153    Code Example:
     154    {{{
     155        n = Rappture.Number()
     156        n.hints()
     157        # ""
     158        n.hints("none")
     159        n.hints()
     160        # "none"
     161    }}}
    111162
    112163n.color([val])
     
    119170           val, if provided, is used to set the object color
    120171    Code Example:
     172    {{{
     173        n = Rappture.Number()
     174        n.color()
     175        # ""
     176        n.color("none")
     177        n.color()
     178        # "none"
     179    }}}
    121180
    122181n.def([val])
     
    128187           val, if provided, is used to set the object default value
    129188    Code Example:
     189    {{{
     190        n = Rappture.Number()
     191        n.def()
     192        # ""
     193        n.def(300)
     194        n.def()
     195        # 300
     196    }}}
    130197
    131198n.cur([val])
     
    137204           val, if provided, is used to set the object current value
    138205    Code Example:
     206    {{{
     207        n = Rappture.Number()
     208        n.cur()
     209        # ""
     210        n.cur(450)
     211        n.cur()
     212        # 450
     213    }}}
    139214
    140215n.min([val])
     
    146221           val, if provided, is used to set the object min
    147222    Code Example:
     223    {{{
     224        n Rappture.Number()
     225        n.min()
     226        # ""
     227        n.min(0)
     228        n.min()
     229        # 0
     230    }}}
    148231
    149232n.max([val])
     
    155238           val, if provided, is used to set the object max
    156239    Code Example:
     240    {{{
     241        n = Rappture.Number()
     242        n.max()
     243        # ""
     244        n.max(500)
     245        n.max()
     246        # 500
     247    }}}
    157248
    158249n.units([val])
     
    164255           val, if provided, is used to set the object units
    165256    Code Example:
     257    {{{
     258        n = Rappture.Number()
     259        n.units()
     260        # ""
     261        n.units("K")
     262        n.units()
     263        # "K"
     264    }}}
    166265
    167266n.property(key[, val])
     
    173272    Notes: A copy val is stored in the property database
    174273    Code Example:
     274    {{{
     275        n = Rappture.Number()
     276        n.property("units")
     277        # ""
     278        n.property("units","K")
     279        # "K"
     280        n.units()
     281        # "K"
     282    }}}
    175283
    176284n.propremove(key)
     
    181289    Notes: None
    182290    Code Example:
     291    {{{
     292        n = Rappture.Number("temperature","K",300)
     293        n.property("units")
     294        # "K"
     295        n.propremove("units")
     296        # "K"
     297        n.property("units")
     298        # ""
     299    }}}
    183300
    184301n.convert(to)
     
    189306    Notes: the values stored in the object are changed
    190307    Code Example:
     308    {{{
     309        n = Rappture.Number("temperature","K",300)
     310        n.min("0K")
     311        n.max("500K")
     312        n.cur(450)
     313        out = n.convert("F")
     314        if (out.value() != 0) {
     315            sys.stderr.write(out.context())
     316            sys.stderr.write(out.remark())
     317        }
     318        n.min()
     319        # -459.67
     320        n.max()
     321        # 440.33
     322        n.def()
     323        # 80.33
     324        n.cur()
     325        # 350.33
     326    }}}
    191327
    192328n.value(to)
     
    200336            as the value.
    201337    Code Example:
     338    {{{
     339        n = Rappture.Number()
     340        n.value()
     341        # 0
     342        n.def(300)
     343        n.value()
     344        # 300
     345        n.cur(450)
     346        n.value()
     347        # 450
     348        n.value("F")
     349        # 350.33
     350    }}}
    202351
    203352n.vvalue([...])
     
    213362                hintKey=hintVal and be comma separated
    214363    Code Example:
     364    {{{
     365        n = Rappture.Number()
     366        n.cur(450)
     367        n.vvalue()
     368        # 450
     369        n.vvalue("units=F")
     370        # 350.33
     371    }}}
    215372
    216373n.random()
     
    222379           max if they were specified.
    223380    Code Example:
     381    {{{
     382        n = Rappture.Number()
     383        n.random()
     384        n.cur()
     385        # 1042.34
     386        # should be something more like:
     387        # n.configure(min=-30,max=30)
     388        # n.random()
     389        n.min(-30)
     390        n.max(30)
     391        n.random()
     392        n.cur()
     393        # 16.89
     394    }}}
    224395
    225396n.diff(o)
     
    231402    Notes: None
    232403    Code Example:
     404    {{{
     405        n1 = Rappture.Number("temperature","K",300,"0K","500K",
     406                                 "Ambiant Temperature",
     407                                 "Temperature of the environment")
     408        n2 = Rappture.Number("Ef","eV","4.5eV","0eV","10eV",
     409                                 "Fermi Level",
     410                                 "Energy at center of distribution")
     411        diffs = n1.diff(n2)
     412        # diffs is a list of tuples or list of lists
     413
     414        for ctype, prop, oVal, nVal in diffs {
     415            print ctype, prop, oVal, nVal
     416        }
     417        # c name temperature Ef
     418        # c units K eV
     419        # c def 300 4.5
     420        # c min 0 0
     421        # c max 500 10
     422        # c label "Ambiant Temperature" "Fermi Level"
     423        # c desc "Temperature of the environment" "Energy at center of distribution"
     424        #
     425        # Note that this function will find a difference in the
     426        # minimum values even though they are numerically equal.
     427        # This is because the objects have different units that
     428        # are not compatible. If compatible units were found,
     429        # n2's values would have been converted to n1's units
     430        # for each comparison.
     431    }}}
    233432
    234433n.addPreset(label, desc, val[, units])
     
    243442                in which they are created
    244443    Code Example:
     444    {{{
     445        n = Rappture.Number("temperature","K",300,"0K","500K",
     446                                "Ambiant Temperature",
     447                                "Temperature of the environment"]
     448        n.addPreset("Room Temperature","","300K")
     449        n.addPreset("Liquid Nitrogen","",77,"K")
     450        n.addPreset("Liquid Helium","","4.2K")
     451
     452        # 3 Presets stored in the Rappture.Number object
     453    }}}
    245454
    246455n.delPreset(label)
     
    251460    Notes: preset is removed from the object
    252461    Code Example:
     462    {{{
     463        n = Rappture.Number("temperature","K",300,"0K","500K",
     464                                "Ambiant Temperature",
     465                                "Temperature of the environment")
     466        n.addPreset("Room Temperature","","300K")
     467        n.addPreset("Liquid Nitrogen","",77,"K")
     468        n.addPreset("Liquid Helium","","4.2K")
     469
     470        n.delPreset("Liquid Helium")
     471        # 2 Presets stored in the Rappture.Number object
     472    }}}
    253473
    254474n.configure(as, c)
     
    267487    Notes: object is configured based on values in "c"
    268488    Code Example:
     489    {{{
     490        n = Rappture.Number()
     491        xmldata = """
     492            <?xml version="1.0">
     493            <number id="temperature">
     494                <about>
     495                    <label>Ambient temperature</label>
     496                    <description>Temperature of the environment.</description>
     497                </about>
     498                <units>K</units>
     499                <min>0K</min>
     500                <max>500K</max>
     501                <default>300K</default>
     502            </number>
     503        """
     504
     505        n.configure(RPCONFIG_XML,xmldata)
     506        n.name()
     507        # temperature
     508        n.label()
     509        # Ambient temperature
     510        n.desc()
     511        # Temperature of the environment.
     512        n.units()
     513        # K
     514        n.min()
     515        # 0
     516        n.max()
     517        # 500
     518        n.def()
     519        # 300
     520    }}}
    269521
    270522n.dump(as, c)
     
    283535    Notes: None
    284536    Code Example:
     537    {{{
     538        n = Rappture.Number("temperature","K",300,"0K","500K",
     539                                "Ambiant Temperature",
     540                                "Temperature of the environment")
     541        xmldata = n.dump(RPCONFIG_XML)
     542        print xmldata
     543
     544        # <number id="temperature">
     545        #     <about>
     546        #         <label>Ambient temperature</label>
     547        #         <description>Temperature of the environment.</description>
     548        #     </about>
     549        #     <units>K</units>
     550        #     <min>0K</min>
     551        #     <max>500K</max>
     552        #     <default>300K</default>
     553        # </number>
     554    }}}
    285555
    286556n.outcome()
     
    290560    Notes: None
    291561    Code Example:
     562    {{{
     563        n = Rappture.Number("temperature","K",300,"0K","500K",
     564                                "Ambiant Temperature",
     565                                "Temperature of the environment")
     566        out = n.outcome()
     567        if (out.value() != 0) {
     568            sys.stderr.write(out.context())
     569            sys.stderr.write(out.remark())
     570        }
     571    }}}
    292572
    293573n.is()
  • trunk/examples/objects/api/python/plot

    r1610 r1619  
    3535    Notes: None
    3636    Code Example:
     37    {{{
     38        lib = Rappture.Library()
     39        p = Rappture.Plot(lib)
     40    }}}
    3741
    3842Rappture.Plot(o)
     
    4347    Notes: None
    4448    Code Example:
     49    {{{
     50        lib = Rappture.Library()
     51        p1 = Rappture.Plot(lib)
     52        p2 = Rappture.Plot(p1)
     53    }}}
    4554
    4655
     
    5564           val, if provided, is used to set the object name
    5665    Code Example:
     66    {{{
     67        p = Rappture.Plot()
     68        p.name()
     69        # ""
     70        p.name("fdfactor")
     71        p.name()
     72        # "fdfactor"
     73    }}}
    5774
    5875p.path([val])
     
    6683           val, if provided, is used to set the object path
    6784    Code Example:
     85    {{{
     86        p = Rappture.Plot()
     87        p.path()
     88        # ""
     89        p.path("output")
     90        p.path()
     91        # "output"
     92    }}}
    6893
    6994p.label([val])
     
    76101           val, if provided, is used to set the object label
    77102    Code Example:
     103    {{{
     104        p = Rappture.Plot()
     105        p.label()
     106        # ""
     107        p.label("Fermi-Dirac Factor")
     108        p.label()
     109        # "Fermi-Dirac Factor"
     110    }}}
    78111
    79112p.desc([val])
     
    88121           val, if provided, is used to set the object description
    89122    Code Example:
     123    {{{
     124        p = Rappture.Plot()
     125        p.desc()
     126        # ""
     127        p.desc("A plot of the Fermi-Dirac Factor")
     128        p.desc()
     129        # "A plot of the Fermi-Dirac Factor"
     130    }}}
    90131
    91132p.hints([val])
     
    98139           val, if provided, is used to set the object hints
    99140    Code Example:
     141    {{{
     142        p = Rappture.Plot()
     143        p.hints()
     144        # ""
     145        p.hints("no hints")
     146        p.hint()
     147        # "no hints"
     148    }}}
    100149
    101150p.color([val])
     
    108157           val, if provided, is used to set the object color
    109158    Code Example:
     159    {{{
     160        p = Rappture.Plot()
     161        p.color()
     162        # ""
     163        p.color("no color")
     164        p.color()
     165        # "no color"
     166    }}}
    110167
    111168p.property(key[, val])
     
    117174    Notes: A copy val is stored in the property database
    118175    Code Example:
     176    {{{
     177        p = Rappture.Plot()
     178        p.property("name")
     179        # ""
     180        p.property("name","fdfactor")
     181        # "fdfactor"
     182        p.name()
     183        # "fdfactor"
     184    }}}
    119185
    120186p.propremove(key)
     
    125191    Notes: None
    126192    Code Example:
     193    {{{
     194        p = Rappture.Plot()
     195        p.name("fdfactor")
     196        p.property("name")
     197        # "fdfactor"
     198        p.propremove("name")
     199        # "fdfactor"
     200        p.property("name")
     201        # ""
     202    }}}
    127203
    128204p.add(x, y, fmt, name)
     
    138214            this follows matlab's formatting rules.
    139215    Code Example:
     216    {{{
     217        x = list()
     218        y = list()
     219        for i in range(0,10) :
     220            x.append(i)
     221            y.append(pow(i,2))
     222
     223        p = Rappture.Plot()
     224        p.add(x, y, fmt="g:o", name="xsquared")
     225        # a single curve, named "xsquared", is stored in the plot object
     226    }}}
    140227
    141228p.add(c, name)
     
    147234    Notes: Curve object should not be deleted by user?
    148235    Code Example:
     236    {{{
     237        x = list()
     238        y = list()
     239        for i in range(0,10) :
     240            x.append(i)
     241            y.append(pow(i,2))
     242
     243        c = Rappture.Curve()
     244
     245        c.axis(name="xvals", label="X Values",
     246                desc="Values along the X axis" val=x)
     247
     248        c.axis(name="yvals", label="Y Values",
     249                desc="Values along the Y axis", val=y)
     250
     251        p = Rappture.Plot()
     252        p.add(c, name="xsquared")
     253        # a single curve, named "xsquared", is stored in the plot object
     254    }}}
    149255
    150256p.count()
     
    154260    Notes: None
    155261    Code Example:
     262    {{{
     263        x = list()
     264        y1 = list()
     265        y2 = list()
     266        for i in range(0,10) :
     267            x.append(i)
     268            y1.append(pow(i,2))
     269            y2.append(pow(i,3))
     270        }
     271
     272        p = Rappture.Plot()
     273        p.add(x, y1, format="g:o", name="xsquared")
     274        p.add(x, y2, format="b-o", name="xcubed")
     275        print p.count()
     276        # 2
     277    }}}
    156278
    157279p.curve(name)
     
    162284    Notes: None
    163285    Code Example:
     286    {{{
     287        x = list()
     288        y1 = list()
     289        y2 = list()
     290        for i in range(0,10) :
     291            x.append(i)
     292            y1.append(pow(i,2))
     293            y2.append(pow(i,3))
     294        }
     295
     296        p = Rappture.Plot()
     297        p.add(x, y1, format="g:o", name="xsquared")
     298        p.add(x, y2, format="b-o", name="xcubed")
     299        c = p.curve("xsquared")
     300        print c.name()
     301        # xsquared
     302    }}}
    164303
    165304p.getNthCurve(n)
     
    171310    Notes: None
    172311    Code Example:
     312    {{{
     313        x = list()
     314        y1 = list()
     315        y2 = list()
     316        for i in range(0,10) :
     317            x.append(i)
     318            y1.append(pow(i,2))
     319            y2.append(pow(i,3))
     320        }
     321
     322        p = Rappture.Plot()
     323        p.add(x, y1, format="g:o", name="xsquared")
     324        p.add(x, y2, format="b-o", name="xcubed")
     325        c = p.getNthCurve(1)
     326        print c.name()
     327        # xcubed
     328    }}}
    173329
    174330p.vvalue([...])
     
    184340           hintKey=hintVal
    185341    Code Example:
     342    {{{
     343        x = list()
     344        y1 = list()
     345        y2 = list()
     346        for i in range(0,10) :
     347            x.append(i)
     348            y1.append(pow(i,2))
     349            y2.append(pow(i,3))
     350        }
     351
     352        p = Rappture.Plot()
     353        p.add(x, y1, format="g:o", name="xsquared")
     354        p.add(x, y2, format="b-o", name="xcubed")
     355        print p.vvalue()
     356        # [ [ [1 2 3 4 5 6 7 8 9 10] \
     357        #     [1 4 9 16 25 36 49 64 81 100] ] \
     358        #   [ [1 2 3 4 5 6 7 8 9 10] \
     359        #     [1 8 27 64 125 216 343 512 729 1000] ] ]
     360
     361    }}}
    186362
    187363p.random();
     
    193369           max if they were specified.
    194370    Code Example:
     371    {{{
     372        p = Rappture.Plot()
     373        p.random()
     374        # plot is filed with random data
     375        print p.vvalue()
     376        # [ [ [1 2 3 4 5 6 7 8 9 10] \
     377        #     [1 2 3 4 5 6 7 8 9 10] ] \
     378        #   [ [1 2 3 4 5 6 7 8 9 10] \
     379        #     [1 4 9 16 25 36 49 64 81 100] ] \
     380        #   [ [1 2 3 4 5 6 7 8 9 10] \
     381        #     [1 8 27 64 125 216 343 512 729 1000] ] ]
     382        print p.count()
     383        # 3
     384
     385    }}}
    195386
    196387p.diff(o);
     
    202393    Notes: None
    203394    Code Example:
     395    {{{
     396        p1 = Rappture.Plot()
     397        p1.random()
     398        # plot is filed with random data
     399        print p.vvalue()
     400        # [ [ [1 2 3 4 5 6 7 8 9 10] \
     401        #     [1 4 9 16 25 36 49 64 81 100] ] ]
     402
     403        p2 = Rappture.Plot()
     404        p2.random()
     405        # plot is filed with random data
     406        print p.vvalue()
     407        # [ [ [1 2 3 4 5 6 7 8 9 10] \
     408        #     [1 8 27 64 125 216 343 512 729 1000] ] ]
     409
     410        diffs = p1.diff(p2)
     411        # diffs is a list of tuples or list of lists.
     412
     413        for ctype, prop, oVal, nVal in diffs {
     414            print "%s %s %s %s" % (ctype, prop, oVal, nVal)"
     415        }
     416        # c name temperature Ef
     417        # c units K eV
     418        # c def 300 4.5
     419        # c min 0 0
     420        # c max 500 10
     421        # c label "Ambiant Temperature" "Fermi Level"
     422        # c desc "Temperature of the environment" "Energy at center of distribution"
     423        #
     424        # Note that this function will find a difference in the
     425        # minimum values even though they are numerically equal.
     426        # This is because the objects have different units that
     427        # are not compatible. If compatible units were found,
     428        # n2's values would have been converted to n1's units
     429        # for each comparison.
     430        #
     431        # if diffs is a flat list, user would need to write something like this:
     432        # for i in range(len(diffs)/4):
     433        #     ctype, prop, oVal, nVal = diffs[(i*4):(i*4)+4]
     434        #     print ctype, prop, oVal, nVal
     435
     436    }}}
    204437
    205438p.configure(as, c)
     
    218451    Notes: object is configured based on values in "c"
    219452    Code Example:
     453    {{{
     454        p = Rappture.Plot()
     455        xmldata = """
     456            <?xml version="1.0">
     457            <curve id="xsquared">
     458                <about>
     459                    <group>auto34</group>
     460                    <label>x squared</label>
     461                    <description>x values are squared</description>
     462                    <type></type>
     463                    <format>g:o</format>
     464                </about>
     465                <xaxis>
     466                    <label>x values</label>
     467                    <description>values being squared</description>
     468                    <units></units>
     469                    <scale>linear</scale>
     470                </xaxis>
     471                <yaxis>
     472                    <label>y values</label>
     473                    <description>squared values</description>
     474                    <units></units>
     475                    <scale>linear</scale>
     476                </yaxis>
     477                <component>
     478                    <xy>         1         1
     479                 2         4
     480                 3         9
     481                 4        16
     482                 5        25
     483                 6        36
     484                 7        49
     485                 8        64
     486                 9        81
     487                10       100
     488                    </xy>
     489                </component>
     490            </curve>
     491            <curve id="xcubed">
     492                <about>
     493                    <group>auto34</group>
     494                    <label>x cubed</label>
     495                    <description>x values are cubed</description>
     496                    <type></type>
     497                    <format>b-o</format>
     498                </about>
     499                <xaxis>
     500                    <label>x values</label>
     501                    <description>values being cubed</description>
     502                    <units></units>
     503                    <scale>linear</scale>
     504                </xaxis>
     505                <yaxis>
     506                    <label>y values</label>
     507                    <description>cubed values</description>
     508                    <units></units>
     509                    <scale>linear</scale>
     510                </yaxis>
     511                <component>
     512                    <xy>         1         1
     513                 2         8
     514                 3        27
     515                 4        64
     516                 5       125
     517                 6       216
     518                 7       343
     519                 8       512
     520                 9       729
     521                10      1000
     522                    </xy>
     523                </component>
     524            </curve>
     525        """
     526
     527        p.configure(RPCONFIG_XML,xmldata)
     528        print p.vvalue()
     529        # [ [ [1 2 3 4 5 6 7 8 9 10] \
     530        #     [1 4 9 16 25 36 49 64 81 100] ] \
     531        #   [ [1 2 3 4 5 6 7 8 9 10] \
     532        #     [1 8 27 64 125 216 343 512 729 1000] ] ]
     533
     534        for cur in range(p.count()):
     535            c = p.getNthCurve(cur)
     536            print c.name()
     537            print c.label()
     538            print c.desc()
     539            print c.format()
     540            for axisCnt in range(c.dims()):
     541                axis = c.getNthAxis(axisCnt)
     542                print axis.label()
     543                print axis.desc()
     544                print axis.units()
     545                print axis.scale()
     546                print axis.data()
     547        # xsquared
     548        # x squared
     549        # x values are squared
     550        # g:o
     551        # xaxis
     552        # x values
     553        # values being squared
     554        #
     555        # linear
     556        # [1 2 3 4 5 6 7 8 9 10]
     557        # yaxis
     558        # y values
     559        # squared values
     560        #
     561        # linear
     562        # [1 4 9 16 25 36 49 64 81 100]
     563        # xcubed
     564        # x cubed
     565        # x values are cubed
     566        # b-o
     567        # xaxis
     568        # x values
     569        # values being cubed
     570        #
     571        # linear
     572        # [1 2 3 4 5 6 7 8 9 10]
     573        # yaxis
     574        # y values
     575        # cubed values
     576        #
     577        # linear
     578        # [1 8 27 64 125 216 343 512 729 1000]
     579
     580    }}}
    220581
    221582p.dump(as, c)
     
    234595    Notes: None
    235596    Code Example:
     597    {{{
     598        x = list()
     599        y1 = list()
     600        y2 = list()
     601        for i in range(0,10) :
     602            x.append(i)
     603            y1.append(pow(i,2))
     604            y2.append(pow(i,3))
     605        }
     606
     607        p = Rappture.Plot()
     608        p.add(x, y1, format="g:o", name="xsquared")
     609        p.add(x, y2, format="b-o", name="xcubed")
     610        print p.dump(RPCONFIG_XML)
     611        # <curve id="xsquared">
     612        #     <about>
     613        #         <group>auto34</group>
     614        #         <label></label>
     615        #         <description></description>
     616        #         <type>(null)</type>
     617        #         <format>g:o</format>
     618        #     </about>
     619        #     <xaxis>
     620        #         <label></label>
     621        #         <description></description>
     622        #         <units></units>
     623        #         <scale>linear</scale>
     624        #     </xaxis>
     625        #     <yaxis>
     626        #         <label></label>
     627        #         <description></description>
     628        #         <units></units>
     629        #         <scale>linear</scale>
     630        #     </yaxis>
     631        #     <component>
     632        #         <xy>         1         1
     633        #      2         4
     634        #      3         9
     635        #      4        16
     636        #      5        25
     637        #      6        36
     638        #      7        49
     639        #      8        64
     640        #      9        81
     641        #     10       100
     642        #         </xy>
     643        #     </component>
     644        # </curve>
     645        # <curve id="xcubed">
     646        #     <about>
     647        #         <group>unnamed</group>
     648        #         <label></label>
     649        #         <description></description>
     650        #         <type>(null)</type>
     651        #         <format>b-o</format>
     652        #     </about>
     653        #     <xaxis>
     654        #         <label></label>
     655        #         <description></description>
     656        #         <units></units>
     657        #         <scale>linear</scale>
     658        #     </xaxis>
     659        #     <yaxis>
     660        #         <label></label>
     661        #         <description></description>
     662        #         <units></units>
     663        #         <scale>linear</scale>
     664        #     </yaxis>
     665        #     <component>
     666        #         <xy>         1         1
     667        #      2         8
     668        #      3        27
     669        #      4        64
     670        #      5       125
     671        #      6       216
     672        #      7       343
     673        #      8       512
     674        #      9       729
     675        #     10      1000
     676        #         </xy>
     677        #     </component>
     678        # </curve>
     679
     680    }}}
    236681
    237682p.outcome()
     
    241686    Notes: None
    242687    Code Example:
     688    {{{
     689        p = Rappture.Plot()
     690        out = p.outcome()
     691        if (out.value() != 0) {
     692            sys.stderr.write(out.context())
     693            sys.stderr.write(out.remark())
     694        }
     695    }}}
     696
    243697
    244698p.is()
  • trunk/examples/objects/api/tcl/plot

    r1610 r1619  
    161161        $p color
    162162        # ""
    163         $p color"no color"
     163        $p color "no color"
    164164        $p color
    165165        # "no color"
     
    366366        #   [ [1 2 3 4 5 6 7 8 9 10] \
    367367        #     [1 8 27 64 125 216 343 512 729 1000] ] ]
    368         put [$p count]
     368        puts [$p count]
    369369        # 3
    370370
     
    432432    Notes: object is configured based on values in "c"
    433433    Code Example:
     434    {{{
     435        set p [Rappture.Plot]
     436        set xmldata {
     437            <?xml version="1.0">
     438            <curve id="xsquared">
     439                <about>
     440                    <group>auto34</group>
     441                    <label>x squared</label>
     442                    <description>x values are squared</description>
     443                    <type></type>
     444                    <format>g:o</format>
     445                </about>
     446                <xaxis>
     447                    <label>x values</label>
     448                    <description>values being squared</description>
     449                    <units></units>
     450                    <scale>linear</scale>
     451                </xaxis>
     452                <yaxis>
     453                    <label>y values</label>
     454                    <description>squared values</description>
     455                    <units></units>
     456                    <scale>linear</scale>
     457                </yaxis>
     458                <component>
     459                    <xy>         1         1
     460                 2         4
     461                 3         9
     462                 4        16
     463                 5        25
     464                 6        36
     465                 7        49
     466                 8        64
     467                 9        81
     468                10       100
     469                    </xy>
     470                </component>
     471            </curve>
     472            <curve id="xcubed">
     473                <about>
     474                    <group>auto34</group>
     475                    <label>x cubed</label>
     476                    <description>x values are cubed</description>
     477                    <type></type>
     478                    <format>b-o</format>
     479                </about>
     480                <xaxis>
     481                    <label>x values</label>
     482                    <description>values being cubed</description>
     483                    <units></units>
     484                    <scale>linear</scale>
     485                </xaxis>
     486                <yaxis>
     487                    <label>y values</label>
     488                    <description>cubed values</description>
     489                    <units></units>
     490                    <scale>linear</scale>
     491                </yaxis>
     492                <component>
     493                    <xy>         1         1
     494                 2         8
     495                 3        27
     496                 4        64
     497                 5       125
     498                 6       216
     499                 7       343
     500                 8       512
     501                 9       729
     502                10      1000
     503                    </xy>
     504                </component>
     505            </curve>
     506        }
     507
     508        $p configure -as RPCONFIG_XML $xmldata
     509        puts [$p vvalue]
     510        # [ [ [1 2 3 4 5 6 7 8 9 10] \
     511        #     [1 4 9 16 25 36 49 64 81 100] ] \
     512        #   [ [1 2 3 4 5 6 7 8 9 10] \
     513        #     [1 8 27 64 125 216 343 512 729 1000] ] ]
     514
     515        for {set cur 0} {$cur < [$p count]} {incr cur} {
     516            set c [$p getNthCurve $cur]
     517            puts [$c name]
     518            puts [$c label]
     519            puts [$c desc]
     520            puts [$c format]
     521            for {set axisCnt 0} {$axisCnt < [$c dims]} {incr axisCnt} {
     522                set axis [$c getNthAxis $axisCnt]
     523                puts [$axis label]
     524                puts [$axis desc]
     525                puts [$axis units]
     526                puts [$axis scale]
     527                puts [$axis data]
     528            }
     529        }
     530        # xsquared
     531        # x squared
     532        # x values are squared
     533        # g:o
     534        # xaxis
     535        # x values
     536        # values being squared
     537        #
     538        # linear
     539        # [1 2 3 4 5 6 7 8 9 10]
     540        # yaxis
     541        # y values
     542        # squared values
     543        #
     544        # linear
     545        # [1 4 9 16 25 36 49 64 81 100]
     546        # xcubed
     547        # x cubed
     548        # x values are cubed
     549        # b-o
     550        # xaxis
     551        # x values
     552        # values being cubed
     553        #
     554        # linear
     555        # [1 2 3 4 5 6 7 8 9 10]
     556        # yaxis
     557        # y values
     558        # cubed values
     559        #
     560        # linear
     561        # [1 8 27 64 125 216 343 512 729 1000]
     562
     563    }}}
    434564
    435565dump -as <as>
     
    447577    Notes: None
    448578    Code Example:
     579    {{{
     580        for {set i 0} {$i < 10} {incr i} {
     581            lappend x $i
     582            lappend y1 [expr pow($i,2)]
     583            lappend y2 [expr pow($i,3)]
     584        }
     585
     586        set p [Rappture::Plot]
     587        $p add $x $y1 -format "g:o" -name "xsquared"
     588        $p add $x $y2 -format "b-o" -name "xcubed"
     589        puts [$p dump -as RPCONFIG_XML]
     590        # <curve id="xsquared">
     591        #     <about>
     592        #         <group>auto34</group>
     593        #         <label></label>
     594        #         <description></description>
     595        #         <type>(null)</type>
     596        #         <format>g:o</format>
     597        #     </about>
     598        #     <xaxis>
     599        #         <label></label>
     600        #         <description></description>
     601        #         <units></units>
     602        #         <scale>linear</scale>
     603        #     </xaxis>
     604        #     <yaxis>
     605        #         <label></label>
     606        #         <description></description>
     607        #         <units></units>
     608        #         <scale>linear</scale>
     609        #     </yaxis>
     610        #     <component>
     611        #         <xy>         1         1
     612        #      2         4
     613        #      3         9
     614        #      4        16
     615        #      5        25
     616        #      6        36
     617        #      7        49
     618        #      8        64
     619        #      9        81
     620        #     10       100
     621        #         </xy>
     622        #     </component>
     623        # </curve>
     624        # <curve id="xcubed">
     625        #     <about>
     626        #         <group>auto34</group>
     627        #         <label></label>
     628        #         <description></description>
     629        #         <type>(null)</type>
     630        #         <format>b-o</format>
     631        #     </about>
     632        #     <xaxis>
     633        #         <label></label>
     634        #         <description></description>
     635        #         <units></units>
     636        #         <scale>linear</scale>
     637        #     </xaxis>
     638        #     <yaxis>
     639        #         <label></label>
     640        #         <description></description>
     641        #         <units></units>
     642        #         <scale>linear</scale>
     643        #     </yaxis>
     644        #     <component>
     645        #         <xy>         1         1
     646        #      2         8
     647        #      3        27
     648        #      4        64
     649        #      5       125
     650        #      6       216
     651        #      7       343
     652        #      8       512
     653        #      9       729
     654        #     10      1000
     655        #         </xy>
     656        #     </component>
     657        # </curve>
     658
     659    }}}
    449660
    450661outcome
     
    454665    Notes: None
    455666    Code Example:
     667    {{{
     668        set p [Rappture::Plot]
     669        set out [$p outcome]
     670        if ([$out value] != 0) {
     671            puts stderr [$out context]
     672            puts stderr [$out remark]
     673        }
     674    }}}
     675
    456676
    457677is
Note: See TracChangeset for help on using the changeset viewer.