ygrenier / SwissEphNet

Swiss Ephemeris for .Net. A Swiss Ephemeris portage for .Net.
Other
77 stars 35 forks source link

BUG: Cannot parse "eop_finals.txt" file #29

Closed barissaydag closed 7 years ago

barissaydag commented 7 years ago

Hi,

I think atoi and int.Parse functions are implemented differently in C and C#. C# doesn't like to parse empty strings, and doesn't stop when it sees space. Therefore, I am getting invalid number exception in load_dpsi_deps. I worked around with below (crude) changes:

double.Parse(s.Substring(99), ... to double.Parse(s.Substring(99, 8).Trim() == "" ? "0" : s.Substring(99, 8).Trim(), ....

Here are the full changes:

while ((s = fp.ReadLine()) != null) {
                mjd = (int) double.Parse(s.Substring(7, 5));  // here
                if (mjd + TJDOFS <= swed.eop_tjd_end)
                    continue;
                if (n >= Sweph.SWE_DATA_DPSI_DEPS)
                    return;
                /* are data in one-day steps? */
                if (mjdsv > 0 && mjd - mjdsv != 1) {
                    /* no error, as we do have data; however, if this file is usefull,
                     * then swed.eop_dpsi_loaded will be set to 2 */
                    swed.eop_dpsi_loaded = -3;
                    fp.Dispose();
                    return;
                }
                /* dpsi, deps Bulletin B */
                dpsi = double.Parse(s.Substring(168, 8).Trim() == "" ? "0" : s.Substring(168, 8).Trim(), CultureInfo.InvariantCulture);
                deps = double.Parse(s.Substring(178, 8).Trim() == "" ? "0" : s.Substring(178, 8).Trim(), CultureInfo.InvariantCulture);
                if (dpsi == 0) {
                    /* try dpsi, deps Bulletin A */
                    dpsi = double.Parse(s.Substring(99, 8).Trim() == "" ? "0" : s.Substring(99, 8).Trim(), CultureInfo.InvariantCulture);
                    deps = double.Parse(**s.Substring(118, 8).Trim() == "" ? "0" : s.Substring(118, 8).Trim()**, CultureInfo.InvariantCulture);
                }
ygrenier commented 7 years ago

Hi,

Thanks for the issue report.

Yes atoi/atof don't have same behavior than int.Parse()/double.Parse(). Normally I was implemented these functions perhaps I missed use them.

I need two things for the test:

Regards,

barissaydag commented 7 years ago

I am soooo sorry, I completely forgot responding you. Yet I was checking Nuget for updates and bug fixes! I uploaded files...

Thanks again for your help.

eop_1962_today.txt eop_finals.txt

ygrenier commented 7 years ago

No problem, this happen to me :)

I'll try to fix some bugs (#29, #30) this WE.

ygrenier commented 7 years ago

This issue if fixed with the 2.6.0.23 version.

barissaydag commented 7 years ago

I confirm that it is fixed. Thanks!