The check to see if an ephemeris file is already open will always be true if an ephemeris file was open at any point in the program, even if ephem_close was called. ephem_close does not reset the EPHFILE pointer to NULL. This bug will be addressed during the next overhaul of the ephemeris-access software.
Memory errors occur when a call to ephem_close occurs between two calls to ephem_open. The second time ephem_open is called, if (EPHFILE) is TRUE because EPHFILE is still the address that was assigned the first time.
Two calls to ephem_open without an intervening call to ephem_close will work because the EPHFILE still is open when if (EPHFILE) checks during the second ephem_open call.
Users who open multiple ephemeris files within a particular program may wish to edit the ephem_close function as follows:
if (EPHFILE)
{
error = (short int) fclose (EPHFILE);
EPHFILE = NULL; // new line, reset pointer
free (BUFFER);
}
return error;