solstice-pp

Post-processing utilities for the solstice app
git clone git://git.meso-star.com/solstice-pp.git
Log | Files | Refs | README | LICENSE

solpaths.c (1996B)


      1 /* Copyright (C) 2017, 2018, 2025 |Méso|Star>
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #include "solpp.h"
     17 
     18 int
     19 main(int argc, char** argv)
     20 {
     21   char s[128];
     22   buf_char_T buf = BUF_NULL;
     23   FILE* input = stdin;
     24   FILE* output = NULL;
     25   char* line = NULL;
     26   double azim, elev, lat, lon;
     27   char time[64];
     28 
     29   if(argc > 1 && !(input = fopen(argv[1], "r"))) {
     30     fprintf(stderr, "Could not open the file `%s'.\n", argv[1]);
     31     return 1;
     32   }
     33   while((line = read_line(&buf, input, NULL))) {
     34     if(!strncmp(line, "#--- Sun direction:", 19)) {
     35       CHK(sscanf(line+19, "%lf %lf (%*f %*f %*f)", &azim, &elev) == 2);
     36       CHK(snprintf(s, sizeof(s), "%g-%g-paths.vtk", azim, elev)
     37           < (long)sizeof(s));
     38       if(output) fclose(output);
     39       printf("Writing `%s'\n", s);
     40       CHK(output = fopen(s, "w"));
     41     } else if(!strncmp(line, "#--- Sun location and time:", 27)) {
     42       memset(time, 0, sizeof(time));
     43       CHK(sscanf(line+27, "%lf %lf %s (%*f %*f %*f)", &lat, &lon, time) == 3);
     44       CHK(snprintf(s, sizeof(s), "%g-%g-%s-paths.vtk", lat, lon, time)
     45           < (long)sizeof(s));
     46       if(output) fclose(output);
     47       printf("Writing `%s'\n", s);
     48       CHK(output = fopen(s, "w"));
     49     } else {
     50       CHK(output != NULL);
     51       fprintf(output, "%s\n", line);
     52     }
     53   }
     54   BUF_RELEASE(buf);
     55   if(output) fclose(output);
     56   if(input && input!=stdin) fclose(input);
     57   return 0;
     58 }