On Wednesday, September 30, 2015 at 11:15:18 PM UTC-3, Lim wrote:
> However the program stop in ReadF, lun, data with the meassages:
> % READF: End of file encountered. Unit: 100
> Execution halted at: mydataASCII 11
>
> could someone show me what i am doing wrong?.
It sounds like the problem happens because you have 3 fields that are strings, and readf is reading them without an explicit format. By default, readf will read a string up to the end of the line. If you do not supply a format, it has no way of knowing at which character the fields datei and datef end, so it reads datei to the end of the line, then will read datef from the next line. You can check to see if that is the case by printing the values of your data array, to see how it was filled up by readf up to the point the program stopped (because it hit the end of the file).
You have to either give readf an explicit format, or read the lines, split them and give each field the proper value. If you have a recent version of my library (pp_lib, http://ppenteado.net/idl/pp_lib/doc/index.html), you can read it just with:
data=pp_parsetext('mydata.dat',nheader=0,delimiter=', ',/as_struct,fieldnames=['var1','var2','var3','datei','datef ','cnt'])
When I do that with your example data, I get:
IDL> data
[
{
"VAR1": 456.33999999999997,
"VAR2": 23.981999999999999,
"VAR3": 4.7999999999999998,
"DATEI": "9/10/2012",
"DATEF": "9/15/2012",
"CNT": "Brazil"
},
{
"VAR1": 3491.3299999999999,
"VAR2": 10003.100000000000,
"VAR3": 10.000000000000000,
"DATEI": "8/10/2014",
"DATEF": "10/10/2014",
"CNT": "USA"
},
{
"VAR1": 333.19999999999999,
"VAR2": 1.3000000000000000,
"VAR3": 100.20000000000000,
"DATEI": "5/5/2010",
"DATEF": "8/20/2010",
"CNT": "USA"
},
{
"VAR1": 1211.8399999999999,
"VAR2": 22.399999999999999,
"VAR3": 82.200000000000003,
"DATEI": "10/15/2014",
"DATEF": "10/20/2014",
"CNT": "UK"
}
]
|