Hello Christian,
There is no Load function for csv files in Ox.
One suggestion is to read the csv file into Excel and then load the xls
file with dbase.LoadXls("filename") (or dbase.Load("filename.xls").
If the file is too large for Excel, you have to convert it to a format
readable to Ox, e.g. by replacing the commas and quotes (see the
alternative load options in the member function documentation for the
Database class).
Alternatively, and maybe more straightforward, is to use the fscan and
sscan functions. Then you can specify the format for each item
separately. But you have to Create the database separately, and Append
the data using the variable names and data matrix.
But BEFORE you can load your data into a Database object, all values
have to be NUMERIC. The first variable looks like a binary value, and
the last is a string (or "no data"? The "no data" specifier in Ox is
normally the string .NaN, but it can be changed, I think).
Binaries are not a data type in Ox, as far as I know (only octal and
hexadecimal). So these will have to be read as strings or integers
(loosing the initial 0). But strings do not go into Databases, except as
variable names. Strings can only be read into arrays.
Good luck,
Tom
Christian M. Dahl wrote:
>Dear all,
>
>I am trying to load the variable "p1" from the following csv-file:
>
>// Ex1.csv
>/*=================================================================
>"hs","cty_code","all_val_mo","p1","p2"
>"0101110000","1220",60600, .5713,"."
>"0101110000","2010",11700, .4286,"."
>=================================================================*/
>
>My code is:
>
>//Main Program
>//=================================================================
>#include <oxstd.h>
>#import <database>
>#include <oxfloat.h>
>
>
>main()
>{
> decl dbase = new Database();
>
> dbase.Load("Ex1.csv");
> decl p1 = dbase.GetVar("p1");
> print("p1:",p1);
>}
>//=================================================================
>
>
>Unfortunately, my output is:
>
>//Output
>/*=================================================================
>Ox version 4.04 (Windows) (C) J.A. Doornik, 1994-2006
>This version may be used for academic research and teaching only
>p1:
> 0.00000
> 1.0000
>=================================================================*/
>
>The reported values should have been p1=(.5713,.4286)'.
>
>Any suggestions on how to "correct" this problem would be greatly
>appreciated (I should note that I am working with very large csv files so
>simply modifying the csv file by "hand" is not an option)
>
>Cheers,
>
>Christian M. Dahl
>Associated Prof.
>Purdue University
>
>
>
--
Tom Petersen
Transport and Location Analysis (TLA)
Teknikringen 78 B, 1st floor
KTH, SE-100 44 Stockholm
Phone: +46 (0)8-790 68 33
Fax: +46 (0)8-790 70 02
Mobile: +46 (0)70-424 00 75
Web: http://www.infra.kth.se/~tomp/
|