Thread: URL help!

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    27

    Smile URL help!

    I'm fairly new at this (i.e., one intro programming course in C, 4 years ago and I've been re-learning for the past week), so bear with me. I have a LARGE data collection project where I need to grab 30 years worth, in hourly increments of only certain variables (i.e., day/hour, temperature, pressure, wind speed and several latitude/longitude coordinates), from a climate data website, make calculations, and output to another file as raw data for analysis using a completely different program.

    I know that getting the data would require ‘wget’ and changing certain components of the URL (which I understand is called 'parsing a URL'?) many, many, many, many, many… times! After browsing a few tutorials I'm still at a loss as to how to do this. I know what loops are and that they somehow apply, but I’m not exactly sure how they would work here.

    Here's one of those URLs to give you an idea...

    "http://nomads.ncdc.noaa.gov/dods/NCEP_NARR_DAILY/200901/20090101/narr-a_221_20090101_0000_000.ascii?tmpprs[0][3][94][327]"

    I'd need to adjust... "200901" and "20090101", "tmpprs" and each of these four components, "[0][3][94][327]" to represent different values.

    Again I'm fairly new at this ‘language’ (i.e., speak slowly please...lol!) Any suggestions are greatly appreciated!!!


    - Thanks!
    Last edited by Liz320; 05-06-2009 at 02:02 PM. Reason: Sorry...trying not to have a hyperlink in here.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    I would advise to split the problem in 2: write a script in any higher level language (shell or python or whatever) to retrieve your data from the website and store it in files, and write your calculation program (in C but you can consider alternatives here too) which takes those files in input and output the result. Trying to embed the network part in your c program, as you are beginner, will cost you a lot of time for no real interest.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    27
    Quote Originally Posted by root4 View Post
    I would advise to split the problem in 2: write a script in any higher level language (shell or python or whatever) to retrieve your data from the website and store it in files, and write your calculation program (in C but you can consider alternatives here too) which takes those files in input and output the result. Trying to embed the network part in your c program, as you are beginner, will cost you a lot of time for no real interest.

    Thanks and I agree on this approach. Sorry for not being more specific, but I'm concerned about working with this URL. How would I get the values to change in the URL, hundreds or more like thousands of times? I'm not sure how to assign them in order to get what I need out into the file, or what that would entail when they are separate parts of a URL.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    curl can fetch URLs with wildcards
    cURL - How To Use
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    27
    I think I'm just looking for a way to parse the link. Anyone have any suggestions?

    Thanks,

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    For instance

    Code:
    for ( y = 1970 ; y <= 2009 ; y++ ) {
        sprintf( buff, "http://nomads.ncdc.noaa.gov/dods/NCEP_NARR_DAILY/%4d01/%4d0101/narr-a_221_20090101_0000_000.ascii?tmpprs", y, y );
    }
    More loops, more combinations.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    27
    Quote Originally Posted by Salem View Post
    For instance

    Code:
    for ( y = 1970 ; y <= 2009 ; y++ ) {
        sprintf( buff, "http://nomads.ncdc.noaa.gov/dods/NCEP_NARR_DAILY/%4d01/%4d0101/narr-a_221_20090101_0000_000.ascii?tmpprs", y, y );
    }
    More loops, more combinations.

    Thank you!!!!!!!!!!!!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. URL escape issue
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 08-12-2008, 11:45 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. frustration on URL encode-decode
    By Lince in forum C Programming
    Replies: 22
    Last Post: 08-22-2007, 05:36 PM
  4. Replies: 1
    Last Post: 07-02-2007, 09:22 AM
  5. Url query encoding/decoding
    By Niara in forum Networking/Device Communication
    Replies: 6
    Last Post: 04-25-2007, 03:30 PM