1
0
Fork 0

Better error handling for IO operations, from cbassa

giza-pure
Jeff Moe 2022-08-20 12:02:42 -06:00
parent 17d364ddd9
commit ba1c537dd8
1 changed files with 53 additions and 9 deletions

View File

@ -301,6 +301,11 @@ init_skymap (void)
// Read LR coefficients
sprintf (filename, "%s/data/moonLR.dat", m.datadir);
file = fopen (filename, "r");
if (file == NULL)
{
printf ("Failed to open %s\n", filename);
exit (1);
}
for (i = 0; i < 60; i++)
fscanf (file, "%d %d %d %d %lf %lf", &clr[i].nd, &clr[i].nm, &clr[i].nm1,
&clr[i].nf, &clr[i].sa, &clr[i].ca);
@ -309,6 +314,11 @@ init_skymap (void)
// Read B coefficients
sprintf (filename, "%s/data/moonB.dat", m.datadir);
file = fopen (filename, "r");
if (file == NULL)
{
printf ("Failed to open %s\n", filename);
exit (1);
}
for (i = 0; i < 60; i++)
fscanf (file, "%d %d %d %d %lf", &cb[i].nd, &cb[i].nm, &cb[i].nm1,
&cb[i].nf, &cb[i].sa);
@ -333,8 +343,8 @@ get_site (int site_id)
file = fopen (filename, "r");
if (file == NULL)
{
printf ("File with site information not found!\n");
return;
printf ("Failed to open %s\n", filename);
exit (1);
}
while (fgets (line, LIM, file) != NULL)
{
@ -376,6 +386,11 @@ read_iod (char *filename, int iobs)
struct observation obs;
file = fopen (filename, "r");
if (file == NULL)
{
printf ("Failed to open %s\n", filename);
exit (1);
}
// Read data
while (fgets (line, LIM, file) != NULL)
{
@ -472,6 +487,17 @@ plot_xyz (double mjd0, char *filename)
char line[LIM];
file = fopen (filename, "r");
if (file == NULL)
{
printf ("Failed to open %s\n", filename);
exit (1);
}
if (file == NULL)
{
printf ("%s not found!\n", filename);
return;
}
while (fgetline (file, line, LIM) > 0)
{
sscanf (line, "%lf %lf %lf %lf", &mjd, &satpos.x, &satpos.y, &satpos.z);
@ -1722,8 +1748,8 @@ skymap_plotconstellations (char *filename)
file = fopen (filename, "r");
if (file == NULL)
{
printf ("Constellation file not found\n");
exit (1);
printf ("%s not found!\n", filename);
return;
}
for (i = 0; fgetline (file, line, LIM) > 0; i++)
@ -2021,7 +2047,10 @@ skymap_plotsatellite (char *filename, int satno, double mjd0, double dt)
// Open TLE file
fp = fopen (filename, "rb");
if (fp == NULL)
fatal_error ("File open failed for reading %s\n", filename);
{
printf ("Failed to open TLE catalog %s\n", filename);
exit (1);
}
// Read TLEs
while (read_twoline (fp, satno, &orb) == 0)
@ -2413,7 +2442,10 @@ planar_search (char *filename, int satno, float rmin, float rmax, int nr,
// Open TLE file
fp = fopen (filename, "rb");
if (fp == NULL)
fatal_error ("File open failed for reading %s\n", filename);
{
printf ("Failed to open TLE catalog %s\n", filename);
exit (1);
}
// Read TLEs
while (read_twoline (fp, satno, &orb) == 0)
@ -2613,7 +2645,10 @@ print_tle (char *filename, int satno)
// Open TLE file
fp = fopen (filename, "rb");
if (fp == NULL)
fatal_error ("File open failed for reading %s\n", filename);
{
printf ("Failed to open TLE catalog %s\n", filename);
exit (1);
}
// Read TLEs
while (fgetline (fp, line, LIM) > 0)
@ -2652,7 +2687,10 @@ identify_satellite (char *filename, int satno, double mjd, float rx, float ry)
// Open TLE file
fp = fopen (filename, "rb");
if (fp == NULL)
fatal_error ("File open failed for reading %s\n", filename);
{
printf ("Failed to open TLE catalog %s\n", filename);
exit (1);
}
// Read TLEs
while (read_twoline (fp, satno, &orb) == 0)
@ -2788,7 +2826,7 @@ read_camera (int no)
file = fopen (filename, "r");
if (file == NULL)
{
printf ("File with camera information not found!\n");
printf ("Failed to open %s\n", filename);
return -1;
}
while (fgets (line, LIM, file) != NULL)
@ -3834,6 +3872,12 @@ plot_iod (char *filename)
cpgsci (2);
file = fopen (filename, "r");
if (file == NULL)
{
printf ("Failed to open %s\n", filename);
return;
}
// Read data
while (fgets (line, LIM, file) != NULL)
{