B4A Library Magnetics Library

Magnetics calculates the magnetic variation, inclination and grid variation (the last for lat > 55 deg or < -55 deg).

The WMMC.COF file is good for 5 years, the attached one is up to 2022. Hence you should put it in File.DirRootExternal & "/Magnetics", so the user will be able to replace it.

Edit: Version 1.1 enables the developer to select where to store the WMMC.COF file. The initialization method includes the directory as a parameter.
File.DirAssets cannot be supplied there. You must copy the file from there to another directory, for example:
B4X:
File.Copy(File.DirAssets,"WMMC.COF",File.DirInternal,"WMMC.COF")
mg.initialize(File.DirInternal)

Edit: The file WMMC.COF has been updated, I attach the new file here (open the zip). It is valid until 2022 ! The library files do not change.
EDIT: A new WMMC.COF file is attached, valid until end of 2024. unzip and copy the WMMC.COF file.

Edit: Updated to ver 1.2
Edit: Uploaded ver 1.3, bug correction.
 

Attachments

  • Magnetics_demo.zip
    7.4 KB · Views: 593
  • Magnetics1.3.zip
    6.4 KB · Views: 517
  • wmmc.zip
    1.1 KB · Views: 351
Last edited:

alfcen

Well-Known Member
Licensed User
Longtime User
Hi derez
Excellent work. The magnetic declination for my location is pin-point :sign0060:
 

PhilN

Member
Licensed User
Longtime User
Hi Derez. Yes indeed excellent work! Where did you get the WMMC.COF file? Just in case I need an updated version, I can include the link in my app. That would be really fantastic.

No worry! I found it. Thanks My over sight :)
 
Last edited:

hmotiwala

Member
Licensed User
Longtime User
Hi Derez,

Like to use the magnetics library, can the location of WMMC.COF file be made configurable.
The reason is I don't expect users to change the file on their own so would like it to be in assets and update it with new version release when necessary.
 
Last edited:

derez

Expert
Licensed User
Longtime User
Sorry for my late answer.
mag.initialize(Assets as Boolean) -
If assets is true then wmmc.cof file should be placed in dirassets, otherwise - in dirRootExternanal & "/magnetics".
 

hmotiwala

Member
Licensed User
Longtime User
With reference to your post #6 above, I have ver 1.02 of Magnetics library and the Initialize() function does not accept any arguments.
Is there a later version of library available with an updated function Initialize(Assets as Boolean)?
 

derez

Expert
Licensed User
Longtime User
The version at the first post is 1.0 which doesn't have this initialization as exlained in post #6.
I shall publish 1.1 soon.
 

derez

Expert
Licensed User
Longtime User
Now I know why version 1.1 was not published: I can't get it to work.
I'm stuck with this part in the library:
B4X:
if(Assets)
    st = File.Combine(File.getDirAssets(), "WMMC.COF") ;
else
    st = File.Combine(File.getDirRootExternal() + "/Magnetics", "WMMC.COF") ;
For some reason which I don't get, when assets is set to true in b4a, the file is not found (and yes, I have not forget to put it in files).
I noticed that in files the file name becomes lowercase letters but even playing with this in the library didn't help.
Version 1.0 use the second option and it works.
If someone knows the answer I shall be able to complete it.
Is there a way to add the file to the library ?
 
Last edited:

hmotiwala

Member
Licensed User
Longtime User
According to its description, the method File.combine() does not support files in the Assets folder.
 

derez

Expert
Licensed User
Longtime User
Until and if solution is found you can use ver 1 and in the app copy the file to place where the lib looks for.
 

hmotiwala

Member
Licensed User
Longtime User
May be it might be better to pass a path as an argument to Initialize() function instead of a boolean. That way if the path is not null then use it otherwise use default path. I think this would give more flexibility in where to place the WMMC.COF file.
 

derez

Expert
Licensed User
Longtime User
it might be better to pass a path as an argument to Initialize() function
Did that, see first post ver 1.1
DirAssets is still not solved - only by copying the file to another directory.
 

derez

Expert
Licensed User
Longtime User
The time has come for a new WMMC file ! It is attached at the first post (unzip it).
Just put the new file in the files directory, the library files do not change.
The new file is valid until 2022 !
 

Andris

Active Member
Licensed User
Longtime User
Thanks Derez - this library has been great for me. What would be involved to make a B4i version?
 

derez

Expert
Licensed User
Longtime User
Thanks Derez - this library has been great for me. What would be involved to make a B4i version?
I am not using B4i so I don't know what it requires.
I can provide the source if someone is willing to do it.
 
Top