Alpha Video Training
Results 1 to 5 of 5

Thread: Wind Direction Xbasic

  1. #1
    "Certified" Alphaholic CharlesParker's Avatar
    Real Name
    Charles Parker
    Join Date
    Dec 2012
    Location
    New Orleans, LA
    Posts
    2,115

    Default Wind Direction Xbasic

    Don't laugh at my code if you can easily see how it could be more efficiently written!
    I did my best.

    So here's the scenario. I am using an openweathermap.org API to pull in the weather data, specifically the wind direction and speed. The wind direction comes back from them as the degrees of a circle, so 360 is the same as zero which would be North (N) as well as the first 11.25 degrees, 180 would be due south, 45 degrees NE, and 90 degrees E. I wanted to use the appropriate abbreviation based on the degree so I did some research and I think I got it!
    It took me all evening as I have never used an array, and not real familiar with math functions.

    I took some javascript i found and figured out how to make it work in xbasic...
    Again, what this does is display the right abbreviation based on the returned json data in the api call to openweathermaps.org.
    I thought I might share...and if you do see a way to make it better let me know - it was my first stab at this!
    The variable "purl" is a concatenated field to include the required URL with the lat & lon fields and my appid as required by the API


    Code:
    function weathercall as c (e as p)
        'debug(1)
        dim weathercall as c
    dim myresponse as p
    dim purl as c
    purl = e._currentRowDataNew.concat_coordinates
    myresponse = http_get(purl)
    dim pp as p
    pp = json_parse(myresponse.body,.t.)
    e.control.wind_speed = pp.wind.speed
    e.control.deg = pp.wind.deg
    dim num as n
    dim val as n
    dim mydir as c
    dim mydir2 as c
    dim numoff as n
    num = pp.wind.deg
    numoff = (num - 11.25)/22.5
        val= round(numoff,0)
        mydir = abs(val)
    
    dim arr[16] as p
        arr[1].0="N"
        arr[1].1="NNE"
        arr[1].2="NE"
        arr[1].3="ENE"
        arr[1].4="E"
        arr[1].5="ESE"
        arr[1].6="SE" 
        arr[1].7="SSE"
        arr[1].8="S"
        arr[1].9="SSW"
        arr[1].10="SW"
        arr[1].11="WSW"
        arr[1].12="W"
        arr[1].13="WNW"
        arr[1].14="NW"
        arr[1].15="NNW"
    
    mydir2 = arr.dump_properties(mydir)
    e.control.wind_direction = mydir2
    end function
    Screenshot shows the test UXweather.JPG made to build it
    NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

  2. #2
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,603

    Default Re: Wind Direction Xbasic

    Very nice result. Well done.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

  3. #3
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,355

    Default Re: Wind Direction Xbasic

    Hi Paul,

    Any time you get things working the way you want, you've done a good job.
    With that said, you could just dim arr as p. No need for the [16].

  4. #4
    "Certified" Alphaholic
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    1,018

    Default Re: Wind Direction Xbasic

    dim arr[0..15] as c
    arr.initialize( comma_to_crlf("N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW"))

  5. #5
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,627

    Default Re: Wind Direction Xbasic

    Very cool .. nicely done Charles.
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

Similar Threads

  1. Is this a wind up?
    By Ted Giles in forum General Questions
    Replies: 0
    Last Post: 09-18-2012, 05:17 AM
  2. Some Direction Please
    By dik_coleman in forum Alpha Five Version 5
    Replies: 10
    Last Post: 12-23-2003, 10:38 PM
  3. Help set me in the right direction
    By BRIAN GRAY in forum Alpha Five Version 5
    Replies: 1
    Last Post: 05-06-2003, 03:01 AM
  4. Need a direction.....
    By Jeff Klages in forum Alpha Five Version 4
    Replies: 8
    Last Post: 05-07-2002, 07:49 PM
  5. need some direction
    By eeetee in forum Alpha Five Version 4
    Replies: 1
    Last Post: 05-10-2000, 10:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •