Jump to content
Sign in to follow this  
ark

XML IF Statement Help Needed

Recommended Posts

I am new to XML and am trying to modify some existng XML code to fix a bug that sometimes results in the display of invalid wind headings. The purpose of the first 3 lines below is to calculate magnetic wind direction from true wind direction. If subtracting the magnetic variation from the true wind heading produces a negative result, 360 is added in line 2, and conversely, if the result of subtracting the variation is greater than 360, 360 is subtracted in line 3. Seems simple enough in concept. However, I would greatly appreciate it if someone could tell me why the two if statements in lines 1 and 2 that correct for invalid wind headings don't work before I pull out the last two hairs I have left on my head!

The remaining code below then either displays the wind direction in degrees or in general headings like N, NE, W, etc depending on the value of DirMode. That part works, probably because I didn't write it (except for using the AdjDir Lvar from the first 3 lines).

Thanks much,

Al

 

<GaugeString>

%((A:AMBIENT WIND DIRECTION,degrees) (A:MAGVAR,degrees) - (>L:AdjDir,degrees))

%((L:AdjDir,degrees) 0 < if{(L:AdjDir,degrees) 360 + (>L:AdjDir,degrees)})

%((L:AdjDir,degrees) 360 > if{(L:AdjDir,degrees) 360 - (>L:AdjDir,degrees)})

 

%((L:DirMode,bool) 1 == )

%{if}

%((L:AdjDir,degrees) near)%!03d!

%{else}

%((L:AdjDir,degrees) 22.5 + 45 / int) %{case} %{:0} N%{:1}NE%{:2} E%{:3}SE%{:4} S%{:5}SW%{:6} W%{:7}NW%{:8} N%{end}

%{end}

</GaugeString>

Share this post


Link to post
Share on other sites

I'm not an expert, but try replacing lines 1-3 with:

 

%((A:AMBIENT WIND DIRECTION,degrees) (A:MAGVAR,degrees) - dnor (>L:AdjDir,degrees))

 

dnor takes care of normalizing the degrees value to between 0 and 360


Barry Friedman

Share this post


Link to post
Share on other sites

Barry -- that worked, thank you very very much!! I have been fighting with this for days.

 

Now, just for my XML education, I hope someone can explain why my original 3 lines of code did not work.

 

Best,

Al

Share this post


Link to post
Share on other sites

Can anyone help me understand why the IF statements in lines 2 and 3 in the <GaugeString> code segment in post#1 above don't work?  I assume there is a syntax error but I can't figure out what it is.

Thx,

Al

Share this post


Link to post
Share on other sites

There is always a space after the opening {  and a space before the closing  }

 

%((L:AdjDir,degrees) 360 > if{(L:AdjDir,degrees) 360 - (>L:AdjDir,degrees)})

                                                   ^                                                                     ^

Share this post


Link to post
Share on other sites

There is always a space after the opening {  and a space before the closing  }

 

%((L:AdjDir,degrees) 360 > if{(L:AdjDir,degrees) 360 - (>L:AdjDir,degrees)})

Shoot, I didn't know that -- thanks very much!

Al

Share this post


Link to post
Share on other sites

There is always a space after the opening {  and a space before the closing  }.

Just to close the loop, I've confirmed the code works fine if the missing spaces are added to the if{ } as tedcook suggested.

Thx again for the help.

Al

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...