User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Legacy and Other Languages section within the Software Development category of DaniWeb, a massive community of 402,918 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,226 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Legacy and Other Languages advertiser: Programming Forums
Views: 578 | Replies: 4
Reply
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 100
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 8
PoovenM PoovenM is offline Offline
Junior Poster

Perl to Python

  #1  
Jul 19th, 2008
Hi guys, I'm trying to make sense of some Perl code. I haven't actually programmed in Perl before but I do image the functions/methods are similar to other languages. Here's the code:
  1. function [dir, wspd] = conv_wind(uwind, vwind)
  2. usize = length(uwind);
  3. vsize = length(vwind);
  4. if(usize ~= vsize)
  5. dir = 0;
  6. wspd = 0;
  7. return
  8. end
  9.  
  10. for m = 1:usize
  11. uu = uwind(m);
  12. vv = vwind(m);
  13.  
  14. wspd(m) = sqrt(vv^2 + uu^2);
  15.  
  16. if(uu ~= 0)
  17. dir(m) = atan( abs(vv)/ abs(uu)) * (180 / 3.14159);
  18. end
  19.  
  20. if( uu == 0 && vv > 0)
  21. dir(m) = 90;
  22. elseif(uu == 0 && vv < 0)
  23. dir(m) = 270;
  24. end
  25.  
  26. if( uu < 0 && vv > 0)
  27. dir(m) = 180 - dir(m);
  28. end
  29.  
  30. if( uu < 0 && vv < 0)
  31. dir(m) = 180 + dir(m);
  32. end
  33.  
  34. if( uu > 0 && vv < 0)
  35. dir(m) = 360 - dir(m);
  36. end
  37.  
  38. dir(m) = 450.0 - dir(m);
  39.  
  40. dir(m) = dir(m) + 180;
  41.  
  42. if(dir(m) > 360)
  43. dir(m) = dir(m) - 360;
  44. end
  45. end
  46. dir = dir';
  47. wspd = wspd';
  48. end

So I've noticed just like Python, there isn't data type binding during compile time. Now since the length function is being used on the uwind and vwind I'm assuming that they are actually a 'string' type variable? And when uwind(m) (line 11) is used, it means we are indexing the string? But then the indexed letter is squared and I'm all lost. I think I'm not understanding what happens at line 11

The above code is meant to convert the u and v components of wind speed to wind speed and direction. I don't think I really need the direction but on Wikipedia the volcity of wind is given by the square root of the sum of square of the u, v and w components.... but the above code doesn't even consider the w component which apparently is the wind velocity. The algo above does a bit more than that though...

So can someone please help me understand the code above... I think if I understand what line 11 means then I'll figure the rest out.

Thanks in advanced
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2006
Posts: 596
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 31
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Posting Pro

Re: Perl to Python

  #2  
Jul 20th, 2008
the code you posted is not perl, I am not sure after reading your post if you know that or not.
Reply With Quote  
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 100
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 8
PoovenM PoovenM is offline Offline
Junior Poster

Re: Perl to Python

  #3  
Jul 20th, 2008
Oh my I did not realize that. I was told that it was Perl and that I should convert it to Python. Can someone please tell me what programming language it is? It had the file extension .m
Reply With Quote  
Join Date: Mar 2006
Posts: 596
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 31
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Posting Pro

Re: Perl to Python

  #4  
Jul 20th, 2008
I'm pretty sure its matlab, of which I know nothing. So I suggest you find a matlab forum or mailing list.
Reply With Quote  
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 100
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 8
PoovenM PoovenM is offline Offline
Junior Poster

Re: Perl to Python

  #5  
Jul 21st, 2008
hehe considering the file extension I think you're you're right! I'd like the original algorithm instead of translating from one language to anther. Anyway, thank you for your assistance!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Legacy and Other Languages Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Legacy and Other Languages Forum

All times are GMT -4. The time now is 4:16 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC