gnuplot

how to contourplot inside a do-loop with different contour levels at each loop


I've got three meteo entries in a file; then, a 4th entry which is the date, in seconds since Jan 1 1970, in which the previous three entries have been simultaneously encountered. The dates encompass the period from July 2022 to October 2024.

I need to contourplot them by month: that is, for each month of that whole period, I should contouplot the first three rows (x-y-z) of the file.

If I just contourplot any month of that July-2022-to-October-2024 span, everything goes well. I can even tune the contour levels so they fit best the range of those 3 meteo parameters in that particular month.

Now if I do the same but inside a do-loop that goes from July 2022 to October 2024, month by month, I get an error message: "expecting discrete level" (with gnuplot 6.1)

If I remove the two do-loops and I substitute them for just any value of the loop variables, everything works to perfection.

My datafile "datos.txt" (reduced) is this:

 5.3     33  0.5     1695735900
 5.3     33.1    0.6     1659030300
 5.3     34  0.5     1663335900
 5.3     34.1    0.7     1684682100
 5.3     36  1   1691343900
 5.3     37  1   1690904700
 5.3     38  0   1675872900
 5.3     38.1    0.2     1667573100
 5.3     39  0.4     1678191300
 5.3     40  0.6     1664639100
 5.3     40.1    1.1     1715868900
 5.3     40.2    0.3     1704978900
 5.3     41  0.7     1683558900
 5.3     41.1    0.7     1727183700
 5.3     41.2    0.6     1727358300
 5.3     42  0.4     1697373900
 5.3     42.1    0.9     1717150500
 5.3     42.2    0.1     1700633700
 5.3     43  0.6     1683562500
 5.3     45  0.4     1681389900
 5.3     47  0.6     1683114300
 5.3     48  0.2     1704802500
 5.3     49  0.2     1700613900
 5.3     49.1    0   1677512700
 5.3     49.2    0.2     1705668300
 5.3     50  0   1677613500
 5.3     50.1    0.3     1709207100
 5.3     50.2    0.2     1669823100
 5.3     51  0.3     1673268300
 5.3     51.1    0.2     1698770700
 5.3     51.2    0.3     1698416100
 5.3     52  0.7     1695392100
 5.3     52.1    0.5     1678279500
 5.3     56  0.2     1669729500
 5.3     56.1    0.2     1727388900
 5.3     56.2    0.5     1684235700
 5.3     59  0   1677483900
 5.3     59.1    0   1698390900
 5.3     63  0.1     1702498500
 5.3     67  0   1677401100
 5.3     80  0   1699148700
 5.4     17  1.1     1689774300
 5.4     17.1    1   1658594700
 5.4     17.2    0.6     1692630900
 5.4     19  0.6     1680617700
 5.4     22  0.5     1680536700
 5.4     23  0.6     1694097900
 5.4     23.1    0.8     1687614300
 5.4     24  0.5     1680540300
 5.4     25  0.4     1680543900
 5.4     26  0.3     1680606900
 5.4     26.1    0.5     1694087100
 5.4     26.2    0.8     1658600100
 5.4     27  0   1675682100
 5.4     27.1    0.5     1687603500
 5.4     27.2    0.6     1663758900
 5.4     27.3    0.5     1663767900
 5.4     27.4    0.6     1685360700
 5.4     27.5    0.6     1685447100
 5.4     28  0.5     1659878100
 5.4     28.1    0.3     1700750700
 5.4     30  0.6     1712846700
 5.4     30.1    0.6     1695654900
 5.4     30.2    0.6     1685376900
 5.4     31  0   1675775700
 5.4     32  0.5     1715271300
 5.4     32.1    0.5     1712850300
 5.4     34  0.5     1680515100
 5.4     34.1    0.6     1684685700
 5.4     34.2    0   1675959300
 5.4     34.3    1.1     1690728300
 5.4     34.4    0.1     1705013100
 5.4     35  0.1     1705011300
 5.4     35.1    0.4     1680974100
 5.4     36  0.3     1680435900
 5.4     37  0.4     1681638300
 5.4     38  0.2     1693953900
 5.4     38.1    0.4     1682867700
 5.4     38.2    1.1     1690735500
 5.4     38.3    1   1713271500
 5.4     39  0.3     1704980700
 5.4     39.1    0.5     1684406700
 5.4     39.2    0   1675935900
 5.4     39.3    0.2     1699020900
 5.4     39.4    0.3     1659863700
 5.4     40  0.6     1727518500
 5.4     40.1    0.7     1724168700
 5.4     41  0.4     1664284500
 5.4     41.1    0.1     1700676900
 5.4     41.2    0.5     1726569900
 5.4     42  0.2     1700657100
 5.4     42.1    0.5     1683132300
 5.4     42.2    0.3     1697471100
 5.4     43  0.8     1686150900
 5.4     43.1    0.4     1695550500
 5.4     43.2    0.6     1711642500
 5.4     43.3    0.2     1700631900
 5.4     44  0.4     1695552300
 5.4     45  0.4     1684331100
 5.4     45.1    0.3     1669902300
 5.4     45.2    0.2     1669805100
 5.4     47  0.1     1705711500
 5.4     47.1    0.2     1669814100
 5.4     48  0.7     1695384900
 5.4     48.1    0.4     1684336500
 5.4     49  0.4     1684332900
 5.4     49.1    0.5     1683110700
 5.4     49.2    0.3     1709212500
 5.4     50  0.6     1683108900
 5.4     50.1    0   1677611700
 5.4     50.2    0.2     1704899700
 5.4     51  1.3     1663253100
 5.4     51.1    0.4     1663258500
 5.4     52  0.5     1683022500
 5.4     52.1    0.4     1682945100
 5.4     52.2    0.6     1715874300
 5.4     52.3    0   1677438900
 5.4     54  0.2     1726155900
 5.4     55  0.2     1678445100
 5.4     55.1    0   1677433500
 5.4     55.2    0.4     1710065700
 5.4     56  0.1     1699217100
 5.4     56.1    0.3     1663262100
 5.4     57  0.2     1701526500
 5.4     58  0.2     1698929100
 5.4     59  0.4     1678457700
 5.4     60  0.4     1684239300
 5.5     12  0.4     1679939100
 5.5     13  0.3     1700919900
 5.5     18  0.5     1657300500
 5.5     20  0.6     1660139100
 5.5     22  0.5     1657282500
 5.5     22.1    0.6     1694099700
 5.5     24  1.1     1656868500
 5.5     24.1    0.6     1687612500
 5.5     24.2    0.6     1715345100
 5.5     25  0.5     1694018700
 5.5     25.1    0.8     1715350500
 5.5     25.2    0.6     1693932300
 5.5     26  0.7     1685364300
 5.5     26.1    0.6     1694006100
 5.5     27  0.6     1687601700
 5.5     28  0.2     1700745300
 5.5     28.1    0.6     1685459700
 5.5     28.2    0.6     1685450700
 5.5     28.3    0   1675779300
 5.5     29  0.7     1685456100
 5.5     29.1    0.1     1700752500
 5.5     30  1.2     1718374500
 5.5     30.1    0.6     1723578300
 5.5     31  0.5     1680516900
 5.5     32  0.7     1712065500
 5.5     32.1    1.4     1693235700
 5.5     32.2    1   1690292700
 5.5     32.3    0.4     1698506100
 5.5     33  0.4     1659192300
 5.5     33.1    0.5     1726236900
 5.5     36  0.3     1681636500
 5.5     37  0.2     1702737900
 5.5     37.1    0.5     1682862300
 5.5     38  0.4     1662718500
 5.5     38.1    0   1675768500
 5.5     39  0.1     1699271100
 5.5     39.1    0.8     1713267900
 5.5     40  0.5     1663343100
 5.5     40.1    0   1675856700
 5.5     41  0.5     1695725100
 5.5     41.1    0.5     1664288100
 5.5     41.2    0.8     1716399900
 5.5     41.3    0.6     1683130500
 5.5     41.4    0.1     1700675100
 5.5     42  0.4     1726836300
 5.5     44  0.1     1700639100
 5.5     44.1    0.9     1714749300
 5.5     45  -0.2    1701483300
 5.5     46  0.1     1699001100
 5.5     46.1    0.1     1704748500
 5.5     47  0.2     1709203500
 5.5     47.1    0.5     1664466300
 5.5     47.2    0.4     1678284900
 5.5     48  0.5     1683112500
 5.5     49  0.9     1686329100
 5.5     49.1    0.5     1726152300
 5.5     49.2    0.4     1684341900
 5.5     50  0.4     1709210700
 5.5     51  0.2     1705689900
 5.5     53  0   1677626100
 5.5     53.1    0.5     1683105300
 5.5     54  0.1     1669830300
 5.5     54.1    0.1     1729439100
 5.5     55  0.4     1684323900
 5.5     58  0.3     1684246500
 5.5     61  0.1     1704338100
 5.5     63  0.2     1704330900
 5.5     66  0.1     1698986700
 5.5     66.1    0.4     1663406100
 5.5     69  0   1699163100
 5.5     70  0   1677417300
 5.5     70.1    0   1677415500
 5.5     70.2    0   1699141500
 5.6     18  1.1     1658596500
 5.6     20  0.6     1680696900
 5.6     21  1.1     1690037100
 5.6     22  1   1690038900
 5.6     23  0.5     1678891500
 5.6     25  0.6     1687608900
 5.6     25.1    0.6     1715343300
 5.6     25.2    0   1675712700
 5.6     26  0.5     1663769700
 5.6     26.1    0   1675683900
 5.6     27  0   1675781100
 5.6     27.1    0   1675685700
 5.6     27.2    0.6     1693831500
 5.6     28  0.5     1694000700
 5.6     28.1    0.7     1685452500
 5.6     28.2    0.5     1680608700
 5.6     28.3    0.2     1700748900
 5.6     29  0.5     1659876300
 5.6     29.1    0.3     1705761900
 5.6     30  0.8     1662740100
 5.6     30.1    0   1675714500
 5.6     30.2    0.5     1662723900
 5.6     32  0.6     1685540700
 5.6     32.1    0.7     1663334100
 5.6     33  0.4     1698504300
 5.6     33.1    0.6     1684683900
 5.6     33.2    0   1675943100
 5.6     33.3    1   1690301700
 5.6     34  0.2     1680565500
 5.6     34.1    0.4     1681640100
 5.6     34.2    0.5     1662720300
 5.6     35  1.4     1693237500
 5.6     37  1.2     1717166700
 5.6     38  0.7     1681382700
 5.6     38.1    0.8     1713273300
 5.6     39  0.3     1697462100
 5.6     39.1    0.3     1680509700
 5.6     39.2    1.1     1691342100
 5.6     39.3    1.1     1691340300
 5.6     40  0.4     1697465700
 5.6     40.1    0.3     1697463900
 5.6     40.2    0.5     1684424700
 5.6     40.3    0.3     1677860100
 5.6     40.4    0   1675858500
 5.6     40.5    0   1704986100
 5.6     41  0.3     1713635100
 5.6     41.1    0.2     1659825900
 5.6     41.2    0.6     1683557100
 5.6     42  0.6     1683123300
 5.6     42.1    0.2     1700653500
 5.6     42.2    0.5     1682849700
 5.6     43  1.2     1727352900
 5.6     44  0.3     1664280900
 5.6     44.1    0.8     1716306300
 5.6     44.2    0.6     1727180100
 5.6     45  0.3     1669810500
 5.6     45.1    0.3     1669900500
 5.6     47  0.3     1698749100
 5.6     47.1    0.5     1697814900
 5.6     49  0.2     1704896100
 5.6     50  0.2     1704897900
 5.6     51  -0.1    1708692300
 5.6     52  0   1677554100
 5.6     53  0.3     1726148700
 5.6     55  0.1     1699213500
 5.6     55.1    0.3     1726146900
 5.6     55.2    0.1     1699215300
 5.6     56  0.1     1698932700
 5.6     56.1    0.2     1709140500
 5.6     56.2    0.1     1698396300
 5.6     60  0.1     1663416900
 5.6     60.1    0   1697777100
 5.7     11  0.5     1679935500
 5.7     21  0.4     1713357900
 5.7     25  0.5     1694088900
 5.7     25.1    0.6     1693916100
 5.7     26  0   1675782900
 5.7     28  0.7     1685373300
 5.7     28.1    0.5     1680522300
 5.7     28.2    0.6     1695816900
 5.7     29  0.3     1680599700
 5.7     29.1    0.5     1695829500
 5.7     30  0.7     1685538900
 5.7     32  0   1675773900
 5.7     33  0.4     1712853900
 5.7     33.1    0.2     1680567300
 5.7     33.2    0.5     1685544300
 5.7     33.3    1.1     1719074700
 5.7     34  0.3     1698500700
 5.7     34.1    0.3     1657228500
 5.7     34.2    0.6     1715262300
 5.7     35  0.8     1690308900
 5.7     36  0.2     1681114500
 5.7     37  0.9     1713269700
 5.7     37.1    0.6     1688658300
 5.7     38  0.3     1680439500
 5.7     39  0.4     1695636900
 5.7     39.1    0.3     1677858300
 5.7     40  0.2     1704984300
 5.7     41  0.4     1678898700
 5.7     41.1    0.4     1678031100
 5.7     41.2    0.5     1726571700
 5.7     42  0.4     1726577100
 5.7     42.1    0.2     1700655300
 5.7     43  0.2     1700648100
 5.7     43.1    0.1     1711649700
 5.7     44  0.4     1684401300
 5.7     44.1    0.2     1700637300
 5.7     44.2    1   1682343900
 5.7     48  0.2     1677766500
 5.7     48.1    0.1     1700885700
 5.7     48.2    0.2     1669821300
 5.7     49  0.2     1699179300
 5.7     49.1    0.3     1677762900
 5.7     49.2    0.3     1704714300
 5.7     50  0.3     1684340100
 5.7     51  0.3     1698763500
 5.7     52  0   1677624300
 5.7     52.1    0.2     1678446900
 5.7     52.2    0.4     1726143300
 5.7     54  0.4     1726667100
 5.7     55  0.1     1669828500
 5.7     58  0   1677429900
 5.7     58.1    0.3     1710063900
 5.7     59  0.3     1678455900
 5.7     72  -0.4    1698959700
 5.7     72.1    0.1     1701488700
 5.7     73  0   1699161300
 5.7     77  0   1699159500
 5.8     22  0.6     1681654500
 5.8     23  0.6     1693919700
 5.8     24  0.4     1678893300
 5.8     25  0.5     1663771500
 5.8     25.1    0.6     1694007900
 5.8     26  0.5     1694085300
 5.8     27  0.7     1685448900
 5.8     28  0.8     1685457900
 5.8     28.1    0   1675687500
 5.8     28.2    0.3     1700747100
 5.8     30  0.4     1681643700
 5.8     31  1   1690305300
 5.8     32  0.1     1702703700
 5.8     32.1    0   1675952100
 5.8     32.2    0.6     1695737700
 5.8     34  0.6     1684680300
 5.8     35  0.9     1716389100
 5.8     36  0.2     1699274700
 5.8     36.1    0.3     1698498900
 5.8     36.2    0.6     1715255100
 5.8     36.3    0.4     1724766300
 5.8     37  0.5     1682864100
 5.8     38  0.5     1663325100
 5.8     39  0   1675860300
 5.8     39.1    0.5     1715251500
 5.8     40  0.5     1682851500
 5.8     41  1   1716657300
 5.8     43  0.4     1726578900
 5.8     43.1    0.5     1678027500
 5.8     43.2    0.9     1716309900
 5.8     44  0.3     1659431700
 5.8     45  0.1     1705713300
 5.8     47  0.3     1660760100
 5.8     48  0.4     1716318900
 5.8     48.1    0.4     1678034700
 5.8     49  0   1677510900
 5.8     49.1    0   1677462300
 5.8     50  0   1677609900
 5.8     52  0.2     1664275500
 5.8     52.1    0.4     1682946900
 5.8     53  0.2     1673271900
 5.8     53.1    0   1677573900
 5.8     53.2    0.3     1683099900
 5.8     54  0   1697786100
 5.8     56  0.5     1682327700
 5.8     58  0.4     1715881500
 5.8     60  -0.5    1660337100
 5.8     60.1    0.4     1684241100
 5.8     64  0.2     1713638700
 5.8     65  0.3     1711617300
 5.8     71  0   1677411900
 5.8     73  -0.6    1728567900
 5.9     26  0   1675691100
 5.9     27  0.7     1694004300
 5.9     29  0.5     1659879900
 5.9     31  0.2     1699276500
 5.9     31.1    0.1     1702701900
 5.9     32  1.5     1693233900
 5.9     32.1    1.2     1691334900
 5.9     32.2    0.6     1662722100
 5.9     33  0   1675955700
 5.9     33.1    0.6     1685542500
 5.9     34  0.6     1684674900
 5.9     34.1    0.4     1712852100
 5.9     34.2    0.5     1684676700
 5.9     34.3    0.4     1726235100
 5.9     34.4    0   1675957500
 5.9     35  0.9     1690290900
 5.9     35.1    0.6     1682088300
 5.9     36  1.1     1690901100
 5.9     39  0.2     1704982500
 5.9     40  0.6     1727185500
 5.9     40.1    0.5     1664286300
 5.9     41  0.6     1683128700
 5.9     43  1   1682345700
 5.9     43.1    0.5     1664289900
 5.9     43.2    0.5     1664291700
 5.9     45  0.3     1659856500
 5.9     46  0.9     1716308100
 5.9     48  0.9     1711640700
 5.9     48.1    0.5     1678281300
 5.9     48.2    0.3     1709205300
 5.9     49  0.5     1726139700
 5.9     49.1    0.8     1716300900
 5.9     49.2    0.3     1726150500
 5.9     49.3    0.3     1704892500
 5.9     50  0.4     1726141500
 5.9     50.1    0   1677514500
 5.9     51  0.2     1698417900
 5.9     52  0.3     1663260300
 5.9     54  0   1677577500
 5.9     54.1    0.4     1684325700
 5.9     54.2    0.1     1669731300
 5.9     54.3    0.3     1709133300
 5.9     56  0.2     1673264700
 5.9     56.1    0.5     1718048700
 5.9     59  0.3     1684242900
 5.9     62  0.3     1682430300
 6   25  0.5     1680605100
 6   26  1   1713194100
 6   27  0.6     1694009700
 6   27.1    0.5     1681649100
 6   28  0.3     1705760100
 6   28.1    0   1675689300
 6   29  0.3     1705749300
 6   29.1    0.4     1678895100
 6   30  0.8     1690910100
 6   30.1    1.5     1693230300
 6   31  1   1690298100
 6   32  0   1675950300
 6   33  0   1675953900
 6   35  1   1716394500
 6   35.1    0.6     1684678500
 6   36  0.9     1690902900
 6   36.1    0.2     1705743900
 6   37  0.2     1693952100
 6   38  0   1675862100
 6   38.1    0   1675766700
 6   39  1.2     1717173900
 6   39.1    0.6     1682853300
 6   41  -0.5    1711289700
 6   41.1    0.3     1659861900
 6   43  0.3     1659858300
 6   43.1    0.5     1683117900
 6   44  0.2     1705706100
 6   44.1    0   1677500100
 6   45  0.2     1702763100
 6   47  0.1     1705709700
 6   47.1    0.1     1705707900
 6   47.2    0   1701512100
 6   48  0   1677460500
 6   48.1    0   1677458700
 6   48.2    0.4     1726580700
 6   49  0.2     1704894300
 6   50  0.3     1686964500
 6   50.1    0   1677516300
 6   52  0.1     1669824900
 6   52.1    0.6     1683107100
 6   53  0.2     1709131500
 6   56  0.4     1728571500
 6   62  -0.1    1663418700
 6   65  0   1677406500
 6   78  -0.5    1701495900
 6.1     22  0.6     1694096100
 6.1     23  0.6     1693926900
 6.1     24  0.5     1694090700
 6.1     27  0.6     1694002500
 6.1     30  1.2     1691689500
 6.1     30.1    0.1     1705803300
 6.1     30.2    0.3     1705747500
 6.1     31  0.6     1663332300
 6.1     32  0.6     1663330500
 6.1     33  0.6     1715265900
 6.1     33.1    0.3     1698502500
 6.1     33.2    0.6     1663328700
 6.1     33.3    0.9     1716390900
 6.1     34  0.5     1695734100
 6.1     35  0.2     1680569100
 6.1     37  0   1675863900
 6.1     39  1.1     1691338500
 6.1     41  0.5     1683125100
 6.1     45  0   1677498300
 6.1     46  0.1     1700624700
 6.1     46.1    0.4     1678283100
 6.1     48  0.3     1698412500
 6.1     49  0.7     1711637100
 6.1     50  0.2     1704890700
 6.1     51  0.4     1711291500
 6.1     52  0.2     1709216100
 6.1     53  0.4     1729433700
 6.1     55  -0.1    1698954300
 6.1     55.1    0.1     1709136900
 6.1     58  0.2     1677782700
 6.1     58.1    0.3     1678459500
 6.1     58.2    0.2     1677780900
 6.1     64  0.1     1700583300
 6.1     75  0.1     1701501300
 6.1     81  -0.3    1701499500
 6.2     20  0.5     1680698700
 6.2     22  0.5     1694101500
 6.2     23  0.6     1694094300
 6.2     24  0.7     1693928700
 6.2     24.1    0.4     1680542100
 6.2     26  0.5     1693914300
 6.2     28  0.6     1694011500
 6.2     30  0.2     1705758300
 6.2     32  0.1     1702727100
 6.2     35  0.5     1715260500
 6.2     35.1    0.2     1699272900
 6.2     36  1.2     1691336700
 6.2     37  0.4     1722690900
 6.2     38  0.8     1660580100
 6.2     38.1    0.7     1690310700
 6.2     40  0.5     1678029300
 6.2     41  0.4     1684403100
 6.2     42  0.4     1695723300
 6.2     42.1    0.6     1681384500
 6.2     43  0   1677501900
 6.2     44  0.4     1678032900
 6.2     47  0.2     1698752700
 6.2     47.1    0   1677496500
 6.2     48  0.3     1677764700
 6.2     51  0   1709493300
 6.2     52  0.4     1683024300
 6.2     53  0.1     1698939900
 6.2     55  0.2     1698934500
 6.2     55.1    0.8     1716295500
 6.2     58  0.3     1678450500
 6.2     64  0.2     1700579700
 6.3     18  0.2     1700909100
 6.3     22  0.5     1680533100
 6.3     23  0.5     1693923300
 6.3     23.1    0.5     1680538500
 6.3     25  0.5     1680525900
 6.3     28  0.5     1681647300
 6.3     28.1    0.5     1659966300
 6.3     30  0.2     1700743500
 6.3     30.1    0.5     1663337700
 6.3     33  0.1     1705745700
 6.3     36  0.5     1715256900
 6.3     39  0.4     1682856900
 6.3     41  0.6     1663344900
 6.3     43  0.5     1683121500
 6.3     45  0.3     1698408900
 6.3     45.1    0.5     1697813100
 6.3     47  0.8     1716302700
 6.3     50  0.4     1726582500
 6.3     50.1    0.3     1698414300
 6.3     51  0.2     1657230300
 6.3     54  0.5     1684327500
 6.3     54.1    0.8     1716297300
 6.3     55  0.3     1678466700
 6.3     56  0   1677431700
 6.3     60  -0.1    1698956100
 6.3     61  0.2     1678454100
 6.4     24  0.5     1693930500
 6.4     26  0.5     1693910700
 6.4     28  1   1690294500
 6.4     30  1   1690303500
 6.4     31  0.2     1702725300
 6.4     32  0   1675946700
 6.4     33  1.1     1690299900
 6.4     33.1    0.3     1702728900
 6.4     36  1.1     1717172100
 6.4     36.1    0.4     1663326900
 6.4     38  0.4     1682858700
 6.4     40  0.6     1723580100
 6.4     41  0.5     1683126900
 6.4     42  0.9     1716304500
 6.4     42.1    0.7     1716313500
 6.4     43  0.5     1683119700
 6.4     44  0   1677503700
 6.4     46  0.3     1698754500
 6.4     47  0   1677447900
 6.4     47.1    0.2     1669815900
 6.4     50  0.9     1716299100
 6.4     51  0.2     1673270100
 6.4     53  0.2     1698936300
 6.4     53.1    0.1     1701519300
 6.4     54  0.2     1709135100
 6.4     56  0.2     1709138700
 6.4     57  0.2     1698930900
 6.5     12  0.2     1700918100
 6.5     31  1.5     1693232100
 6.5     32  0   1675948500
 6.5     33  0.2     1702732500
 6.5     37  0.5     1682860500
 6.5     39  0.2     1699197300
 6.5     39.1    0.5     1682865900
 6.5     43  0.2     1699182900
 6.5     43.1    0.4     1716317100
 6.5     45  0.2     1669806900
 6.5     48  0   1677444300
 6.5     49  0   1677494700
 6.5     50  0.2     1698761700
 6.5     51  0   1677606300
 6.5     61  0.1     1713636900
 6.6     21  0.6     1680534900
 6.6     23  0.7     1693921500
 6.6     25  0.5     1693912500
 6.6     26  0.5     1680524100
 6.6     33  0   1675944900
 6.6     33.1    0.5     1663339500
 6.6     35  0.8     1716392700
 6.6     36  0.4     1722689100
 6.6     38  0.2     1699195500
 6.6     43  0.5     1681388100
 6.6     45  0.2     1699188300
 6.6     48  0.3     1698750900
 6.6     48.1    0.1     1705691700
 6.6     48.2    0   1677446100
 6.6     49  0.8     1727873100
 6.6     51  0.3     1677761100
 6.6     51.1    0   1677608100
 6.6     56  0.3     1678461300
 6.6     61  0.1     1701524700
 6.6     68  -0.1    1660844700
 6.6     70  0.2     1714657500
 6.6     76  0   1660594500
 6.7     25  0.5     1681650900
 6.7     30  0.6     1659026700
 6.7     36  0.5     1715258700
 6.7     37  0.2     1702736100
 6.7     38  0.4     1682855100
 6.7     41  0.6     1716315300
 6.7     42  0.1     1700630100
 6.7     43  0.2     1699190100
 6.7     51  0.3     1724787900
 6.7     54  0.1     1669826700
 6.7     58  0.4     1715877900
 6.7     58.1    0.4     1715879700
 6.7     61  -0.1    1663415100
 6.7     63  0.2     1711619100
 6.7     64  -0.2    1698957900
 6.8     33  0.2     1702730700
 6.8     41  0.9     1716311700
 6.8     43  0.1     1700628300
 6.8     46  0.2     1699200900
 6.8     51  0.8     1711635300
 6.8     52  0.2     1673266500
 6.8     52.1    0   1677579300
 6.8     53  0.3     1709217900
 6.8     53.1    0.1     1697787900
 6.8     54  0.3     1678448700
 6.8     56  0   1705682700
 6.8     69  0   1677410100
 6.9     43  0.2     1699184700
 6.9     44  0.3     1698407100
 6.9     46  0.5     1727874900
 6.9     46.1    0   1677507300
 6.9     47  0   1677509100
 6.9     52  0   1677622500
 6.9     52.1    0.4     1677773700
 6.9     55  0   1677437100
 6.9     55.1    0.4     1678464900
 6.9     61  0.1     1704336300
 7   16  0.3     1700912700
 7   33  0.2     1699019100
 7   36  0.2     1711646100
 7   44  0   1677505500
 7   48  0.3     1698410700
 7   48.1    0.3     1677768300
 7   50  0   1677581100
 7   50.1    0.3     1677770100
 7   53  1   1711631700
 7   55  0.4     1678463100
 7   56  0.1     1677779100
 7   58  0.4     1728569700
 7   61  0.5     1711622700
 7.1     48  0   1677582900
 7.1     48.1    0   1677442500
 7.1     50  0.4     1677771900
 7.1     52  0.8     1711633500
 7.1     59  0   1697778900
 7.2     16  0.3     1700910900
 7.2     23  0.5     1694092500
 7.2     39  0.2     1711647900
 7.2     40  0.7     1690188300
 7.2     44  0.1     1705700700
 7.2     44.1    0.2     1699186500
 7.2     52  0   1698941700
 7.2     52.1    0.3     1677759300
 7.3     22  0.6     1693925100
 7.3     23  0.6     1693917900
 7.3     37  0.3     1699193700
 7.3     43  0.1     1705704300
 7.3     45  0.3     1698756300
 7.3     47  0   1677584700
 7.3     48  0   1677456900
 7.3     49  0   1677455100
 7.3     53  0.3     1677775500
 7.3     59  1.1     1711628100
 7.3     62  0   1677404700
 7.4     23  0.6     1680529500
 7.4     30  0.3     1705751100
 7.4     48  0   1677449700
 7.4     49  0   1677453300
 7.4     55  1.2     1711629900
 7.4     63  0   1677402900
 7.5     23  0.5     1680531300
 7.5     33  0.4     1657116900
 7.5     41  0.2     1699199100
 7.5     49  0   1677591900
 7.5     49.1    0   1677451500
 7.5     52  0   1698943500
 7.5     82  -0.4    1699157700
 7.6     23  0.6     1680527700
 7.6     28  0.3     1705752900
 7.6     36  0.4     1678896900
 7.6     37  0.2     1701515700
 7.6     39  0.3     1699191900
 7.6     47  0.2     1705697100
 7.6     53  0.1     1705688100
 7.6     54  0.2     1677777300
 7.6     59  1   1711626300
 7.6     61  0.3     1711620900
 7.7     45  0.2     1699002900
 7.7     56  0   1705684500
 7.8     36  0.2     1702734300
 7.8     54  0.2     1701522900
 7.8     64  -0.1    1663413300
 7.9     47  0   1677599100
 7.9     48  0   1677600900
 7.9     70  -0.6    1663409700
 8   28  0.3     1705756500
 8   34  0.4     1711644300
 8   38  0.2     1701517500
 8   42  0.2     1705702500
 8   46  0.2     1705698900
 8   47  0.1     1705693500
 8   48  0.1     1701521100
 8   48.1    0.6     1711638900
 8   50  0.2     1698759900
 8   55  0.1     1705686300
 8.1     30  0.3     1699015500
 8.1     33  0.6     1659028500
 8.2     30  0.3     1699017300
 8.2     47  0   1677593700
 8.2     50  0   1677604500
 8.2     66  -0.4    1663411500
 8.3     52  0.1     1698938100
 8.3     74  -0.5    1663407900
 8.4     47  0   1677597300
 8.4     47.1    0.1     1705695300
 8.5     44  0.3     1698758100
 8.5     47  0   1677595500
 8.6     28  0.3     1705754700
 8.6     50  0   1677602700
 8.6     59  0.5     1711624500
 8.8     42  0.3     1699004700
 8.9     37  0.2     1699006500
 9   49  0   1677586500
 9.3     34  0.2     1699008300
 9.3     50  0   1677590100
 9.5     39  0.2     1701513900
 9.7     34  0.4     1699010100
 10  50  0   1677588300
 10.2    30  0.3     1699011900
 11.3    29  0.3     1699013700

and my script (as reduced as I could) is the following:

reset session
set term win
set datafile missing NaN

   v = 6   #  N° OF CONTOURS OF contourplot

   year1 = 2022
   month1 = 'Julio'
   day1 = 1
   time1 = '08:00:00'
   year2 = 2024
   month2 = 'Noviembre'
   day2 = 1
   time2 = '00:00:00'
   set locale "spanish"
s1 = sprintf("%02.0f",day1)
s2 = sprintf("%02.0f",day2)
   vi = strptime("%Y-%m-%d %H:%M:%S","".year1.'-'."".int(tm_mon(strptime("%B",month1))+1).'-'.s1.time1)
   vf = strptime("%Y-%m-%d %H:%M:%S","".year2.'-'."".int(tm_mon(strptime("%B",month2))+1).'-'.s2.time2)
  
stats "datos.txt" u 1:2
x0 = STATS_min_x; xf = STATS_max_x
y0 = STATS_min_y; yf = STATS_max_y
stats "datos.txt" u 3
z0 = STATS_min
zf = STATS_max
set table $Contour0 
    plot "datos.txt" u 1:2:3:(gprintf("%.f",timecolumn(4,"%s"))) w table
unset table
set dgrid3d 257,257 qnorm 9

# Use a coarser grid when generating 1 label per contour >>TO BE DEFINED OUTSIDE ANY DO-LOOP, OTHERWISE IT GIVES ERROR<< (THE SAME FOR '<< EOD BLOCKS') 
# use a dummy definition g = $smallgrid() to force a single execution of a function that resets the grid parameters
function $smallgrid() << EOF
    set dgrid3d 65,65 qnorm 9
