We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Using Process to download text file...and...
Page Index Toggle Pages: 1
Using Process to download text file...and... (Read 608 times)
Using Process to download text file...and...
Nov 7th, 2009, 12:35pm
 
Would someone please give me a short example of how I could parse out this downloaded file,  and get the parameter that I am looking for.

The file I am accessing on the internet is located at:

ftp://ftp.swpc.noaa.gov/pub/lists/costello/ace_pkp_15m.txt

Here's a very short sample of the file structure:

Cheesyata_list: ace_pkp_15m.txt
:Created: 2009 Nov 07 2021 UT
# Prepared by the U.S. Dept. of Commerce, NOAA, Space Environment Center.
# Please send comments and suggestions to SEC.Webmaster@noaa.gov
#
# Units: Predicted Index 0-9 in Kp units
# Status(S): 0 = nominal solar wind input data,
#       1 to 5 = incomplete input data, but model output available
#           >5 = incomplete input data, no model output
# Solar Wind Source: ACE Satellite
# Missing data values: -1
#
#              15-minute Costello Geomagnetic Activity Index
#
# UT Date   Time         -Predicted Time-  Predicted  Lead-time  USAF Est.
# YR MO DA  HHMM   S     YR MO DA  HHMMSS    Index    in Minutes     Kp  
#-------------------------------------------------------------------------
2009 10 31  1800   0   2009 10 31  191400     1.67      74.0        0.00
2009 10 31  1815   0   2009 10 31  192853     1.33      73.9        0.00
2009 10 31  1830   0   2009 10 31  194404     1.33      74.1        0.00

The only data I am interested in would be in the last line of the file, in the 10th column,  which shows up in the above sample as 1.33...

I know I can already connect to that url within Processing,  by using the following syntax, where urlstr is equal to the URL of the file shown above.

URL url = new URL(urlstr);
   URLConnection conn = url.openConnection();
   conn.connect();

I just need to know how to extract that one very small piece of data from the file.

PHP is not an option, as I don't have access to a server,  and the free ones don't allow you to run this type of php script.

thanks....
Jim
Re: Using Process to download text file...and...
Reply #1 - Nov 7th, 2009, 2:30pm
 
Just use loadStrings() which accepts an URL, and access the column data with lines[lines.length-1].substring(46, 50)

OK, here is the full code, as I tested what I wrote...
Code:
String lines[] = loadStrings("ftp://ftp.swpc.noaa.gov/pub/lists/costello/ace_pkp_15m.txt");
String data = lines[lines.length-1].substring(46, 50);
println(data);
Re: Using Process to download text file...and...
Reply #2 - Nov 7th, 2009, 3:03pm
 
Phlho,

Thank you very much for putting up with all my questions today,  and for all the assistance.  

Jim
Page Index Toggle Pages: 1