Re: load query output into array

From: donna Cote <d-cote_at_nyahnyahspammersnyahnyah>
Date: Thu Aug 25 2011 - 08:26:01 MDT

Using asciiread to read a file is not a problem. I want to run the query
"on-the-fly" and redirect the output to the NCL script. Maybe some
system or systemfunc code? Will asciiread cough up an error if I try
something like

txt = asciiread(systemfunc("select datadatetime, longitude, latitude,
depth, temperature, axbtidtext from axbtdata order by axbtidtext,
datadatetime limit 3; | cat - "), -1, "string")

Hmmm

On 8/24/11 5:12 PM, Dennis Shea wrote:
> fname = "donna.SQL.txt"
> txt = asciiread(fname, -1, "string")
> print(txt)
>
> nrow = dimsizes(txt)
> ncol = str_fields_count(txt(0), ",") ; use initial line
> print(ncol)
>
> data = new( (/nrow,ncol/), "string")
> do nr=0,nrow-1
> data(nr,:) = str_split(txt(nr), ",")
> end do
> print(data) ; all elements are strings
>
> lat = tofloat(data(:,1)) ; string to float
> lon = tofloat(data(:,2))
> z = tofloat(data(:,3))
>
>
> ===
> As RickB comments ... not sure how you need 'time'
>
> Good Luck
>

Rick, the sample is a slapped together example. I could easily use
postgres functions to put the date into a format like yyyymmddTHHMMSS-00

I'm past that part of this search for answers.

> On 8/24/11 3:00 PM, Rick Brownrigg wrote:
>> Hi Donna,
>>
>> Doesn't ascii read require data of all the same type? You might be
>> able to convert your dates into "seconds since the epoch" via your sql
>> query:
>>
>> http://www.postgresql.org/docs/8.1/static/functions-datetime.html
>>
>> (search for "epoch" on that page)
>>
>> I'm not sure how you'd reconstitute those values back into a timestamp
>> in NCL; perhaps its not crucial to your app?
>>
>> Rick
>>
>> On Aug 24, 2011, at 12:53 PM, donna Cote wrote:
>>
>>> I'm familiar with asciiread but I'm stumped about how to go about taking
>>> the output of a PostgreSQL query (text, rows of data) and loading those
>>> columns into NCL arrays. How might I approach this idea?
>>>
>>> Sample query:
>>> select datadatetime, longitude, latitude, depth, temperature, axbtidtext
>>> from axbtdata order by axbtidtext, datadatetime limit 3;
>>>
>>> Sample output (comma-separated or can be space separated):
>>> 2010-05-08 05:40:39-05,-85.051,28.341,0,23.07,2010-129-15:57:28
>>> 2010-05-08 05:40:39-05,-85.051,28.341,-3,22.97,2010-129-15:57:28
>>> 2010-05-08 05:40:39-05,-85.051,28.341,-1.5,23.07,2010-129-15:57:28
>>>
>>> Donna
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Aug 25 08:26:24 2011

This archive was generated by hypermail 2.1.8 : Thu Aug 25 2011 - 09:54:48 MDT