48cpl_error_code
sc_lines(cpl_table *groups, cpl_parameterlist *parlist)
70 cpl_error_code status = CPL_ERROR_NONE;
84 varpar = cpl_array_new(0, CPL_TYPE_DOUBLE);
86 cpl_array_delete(varpar);
96 cpl_array_delete(varpar);
101 cpl_array_delete(varpar);
103 return CPL_ERROR_NONE;
108 const cpl_parameterlist *parlist)
130 const cpl_parameter *p;
131 char* basedir = NULL;
133 char* linetabname = NULL;
137 cpl_boolean isoutrange = CPL_FALSE;
138 int nhead = 0, nrec = 0, feat = 0, syst = 0, agroup = 0, bgroup = 0;
139 int ncol0 = 0, ncolmin = 7, i = 0, ncol = 0;
140 double lam = 0., flux = 0., trans = 0.;
143 cpl_table_new_column(groups,
"lambda", CPL_TYPE_DOUBLE);
144 cpl_table_new_column(groups,
"flux", CPL_TYPE_DOUBLE);
145 cpl_table_new_column(groups,
"trans", CPL_TYPE_DOUBLE);
146 cpl_table_new_column(groups,
"feat", CPL_TYPE_INT);
147 cpl_table_new_column(groups,
"system", CPL_TYPE_INT);
148 cpl_table_new_column(groups,
"groupA", CPL_TYPE_INT);
149 cpl_table_new_column(groups,
"groupB", CPL_TYPE_INT);
152 p = cpl_parameterlist_find_const(parlist,
"inst_dir");
153 basedir = cpl_sprintf(
"%s",cpl_parameter_get_string(p));
154 p = cpl_parameterlist_find_const(parlist,
"data_dir");
156 p = cpl_parameterlist_find_const(parlist,
"linetabname");
157 linetabname = cpl_sprintf(
"%s",cpl_parameter_get_string(p));
158 sprintf(linetabfile,
"%s%s", datadir, linetabname);
159 if ((stream = fopen(linetabfile,
"r")) == NULL) {
160 sprintf(errtxt,
"%s: %s", SC_ERROR_FOF_TXT, linetabfile);
161 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_FOF,
"%s", errtxt);
168 while (fgets(str,
SC_LENLINE+2, stream) != NULL) {
173 sprintf(errtxt,
"%s: %s (comment line in data part)",
174 SC_ERROR_UFS_TXT, linetabfile);
175 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s",
178 }
else if (isdigit(str[0]) || isspace(str[0]) || str[0] ==
'-') {
181 ncol0 = sscanf(str,
"%le %le %le %d %d %d %d", &lam, &flux,
182 &trans, &feat, &syst, &agroup, &bgroup);
185 sprintf(errtxt,
"%s: %s (empty line)",
186 SC_ERROR_UFS_TXT, linetabfile);
187 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s",
189 }
else if (ncol0 < ncolmin) {
191 sprintf(errtxt,
"%s: %s (too low number of columns)",
192 SC_ERROR_UFS_TXT, linetabfile);
193 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s",
200 sprintf(errtxt,
"%s: %s (unexpected first character at line)",
201 SC_ERROR_UFS_TXT, linetabfile);
202 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s",
211 sprintf(errtxt,
"%s: %s (no data)",
212 SC_ERROR_UFS_TXT, linetabfile);
213 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s", errtxt);
217 cpl_table_set_size(groups, nrec);
220 for (i = 0; i < nhead; i++) {
226 for (i = 0; i < nrec; i++) {
228 ncol = fscanf(stream,
"%le %le %le %d %d %d %d",
229 &lam, &flux, &trans, &feat, &syst, &agroup, &bgroup);
232 cpl_table_set_size(groups, 0);
234 sprintf(errtxt,
"%s: %s (unexpected number of values at line)",
235 SC_ERROR_UFS_TXT, linetabfile);
236 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s",
240 cpl_table_set(groups,
"lambda", i, lam);
241 cpl_table_set(groups,
"flux", i, flux);
242 cpl_table_set(groups,
"trans", i, trans);
243 cpl_table_set(groups,
"feat", i, feat);
244 cpl_table_set(groups,
"system", i, syst);
245 cpl_table_set(groups,
"groupA", i, agroup);
246 if (syst > 0 && bgroup == 0) {
248 cpl_table_set(groups,
"groupB", i, -syst);
250 cpl_table_set(groups,
"groupB", i, bgroup);
255 isoutrange = CPL_TRUE;
260 isoutrange = CPL_TRUE;
265 isoutrange = CPL_TRUE;
270 isoutrange = CPL_TRUE;
275 isoutrange = CPL_TRUE;
280 isoutrange = CPL_TRUE;
287 if (isoutrange == CPL_TRUE) {
288 cpl_msg_warning(cpl_func,
"%s: Input value(s) out of range -> "
289 "Take lowest/highest allowed value(s)",
292 cpl_free(linetabname);
294 return CPL_ERROR_NONE;
325 cpl_error_code status = CPL_ERROR_NONE;
326 cpl_parameter *p, *q;
328 int year = 0, month = 0, day = 0, hh = 0, mm = 0;
329 int season = 0, timebin = 0;
330 double ss = 0., fracyear = 0., ut = 0., nlen = 0.;
331 double tlim1 = 0., tlim2 = 0.;
332 double nstart[6] = {0.98, 0.48, -0.44, -0.57, -0.23, 0.29};
333 double nend[6] = {8.50, 9.29, 9.77, 10.07, 9.61, 8.60};
336 p = cpl_parameterlist_find(parlist,
"date_val");
337 fracyear = cpl_parameter_get_double(p);
338 p = cpl_parameterlist_find(parlist,
"time_val");
339 ut = cpl_parameter_get_double(p) / 3600.;
342 if (fracyear < 0 || ut < 0) {
343 sprintf(errtxt,
"%s: cpl_parameterlist *parlist (invalid date_val "
344 "and/or time_val)", SC_ERROR_IOV_TXT);
345 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_IOV,
"%s", errtxt);
353 season = floor(month / 2) + 1;
360 nlen = nend[season-1] - nstart[season-1];
361 tlim1 = nstart[season-1] + nlen / 3;
362 tlim2 = nend[season-1] - nlen / 3;
365 }
else if (ut >= tlim2) {
372 p = cpl_parameter_new_value(
"season", CPL_TYPE_INT,
"",
"", season);
373 cpl_parameterlist_append(parlist, p);
374 p = cpl_parameter_new_value(
"timebin", CPL_TYPE_INT,
"",
"", timebin);
375 cpl_parameterlist_append(parlist, p);
378 p = cpl_parameter_new_value(
"year", CPL_TYPE_INT,
"",
"", year);
379 cpl_parameterlist_append(parlist, p);
380 p = cpl_parameter_new_value(
"month", CPL_TYPE_INT,
"",
"", month);
381 cpl_parameterlist_append(parlist, p);
384 q = cpl_parameterlist_find(parlist,
"solflux");
385 if (cpl_parameter_get_double(q) >= 0) {
386 cpl_msg_debug(cpl_func,
"SOLFLUX = %g sfu",
387 cpl_parameter_get_double(q));
388 return CPL_ERROR_NONE;
392 p = cpl_parameterlist_find(parlist,
"soldatsource");
393 cpl_parameter_set_string(p,
"LOCAL");
397 q = cpl_parameterlist_find(parlist,
"solflux");
398 if (cpl_parameter_get_double(q) < 0) {
399 cpl_parameter_set_string(p,
"WEB");
404 if (cpl_parameter_get_double(q) < 0) {
405 cpl_parameter_set_string(p,
"NONE");
410 q = cpl_parameterlist_find(parlist,
"solflux");
441 char* soldatsource = NULL;
442 char* soldaturl = NULL;
443 char* soldatname = NULL;
445 char* basedir = NULL;
449 int year = 0, month = 0, i = 0, y = 0, m = 0, ncol = 0, ncolmin = 5;
450 double obsflux = 0., adjflux = 0., absflux = 0., solflux = -1.;
453 p = cpl_parameterlist_find(parlist,
"year");
454 year = cpl_parameter_get_int(p);
455 p = cpl_parameterlist_find(parlist,
"month");
456 month = cpl_parameter_get_int(p);
459 p = cpl_parameterlist_find(parlist,
"solflux");
460 cpl_parameter_set_double(p, -1.);
463 p = cpl_parameterlist_find(parlist,
"soldatsource");
465 soldatsource = cpl_sprintf(
"%s",cpl_parameter_get_string(p));
467 if ((strcmp(soldatsource,
"LOCAL") != 0 &&
468 strcmp(soldatsource,
"WEB") != 0) ||
469 (strcmp(soldatsource,
"WEB") == 0 &&
470 ((year == 1947 && month == 1) || year < 1947))) {
471 p = cpl_parameterlist_find(parlist,
"solflux");
472 cpl_parameter_set_double(p, 130.);
473 cpl_msg_warning(cpl_func,
"No source for solar radio flux available"
474 " -> Take average of 130 sfu");
475 return CPL_ERROR_NONE;
479 p = cpl_parameterlist_find(parlist,
"soldaturl");
480 soldaturl = cpl_sprintf(
"%s", cpl_parameter_get_string(p));
481 p = cpl_parameterlist_find(parlist,
"soldatname");
482 soldatname = cpl_sprintf(
"%s",cpl_parameter_get_string(p));
483 sprintf(soldatwebfile,
"ftp://%s/%s", soldaturl, soldatname);
486 p = cpl_parameterlist_find(parlist,
"inst_dir");
487 basedir = cpl_sprintf(
"%s", cpl_parameter_get_string(p));
488 p = cpl_parameterlist_find(parlist,
"data_dir");
492 sprintf(soldatfile,
"%s%s", datadir, soldatname);
495 if (strcmp(soldatsource,
"WEB") == 0) {
496 cpl_msg_debug(cpl_func,
497 "Download solar radio flux data from web server");
498 sprintf(sys,
"wget -q --directory-prefix=%s %s", datadir,
510 if ((stream = fopen(soldatfile,
"r")) == NULL) {
511 sprintf(errtxt,
"%s: %s", SC_ERROR_FOF_TXT, soldatfile);
512 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_FOF,
"%s", errtxt);
516 for (i = 0; i < 2; i++) {
522 while (fgets(str,
SC_LENLINE+2, stream) != NULL) {
524 if (isdigit(str[0]) || isspace(str[0])) {
527 ncol = sscanf(str,
"%d %d %le %le %le",
528 &y, &m, &obsflux, &adjflux, &absflux);
533 sprintf(errtxt,
"%s: %s (empty line)",
534 SC_ERROR_UFS_TXT, soldatfile);
535 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s",
537 }
else if (ncol < ncolmin) {
539 sprintf(errtxt,
"%s: %s (too low number of columns)",
540 SC_ERROR_UFS_TXT, soldatfile);
541 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s",
546 if ((y < 1947) || (m < 1) || (m > 12) || (obsflux < 0.)) {
548 sprintf(errtxt,
"%s: %s (invalid value(s))",
549 SC_ERROR_UFS_TXT, soldatfile);
550 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s",
555 if (y == year && m == month) {
564 sprintf(errtxt,
"%s: %s (unexpected first character at line)",
565 SC_ERROR_UFS_TXT, soldatfile);
566 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s",
577 if(strcmp(soldatsource,
"WEB") == 0) {
578 if ((month != 1 && m < month-1 && y == year) ||
579 (month != 1 && y < year) ||
580 (month == 1 && m < 12 && y == year-1) ||
581 (month == 1 && y < year-1)) {
583 cpl_msg_warning(cpl_func,
"Solar radio fluxes until %d/%d only",
586 if (obsflux != solflux) {
592 p = cpl_parameterlist_find(parlist,
"solflux");
593 cpl_parameter_set_double(p, floor(solflux + 0.5));
594 cpl_free(soldatsource);
596 cpl_free(soldatname);
598 return CPL_ERROR_NONE;
603 cpl_parameterlist *parlist)
629 char* basedir = NULL;
631 char* vardatname = NULL;
634 int n =
SC_MAXPAR, nfeat = 0, nseason = 0, ntime = 0, season = 0;
635 int timebin = 0, i = 0, j = 0;
636 double alt = 0., solflux = 0., height = 0., scale = 0., cons = 0.;
637 double slope = 0., mean = 0., z = 0., cvr = 0., csol = 0.;
640 p = cpl_parameterlist_find(parlist,
"inst_dir");
641 basedir = cpl_sprintf(
"%s", cpl_parameter_get_string(p));
642 p = cpl_parameterlist_find(parlist,
"data_dir");
644 p = cpl_parameterlist_find(parlist,
"vardatname");
645 vardatname = cpl_sprintf(
"%s", cpl_parameter_get_string(p));
646 sprintf(vardatfile,
"%s%s", datadir, vardatname);
647 if ((stream = fopen(vardatfile,
"r")) == NULL) {
648 sprintf(errtxt,
"%s: %s", SC_ERROR_FOF_TXT, vardatfile);
649 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_FOF,
"%s", errtxt);
667 if (nfeat == 0 || nseason == 0 || ntime == 0) {
669 sprintf(errtxt,
"%s: %s (nfeat == 0 || nseason == 0 || ntime == 0)",
670 SC_ERROR_UFS_TXT, vardatfile);
671 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_UFS,
"%s", errtxt);
675 p = cpl_parameterlist_find(parlist,
"telalt_val");
676 alt = cpl_parameter_get_double(p);
677 p = cpl_parameterlist_find(parlist,
"solflux");
678 solflux = cpl_parameter_get_double(p);
679 p = cpl_parameterlist_find(parlist,
"season");
680 season = cpl_parameter_get_int(p);
681 p = cpl_parameterlist_find(parlist,
"timebin");
682 timebin = cpl_parameter_get_int(p);
683 if ((alt < 0.) || (alt > 90.) || (solflux < 0.) ||
684 (season < 0) || (season > nseason) || (timebin < 0) || (timebin > ntime)) {
686 sprintf(errtxt,
"%s: cpl_parameterlist *parlist (telalt, solflux, "
687 "season, and/or timebin out of range) ", SC_ERROR_IOV_TXT);
688 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_IOV,
"%s", errtxt);
692 cpl_array_set_size(varpar, nfeat);
697 for (i = 0; i < nfeat; i++) {
711 for (j = 0; j < ntime + 1; j++) {
719 for (j = 0; j < ntime + 1; j++) {
725 z = (90. - alt) * CPL_MATH_RAD_DEG;
726 cvr = 1 / sqrt(1 - pow((
SC_ERAD / (
SC_ERAD + height)) * sin(z), 2));
729 csol = slope * solflux + cons;
732 cpl_array_set(varpar, i, scale * cvr * csol * mean);
739 cpl_free(vardatname);
741 return CPL_ERROR_NONE;
746 const cpl_parameterlist *parlist)
768 const cpl_parameter *p;
769 cpl_boolean isoutrange = CPL_FALSE;
770 int nlin = 0, nfeat = 0, i = 0, feat = 0;
771 const double *corr = NULL;
772 double z = 0., xz = 0., trans = 0., flux = 0.;
775 nlin = cpl_table_get_nrow(groups);
776 nfeat = cpl_array_get_size(varpar);
779 corr = cpl_array_get_data_double_const(varpar);
782 p = cpl_parameterlist_find_const(parlist,
"telalt_val");
783 z = (90. - cpl_parameter_get_double(p)) * CPL_MATH_RAD_DEG;
787 xz = 1 / (cos(z) + 0.025 * exp(-11 * cos(z)));
794 for (i = 0; i < nlin; i++) {
795 feat = cpl_table_get(groups,
"feat", i, NULL);
798 isoutrange = CPL_TRUE;
800 trans = pow(cpl_table_get(groups,
"trans", i, NULL), xz);
801 flux = cpl_table_get(groups,
"flux", i, NULL);
802 cpl_table_set(groups,
"flux", i, flux * corr[feat-1] * trans);
807 if (isoutrange == CPL_TRUE) {
808 cpl_msg_warning(cpl_func,
"Variability class too high -> "
812 return CPL_ERROR_NONE;
817 const cpl_parameterlist *parlist)
836 const cpl_parameter *p;
839 double *lam, sig2 = 0., n = 0.;
842 p = cpl_parameterlist_find_const(parlist,
"vac_air");
843 strcpy(vac_air, cpl_parameter_get_string(p));
846 if (strncmp(vac_air,
"vac", 3) != 0 && strncmp(vac_air,
"air", 3) != 0) {
847 sprintf(errtxt,
"%s: cpl_parameterlist *parlist (vac_air neither "
848 "'vac' nor 'air')", SC_ERROR_IOV_TXT);
849 return cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_IOV,
"%s", errtxt);
853 if (strncmp(vac_air,
"vac", 3) == 0) {
854 return CPL_ERROR_NONE;
858 nrow = cpl_table_get_nrow(groups);
861 lam = cpl_table_get_data_double(groups,
"lambda");
864 for (i = 0; i < nrow; i++) {
865 sig2 = pow(lam[i], -2);
866 n = 8342.13 + 2406030. / (130. - sig2) + 15997. / (38.9 - sig2);
871 return CPL_ERROR_NONE;
double sc_basic_fracyear2date(int *year, int *month, int *day, int *hh, int *mm, double *ss, const double *fracyear)
void sc_basic_abspath(char *out, const char *dir, const char *cwd)
cpl_error_code sc_basic_readline(FILE *stream, scpar par[], int *npar)
cpl_error_code sc_lines(cpl_table *groups, cpl_parameterlist *parlist)
cpl_error_code sc_lines_vactoair(cpl_table *groups, const cpl_parameterlist *parlist)
cpl_error_code sc_lines_readlist(cpl_table *groups, const cpl_parameterlist *parlist)
cpl_error_code sc_lines_readsolflux(cpl_parameterlist *parlist)
cpl_error_code sc_lines_readvarpar(cpl_array *varpar, cpl_parameterlist *parlist)
cpl_error_code sc_lines_scalelines(cpl_table *groups, const cpl_array *varpar, const cpl_parameterlist *parlist)
cpl_error_code sc_lines_getmodelbins(cpl_parameterlist *parlist)