Magdec BGL File: Difference between revisions

From FSDeveloper Wiki
Jump to navigationJump to search
(Created Magnetic Declination BGL framework.)
 
m (Replaced Applicable-FSVersion for MSFS with MSFS2020, added MSFS2024)
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{:Ambox-Content-WIP}}
{{Infobox-Applicable-FSVersion
{{Infobox-Applicable-FSVersion
| MSFS2024 = unknown
| MSFS2020 = true
| P3D5 = true
| P3D4 = true
| P3D3 = true
| P3D2 = true
| P3D2 = true
| P3D = true
| P3D = true
| FSXI = true
| FSXI = unknown
| FSXA = true
| FSXA = true
| FSX = true
| FSX = true
| FS2004 = true
| FS2004 = true
| FS2002 = true
| FS2002 = unknown
| FS2000 = true
| FS2000 = unknown
| FS98 = true
| FS98 = unknown
}}
}}


Placeholder for Hervé Sors
== Introduction ==
The '''Magdec.bgl''' file provides the basis for magnetic variation (declination) calculation by the simulator at current aircraft position.
<br> By convention, East magnetic variation values are POSITIVE, while west values are NEGATIVE.
<br> See this [https://en.wikipedia.org/wiki/Magnetic_declination Wikipedia article] for some basics regarding magnetic declination meaning as well as this [https://www.aero.sors.fr/documentation/UnderstandingMV.pdf Understanding magnetic variation use in the simulators] document for a more in-depth review of its use in the simulator.
<br>


Article introduction.
=== File length ===
File length is 130,468 bytes in FS2004 (offsets 0x0 to 0x1FDA3) and 130,456 bytes in FSX, P3D (all versions) and MSFS (offsets 0x0 to 0x1FD97)


== Headline text ==
=== File location ===
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ultrices neque sit amet rutrum fermentum. Nunc placerat nibh ut lacus lobortis placerat. Etiam rutrum sapien nec mi gravida, at mattis tortor ornare. Sed malesuada condimentum accumsan. Sed eu nunc tempor, mattis nunc vel, imperdiet dolor. Nunc tempus urna metus, nec.  
In FS2004, FSX and all P3D versions, the Magdec.bgl file is located in the (SIM DRIVE-FOLDER)\Scenery\Base\Scenery\ subfolder.
<br>In MSFS it is located in:
<br>C:\Users\LOGINNAME\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\Packages\Official\OneStore\fs-base\scenery\Base\scenery\  subfolder (Box/Microsoft Store)
<br>(STEAM DRIVE):\Steam\steamapps\common\MicrosoftFlightSimulator\Official\OneStore\fs-base\scenery\Base\scenery\ subfolder (Steam edition)


== Headline text ==
== File structure ==


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tellus eros, maximus sed elementum quis, tempus at tellus. Nunc lacinia facilisis purus. Sed id ex a eros faucibus scelerisque eu at libero. Donec aliquet nisl nec ipsum sollicitudin porttitor. Nam sed nulla eget nulla volutpat lobortis. Cras vitae finibus leo.  
Magdec.bgl file includes a header, a latitude/longitude table and optionally (FS2004 only) an ending string.  


=== Sub-Headline text ===
=== File header ===
 
File header is 136 bytes long (offsets 0x0 to 0x87) and has the following structure
{| class="wikitable"
|-
! Offset
! Length
! Description
! Content
|-
| 0x00
| 1 - BYTE
| World set number
| 0X01
|-
| 0x01
| 127 - ?
| Unknown
| All 0, except 0x80 at offset 0x6E
|-
| 0x80
| 2 - WORD
| Number of longitude values
| 0x168 (360)
|-
| 0x82
| 2 - WORD
| Number of latitude values
| 0xB5 (181)
|-
| 0x84
| 1 - BYTE
| Unknown - Reference date day (?)
| 0x01
|-
| 0x85
| 1 - BYTE
| Unknown - Reference date month (?)
| 0x01 (FS2004) - 0x11 (FSX/P3D/MSFS)
|-
| 0x86
| 2 - WORD
| Unknown - Reference date year (?)
| 0x1993 (FS2004) - 0x2006 (FSX/P3D/MSFS)
|}
 
=== Latitude/Longitude table ===
 
Latitude/Longitude table is 130,320 bytes length and starts at offset 0x88.
<br>
Magnetic variations for all entire degree latitude/longitude values are stored as a WORD list starting at E000-S90.
<br>
For each longitude value from E000 to W179, the list tabulates magnetic variations by increasing latitude from S90 to N90.
<br>
This organization can be sumarized as follows:
 
E000 (S90->S89->S88...->S01->N00->N01->...->N90), then
<br>
E001 (S90->S89->S88...->S01->N00->N01->...->N90), followed by E002, E003 lines
<br>
...
<br>
E180 (S90->S89->S88...->S01->N00->N01->...->N90), then
<br>
W179 (S90->S89->S88...->S01->N00->N01->...->N90), followed by W178, W177 lines
<br>
...
<br>
W001 (S90->S89->S88...->S01->N00->N01->...->N90) that is the last line
<br>
Therefore, for each of the 360 longitude values, there is 181 latitude values for a total of 65,160 consecutive WORD values.
First value of this table is at offset 0x88 (E000/S90) and last is at offset 0x1FD96 (W001/N90).
<br>
File offset for a given Lat/Long can be obtained using the following formula
<br>
For positive (East) longitudes (from 0 to 180):
Offset = (Long*362)+(Lat*2)+316
For negative (West) longitudes (from -1 to -179):
Offset =((Long+360)*362)+(Lat*2)+316
 
Note that North latitudes should be entered as positive values (0 to 90) and South latitudes as negative values (-1 to -90)
 
=== Magnetic variation encoding ===
 
Each magnetic variation value is coded on 2 bytes (WORD) using a '''16-bit pseudo-degrees representation''' (360°=0x10000).
<br>
East values are positive while West values are negative (complement at 0x10000).
<br>
<br>
As an example a E03.4° value will be coded as:
MV (E03.4°) = 65536*3.4/360 = 619 (0x26B)
A W01.1° value will be coded as:
MV (W01.1°) = 65536 - (65536*1.1/360) = 65336 (0xFF38)
 
=== File end ===
 
File end differs in FS2004 and FSX-P3D-MSFS but this doesn't seem to change file usage by the simulator.
<br>
In FS2004, file is terminated by the string "End of Data " (offset 0x1FD98 - length: 12 bytes), while there is no ending string in FSX-P3D-MSFS.
 
== Internal calculation of current magnetic variation ==
 
Internally, the simulator makes use of this table to calculate current magnetic variation (probably as a FLOAT32 or FLOAT64) at aircraft position using a [https://en.wikipedia.org/wiki/Bilinear_interpolation Bilinear interpolation prodedure] from the 4 nearest table values.
<br>
As an example calculation of current magnetic variation by the simulator for an aircraft located at KLAX (N33°57' - W118°24') will use the following table values for its calculation:
<br>
N33°-W118°,N33°-W119°, N34°-W118° and N34°-W119°
 
== Reliability of simulator data ==
Magnetic declination changes with time, more or less depending on world area.
<br>
From [http://www.ngdc.noaa.gov/geomag-web/ available historical data], it appears coded values in stock simulator files date from 1988 for FS2004 and 2009-2010 for FSX, P3Dv1-4 files and MSFS (stock MSFS magdec.bgl is identical to FSX one). P3DV5 includes a more up-to-date file (2018-2019)
<br>
Current values (2021) differ by an average of 3-4° and 1-2° for FS2004 and FSX/P3D/MSFS respectively, although larger variations can be observed in some parts of the world
<br>   


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pretium dolor eu erat lobortis iaculis. Vivamus at venenatis urna. Donec tristique, dolor vitae vestibulum pretium, eros risus scelerisque sapien, a placerat nisi arcu ac felis. Morbi eleifend risus erat, vel facilisis odio pretium vel. Suspendisse consequat urna dapibus, vulputate diam.


[[category:General]][[Category:File_Formats]]
[[category:General]][[Category:File_Formats]]

Latest revision as of 12:27, 25 May 2024

Introduction

The Magdec.bgl file provides the basis for magnetic variation (declination) calculation by the simulator at current aircraft position.
By convention, East magnetic variation values are POSITIVE, while west values are NEGATIVE.
See this Wikipedia article for some basics regarding magnetic declination meaning as well as this Understanding magnetic variation use in the simulators document for a more in-depth review of its use in the simulator.

File length

File length is 130,468 bytes in FS2004 (offsets 0x0 to 0x1FDA3) and 130,456 bytes in FSX, P3D (all versions) and MSFS (offsets 0x0 to 0x1FD97)

File location

In FS2004, FSX and all P3D versions, the Magdec.bgl file is located in the (SIM DRIVE-FOLDER)\Scenery\Base\Scenery\ subfolder.
In MSFS it is located in:
C:\Users\LOGINNAME\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\Packages\Official\OneStore\fs-base\scenery\Base\scenery\ subfolder (Box/Microsoft Store)
(STEAM DRIVE):\Steam\steamapps\common\MicrosoftFlightSimulator\Official\OneStore\fs-base\scenery\Base\scenery\ subfolder (Steam edition)

File structure

Magdec.bgl file includes a header, a latitude/longitude table and optionally (FS2004 only) an ending string.

File header

File header is 136 bytes long (offsets 0x0 to 0x87) and has the following structure

Offset Length Description Content
0x00 1 - BYTE World set number 0X01
0x01 127 - ? Unknown All 0, except 0x80 at offset 0x6E
0x80 2 - WORD Number of longitude values 0x168 (360)
0x82 2 - WORD Number of latitude values 0xB5 (181)
0x84 1 - BYTE Unknown - Reference date day (?) 0x01
0x85 1 - BYTE Unknown - Reference date month (?) 0x01 (FS2004) - 0x11 (FSX/P3D/MSFS)
0x86 2 - WORD Unknown - Reference date year (?) 0x1993 (FS2004) - 0x2006 (FSX/P3D/MSFS)

Latitude/Longitude table

Latitude/Longitude table is 130,320 bytes length and starts at offset 0x88.
Magnetic variations for all entire degree latitude/longitude values are stored as a WORD list starting at E000-S90.
For each longitude value from E000 to W179, the list tabulates magnetic variations by increasing latitude from S90 to N90.
This organization can be sumarized as follows:

E000 (S90->S89->S88...->S01->N00->N01->...->N90), then
E001 (S90->S89->S88...->S01->N00->N01->...->N90), followed by E002, E003 lines
...
E180 (S90->S89->S88...->S01->N00->N01->...->N90), then
W179 (S90->S89->S88...->S01->N00->N01->...->N90), followed by W178, W177 lines
...
W001 (S90->S89->S88...->S01->N00->N01->...->N90) that is the last line
Therefore, for each of the 360 longitude values, there is 181 latitude values for a total of 65,160 consecutive WORD values. First value of this table is at offset 0x88 (E000/S90) and last is at offset 0x1FD96 (W001/N90).
File offset for a given Lat/Long can be obtained using the following formula
For positive (East) longitudes (from 0 to 180):

Offset = (Long*362)+(Lat*2)+316 

For negative (West) longitudes (from -1 to -179):

Offset =((Long+360)*362)+(Lat*2)+316

Note that North latitudes should be entered as positive values (0 to 90) and South latitudes as negative values (-1 to -90)

Magnetic variation encoding

Each magnetic variation value is coded on 2 bytes (WORD) using a 16-bit pseudo-degrees representation (360°=0x10000).
East values are positive while West values are negative (complement at 0x10000).

As an example a E03.4° value will be coded as:

MV (E03.4°) = 65536*3.4/360 = 619 (0x26B)

A W01.1° value will be coded as:

MV (W01.1°) = 65536 - (65536*1.1/360) = 65336 (0xFF38)

File end

File end differs in FS2004 and FSX-P3D-MSFS but this doesn't seem to change file usage by the simulator.
In FS2004, file is terminated by the string "End of Data " (offset 0x1FD98 - length: 12 bytes), while there is no ending string in FSX-P3D-MSFS.

Internal calculation of current magnetic variation

Internally, the simulator makes use of this table to calculate current magnetic variation (probably as a FLOAT32 or FLOAT64) at aircraft position using a Bilinear interpolation prodedure from the 4 nearest table values.
As an example calculation of current magnetic variation by the simulator for an aircraft located at KLAX (N33°57' - W118°24') will use the following table values for its calculation:
N33°-W118°,N33°-W119°, N34°-W118° and N34°-W119°

Reliability of simulator data

Magnetic declination changes with time, more or less depending on world area.
From available historical data, it appears coded values in stock simulator files date from 1988 for FS2004 and 2009-2010 for FSX, P3Dv1-4 files and MSFS (stock MSFS magdec.bgl is identical to FSX one). P3DV5 includes a more up-to-date file (2018-2019)
Current values (2021) differ by an average of 3-4° and 1-2° for FS2004 and FSX/P3D/MSFS respectively, although larger variations can be observed in some parts of the world