star-phor-input

File format for describing photoreactor configurations
git clone https://www.edstar.cnrs.fr/git/star-phor-input.git
Log | Files | Refs | README | LICENSE

sphin_sensor.c (2373B)


      1 /* Copyright (C) 2024-2026 Centre National de la Recherche Scientifique
      2  * Copyright (C) 2024-2026 Clermont Auvergne INP
      3  * Copyright (C) 2024-2026 INSA Lyon
      4  * Copyright (C) 2024-2026 Institut Mines Télécom Albi-Carmaux
      5  * Copyright (C) 2024-2026 Institut National Polytechnique de Toulouse
      6  * Copyright (C) 2024-2026 |Méso|Star> (contact@meso-star.com)
      7  * Copyright (C) 2024-2026 PhotonLyX (info@photonlyx.com)
      8  * Copyright (C) 2024-2026 Université de Lorraine
      9  * Copyright (C) 2024-2026 Université Paul Sabatier
     10  * Copyright (C) 2024-2026 Université Toulouse - Jean Jaurès
     11  *
     12  * This program is free software: you can redistribute it and/or modify
     13  * it under the terms of the GNU General Public License as published by
     14  * the Free Software Foundation, either version 3 of the License, or
     15  * (at your option) any later version.
     16  *
     17  * This program is distributed in the hope that it will be useful,
     18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     20  * GNU General Public License for more details.
     21  *
     22  * You should have received a copy of the GNU General Public License
     23  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     24 #define _POSIX_C_SOURCE 200112L /* for strtok_r support */
     25 
     26 #include "sphin_sensor.h"
     27 
     28 #include <rsys/cstr.h>
     29 #include <rsys/rsys.h>
     30 #include <rsys/str.h>
     31 #include <rsys/text_reader.h>
     32 
     33 struct txtrdr;
     34 
     35 /*******************************************************************************
     36  * Local functions
     37  ******************************************************************************/
     38 res_T
     39 parse_response_function
     40   (double* out_response_function,
     41    struct txtrdr* txtrdr,
     42    char* value)
     43 {
     44   char* token = NULL;
     45   char* token_ptr = NULL;
     46   res_T res = RES_OK;
     47   double response_function = 0;
     48 
     49   ASSERT(NULL != txtrdr);
     50 
     51   if (NULL == value) { res = RES_BAD_ARG; goto error; }
     52 
     53   token = strtok_r(value, " \t", &token_ptr);
     54 
     55   res = cstr_to_double(token, &response_function);
     56   if (RES_OK != res) { goto error; }
     57   if (response_function < 0) { res = RES_BAD_ARG; goto error; }
     58 
     59   token = strtok_r(NULL, " \t", &token_ptr);
     60   if (NULL != token) { res = RES_BAD_ARG; goto error; }
     61 
     62   res = txtrdr_read_line(txtrdr);
     63   if (RES_OK != res) { goto error; }
     64 
     65 exit:
     66   *out_response_function = response_function;
     67   return res;
     68 error:
     69   goto exit;
     70 }