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 (1576B)


      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 = 0;
     27   double elev = 0;
     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))) {
     34     if(strncmp(line, "#--- Sun direction:", 19)) {
     35       CHK(output != NULL);
     36       fprintf(output, "%s\n", line);
     37     } else {
     38       CHK(sscanf(line+19, "%lf %lf (%*f %*f %*f)", &azim, &elev) == 2);
     39       CHK(snprintf(s, sizeof(s), "%g-%g-paths.vtk", azim, elev) < sizeof(s));
     40       if(output) fclose(output);
     41       printf("Writing `%s'\n", s);
     42       CHK(output = fopen(s, "w"));
     43     }
     44   }
     45   BUF_RELEASE(buf);
     46   if(output) fclose(output);
     47   if(input && input!=stdin) fclose(input);
     48   return 0;
     49 }