1, support Crystal,
authoryu.dongliang <18588496441@163.com>
Sun, 1 Jun 2025 14:18:07 +0000 (22:18 +0800)
committeryu.dongliang <18588496441@163.com>
Sun, 1 Jun 2025 14:18:12 +0000 (22:18 +0800)
2, add command line mode, get args from 'stdin' & print VA to 'stdout'

52 files changed:
Makefile
cpk/Makefile
cpk/crystal.c [new file with mode: 0644]
cpk/crystal.cpk [new file with mode: 0644]
cpk/op_amp_f007.cpk
cpk/ttl_adc.cpk
cpk/ttl_add.cpk
cpk/ttl_and.cpk
cpk/ttl_and2_or.cpk
cpk/ttl_dff.cpk
cpk/ttl_if.cpk
cpk/ttl_mla.cpk
cpk/ttl_nand.c
cpk/ttl_nand.cpk
cpk/ttl_nand4.c
cpk/ttl_nand4.cpk
cpk/ttl_nor.cpk
cpk/ttl_not.cpk
cpk/ttl_not_delay.cpk
cpk/ttl_or.cpk
cpk/ttl_xor.cpk
examples/astable_multivibrator.cpk
examples/colpitts_oscillator.cpk
examples/crystal_oscillator.cpk [new file with mode: 0644]
examples/pnp_oscillator.cpk
examples/sin_oscillator.cpk
main.c
scf_def.h
scf_eda_pack.c
scf_eda_pack.h
ses_core.h
ses_layout.c
ses_node_analysis.c
ses_path.c
ses_step_crystal.c [new file with mode: 0644]
ses_step_dc_diode.c
ses_step_dc_input.c
ses_step_dc_npn.c
ses_step_dc_pnp.c
ses_step_draw.c
ses_step_open.c
ses_step_output.c
ses_step_topo.c
ses_steps.c
ses_utils.c
test/LC_NAND.c [new file with mode: 0644]
test/Makefile
test/crystal.c [new file with mode: 0644]
test/crystal_NAND.c [new file with mode: 0644]
test/fft.c
test/test.c [deleted file]
test/v.txt [deleted file]

index d7d682186f2f130474385aef6b6351e86d1c9196..d6d3cbae23350154560002264acd7a40d70217cc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,8 @@ CFILES += ses_node_analysis.c
 
 CFILES += ses_steps.c
 CFILES += ses_step_battery.c
+CFILES += ses_step_crystal.c
+
 CFILES += ses_step_dc_input.c
 CFILES += ses_step_ac_input.c
 
index 8807f056995bc2981d9946cbac7ea1018b5cba36..634f1be838d3009c369504c7f2485a37eb19caa6 100644 (file)
@@ -12,6 +12,9 @@
 #CFILES += ttl_if.c
 #CFILES += ttl_d_flip_flop.c
 #CFILES += ttl_mla.c
+#CFILES += op_amp_f007.c
+CFILES += crystal.c
+
 #CFILES += ttl_mla_test.c
 #CFILES += ttl_if_test.c
 #CFILES += ttl_nand_test.c
 #CFILES += ttl_add_test.c
 #CFILES += ttl_adc_test.c
 #CFILES += ttl_ck_test.c
-#CFILES += add.c
-#CFILES += jk_gate.c
-#CFILES += jk_gate2.c
-#CFILES += rs_gate.c
 #CFILES += ttl_dff_test.c
 #CFILES += for_test.c
-#CFILES += add_gate.c
-#CFILES += adc_gate.c
-#CFILES += op_amp_741.c
-CFILES += op_amp_f007.c
 #CFILES += op_amp_test.c
 CFILES += ../scf_eda_pack.c
 CFILES += ../pack/scf_pack.c
diff --git a/cpk/crystal.c b/cpk/crystal.c
new file mode 100644 (file)
index 0000000..9543089
--- /dev/null
@@ -0,0 +1,47 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include"ses_core.h"
+
+int main(int argc, char* argv[])
+{
+       ScfEcomponent* Rs;
+       ScfEcomponent* Ls;
+       ScfEcomponent* Cs;
+
+       ScfEfunction*  f = scf_efunction__alloc("crystal.cpk");
+
+       EDA_INST_ADD_COMPONENT(f, Ls,  SCF_EDA_Inductor);
+       EDA_INST_ADD_COMPONENT(f, Cs,  SCF_EDA_Capacitor);
+
+       EDA_PIN_ADD_PIN(Ls, 0, Cs, 1);
+
+       Ls->r  = 5;
+       Ls->uh = 2546;
+       Cs->r  = 1;
+       Cs->uf = 0.09972e-6;
+
+       Ls->pins[1]->ic_lid = 1;
+       Cs->pins[0]->ic_lid = 0;
+
+       int ret = ses_layout_function(f, 100);
+       if (ret < 0)
+               return ret;
+
+       ses_draw(f, "crystal.png", f->x, f->y, f->w, f->h, 0, -1);
+
+       long     len = 0;
+       uint8_t* buf = NULL;
+
+       ScfEfunction_pack(f, &buf, &len);
+       ScfEfunction_free(f);
+       f = NULL;
+
+       FILE* fp = fopen("./crystal.cpk", "wb");
+       if (!fp)
+               return -EINVAL;
+
+       fwrite(buf, len, 1, fp);
+       fclose(fp);
+       return 0;
+}
diff --git a/cpk/crystal.cpk b/cpk/crystal.cpk
new file mode 100644 (file)
index 0000000..5b0821c
Binary files /dev/null and b/cpk/crystal.cpk differ
index 5fc9748e67971606c51be006b9effe1d5e973560..071e1239e4bd519daa82f748f927766581600934 100644 (file)
Binary files a/cpk/op_amp_f007.cpk and b/cpk/op_amp_f007.cpk differ
index 763b3b55041dd562260091d9b96fe1d32e91a884..8e75ada7221ed1fb66958d5d8988fe52a6ac1fb6 100644 (file)
Binary files a/cpk/ttl_adc.cpk and b/cpk/ttl_adc.cpk differ
index f51d3525c88f8568a4de6061964c62808e68a671..38d06a5f332a3da0bdf0f90dfa9a8ec2c4a40c90 100644 (file)
Binary files a/cpk/ttl_add.cpk and b/cpk/ttl_add.cpk differ
index e64b1828f2ca1ecaef084f287bc5569c8848ce68..60996aab8aa5b533eb56eafe7b07ea67cf326c4b 100644 (file)
Binary files a/cpk/ttl_and.cpk and b/cpk/ttl_and.cpk differ
index d13df3d3e2ca5a17cc0cb6bf3792a47f61ccb932..766cf696a6c68303e8523db9709e036734675b7b 100644 (file)
Binary files a/cpk/ttl_and2_or.cpk and b/cpk/ttl_and2_or.cpk differ
index b2d9cdebd2e261b68aa98f6df093c149e2b2f275..b76ad02b50762c862862f2003f83ee5614e0cd0c 100644 (file)
Binary files a/cpk/ttl_dff.cpk and b/cpk/ttl_dff.cpk differ
index 0f7da1735e4689c1df984f0b49a1564a03439901..68e0bab4b3ecd96299c4ecb447bcf0b7883c45cf 100644 (file)
Binary files a/cpk/ttl_if.cpk and b/cpk/ttl_if.cpk differ
index 7ea1d6a3cd91ab7599c60882309cbc90d9178db0..34423198c4d4cfbc68fca7c04e9978471c1c170b 100644 (file)
Binary files a/cpk/ttl_mla.cpk and b/cpk/ttl_mla.cpk differ
index a120be0e0d55866ec00545f6b4c69e482e257c27..dc2660da2ebc0b6f900ce8803a0448e12c881d75 100644 (file)
@@ -69,7 +69,7 @@ int main(int argc, char* argv[])
        R0->r = 4000;
        R1->r = 1600;
        R2->r = 130;
-       R3->r = 10 * 1000;
+       R3->r = 1000;
 
        R0->pins[1]->flags  = SCF_EDA_PIN_POS;
        R3->pins[0]->flags  = SCF_EDA_PIN_NEG;
index 9bfc9987c5ff2715114477af01c4495713c321bf..673236e0af0ecb63b240bf82c93507c6cf4aafbb 100644 (file)
Binary files a/cpk/ttl_nand.cpk and b/cpk/ttl_nand.cpk differ
index 60d613fdb5468025e8447c3497ba71c4de17537e..8cd784ee691e062f186c86ead855b0e244cc6c21 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char* argv[])
        R0->r = 4000;
        R1->r = 1600;
        R2->r = 130;
-       R3->r = 10 * 1000;
+       R3->r = 1000;
 
        R0->pins[1]->flags  = SCF_EDA_PIN_POS;
        R3->pins[0]->flags  = SCF_EDA_PIN_NEG;
index e6f60fc0836f5bef67c533e89d370bd9762c971c..d608e2e7953bc4c49960b7df603390e94290ef6f 100644 (file)
Binary files a/cpk/ttl_nand4.cpk and b/cpk/ttl_nand4.cpk differ
index cd7c79351ba6d97cc5baabf352677711e8117ee9..fe6baa24bcc012d3e9d572a6d945142f95c65e6b 100644 (file)
Binary files a/cpk/ttl_nor.cpk and b/cpk/ttl_nor.cpk differ
index 12595132196e70e77547b84a1ec8cd4ee9a31481..326fe4687a488ab0f0fb7c1fa8e6beaaf00ebddd 100644 (file)
Binary files a/cpk/ttl_not.cpk and b/cpk/ttl_not.cpk differ
index 4f52ff93f38771c7341fd40c39cc95072fbc7bc1..a08c29b2a14dc0cad84752c3720f5aae0103cd47 100644 (file)
Binary files a/cpk/ttl_not_delay.cpk and b/cpk/ttl_not_delay.cpk differ
index d3f4e4250e74406b098f13e8c2f9bd6bf22ef7e2..319d914da89923591d71cec88c5b186c792e9d97 100644 (file)
Binary files a/cpk/ttl_or.cpk and b/cpk/ttl_or.cpk differ
index fe1f6b95c7cd0b6cb2ac21d67db1114cc8ceea27..9ab82774a7dce55cc6491f506e0ae1442ea01c41 100644 (file)
Binary files a/cpk/ttl_xor.cpk and b/cpk/ttl_xor.cpk differ
index c47628b08b1bf4bd69e95b3bf82b89eaf89af98e..cbdd4190b0ac010d7a57e9c21b692e889e85411a 100644 (file)
Binary files a/examples/astable_multivibrator.cpk and b/examples/astable_multivibrator.cpk differ
index 9025e897fdcbef52840f5e7ae6e85b1995410449..f9f94c6b2d248ee5b11bdcc8615abcd0c40483fc 100644 (file)
Binary files a/examples/colpitts_oscillator.cpk and b/examples/colpitts_oscillator.cpk differ
diff --git a/examples/crystal_oscillator.cpk b/examples/crystal_oscillator.cpk
new file mode 100644 (file)
index 0000000..b1c5939
Binary files /dev/null and b/examples/crystal_oscillator.cpk differ
index 68f5366210c5dccaaab81499a6ed92f681511a39..63cc92c0509f116bab11b491a3ea7229ce23c33c 100644 (file)
Binary files a/examples/pnp_oscillator.cpk and b/examples/pnp_oscillator.cpk differ
index 8b028b9d79f48916697e149f558f29d1076a3caa..cb50e81c326585ba32cf6afcb3931ae8ded54f1c 100644 (file)
Binary files a/examples/sin_oscillator.cpk and b/examples/sin_oscillator.cpk differ
diff --git a/main.c b/main.c
index 9e27fbe026fa7562f2e459e7c0aee18ed26bcdd2..5b00d39db057bb9cc0b354de3a190724143f9793 100644 (file)
--- a/main.c
+++ b/main.c
@@ -186,21 +186,23 @@ int ses_draw_IC(ScfEcomponent* c)
 
 static void usage()
 {
-       printf("usage: ./ses [-l 0] [-f fname] [-t timeslice] [-c count] [-d 0] [-s Nth] [-n N] [-I IC] [-V \"v0, v1 - v2,...\"] [-A \"i1,i2c,...\"] src.cpk\n\n");
-       printf("-l: if need layout: 0 not, 1 layout, default is 1.\n");
-       printf("-f: function name in board\n");
-       printf("-t: time slice, such as 100ps, 100ns, 100us, 100ms.\n");
-       printf("-c: count of running times\n");
-       printf("-d: if draw graphs of circuit status: 0 not, 1 draw, default is 1.\n");
-       printf("-s: show from the Nth sample\n");
-       printf("-n: show when every N samples\n");
-       printf("-I: show the internal circuit graph of IC number\n");
-       printf("-V: save the voltage of lines      in 'v.txt', v1 - v2 means the diff voltage between line 1 and line 2.\n");
-       printf("-A: save the current of components in 'a.txt', i1 means the component with ID 1, i2c means the C pin of NPN or PNP with ID 2.\n");
-       printf("src.cpk: electronic model file to simulate\n\n");
+       fprintf(stderr, "usage: ./ses [-l 0] [-f fname] [-t timeslice] [-c count] [-d 0] [-s Nth] [-n N] [-I IC] [-V \"v0, v1 - v2,...\"] [-A \"i1,i2c,...\"] [-dc] src.cpk\n\n");
+       fprintf(stderr, "-l: if need layout: 0 not, 1 layout, default is 1.\n");
+       fprintf(stderr, "-f: function name in board\n");
+       fprintf(stderr, "-t: time slice, such as 100ps, 100ns, 100us, 100ms.\n");
+       fprintf(stderr, "-c: count of running times\n");
+       fprintf(stderr, "-d: if draw graphs of circuit status: 0 not, 1 draw, default is 1.\n");
+       fprintf(stderr, "-s: show from the Nth sample\n");
+       fprintf(stderr, "-n: show when every N samples\n");
+       fprintf(stderr, "-I: show the internal circuit graph of IC number\n");
+       fprintf(stderr, "-V: save the voltage of lines      in 'v.txt', v1 - v2 means the diff voltage between line 1 and line 2.\n");
+       fprintf(stderr, "-A: save the current of components in 'a.txt', i1 means the component with ID 1, i2c means the C pin of NPN or PNP with ID 2.\n");
+
+       fprintf(stderr, "-dc: run in DC mode, default is AC mode.\n");
+       fprintf(stderr, "src.cpk: electronic model file to simulate\n\n");
 }
 
