00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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
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