00001
00002
00003
00004
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
00048
00049
00050
00051
00052
00053
00054 #include <string.h>
00055 #include <stdio.h>
00056 #include <stdlib.h>
00057 #include <stdarg.h>
00058 #include <sys/stat.h>
00059
00060 #include "cJSON.h"
00061
00062 #include "segment_modelset.h"
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 static double seg_model_qs_test_yang[] = {
00085 0.204635504622, 1.20531725063, 1.00777710322, 19.346252856, 0.00419579448962, 0.0564904666445,
00086 0.204635504622, -1.20531725063, 1.00777710322, 19.346252856, 0.00419579448962, -0.0564904666445,
00087 0.232398997138, 0, 1.02955618645, 2.7404836868, 0.00427555589387, 0,
00088 0.145253155252, 0, 0.992142854282, 247.248235524, 0.00504149434045, 0,
00089 0.139157664971, 0, 0.950374859774, 74.2478459635, 0.000555807820391, 0,
00090 0.0617507192555, 0, 0.986125619938, 2854.35303874, 0.00151332362565, 0,
00091 0.01216845414, 0, 1.01070360771, 89583.9686521, 0.0145007628344, 0};
00092 static double seg_model_ar_test_yang[] = {
00093 0.192105993124, -846.854676681, 0.743104620169, 118603.827293, 0.00499678354147, 10.6891118764,
00094 0.192105993124, 846.854676681, 0.743104620169, 118603.827293, 0.00499678354147, -10.6891118764,
00095 0.126980271901, 311.120029981, 0.773004292296, 18546.8591144, 0.00277679162354, 0.270699599935,
00096 0.126980271901, -311.120029981, 0.773004292296, 18546.8591144, 0.00277679162354, -0.270699599935,
00097 0.111840866217, 1725.55076542, 0.432208758685, 148513.00487, 0.0244679802074, -43.2940104149,
00098 0.111840866217, -1725.55076542, 0.432208758685, 148513.00487, 0.0244679802074, 43.2940104149,
00099 0.0690728687575, -2565.81843681, 0.13790051683, 124931.169245, 0.0014162131028, 10.5502256214,
00100 0.0690728687575, 2565.81843681, 0.13790051683, 124931.169245, 0.0014162131028, -10.5502256214};
00101 static double seg_model_alpha_test_yang[] = {0, -4.0};
00102
00103
00104
00105
00106 static double seg_model_qs_M_Ic_720s[] = {
00107 0.676700379049, 0, 13321.3804543, 137.665818814, 133580569.057, 0,
00108 0.30516524961, 0, 13833.1964163, 214.193316404, 127827406.447, 0,
00109 0.0181343713409, 0, 13300.8328273, 4715.87050328, 147742870.796, 0};
00110 static double seg_model_ar_M_Ic_720s[] = {
00111 0.373249775824, -534.166827748, 13470.5783991, 87955.4275489, 140934500.036, -21833.1675272,
00112 0.373249775824, 534.166827748, 13470.5783991, 87955.4275489, 140934500.036, 21833.1675272,
00113 0.118699362858, 194.068579955, 13621.338073, 6919.60349716, 150211728.679, -33384.7350668,
00114 0.118699362858, -194.068579955, 13621.338073, 6919.60349716, 150211728.679, 33384.7350668,
00115 0.0161017226367, 0, 13038.102521, 165305.443351, 73124251.7542, 0};
00116 static double seg_model_alpha_M_Ic_720s[] = {0, -4.0};
00117
00118
00119
00120
00121 static double seg_model_qs_M_Ic_noLD_V1_720s[] = {
00122 0.6767003790, 0.0000000000, 0.9867689225, 137.6658188140, 0.7329523679, 0.0000000000,
00123 0.3051652496, 0.0000000000, 1.0246812160, 214.1933164040, 0.7013849462, 0.0000000000,
00124 0.0181343713, 0.0000000000, 0.9852468761, 4715.8705032800, 0.8106604708, 0.0000000000};
00125 static double seg_model_ar_M_Ic_noLD_V1_720s[] = {
00126 0.3732497758, -534.1668277480, 0.9978206222, 87955.4275489000, 0.7733031552, -1.6172716687,
00127 0.3732497758, 534.1668277480, 0.9978206222, 87955.4275489000, 0.7733031552, 1.6172716687,
00128 0.1186993629, 194.0685799550, 1.0089880054, 6919.6034971600, 0.8242070161, -2.4729433383,
00129 0.1186993629, -194.0685799550, 1.0089880054, 6919.6034971600, 0.8242070161, 2.4729433383,
00130 0.0161017226, 0.0000000000, 0.9657853719, 165305.443351000, 0.4012304623, 0.0000000000};
00131 static double seg_model_alpha_M_Ic_noLD_V1_720s[] = {0, -4.0};
00132
00133
00134
00135
00136
00137 static double seg_model_qs_M_Ic_noLD_720s[] = {
00138 0.6767003790, 0.0000000000, 0.9867689225, 232.65523379566, 0.7329523679, 0.0000000000,
00139 0.3051652496, 0.0000000000, 1.0246812160, 361.98670472276, 0.7013849462, 0.0000000000,
00140 0.0181343713, 0.0000000000, 0.9852468761, 7969.82115054320, 0.8106604708, 0.0000000000};
00141 static double seg_model_ar_M_Ic_noLD_720s[] = {
00142 0.3732497758, -694.4168760724, 0.9978206222, 148644.672557641, 0.7733031552, -2.1024531693,
00143 0.3732497758, 694.4168760724, 0.9978206222, 148644.672557641, 0.7733031552, 2.1024531693,
00144 0.1186993629, 252.2891539415, 1.0089880054, 11694.129910200, 0.8242070161, -3.2148263398,
00145 0.1186993629, -252.2891539415, 1.0089880054, 11694.129910200, 0.8242070161, 3.2148263398,
00146 0.0161017226, 0.0000000000, 0.9657853719, 279366.199263190, 0.4012304623, 0.0000000000};
00147 static double seg_model_alpha_M_Ic_noLD_720s[] = {0, -4.0};
00148
00149
00150
00151
00152
00153 static double seg_model_qs_mdi_fdM_II_96m[] = {
00154 0.6767003790, 0.0000000000, 0.9867689225, 456.00425823949, 0.7329523679, 0.0000000000,
00155 0.3051652496, 0.0000000000, 1.0246812160, 709.49394125661, 0.7013849462, 0.0000000000,
00156 0.0181343713, 0.0000000000, 0.9852468761,15620.84945506467, 0.8106604708, 0.0000000000};
00157 static double seg_model_ar_mdi_fdM_II_96m[] = {
00158 0.3732497758, -972.18362650136, 0.9978206222, 291343.55821297632, 0.7733031552, -2.94343443702,
00159 0.3732497758, 972.18362650136, 0.9978206222, 291343.55821297632, 0.7733031552, 2.94343443702,
00160 0.1186993629, 353.20481551810, 1.0089880054, 22920.49462399200, 0.8242070161, -4.50075687572,
00161 0.1186993629, -353.20481551810, 1.0089880054, 22920.49462399200, 0.8242070161, 4.50075687572,
00162 0.0161017226, 0.00000000000, 0.9657853719, 547557.75055585231, 0.4012304623, 0.00000000000};
00163 static double seg_model_alpha_mdi_fdM_II_96m[] = {0, -4.0};
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 #define SEG_MODEL_ONEROW (6 * sizeof(double))
00178
00179 static seg_modelset_t
00180 seg_model_test_yang = {
00181 SEG_BUILTIN_PREFIX "/hmi.M_Ic_proxy.test",
00182 "Pre-launch model for proxy images made by Yang Liu",
00183 "1 from 2010.03.01",
00184 2,
00185 2, "var,diag-then-upper",
00186 seg_model_alpha_test_yang,
00187 {
00188
00189 {"quiet Sun",
00190 sizeof(seg_model_qs_test_yang)/SEG_MODEL_ONEROW,
00191 seg_model_qs_test_yang},
00192 {"active region",
00193 sizeof(seg_model_ar_test_yang)/SEG_MODEL_ONEROW,
00194 seg_model_ar_test_yang}
00195 }
00196 };
00197
00198 static seg_modelset_t
00199 seg_model_M_Ic_720s = {
00200 SEG_BUILTIN_PREFIX "/hmi.M_Ic_720s.production",
00201 "First post-launch model using hmi.Ic_720s and hmi.M_720s",
00202 "1 from 2010.04.15",
00203 2,
00204 2, "var,diag-then-upper",
00205 seg_model_alpha_M_Ic_720s,
00206 {
00207
00208 {"quiet Sun",
00209 sizeof(seg_model_qs_M_Ic_720s)/SEG_MODEL_ONEROW,
00210 seg_model_qs_M_Ic_720s},
00211 {"active region",
00212 sizeof(seg_model_ar_M_Ic_720s)/SEG_MODEL_ONEROW,
00213 seg_model_ar_M_Ic_720s}
00214 }
00215 };
00216
00217 static seg_modelset_t
00218 seg_model_M_Ic_noLD_V1_720s = {
00219 SEG_BUILTIN_PREFIX "/hmi.M_Ic_noLimbDark_720s.version1",
00220 "Model using hmi.Ic_noLimbDark_720s and hmi.M_720s, June 2011, obsolete",
00221 "1 from 2011.06.20",
00222 2,
00223 2, "var,diag-then-upper",
00224 seg_model_alpha_M_Ic_noLD_V1_720s,
00225 {
00226
00227 {"quiet Sun",
00228 sizeof(seg_model_qs_M_Ic_noLD_V1_720s)/SEG_MODEL_ONEROW,
00229 seg_model_qs_M_Ic_noLD_V1_720s},
00230 {"active region",
00231 sizeof(seg_model_ar_M_Ic_noLD_V1_720s)/SEG_MODEL_ONEROW,
00232 seg_model_ar_M_Ic_noLD_V1_720s}
00233 }
00234 };
00235
00236 static seg_modelset_t
00237 seg_model_M_Ic_noLD_720s = {
00238 SEG_BUILTIN_PREFIX "/hmi.M_Ic_noLimbDark_720s.production",
00239 "Model using hmi.Ic_noLimbDark_720s and hmi.M_720s",
00240 "1 from 2011.10.10",
00241 2,
00242 2, "var,diag-then-upper",
00243 seg_model_alpha_M_Ic_noLD_720s,
00244 {
00245
00246 {"quiet Sun",
00247 sizeof(seg_model_qs_M_Ic_noLD_720s)/SEG_MODEL_ONEROW,
00248 seg_model_qs_M_Ic_noLD_720s},
00249 {"active region",
00250 sizeof(seg_model_ar_M_Ic_noLD_720s)/SEG_MODEL_ONEROW,
00251 seg_model_ar_M_Ic_noLD_720s}
00252 }
00253 };
00254
00255 static seg_modelset_t
00256 seg_model_mdi_fd_M_II_96m = {
00257 SEG_BUILTIN_PREFIX "/mdi.fd_M_II_96m.production",
00258 "Model using su_turmon.mdi_II_96m and mdi.fd_M_96m_lev182",
00259 "1 from 2013.09.01",
00260 2,
00261 2, "var,diag-then-upper",
00262 seg_model_alpha_mdi_fdM_II_96m,
00263 {
00264
00265 {"quiet Sun",
00266 sizeof(seg_model_qs_mdi_fdM_II_96m)/SEG_MODEL_ONEROW,
00267 seg_model_qs_mdi_fdM_II_96m},
00268 {"active region",
00269 sizeof(seg_model_ar_mdi_fdM_II_96m)/SEG_MODEL_ONEROW,
00270 seg_model_ar_mdi_fdM_II_96m}
00271 }
00272 };
00273
00274
00275
00276 #undef SEG_MODEL_ONEROW
00277
00278
00279
00280 static seg_modelset_t *
00281 seg_models_known[] = {
00282 &seg_model_test_yang,
00283 &seg_model_M_Ic_720s,
00284 &seg_model_M_Ic_noLD_V1_720s,
00285 &seg_model_M_Ic_noLD_720s,
00286 &seg_model_mdi_fd_M_II_96m,
00287 NULL};
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 static char seg_err_buf[200];
00321
00322 static
00323 char *
00324 seg_err_log(const char *fmt, ...)
00325 {
00326 va_list ap;
00327 char *rv;
00328
00329 va_start(ap, fmt);
00330 if (fmt) {
00331 vsnprintf(seg_err_buf, sizeof(seg_err_buf), fmt, ap);
00332 rv = NULL;
00333 }
00334 else {
00335 rv = seg_err_buf;
00336 }
00337 va_end(ap);
00338 return rv;
00339 }
00340
00341
00342
00343
00344
00345
00346 static
00347 char *
00348 retrieve_str(cJSON *obj, char *name, char *parent, int *status)
00349 {
00350 cJSON *field;
00351 char *str;
00352
00353 if (*status) return NULL;
00354 if ((field = cJSON_GetObjectItem(obj, name)) == NULL) {
00355 *status = 1;
00356 seg_err_log("string: no field `%s' in `%s'.", name, parent);
00357 return NULL;
00358 }
00359 if (field->type != cJSON_String) {
00360 *status = 1;
00361 seg_err_log("string: field `%s' in `%s' was not a string.", name, parent);
00362 return NULL;
00363 }
00364
00365 if ((str = strdup(field->valuestring)) == NULL) {
00366 *status = 1;
00367 seg_err_log("string: out of memory for field `%s' in `%s'.", name, parent);
00368 return NULL;
00369 }
00370 return str;
00371 }
00372
00373
00374
00375
00376
00377
00378 static
00379 int
00380 retrieve_int(cJSON *obj, char *name, char *parent, int *status)
00381 {
00382 cJSON *field;
00383
00384 if (*status) return 0;
00385 if ((field = cJSON_GetObjectItem(obj, name)) == NULL) {
00386 *status = 1;
00387 seg_err_log("int: no field `%s' in `%s'.", name, parent);
00388 return 0;
00389 }
00390 if (field->type != cJSON_Number) {
00391 *status = 1;
00392 seg_err_log("int: field `%s' in `%s' was not an int.", name, parent);
00393 return 0;
00394 }
00395 return field->valueint;
00396 }
00397
00398
00399
00400
00401
00402
00403
00404 static
00405 cJSON *
00406 retrieve_obj(cJSON *obj, char *name, char *parent, int *status)
00407 {
00408 cJSON *obj2;
00409
00410 if (*status) return NULL;
00411 if ((obj2 = cJSON_GetObjectItem(obj, name)) == NULL) {
00412 *status = 1;
00413 seg_err_log("obj: no field `%s' in `%s'.", name, parent);
00414 return NULL;
00415 }
00416 return obj2;
00417 }
00418
00419
00420
00421
00422
00423
00424
00425 static
00426 cJSON *
00427 retrieve_itm(cJSON *obj, int i, char *parent, int *status)
00428 {
00429 cJSON *obj2;
00430
00431 if (*status) return NULL;
00432 if (obj->type != cJSON_Array) {
00433 *status = 1;
00434 seg_err_log("item: parent object `%s' was not an array.", parent);
00435 return NULL;
00436 }
00437 if ((obj2 = cJSON_GetArrayItem(obj, i)) == NULL) {
00438 *status = 1;
00439 seg_err_log("item: no item #%d in parent `%s'.", i+1, parent);
00440 return NULL;
00441 }
00442 return obj2;
00443 }
00444
00445
00446
00447
00448
00449
00450
00451 static
00452 double *
00453 retrieve_arr(cJSON *obj, char *name, char *parent, int len, int *status)
00454 {
00455 int len1, i;
00456 double *arr;
00457 cJSON *field, *entry;
00458
00459 if (*status) return NULL;
00460 if ((field = cJSON_GetObjectItem(obj, name)) == NULL) {
00461 *status = 1;
00462 seg_err_log("array: no field `%s' in `%s'.", name, parent);
00463 return NULL;
00464 }
00465 if (field->type != cJSON_Array) {
00466 *status = 1;
00467 seg_err_log("array: field `%s' in `%s' was not an array.", name, parent);
00468 return NULL;
00469 }
00470 len1 = cJSON_GetArraySize(field);
00471 if (len < 0) {
00472 len = len1;
00473 } else if (len1 != len) {
00474
00475 *status = 1;
00476 seg_err_log("array: field `%s' in `%s' had length %d, expected %d.",
00477 name, parent, len1, len);
00478 return NULL;
00479 }
00480 if ((arr = calloc(len, sizeof(double))) == NULL) {
00481 *status = 1;
00482 seg_err_log("array: field `%s' in `%s': failed calloc (%d doubles).",
00483 name, parent, len);
00484 return NULL;
00485 }
00486
00487 for (i = 0; i < len; i++) {
00488 entry = cJSON_GetArrayItem(field, i);
00489 if (!entry) {
00490 *status = 1;
00491 seg_err_log("array: field `%s' in `%s': could not find item #%d of %d.",
00492 name, parent, i+1, len);
00493 return NULL;
00494 }
00495 if (entry->type != cJSON_Number) {
00496 *status = 1;
00497 seg_err_log("array: field `%s' in `%s': expected item #%d of %d to be numeric",
00498 name, parent, i+1, len);
00499 return NULL;
00500 }
00501 arr[i] = entry->valuedouble;
00502 }
00503 return arr;
00504 }
00505
00506
00507
00508
00509
00510
00511
00512 static
00513 seg_modelset_t *
00514 extract_modelset(cJSON *root)
00515 {
00516 int i, Nc;
00517 seg_modelset_t *m = NULL;
00518 seg_onemodel_t *m1;
00519 cJSON *JS_set;
00520 cJSON *JS_models;
00521 cJSON *JS_m1;
00522 int status = 0;
00523 char str_m1[40];
00524
00525
00526 seg_err_log("");
00527
00528 JS_set = retrieve_obj(root, "modelset","root", &status);
00529 Nc = retrieve_int(JS_set, "nclass", "modelset", &status);
00530
00531 if (status) return NULL;
00532
00533 if ((m = calloc(1,
00534 sizeof(seg_modelset_t) +
00535 sizeof(seg_onemodel_t)*Nc)) == NULL) {
00536 seg_err_log("extract: failed calloc for modelset");
00537 return NULL;
00538 }
00539 m->nclass = Nc;
00540 m->name = retrieve_str(JS_set, "name", "modelset", &status);
00541 m->descrip = retrieve_str(JS_set, "descrip", "modelset", &status);
00542 m->version = retrieve_str(JS_set, "version", "modelset", &status);
00543 m->ndim = retrieve_int(JS_set, "ndim", "modelset", &status);
00544 m->format = retrieve_str(JS_set, "format", "modelset", &status);
00545 m->alpha = retrieve_arr(JS_set, "alpha", "modelset", Nc, &status);
00546 JS_models = retrieve_obj(JS_set, "models", "modelset", &status);
00547 for (i = 0; i < Nc; i++) {
00548
00549 snprintf(str_m1, sizeof(str_m1), "models(%d) in modelset", i+1);
00550
00551 m1 = m->models+i;
00552 JS_m1 = retrieve_itm(JS_models, i, str_m1, &status);
00553 m1->name = retrieve_str(JS_m1, "name", str_m1, &status);
00554 m1->k = retrieve_int(JS_m1, "k", str_m1, &status);
00555 m1->params= retrieve_arr(JS_m1, "params", str_m1, (m1->k)*6, &status);
00556 }
00557 if (status) {
00558 seg_modelset_destroy(m);
00559 return NULL;
00560 } else {
00561 return m;
00562 }
00563 }
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579 seg_modelset_t *
00580 seg_text2modelset(char *text, char **errmsg)
00581 {
00582 const int errmsg_max = 140;
00583 const char *msg_low;
00584 int low_len;
00585 const char *msg_fmt;
00586 char *msg_ez;
00587 char *suffix;
00588 cJSON *json;
00589 seg_modelset_t *m;
00590
00591 json = cJSON_Parse(text);
00592 if (json == NULL) {
00593 m = NULL;
00594
00595 msg_low = cJSON_GetErrorPtr();
00596 msg_fmt = "JSON parse error before the string:\n%.96s%s";
00597 msg_ez = "JSON parse error. Could not allocate memory for description";
00598 } else {
00599 m = extract_modelset(json);
00600 cJSON_Delete(json);
00601 if (!m) {
00602 msg_low = seg_err_log(NULL);
00603 msg_fmt = "text2modelset: Could not retrieve %.96s%s";
00604 msg_ez = "text2modelset: Could not retrieve an element";
00605 }
00606 }
00607
00608 if (m) {
00609 *errmsg = NULL;
00610 } else {
00611
00612 low_len = strlen(msg_low);
00613 if (low_len > 96) suffix = " [...]"; else suffix = "";
00614 if ((*errmsg = calloc(errmsg_max, 1)) == NULL) {
00615 *errmsg = msg_ez;
00616 } else {
00617 snprintf(*errmsg, errmsg_max, msg_fmt, msg_low, suffix);
00618 }
00619 }
00620 return m;
00621 }
00622
00623
00624
00625
00626
00627
00628 seg_modelset_t *
00629 seg_modelfile2modelset(const char *filename, char **errmsg)
00630 {
00631 long len;
00632 char *text;
00633 seg_modelset_t *m;
00634 FILE *fp;
00635
00636 *errmsg = NULL;
00637 if ((fp = fopen(filename,"r")) == NULL) {
00638 *errmsg = "Could not open file for reading";
00639 return NULL;
00640 }
00641 fseek(fp, 0, SEEK_END);
00642 len = ftell(fp);
00643 rewind(fp);
00644 if ((text = calloc(len+1, 1)) == NULL) {
00645 *errmsg = "Insufficient memory to read named file";
00646 fclose(fp);
00647 return NULL;
00648 }
00649 if (fread(text, 1, len, fp) != len) {
00650 *errmsg = "Failed to read all of named file";
00651 fclose(fp);
00652 return NULL;
00653 }
00654 fclose(fp);
00655
00656 m = seg_text2modelset(text, errmsg);
00657 free(text);
00658 return m;
00659 }
00660
00661
00662
00663
00664
00665
00666
00667
00668 seg_modelset_t *
00669 seg_modelsetname2modelset(const char *name, char **errmsg, int enable_files)
00670 {
00671 seg_modelset_t *m;
00672 int i;
00673 struct stat BUF;
00674
00675 *errmsg = "";
00676 if (strstr(name, SEG_BUILTIN_PREFIX) == name) {
00677
00678 for (i = 0; (m = seg_models_known[i]) != NULL; i++) {
00679
00680 if (strcmp(name, m->name) == 0)
00681 return m;
00682 }
00683 *errmsg = "modelset given as builtin, but not found as builtin";
00684 return NULL;
00685 }
00686
00687 if (!enable_files) {
00688 m = NULL;
00689 *errmsg = "modelset not found as builtin";
00690 } else {
00691
00692 m = seg_modelfile2modelset(name, errmsg);
00693 }
00694 return m;
00695 }
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706 void
00707 seg_modelset_destroy(seg_modelset_t *m)
00708 {
00709 seg_onemodel_t *m1;
00710 int i;
00711
00712 if (!m) return;
00713
00714 if (strstr(m->name, SEG_BUILTIN_PREFIX) == m->name) return;
00715
00716 if (m->alpha)
00717 free(m->alpha);
00718
00719 for (i = 0; i < m->nclass; i++) {
00720 m1 = m->models+i;
00721 if (m1 && m1->params)
00722 free(m1->params);
00723 }
00724 free(m);
00725 }
00726
00727
00728
00729
00730
00731
00732
00733
00734 seg_modelset_t *
00735 seg_modelset_builtin(int i)
00736 {
00737 return seg_models_known[i];
00738 }
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750 int
00751 seg_modelname2modelnum(seg_modelset_t *modelset, char *modelname)
00752 {
00753 int class;
00754 seg_onemodel_t *m1;
00755
00756 for (class = 0; class < modelset->nclass; class++) {
00757 m1 = &(modelset->models[class]);
00758 if (strstr(m1->name, modelname) != 0)
00759 return class;
00760 }
00761 return -1;
00762 }
00763
00764
00765 #define SEG_FLFMT "%.4g "
00766
00767
00768
00769
00770
00771
00772 void
00773 seg_modelset_fprintf(FILE *fp, int verbose, seg_modelset_t *m)
00774 {
00775 int class, inx;
00776 int nbump, bump;
00777 double *params;
00778 seg_onemodel_t *m1;
00779
00780 fprintf(fp, "Name = <%s>.\n\tVersion = %s.\n\t%s\n",
00781 m->name, m->version, m->descrip);
00782 fprintf(fp, "\tModel set has %d components in %d dimensions.\n",
00783 m->nclass, m->ndim);
00784 if (verbose)
00785 fprintf(fp, "\tModel set uses vectorization format %s.\n", m->format);
00786 if (verbose) {
00787
00788 fprintf(fp, "\tParams listed in this order: "
00789 "wt, mu(B), mu(Ic), var(B), var(Ic), cov(B,Ic)\n");
00790 for (class = 0; class < m->nclass; class++) {
00791 m1 = &(m->models[class]);
00792 nbump = m1->k;
00793 params = m1->params;
00794 fprintf(fp, "\n\tFor %s:\n", m1->name);
00795 for (inx = bump = 0; bump < nbump; bump++, inx += 6) {
00796 fprintf(fp,
00797 "\t"
00798 SEG_FLFMT SEG_FLFMT SEG_FLFMT
00799 SEG_FLFMT SEG_FLFMT SEG_FLFMT
00800 "\n",
00801 params[inx+0],
00802 params[inx+1],
00803 params[inx+2],
00804 params[inx+3],
00805 params[inx+4],
00806 params[inx+5]);
00807 }
00808 }
00809 }
00810 }
00811
00812
00813
00814
00815
00816
00817 void
00818 seg_modelsets_fprintf(FILE *fp, int verbose)
00819 {
00820 int i;
00821 seg_modelset_t *m;
00822
00823 for (i = 0; seg_models_known[i] != NULL; i++) {
00824 m = seg_models_known[i];
00825 fprintf(fp, "\n");
00826 seg_modelset_fprintf(fp, verbose, m);
00827 }
00828 fprintf(fp, "\n");
00829 }
00830
00831
00832 #undef SEG_FLFMT
00833
00834