-int main(int argc, char* argv[])
+int run(int argc, char* argv[])
 {
        if (argc < 2) {
                usage();
@@ -219,6 +221,7 @@ int main(int argc, char* argv[])
        int      draw   = 1;
        int      start  = 0;
        int      every  = 1;
+       int      dc     = 0;
 
        long i;
        long j;
@@ -287,6 +290,11 @@ int main(int argc, char* argv[])
                                        break;
 
                                case 'd':
+                                       if (3 == len && 'c' == argv[i][2]) {
+                                               dc = 1;
+                                               break;
+                                       }
+
                                        if (++i >= argc) {
                                                usage();
                                                return -EINVAL;
@@ -319,20 +327,22 @@ int main(int argc, char* argv[])
                                                return -EINVAL;
                                        }
 
-                                       ps = atol(argv[i]);
+                                       double __ps = atof(argv[i]);
 
                                        len = strlen(argv[i]);
 
                                        if (len > 2) {
                                                if (!strcmp(argv[i] + len - 2, "ns"))
-                                                       ps *= 1000LL;
+                                                       __ps *= 1e3;
 
                                                else if (!strcmp(argv[i] + len - 2, "us"))
-                                                       ps *= 1000LL * 1000LL;
+                                                       __ps *= 1e6;
 
                                                else if (!strcmp(argv[i] + len - 2, "ms"))
-                                                       ps *= 1000LL * 1000LL * 1000LL;
+                                                       __ps *= 1e9;
                                        }
+
+                                       ps = __ps;
                                        break;
                                default:
                                        break;
@@ -358,7 +368,7 @@ int main(int argc, char* argv[])
 
        long len = scf_pack_read(&buf, cpk);
        if (len < 0) {
-               scf_loge("scf_pack_read error: %ld\n", len);
+               scf_loge("scf_pack_read '%s' error: %ld\n", cpk, len);
                return len;
        }
 
@@ -393,7 +403,7 @@ int main(int argc, char* argv[])
                                return ret;
                        }
 
-                       scf_logi("c%ld, c->x: %d, c->y: %d, c->color: %ld\n", c->id, c->x, c->y, c->color);
+                       scf_logd("c%ld, c->x: %d, c->y: %d, c->color: %ld\n", c->id, c->x, c->y, c->color);
 
                        c->pf = f;
 
@@ -429,16 +439,17 @@ int main(int argc, char* argv[])
                ctx->N     = every;
                ctx->i     = 0;
                ctx->draw_flag = draw;
+               ctx->dc_flag   = dc;
 
                ret = 0;
                if (fname) {
                        if (!strcmp(f->name, fname)) {
-                               printf("f: %s\n", f->name);
+                               fprintf(stderr, "f: %s\n", f->name);
 
                                ret = ses_steps_analyse(b, f, ps, count, ctx);
                        }
                } else {
-                       printf("f: %s\n", f->name);
+                       fprintf(stderr, "f: %s\n", f->name);
 
                        ret = ses_steps_analyse(b, f, ps, count, ctx);
                }
@@ -455,3 +466,58 @@ int main(int argc, char* argv[])
        ScfEboard_free(b);
        return ret;
 }
+
+int main(int argc, char* argv[])
+{
+       if (argc >= 2)
+               return run(argc, argv);
+
+       long  ret = 0;
+       long  len = 0;
+       char* buf = NULL;
+       char* args[256];
+
+       usage();
+       printf("# ");
+
+       while ((ret = getline(&buf, &len, stdin)) != -1) {
+               char* p0 = buf;
+               char* p1 = p0;
+               int   i  = 0;
+
+               while (*p1) {
+                       if (' ' == *p1 || '\n' == *p1 || '\r' == *p1 || '\t' == *p1) {
+                               *p1 = '\0';
+
+                               if ('\0' == *p0) {
+                                       p0 = ++p1;
+                                       continue;
+                               }
+
+                               if (i >= sizeof(args) / sizeof(args[0])) {
+                                       scf_loge("args should not be more than 256.\n");
+                                       free(buf);
+                                       return -1;
+                               }
+
+                               args[i++] = p0;
+                               p0 = ++p1;
+                       } else
+                               ++p1;
+               }
+
+               ret = run(i, args);
+
+               free(buf);
+               buf = NULL;
+               len = 0;
+
+               if (ret < 0)
+                       return ret;
+
+               printf("# ");
+       }
+
+       free(buf);
+       return ret;
+}
index 55b1def0cdce3471b7196b3eb26fe0e2d2d573b7..2d891329edaad4e7e9958bc1f8152a249f8c5867 100644 (file)
--- a/scf_def.h
+++ b/scf_def.h
@@ -51,23 +51,14 @@ static inline uint64_t scf_zero_extend(uint64_t src, int src_bits)
        } while (0)
 
 #ifdef SCF_DEBUG
-#define scf_logd(fmt, ...) printf("%s(), %d, "fmt, __func__, __LINE__, ##__VA_ARGS__)
+#define scf_logd(fmt, ...) fprintf(stderr, "%s(), %d, "fmt, __func__, __LINE__, ##__VA_ARGS__)
 #else
 #define scf_logd(fmt, ...)
 #endif
 
-#define scf_logi(fmt, ...) printf("%s(), %d, info: "fmt, __func__, __LINE__, ##__VA_ARGS__)
+#define scf_logi(fmt, ...) fprintf(stderr, "%s(), %d, info: "fmt, __func__, __LINE__, ##__VA_ARGS__)
 
