--------------------------------------------------------- */
| 1783 | |
| 1784 | /* --------------------------------------------------------- */ |
| 1785 | void cmaes_ReadFromFilePtr(cmaes_t *t, FILE *fp) { |
| 1786 | /* reading commands e.g. from signals.par file |
| 1787 | */ |
| 1788 | const char *keys[15]; |
| 1789 | char s[199], sin1[99], sin2[129], sin3[99], sin4[99]; |
| 1790 | int ikey, ckeys, nb; |
| 1791 | double d; |
| 1792 | static int flglockprint = 0; |
| 1793 | static int flglockwrite = 0; |
| 1794 | static long countiterlastwritten; |
| 1795 | static long maxdiffitertowrite; /* to prevent long gaps at the beginning */ |
| 1796 | int flgprinted = 0; |
| 1797 | int flgwritten = 0; |
| 1798 | double deltaprinttime = time(nullptr) - t->printtime; /* using clock instead might not be a good */ |
| 1799 | double deltawritetime = time(nullptr) - t->writetime; /* idea as disc time is not CPU time? */ |
| 1800 | double deltaprinttimefirst = |
| 1801 | t->firstprinttime ? time(nullptr) - t->firstprinttime : 0; /* time is in seconds!? */ |
| 1802 | double deltawritetimefirst = t->firstwritetime ? time(nullptr) - t->firstwritetime : 0; |
| 1803 | |
| 1804 | if (countiterlastwritten > t->gen) { /* probably restarted */ |
| 1805 | maxdiffitertowrite = 0; |
| 1806 | countiterlastwritten = 0; |
| 1807 | } |
| 1808 | |
| 1809 | keys[0] = " stop%98s %98s"; /* s=="now" or eg "MaxIter+" %lg"-number */ |
| 1810 | /* works with and without space */ |
| 1811 | keys[1] = " print %98s %98s"; /* s==keyword for WriteFile */ |
| 1812 | keys[2] = " write %98s %128s %98s"; /* s1==keyword, s2==filename */ |
| 1813 | keys[3] = " check%98s %98s"; |
| 1814 | keys[4] = " maxTimeFractionForEigendecompostion %98s"; |
| 1815 | ckeys = 5; |
| 1816 | strcpy(sin2, "tmpcmaes.dat"); |
| 1817 | |
| 1818 | if (cmaes_TestForTermination(t)) { |
| 1819 | deltaprinttime = time(nullptr); /* forces printing */ |
| 1820 | deltawritetime = time(nullptr); |
| 1821 | } |
| 1822 | |
| 1823 | while (fgets(s, sizeof(s), fp) != nullptr) { |
| 1824 | if (s[0] == '#' || s[0] == '%') { /* skip comments */ |
| 1825 | continue; |
| 1826 | } |
| 1827 | |
| 1828 | sin1[0] = sin2[0] = sin3[0] = sin4[0] = '\0'; |
| 1829 | |
| 1830 | for (ikey = 0; ikey < ckeys; ++ikey) { |
| 1831 | if ((nb = sscanf(s, keys[ikey], sin1, sin2, sin3, sin4)) >= 1) { |
| 1832 | switch (ikey) { |
| 1833 | case 0: /* "stop", reads "stop now" or eg. stopMaxIter */ |
| 1834 | if (strncmp(sin1, "now", 3) == 0) { |
| 1835 | t->flgStop = 1; |
| 1836 | } else if (strncmp(sin1, "MaxFunEvals", 11) == 0) { |
| 1837 | if (sscanf(sin2, " %lg", &d) == 1) { |
| 1838 | t->sp.stopMaxFunEvals = d; |
| 1839 | } |
| 1840 | } else if (strncmp(sin1, "MaxIter", 4) == 0) { |
| 1841 | if (sscanf(sin2, " %lg", &d) == 1) { |
| 1842 | t->sp.stopMaxIter = d; |
no test coverage detected