•
•
•
•
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
![]() |
•
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 100
Reputation:
Rep Power: 3
Solved Threads: 8
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:
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
perl Syntax (Toggle Plain Text)
function [dir, wspd] = conv_wind(uwind, vwind) usize = length(uwind); vsize = length(vwind); if(usize ~= vsize) dir = 0; wspd = 0; return end for m = 1:usize uu = uwind(m); vv = vwind(m); wspd(m) = sqrt(vv^2 + uu^2); if(uu ~= 0) dir(m) = atan( abs(vv)/ abs(uu)) * (180 / 3.14159); end if( uu == 0 && vv > 0) dir(m) = 90; elseif(uu == 0 && vv < 0) dir(m) = 270; end if( uu < 0 && vv > 0) dir(m) = 180 - dir(m); end if( uu < 0 && vv < 0) dir(m) = 180 + dir(m); end if( uu > 0 && vv < 0) dir(m) = 360 - dir(m); end dir(m) = 450.0 - dir(m); dir(m) = dir(m) + 180; if(dir(m) > 360) dir(m) = dir(m) - 360; end end dir = dir'; wspd = wspd'; 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
•
•
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 100
Reputation:
Rep Power: 3
Solved Threads: 8
![]() |
•
•
•
•
•
•
•
•
DaniWeb Legacy and Other Languages Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- perl rather than php because no good php books. comment please. (PHP)
- Is it too late to learn Python (Python)
- simple python web server (Python)
- where to start with perl? (Perl)
- design customized mysql frontend with perl or python (MySQL)
- Features in PHP 5 (PHP)
- Any Ideas for Projects???? (*nix Software)
Other Threads in the Legacy and Other Languages Forum
- Previous Thread: help learning RPG IV *sigh*
- Next Thread: ABAP programming (SAP R/3)HELP


Linear Mode