star-meteo

Time varying meteorological data
git clone git://git.meso-star.fr/star-meteo.git
Log | Files | Refs | README | LICENSE

smeteo.h (3805B)


      1 /* Copyright (C) 2025 |Méso|Star> (contact@meso-star.com)
      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 dismshbuted 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 #ifndef SMETEO_H
     17 #define SMETEO_H
     18 
     19 #include <rsys/rsys.h>
     20 #include <time.h>
     21 
     22 /* Library symbol management */
     23 #if defined(SMETEO_SHARED_BUILD)
     24   #define SMETEO_API extern EXPORT_SYM
     25 #else
     26   #define SMETEO_API extern IMPORT_SYM
     27 #endif
     28 
     29 /* Help macro which, in debug mode, stops execution when API functions fail
     30  * To be used when calling functions for which there is no error handling */
     31 #ifndef NDEBUG
     32   #define SMETEO(Func) ASSERT(smeteo_ ## Func == RES_OK)
     33 #else
     34   #define SMETEO(Func) smeteo_ ## Func
     35 #endif
     36 
     37 /* Meteo data for a fixed time interval across the entire dataset */
     38 struct smeteo_entry {
     39   struct tm time; /* Time at the middle of the time interval */
     40 
     41   /* Properties averaged over the time interval */
     42   double Tsrf; /* Surface temperature [K] */
     43   double Tatm; /* Atmosphere temperature [K] */
     44   double Ahum; /* Air humidity [g(water)/kg(air)] */
     45   double Rhum; /* Relative humidity in [0-100] */
     46   double SWdn_direct; /* Direct shortwave downward flux [W/m^2] */
     47   double SWdn_diffuse; /* Diffuse shortwave downward flux [W/m^2] */
     48   double SWup; /* Shortwave upward flux [W/m^2] */
     49   double Trad; /* Radiative temperature [K] */
     50   double H; /* Convection coefficient [W/K/m^2] */
     51   double LE; /* Latent flux >0 from ground to atmosphere [W/m^2] */
     52 
     53   /* Time as a fraction of a day since 00:00 on 1 january 1850, UTC +00:00 */
     54   double day_1850;
     55 };
     56 #define SMETEO_ENTRY_NULL__ {0}
     57 static const struct smeteo_entry SMETEO_ENTRY_NULL = SMETEO_ENTRY_NULL__;
     58 
     59 struct smeteo_desc {
     60   const char* filename;
     61 
     62   /* In [-180,180] decimal degree relative to Greenwitch.
     63    * Positive toward the east */
     64   double longitude;
     65 
     66   /* In [-90, 90] decimal degree relative to the equator.
     67    * Positive toward the north */
     68   double latitude;
     69 
     70   double albedo; /* Ground albedo, for shortwave radiation */
     71 
     72   /* List of meteo data over a period divided into fixed time intervals */
     73   const struct smeteo_entry* entries;
     74   size_t nentries;
     75 };
     76 #define SMETEO_DESC_NULL__ {0}
     77 static const struct smeteo_desc SMETEO_DESC_NULL = SMETEO_DESC_NULL__;
     78 
     79 struct smeteo_create_args {
     80   struct logger* logger; /* May be NULL <=> default logger */
     81   struct mem_allocator* allocator; /* NULL <=> use default allocator */
     82   int verbose; /* Verbosity level */
     83 };
     84 #define SMETEO_CREATE_ARGS_DEFAULT__ {NULL,NULL,0}
     85 static const struct smeteo_create_args SMETEO_CREATE_ARGS_DEFAULT =
     86   SMETEO_CREATE_ARGS_DEFAULT__;
     87 
     88 /* Forward declaration of external data types */
     89 struct logger;
     90 struct mem_allocator;
     91 
     92 /* Forward declaration of opaque data types */
     93 struct smeteo;
     94 
     95 BEGIN_DECLS
     96 
     97 SMETEO_API res_T
     98 smeteo_create
     99   (const struct smeteo_create_args* args,
    100    struct smeteo** smeteo);
    101 
    102 SMETEO_API res_T
    103 smeteo_ref_get
    104   (struct smeteo* smeteo);
    105 
    106 SMETEO_API res_T
    107 smeteo_ref_put
    108   (struct smeteo* smeteo);
    109 
    110 SMETEO_API res_T
    111 smeteo_load
    112   (struct smeteo* smeteo,
    113    const char* filename);
    114 
    115 SMETEO_API res_T
    116 smeteo_load_stream
    117   (struct smeteo* smeteo,
    118    FILE* fp,
    119    const char* name);
    120 
    121 SMETEO_API res_T
    122 smeteo_get_desc
    123   (const struct smeteo* smeteo,
    124    struct smeteo_desc* desc);
    125 
    126 END_DECLS
    127 
    128 #endif /* SMETEO_H */