00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #include <dsclim.h>
00063
00065 void show_usage(char *pgm);
00066 short int show_license();
00067
00069 int main(int argc, char **argv)
00070 {
00078 int i;
00079 int istat = 0;
00080 data_struct *data = NULL;
00081 short int license_accept = 0;
00082 short int downscale = TRUE;
00083
00084
00085 char fileconf[500];
00086
00087
00088 license_accept = show_license();
00089 if (license_accept == 1)
00090 (void) printf("\n\nYou accepted the license and its terms: the program can continue!\nYou will not have to input again the acceptance of the license\nand its terms for further use of the program in the current account.\n\n");
00091 else if (license_accept != 2) {
00092 (void) printf("\n\nYou did not accept the license and its terms: the program cannot continue. It must exit now.\n\n");
00093 (void) exit(0);
00094 }
00095
00096
00097
00098 (void) banner(PACKAGE_NAME, PACKAGE_VERSION, "BEGIN");
00099
00100
00101 data = (data_struct *) malloc(sizeof(data_struct));
00102 if (data == NULL) alloc_error(__FILE__, __LINE__);
00103
00104
00105 (void) printf("\n**** PROCESS COMMAND-LINE ARGUMENTS ****\n\n");
00106 if (argc <= 1) {
00107 (void) show_usage(PACKAGE_NAME);
00108 (void) banner(PACKAGE_NAME, "ABORT", "END");
00109 (void) exit(1);
00110 }
00111 else
00112
00113 for (i=1; i<argc; i++) {
00114 if ( !strcmp(argv[i], "-conf") )
00115 (void) strcpy(fileconf, argv[++i]);
00116 else if ( !strcmp(argv[i], "--version") ) {
00117 (void) printf("%s version %s\n\n", PACKAGE_NAME, PACKAGE_VERSION);
00118 (void) banner(PACKAGE_NAME, "OK", "END");
00119 (void) exit(0);
00120 }
00121 else {
00122 (void) fprintf(stderr, "%s:: Wrong arg %s.\n\n", PACKAGE_NAME, argv[i]);
00123 (void) show_usage(PACKAGE_NAME);
00124 (void) banner(PACKAGE_NAME, "ABORT", "END");
00125 (void) exit(1);
00126 }
00127 }
00128
00129
00130
00131 (void) printf("\n**** LOADING CONFIGURATION ****\n\n");
00132 istat = load_conf(data, fileconf);
00133 if (istat != 0) {
00134 (void) fprintf(stderr, "%s: Error in loading configuration file. Aborting.\n", __FILE__);
00135 (void) banner(PACKAGE_NAME, "ABORT", "END");
00136 (void) abort();
00137 }
00138
00139
00140
00141 if (data->conf->output_only == FALSE) {
00142
00143
00144 if (data->reg->filename != NULL) {
00145 (void) printf("\n**** READING REGRESSION POSITIONS ****\n\n");
00146 istat = read_regression_points(data->reg);
00147 if (istat != 0) {
00148 (void) fprintf(stderr, "%s: Error in reading regression points positions. Aborting.\n", __FILE__);
00149 (void) banner(PACKAGE_NAME, "ABORT", "END");
00150 (void) abort();
00151 }
00152 }
00153
00154
00155 if (data->secondary_mask->use_mask == TRUE) {
00156 (void) printf("\n**** SECONDARY LARGE-SCALE FIELDS MASK ****\n\n");
00157 istat = read_mask(data->secondary_mask);
00158 if (istat != 0) {
00159 (void) fprintf(stderr, "%s: Error in reading secondary large-scale mask file. Aborting.\n", __FILE__);
00160 (void) banner(PACKAGE_NAME, "ABORT", "END");
00161 (void) abort();
00162 }
00163 }
00164
00165
00166 if (data->conf->learning_maskfile->use_mask == TRUE) {
00167 (void) printf("\n**** LEARNING FIELDS MASK ****\n\n");
00168 istat = read_mask(data->conf->learning_maskfile);
00169 if (istat != 0) {
00170 (void) fprintf(stderr, "%s: Error in reading learning mask file. Aborting.\n", __FILE__);
00171 (void) banner(PACKAGE_NAME, "ABORT", "END");
00172 (void) abort();
00173 }
00174 }
00175
00176
00177 (void) printf("\n**** LEARNING ****\n\n");
00178 istat = wt_learning(data);
00179 if (istat != 0) {
00180 (void) fprintf(stderr, "%s: Error in computing or reading learning data needed for downscaling. Aborting.\n", __FILE__);
00181 (void) banner(PACKAGE_NAME, "ABORT", "END");
00182 (void) abort();
00183 }
00184 }
00185
00186
00187 downscale = FALSE;
00188 for (i=0; i<data->conf->nperiods; i++)
00189 if (data->conf->period[i].downscale == TRUE)
00190 downscale = TRUE;
00191 if (data->conf->period_ctrl->downscale == TRUE || downscale == TRUE) {
00192 (void) printf("\n**** DOWNSCALING ****\n\n");
00193 if (data->conf->output_only == TRUE)
00194 (void) printf("****WARNING: Configuration for reading analog dates and writing data ONLY!\n\n");
00195 istat = wt_downscaling(data);
00196 if (istat != 0) {
00197 (void) fprintf(stderr, "%s: Error in performing downscaling. Aborting.\n", __FILE__);
00198 (void) banner(PACKAGE_NAME, "ABORT", "END");
00199 (void) abort();
00200 }
00201 }
00202
00203
00204 (void) printf("\n**** FREE MEMORY ****\n\n");
00205 (void) free_main_data(data);
00206 (void) free(data);
00207
00208
00209 (void) banner(PACKAGE_NAME, "OK", "END");
00210
00211 return 0;
00212 }
00213
00214
00218 void
00219 show_usage(char *pgm) {
00224 (void) fprintf(stderr, "%s:: usage:\n", pgm);
00225 (void) fprintf(stderr, "-conf: configuration file\n");
00226
00227 }
00228
00230 short int
00231 show_license() {
00236 short int license_accept = 0;
00237 int istat = -1;
00238 const char license[5000] = "\nCopyright Cerfacs (Christian Page) (2010)\n\nchristian.page@cerfacs.fr\n\nThis software is a computer program whose purpose is to downscale climate\nscenarios using a statistical methodology based on weather regimes.\n\nThis software is governed by the CeCILL license under French law and\nabiding by the rules of distribution of free software. You can use, \nmodify and/ or redistribute the software under the terms of the CeCILL\nlicense as circulated by CEA, CNRS and INRIA at the following URL\n\"http://www.cecill.info\". \n\nAs a counterpart to the access to the source code and rights to copy,\nmodify and redistribute granted by the license, users are provided only\nwith a limited warranty and the software's author, the holder of the\neconomic rights, and the successive licensors have only limited\nliability. \n\nIn this respect, the user's attention is drawn to the risks associated\nwith loading, using, modifying and/or developing or reproducing the\nsoftware by the user in light of its specific status of free software,\nthat may mean that it is complicated to manipulate, and that also\ntherefore means that it is reserved for developers and experienced\nprofessionals having in-depth computer knowledge. Users are therefore\nencouraged to load and test the software's suitability as regards their\nrequirements in conditions enabling the security of their systems and/or \ndata to be ensured and, more generally, to use and operate it in the \nsame conditions as regards security. \n\nTo further continue, you must accept the CeCILL license and its terms.\n\n";
00239 char *dsclim_lic_file = NULL;
00240 char *dsclim_lic = NULL;
00241 FILE *ifile = NULL;
00242
00243
00244 dsclim_lic_file = (char *) malloc(MAXPATH * sizeof(char));
00245 if (dsclim_lic_file == NULL) alloc_error(__FILE__, __LINE__);
00246 (void) sprintf(dsclim_lic_file, "%s/%s", getenv("HOME"), ".dsclim_lic");
00247
00248 if ( access(dsclim_lic_file, F_OK) != 0 ) {
00249 dsclim_lic = (char *) malloc(10 * sizeof(char));
00250 if (dsclim_lic == NULL) alloc_error(__FILE__, __LINE__);
00251
00252 (void) fprintf(stdout, license);
00253 (void) fprintf(stdout, "Do you accept or deny the license? [Type accept or deny]: ");
00254
00255 istat = scanf("%7s", dsclim_lic);
00256 if ( !strcmp(dsclim_lic, "accept") ) {
00257 license_accept = 1;
00258 ifile = fopen(dsclim_lic_file, "w");
00259 if (ifile == NULL)
00260 (void) fprintf(stderr, "%s: Failed to write license acceptance file.\n", __FILE__);
00261 (void) fprintf(ifile, license);
00262 (void) fprintf(ifile, "The user accepted the dsclim license and its terms.\n\n");
00263 (void) fclose(ifile);
00264 }
00265 (void) free(dsclim_lic);
00266 }
00267 else
00268 license_accept = 2;
00269
00270 (void) free(dsclim_lic_file);
00271
00272 return license_accept;
00273 }