-#define scf_loge(fmt, ...) printf("%s(), %d, \033[31m error:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__)
-#define scf_logw(fmt, ...) printf("%s(), %d, \033[33m warning:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__)
-
-#define SCF_CHECK_ERROR(cond, ret, fmt, ...) \
-       do { \
-               if (cond) { \
-                       printf("%s(), %d, \033[31m error:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__); \
-                       return ret; \
-               } \
-       } while (0)
+#define scf_loge(fmt, ...) fprintf(stderr, "%s(), %d, \033[31m error:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__)
+#define scf_logw(fmt, ...) fprintf(stderr, "%s(), %d, \033[33m warning:\033[0m "fmt, __func__, __LINE__, ##__VA_ARGS__)
 
 #endif
-
index 98938475afc0e76018cb2130a81255720ec60953..c689c0e8fdbf56f83dd6da3a99fff76fd98b5f5b 100644 (file)
@@ -35,6 +35,7 @@ static int component_pins[SCF_EDA_Components_NB] =
        SCF_EDA_Signal_NB,
 
        SCF_EDA_OP_AMP_NB,
+       2, // crystal oscillator
 };
 
 static int __diode_path_off(ScfEpin* p0, ScfEpin* p1, int flags)
@@ -416,50 +417,52 @@ static ScfEops __741_op_amp_ops =
 
 static ScfEdata  component_datas[] =
 {
-       {SCF_EDA_None,       0,                   0, 0, 0,    0,   0,   0, 0, NULL, NULL, NULL},
-       {SCF_EDA_Battery,    0,                   0, 0, 0, 1e-9, 1e9,   0, 0, NULL, NULL, NULL},
-       {SCF_EDA_Signal,     0,                   0, 0, 0, 1e-9, 1e9,   0, 0, NULL, NULL, NULL},
-
-       {SCF_EDA_Resistor,   0,                   0, 0, 0,  1e4,   0,   0, 0, NULL, NULL, NULL},
-       {SCF_EDA_Capacitor,  0,                   0, 0, 0,   10, 0.1,   0, 0, NULL, NULL, NULL},
-       {SCF_EDA_Inductor,   0,                   0, 0, 0,   10,   0, 1e3, 0, NULL, NULL, NULL},
-
-       {SCF_EDA_Diode,      0,                   0, 0, 0,    0,   0,   0, 0, &__diode_ops, NULL, "./cpk/9013.txt"},
-       {SCF_EDA_NPN,        0,                   0, 0, 0,    0,   0,   0, 0, &__npn_ops,   NULL, "./cpk/9013.txt"},
-       {SCF_EDA_PNP,        0,                   0, 0, 0,    0,   0,   0, 0, &__pnp_ops,   NULL, "./cpk/9012.txt"},
-
-       {SCF_EDA_NAND,       0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_nand_ops, "./cpk/ttl_nand.cpk", NULL},
-       {SCF_EDA_NOT,        0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_not_ops,  "./cpk/ttl_not.cpk",  NULL},
-       {SCF_EDA_AND,        0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_gate_ops, "./cpk/ttl_and.cpk",  NULL},
-       {SCF_EDA_OR,         0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_gate_ops, "./cpk/ttl_or.cpk",   NULL},
-       {SCF_EDA_NOR,        0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_gate_ops, "./cpk/ttl_nor.cpk",  NULL},
-       {SCF_EDA_XOR,        0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_gate_ops, "./cpk/ttl_xor.cpk",  NULL},
-       {SCF_EDA_DFF,        0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_gate_ops, "./cpk/ttl_dff.cpk",  NULL},
-
-       {SCF_EDA_ADD,        0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_add_ops,  "./cpk/ttl_add.cpk",  NULL},
-       {SCF_EDA_ADC,        0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_adc_ops,  "./cpk/ttl_adc.cpk",  NULL},
-
-       {SCF_EDA_NAND4,      0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_nand4_ops,   "./cpk/ttl_nand4.cpk",   NULL},
-       {SCF_EDA_AND2_OR,    0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_and2_or_ops, "./cpk/ttl_and2_or.cpk", NULL},
-       {SCF_EDA_IF,         0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_if_ops,      "./cpk/ttl_if.cpk",      NULL},
-       {SCF_EDA_MLA,        0,                   0, 0, 0,    0,   0,   0, 0, &__ttl_mla_ops,     "./cpk/ttl_mla.cpk",     NULL},
-
-       {SCF_EDA_NOT,        SCF_EDA_TTL_DELAY,   0, 0, 0,    0,   0,   0, 0, &__ttl_not_ops,     "./cpk/ttl_not_delay.cpk", NULL},
-
-       {SCF_EDA_OP_AMP,     0,                   0, 0, 0,    0,   0,   0, 0, &__741_op_amp_ops, "./cpk/op_amp_f007.cpk",   NULL},
+       {SCF_EDA_None,       0,                   0, 0, 0,    0,   0,   0, 0, 0,   NULL, NULL, NULL},
+       {SCF_EDA_Battery,    0,                   0, 0, 0, 1e-9, 1e9,   0, 0, 0,   NULL, NULL, NULL},
+       {SCF_EDA_Signal,     0,                   0, 0, 0, 1e-9, 1e9,   0, 0, 0,   NULL, NULL, NULL},
+                                                                             
+       {SCF_EDA_Resistor,   0,                   0, 0, 0,  1e4,   0,   0, 0, 0,   NULL, NULL, NULL},
+       {SCF_EDA_Capacitor,  0,                   0, 0, 0,   10, 0.1,   0, 0, 0,   NULL, NULL, NULL},
+       {SCF_EDA_Inductor,   0,                   0, 0, 0,   10,   0, 1e3, 0, 0,   NULL, NULL, NULL},
+                                                                             
+       {SCF_EDA_Diode,      0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__diode_ops, NULL, "./cpk/9013.txt"},
+       {SCF_EDA_NPN,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__npn_ops,   NULL, "./cpk/9013.txt"},
+       {SCF_EDA_PNP,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__pnp_ops,   NULL, "./cpk/9012.txt"},
+                                                                             
+       {SCF_EDA_NAND,       0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_nand_ops, "./cpk/ttl_nand.cpk", NULL},
+       {SCF_EDA_NOT,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_not_ops,  "./cpk/ttl_not.cpk",  NULL},
+       {SCF_EDA_AND,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_gate_ops, "./cpk/ttl_and.cpk",  NULL},
+       {SCF_EDA_OR,         0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_gate_ops, "./cpk/ttl_or.cpk",   NULL},
+       {SCF_EDA_NOR,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_gate_ops, "./cpk/ttl_nor.cpk",  NULL},
+       {SCF_EDA_XOR,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_gate_ops, "./cpk/ttl_xor.cpk",  NULL},
+       {SCF_EDA_DFF,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_gate_ops, "./cpk/ttl_dff.cpk",  NULL},
+                                                                             
+       {SCF_EDA_ADD,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_add_ops,  "./cpk/ttl_add.cpk",  NULL},
+       {SCF_EDA_ADC,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_adc_ops,  "./cpk/ttl_adc.cpk",  NULL},
+                                                                             
+       {SCF_EDA_NAND4,      0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_nand4_ops,   "./cpk/ttl_nand4.cpk",   NULL},
+       {SCF_EDA_AND2_OR,    0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_and2_or_ops, "./cpk/ttl_and2_or.cpk", NULL},
+       {SCF_EDA_IF,         0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_if_ops,      "./cpk/ttl_if.cpk",      NULL},
+       {SCF_EDA_MLA,        0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_mla_ops,     "./cpk/ttl_mla.cpk",     NULL},
+                                                                             
+       {SCF_EDA_NOT,        SCF_EDA_TTL_DELAY,   0, 0, 0,    0,   0,   0, 0, 0,   &__ttl_not_ops,     "./cpk/ttl_not_delay.cpk", NULL},
+                                                                             
+       {SCF_EDA_OP_AMP,     0,                   0, 0, 0,    0,   0,   0, 0, 0,   &__741_op_amp_ops, "./cpk/op_amp_f007.cpk",   NULL},
+                                                                             
+       {SCF_EDA_Crystal,    0,                   0, 0, 0,    0,   0,   0, 0, 1e7, NULL,              "./cpk/crystal.cpk",       NULL},
 };
 
 static ScfEdata  pin_datas[] =
 {
-       {SCF_EDA_None,       0,                   0, 0, 0,    0,   0,   0,   0, NULL, NULL, NULL},
+       {SCF_EDA_None,       0,                   0, 0, 0,    0,   0,   0,   0, 0, NULL, NULL, NULL},
 
-       {SCF_EDA_Diode,      0,   SCF_EDA_Diode_NEG, 0, 0,  750,   0,   0,   0, NULL, NULL, NULL},
+       {SCF_EDA_Diode,      0,   SCF_EDA_Diode_NEG, 0, 0,  750,   0,   0,   0, 0, NULL, NULL, NULL},
 
-       {SCF_EDA_NPN,        0,       SCF_EDA_NPN_B, 0, 0,  750,   0,   0,   0, NULL, NULL, NULL},
-       {SCF_EDA_NPN,        0,       SCF_EDA_NPN_C, 0, 0,    3,   0,   0, 200, NULL, NULL, NULL},
+       {SCF_EDA_NPN,        0,       SCF_EDA_NPN_B, 0, 0,  750,   0,   0,   0, 0, NULL, NULL, NULL},
+       {SCF_EDA_NPN,        0,       SCF_EDA_NPN_C, 0, 0,    3,   0,   0, 200, 0, NULL, NULL, NULL},
 
-       {SCF_EDA_PNP,        0,       SCF_EDA_PNP_B, 0, 0,  750,   0,   0,   0, NULL, NULL, NULL},
-       {SCF_EDA_PNP,        0,       SCF_EDA_PNP_C, 0, 0,    3,   0,   0, 200, NULL, NULL, NULL},
+       {SCF_EDA_PNP,        0,       SCF_EDA_PNP_B, 0, 0,  750,   0,   0,   0, 0, NULL, NULL, NULL},
+       {SCF_EDA_PNP,        0,       SCF_EDA_PNP_C, 0, 0,    3,   0,   0, 200, 0, NULL, NULL, NULL},
 };
 
 static ScfEdata* _pin_find_data(const uint64_t type, const uint64_t model, const uint64_t pid)
@@ -796,6 +799,7 @@ ScfEcomponent* scf_ecomponent__alloc(uint64_t type)
                c->r   = ed->r;
                c->uf  = ed->uf;
                c->uh  = ed->uh;
+               c->Hz  = ed->Hz;
                c->ops = ed->ops;
        }
 
index e54420fb62fe014f489a4d2d0bbf47a932bc3baa..3e2c02780d4a1fdbb383f9622035a5caab2693ca 100644 (file)
@@ -38,6 +38,8 @@ enum {
 
        SCF_EDA_OP_AMP,
 
+       SCF_EDA_Crystal,
+
        SCF_EDA_Components_NB,
 };
 
@@ -288,6 +290,7 @@ typedef struct {
        double    uf;
        double    uh;
        double    hfe;
+       double    Hz;
 
        void*     ops;
        char*     cpk;
@@ -480,6 +483,8 @@ struct scf_ecomponent_s
        SCF_PACK_DEF_VAR(double, uf);
        SCF_PACK_DEF_VAR(double, uh);
 
+       SCF_PACK_DEF_VAR(double, Hz);
+
        SCF_PACK_DEF_VAR(int64_t, mirror_id);
 
        SCF_PACK_DEF_VAR(int64_t, count);
@@ -509,6 +514,7 @@ SCF_PACK_INFO_VAR(ScfEcomponent, dr),
 SCF_PACK_INFO_VAR(ScfEcomponent, r),
 SCF_PACK_INFO_VAR(ScfEcomponent, uf),
 SCF_PACK_INFO_VAR(ScfEcomponent, uh),
+SCF_PACK_INFO_VAR(ScfEcomponent, Hz),
 
 SCF_PACK_INFO_VAR(ScfEcomponent, mirror_id),
 
index 01401a1042f64eab84c7435fb64c6d94bac8c1b1..412a08363e094c801a6c38137527835833205e29 100644 (file)
@@ -111,15 +111,14 @@ struct ses_ctx_s
        char*          Vshow;
        char*          Ashow;
 
-       FILE*          Vfp;
-       FILE*          Afp;
-
        int            changed;
 
        int            start;
        int            N;
        int            i;
+
        uint8_t        draw_flag:1;
+       uint8_t        dc_flag:1;
 };
 
 struct ses_step_s
index 32ba8856074dd345f9df74390a6cf070de7374d4..62402d3ec1aa91b455c8d43fdea27789d09f9ab6 100644 (file)
@@ -159,7 +159,7 @@ int ses_layout_board(ScfEboard* b, int d)
        for (i = 0; i < b->n_functions; i++) {
                f  =        b->functions[i];
 
-               printf("f: %s\n", f->name);
+               fprintf(stderr, "f: %s\n", f->name);
 
                int ret = ses_layout_function(f, d);
                if (ret < 0) {
index 830b5e80ee9a6ce6aa264d4c546626dbaa0e5271..b9328ada17a497ff2bd5cb34a08bf256471071dd 100644 (file)
@@ -267,20 +267,20 @@ static void ses_AbX_print(double* A, double* b, double* X, int N)
        int i;
        int j;
 
-       printf("A:\n");
+       fprintf(stderr, "A:\n");
        for (i = 0; i < N; i++) {
                for (j = 0; j < N; j++)
-                       printf("%3lg ", A[i * N + j]);
-               printf("\n");
+                       fprintf(stderr, "%3lg ", A[i * N + j]);
+               fprintf(stderr, "\n");
        }
 
-       printf("\nb:\n");
+       fprintf(stderr, "\nb:\n");
        for (j = 0; j < N; j++)
-               printf("%lg\n", b[j]);
+               fprintf(stderr, "%lg\n", b[j]);
 
-       printf("\nX:\n");
+       fprintf(stderr, "\nX:\n");
        for (j = 0; j < N; j++)
-               printf("%lg\n", X[j]);
+               fprintf(stderr, "%lg\n", X[j]);
 }
 
 /*
@@ -375,6 +375,15 @@ static void __ses_nodes_set_Ab(ScfEfunction* f, scf_vector_t* nodes, scf_vector_
                edge->r = r;
 
                scf_logd("c%ldp%ld-c%ldp%ld, r: %lg, cv: %lg, uh: %lg, la: %lg, edge->index: %d\n", p0->cid, p0->id, p1->cid, p1->id, r, cv, uh, la, edge->index);
+
+               if (edge->edge_b) {
+                       edge->amplify_flag = 1;
+
+                       A[(n + edge->index) * N + n + edge->index]         = -1;
+                       A[(n + edge->index) * N + n + edge->edge_b->index] = edge->hfe;
+                       b[ n + edge->index] = 0;
+                       continue;
+               }
 /* dv = idt / C
     v = Ldi/dt
    v0 - v1 - ir = cv + idt/C + Ldi/dt
@@ -496,7 +505,7 @@ static int __ses_edges_inverse_off(ScfEfunction* f, scf_vector_t* edges, double*
 #if 1
                                scf_logi("\033[31medge: [%d], ", edge->index);
                                ses_pin_print(p0);
-                               printf("status: %d, dV: %lg, Vb: %lg, Ve: %lg, Ib: %lg\033[0m\n", c->status, dV, Vb, Ve, Ib);
+                               fprintf(stderr, "status: %d, dV: %lg, Vb: %lg, Ve: %lg, Ib: %lg\033[0m\n", c->status, dV, Vb, Ve, Ib);
 #endif
                        }
                } else if (dV > SCF_EDA_V_Diode_OFF) {
@@ -520,7 +529,7 @@ static int __ses_edges_inverse_off(ScfEfunction* f, scf_vector_t* edges, double*
 #if 1
                                scf_logi("\033[32medge: [%d], ", edge->index);
                                ses_pin_print(p0);
-                               printf("status: %d, dV: %lg, Vb: %lg, Ve: %lg, Ib: %lg\033[0m\n", c->status, dV, Vb, Ve, Ib);
+                               fprintf(stderr, "status: %d, dV: %lg, Vb: %lg, Ve: %lg, Ib: %lg\033[0m\n", c->status, dV, Vb, Ve, Ib);
 #endif
                                k++;
                        }
@@ -584,7 +593,7 @@ static int __ses_edges_update_Ab(ScfEfunction* f, scf_vector_t* edges, double* A
 #if 1
                                        scf_logi("edge: [%d], ", edge->index);
                                        ses_pin_print(p0);
-                                       printf("status: %d, dV: %lg, Vb: %lg, Ve: %lg, V: %lg, Ib: %lg, Rb: %lg\n", c->status, dV, Vb, Ve, V, Ib, Rb);
+                                       fprintf(stderr, "status: %d, dV: %lg, Vb: %lg, Ve: %lg, V: %lg, Ib: %lg, Rb: %lg\n", c->status, dV, Vb, Ve, V, Ib, Rb);
 #endif
                                        A[(n + edge->index) * N + n + edge->index] = -Rb;
                                        b[ n + edge->index] += 0;
@@ -593,7 +602,7 @@ static int __ses_edges_update_Ab(ScfEfunction* f, scf_vector_t* edges, double* A
 #if 0
                                        scf_logi("edge: [%d], ", edge->index);
                                        ses_pin_print(p0);
-                                       printf("status: %d, dV: %lg, Vb: %lg, Ve: %lg, V: %lg, Ib: %lg, Rb: %lg\n", c->status, dV, Vb, Ve, V, Ib, Rb);
+                                       fprintf(stderr, "status: %d, dV: %lg, Vb: %lg, Ve: %lg, V: %lg, Ib: %lg, Rb: %lg\n", c->status, dV, Vb, Ve, V, Ib, Rb);
 #endif
                                }
                        } else {
@@ -607,44 +616,8 @@ static int __ses_edges_update_Ab(ScfEfunction* f, scf_vector_t* edges, double* A
 #if 0
                                scf_logi("\033[34medge: [%d], ", edge->index);
                                ses_pin_print(p0);
-                               printf("status: %d, dV: %lg, Vb: %lg, Ve: %lg, V: %lg, Ib: %lg, Rb: %lg\033[0m\n", c->status, dV, Vb, Ve, V, Ib, Rb);
-#endif
-                       }
-
-               } else if (edge->edge_b) {
-                       double Ic = X[n + edge->index];
-                       double Ib = X[n + edge->edge_b->index];
-                       double Vc = Vb;
-
-                       if (edge->edge_b->node1 && !edge->edge_b->node1->el->vconst)
-                               Vb = X[edge->edge_b->node1->index];
-                       else {
-                               p  = edge->edge_b->path->pins->data[edge->edge_b->vip_m];
-                               Vb = ses_top_pline(p)->v;
-                       }
-
-                       double dI = Ib * edge->hfe - Ic;
-                       double V  = SCF_EDA_V_NPN_ON;
-                       double Rb = V / Ib;
-#if 1
-                       if (c->curves && c->n_curves > 0) {
-                               __ses_Vb_by_curve(c, Ib, &V);
-                               __ses_Vb_by_curve(c, V,  &V);
-                               Rb = V / Ib;
-                       }
+                               fprintf(stderr, "status: %d, dV: %lg, Vb: %lg, Ve: %lg, V: %lg, Ib: %lg, Rb: %lg\033[0m\n", c->status, dV, Vb, Ve, V, Ib, Rb);
 #endif
-                       if (dI < -1e-10 && -1e8 < Rb && Rb < 1e8) {
-                               if (!edge->amplify_flag) {
-                                       edge->amplify_flag = 1;
-
-                                       for (i = 0; i < N; i++)
-                                               A[(n + edge->index) * N + i] = 0;
-
-                                       A[(n + edge->index) * N + n + edge->index]         = -1;
-                                       A[(n + edge->index) * N + n + edge->edge_b->index] = edge->hfe;
-                                       b[ n + edge->index] = 0;
-                                       k++;
-                               }
                        }
                }
        }
@@ -673,7 +646,7 @@ static void ses_edge_hfe_print(ses_edge_t* edge, double hfe, double* X, int n, d
        scf_logi("\033[33medge: [%d], ", edge->index);
        ses_pin_print(p0);
        ses_pin_print(p1);
-       printf("Vc: %lg, Ve: %lg, Vce: %lg, Ic: %lg, hfe: %lg, alpha: %lg\033[0m\n", Vc, Ve, Vc - Ve, Ic, hfe, alpha);
+       fprintf(stderr, "Vc: %lg, Ve: %lg, Vce: %lg, Ic: %lg, hfe: %lg, alpha: %lg\033[0m\n", Vc, Ve, Vc - Ve, Ic, hfe, alpha);
 }
 
 static int __edge_update_hfe(ses_edge_t* edge, double* A, double* X, int N, int n, double alpha)
@@ -703,7 +676,7 @@ static int __edge_update_hfe(ses_edge_t* edge, double* A, double* X, int N, int
                }
 
                if (k > 0)
-                       printf("\n");
+                       fprintf(stderr, "\n");
        }
        return k;
 }
@@ -858,7 +831,7 @@ static int __ses_nodes_update_vmax(ScfEfunction* f, scf_vector_t* nodes, double*
                scf_logi("\033[31medge: [%d], ", edge->index);
                ses_pin_print(p0);
                ses_pin_print(p1);
-               printf("Vmax: %lg\033[0m\n", Vmax);
+               fprintf(stderr, "Vmax: %lg\033[0m\n", Vmax);
        }
 
        __ses_gsl_solve(A, N);
@@ -983,7 +956,7 @@ static int __ses_nodes_solve(ScfEfunction* f, scf_vector_t* nodes, scf_vector_t*
                try++;
        } while (ret > 0 && try < MAX_TRYS);
 
-       __ses_nodes_update_vmax(f, nodes, A, b, X, N, n);
+//     __ses_nodes_update_vmax(f, nodes, A, b, X, N, n);
 
        if (try >= MAX_TRYS)
                scf_loge("try: %d\n\n", try);
@@ -1011,13 +984,13 @@ static int __ses_nodes_solve(ScfEfunction* f, scf_vector_t* nodes, scf_vector_t*
                edge->a = X[n + edge->index];
 #if 1
                if (edge->a < -1e-4)
-                       printf("\033[36m");
+                       fprintf(stderr, "\033[36m");
                ses_pin_print(p0);
                ses_pin_print(p1);
                if (edge->a < -1e-4)
-                       printf(", v: %lg, %lg, a: %lg, edge->index: %d\033[0m\n", p0->v, p1->v, edge->a, edge->index);
+                       fprintf(stderr, ", v: %lg, %lg, a: %lg, edge->index: %d\033[0m\n", p0->v, p1->v, edge->a, edge->index);
                else
-                       printf(", v: %lg, %lg, a: %lg, edge->index: %d\n", p0->v, p1->v, edge->a, edge->index);
+                       fprintf(stderr, ", v: %lg, %lg, a: %lg, edge->index: %d\n", p0->v, p1->v, edge->a, edge->index);
 #endif
                if (SCF_EDA_NPN == c->type) {
                        if (SCF_EDA_NPN_B == p0->id
@@ -1065,10 +1038,17 @@ static int __ses_nodes_solve(ScfEfunction* f, scf_vector_t* nodes, scf_vector_t*
 
                        c->v = (edge->a * sign - c->a) * c->uh * 1000000.0 / ps;
 
+                       if (c->pf->IC && SCF_EDA_Crystal == c->pf->IC->type)
+                               c->pf->IC->v += c->v;
+
                } else if (SCF_EDA_Capacitor == c->type) {
 
-//                     if (!c->pf->IC || SCF_EDA_OP_AMP != c->pf->IC->type)
-                               c->v += edge->a * sign * ps / 1000000.0 / c->uf;
+                       c->v += edge->a * sign * ps / 1000000.0 / c->uf;
+
+                       if (c->pf->IC && SCF_EDA_Crystal == c->pf->IC->type) {
+                               c->pf->IC->a  = edge->a * sign;
+                               c->pf->IC->v += c->v;
+                       }
                }
 
                c->a  = edge->a * sign;
index da24a7a960e7203f05d501671cfc637b101754f9..619873284dadcb93cae4306b1b2958ea2026b7be 100644 (file)
@@ -56,30 +56,30 @@ void ses_IC_print(ScfEcomponent* IC)
 
        switch (IC->type) {
                case SCF_EDA_NAND:
-                       printf("Nand%ld_", IC->id);
+                       fprintf(stderr, "Nand%ld_", IC->id);
                        break;
                case SCF_EDA_NOR:
-                       printf("Nor%ld_", IC->id);
+                       fprintf(stderr, "Nor%ld_", IC->id);
                        break;
 
                case SCF_EDA_NOT:
-                       printf("Not%ld_", IC->id);
+                       fprintf(stderr, "Not%ld_", IC->id);
                        break;
                case SCF_EDA_AND:
-                       printf("And%ld_", IC->id);
+                       fprintf(stderr, "And%ld_", IC->id);
                        break;
                case SCF_EDA_OR:
-                       printf("Or%ld_", IC->id);
+                       fprintf(stderr, "Or%ld_", IC->id);
                        break;
 
                case SCF_EDA_XOR:
-                       printf("Xor%ld_", IC->id);
+                       fprintf(stderr, "Xor%ld_", IC->id);
                        break;
                case SCF_EDA_ADD:
-                       printf("Add%ld_", IC->id);
+                       fprintf(stderr, "Add%ld_", IC->id);
                        break;
                default:
-                       printf("IC%ld_", IC->id);
+                       fprintf(stderr, "IC%ld_", IC->id);
                        break;
        };
 }
@@ -90,32 +90,32 @@ void ses_pin_print(ScfEpin* p)
 
        switch (p->c->type) {
                case SCF_EDA_Resistor:
-                       printf("R%ldp%ld ", p->cid, p->id);
+                       fprintf(stderr, "R%ldp%ld ", p->cid, p->id);
                        break;
 
                case SCF_EDA_Capacitor:
-                       printf("C%ldp%ld ", p->cid, p->id);
+                       fprintf(stderr, "C%ldp%ld ", p->cid, p->id);
                        break;
 
                case SCF_EDA_Inductor:
-                       printf("L%ldp%ld ", p->cid, p->id);
+                       fprintf(stderr, "L%ldp%ld ", p->cid, p->id);
                        break;
 
                case SCF_EDA_Diode:
-                       printf("D%ldp%ld ", p->cid, p->id);
+                       fprintf(stderr, "D%ldp%ld ", p->cid, p->id);
                        break;
 
                case SCF_EDA_NPN:
                case SCF_EDA_PNP:
                        if (SCF_EDA_NPN_B == p->id)
-                               printf("T%ldb  ", p->cid);
+                               fprintf(stderr, "T%ldb  ", p->cid);
                        else if (SCF_EDA_NPN_C == p->id)
-                               printf("T%ldc  ", p->cid);
+                               fprintf(stderr, "T%ldc  ", p->cid);
                        else
-                               printf("T%lde  ", p->cid);
+                               fprintf(stderr, "T%lde  ", p->cid);
                        break;
                default:
-                       printf("c%ldp%ld ", p->cid, p->id);
+                       fprintf(stderr, "c%ldp%ld ", p->cid, p->id);
                        break;
        };
 }
@@ -130,7 +130,7 @@ void ses_path_print(ses_path_t* path)
        int i;
 
        if (!path->parent)
-               printf("\033[31mpath  : %d, n_diodes: %d, n_NPNs: %d, n_PNPs: %d, n_capacitors: %d, n_transistors: %d, \033[0m\n",
+               fprintf(stderr, "\033[31mpath  : %d, n_diodes: %d, n_NPNs: %d, n_PNPs: %d, n_capacitors: %d, n_transistors: %d, \033[0m\n",
                                path->index, path->n_diodes, path->n_NPNs, path->n_PNPs, path->n_capacitors, path->n_transistors);
 
        for (i = 0; i < path->pins->size; i++) {
@@ -138,20 +138,20 @@ void ses_path_print(ses_path_t* path)
 
                ses_pin_print(p);
        }
-       printf("\n");
+       fprintf(stderr, "\n");
 
        if (path->connections) {
                for (i = 0; i < path->connections->size; i++) {
                        child     = path->connections->data[i];
 
                        if (child->parent == path) {
-                               printf("\n");
-                               printf("\033[34mconnection: %d, n_diodes: %d, n_NPNs: %d, n_PNPs: %d, n_capacitors: %d, n_transistors: %d, parent: %d, \033[0m\n",
+                               fprintf(stderr, "\n");
+                               fprintf(stderr, "\033[34mconnection: %d, n_diodes: %d, n_NPNs: %d, n_PNPs: %d, n_capacitors: %d, n_transistors: %d, parent: %d, \033[0m\n",
                                                child->index, child->n_diodes, child->n_NPNs, child->n_PNPs, child->n_capacitors, child->n_transistors, path->index);
 
                                ses_path_print(child);
                        } else
-                               printf("\033[34mconnection: %d\033[0m\n", child->index);
+                               fprintf(stderr, "\033[34mconnection: %d\033[0m\n", child->index);
                }
        }
 
@@ -159,8 +159,8 @@ void ses_path_print(ses_path_t* path)
                for (i = 0; i < path->childs->size; i++) {
                        child     = path->childs->data[i];
 
-                       printf("\n");
-                       printf("\033[32mchild : %d, n_diodes: %d, n_NPNs: %d, n_PNPs: %d, n_capacitors: %d, n_transistors: %d, parent: %d, \033[0m\n",
+                       fprintf(stderr, "\n");
+                       fprintf(stderr, "\033[32mchild : %d, n_diodes: %d, n_NPNs: %d, n_PNPs: %d, n_capacitors: %d, n_transistors: %d, parent: %d, \033[0m\n",
                                        child->index, child->n_diodes, child->n_NPNs, child->n_PNPs, child->n_capacitors, child->n_transistors, path->index);
 
                        ses_path_print(child);
@@ -171,8 +171,8 @@ void ses_path_print(ses_path_t* path)
                for (i = 0; i < path->bridges->size; i++) {
                        child     = path->bridges->data[i];
 
-                       printf("\n");
-                       printf("\033[33mbridge: %d, n_diodes: %d, n_NPNs: %d, n_PNPs: %d, n_capacitors: %d, n_transistors: %d, parent: %d, \033[0m\n",
+                       fprintf(stderr, "\n");
+                       fprintf(stderr, "\033[33mbridge: %d, n_diodes: %d, n_NPNs: %d, n_PNPs: %d, n_capacitors: %d, n_transistors: %d, parent: %d, \033[0m\n",
                                        child->index, child->n_diodes, child->n_NPNs, child->n_PNPs, child->n_capacitors, child->n_transistors, path->index);
 
                        ses_path_print(child);
@@ -189,7 +189,7 @@ void ses_paths_print(scf_vector_t* paths)
                path      = paths->data[i];
 
                ses_path_print(path);
-               printf("------------------------\n");
+               fprintf(stderr, "------------------------\n");
        }
 }
 
diff --git a/ses_step_crystal.c b/ses_step_crystal.c
new file mode 100644 (file)
index 0000000..200fc7e
--- /dev/null
@@ -0,0 +1,55 @@
+#include"ses_core.h"
+
+static int __crystal_Hz(ScfEfunction* f)
+{
+       ScfEcomponent*  c;
+
+       long i;
+       long j;
+       for (i = 0; i < f->n_components; i++) {
+               c  =        f->components[i];
+
+               if (SCF_EDA_Crystal == c->type) {
+                       assert(c->f);
+
+                       ScfEcomponent*  Ls = NULL;
+                       ScfEcomponent*  Cs = NULL;
+                       ScfEcomponent*  c2;
+
+                       for (j = 0; j < c->f->n_components; j++) {
+                               c2 =        c->f->components[j];
+
+                               if (SCF_EDA_Capacitor == c2->type)
+                                       Cs = c2;
+                               else if (SCF_EDA_Inductor == c2->type)
+                                       Ls = c2;
+                       }
+
+                       double T = 1.0 / (2.0 * 3.1415926 * c->Hz);
+
+                       Ls->uh = T * T / Cs->uf * 1e12;
+                       scf_logi("Ls->uh: %lg, Cs->uf: %lg, c->Hz: %lg\n", Ls->uh, Cs->uf, c->Hz);
+                       continue;
+               }
+
+               if (c->f) {
+                       int ret = __crystal_Hz(c->f);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
+
+static int _crystal_handler(ScfEfunction* f, int64_t ps, int64_t count, ses_ctx_t* ctx)
+{
+       return __crystal_Hz(f);
+}
+
+ses_step_t   ses_step_crystal =
+{
+       .name    = "crystal",
+
+       .handler = _crystal_handler,
+};
index 10531424413caef9bf00454cb8bbf6467c4702e3..f1b10dbe4c7c9fa2aa60c9f8585e90b1c97a7764 100644 (file)
@@ -1,6 +1,6 @@
 #include"ses_core.h"
 
-static int __dc_diode_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, ScfEline* LN)
+static int __dc_diode_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, ScfEline* LN, ses_ctx_t* ctx)
 {
        ScfEcomponent* c;
        ScfEpin*       pb;
@@ -13,7 +13,7 @@ static int __dc_diode_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP,
                c  =        f->components[i];
 
                if (c->f) {
-                       int ret = __dc_diode_status(root, c->f, LP, LN);
+                       int ret = __dc_diode_status(root, c->f, LP, LN, ctx);
                        if (ret < 0)
                                return ret;
 
@@ -32,7 +32,7 @@ static int __dc_diode_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP,
                if (lb == LP && le == LN) {
                        scf_loge("short connected, ");
                        ses_pin_print(pb);
-                       printf("\n");
+                       fprintf(stderr, "\n");
                        return -EINVAL;
                }
 
@@ -88,7 +88,8 @@ static int __dc_diode_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP,
                }
 
 check:
-               if ((c->pf->IC && SCF_EDA_OP_AMP == c->pf->IC->type)
+               if (!ctx->dc_flag
+                               || (c->pf->IC && SCF_EDA_OP_AMP == c->pf->IC->type)
                                || pe->v >= LP->v - SCF_EDA_V_NPN_OFF
                                || pb->v <= LN->v + SCF_EDA_V_NPN_OFF) {
                        c->lock   = 0;
@@ -97,7 +98,7 @@ check:
 
                scf_logi("\033[34m status: %d, lock: %d, ", c->status, c->lock);
                ses_pin_print(pb);
-               printf("pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\033[0m\n", pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_Diode_OFF);
+               fprintf(stderr, "pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\033[0m\n", pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_Diode_OFF);
        }
 
        return 0;
@@ -108,7 +109,7 @@ static int _dc_diode_handler(ScfEfunction* f, int64_t ps, int64_t count, ses_ctx
        ScfEline*  LP = ses_find_line_by_flag(f, SCF_EDA_PIN_POS);
        ScfEline*  LN = ses_find_line_by_flag(f, SCF_EDA_PIN_NEG);
 
-       return __dc_diode_status(f, f, LP, LN);
+       return __dc_diode_status(f, f, LP, LN, ctx);
 }
 
 ses_step_t   ses_step_dc_diode =
index ea43f57e7c3169d5521abf50809b2fa1f5d5098a..a9595d756b662de2456c0b25b2cd0b2c92209a22 100644 (file)
@@ -32,7 +32,7 @@ static int _dc_input_handler(ScfEfunction* f, int64_t ps, int64_t count, ses_ctx
 
                el2 = f->elines[B->pins[k]->lid];
 
-               el->v      = el2->v;
+               ses_line_set_v(el, el2->v);
                el->vconst = 1;
 
                scf_logi("el->io_lid: %ld, k: %d, v: %lg\n", el->io_lid, k, el->v);
index 3663ee85d31ccbe249099caffd8bd7bc445bb8c2..fedf6e9c3d9cd2a0e8b9bd36fb1b5e8f9a7b02a0 100644 (file)
@@ -1,6 +1,6 @@
 #include"ses_core.h"
 
-static int __dc_npn_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, ScfEline* LN)
+static int __dc_npn_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, ScfEline* LN, ses_ctx_t* ctx)
 {
        ScfEcomponent*   c;
        ScfEpin*         pb;
@@ -14,7 +14,7 @@ static int __dc_npn_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, Sc
                c  =        f->components[i];
 
                if (c->f) {
-                       int ret = __dc_npn_status(root, c->f, LP, LN);
+                       int ret = __dc_npn_status(root, c->f, LP, LN, ctx);
                        if (ret < 0)
                                return ret;
 
@@ -34,7 +34,7 @@ static int __dc_npn_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, Sc
                if (lb == LP && le == LN) {
                        scf_loge("short connected, ");
                        ses_pin_print(pb);
-                       printf("\n");
+                       fprintf(stderr, "\n");
                        return -EINVAL;
                }
 
@@ -46,7 +46,7 @@ static int __dc_npn_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, Sc
 
                        scf_logi("\033[34m status: %d, lock: %d, \033[0m", c->status, c->lock);
                        ses_pin_print(pb);
-                       printf("pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\n", pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_NPN_OFF);
+                       fprintf(stderr, "pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\n", pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_NPN_OFF);
                        continue;
                }
 
@@ -55,7 +55,7 @@ static int __dc_npn_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, Sc
 
                        scf_logi("\033[34m status: %d, lock: %d, \033[0m", c->status, c->lock);
                        ses_pin_print(pb);
-                       printf("pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\n", pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_NPN_OFF);
+                       fprintf(stderr, "pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\n", pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_NPN_OFF);
                        continue;
                }
 #endif
@@ -100,7 +100,8 @@ static int __dc_npn_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, Sc
                }
 
 check:
-               if ((c->pf->IC && SCF_EDA_OP_AMP == c->pf->IC->type)
+               if (!ctx->dc_flag
+                               || (c->pf->IC && SCF_EDA_OP_AMP == c->pf->IC->type)
                                || pe->v >= LP->v - SCF_EDA_V_NPN_OFF
                                || pb->v <= LN->v + SCF_EDA_V_NPN_OFF) {
                        c->lock   = 0;
@@ -109,7 +110,7 @@ check:
 
                scf_logi("\033[34m status: %d, lock: %d, ", c->status, c->lock);
                ses_pin_print(pb);
-               printf("pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\033[0m\n", pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_NPN_OFF);
+               fprintf(stderr, "pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\033[0m\n", pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_NPN_OFF);
        }
 
        return 0;
@@ -120,7 +121,7 @@ static int _dc_npn_handler(ScfEfunction* f, int64_t ps, int64_t count, ses_ctx_t
        ScfEline*  LP = ses_find_line_by_flag(f, SCF_EDA_PIN_POS);
        ScfEline*  LN = ses_find_line_by_flag(f, SCF_EDA_PIN_NEG);
 
-       return __dc_npn_status(f, f, LP, LN);
+       return __dc_npn_status(f, f, LP, LN, ctx);
 }
 
 ses_step_t   ses_step_dc_npn =
index 305d42ffff73416ffa328ad8a2f44762d9b010e6..118a6128a91598df7261bb2f3ca5430f1a925f19 100644 (file)
@@ -1,6 +1,6 @@
 #include"ses_core.h"
 
-static int __dc_pnp_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, ScfEline* LN)
+static int __dc_pnp_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, ScfEline* LN, ses_ctx_t* ctx)
 {
        ScfEcomponent*  c;
        ScfEpin*        pb;
@@ -14,7 +14,7 @@ static int __dc_pnp_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, Sc
                c  =        f->components[i];
 
                if (c->f) {
-                       int ret = __dc_pnp_status(root, c->f, LP, LN);
+                       int ret = __dc_pnp_status(root, c->f, LP, LN, ctx);
                        if (ret < 0)
                                return ret;
 
@@ -34,7 +34,7 @@ static int __dc_pnp_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, Sc
                if (le == LP && lb == LN) {
                        scf_loge("short connected, ");
                        ses_pin_print(pb);
-                       printf("\n");
+                       fprintf(stderr, "\n");
                        return -EINVAL;
                }
 
@@ -82,7 +82,8 @@ static int __dc_pnp_status(ScfEfunction* root, ScfEfunction* f, ScfEline* LP, Sc
                }
 
 check:
-               if ((c->pf->IC && SCF_EDA_OP_AMP == c->pf->IC->type)
+               if (!ctx->dc_flag
+                               || (c->pf->IC && SCF_EDA_OP_AMP == c->pf->IC->type)
                                || pb->v >= LP->v - SCF_EDA_V_NPN_OFF
                                || pe->v <= LN->v + SCF_EDA_V_NPN_OFF) {
                        c->lock   = 0;
@@ -91,7 +92,7 @@ check:
 
                scf_logi("\033[34m status: %d, lock: %d, ", c->status, c->lock);
                ses_pin_print(pb);
-               printf("pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\033[0m\n", pb->v, pe->v, pe->v - pb->v, SCF_EDA_V_PNP_OFF);
+               fprintf(stderr, "pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\033[0m\n", pb->v, pe->v, pe->v - pb->v, SCF_EDA_V_PNP_OFF);
        }
 
        return 0;
@@ -102,7 +103,7 @@ static int _dc_pnp_handler(ScfEfunction* f, int64_t ps, int64_t count, ses_ctx_t
        ScfEline*  LP = ses_find_line_by_flag(f, SCF_EDA_PIN_POS);
        ScfEline*  LN = ses_find_line_by_flag(f, SCF_EDA_PIN_NEG);
 
-       return __dc_pnp_status(f, f, LP, LN);
+       return __dc_pnp_status(f, f, LP, LN, ctx);
 }
 
 ses_step_t   ses_step_dc_pnp =
index ca3e43395dd2bfe8a6c19146b17ab6bf48acc049..001a9675f0e75f40f01fc33766e3c2f872c6128b 100644 (file)
@@ -1,7 +1,8 @@
 #include<cairo/cairo.h>
 #include"ses_core.h"
 
-#define SHOW_BITS  1000.0
+#define SHOW_BITS     1000.0
+#define SHOW_DATA(d)  ((int64_t)((d) * SHOW_BITS) / SHOW_BITS)
 
 static void ses_text_a(cairo_t* cr, int x, int y, double a)
 {
@@ -13,25 +14,25 @@ static void ses_text_a(cairo_t* cr, int x, int y, double a)
                SHOW_COLOR(cr, 0.0, 0.0, 0.7);
 
        if (a > 1e-1 || a < -1e-1) {
-               snprintf(text, sizeof(text) - 1, "%lgA", (int64_t)(a * SHOW_BITS) / SHOW_BITS);
+               snprintf(text, sizeof(text) - 1, "%lgA", SHOW_DATA(a));
 
                cairo_move_to  (cr, x, y);
                cairo_show_text(cr, text);
 
        } else if (a > 1e-5 || a < -1e-5) {
-               snprintf(text, sizeof(text) - 1, "%lgmA", (int64_t)(a * 1000.0 * SHOW_BITS) / SHOW_BITS);
+               snprintf(text, sizeof(text) - 1, "%lgmA", SHOW_DATA(a * 1000.0));
 
                cairo_move_to  (cr, x, y);
                cairo_show_text(cr, text);
 
        } else if (a > 1e-9 || a < -1e-9) {
-               snprintf(text, sizeof(text) - 1, "%lguA", (int64_t)(a * 1000000.0 * SHOW_BITS) / SHOW_BITS);
+               snprintf(text, sizeof(text) - 1, "%lguA", SHOW_DATA(a * 1000000.0));
 
                cairo_move_to  (cr, x, y);
                cairo_show_text(cr, text);
 
        } else if (a > 1e-13 || a < -1e-13) {
-               snprintf(text, sizeof(text) - 1, "%lgnA", (int64_t)(a * 1e9 * SHOW_BITS) / SHOW_BITS);
+               snprintf(text, sizeof(text) - 1, "%lgnA", SHOW_DATA(a * 1e9));
 
                cairo_move_to  (cr, x, y);
                cairo_show_text(cr, text);
@@ -48,19 +49,19 @@ static void ses_text_v(cairo_t* cr, int x, int y, double v)
                SHOW_COLOR(cr, 0.0, 0.0, 0.7);
 
        if (v > 1e-1 || v < -1e-1) {
-               snprintf(text, sizeof(text) - 1, "%lgV", (int64_t)(v * SHOW_BITS) / SHOW_BITS);
+               snprintf(text, sizeof(text) - 1, "%lgV", SHOW_DATA(v));
 
                cairo_move_to  (cr, x, y);
                cairo_show_text(cr, text);
 
        } else if (v > 1e-5 || v < -1e-5) {
-               snprintf(text, sizeof(text) - 1, "%lgmV", (int64_t)(v * 1000.0 * SHOW_BITS) / SHOW_BITS);
+               snprintf(text, sizeof(text) - 1, "%lgmV", SHOW_DATA(v * 1000.0));
 
                cairo_move_to  (cr, x, y);
                cairo_show_text(cr, text);
 
        } else if (v > 1e-9 || v < -1e-9) {
-               snprintf(text, sizeof(text) - 1, "%lguV", (int64_t)(v * 1000000.0 * SHOW_BITS) / SHOW_BITS);
+               snprintf(text, sizeof(text) - 1, "%lguV", SHOW_DATA(v * 1000000.0));
 
                cairo_move_to  (cr, x, y);
                cairo_show_text(cr, text);
@@ -101,6 +102,12 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
                                cairo_move_to(cr, c->x + 10, c->y + 8);
                                break;
 
+                       case SCF_EDA_Crystal:
+                               n = snprintf(text, sizeof(text) - 1, "X%ld", c->id);
+
+                               cairo_move_to(cr, c->x - 8 - n * 10, c->y - 12);
+                               break;
+
                        case SCF_EDA_Capacitor:
                                n = snprintf(text, sizeof(text) - 1, "C%ld", c->id);
 
@@ -110,7 +117,7 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
                        case SCF_EDA_Inductor:
                                n = snprintf(text, sizeof(text) - 1, "L%ld", c->id);
 
-                               cairo_move_to(cr, c->x - 12 - n * 10, c->y - 12);
+                               cairo_move_to(cr, c->x - 8 - n * 10, c->y - 12);
                                break;
 
                        case SCF_EDA_Diode:
@@ -184,7 +191,7 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
                cairo_show_text(cr, text);
                cairo_stroke(cr);
 
-               cairo_set_font_size(cr, 16);
+               cairo_set_font_size(cr, 15);
 #if 0
                snprintf(text, sizeof(text) - 1, "c%ld", c->color);
                cairo_move_to(cr, c->x - 10, c->y - 24);
@@ -252,6 +259,64 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
                                cairo_stroke(cr);
                                break;
 
+                       case SCF_EDA_Crystal:
+                               cairo_rectangle(cr, c->x - 8, c->y - 3, 16, 6);
+                               cairo_fill(cr);
+                               cairo_stroke(cr);
+
+                               p0 = c->pins[0];
+                               p1 = c->pins[1];
+
+                               if (p0->y < c->y) {
+                                       cairo_move_to(cr, p0->x, p0->y);
+                                       cairo_line_to(cr, c->x,  c->y - 6);
+
+                                       cairo_move_to(cr, p1->x, p1->y);
+                                       cairo_line_to(cr, c->x,  c->y + 6);
+
+                                       cairo_move_to(cr, c->x - 6, c->y + 6);
+                                       cairo_line_to(cr, c->x + 6, c->y + 6);
+                                       cairo_stroke(cr);
+
+                                       SHOW_COLOR(cr, 0.0, 0.0, 0.8);
+                                       cairo_move_to(cr, c->x - 6, c->y - 6);
+                                       cairo_line_to(cr, c->x + 6, c->y - 6);
+                                       cairo_stroke(cr);
+                               } else {
+                                       cairo_move_to(cr, p0->x, p0->y);
+                                       cairo_line_to(cr, c->x,  c->y + 6);
+
+                                       cairo_move_to(cr, p1->x, p1->y);
+                                       cairo_line_to(cr, c->x,  c->y - 6);
+
+                                       cairo_move_to(cr, c->x - 6, c->y - 6);
+                                       cairo_line_to(cr, c->x + 6, c->y - 6);
+                                       cairo_stroke(cr);
+
+                                       SHOW_COLOR(cr, 0.0, 0.0, 0.8);
+                                       cairo_move_to(cr, c->x - 6, c->y + 6);
+                                       cairo_line_to(cr, c->x + 6, c->y + 6);
+                                       cairo_stroke(cr);
+                               }
+
+                               cairo_select_font_face(cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+
+                               ses_text_v(cr, c->x + 10, c->y + 8, c->v);
+                               ses_text_a(cr, c->x + 10, c->y + 23, c->a);
+
+                               SHOW_COLOR(cr, 0.0, 0.0, 0.0);
+                               if (c->Hz > 999999)
+                                       snprintf(text, sizeof(text) - 1, "%lgMHz", SHOW_DATA(c->Hz / 1e6));
+                               else if (c->Hz > 999)
+                                       snprintf(text, sizeof(text) - 1, "%lgkHz", SHOW_DATA(c->Hz / 1000.0));
+                               else
+                                       snprintf(text, sizeof(text) - 1, "%lgHz", SHOW_DATA(c->Hz));
+
+                               cairo_move_to  (cr, c->x + 8, c->y - 9);
+                               cairo_show_text(cr, text);
+                               cairo_stroke(cr);
+                               break;
+
                        case SCF_EDA_Capacitor:
                                SHOW_COLOR(cr, 0.8, 0.0, 0.0);
 
@@ -301,12 +366,12 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
 
                                SHOW_COLOR(cr, 0.0, 0.0, 0.0);
 
-                               if (c->uf < 1e-5)
-                                       snprintf(text, sizeof(text) - 1, "%lgpF", c->uf * 1e6);
+                               if (c->uf < 1e-4)
+                                       snprintf(text, sizeof(text) - 1, "%lgpF", SHOW_DATA(c->uf * 1e6));
                                else if (c->uf < 1e-2)
-                                       snprintf(text, sizeof(text) - 1, "%lgnF", c->uf * 1000.0);
+                                       snprintf(text, sizeof(text) - 1, "%lgnF", SHOW_DATA(c->uf * 1000.0));
                                else
-                                       snprintf(text, sizeof(text) - 1, "%lguF", c->uf);
+                                       snprintf(text, sizeof(text) - 1, "%lguF", SHOW_DATA(c->uf));
 
                                cairo_move_to  (cr, c->x + 2, c->y - 8);
                                cairo_show_text(cr, text);
@@ -352,13 +417,13 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
                                SHOW_COLOR(cr, 0.0, 0.0, 0.0);
 
                                if (c->uh > 100000.0)
-                                       snprintf(text, sizeof(text) - 1, "%lgH", c->uh / 1000000.0);
+                                       snprintf(text, sizeof(text) - 1, "%lgH", SHOW_DATA(c->uh / 1000000.0));
                                else if (c->uh > 100.0)
-                                       snprintf(text, sizeof(text) - 1, "%lgmH", c->uh / 1000.0);
-                               else if (c->uh < 1e-3)
-                                       snprintf(text, sizeof(text) - 1, "%lgnH", c->uh * 1000.0);
+                                       snprintf(text, sizeof(text) - 1, "%lgmH", SHOW_DATA(c->uh / 1000.0));
+                               else if (c->uh < 1e-2)
+                                       snprintf(text, sizeof(text) - 1, "%lgnH", SHOW_DATA(c->uh * 1000.0));
                                else
-                                       snprintf(text, sizeof(text) - 1, "%lguH", c->uh);
+                                       snprintf(text, sizeof(text) - 1, "%lguH", SHOW_DATA(c->uh));
 
                                cairo_move_to  (cr, c->x + 4, c->y - 5);
                                cairo_show_text(cr, text);
@@ -398,12 +463,12 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
                                ses_text_a(cr, c->x + 8, c->y + 27, c->a);
 
                                SHOW_COLOR(cr, 0.0, 0.0, 0.0);
-                               if (c->r + c->dr > 1e6)
-                                       snprintf(text, sizeof(text) - 1, "%lgMΩ", (int64_t)(c->r + c->dr) / 1000000.0);
-                               else if (c->r + c->dr > 999)
-                                       snprintf(text, sizeof(text) - 1, "%lgkΩ", (int64_t)((c->r + c->dr) * 1000.0) / 1000000.0);
+                               if (c->r > 999999)
+                                       snprintf(text, sizeof(text) - 1, "%lgMΩ", SHOW_DATA(c->r / 1e6));
+                               else if (c->r > 999)
+                                       snprintf(text, sizeof(text) - 1, "%lgkΩ", SHOW_DATA(c->r / 1000.0));
                                else
-                                       snprintf(text, sizeof(text) - 1, "%lgΩ", (int64_t)((c->r + c->dr) * 1000.0) / 1000.0);
+                                       snprintf(text, sizeof(text) - 1, "%lgΩ", SHOW_DATA(c->r));
 
                                cairo_move_to  (cr, c->x + 8, c->y - 9);
                                cairo_show_text(cr, text);
@@ -1451,12 +1516,12 @@ int ses_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t by, uint32
                                n = snprintf(text, sizeof(text) - 1, "%lgV", B->pins[SCF_EDA_Battery_POS]->v);
 
                        else if (el->v > 1e-2 || el->v < -1e-2)
-                               n = snprintf(text, sizeof(text) - 1, "%lgV", (int64_t)(el->v * SHOW_BITS) / SHOW_BITS);
+                               n = snprintf(text, sizeof(text) - 1, "%lgV", SHOW_DATA(el->v));
 
                        else if (el->v > 1e-5 || el->v < -1e-5)
-                               n = snprintf(text, sizeof(text) - 1, "%lgmV", (int64_t)(el->v * 1000.0 * SHOW_BITS) / SHOW_BITS);
+                               n = snprintf(text, sizeof(text) - 1, "%lgmV", SHOW_DATA(el->v * 1000.0));
                        else
-                               n = snprintf(text, sizeof(text) - 1, "%lguV", (int64_t)(el->v * 1000000.0 * SHOW_BITS) / SHOW_BITS);
+                               n = snprintf(text, sizeof(text) - 1, "%lguV", SHOW_DATA(el->v * 1e6));
 
                        if (el->v == B->pins[SCF_EDA_Battery_POS]->v)
                                SHOW_COLOR(cr, 1, 0, 0);
@@ -1552,17 +1617,11 @@ static int print_a(ScfEfunction* f, ses_ctx_t* ctx)
        if (!ctx->Ashow)
                return 0;
 
-       if (!ctx->Afp) {
-               ctx->Afp = fopen("a.txt", "w");
-               if (!ctx->Afp)
-                       return -1;
-       }
-
        char* p;
        int   j = -1;
        int   k = SCF_EDA_NPN_E;
 
-       fprintf(ctx->Afp, "%d", ctx->i);
+       printf("A, %d", ctx->i);
 
        for (p = ctx->Ashow; *p; p++) {
 
@@ -1604,7 +1663,7 @@ static int print_a(ScfEfunction* f, ses_ctx_t* ctx)
                                        if (SCF_EDA_NPN == c->type || SCF_EDA_PNP == c->type)
                                                a = c->pins[k]->a;
 
-                                       fprintf(ctx->Afp, ", %lg", a);
+                                       printf(", %lg", a);
                                }
 
                                j = -1;
@@ -1623,11 +1682,10 @@ static int print_a(ScfEfunction* f, ses_ctx_t* ctx)
                if (SCF_EDA_NPN == c->type || SCF_EDA_PNP == c->type)
                        a = c->pins[k]->a;
 
-               fprintf(ctx->Afp, ", %lg", a);
+               printf(", %lg", a);
        }
 
-       fprintf(ctx->Afp, "\n");
-       fflush(ctx->Afp);
+       printf("\n");
        return 0;
 }
 
@@ -1636,18 +1694,12 @@ static int print_v(ScfEfunction* f, ses_ctx_t* ctx)
        if (!ctx->Vshow)
                return 0;
 
-       if (!ctx->Vfp) {
-               ctx->Vfp = fopen("v.txt", "w");
-               if (!ctx->Vfp)
-                       return -1;
-       }
-
        char* p;
        int   op = 0;
        int   j  = -1;
        int   k  = -1;
 
-       fprintf(ctx->Vfp, "%d", ctx->i);
+       printf("V, %d", ctx->i);
 
        for (p = ctx->Vshow; *p; p++) {
 
@@ -1670,11 +1722,11 @@ static int print_v(ScfEfunction* f, ses_ctx_t* ctx)
                                                        && j < f->n_elines
                                                        && k < f->n_elines
                                                        && k >= 0)
-                                               fprintf(ctx->Vfp, ", %lg", f->elines[j]->v - f->elines[k]->v);
+                                               printf(", %lg", f->elines[j]->v - f->elines[k]->v);
 
                                } else {
                                        if (j >= 0 && j < f->n_elines)
-                                               fprintf(ctx->Vfp, ", %lg", f->elines[j]->v);
+                                               printf(", %lg", f->elines[j]->v);
                                }
 
                                j  = -1;
@@ -1691,15 +1743,14 @@ static int print_v(ScfEfunction* f, ses_ctx_t* ctx)
                                && j < f->n_elines
                                && k < f->n_elines
                                && k >= 0)
-                       fprintf(ctx->Vfp, ", %lg", f->elines[j]->v - f->elines[k]->v);
+                       printf(", %lg", f->elines[j]->v - f->elines[k]->v);
 
        } else {
                if (j >= 0 && j < f->n_elines)
-                       fprintf(ctx->Vfp, ", %lg", f->elines[j]->v);
+                       printf(", %lg", f->elines[j]->v);
        }
 
-       fprintf(ctx->Vfp, "\n");
-       fflush(ctx->Vfp);
+       printf("\n");
        return 0;
 }
 
index 5afc4b03b67e449607148dc757521607c04e7cce..48a5fc734a226ccc63d632f21f913c2be3342026 100644 (file)
@@ -219,7 +219,7 @@ static void __open_status_line(ScfEfunction* f, ScfEline* el, ScfEline* LP, ScfE
 
 //     scf_logw("");
 //     ses_eline_print(el);
-//     printf("->v: %lg\n", el->v);
+//     fprintf(stderr, "->v: %lg\n", el->v);
 }
 
 static void __open_status_IC(ScfEfunction* f, ScfEcomponent* IC, ScfEline* LP, ScfEline* LN)
@@ -266,7 +266,7 @@ static int _open_handler(ScfEfunction* f, int64_t ps, int64_t count, ses_ctx_t*
                        __open_status_IC(f, c, LP, LN);
        }
 
-       printf("\n");
+       fprintf(stderr, "\n");
        return 0;
 }
 
index 2d8f109eb9bb580cf341f07f6673168bf5141e4a..7a78113dc3cf4896ec2525a8f83f5ac41645854e 100644 (file)
@@ -5,7 +5,7 @@ static int _output_handler(ScfEfunction* f, int64_t ps, int64_t count, ses_ctx_t
        ScfEline* el;
        long i;
 
-       printf("\n");
+       fprintf(stderr, "\n");
 
        for (i = 0; i < f->n_elines; i++) {
                el =        f->elines[i];
@@ -14,7 +14,7 @@ static int _output_handler(ScfEfunction* f, int64_t ps, int64_t count, ses_ctx_t
                        scf_logi("out el: %ld, V: %lg\n", el->id, el->v);
        }
 
-       printf("\n");
+       fprintf(stderr, "\n");
 
        for (i = 0; i < f->n_elines; i++) {
                el =        f->elines[i];
index d4e31af713fed6edaa7d62b0a473c4995cdc6859..4d0e09b46e997538bec692a2aadeee7734cbeaf6 100644 (file)
@@ -98,7 +98,7 @@ static int __ses_dfs_line(ScfEcomponent* rc, ScfEpin* np, scf_vector_t* __paths,
 #if 0
                                scf_logw("branch l%ld, ", el->id);
                                ses_pin_print(p);
-                               printf("\n");
+                               fprintf(stderr, "\n");
 #endif
                                ret = __ses_dfs_add_ppath(__paths, ppath);
                                if (ret < 0)
@@ -139,7 +139,7 @@ static int __ses_dfs_line(ScfEcomponent* rc, ScfEpin* np, scf_vector_t* __paths,
 #if 0
        scf_logi("");
        ses_pin_print(np);
-       printf("l%ld, vflag: %d, pflag: %d\n", np->lid, np->vflag, np->pflag);
+       fprintf(stderr, "l%ld, vflag: %d, pflag: %d\n", np->lid, np->vflag, np->pflag);
 #endif
        return ret;
 }
@@ -156,7 +156,7 @@ static int __ses_dfs_IC(ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __paths, s
 #if 0
        scf_logi("*** rc->f->n_elines: %ld, ", rc->f->n_elines);
        ses_pin_print(rp);
-       printf("l%ld, vflag: %d, pflag: %d\n", rp->lid, rp->vflag, rp->pflag);
+       fprintf(stderr, "l%ld, vflag: %d, pflag: %d\n", rp->lid, rp->vflag, rp->pflag);
 #endif
 
        int size = __paths->size;
@@ -169,9 +169,9 @@ static int __ses_dfs_IC(ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __paths, s
 #if 0
                scf_logi("\033[34m--- j:%ld, rc->f: %p, \033[0m", j, rc->f);
                ses_pin_print(rp);
-               printf(", l%ld, vflag: %d, pflag: %d, p: ", p->lid, p->vflag, p->pflag);
+               fprintf(stderr, ", l%ld, vflag: %d, pflag: %d, p: ", p->lid, p->vflag, p->pflag);
                ses_pin_print(p);
-               printf("\n");
+               fprintf(stderr, "\n");
 #endif
                if (p->pflag) {
                        assert(p != rp);
@@ -264,7 +264,7 @@ static int __ses_dfs_path(ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __paths,
 #if 0
        scf_logi("");
        ses_pin_print(rp);
-       printf("l%ld, vflag: %d, pflag: %d\n", rp->lid, rp->vflag, rp->pflag);
+       fprintf(stderr, "l%ld, vflag: %d, pflag: %d\n", rp->lid, rp->vflag, rp->pflag);
 #endif
        int  ret = 0;
        long i;
@@ -280,7 +280,7 @@ static int __ses_dfs_path(ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __paths,
 #if 0
                scf_logi("");
                ses_pin_print(np);
-               printf("l%ld, vflag: %d, pflag: %d\n", np->lid, np->vflag, np->pflag);
+               fprintf(stderr, "l%ld, vflag: %d, pflag: %d\n", np->lid, np->vflag, np->pflag);
 #endif
                el = rc->pf->elines[np->lid];
 
@@ -361,7 +361,7 @@ static int __ses_dfs_path(ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __paths,
 #if 0
                        scf_loge("off: ");
                        ses_pin_print(rp);
-                       printf("l%ld, vflag: %d, pflag: %d\n\n", rp->lid, rp->vflag, rp->pflag);
+                       fprintf(stderr, "l%ld, vflag: %d, pflag: %d\n\n", rp->lid, rp->vflag, rp->pflag);
 #endif
                }
        }
@@ -1010,10 +1010,10 @@ static int _topo_path_completes(ScfEfunction* f, scf_vector_t* paths)
                                        scf_logi("\033[36mconnect path: \033[0m");
                                        ses_pin_print(p2);
                                        ses_pin_print(__p3);
-                                       printf("(%d)--", path1->pins->size);
+                                       fprintf(stderr, "(%d)--", path1->pins->size);
                                        ses_pin_print(__p0);
                                        ses_pin_print(p1);
-                                       printf("(%d)\n", path0->pins->size);
+                                       fprintf(stderr, "(%d)\n", path0->pins->size);
 #endif
                                        int ret = __topo_path_xchg(f, paths, path0, m, path1, k + 1);
                                        if (ret < 0)
@@ -1107,10 +1107,10 @@ static int _topo_path_neg(ScfEfunction* f, scf_vector_t* paths)
                                scf_logi("\033[36mconnect path: \033[0m");
                                ses_pin_print(p2);
                                ses_pin_print(p);
-                               printf("(%d)--", path1->pins->size);
+                               fprintf(stderr, "(%d)--", path1->pins->size);
                                ses_pin_print(p0);
                                ses_pin_print(p1);
-                               printf("\n");
+                               fprintf(stderr, "\n");
 #endif
                                int ret = __topo_path_xchg(f, paths, path0, 0, path1, k + 1);
                                if (ret < 0)
@@ -1213,10 +1213,10 @@ xchg:
                scf_logi("\033[36mconnect path: \033[0m");
                ses_pin_print(p2);
                ses_pin_print(__p3);
-               printf("(%d)--", path1->pins->size);
+               fprintf(stderr, "(%d)--", path1->pins->size);
                ses_pin_print(__p0);
                ses_pin_print(p1);
-               printf("(%d)\n", path0->pins->size);
+               fprintf(stderr, "(%d)\n", path0->pins->size);
 #endif
                int ret = __topo_path_xchg(f, paths, path0, m, path1, k + 1);
                if (ret < 0)
@@ -1446,6 +1446,9 @@ static void _topo_clear(ScfEfunction* f)
                if (SCF_EDA_Inductor != c->type)
                        c->a = 0;
 
+               if (SCF_EDA_Crystal == c->type)
+                       c->v = 0;
+
                for (j = 0; j < c->n_pins; j++) {
                        p         = c->pins[j];
                        p->vflag  = 0;
@@ -1576,61 +1579,6 @@ static int _topo_bridge_piers(ScfEfunction* f, scf_vector_t* paths)
        return 0;
 }
 
-static int _topo_path_leaf(ScfEfunction* f, scf_vector_t* paths)
-{
-       ses_path_t*  leaf;
-       ses_path_t*  path;
-       ScfEpin*     p0;
-       ScfEpin*     p1;
-
-       int i;
-       int k;
-
-       for (i   = paths->size - 1; i >= 0; i--) {
-               leaf = paths->data[i];
-
-               p0 = leaf->pins->data[0];
-               p1 = leaf->pins->data[leaf->pins->size - 1];
-
-               if (SES_LINE_POS(p0) && SES_LINE_NEG(p1))
-                       continue;
-
-               if (leaf->childs || leaf->bridges || leaf->connections)
-                       continue;
-
-               path = NULL;
-
-               k = __topo_connect(f, paths, leaf, p1, &path);
-               if (k < 0) {
-                       k = __topo_connect(f, paths, leaf, p0, &path);
-                       if (k < 0)
-                               continue;
-
-                       leaf->parent_p0 = (k + 1) & ~0x1;
-                       leaf->parent_p1 = -2;
-               } else {
-                       leaf->parent_p0 = -2;
-                       leaf->parent_p1 = k;
-               }
-
-               if (!path->bridges) {
-                       path->bridges = scf_vector_alloc();
-                       if (!path->bridges)
-                               return -ENOMEM;
-               }
-
-               int ret = scf_vector_add(path->bridges, leaf);
-               if (ret < 0)
-                       return ret;
-
-               assert(0 == scf_vector_del(paths, leaf));
-
-               leaf->parent = path;
-       }
-
-       return 0;
-}
-
 static int _topo_add_connection(ses_path_t* path, ses_path_t* conn)
 {
        if (!conn->connections) {
@@ -1732,56 +1680,6 @@ static int _topo_paths_mov_top(ScfEfunction* f, scf_vector_t* paths, ses_path_t*
        return 0;
 }
 
-static int _topo_path_parallel(ScfEfunction* f, scf_vector_t* paths)
-{
-       ses_path_t*  parent;
-       ses_path_t*  child;
-       ScfEpin*     p0;
-       ScfEpin*     p1;
-       ScfEpin*     p2;
-       ScfEpin*     p3;
-
-       int i;
-       int j;
-
-       for (i = 0; i < paths->size - 1; i++) {
-               parent    = paths->data[i];
-
-               p0 = parent->pins->data[0];
-               p1 = parent->pins->data[parent->pins->size - 1];
-
-               for (j    = paths->size - 1; j > i; j--) {
-                       child = paths->data[j];
-
-                       p2 = child->pins->data[0];
-                       p3 = child->pins->data[child->pins->size - 1];
-
-                       if (ses_same_line(p0, p2) && ses_same_line(p1, p3)) {
-
-                               int ret = ses_path_add(f, parent, child);
-                               if (ret < 0)
-                                       return ret;
-
-                               assert(0 == scf_vector_del(paths, child));
-
-                               if (child->childs) {
-                                       ret = _topo_paths_mov_top(f, child->childs, parent, child);
-                                       if (ret < 0)
-                                               return ret;
-                               }
-
-                               if (child->bridges) {
-                                       ret = _topo_paths_mov_top(f, child->bridges, parent, child);
-                                       if (ret < 0)
-                                               return ret;
-                               }
-                       }
-               }
-       }
-
-       return 0;
-}
-
 int __ses_topo_layers(ScfEfunction* f, scf_vector_t* paths, int layout_flag)
 {
        ses_path_t* path;
@@ -1946,23 +1844,7 @@ static int _topo_handler(ScfEfunction* f, int64_t ps, int64_t count, ses_ctx_t*
        int ret = _topo_paths_lc(f, f, ctx->paths);
        if (ret < 0)
                return ret;
-#if 0
-       ret = __ses_topo_layers(f, ctx->paths, 0);
-       if (ret < 0)
-               return ret;
-
-       ret = __topo_bridge_connections(f, ctx->paths, 0);
-       if (ret < 0)
-               return ret;
-
-       ret = _topo_path_parallel(f, ctx->paths);
-       if (ret < 0)
-               return ret;
 
-       ret = _topo_path_leaf(f, ctx->paths);
-       if (ret < 0)
-               return ret;
-#endif
        ses_paths_print(ctx->paths);
        return 0;
 }
index 6d6a515e84afaa1cbea0aa20728a5bc40610237c..1c580f4853d31d180972eb560ca5556612e4dd1a 100644 (file)
@@ -1,6 +1,7 @@
 #include"ses_core.h"
 
 extern ses_step_t   ses_step_battery;
+extern ses_step_t   ses_step_crystal;
 
 extern ses_step_t   ses_step_dc_input;
 extern ses_step_t   ses_step_ac_input;
@@ -21,6 +22,7 @@ extern ses_step_t   ses_step_draw;
 static ses_step_t*  ses_steps_0[] =
 {
        &ses_step_battery,
+       &ses_step_crystal,
 
        &ses_step_dc_input,
 //     &ses_step_ac_input,
@@ -164,7 +166,7 @@ int ses_steps_analyse(ScfEboard* b, ScfEfunction* f, int64_t ps, int64_t count,
        __ses_init_v(f);
 
        for (i = 0; i < count; i++) {
-               printf("\n\033[36m%s(), %d(), count: %ld\033[0m\n", __func__, __LINE__, i);
+               fprintf(stderr, "\n\033[36m%s(), %d(), count: %ld\033[0m\n", __func__, __LINE__, i);
 
                int ret = __ses_analyse_input(f, ps, i, ctx);
                if (ret < 0)
@@ -172,7 +174,7 @@ int ses_steps_analyse(ScfEboard* b, ScfEfunction* f, int64_t ps, int64_t count,
 
                int j;
                for (j = 0; j < 1; j++) {
-                       printf("\n\033[33m%s(), %d(), j: %d\033[0m\n", __func__, __LINE__, j);
+                       fprintf(stderr, "\n\033[33m%s(), %d(), j: %d\033[0m\n", __func__, __LINE__, j);
 
                        ret = __ses_analyse_current(f, ps, i, ctx);
 
index 67eba7abff02d73ae08c56d56d0bd0cad6dfb203..4d04a9597a13bda5f8d33c4d54885bb3383d17ec 100644 (file)
@@ -23,12 +23,6 @@ void ses_ctx_free(ses_ctx_t* ctx)
                        scf_vector_free (ctx->paths);
                }
 
-               if (ctx->Vfp)
-                       fclose(ctx->Vfp);
-
-               if (ctx->Afp)
-                       fclose(ctx->Afp);
-
                free(ctx);
        }
 }
@@ -61,7 +55,7 @@ void ses_edge_print(ses_edge_t* edge)
        ScfEpin* p;
        int      j;
 
-       printf("[%d] ", edge->index);
+       fprintf(stderr, "[%d] ", edge->index);
 
        if (edge->vip_m < edge->vip_n) {
 
@@ -79,25 +73,25 @@ void ses_edge_print(ses_edge_t* edge)
                }
        }
 
-       printf("(");
+       fprintf(stderr, "(");
        if (edge->node1)
-               printf("%d", edge->node1->index);
+               fprintf(stderr, "%d", edge->node1->index);
        else
-               printf(" ");
-       printf("-->");
+               fprintf(stderr, " ");
+       fprintf(stderr, "-->");
 
        if (edge->node0)
-               printf("%d", edge->node0->index);
+               fprintf(stderr, "%d", edge->node0->index);
        else
-               printf(" ");
-       printf(")");
+               fprintf(stderr, " ");
+       fprintf(stderr, ")");
 
        if (edge->edge_b)
-               printf(" b[%d]", edge->edge_b->index);
+               fprintf(stderr, " b[%d]", edge->edge_b->index);
 
        if (edge->mirror)
-               printf(" m[%d]", edge->mirror->index);
-       printf("; ");
+               fprintf(stderr, " m[%d]", edge->mirror->index);
+       fprintf(stderr, "; ");
 }
 
 ses_node_t* ses_node_alloc()
@@ -140,15 +134,15 @@ void ses_node_print(ses_node_t* node)
        ses_edge_t* edge;
        int i;
 
-       printf("node %d: \n", node->index);
+       fprintf(stderr, "node %d: \n", node->index);
 
        for (i = 0; i < node->edges->size; i++) {
                edge      = node->edges->data[i];
 
                ses_edge_print(edge);
-               printf("\n");
+               fprintf(stderr, "\n");
        }
-       printf("\n");
+       fprintf(stderr, "\n");
 }
 
 void ses_nodes_print(scf_vector_t* nodes)
@@ -203,7 +197,7 @@ void ses_eline_print(ScfEline* el)
        if (el->pf->IC)
                ses_IC_print(el->pf->IC);
 
-       printf("el%ld", el->id);
+       fprintf(stderr, "el%ld", el->id);
 }
 
 void ses_elines_print(ScfEfunction* f)
@@ -214,7 +208,7 @@ void ses_elines_print(ScfEfunction* f)
                el =        f->elines[i];
 
                ses_eline_print(el);
-               printf("->v: %lg\n", el->v);
+               fprintf(stderr, "->v: %lg\n", el->v);
        }
 }
 
@@ -232,7 +226,7 @@ void ses_components_print(ScfEfunction* f)
                for (j = 0; j < c->n_pins; j++) {
                        p  =        c->pins[j];
 
-                       printf("c%ldp%ld->v: %lg\n", p->cid, p->id, p->v);
+                       fprintf(stderr, "c%ldp%ld->v: %lg\n", p->cid, p->id, p->v);
                }
        }
 }
diff --git a/test/LC_NAND.c b/test/LC_NAND.c
new file mode 100644 (file)
index 0000000..606fff0
--- /dev/null
@@ -0,0 +1,80 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include"ses_core.h"
+
+int main(int argc, char* argv[])
+{
+       ScfEcomponent* B;
+
+       ScfEcomponent* NAND;
+       ScfEcomponent* R1;
+       ScfEcomponent* R2;
+
+       ScfEcomponent* L;
+       ScfEcomponent* C1;
+       ScfEcomponent* C2;
+
+       ScfEfunction*  f;
+       ScfEboard*     b;
+
+       b = scf_eboard__alloc();
+       f = scf_efunction__alloc("LC_NAND");
+
+       EDA_INST_ADD_COMPONENT(f, B,  SCF_EDA_Battery);
+
+       B->pins[SCF_EDA_Battery_NEG]->flags = SCF_EDA_PIN_NEG;
+       B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS;
+
+       EDA_INST_ADD_COMPONENT(f, NAND, SCF_EDA_NAND);
+       EDA_INST_ADD_COMPONENT(f, R1,   SCF_EDA_Resistor);
+       EDA_INST_ADD_COMPONENT(f, R2,   SCF_EDA_Resistor);
+
+       EDA_INST_ADD_COMPONENT(f, L,    SCF_EDA_Inductor);
+       EDA_INST_ADD_COMPONENT(f, C1,   SCF_EDA_Capacitor);
+       EDA_INST_ADD_COMPONENT(f, C2,   SCF_EDA_Capacitor);
+
+       EDA_PIN_ADD_PIN(B,    SCF_EDA_Battery_POS,  NAND, SCF_EDA_NAND_POS);
+       EDA_PIN_ADD_PIN(B,    SCF_EDA_Battery_NEG,  NAND, SCF_EDA_NAND_NEG);
+
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_IN0,     NAND, SCF_EDA_NAND_IN1);
+
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_OUT,     R1,   1);
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_IN0,     R1,   0);
+
+       EDA_PIN_ADD_PIN(L,  1,                      C2,   1);
+       EDA_PIN_ADD_PIN(L,  0,                      C1,   1);
+       EDA_PIN_ADD_PIN(C1, 0,                      C2,   0);
+       EDA_PIN_ADD_PIN(C1, 0,                      B,    SCF_EDA_Battery_NEG);
+
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_OUT,     R2,   1);
+       EDA_PIN_ADD_PIN(R2,   0,                    L,    1);
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_IN0,     L,    0);
+
+       NAND->pins[SCF_EDA_NAND_OUT]->flags |= SCF_EDA_PIN_OUT;
+
+       B->v   = 5;
+
+       R1->r  = 1000 * 1000;
+       R2->r  = 1000;
+       L->uh  = 1000;
+       C1->uf = 0.001;
+       C2->uf = 0.001;
+
+       scf_eboard__add_function(b, f);
+
+       long     len = 0;
+       uint8_t* buf = NULL;
+
+       ScfEboard_pack(b, &buf, &len);
+       ScfEboard_free(b);
+       b = NULL;
+
+       FILE* fp = fopen("./LC_NAND_oscillator.cpk", "wb");
+       if (!fp)
+               return -EINVAL;
+
+       fwrite(buf, len, 1, fp);
+       fclose(fp);
+       return 0;
+}
index 4b02ef6ad1e9ca8ab59561e3641d2089037dd786..ac2f593e5879f5492a9ebb78cf3447f19f9a7a81 100644 (file)
@@ -1,12 +1,16 @@
 #CFILES += main.c
-#CFILES += test.c
-#CFILES += fft.c
-#CFILES += dct.c
 #CFILES += pnp.c
 #CFILES += colpitts.c
 #CFILES += astable_multivibrator.c
 #CFILES += two_battery.c
-CFILES += opa_rc.c
+#CFILES += opa_rc.c
+#CFILES += crystal.c
+#CFILES += crystal_NAND.c
+#CFILES += LC_NAND.c
+
+#CFILES += test.c
+CFILES += fft.c
+#CFILES += dct.c
 #CFILES += draw_timing.c
 
 CFILES += ../scf_eda_pack.c
diff --git a/test/crystal.c b/test/crystal.c
new file mode 100644 (file)
index 0000000..c9deb81
--- /dev/null
@@ -0,0 +1,88 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include"ses_core.h"
+
+int main(int argc, char* argv[])
+{
+       ScfEcomponent* B;
+
+       ScfEcomponent* T;
+       ScfEcomponent* R1;
+       ScfEcomponent* R2;
+       ScfEcomponent* R3;
+
+       ScfEcomponent* X;
+       ScfEcomponent* C1;
+       ScfEcomponent* C2;
+       ScfEcomponent* C3;
+
+       ScfEfunction*  f;
+       ScfEboard*     b;
+
+       b = scf_eboard__alloc();
+       f = scf_efunction__alloc("crystal_oscillator");
+
+       EDA_INST_ADD_COMPONENT(f, B,  SCF_EDA_Battery);
+
+       B->pins[SCF_EDA_Battery_NEG]->flags = SCF_EDA_PIN_NEG;
+       B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS;
+
+       EDA_INST_ADD_COMPONENT(f, T,  SCF_EDA_NPN);
+       EDA_INST_ADD_COMPONENT(f, R1, SCF_EDA_Resistor);
+       EDA_INST_ADD_COMPONENT(f, R2, SCF_EDA_Resistor);
+       EDA_INST_ADD_COMPONENT(f, R3, SCF_EDA_Resistor);
+
+       EDA_INST_ADD_COMPONENT(f, X,  SCF_EDA_Crystal);
+       EDA_INST_ADD_COMPONENT(f, C1, SCF_EDA_Capacitor);
+       EDA_INST_ADD_COMPONENT(f, C2, SCF_EDA_Capacitor);
+       EDA_INST_ADD_COMPONENT(f, C3, SCF_EDA_Capacitor);
+
+       EDA_PIN_ADD_PIN(B,  SCF_EDA_Battery_POS,  R1, 1);
+       EDA_PIN_ADD_PIN(R1, 0,                    T,  SCF_EDA_NPN_C);
+       EDA_PIN_ADD_PIN(T,  SCF_EDA_NPN_E,        R2, 1);
+       EDA_PIN_ADD_PIN(R2, 0,                    B,  SCF_EDA_Battery_NEG);
+
+       EDA_PIN_ADD_PIN(T,  SCF_EDA_NPN_C,        R3, 1);
+       EDA_PIN_ADD_PIN(T,  SCF_EDA_NPN_B,        R3, 0);
+
+       EDA_PIN_ADD_PIN(X,  1,                    C2, 1);
+       EDA_PIN_ADD_PIN(X,  0,                    C1, 1);
+       EDA_PIN_ADD_PIN(C1, 0,                    C2, 0);
+       EDA_PIN_ADD_PIN(C1, 0,                    B,  SCF_EDA_Battery_NEG);
+
+       EDA_PIN_ADD_PIN(X,  1,                    T,  SCF_EDA_NPN_C);
+       EDA_PIN_ADD_PIN(X,  0,                    C3, 1);
+       EDA_PIN_ADD_PIN(C3, 0,                    T,  SCF_EDA_NPN_B);
+
+       T->pins[SCF_EDA_NPN_C]->flags |= SCF_EDA_PIN_OUT;
+       T->pins[SCF_EDA_NPN_C]->hfe    = 220;
+
+       B->v   = 5;
+
+       R1->r  = 2000;
+       R2->r  = 200;
+       R3->r  = 1000 * 200;
+
+       X ->Hz = 3.5e6;
+       C1->uf = 22e-6;
+       C2->uf = 22e-6;
+       C3->uf = 10;
+
+       scf_eboard__add_function(b, f);
+
+       long     len = 0;
+       uint8_t* buf = NULL;
+
+       ScfEboard_pack(b, &buf, &len);
+       ScfEboard_free(b);
+       b = NULL;
+
+       FILE* fp = fopen("./crystal_oscillator.cpk", "wb");
+       if (!fp)
+               return -EINVAL;
+
+       fwrite(buf, len, 1, fp);
+       fclose(fp);
+       return 0;
+}
diff --git a/test/crystal_NAND.c b/test/crystal_NAND.c
new file mode 100644 (file)
index 0000000..60b7a69
--- /dev/null
@@ -0,0 +1,95 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include"ses_core.h"
+
+int main(int argc, char* argv[])
+{
+       ScfEcomponent* B;
+
+       ScfEcomponent* NAND;
+       ScfEcomponent* R1;
+       ScfEcomponent* R2;
+
+       ScfEcomponent* Rs;
+       ScfEcomponent* Ls;
+       ScfEcomponent* Cs;
+
+       ScfEcomponent* C1;
+       ScfEcomponent* C2;
+
+       ScfEfunction*  f;
+       ScfEboard*     b;
+
+       b = scf_eboard__alloc();
+       f = scf_efunction__alloc("crystal_NAND");
+
+       EDA_INST_ADD_COMPONENT(f, B,  SCF_EDA_Battery);
+
+       B->pins[SCF_EDA_Battery_NEG]->flags = SCF_EDA_PIN_NEG;
+       B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS;
+
+       EDA_INST_ADD_COMPONENT(f, NAND,  SCF_EDA_NAND);
+       EDA_INST_ADD_COMPONENT(f, R1,    SCF_EDA_Resistor);
+       EDA_INST_ADD_COMPONENT(f, R2,    SCF_EDA_Resistor);
+
+       EDA_INST_ADD_COMPONENT(f, Rs, SCF_EDA_Resistor);
+       EDA_INST_ADD_COMPONENT(f, Ls, SCF_EDA_Inductor);
+       EDA_INST_ADD_COMPONENT(f, Cs, SCF_EDA_Capacitor);
+
+       EDA_INST_ADD_COMPONENT(f, C1, SCF_EDA_Capacitor);
+       EDA_INST_ADD_COMPONENT(f, C2, SCF_EDA_Capacitor);
+
+       EDA_PIN_ADD_PIN(B,    SCF_EDA_Battery_POS,  NAND, SCF_EDA_NAND_POS);
+       EDA_PIN_ADD_PIN(B,    SCF_EDA_Battery_NEG,  NAND, SCF_EDA_NAND_NEG);
+
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_IN0,     NAND, SCF_EDA_NAND_IN1);
+
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_OUT,   R1, 1);
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_IN0,   R1, 0);
+
+       EDA_PIN_ADD_PIN(Rs, 0,                    Ls, 1);
+       EDA_PIN_ADD_PIN(Ls, 0,                    Cs, 1);
+
+       EDA_PIN_ADD_PIN(Rs, 1,                    C2, 1);
+       EDA_PIN_ADD_PIN(Cs, 0,                    C1, 1);
+       EDA_PIN_ADD_PIN(C1, 0,                    C2, 0);
+       EDA_PIN_ADD_PIN(C1, 0,                    B,  SCF_EDA_Battery_NEG);
+
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_OUT,   R2, 1);
+       EDA_PIN_ADD_PIN(R2,   0,                  Rs, 1);
+       EDA_PIN_ADD_PIN(NAND, SCF_EDA_NAND_IN0,   Cs, 0);
+
+       NAND->pins[SCF_EDA_NAND_OUT]->flags |= SCF_EDA_PIN_OUT;
+
+       B->v   = 5;
+
+       R1->r  = 1000 * 1000;
+       R2->r  = 1000;
+
+       Rs->r  = 5;
+       Ls->r  = 1;
+       Cs->r  = 1;
+       Ls->uh = 1000;
+       Cs->uf = 22e-6;
+
+       C1->uf = 0.001;
+       C2->uf = 0.001;
+
+       scf_eboard__add_function(b, f);
+
+       long     len = 0;
+       uint8_t* buf = NULL;
+
+       ScfEboard_pack(b, &buf, &len);
+       ScfEboard_free(b);
+       b = NULL;
+
+       FILE* fp = fopen("./crystal_NAND.cpk", "wb");
+       if (!fp)
+               return -EINVAL;
+
+       fwrite(buf, len, 1, fp);
+       fclose(fp);
+       return 0;
+}
index c4f97b8633ea819fc01a8275b79d73161a819ec0..44c331014e083620fe61ed05138d34a5064ba439 100644 (file)
@@ -9,7 +9,7 @@
 #define REAL(z,i) ((z)[2*(i)])
 #define IMAG(z,i) ((z)[2*(i)+1])
 
-#define N 512
+#define N 1024
 
 int main()
 {
@@ -25,12 +25,12 @@ int main()
        cairo_surface_t* surface;
        cairo_t*         cr;
 
-       surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1200, 720);
+       surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, N + 100, 720);
        cr      = cairo_create (surface);
 
        cairo_set_line_width(cr, 2);
        cairo_set_source_rgb(cr, 1, 1, 1);
-       cairo_rectangle     (cr, 0, 0, 1280, 720);
+       cairo_rectangle     (cr, 0, 0, N + 100, 720);
        cairo_fill(cr);
        cairo_stroke(cr);
 
@@ -42,9 +42,10 @@ int main()
        double s  = 0.0;
        double min = 10.0;
        double max = 0.0;
+       char   c   = 0;
 
        for (i = 0; i < N; i++) {
-               fscanf(fp, "%d, %lg", &j, &v);
+               fscanf(fp, "%c, %d, %lg", &c, &j, &v);
 
                REAL(data, i) = v;
                IMAG(data, i) = 0.0;
@@ -57,21 +58,33 @@ int main()
                        if (min > v)
                                min = v;
 
-                       cairo_move_to(cr, 40 + 1 * (i - 1), 300 - 20 * v0);
-                       cairo_line_to(cr, 40 + 1 * i,       300 - 20 * v);
-                       cairo_stroke(cr);
-
                        s += v;
                }
                v0 = v;
 #endif
        }
 
-       cairo_move_to(cr,   20, 300 - 10 * (max + min));
-       cairo_line_to(cr, 1200, 300 - 10 * (max + min));
+       double avg = (max + min) / 2;
+       double pix = 100.0 / (max - min);
+
+       fseek(fp, 0, SEEK_SET);
+       for (i = 0; i < N; i++) {
+               fscanf(fp, "%c, %d, %lg", &c, &j, &v);
+
+               if (i > 1 && i < N) {
+                       cairo_move_to(cr, 40 + 1 * (i - 1), 300 - pix * (v0 - avg));
+                       cairo_line_to(cr, 40 + 1 * i,       300 - pix * (v - avg));
+                       cairo_stroke(cr);
+               }
+
+               v0 = v;
+       }
+
+       cairo_move_to(cr,     20, 300);
+       cairo_line_to(cr, N + 80, 300);
        cairo_stroke(cr);
 
-       printf("avg: %lg, max: %lg, min: %lg, 300 - 10 * (max + min): %lg\n", (max + min) / 2, max, min, 300 - 10 * (max + min));
+       printf("avg: %lg, max: %lg, min: %lg, pix: %lg/%lg\n", avg, max, min, pix, max - min);
 
        cairo_surface_write_to_png(surface, "sin.png");
 
@@ -104,7 +117,7 @@ int main()
                printf("%d, %lg %lg\n", i, REAL(data, i) / sqrt(N), IMAG(data, i) / sqrt(N));
        }
 
-       double f = 1000 * 1000 * imax / N;
+       double f = 2000.0 * 1e6 * imax / N;
 
        printf("avg: %lg, Zmax: %lg, imax: %d, f: %lg\n", sum / (N - 1), Zmax, imax, f);
 
diff --git a/test/test.c b/test/test.c
deleted file mode 100644 (file)
index 6c2816f..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include"ses_core.h"
-
-int main(int argc, char* argv[])
-{
-       ScfEcomponent* B;
-
-       ScfEcomponent* R0;
-       ScfEcomponent* T0;
-       ScfEcomponent* R1;
-       ScfEcomponent* R2;
-
-       ScfEfunction*  f;
-       ScfEboard*     b;
-
-       b = scf_eboard__alloc();
-       f = scf_efunction__alloc("sin_oscillator");
-
-       EDA_INST_ADD_COMPONENT(f, B,  SCF_EDA_Battery);
-
-       B->pins[SCF_EDA_Battery_NEG]->flags = SCF_EDA_PIN_NEG;
-       B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS;
-
-       EDA_INST_ADD_COMPONENT(f, R0, SCF_EDA_Resistor);
-       EDA_INST_ADD_COMPONENT(f, T0, SCF_EDA_NPN);
-       EDA_INST_ADD_COMPONENT(f, R1, SCF_EDA_Resistor);
-       EDA_INST_ADD_COMPONENT(f, R2, SCF_EDA_Resistor);
-
-       EDA_PIN_ADD_PIN(B,  SCF_EDA_Battery_POS,  R0, 1);
-       EDA_PIN_ADD_PIN(B,  SCF_EDA_Battery_POS,  R1, 1);
-
-       EDA_PIN_ADD_PIN(R0, 0,                    T0, SCF_EDA_NPN_B);
-       EDA_PIN_ADD_PIN(R1, 0,                    T0, SCF_EDA_NPN_C);
-       EDA_PIN_ADD_PIN(T0, SCF_EDA_NPN_E,        R2, 1);
-       EDA_PIN_ADD_PIN(R2, 0,                    B,  SCF_EDA_Battery_NEG);
-
-       T0->pins[SCF_EDA_NPN_C]->flags |= SCF_EDA_PIN_OUT;
-       T0->pins[SCF_EDA_NPN_C]->hfe    = 80;
-
-       R0->r  = 1000 * 10;
-       R1->r  = 1000;
-       R2->r  = 100;
-
-       scf_eboard__add_function(b, f);
-
-       int      len = 0;
-       uint8_t* buf = NULL;
-
-       ScfEboard_pack(b, &buf, &len);
-       ScfEboard_free(b);
-       b = NULL;
-
-       FILE* fp = fopen("./test.cpk", "wb");
-       if (!fp)
-               return -EINVAL;
-
-       fwrite(buf, len, 1, fp);
-       fclose(fp);
-
-       return 0;
-}
diff --git a/test/v.txt b/test/v.txt
deleted file mode 100644 (file)
index 539ce0a..0000000
+++ /dev/null
@@ -1,522 +0,0 @@
-0, 2.13208
-1, 2.38949
-2, 2.23283
-3, 2.48285
-4, 2.45575
-5, 2.56437
-6, 2.68932
-7, 2.5387
-8, 2.54218
-9, 2.53663
-10, 2.64899
-11, 2.68221
-12, 2.62339
-13, 2.80192
-14, 2.75316
-15, 2.74723
-16, 2.67439
-17, 2.95593
-18, 2.64538
-19, 2.9787
-20, 2.73434
-21, 2.93464
-22, 2.86214
-23, 2.75561
-24, 2.76333
-25, 2.94852
-26, 2.89052
-27, 3.00143
-28, 3.04008
-29, 2.95826
-30, 2.95658
-31, 2.88063
-32, 3.0633
-33, 3.10414
-34, 3.12577
-35, 3.03991
-36, 3.22946
-37, 3.30166
-38, 3.28851
-39, 3.11064
-40, 3.28833
-41, 3.30982
-42, 3.14457
-43, 3.20641
-44, 3.12846
-45, 3.31886
-46, 3.36288
-47, 3.28914
-48, 3.19167
-49, 3.36793
-50, 3.30324
-51, 3.40888
-52, 3.33287
-53, 3.24033
-54, 3.31515
-55, 3.34863
-56, 3.26273
-57, 3.16493
-58, 3.34007
-59, 3.36206
-60, 3.45495
-61, 3.50641
-62, 3.4254
-63, 3.60361
-64, 3.4665
-65, 3.63286
-66, 3.46455
-67, 3.4569
-68, 3.64808
-69, 3.57349
-70, 3.68024
-71, 3.60285
-72, 3.50104
-73, 3.68119
-74, 3.61525
-75, 3.62188
-76, 3.72188
-77, 3.75517
-78, 3.85025
-79, 3.6848
-80, 3.75468
-81, 3.76599
-82, 3.87205
-83, 3.70659
-84, 3.7928
-85, 3.80258
-86, 3.78763
-87, 3.90154
-88, 3.92385
-89, 3.94793
-90, 3.86628
-91, 4.04405
-92, 3.97506
-93, 3.80208
-94, 3.92942
-95, 3.63662
-96, 3.75362
-97, 3.93322
-98, 3.98091
-99, 4.08843
-100, 4.09603
-101, 4.01992
-102, 4.02927
-103, 4.10356
-104, 4.04043
-105, 4.01904
-106, 4.11779
-107, 3.98382
-108, 4.12752
-109, 4.13555
-110, 3.98075
-111, 4.06033
-112, 4.23588
-113, 4.0027
-114, 4.14337
-115, 3.90923
-116, 4.03169
-117, 3.96853
-118, 4.15831
-119, 4.16498
-120, 4.09948
-121, 4.08805
-122, 3.99892
-123, 4.00233
-124, 4.16627
-125, 4.30389
-126, 4.30386
-127, 4.24722
-128, 4.21934
-129, 4.11948
-130, 4.19074
-131, 4.37842
-132, 4.43089
-133, 4.36509
-134, 4.26449
-135, 4.33731
-136, 4.34222
-137, 4.3638
-138, 4.43991
-139, 4.37073
-140, 4.37363
-141, 4.3743
-142, 4.54416
-143, 4.4651
-144, 4.37942
-145, 4.37692
-146, 3.8804
-147, 4.58595
-148, 4.44275
-149, 4.48275
-150, 4.31009
-151, 4.38659
-152, 4.51879
-153, 4.4928
-154, 4.49271
-155, 4.33285
-156, 4.54341
-157, 4.49648
-158, 4.49245
-159, 4.57774
-160, 4.51809
-161, 4.59196
-162, 4.59082
-163, 4.51811
-164, 4.56934
-165, 4.44416
-166, 4.57492
-167, 4.52176
-168, 4.69915
-169, 4.61404
-170, 4.61289
-171, 4.66836
-172, 4.69716
-173, 4.54284
-174, 4.67514
-175, 4.68925
-176, 4.50114
-177, 4.51755
-178, 4.56938
-179, 4.75097
-180, 4.70176
-181, 4.49848
-182, 4.57626
-183, 4.67455
-184, 4.77866
-185, 4.70609
-186, 4.56724
-187, 4.75278
-188, 4.85325
-189, 4.63563
-190, 4.77179
-191, 4.78467
-192, 4.94007
-193, 4.96517
-194, 4.90686
-195, 4.35706
-196, 4.97794
-197, 4.96305
-198, 4.90907
-199, 4.98106
-200, 4.88974
-201, 4.98652
-202, 4.82007
-203, 4.93275
-204, 4.80944
-205, 4.24273
-206, 4.55276
-207, 4.71837
-208, 4.94968
-209, 4.94702
-210, 4.98662
-211, 4.97586
-212, 4.9887
-213, 4.9838
-214, 4.98066
-215, 4.98867
-216, 5.0318
-217, 4.98604
-218, 4.96149
-219, 4.9851
-220, 5.02289
-221, 4.9239
-222, 4.97783
-223, 4.98925
-224, 4.98781
-225, 5.08306
-226, 5.01137
-227, 4.98713
-228, 5.07848
-229, 5.00943
-230, 5.07552
-231, 5.00222
-232, 4.99044
-233, 4.98971
-234, 4.92488
-235, 4.93332
-236, 4.98987
-237, 4.81875
-238, 4.58579
-239, 4.5947
-240, 4.36254
-241, 4.29727
-242, 4.38218
-243, 4.28025
-244, 4.21077
-245, 4.18975
-246, 4.20901
-247, 4.21188
-248, 4.0726
-249, 3.9696
-250, 3.61913
-251, 3.5383
-252, 3.5628
-253, 3.43792
-254, 3.44152
-255, 3.49177
-256, 3.43107
-257, 3.38868
-258, 3.39343
-259, 3.35427
-260, 3.35321
-261, 3.36823
-262, 3.34709
-263, 3.3686
-264, 3.36832
-265, 3.32954
-266, 3.31812
-267, 3.31688
-268, 3.33872
-269, 3.28546
-270, 3.26747
-271, 3.25683
-272, 3.23746
-273, 2.8825
-274, 3.35591
-275, 3.28977
-276, 3.22464
-277, 3.21837
-278, 3.21489
-279, 3.20853
-280, 3.22325
-281, 3.21249
-282, 3.18781
-283, 3.16809
-284, 3.11347
-285, 3.15598
-286, 3.14428
-287, 3.18223
-288, 2.81148
-289, 3.37431
-290, 3.26587
-291, 3.2213
-292, 3.2213
-293, 3.20903
-294, 3.21861
-295, 3.21398
-296, 3.22911
-297, 3.22585
-298, 3.26204
-299, 3.22098
-300, 3.19378
-301, 3.20361
-302, 3.19584
-303, 3.21097
-304, 3.2821
-305, 3.21143
-306, 3.22281
-307, 3.21044
-308, 3.25118
-309, 3.17331
-310, 3.19443
-311, 3.21125
-312, 3.20545
-313, 3.26406
-314, 3.28707
-315, 3.28584
-316, 3.28617
-317, 3.22017
-318, 3.19896
-319, 3.19874
-320, 2.50462
-321, 3.39303
-322, 3.3438
-323, 3.36115
-324, 3.30999
-325, 3.31346
-326, 3.28987
-327, 3.27508
-328, 3.27076
-329, 3.26712
-330, 3.34476
-331, 3.35874
-332, 3.36514
-333, 3.24859
-334, 3.27504
-335, 3.3592
-336, 3.36832
-337, 3.30345
-338, 3.33376
-339, 3.33151
-340, 3.34543
-341, 3.38261
-342, 3.34998
-343, 3.36194
-344, 3.3355
-345, 3.38855
-346, 3.3875
-347, 3.41735
-348, 3.39603
-349, 3.40963
-350, 3.38779
-351, 3.39266
-352, 3.42148
-353, 3.41006
-354, 3.43749
-355, 3.39357
-356, 3.41801
-357, 3.44995
-358, 3.45555
-359, 3.42421
-360, 3.4234
-361, 3.42321
-362, 3.42555
-363, 3.33314
-364, 3.41304
-365, 3.43145
-366, 3.43935
-367, 3.41391
-368, 3.44901
-369, 3.3337
-370, 3.39442
-371, 3.3528
-372, 3.35754
-373, 3.37209
-374, 3.38392
-375, 3.38039
-376, 3.40601
-377, 3.41786
-378, 3.41785
-379, 3.46041
-380, 3.54033
-381, 3.52695
-382, 3.52783
-383, 3.57498
-384, 1.32579
-385, 3.6227
-386, 3.63638
-387, 3.64581
-388, 3.60546
-389, 3.59556
-390, 3.62466
-391, 3.62134
-392, 3.67367
-393, 3.68761
-394, 3.67741
-395, 3.66349
-396, 3.65938
-397, 3.61752
-398, 3.61494
-399, 3.61835
-400, 3.63379
-401, 3.63969
-402, 3.64895
-403, 3.67198
-404, 2.68957
-405, 4.03279
-406, 4.02441
-407, 2.79805
-408, 4.11949
-409, 4.04118
-410, 4.08086
-411, 3.9476
-412, 1.78051
-413, 1.68485
-414, 3.96256
-415, 3.98327
-416, 3.99431
-417, 4.00565
-418, 3.98249
-419, 4.04517
-420, 3.99148
-421, 4.0322
-422, 4.03997
-423, 4.06094
-424, 2.89884
-425, 4.22268
-426, 4.04922
-427, 2.95748
-428, 3.96907
-429, 4.09722
-430, 4.06566
-431, 2.86896
-432, 3.94281
-433, 4.0211
-434, 4.03518
-435, 3.97858
-436, 3.9948
-437, 3.98346
-438, 4.00065
-439, 4.02364
-440, 4.03978
-441, 4.07175
-442, 4.09056
-443, 2.0118
-444, 2.16126
-445, 2.03352
-446, 2.50013
-447, 3.1259
-448, 2.74588
-449, 3.29986
-450, 2.77648
-451, 2.94137
-452, 2.91157
-453, 3.00271
-454, 2.81717
-455, 3.5262
-456, 3.6481
-457, 2.95621
-458, 3.0557
-459, 2.94417
-460, 3.07852
-461, 3.44557
-462, 3.24696
-463, 3.2518
-464, 3.41009
-465, 3.61717
-466, 4.28662
-467, 5.6578
-468, 4.6118
-469, 4.67737
-470, 4.25566
-471, 3.98123
-472, 3.7769
-473, 5.18243
-474, 5.45351
-475, 4.88072
-476, 4.59733
-477, 4.88371
-478, 4.89936
-479, 4.90935
-480, 4.64011
-481, 4.96066
-482, 4.97311
-483, 4.36167
-484, 5.41538
-485, 3.43685
-486, 5.42988
-487, 3.16915
-488, 3.79269
-489, 4.99028
-490, 4.89835
-491, 3.96859
-492, 4.42669
-493, 4.20309
-494, 4.90677
-495, 4.32589
-496, 3.34028
-497, 4.92968
-498, 4.94964
-499, 3.18155
-500, 4.27806
-501, 4.9805
-502, 4.98025
-503, 4.9881
-504, 3.214
-505, 4.06582
-506, 3.25406
-507, 3.23653
-508, 4.97834
-509, 4.42907
-510, 4.95403
-511, 4.23166
-512, 4.93361
-513, 4.60094
-514, 4.40375
-515, 4.65495
-516, 4.57164
-517, 4.85458
-518, 5.00691
-519, 4.92807
-520, 4.85648
-521, 4.90386