swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: InFile method usage


From: Pietro Terna
Subject: Re: InFile method usage
Date: Sun, 07 Feb 1999 12:06:18 +0100

        Hi Marcus,

        this is exactly the kind of explanations that we need to improve our
knowledge about Swarm! Please write a lot of them.

        Thanks, Pietro

At 15.10 06/02/99 -0800, you wrote:
>>>>>> "RLR" == Rick Riolo <address@hidden> writes:
>
>RLR> 1. Does a method like getDouble (&friends) span white space
>RLR> (blanks,tabs,newlines) before deciding if the next token is a
>RLR> double, and if so, loading it into the given double variable?
>
>Yes.
>
>RLR> 2. Does getDouble accept values like 22 32 4444 as valid double
>RLR> values?
>
>Yes.
>
>RLR> 3. If input looks like: 333.3 abc 4443.3 and I send three
>RLR> getDouble messages to anInFile, will it read 333.3 ok, return
>RLR> error for abc, then read 4443.3 ok?  That is, does it leave the
>RLR> InFile read-point after the "abc" after an error?
>
>It leaves the read-point before the abc.  This is the behavior of scanf
>conversion failures.  Thus, the 4443.3 will never read.
>
>
>To load data in to Swarm, I suggest using R
>(http://www.ci.tuwien.ac.at/R) to read in the data, and then store it
>as HDF5.  R is programmable, so there are many options for preprocessing
>data for Swarm. 
>
>Here's an example: 
>
>1. Given a text file of data to load, say `input.txt',
>----
>$ cat > input.txt << EOF
>val1 val2 val3
>222  32   4444
>111  16   2222
>EOF
>----
>
>2. First, run R, the version at:
> ftp://ftp.santafe.edu/pub/swarm/support-software
>----
>$ R
>----
>
>3. Read in the data file from input.txt, using the first line to define
>the field names.  Assign the result to the `data' variable.
>----
>> mydata <- read.table("input.txt", header=TRUE) 
>----
>
>4. Then, tag the `data' variable with attributes telling Swarm how to 
>use it.  Tell Swarm that the object should be loaded as a List.
>---- 
>> attr(data,"type") <- "List"
>----
>
>5. Also tag the object telling Swarm how to treat each component in
>the List.  Tell Swarm that the items in the List should be of
>MyClass type (see the class definition below).
>----
>> attr(data,"component-type") <- "MyClass"
>----
>
>6. Currently, in the simplest case, Swarm expects to get
>objects from two sources.  One place is the ~/.swarmArchiver file,
>e.g. the place where window geometry is saved.  The other place, new
>to Swarm 1.4, is from a file called ~/swarmArchiver.hdf.  Objects
>stored in both of these files are organized hierarchally by the owning
>application, and the application's `personality' or `mode' identifier.
>In order for a Swarm model to read an object from one these files, it
>is necessary to tell Swarm what model will own the object.
>----
>> inputapp <- list(default=list(data=mydata))
>----
>What this expression means is to create an object of the form below, and
>store it to the variable inputapp.  (The other names, default and data,
>are not global names, but exist only within their respective lists.)
>
>+------------------+
>| inputapp         |
>|  +------------+  |
>|  | default    |  |
>|  | +-------+  |  |
>|  | | data  |  |  |
>|  | +-------+  |  |
>|  +------------+  |
>+------------------+
>
>The `inputapp' and `default' shells around `data' is necessary for Swarm
>find what data is relevant to a particular application mode-of-use.
>
>7. Finally, once you've created the data, and described the application
>context, you can save it to file: 
>----
>> hdf5save("swarmArchiver.hdf", inputapp)
>----
>(This is assuming you are in your home directory.)
>
>8. Quit R.
>----
>> quit()
>----
>
>9. Now the data can be loaded in to Swarm.  Although Swarm will create
>classes on-the-fly if necessary, it tends to be easier to work with an
>object if there are some methods defined, although Probes are another option.
>The data file above is described by a class like this:
>
>----
>@interface MyClass: CreateDrop
>{
>  double val1;
>  double val2;
>  double val3;
>}
>@end
>
>@implementation MyClass
>- print
>{
>  printf ("%f %f %f\n", val1, val2, val3);
>  return self;
>}
>@end   
>----
>
>10. To recover the List of MyClass instances stored in the HDF5, you
>simply ask for the object by name:
>
>----
> obj = [hdf5Archiver getObject: "data";
>----
>
>11. Then printing the results:
>
>---
> [obj forEach: M(print)]; 
>---
>
>..you get:
>
>----
>address@hidden $ ./inputapp
>222.000000 32.000000 4444.000000
>111.000000 16.000000 2222.000000   
>----
>
>                  ==================================
>   Swarm-Support is for discussion of the technical details of the day
>   to day usage of Swarm.  For list administration needs (esp.
>   [un]subscribing), please send a message to <address@hidden>
>   with "help" in the body of the message.
>
>


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]