utils.h

Go to the documentation of this file.
00001 
00005 /* LICENSE BEGIN
00006 
00007 Copyright Cerfacs (Christian Page) (2015)
00008 
00009 christian.page@cerfacs.fr
00010 
00011 This software is a computer program whose purpose is to downscale climate
00012 scenarios using a statistical methodology based on weather regimes.
00013 
00014 This software is governed by the CeCILL license under French law and
00015 abiding by the rules of distribution of free software. You can use, 
00016 modify and/ or redistribute the software under the terms of the CeCILL
00017 license as circulated by CEA, CNRS and INRIA at the following URL
00018 "http://www.cecill.info". 
00019 
00020 As a counterpart to the access to the source code and rights to copy,
00021 modify and redistribute granted by the license, users are provided only
00022 with a limited warranty and the software's author, the holder of the
00023 economic rights, and the successive licensors have only limited
00024 liability. 
00025 
00026 In this respect, the user's attention is drawn to the risks associated
00027 with loading, using, modifying and/or developing or reproducing the
00028 software by the user in light of its specific status of free software,
00029 that may mean that it is complicated to manipulate, and that also
00030 therefore means that it is reserved for developers and experienced
00031 professionals having in-depth computer knowledge. Users are therefore
00032 encouraged to load and test the software's suitability as regards their
00033 requirements in conditions enabling the security of their systems and/or 
00034 data to be ensured and, more generally, to use and operate it in the 
00035 same conditions as regards security. 
00036 
00037 The fact that you are presently reading this means that you have had
00038 knowledge of the CeCILL license and that you accept its terms.
00039 
00040 LICENSE END */
00041 
00042 
00043 
00044 
00045 
00046 
00047 #ifndef UTILS_H
00048 #define UTILS_H
00049 
00050 #ifdef HAVE_CONFIG_H
00051 #include <config.h>
00052 #endif
00053 
00055 #define _GNU_SOURCE
00056 
00057 #ifdef HAVE_STDLIB_H
00058 #include <stdlib.h>
00059 #endif
00060 #ifdef HAVE_SYS_TYPES_H
00061 #include <sys/types.h>
00062 #endif
00063 #ifdef HAVE_SYS_STAT_H
00064 #include <sys/stat.h>
00065 #endif
00066 #ifdef HAVE_FCNTL_H
00067 #include <fcntl.h>
00068 #endif
00069 #ifdef HAVE_SIGNAL_H
00070 #include <signal.h>
00071 #endif
00072 #ifdef HAVE_TIME_H
00073 #include <time.h>
00074 #endif
00075 #ifdef HAVE_UNISTD_H
00076 #include <unistd.h>
00077 #endif
00078 #ifdef HAVE_STRING_H
00079 #include <string.h>
00080 #endif
00081 #ifdef HAVE_STDIO_H
00082 #include <stdio.h>
00083 #endif
00084 #ifdef HAVE_SYS_MMAN_H
00085 #include <sys/mman.h>
00086 #endif
00087 #ifdef HAVE_ERRNO_H
00088 #include <errno.h>
00089 #endif
00090 
00091 #include <gsl/gsl_statistics.h>
00092 
00093 #include "utCalendar2_cal.h"
00094 
00095 /* Local dependent includes */
00096 #include <misc.h>
00097 #include <constants.h>
00098 
00100 #define TRUE 1
00101 
00102 #define FALSE 0
00103 
00105 typedef struct {
00106   int year;  
00107   int month; 
00108   int day;   
00109   int hour;  
00110   int min;   
00111   float sec; 
00112 } tstruct;
00113 
00114 void alloc_mmap_shortint(short int **map, int *fd, size_t *byte_size, char *filename, size_t page_size, int size);
00115 void alloc_mmap_longint(long int **map, int *fd, size_t *byte_size, char *filename, size_t page_size, int size);
00116 void alloc_mmap_int(int **map, int *fd, size_t *byte_size, char *filename, size_t page_size, int size);
00117 void alloc_mmap_float(float **map, int *fd, size_t *byte_size, char *filename, size_t page_size, int size);
00118 void alloc_mmap_double(double **map, int *fd, size_t *byte_size, char *filename, size_t page_size, int size);
00119 int data_to_gregorian_cal_d(double **bufout, double **outtimeval, int *ntimeout, double *bufin,
00120                             double *intimeval, char *tunits_in, char *tunits_out, char *cal_type, int ni, int nj, int ntimein);
00121 int data_to_gregorian_cal_f(float **bufout, double **outtimeval, int *ntimeout, float *bufin,
00122                             double *intimeval, char *tunits_in, char *tunits_out, char *cal_type, int ni, int nj, int ntimein);
00123 int get_calendar(int *year, int *month, int *day, int *hour, int *minutes, float *seconds, char *tunits, double *timein, int ntime);
00124 int get_calendar_ts(tstruct *timeout, char *tunits, double *timein, int ntime);
00125 void change_date_origin(double *timeout, char *tunits_out, double *timein, char *tunits_in, int ntime);
00126 void mean_variance_field_spatial(double *buf_mean, double *buf_var, double *buf, short int *mask, int ni, int nj, int ntime);
00127 void mean_field_spatial(double *buf_mean, double *buf, short int *mask, int ni, int nj, int ntime);
00128 void normalize_field_2d(double *nbuf, double *buf, double *mean, double *var, int ndima, int ndimb, int ntime);
00129 void time_mean_variance_field_2d(double *bufmean, double *bufvar, double *buf, int ni, int nj, int nt);
00130 void covariance_fields_spatial(double *cov, double *buf1, double *buf2, short int *mask, int t1, int t2, int ni, int nj);
00131 int sub_period_common(double **buf_sub, int *ntime_sub, double *bufin, int *year, int *month, int *day,
00132                       int *year_learn, int *month_learn, int *day_learn, int timedim, int ndima, int ndimb, int ntime, int ntime_learn);
00133 void extract_subdomain(double **buf_sub, double **lon_sub, double **lat_sub, int *nlon_sub, int *nlat_sub, double *buf,
00134                        double *lon, double *lat, double minlon, double maxlon, double minlat, double maxlat,
00135                        int nlon, int nlat, int ndim);
00136 void extract_subperiod_months(double **buf_sub, int *ntime_sub, double *bufin, int *year, int *month, int *day,
00137                               int *smonths, int timedim, int ndima, int ndimb, int ntime, int nmonths);
00138 void mask_region(double *buffer, double missing_value, double *lon, double *lat,
00139                  double minlon, double maxlon, double minlat, double maxlat,
00140                  int nlon, int nlat, int ndim);
00141 void mask_points(double *buffer, double missing_value, short int *mask, int nlon, int nlat, int ndim);
00142 void normalize_field(double *nbuf, double *buf, double mean, double var, int ndima, int ndimb, int ntime);
00143 int comparf(const void *a, const void *b);
00144 double distance_point(double lon1, double lat1, double lon2, double lat2);
00145 int find_str_value(char *str, char **str_vect, int nelem);
00146 short int is_leap_year(int year);
00147 void alt_to_press(double *pres, double *alt, int ni, int nj);
00148 void spechum_to_hr(double *hr, double *tas, double *hus, double *pmsl, double fillvalue, int ni, int nj);
00149 void calc_etp_mf(double *etp, double *tas, double *hus, double *rsds, double *rlds, double *uvas, double *pmsl, double fillvalue, int ni, int nj);
00150 
00151 #endif

Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1