473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Parsing a setup file

Hi,

I have a setup file for some numerical simulation code written in
C that looks like this:

dt 0.1
time 0.0
nupdate 10
noutput 100
ntotal 10000
G 39.476926421373015
Sun 1.00000597682
mplanet 9.547861040430418e-4
3.409530427945 3.635870038323 .03424028779975
-2.0471057839802485 2.0178211484578044 -9.730193916219667e-4
mplanet 2.8558373315055975e-4
6.612079829705 6.386934883415 -.1361443021015
-1.5268292602445992 1.4623064051166743 6.108354829704997e-3
mplanet 4.372731645458918e-5
11.16769742623 16.04343604329 .3617849409933
-1.1927379555398092 .7563317049955387 -7.950313544811802e-3
particle
5.0 0.2 10.5
0.0 0.0 10.0
particle
6.0 0.1 5.5
0.0 180.0 -10.0

there can be any number of mplanet and particle enteries in the the
file.
As I am working on porting this code to python I am trying to figure out
an efficient way of parsing such data into the program. I have the
freedom
to play around with the setup file(s) which is nice. I have played
around with
cfgparse, which I like, and made a file like this

[DEFAULT]
dt = 0.1
time = 0.0

and so on, but that does not give me a good way of parsing in the
list of
mplanets and particles. I can write my own little parser to handle a
file
that contains only the mplanets or particles, but I am wondering if
there are
any parsers out there that will handle this type of data? Or is there a
way to organize my setup file that would simplify the input that I am
missing?

Cheers
Tommy
Apr 3 '07 #1
1 1484
Tommy Grav wrote:
Hi,

I have a setup file for some numerical simulation code written in C
that looks like this:

dt 0.1
time 0.0
nupdate 10
noutput 100
ntotal 10000
G 39.476926421373015
Sun 1.00000597682
mplanet 9.547861040430418e-4
3.409530427945 3.635870038323 .03424028779975
-2.0471057839802485 2.0178211484578044 -9.730193916219667e-4
mplanet 2.8558373315055975e-4
6.612079829705 6.386934883415 -.1361443021015
-1.5268292602445992 1.4623064051166743 6.108354829704997e-3
mplanet 4.372731645458918e-5
11.16769742623 16.04343604329 .3617849409933
-1.1927379555398092 .7563317049955387 -7.950313544811802e-3
particle
5.0 0.2 10.5
0.0 0.0 10.0
particle
6.0 0.1 5.5
0.0 180.0 -10.0

there can be any number of mplanet and particle enteries in the the file.
As I am working on porting this code to python I am trying to figure out
an efficient way of parsing such data into the program. I have the freedom
to play around with the setup file(s) which is nice. I have played
around with
cfgparse, which I like, and made a file like this

[DEFAULT]
dt = 0.1
time = 0.0

and so on, but that does not give me a good way of parsing in the list of
mplanets and particles. I can write my own little parser to handle a file
that contains only the mplanets or particles, but I am wondering if
there are
any parsers out there that will handle this type of data? Or is there a
way to organize my setup file that would simplify the input that I am
missing?

Cheers
Tommy
pyaml is good for this kind of thing. No parser needed.
Also, you may be mistaken about ConfigParser, you just need
to indent line continuations (and who says the syntactical meaning of
whitespace is not a good thing?). E.g.:
euler 6% cat test.conf
[stuff]
mplanet = 4.372731645458918e-5
11.16769742623 16.04343604329 .3617849409933
-1.1927379555398092 .7563317049955387 -7.950313544811802e-3

pyfrom ConfigParser import ConfigParser
pyc = ConfigParser()
pyc.read('test.conf')
['test.conf']
pyc.items('stuff')

[('mplanet',
'4.372731645458918e-5\n11.16769742623 16.04343604329
..3617849409933\n-1.1927379555398092 .7563317049955387
-7.950313544811802e-3')]

James
Apr 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Phil Powell | last post by:
What would one best recommend to parse an existing Excel spreadsheet (was done in Excel 97 or 2000 not sure to be honest)? I am looking for the most practical way of parsing an existing...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
2
by: Brett | last post by:
I uploaded an ASP.NET website from my developer machine to a remote server. The paths differ slightly as follows: Local Path: C:\Inetpub\wwwroot\mysite Server Path: C:\Inetpub\mysite.com\ I...
0
by: XML newbie: Urgent pls help! | last post by:
When I try to parse: I get the following error message: Unable to cast COM object of type 'Microsoft.SqlServer.MSXML6.DOMDocumentClass' to interface type 'MSXML2.ServerXMLHTTP40'. This operation...
0
by: XML newbie: Urgent pls help! | last post by:
I am using Vb.net. I am new to XML.I appreciate your help in advance. Please reply soon. When I try to parse: I get the following error message: Unable to cast COM object of type...
6
by: giulianodammando | last post by:
In the development of a simple numerical simulation software i need to read some initialization parameters from a file that looks like: # Global Setup species = 1; \begin{specie}<1>...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
3
by: =?Utf-8?B?RGFuYQ==?= | last post by:
I am re-posting this message after registering my posting alias. When I specify an end tag for the clear element of namespaces in my web.config file, the parser error "Unrecognized element 'add'"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.