EOF

do for [i=year1:year2] { 
j0 = 1; if (i==year1) {j0 = 0+strftime ("%m",vi)}
jf =12; if (i==year2) {jf =-1+strftime ("%m",vf)}
do for [j=j0:jf] {
vii = strptime("%Y%m","".i."".j)
vff = strptime("%Y%m","".i."".(j+1))

        set palette rgbformulae 33,13,10  
        set cbrange[z0:zf]
# CONTOUR LEVELS:
set yrange [*:*]    # otherwise a warning comes out though it doesn't do anything bad
stats "datos.txt" u (($4-900)>vii && ($4-900)<=vff ? $3: NaN)
w = 0.1 * int((STATS_max-STATS_min-0.2)*10./(v-1.))   # THIS IS THE STEP OF THE CONTOUR LEVELS
if (w==0.) {w = 1.}
set cntrparam levels incremental STATS_min+0.1,w,STATS_max-0.1
  set table $Temp
      set samples v
      plot '+' u (STATS_min+0.1+$0*w) w table
  if ((((STATS_max-STATS_min-0.2) - int(STATS_max-STATS_min-0.2))/w) >= 0.5) {plot '+' every ::::0 u (STATS_max-0.1) w table}
  set table $Levels
      plot $Temp u 1:0 smooth freq   # sort levels
  unset table
  myLevels = ''
  stats $Levels u (myLevels = myLevels.($0==0?'':', ').strcol(1)) nooutput

set view 0,0,1.5
set xrange [x0:xf]
set yrange [y0:yf]
set zrange [z0:zf]
# I KEEP THE ORIGINAL set tics JUST IN CASE THE PROBLEM ORIGINATES THERE.
set xtics format "{/:Bold %.1f}" font "Times-New Roman, 10"
set ytics format "{/:Bold %.f}" scale 0.35 font "Times-New Roman, 10"  offset -1.5,0
set ztics

set cntrlabel format "{/:Bold %.1f}" font "Times-New Roman, 10" onecolor
set contour;  set cntrparam levels discrete @myLevels
set pm3d explicit
  splot "datos.txt" u 1:2:(($4-900)>vii && ($4-900)<=vff ? $3: NaN) with pm3d notitle, \
      '' u 1:2:(($4-900)>vii && ($4-900)<=vff ? $3: NaN) with lines lw 1 lc "black" nosurface notitle, \
      g=$smallgrid() '' u 1:2:(($4-900)>vii && ($4-900)<=vff ? $3: NaN) with labels pointnumber 1 notitle, \
      $Contour0 u 1:2:(($4-900)>vii && ($4-900)<=vff ? $3: NaN) w p nogrid pt 7 ps 0.15 lc "black" notitle
#  THERE'S A WARNING AS A RESULT OF PLOTTING $Contour0 BUT THAT'S NOT BIG DEAL

#  RE-INITIALIZING PARAMETERS JUST IN CASE
    set xrange [*:*]
    set yrange [*:*]
    set zrange [*:*]
    set xtics
    set ytics
    undefine $Temp
    undefine $Levels
}
}

Solution

  • I have not tried to run your script, but I can see that the problem is in the line:

    set cntrparam levels discrete @myLevels

    It is not possible to set a string variable inside a do loop and then dereference it inside that same do loop. The reason for this is that operation of replacing @var with the string contained by var is performed only once, before executing the loop. Thus all iterations of the loop see the same constant string value that was set before the loop was executed for the first time.

    If you absolutely must use a constructed command inside a loop, you could instead use the evaluate() command rather than macro expansion:

    level_command = "set cntrparam levels discrete " . myLevels
    evaluate(level_command)