Importing Nbody text examples

Nbody examples are text strings/files which contain all of the settings which can be entered in the Settings view, plus the initial locations, initial velocities, and settings of all masses. For example, the text representation of the '2-body' built-in example is the following string:

Nbody_simulation_file_version = 1.0
Name = 2-body
Description = 2_symmetric_orbiting_masses
Data_alt = 7.000000000e+01
Data_az = 1.200000000e+02
Data_mag = 1.500000000e+02
Data_G = 1.250000000e+00
Data_dt = 5.000000000e-02
Data_ntrails = 500
Data_max_acc = 1.000000000e+01
Data_axes_origin = 0
Data_axes_origin_mass_index = 0
Data_selected_mass_index = -1
Data_show_axes = 1
Data_xform_trails = 0
Data_axis_length = 1.000000000e+00
Data_rho = 5.000000000e+02
Data_max_updates = 50
Data_nmasses = 2
Mass =     0     1.000000000e+00     1.000000000e+00     0.000000000e+00     0.000000000e+00     0.000000000e+00    -5.000000000e-01     0.000000000e+00     1.000000000e+00     2.500000000e-01     2.500000000e-01      1      0
Mass =     1     1.000000000e+00    -1.000000000e+00     0.000000000e+00     0.000000000e+00     0.000000000e+00     5.000000000e-01     0.000000000e+00     2.500000000e-01     1.000000000e+00     2.500000000e-01      1      0

You can create an Nbody example string by hand in a text editor, or by editing a string exported from one of the examples in the Nbody application. To export an example string, go to the Examples view, load the example, tap 'Save', choose the 'Copy to pasteboard' location, enter a name and description, and tap 'Save'. You can then paste the string into an email message in the Mail program and send it to another account. You can also create an Nbody example on your desktop computer by using a programming language such as Python to generate the initial mass coordinates and velocities and write the properly formatted example string to a file for emailing or placing on a web page.

The format of example strings must obey the following constraints:

  1. All characters in the string are ASCII.
  2. Lines are of the form 'keyword = value(s)', with spaces before and after the '='.
  3. All lines must end with just the '\n' newline character.
  4. Keywords and string values cannot contain spaces. The '_' character in a name or description value will be translated to a space on input.
  5. Name strings can only contain letters, numbers, '-', or '_'.
  6. The first line of the file must contain the Nbody_simulation_file_version keyword, followed by the version number (currently 1.0).
  7. All of the fields shown above are required: Name, Description, and all keywords beginning with 'Data_'. Valid ranges for values are:

    -180 <= Data_alt < 180
    0 <= Data_az < 360
    1e-11 <= Data_mag <= 1e6
    6.67e-11 <= Data_G <= 1e6
    1e-6 <= Data_dt <= 1e7
    0 <= Data_ntrails <= 10000
    1e-6 <= Data_max_acc <= 1e6
    0 <= Data_axes_origin <= 2 (for {0,0,0}, centroid, and mass relative)
    0 <= Data_axes_origin_mass_index < Data_nmasses
    -1 <= Data_selected_mass_index < Data_nmasses (-1 for no selection)
    0 <= Data_show_axes <= 1
    0 <= Data_xform_trails <= 1
    1e-6 <= Data_axis_length <= 1e12
    1e-60 <= Data_rho <= 1e6 (density)
    1 <= Data_max_updates <= 100
    0 <= Data_nmasses <= 100

  8. Masses are specified by a line having the Mass keyword and 13 values. The number of mass entries must be the same as Data_nmasses. Mass values on each line are in the following order after the '=', and are separated by spaces:

    1. Index. Must be a unique integer from 0 to Data_nmasses - 1.
    2. Mass.
    3-5. Initial values for x, y, z.
    6-8. Initial values for vx, vy, vz.
    9-11. Color as red, green, blue (each from 0.0 to 1.0).
    12. Show trails flag (0 or 1).
    13. Fixed position flag (0 or 1).

A string copied to the general pasteboard which meets these constraints and can be correctly parsed by the Nbody application will show up as a table entry in the 'Example in iPhone pasteboard' section of the Examples view. At present, there is no facility for reporting string format errors. Strings which are correctly formatted will show up in the table, while all others will not. If you think you have created a correctly formatted string, but it does not appear in the Examples table, please check it carefully against all the criteria listed above.

Two possible ways to copy an example string into the pasteboard are from either Safari or the Mail program. From Safari, navigate to a website on which an Nbody example appears as preformatted text (such as the 2-body example above), select all of the text (by first selecting a single word and then moving and expanding the selection to the first line of the string and then expanding it to include all lines) and tap the 'copy' pop-up button. You must include the entire string in the selection, from 'Nbody_simulation_file_version' to the end of the last line. Another convenient way to select an example string from a website is to place the string in a 'textarea' tag (as shown below). In this case, you should mark the text area as 'readonly' so that it cannot be edited. Tap in the text area to bring up the keyboard, select a word, and then tap the 'select all' pop-up. Although the text area wraps the long Mass lines, it does not break them into more than one line.

To import an example via email, send the example to your iPhone email account, open the message and either 'select all' or select only the example string (again, from 'Nbody_simulation_file_version' to the end of the last line), and tap 'copy'.

NOTE: You must make sure that your sending email program does not break up the long Mass lines into several lines. If it does, you will have to re-join the lines before copying the example string to the pasteboard, or it will not appear in the Examples view.

(iPhone and Safari are trademarks of Apple, Inc.)

© 2009 Sky Coyote