QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: bartok on February 20, 2021, 05:56:41 am

Title: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 20, 2021, 05:56:41 am
Hi,
I have a problem and I don't find a solution.
Launching the code, press 1 or 2, and then any key at time.
In the ordinate is drawn a notch every X mc/s.

Given this notch, the target is to print the corresponding value on the axis. The problem is just to print it in the right position.
In the code below, we have to see the subroutine "grafici": lines 302 to 385, but the core of the problem is in lines 365 (inside the command WINDOW) and 374 (outside).

I have thought to print the value with che command _PRINTSTRING. At the moment there is no value, but the string "-". _PRINTSTRING, unfortunately, doesn't use the local coordinates of WINDOW (line 333), but always the general coordinates in pixels of the screen in use (line 331). So, in order to use _PRINTSTRING, the idea was to transform (line 365 and 374) the general coordinates of _PRINTSTRING, into the local coordinates of WINDOW by using fx! and fy!: lines 323-328.

But, as we can see launching the code, there is no way in order to have the strings "-" to fit and match the notches, also introducing a parameter k! (line 362) to do so. In any way, the strings "-" are ot of phase with the notches. The solution is not to use double precision variables for the transformation between coordinates.

So how we can print the values on the axis? I never thought that the problem was this!

Code: QB64: [Select]
  1.  
  2. mockus: 'dati dell'idrogramma unitario di Mockus
  3. DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  4. DATA 0.030,0.100,0.190,0.310,0.470,0.660,0.820,0.930,0.990,1.000,0.990,0.930,0.860,0.780,0.680,0.560,0.460,0.390,0.330,0.280,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.040,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0.000: ' t/tp
  5.  
  6. coefficienti:
  7. DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32: 'N volte tc!.
  8. DATA 0.1,0.1,0.1,0.2,0.3,0.2,0.3,0.3,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,1,1,1,1,1,1,1: 'discretizzazione dei coeff. di Mockus.
  9.  
  10. TYPE mockus
  11.     MOCKUStSUta AS SINGLE
  12.     MOCKUSqSUqp AS SINGLE
  13.  
  14. TYPE matrice1
  15.     m AS INTEGER '[numero naturale] conta il numero di interazioni fino al raggiungimento di "d".
  16.     mdt AS SINGLE '[ore] conta la progessione delle ore fino al raggiungimento di "d".
  17.     tminuti AS SINGLE '[minuti] trasforma mdt in minuti.
  18.     h1 AS SINGLE '[mm] valore h della curva di possibilità climatica.
  19.     i1 AS SINGLE '[mm/ora] intensità di pioggia.
  20.     i2 AS SINGLE '[mm/ora] intensità di pioggia secondo lo ietogramma Chicago o costante.
  21.     DH AS SINGLE '[mm] pioggia in ogni istante temporale dt.
  22.     H2 AS SINGLE '[mm] pioggia cumulata ad ogni istante temporale.
  23.     he AS SINGLE '[mm] piggia efficace cumulata ad ogni istante temporale.
  24.     Dhe AS SINGLE '[mm] pioggia efficace ad ogni istante temporale.
  25.     MOCKUStSUta AS SINGLE
  26.     MOCKUSqSUqp AS SINGLE
  27.     tmSUta AS SINGLE '[-].
  28.     qmSUqp AS SINGLE '[-] il valore di qm/qp corrispondente a tm/ta e' = al valore di q/qp che corrisponde a t/ta=tm/ta.
  29.     qm AS SINGLE '[mc/s].
  30.  
  31. TYPE coefficienti
  32.     d AS SINGLE
  33.     tSUta AS SINGLE
  34.  
  35. TYPE idrogramma
  36.     ore AS SINGLE
  37.     minuti AS SINGLE
  38.     portata AS SINGLE
  39.  
  40. CONST limit = 200 '50
  41.  
  42. DIM schermo&
  43.  
  44. DIM SHARED mockus(50) AS mockus
  45. DIM SHARED dt!(2, 24)
  46. DIM SHARED matrice1(2, 24, 50, 1) AS matrice1
  47. DIM SHARED coefficienti(24) AS coefficienti
  48. DIM SHARED matrice2!(2, 24, 50, 50)
  49. DIM SHARED idrogramma(2, 24, 50, 1) AS idrogramma
  50. DIM SHARED massimi1(2, 24, 1) AS idrogramma
  51. DIM SHARED massimi2(2) AS idrogramma
  52. DIM SHARED i%, n%, z%, ieto%
  53. DIM SHARED m%(2, 24)
  54. DIM SHARED S2! '[mm] contenuto idrico massimo del terreno.
  55. DIM SHARED Ia! '[mm] perdite iniziali.
  56. DIM SHARED tc! '[ore] tempo di corrivazione
  57. DIM SHARED ta! '[ore] tempo di picco.
  58. DIM SHARED qp! '[mc/s] portata al colmo dell'idrogramma unitario.
  59. DIM SHARED k! '[-] coeff. della curva di possibilità climatica tado dal sito della Regione.
  60. DIM SHARED a2! '[mm/d^n] coeff. della curva di possibilità climatica.
  61. DIM SHARED n1! '[-] coeff. della curva di possibilità climatica.
  62. DIM SHARED visualizzaieto%
  63. DIM A1! '[mq] superficie bacino idrografico.
  64. DIM L! '[m] lunghezza asta principale.
  65. DIM HmaxL! '[m] punto più alto dell'astra principale.
  66. DIM HminL! '[m] punto più basso dell'asta principale.
  67. DIM s1! '[-] pendenza media del bacino non espressa in percentuale ma come 0,x.
  68. DIM CNII! '[-] tabellato.
  69. DIM CNIII '[-] discende da CNII.
  70. DIM tl! '[ore] tempo di ritardo.
  71. DIM keypress$
  72.  
  73. SCREEN schermo&
  74.  
  75. A1! = 2641902
  76. k! = 2.34
  77. a2! = 14.6653
  78. n1! = 0.45596
  79. L! = 3300
  80. HmaxL! = 1981
  81. HminL! = 1062
  82. s1! = 0.415
  83. CNII! = 70
  84.  
  85. 'INPUT A1!
  86. 'INPUT k!
  87. 'INPUT a2!
  88. 'INPUT n1!
  89. 'INPUT L!
  90. 'INPUT HmaxL!
  91. 'INPUT HminL!
  92. 'INPUT s1!
  93. 'INPUT CNII!
  94. 'INPUT d1!
  95.  
  96. CNIII! = (23 * CNII!) / (10 + 0.13 * CNII!)
  97. tl! = 0.342 * ((L! / 1000) ^ 0.8 / (100 * s1!) ^ 0.5) * (1000 / CNIII! - 9) ^ 0.7 'formula di Mockus.
  98. S2! = 25.4 * (1000 / CNIII! - 10)
  99. Ia! = 0.1 * S2! 'coeff.=0.03-0.2.
  100. tc! = tl! / 0.6
  101. ta! = tl! / 0.9
  102. qp! = 0.208 * ((A1! / 1000000) / ta!)
  103.  
  104. RESTORE mockus
  105. FOR i% = 1 TO 100
  106.     IF i% <= 50 THEN READ mockus(i%).MOCKUStSUta
  107.     IF i% > 50 THEN READ mockus(i% - 50).MOCKUSqSUqp
  108. NEXT i%
  109.  
  110. RESTORE coefficienti
  111. FOR i% = 1 TO 48
  112.     IF i% <= 24 THEN READ coefficienti(i%).d: coefficienti(i%).d = coefficienti(i%).d * tc!
  113.     IF i% > 24 THEN READ coefficienti(i% - 24).tSUta
  114. NEXT i%
  115.  
  116. PRINT "Ietogramma Chicago/costante: 1/2> "
  117.     _LIMIT 60 'limit
  118.     keypress$ = INKEY$
  119. LOOP UNTIL keypress$ = "1" OR keypress$ = "2"
  120. visualizzaieto% = VAL(keypress$)
  121.  
  122. FOR ieto% = 1 TO 2
  123.     CALL creamatrici
  124. NEXT ieto%
  125.  
  126. CALL grafici(massimi1(visualizzaieto%, 24, 1).ore, massimi2(visualizzaieto%).ore, massimi2(visualizzaieto%).portata) 'valori passati per disegnare il grafico.
  127.  
  128. 'CALL risultati
  129.  
  130. '-----------------------------------------matrice1---------------------------------------------------------------------------------------------------------------------------------
  131. SUB creamatrici ()
  132.     z% = 0
  133.     DO
  134.         z% = z% + 1
  135.         dt!(ieto%, z%) = coefficienti(z%).tSUta * ta!
  136.         m%(ieto%, z%) = coefficienti(z%).d / (coefficienti(z%).tSUta * ta!) 'determina il numero di passi temporali necessari ad arrivare allla durata d considerata con il paso temporale dt!.
  137.         FOR i% = 1 TO 50
  138.             matrice1(ieto%, z%, i%, 1).MOCKUStSUta = mockus(i%).MOCKUStSUta
  139.             matrice1(ieto%, z%, i%, 1).MOCKUSqSUqp = mockus(i%).MOCKUSqSUqp
  140.             matrice1(ieto%, z%, i%, 1).m = i%
  141.             matrice1(ieto%, z%, i%, 1).mdt = matrice1(ieto%, z%, i%, 1).m * dt!(ieto%, z%)
  142.             matrice1(ieto%, z%, i%, 1).tminuti = matrice1(ieto%, z%, i%, 1).mdt * 60
  143.             SELECT CASE (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 'crea il vettore dell'idrogramma unitario di Mockus con i multipli del coeff. z% considerato (0.1,0.2,0.3,0.5,1).
  144.                 CASE IS <= 5 'valore massimo di t/ta di Mockus
  145.                     matrice1(ieto%, z%, i%, 1).tmSUta = (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 '=matrice1(i%).m *  matrice1(i%).mdt / ta!
  146.                 CASE ELSE
  147.                     matrice1(ieto%, z%, i%, 1).tmSUta = 0
  148.             END SELECT
  149.         NEXT i%
  150.         FOR i% = 1 TO 50
  151.             n% = 1
  152.             DO 'crea il vettore dell'idrogramma unitario Mockus prendendo i valori corrispondenti di ai coefficienti.
  153.                 IF matrice1(ieto%, z%, i%, 1).tmSUta = matrice1(ieto%, z%, n%, 1).MOCKUStSUta THEN
  154.                     matrice1(ieto%, z%, i%, 1).qmSUqp = matrice1(ieto%, z%, n%, 1).MOCKUSqSUqp
  155.                     EXIT DO
  156.                 ELSE
  157.                     n% = n% + 1
  158.                 END IF
  159.             LOOP UNTIL n% = 50
  160.             matrice1(ieto%, z%, i%, 1).qm = matrice1(ieto%, z%, i%, 1).qmSUqp * qp!
  161.         NEXT i%
  162.         FOR i% = 1 TO m%(ieto%, z%)
  163.             matrice1(ieto%, z%, i%, 1).h1 = k! * a2! * matrice1(ieto%, z%, i%, 1).mdt ^ n1!
  164.             IF i% = 1 THEN
  165.                 matrice1(ieto%, z%, i%, 1).i1 = matrice1(ieto%, z%, i%, 1).h1 / dt!(ieto%, z%)
  166.             ELSE
  167.                 matrice1(ieto%, z%, i%, 1).i1 = (matrice1(ieto%, z%, i%, 1).h1 - matrice1(ieto%, z%, i% - 1, 1).h1) / dt!(ieto%, z%)
  168.             END IF
  169.         NEXT i%
  170.         SELECT CASE ieto%
  171.             CASE 1 'Chicago.
  172.                 CALL chicago
  173.             CASE 2 'costante
  174.                 FOR i% = 1 TO m%(ieto%, z%)
  175.                     matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z%, m%(ieto%, z%), 1).h1 / matrice1(ieto%, z%, m%(ieto%, z%), 1).mdt
  176.                 NEXT i%
  177.         END SELECT
  178.         FOR i% = 1 TO m%(ieto%, z%)
  179.             matrice1(ieto%, z%, i%, 1).DH = matrice1(ieto%, z%, i%, 1).i2 * dt!(ieto%, z%)
  180.             IF i% = 1 THEN
  181.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH
  182.             ELSE
  183.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH + matrice1(ieto%, z%, i% - 1, 1).H2
  184.             END IF
  185.             SELECT CASE matrice1(ieto%, z%, i%, 1).H2 - Ia!
  186.                 CASE IS < 0
  187.                     matrice1(ieto%, z%, i%, 1).he = 0
  188.                 CASE IS >= 0
  189.                     matrice1(ieto%, z%, i%, 1).he = (matrice1(ieto%, z%, i%, 1).H2 - Ia!) ^ 2 / (matrice1(ieto%, z%, i%, 1).H2 - Ia! + S2!)
  190.             END SELECT
  191.             IF i% = 1 THEN
  192.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he
  193.             ELSE
  194.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he - matrice1(ieto%, z%, i% - 1, 1).he
  195.             END IF
  196.         NEXT i%
  197.  
  198.         '-------------------------------matrice2-------------------------------------------------------------------------------------------------------------------------
  199.  
  200.         FOR n% = 1 TO 50 'colonna
  201.             FOR i% = n% TO 50 ' riga
  202.                 matrice2!(ieto%, z%, i%, n%) = matrice1(ieto%, z%, i% - n% + 1, 1).Dhe * matrice1(ieto%, z%, n%, 1).qm
  203.             NEXT i%
  204.         NEXT n%
  205.         '-------------------------------idrogramma------------------------------------------------------------------------------------------------------------------
  206.         FOR i% = 1 TO 50 'riga
  207.             FOR n% = 1 TO 50 'colonna
  208.                 idrogramma(ieto%, z%, i%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata + matrice2!(ieto%, z%, i%, n%)
  209.  
  210.             NEXT n%
  211.             idrogramma(ieto%, z%, i%, 1).ore = matrice1(ieto%, z%, i%, 1).mdt
  212.             idrogramma(ieto%, z%, i%, 1).minuti = matrice1(ieto%, z%, i%, 1).tminuti
  213.         NEXT i%
  214.         '-------------------------------Massimi-----------------------------------------------------
  215.         i% = 1
  216.         'massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, 1, 1).portata
  217.         DO
  218.             IF massimi1(ieto%, z%, 1).portata < idrogramma(ieto%, z%, i%, 1).portata THEN
  219.                 massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata
  220.                 massimi1(ieto%, z%, 1).ore = idrogramma(ieto%, z%, i%, 1).ore
  221.                 massimi1(ieto%, z%, 1).minuti = idrogramma(ieto%, z%, i%, 1).minuti
  222.             END IF
  223.             i% = i% + 1
  224.         LOOP UNTIL i% = 50
  225.         ' IF massimi2(ieto%).ore < massimi1(visualizzaieto%, z%, 1).ore THEN massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  226.         IF massimi2(ieto%).portata < massimi1(visualizzaieto%, z%, 1).portata THEN
  227.             massimi2(ieto%).portata = massimi1(visualizzaieto%, z%, 1).portata
  228.             massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  229.         END IF
  230.     LOOP UNTIL z% = UBOUND(coefficienti)
  231. '---------------------------------------------------------------------------------------------------------------------------------------------------
  232. 'Questa subroutine crea gli ietogrammi chicago per ogni iterazione z%.
  233. 'Ad ogni nuovo dt! pone l'ultimo valore di pioggia come ultimo, il penultimo come primo, il terzultimo come penultimo, il quartultimo come secondo e così via.
  234. 'Quando vi è un valore di z% che ha un dt! non nuovo, cerca la precedente iterazione z% con lo stesso dt! e copia i suoi valori dello ietogramma chicago in quello dell'iterazione z% in corso. I valori rimanenti sono riempiti
  235. 'procedendo come prima.
  236. 'Quindi per esempio l'iterazione z%=1 corrisponde a d=1tc con passo temporale dt!. L'iterazione z%=2 corrisponde a d=2tc con il medesimo passo temporale. Per cui lo ietogramma chicago per d=2tc e' dato dallo stesso ietogramma
  237. 'chicago che si ha per d=1tc, con l'aggiunta, ai suoi estremi, dei nuovi valori. Il meccanismo si ripete per z%=3, che corrisponde a d=3tc, con il medesimo dt!. Per z%=4, corrispondente a d=4tc, invece, il passo temporale dt!
  238. 'cambia.
  239. 'Quanto detto e' necessario per evitare piccole discrepanze che potrebbero comportare il fatto che alcuni massimi risultino localmente poco piu' bassi del precedente, anche quando il trend generale e' chiaramente di aumento dei
  240. 'massimi all'aumentare della durata della pioggia. In questo modo si fa l'ipotesi che all'aumentare della durata della pioggia, discretizzata con uno stesso passo temporale dt!, ogni ietogramma contenga a sua volta il precedente.
  241. 'In tal modo, se si condiera per esempio d=2tc, si assume che l'altezza di pioggia corrispondente a 1tc, segua lo ietogramma relativo a d=1tc, cosi' che l'altezza di pioggia rimamente sia eclusivamente dovuta ai nuovi valori.
  242. SUB chicago ()
  243.     DIM test%
  244.     DIM k%
  245.     n% = 1
  246.     DO
  247.         IF z% = 1 THEN test% = 0: EXIT DO 'permette il calcolo dello ietogramma chicago della prima iterazione. test%=0
  248.         IF dt!(ieto%, z%) = dt!(ieto%, z% - n%) THEN ' se trova un'iterazione z% precedente con lo stesso dt! di quella in corso, esegue i comandi successivi
  249.             test% = 1
  250.             k% = m%(ieto%, z%)
  251.             i% = 0
  252.             DO 'inserisce i nuovi valori dello ietogramma chicago dell'iterazione z% in corso.
  253.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  254.                 k% = k% - 1
  255.                 IF k% = m%(ieto%, z% - n%) THEN EXIT DO 'se ha completato l'inserimento dei nuovi valori, passa oltre.
  256.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  257.                 k% = k% - 1
  258.                 i% = i% + 1
  259.             LOOP UNTIL k% = m%(ieto%, z% - n%)
  260.             IF matrice1(ieto%, z%, i%, 1).i2 = 0 THEN i% = i% - 1
  261.             k% = 1
  262.             DO 'inserisce lo ietogramma chicago dell'iterazione z% precedente con lo stesso dt!, nello ietogramma dell'iterazione z% in corso.
  263.                 i% = i% + 1
  264.                 matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z% - n%, k%, 1).i2
  265.                 k% = k% + 1
  266.             LOOP UNTIL k% > m%(ieto%, z% - n%)
  267.             EXIT DO 'siccome ha completato lo ietogramma dell'iterazione z% in corso, non serve incrementare n%, quindi passa oltre. test%=1.
  268.         ELSE ' se non trova l'iterazione z% precedente con lo stesso dt! di quella in corso, incrementa n% e ripete la ricerca.
  269.             test% = 0
  270.             n% = n% + 1
  271.         END IF
  272.     LOOP UNTIL n% = z% - 1 'se non ha trovato iterazioni z% precedenti con lo stesso dt!, allora passa oltre e test%=0.
  273.     SELECT CASE test%
  274.         CASE IS = 1 'esce dalla subroutine, in quanto lo ietogramma e' definito.
  275.             EXIT SUB
  276.         CASE IS = 0 'calcola ex-novo lo ietogramma relativo all'iterazione z% in corso in quanto non vi e' un'iterazioni z% precedente con lo stesso dt! dell'iterazione z% in corso.
  277.             k% = m%(ieto%, z%)
  278.             i% = 0
  279.             DO
  280.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  281.                 k% = k% - 1
  282.                 IF k% = 0 THEN EXIT DO
  283.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  284.                 k% = k% - 1
  285.                 i% = i% + 1
  286.             LOOP UNTIL k% = 0
  287.     END SELECT
  288. '-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  289. SUB grafici (ore!, oreM!, QM!)
  290.     'ore!: ore massime di analisi.
  291.     'oreM!: ore corrispondenti alla portata massima.
  292.     'QM!: portata massima.
  293.  
  294.     CONST dxy% = 30
  295.     CONST L% = 800
  296.     CONST H% = 600
  297.  
  298.     ' CONST LH! = L% / H% 'costante che, all'interno del comando WINDOW, di portare la scala delle ordinate uguale a quella delle ascisse.
  299.     CONST rosso = _RGB32(255, 0, 0)
  300.     CONST bianco = _RGB32(255, 255, 255)
  301.     CONST giallo = _RGB32(255, 255, 0)
  302.  
  303.     DIM grafico&
  304.     DIM fx! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse x e nelle circonferenze.
  305.     DIM fy! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse y.
  306.     DIM dx!, dy!
  307.     DIM tacca%
  308.     DIM k%
  309.  
  310.     grafico& = _NEWIMAGE(L%, H%, 32)
  311.     fx! = L% / (ore! * 1.1) '=168.3349 'pixel/ora
  312.     fy! = H% / (QM! * 1.1) '=23.3657 'pixel/mc
  313.     dx! = dxy% / fx! '=0.1782162:dx! e' la lunghezza dentro WINDOWS per avere un numero di pixel=dxy%.
  314.     dy! = dxy% / fy! '=1.283933
  315.     tacca% = QM! \ 5
  316.  
  317.     _DEST grafico&
  318.     SCREEN grafico&
  319.     LINE (0, 0)-(L% - 1, H% - 1), rosso, B
  320.     WINDOW (0, 0)-(ore! * 1.1 + dx!, QM! * 1.1 + dy!) 'scala ascisse e ordinate in base alle ore e alla portata, estendendole del 10%.
  321.     LINE (dx!, QM! * 1.1)-(dx!, dy!): LINE -(ore! * 1.1, dy!), bianco
  322.     PSET (dx!, QM! * 1.1!), bianco: DRAW "F20": PSET (dx!, QM! * 1.1), bianco: DRAW "G20" ': LOCATE 7, 65: PRINT "y"
  323.     PSET (ore! * 1.1, dy!), bianco: DRAW "G20": PSET (ore! * 1.1, dy!), bianco: DRAW "H20" ': LOCATE 25, 112: PRINT "x"
  324.     FOR z% = 1 TO 24
  325.         CIRCLE (dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), 3 / fx!, rosso
  326.         PAINT (dx! + massimi1(visualizzaieto%, z%, 1).ore + 0.5 / fx!, dy! + massimi1(visualizzaieto%, z%, 1).portata + 0.5 / fx!), rosso
  327.         IF z% = 1 THEN
  328.             LINE (dx!, dy!)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), rosso
  329.         ELSE
  330.             LINE (dx! + massimi1(visualizzaieto%, z% - 1, 1).ore, dy! + massimi1(visualizzaieto%, z% - 1, 1).portata)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), rosso
  331.         END IF
  332.         IF z% = 24 THEN
  333.             SELECT CASE visualizzaieto%
  334.                 CASE IS = 1
  335.                     LINE -(dx!, dy! + massimi1(visualizzaieto%, z%, 1).portata), bianco, , 61440
  336.                     LINE (dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy!), bianco, , 61440
  337.                 CASE IS = 2
  338.                     LINE (dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy!), bianco, , 61440
  339.             END SELECT
  340.         END IF
  341.     NEXT z%
  342.     IF visualizzaieto% = 2 THEN
  343.         LINE (dx!, dy! + QM!)-(dx! + oreM!, dy! + QM!), bianco, , 61440
  344.         LINE -(dx! + oreM!, dy!), bianco, , 61440
  345.     END IF
  346.     ' _PRINTSTRING (L% \ 2, H% \ 2), "O" '_PRINTSTRING non usa le coordinate locali di VIEW, ma sempre quello dello SCREEN in uso. Per tal ragione e' stato necessario creare grafico&.
  347.     SLEEP
  348.     i% = 1
  349.     k! = 0.98
  350.     WHILE i% * tacca% <= QM!
  351.         LINE (dx! - 5 / fx!, dy! + i% * tacca%)-(dx! + 5 / fx!, dy! + i% * tacca%): SLEEP
  352.         _PRINTSTRING (dx! * fx! - 20, H% - 1 - (dy! + i% * tacca%) * fy! * k!), "-": SLEEP
  353.         i% = i% + 1
  354.     WEND
  355.     WINDOW
  356.     i% = 1
  357.     '  k! = 1
  358.     WHILE i% * tacca% <= QM!
  359.         '   LINE (dxy% - 1 - 5, H% - 1 - (dy! + i% * tacca%) * fy! * k!)-(dxy% - 1 + 1000, H% - 1 - (dy! + i% * tacca%) * fy! * k!), giallo: SLEEP
  360.         '   PRINT (dy! + i% * tacca%) * fy!: SLEEP
  361.         _PRINTSTRING (dx! * fx! - 20, H% - 1 - (dy! + i% * tacca%) * fy! * k!), "--": SLEEP
  362.         i% = i% + 1
  363.     WEND
  364.     ' k% = i% * tacca%
  365.     'i% = 1
  366.     'WHILE i% <= ore!
  367.     '    _PRINTSTRING (dxy%, H% - 1 - (dxy% + i% * k%)), "-"
  368.     'i% = i% + 1
  369.     'WEND
  370.     '  _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  371.     '   _FREEIMAGE grafico&
  372. '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  373. SUB risultati ()
  374.     FOR z% = 1 TO 24
  375.         CLS
  376.         PRINT "z%="; z%
  377.         PRINT "dt="; dt!(visualizzaieto%, z%); ";"; dt!(visualizzaieto%, z%) * 60
  378.         PRINT "visualizzaieto%="; visualizzaieto%
  379.         PRINT "m%="; m%(visualizzaieto%, z%)
  380.         PRINT "N="; coefficienti(z%).d / tc!
  381.         PRINT "n="; coefficienti(z%).tSUta
  382.         FOR i% = 1 TO 50
  383.             '  _LIMIT limit
  384.     PRINT _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).m)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).mdt)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tminuti)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).h1)),_
  385.      _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i1)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i2)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).DH)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).H2)),_
  386.       _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).he)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).Dhe)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUStSUta)),_
  387.        _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUSqSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tmSUta)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qmSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qm))
  388.         NEXT i%
  389.         SLEEP
  390.         CLS
  391.         FOR n% = 1 TO 50
  392.             '  _LIMIT limit
  393.             LOCATE 1,
  394.             FOR i% = 1 TO 50
  395.                 LOCATE , n% * 4 - 3
  396.                 PRINT matrice2!(visualizzaieto%, z%, i%, n%)
  397.             NEXT i%
  398.         NEXT n%
  399.         SLEEP
  400.     NEXT z%
  401.     CLS
  402.     FOR n% = 1 TO 24
  403.         ' _LIMIT limit
  404.         SELECT CASE n%
  405.             CASE IS <= 16
  406.                 FOR i% = 1 TO 50
  407.                     LOCATE i%, n% * 15 - 14
  408.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  409.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  410.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  411.  
  412.                 NEXT i%
  413.                 IF n% = 16 THEN SLEEP: CLS
  414.             CASE IS > 16
  415.                 FOR i% = 1 TO 50
  416.                     LOCATE i%, (n% - 16) * 15 - 14
  417.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  418.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  419.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  420.                 NEXT i%
  421.         END SELECT
  422.     NEXT n%
  423.     SLEEP
  424.     CLS
  425.     FOR z% = 1 TO 24
  426.         ' _LIMIT limit
  427.         PRINT massimi1(visualizzaieto%, z%, 1).ore, massimi1(visualizzaieto%, z%, 1).minuti, massimi1(visualizzaieto%, z%, 1).portata
  428.     NEXT z%
  429.     SLEEP
  430.     PRINT
  431.     PRINT massimi2(visualizzaieto%).ore; massimi2(visualizzaieto%).portata
  432.  

Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: OldMoses on February 20, 2021, 08:07:07 am
I don't know if I understand this correctly, but if you have a positioning problem between screen absolute coordinates and WINDOW defined coordinates, I've used the map! function to good effect. If you have a value that needs translation from an old  range {minRange!/maxRange!}, it will translate that value to the new range {newMinRange!/newMaxRange!}. The order depends upon which way one is going, from WINDOW to screen or from screen to WINDOW. Hope this helps

Code: QB64: [Select]
  1. Function map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  2.  
  3.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  4.  
  5.  
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 20, 2021, 10:52:47 am
Aren't _PrintString coordinates automatically translated to Window coordinates like the graphics pset, line, circle..., if not, try same trick for translating Mouse Coordinates in a Window use PMap see Wiki.

Use Moses idea if printing outside the Window or returning screen back to normal.

BTW is your graph reversed? Both look flipped: up/down and left/right? Your screen bigger than my laptop, didn't see the axis arrows they were over in the storage shelf left of my laptop on my desk. :)

Ah TempodiBasic and or Kiara are recruiting ;-))
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 20, 2021, 11:36:36 am
I don't know if I understand this correctly, but if you have a positioning problem between screen absolute coordinates and WINDOW defined coordinates, I've used the map! function to good effect. If you have a value that needs translation from an old  range {minRange!/maxRange!}, it will translate that value to the new range {newMinRange!/newMaxRange!}. The order depends upon which way one is going, from WINDOW to screen or from screen to WINDOW. Hope this helps

Code: QB64: [Select]
  1. Function map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  2.  
  3.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  4.  
  5.  

Hi and thanks for the tip, but it doesn't work with the damned _PRINTSTRING!

As you can see in the semplified code above (press any key to go ahead), outside WINDOW, your function works, because lines drawn in the WHILE cicle of lines 55 to 59, perfetly mach the notches drawn inside WINDOW in the WHILE circle of lines 40 to 44.

But, in the WHILE cicle of lines 62 to 66, no matches! I have also tried to add something like this:

_PRINTSTRING (55, H% - 1 - test!+K)

where K is an empirical and inexplicable value brutally added in order to have the match: no way.

Code: QB64: [Select]
  1. CONST ore! = 6.723612
  2. CONST oreM! = 6.723612
  3. CONST QM! = 29.88063
  4.  
  5. CONST dxy% = 30
  6. CONST L% = 800
  7. CONST H% = 600
  8.  
  9. CONST rosso = _RGB32(255, 0, 0)
  10. CONST bianco = _RGB32(255, 255, 255)
  11. CONST giallo = _RGB32(255, 255, 0)
  12.  
  13. DIM grafico&
  14. DIM fx! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse x e nelle circonferenze.
  15. DIM fy! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse y.
  16. DIM dx!, dy!
  17. DIM test%
  18. DIM tacca%
  19. DIM i%
  20.  
  21. grafico& = _NEWIMAGE(L%, H%, 32)
  22. fx! = L% / (ore! * 1.1) '=168.3349 'pixel/ora
  23. fy! = H% / (QM! * 1.1) '=23.3657 'pixel/mc
  24. dx! = dxy% / fx! '=0.1782162:dx! e' la lunghezza dentro WINDOWS per avere un numero di pixel=dxy%.
  25. dy! = dxy% / fy! '=1.283933
  26. tacca% = QM! \ 5
  27.  
  28.  
  29.  
  30. _DEST grafico&
  31. SCREEN grafico&
  32. LINE (0, 0)-(L% - 1, H% - 1), rosso, B
  33. WINDOW (0, 0)-(ore! * 1.1 + dx!, QM! * 1.1 + dy!) 'scala ascisse e ordinate in base alle ore e alla portata, estendendole del 10%.
  34. 'test! = map!(QM! \ 5 + dy!, 0, dy! + QM! * 1.1, 0, H% - 1)
  35. LINE (dx!, QM! * 1.1)-(dx!, dy!): LINE -(ore! * 1.1, dy!), bianco
  36. PSET (dx!, QM! * 1.1!), bianco: DRAW "F20": PSET (dx!, QM! * 1.1), bianco: DRAW "G20" ': LOCATE 7, 65: PRINT "y"
  37. PSET (ore! * 1.1, dy!), bianco: DRAW "G20": PSET (ore! * 1.1, dy!), bianco: DRAW "H20" ': LOCATE 25, 112: PRINT "x"
  38. i% = 1
  39. WHILE i% * tacca% <= QM!
  40.     LINE (dx! - 5 / fx!, dy! + i% * tacca%)-(dx! + 5 / fx!, dy! + i% * tacca%): SLEEP
  41.     '  _PRINTSTRING (dx! * fx! - 20, H% - 1 - (dy! + i% * tacca%) * fy! * k!), "-": SLEEP
  42.     i% = i% + 1
  43.  
  44.  
  45. 'i% = 1
  46. 'WHILE i% * tacca% <= QM!
  47. '_PRINTSTRING (dx! * fx! - 20, H% - 1 - (dy! + i% * tacca%) * fy!), "--": SLEEP
  48. 'i% = i% + 1
  49. 'WEND
  50.  
  51. i% = 1
  52. WHILE i% * tacca% <= QM!
  53.     test! = map!(i% * QM! \ 5 + dy!, 0, dy! + QM! * 1.1, 0, H% - 1)
  54.     LINE (35, H% - 1 - test!)-(50, H% - 1 - test!): PRINT test!: SLEEP '------|
  55.     i% = i% + 1 '                                                             |
  56. WEND '                                                                        |
  57. '                                                                             |
  58. i% = 1 '                                                                      |---Same (H%-1-test!), different output!
  59. WHILE i% * tacca% <= QM! '                                                    |
  60.     test! = map!(i% * QM! \ 5 + dy!, 0, dy! + QM! * 1.1, 0, H% - 1) '         |
  61.     _PRINTSTRING (55, H% - 1 - test!), "--": PRINT test!: SLEEP '-------------|
  62.     i% = i% + 1
  63. '---------------------------------------------------------------------------------------
  64. FUNCTION map! (value!, minWINDOW!, maxWINDOW!, minPIXEL%, maxPIXEL%)
  65.     map! = ((value! - minWINDOW!) / (maxWINDOW! - minWINDOW!)) * (maxPIXEL% - minPIXEL%) + minPIXEL%
  66.  
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 20, 2021, 11:42:07 am
Your screen bigger than my laptop, didn't see the axis arrows they were over in the storage shelf left of my laptop on my desk. :)

Ah TempodiBasic and or Kiara are recruiting ;-))

I have changed both of the 2 codes with 800x600.

In the second post, I have semplified the code, because the core of my problem is in the "graphs" subroutine of the first code I have posted. However, the program is finalized to calculate the maximum flow of a given drainage basin for a given return period, depending on the duration of the rain.

Quote
Aren't _PrintString coordinates automatically translated to Window coordinates like the graphics pset, line, circle.

no, unfortunately they aren't...
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: SMcNeill on February 20, 2021, 12:04:58 pm
You’re in SCREEN 0, where _PRINTSTRING is nothing more than a shortcut for LOCATE x, y: PRINT.

Here’s the relevant c-snippet for you:

Code: C++: [Select]
  1.        void sub__printstring(float x,float y,qbs* text,int32 i,int32 passed){
  2.             .... STUFF
  3.             if (im->text){
  4.                 int oldx = func_pos(0), oldy = func_csrlin();
  5.                 qbg_sub_locate(y, x, 0, 0, 0, 3);
  6.                 qbs_print(text, 0);
  7.                 qbg_sub_locate(oldy, oldx, 0, 0, 0, 3);
  8.                 goto printstring_exit;
  9.             }
  10.             ..... STUFF

If you’re in a text screen, simply use _PRINTSTRING as a LOCATE, PRINT, then restore the previous LOCATE position.

If _PRINTSTRING doesn’t work, just go back to LOCATE: PRINT

Edit: Nevermind...  I see your SCREEN statement down on line 70something...  You’re not trying anything in a text screen after all. 
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 20, 2021, 01:06:24 pm
SMcNeill,
yes, in fact I am in graphic mode.

It is not possible it is so complicated to put a text in a graph!:D

(I try to avoid the use of GOTO).
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 20, 2021, 01:23:25 pm
Found my old test code.

YES you MUST use PMAP for x, y conversion for both MOUSE and for _PRINTSTRING

demo
Code: QB64: [Select]
  1. _TITLE "Test Using Window for Cartesian Coordinate System x = -100 to 100, y = -100 to 100"
  2. 'It seems all graphics commands convert x, y to window system BUT...
  3. 'Mouse and _PrintString do not convert! BUT...
  4. 'Somebody setup a PMAP system that will do these conversions both to grapghics coordinate system and back
  5. ' convert mouse qbx, qby to graphics x, y use
  6. ' PMAP(qbx, 2), PMAP(qby, 3)
  7. ' And to print something at the graphics location use
  8. ' PMAP(graphicsX, 0), PMAP(graphicsY, 1) to _PRINTSTRING to a graphics location
  9.  
  10. CONST xmax = 700, ymax = 700, red = &HFFFF0000, grn = &HFF009900, blu = &HFF0000AA
  11. CONST tlx = -100, tly = 100, brx = 100, bry = -100 ' Cartesian Coordinate System corners for WINDOW command
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. _SCREENMOVE 300, 40
  14.  
  15. DIM mx, my, a, r, s$
  16.  
  17. WINDOW (tlx, tly)-(brx, bry) ' converts QB csreen to Cartesian Coodianate System
  18. WHILE _KEYDOWN(27) = 0
  19.     CLS
  20.     mx = INT(PMAP(_MOUSEX, 2)): my = INT(PMAP(_MOUSEY, 3)) 'covert mouse to Cart Cood using PMAP
  21.     a = atan360(my, mx) 'mouse angle to origin
  22.     r = INT((mx * mx + my * my) ^ .5)
  23.     LINE (0, 0)-(mx, my), grn 'hypotenuse = radius
  24.     LINE (0, 0)-(mx, 0), blu ' r*cos
  25.     LINE (mx, 0)-(mx, my), red ' r*sin
  26.     arc 0, 0, 10, 0, _R2D(a), &HFFFFFF00 'yellow arc
  27.     s$ = "Mouse (" + _TRIM$(STR$(mx)) + ", " + _TRIM$(STR$(my)) + "), Radius: "
  28.     s$ = s$ + _TRIM$(STR$(r)) + ", Degrees: " + _TRIM$(STR$(_R2D(a) \ 1))
  29.     _PRINTSTRING (PMAP(0, 0), PMAP(-1, 1)), s$
  30.     _PRINTSTRING (PMAP(-95, 0), PMAP(95, 1)), "COS = x/r = " + _TRIM$(STR$(mx / r))
  31.     _PRINTSTRING (PMAP(-95, 0), PMAP(89, 1)), "SIN = y/r = " + _TRIM$(STR$(my / r))
  32.     IF mx <> 0 THEN _PRINTSTRING (PMAP(-95, 0), PMAP(83, 1)), "TAN = y/x = " + _TRIM$(STR$(my / mx)) 'EDIT
  33.     _DISPLAY
  34.     _LIMIT 60
  35.  
  36. ' A regular graphic draw still works correctly in a Cartesian Window System!
  37. 'note: degrees start due East = 0 and go clockwise: South = 90, West = 180, North = 270
  38. SUB arc (x, y, r, degStart, degStop, c~&)
  39.  
  40.     DIM rs, re, a, ax, ay, lastx, lasty
  41.     'x, y origin, r = radius, c = color
  42.  
  43.     'degStart is first angle clockwise from due East = 0 degrees
  44.     ' arc will start drawing there and clockwise until degStop angle reached, unless in Cartesain Window
  45.  
  46.     IF degStop < degStart THEN
  47.         arc x, y, r, degStart, 360, c~&
  48.         arc x, y, r, 0, degStop, c~&
  49.     ELSE
  50.         rs = _D2R(degStart): re = _D2R(degStop)
  51.         FOR a = rs TO re STEP 1 / (7 * r)
  52.             ax = x + r * COS(a)
  53.             ay = y + r * SIN(a)
  54.             IF a <> rs THEN LINE (lastx, lasty)-(ax, ay), c~&
  55.             lastx = ax: lasty = ay
  56.         NEXT
  57.     END IF
  58.  
  59. 'need to match degrees going around clockwise up to full circle
  60. FUNCTION atan360 (y, x)
  61.     DIM test
  62.     test = _ATAN2(y, x)
  63.     IF test < 0 THEN atan360 = _PI(2) + test ELSE atan360 = test
  64.  
  65.  
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 20, 2021, 01:46:08 pm
bplus,
thank you very much! I did not have time yet to try PMAP after your message, but it was already my purpose to try it. I didn't know the command PMAP before today.
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 21, 2021, 04:01:32 am
Thank's you bplus, with PMAP it works better!

But, as you can see in the code above on line 43, I have to add "-7" in order to have the strings "--" fitting. I don't know why! In line 41 PMAP gets the y screen coordinates of WINDOW y coordinates of the line drawn in line 39. So the string "--" printed with _PRINTSTRING in line 43 should match using y calculated by PMAP without this "-7"...

Code: QB64: [Select]
  1. CONST ore! = 6.723612
  2. CONST oreM! = 6.723612
  3. CONST QM! = 29.88063
  4.  
  5. CONST dxy% = 30
  6. CONST rosso = _RGB32(255, 0, 0)
  7. CONST bianco = _RGB32(255, 255, 255)
  8. CONST giallo = _RGB32(255, 255, 0)
  9.  
  10. DIM L%, H%
  11. DIM grafico&
  12. DIM fx! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse x e nelle circonferenze.
  13. DIM fy! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse y.
  14. DIM dx!, dy!
  15. DIM tacca%
  16. DIM x%, y%
  17.  
  18. H% = _DESKTOPHEIGHT * 2 / 3
  19. L% = H% * 1.62
  20.  
  21. grafico& = _NEWIMAGE(L%, H%, 32)
  22. fx! = L% / (ore! * 1.1) '=168.3349 'pixel/ora
  23. fy! = H% / (QM! * 1.1) '=23.3657 'pixel/mc
  24. dx! = dxy% / fx! '=0.1782162:dx! e' la lunghezza dentro WINDOWS per avere un numero di pixel=dxy%.
  25. dy! = dxy% / fy! '=1.283933
  26. tacca% = QM! \ 5
  27.  
  28. _DEST grafico&
  29. SCREEN grafico&
  30. LINE (0, 0)-(L% - 1, H% - 1), rosso, B
  31. WINDOW (0, 0)-(ore! * 1.1 + dx!, QM! * 1.1 + dy!) 'scala ascisse e ordinate in base alle ore e alla portata, estendendole del 10%.
  32. LINE (dx!, QM! * 1.1)-(dx!, dy!): LINE -(ore! * 1.1, dy!), bianco
  33. PSET (dx!, QM! * 1.1!), bianco: DRAW "F20": PSET (dx!, QM! * 1.1), bianco: DRAW "G20" ': LOCATE 7, 65: PRINT "y"
  34. PSET (ore! * 1.1, dy!), bianco: DRAW "G20": PSET (ore! * 1.1, dy!), bianco: DRAW "H20" ': LOCATE 25, 112: PRINT "x"
  35. i% = 1
  36. i% = 1
  37. WHILE i% * tacca% <= QM!
  38.     LINE (dx! - 5 / fx!, dy! + i% * tacca%)-(dx! + 5 / fx!, dy! + i% * tacca%): SLEEP
  39.     x% = PMAP(dx! - 5 / fx!, 0)
  40.     y% = PMAP(dy! + i% * tacca%, 1)
  41.     PRINT x%, y%: SLEEP
  42.     _PRINTSTRING (x% + 10, y% - 7), "--": SLEEP '----------------------------------------------------> WHY 7??
  43.     i% = i% + 1
  44.  
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 21, 2021, 05:38:33 am
Ok, solved!

PMAP works perfectly with _PRINTSTRING. In this case "--" didn't match the line because the line is drawn at the top and "--" in the middle (_--)-->up side down.
But this is not the solution without using PMAP, because in the preview tries the "--"  changed the distance with the line. So PMAP is necessary.
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: OldMoses on February 21, 2021, 09:20:12 am
I find this interesting as I have not, thus far, investigated PMAP.

It would seem that it is essentially FUNCTION map! that I posted earlier, only optimized for screen ops, and much less typing.

You couldn't use it, like you can map!, for general computations, but it's much easier for graphics. You don't have to do that much range figuring.

Having learned about a new trick, I'll have to do some experiments now...;)


Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 21, 2021, 01:23:56 pm
Yeah WINDOW is the way to go especially for math apps that you want standard 4 quads upper right #1 and going Counter-clockwise 2, 3, 4 with angle increases.

Anyway with that command (set correctly of course) angles Increase going counter-clockwise and y up is up and x up is right! The way you learned it in school before Basic ruined your mind by flipping it upside down and making angles increase clockwise ;-))

Trouble is I don't know if anyone uses it enough to report bugs when working with all the new extensions installed with QB64 ie how z axis might work with GL 3D?



Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 21, 2021, 05:21:58 pm
Trouble is I don't know if anyone uses it enough to report bugs when working with all the new extensions installed with QB64 ie how z axis might work with GL 3D?

I am a beginner, so I think that my level is not enough hight to report bugs, but maybe it wouldn't be bad if _PRINTSTRING worked also inside WINDOW. But perhaps there is a reason if it doesn't. For the 3D, maybe some games programmer. I don't think my graphics needs will go beyond 2D.
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 21, 2021, 06:45:55 pm
Code: QB64: [Select]
  1. _TITLE "But _PrintString Works Fine in a Winodow!"
  2. CONST xmax = 512, ymax = 400
  3. CONST Top_Left_X = -100, Top_Left_Y = 100, Bottom_Right_X = 100, Bottom_Right_Y = -100 ' Cartesian Coordinate System corners for WINDOW command
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. _SCREENMOVE 300, 40
  6. WINDOW (Top_Left_X, Top_Left_Y)-(Bottom_Right_X, Bottom_Right_Y) ' converts QB csreen to Cartesian Coodianate System
  7. _PRINTSTRING (PMAP(-95, 0), PMAP(60, 1)), "I am a beginner, so I think that my level is not enough high"
  8. _PRINTSTRING (PMAP(-95, 0), PMAP(30, 1)), "to report bugs, but maybe it wouldn't be bad if _PRINTSTRING"
  9. _PRINTSTRING (PMAP(-95, 0), PMAP(0, 1)), "worked also inside WINDOW. But perhaps there is a reason if "
  10. _PRINTSTRING (PMAP(-95, 0), PMAP(-30, 1)), "it doesn't. For the 3D, maybe some games programmer. I don't"
  11. _PRINTSTRING (PMAP(-95, 0), PMAP(-60, 1)), " think my graphics needs will go beyond 2D."
  12.  
  13.  
  14.  
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 22, 2021, 02:38:42 am
You are right. I said that badly. I meant that it would be not bad if _PRINTSTRING, inside WINDOW, worked with the local coordinates of WINDOW, without the convertion with PMAP.
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 22, 2021, 03:51:23 am
You are right. I said that badly. I meant that it would be not bad if _PRINTSTRING, inside WINDOW, worked with the local coordinates of WINDOW, without the convertion with PMAP.

Oh you mean like pset, circle and line x, y's, yeah that would be nice. But as I was trying to say, to my knowledge, Window is not used so much to keep it updated with newer stuff like mouse and _printstring.

But at least PMap is a resource that works.
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 22, 2021, 07:46:28 am
Oh you mean like pset, circle and line x, y's, yeah that would be nice. But as I was trying to say, to my knowledge, Window is not used so much to keep it updated with newer stuff like mouse and _printstring.

But at least PMap is a resource that works.

why is not used so much! It's seems fundamental to me.

However, the result for now is not bad.

Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 22, 2021, 10:41:06 am
@bartok looks good man!
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 22, 2021, 10:46:43 am
@bartok looks good man!

thank you!

I have an other problem, that it seems inexplicable.

Launch the program.
The purpose is to draw a dashed line from X=3 going up until it find a yellow pixel. As we can see, it works. But, if we deactivate line 403, it doesn't and it goes in loop, as if it doesn't match the yellow pixel. I don't understand, considering that in both cases I am working on grafico& (line 400). I don't want to see grafico&: I just want to work in background on it and then _PUTIMAGE it (line 410) on the visualized screen.

Code: QB64: [Select]
  1.  
  2. mockus: 'dati dell'idrogramma unitario di Mockus
  3. DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  4. DATA 0.030,0.100,0.190,0.310,0.470,0.660,0.820,0.930,0.990,1.000,0.990,0.930,0.860,0.780,0.680,0.560,0.460,0.390,0.330,0.280,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.040,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0.000: ' t/tp
  5.  
  6. coefficienti:
  7. DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32: 'N volte tc!.
  8. DATA 0.1,0.1,0.1,0.2,0.3,0.2,0.3,0.3,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,1,1,1,1,1,1,1: 'discretizzazione dei coeff. di Mockus.
  9.  
  10. TYPE mockus
  11.     MOCKUStSUta AS SINGLE
  12.     MOCKUSqSUqp AS SINGLE
  13.  
  14. TYPE matrice1
  15.     m AS INTEGER '[numero naturale] conta il numero di interazioni fino al raggiungimento di "d".
  16.     mdt AS SINGLE '[ore] conta la progessione delle ore fino al raggiungimento di "d".
  17.     tminuti AS SINGLE '[minuti] trasforma mdt in minuti.
  18.     h1 AS SINGLE '[mm] valore h della curva di possibilità climatica.
  19.     i1 AS SINGLE '[mm/ora] intensità di pioggia.
  20.     i2 AS SINGLE '[mm/ora] intensità di pioggia secondo lo ietogramma Chicago o costante.
  21.     DH AS SINGLE '[mm] pioggia in ogni istante temporale dt.
  22.     H2 AS SINGLE '[mm] pioggia cumulata ad ogni istante temporale.
  23.     he AS SINGLE '[mm] piggia efficace cumulata ad ogni istante temporale.
  24.     Dhe AS SINGLE '[mm] pioggia efficace ad ogni istante temporale.
  25.     MOCKUStSUta AS SINGLE
  26.     MOCKUSqSUqp AS SINGLE
  27.     tmSUta AS SINGLE '[-].
  28.     qmSUqp AS SINGLE '[-] il valore di qm/qp corrispondente a tm/ta e' = al valore di q/qp che corrisponde a t/ta=tm/ta.
  29.     qm AS SINGLE '[mc/s].
  30.  
  31. TYPE coefficienti
  32.     d AS SINGLE
  33.     tSUta AS SINGLE
  34.  
  35. TYPE idrogramma
  36.     ore AS SINGLE
  37.     minuti AS SINGLE
  38.     portata AS SINGLE
  39.  
  40. CONST limit = 200 '50
  41.  
  42. DIM SHARED schermo&
  43.  
  44. DIM SHARED mockus(50) AS mockus
  45. DIM SHARED dt!(2, 24)
  46. DIM SHARED matrice1(2, 24, 50, 1) AS matrice1
  47. DIM SHARED coefficienti(24) AS coefficienti
  48. DIM SHARED matrice2!(2, 24, 50, 50)
  49. DIM SHARED idrogramma(2, 24, 50, 1) AS idrogramma
  50. DIM SHARED massimi1(2, 24, 1) AS idrogramma
  51. DIM SHARED massimi2(2) AS idrogramma
  52. DIM SHARED i%, n%, z%, ieto%
  53. DIM SHARED m%(2, 24)
  54. DIM SHARED S2! '[mm] contenuto idrico massimo del terreno.
  55. DIM SHARED Ia! '[mm] perdite iniziali.
  56. DIM SHARED tc! '[ore] tempo di corrivazione
  57. DIM SHARED ta! '[ore] tempo di picco.
  58. DIM SHARED qp! '[mc/s] portata al colmo dell'idrogramma unitario.
  59. DIM SHARED k! '[-] coeff. della curva di possibilità climatica tado dal sito della Regione.
  60. DIM SHARED a2! '[mm/d^n] coeff. della curva di possibilità climatica.
  61. DIM SHARED n1! '[-] coeff. della curva di possibilità climatica.
  62. DIM SHARED visualizzaieto%
  63. DIM A1! '[mq] superficie bacino idrografico.
  64. DIM L! '[m] lunghezza asta principale.
  65. DIM HmaxL! '[m] punto più alto dell'astra principale.
  66. DIM HminL! '[m] punto più basso dell'asta principale.
  67. DIM s1! '[-] pendenza media del bacino non espressa in percentuale ma come 0,x.
  68. DIM CNII! '[-] tabellato.
  69. DIM CNIII '[-] discende da CNII.
  70. DIM tl! '[ore] tempo di ritardo.
  71. DIM keypress$
  72.  
  73. SCREEN schermo&
  74.  
  75. A1! = 2641902
  76. k! = 2.34
  77. a2! = 14.6653
  78. n1! = 0.45596
  79. L! = 3300
  80. HmaxL! = 1981
  81. HminL! = 1062
  82. s1! = 0.415
  83. CNII! = 70
  84.  
  85. 'INPUT A1!
  86. 'INPUT k!
  87. 'INPUT a2!
  88. 'INPUT n1!
  89. 'INPUT L!
  90. 'INPUT HmaxL!
  91. 'INPUT HminL!
  92. 'INPUT s1!
  93. 'INPUT CNII!
  94. 'INPUT d1!
  95.  
  96. CNIII! = (23 * CNII!) / (10 + 0.13 * CNII!)
  97. tl! = 0.342 * ((L! / 1000) ^ 0.8 / (100 * s1!) ^ 0.5) * (1000 / CNIII! - 9) ^ 0.7 'formula di Mockus.
  98. S2! = 25.4 * (1000 / CNIII! - 10)
  99. Ia! = 0.1 * S2! 'coeff.=0.03-0.2.
  100. tc! = tl! / 0.6
  101. ta! = tl! / 0.9
  102. qp! = 0.208 * ((A1! / 1000000) / ta!)
  103.  
  104. RESTORE mockus
  105. FOR i% = 1 TO 100
  106.     IF i% <= 50 THEN READ mockus(i%).MOCKUStSUta
  107.     IF i% > 50 THEN READ mockus(i% - 50).MOCKUSqSUqp
  108. NEXT i%
  109.  
  110. RESTORE coefficienti
  111. FOR i% = 1 TO 48
  112.     IF i% <= 24 THEN READ coefficienti(i%).d: coefficienti(i%).d = coefficienti(i%).d * tc!
  113.     IF i% > 24 THEN READ coefficienti(i% - 24).tSUta
  114. NEXT i%
  115.  
  116. 'PRINT "Ietogramma Chicago/costante: 1/2> "
  117. 'DO
  118. '    _LIMIT 60 'limit
  119. 'keypress$ = INKEY$
  120. 'LOOP UNTIL keypress$ = "1" OR keypress$ = "2"
  121. 'visualizzaieto% = VAL(keypress$)
  122. visualizzaieto% = 1
  123.  
  124. FOR ieto% = 1 TO 2
  125.     CALL creamatrici
  126. NEXT ieto%
  127.  
  128. CALL grafici(massimi1(visualizzaieto%, 24, 1).ore, massimi2(visualizzaieto%).ore, massimi2(visualizzaieto%).portata) 'valori passati per disegnare il grafico.
  129. 'CALL risultati
  130.  
  131. '-----------------------------------------matrice1---------------------------------------------------------------------------------------------------------------------------------
  132. SUB creamatrici ()
  133.     z% = 0
  134.     DO
  135.         z% = z% + 1
  136.         dt!(ieto%, z%) = coefficienti(z%).tSUta * ta!
  137.         m%(ieto%, z%) = coefficienti(z%).d / (coefficienti(z%).tSUta * ta!) 'determina il numero di passi temporali necessari ad arrivare allla durata d considerata con il paso temporale dt!.
  138.         FOR i% = 1 TO 50
  139.             matrice1(ieto%, z%, i%, 1).MOCKUStSUta = mockus(i%).MOCKUStSUta
  140.             matrice1(ieto%, z%, i%, 1).MOCKUSqSUqp = mockus(i%).MOCKUSqSUqp
  141.             matrice1(ieto%, z%, i%, 1).m = i%
  142.             matrice1(ieto%, z%, i%, 1).mdt = matrice1(ieto%, z%, i%, 1).m * dt!(ieto%, z%)
  143.             matrice1(ieto%, z%, i%, 1).tminuti = matrice1(ieto%, z%, i%, 1).mdt * 60
  144.             SELECT CASE (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 'crea il vettore dell'idrogramma unitario di Mockus con i multipli del coeff. z% considerato (0.1,0.2,0.3,0.5,1).
  145.                 CASE IS <= 5 'valore massimo di t/ta di Mockus
  146.                     matrice1(ieto%, z%, i%, 1).tmSUta = (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 '=matrice1(i%).m *  matrice1(i%).mdt / ta!
  147.                 CASE ELSE
  148.                     matrice1(ieto%, z%, i%, 1).tmSUta = 0
  149.             END SELECT
  150.         NEXT i%
  151.         FOR i% = 1 TO 50
  152.             n% = 1
  153.             DO 'crea il vettore dell'idrogramma unitario Mockus prendendo i valori corrispondenti di ai coefficienti.
  154.                 IF matrice1(ieto%, z%, i%, 1).tmSUta = matrice1(ieto%, z%, n%, 1).MOCKUStSUta THEN
  155.                     matrice1(ieto%, z%, i%, 1).qmSUqp = matrice1(ieto%, z%, n%, 1).MOCKUSqSUqp
  156.                     EXIT DO
  157.                 ELSE
  158.                     n% = n% + 1
  159.                 END IF
  160.             LOOP UNTIL n% = 50
  161.             matrice1(ieto%, z%, i%, 1).qm = matrice1(ieto%, z%, i%, 1).qmSUqp * qp!
  162.         NEXT i%
  163.         FOR i% = 1 TO m%(ieto%, z%)
  164.             matrice1(ieto%, z%, i%, 1).h1 = k! * a2! * matrice1(ieto%, z%, i%, 1).mdt ^ n1!
  165.             IF i% = 1 THEN
  166.                 matrice1(ieto%, z%, i%, 1).i1 = matrice1(ieto%, z%, i%, 1).h1 / dt!(ieto%, z%)
  167.             ELSE
  168.                 matrice1(ieto%, z%, i%, 1).i1 = (matrice1(ieto%, z%, i%, 1).h1 - matrice1(ieto%, z%, i% - 1, 1).h1) / dt!(ieto%, z%)
  169.             END IF
  170.         NEXT i%
  171.         SELECT CASE ieto%
  172.             CASE 1 'Chicago.
  173.                 CALL chicago
  174.             CASE 2 'costante
  175.                 FOR i% = 1 TO m%(ieto%, z%)
  176.                     matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z%, m%(ieto%, z%), 1).h1 / matrice1(ieto%, z%, m%(ieto%, z%), 1).mdt
  177.                 NEXT i%
  178.         END SELECT
  179.         FOR i% = 1 TO m%(ieto%, z%)
  180.             matrice1(ieto%, z%, i%, 1).DH = matrice1(ieto%, z%, i%, 1).i2 * dt!(ieto%, z%)
  181.             IF i% = 1 THEN
  182.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH
  183.             ELSE
  184.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH + matrice1(ieto%, z%, i% - 1, 1).H2
  185.             END IF
  186.             SELECT CASE matrice1(ieto%, z%, i%, 1).H2 - Ia!
  187.                 CASE IS < 0
  188.                     matrice1(ieto%, z%, i%, 1).he = 0
  189.                 CASE IS >= 0
  190.                     matrice1(ieto%, z%, i%, 1).he = (matrice1(ieto%, z%, i%, 1).H2 - Ia!) ^ 2 / (matrice1(ieto%, z%, i%, 1).H2 - Ia! + S2!)
  191.             END SELECT
  192.             IF i% = 1 THEN
  193.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he
  194.             ELSE
  195.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he - matrice1(ieto%, z%, i% - 1, 1).he
  196.             END IF
  197.         NEXT i%
  198.  
  199.         '-------------------------------matrice2-------------------------------------------------------------------------------------------------------------------------
  200.  
  201.         FOR n% = 1 TO 50 'colonna
  202.             FOR i% = n% TO 50 ' riga
  203.                 matrice2!(ieto%, z%, i%, n%) = matrice1(ieto%, z%, i% - n% + 1, 1).Dhe * matrice1(ieto%, z%, n%, 1).qm
  204.             NEXT i%
  205.         NEXT n%
  206.         '-------------------------------idrogramma------------------------------------------------------------------------------------------------------------------
  207.         FOR i% = 1 TO 50 'riga
  208.             FOR n% = 1 TO 50 'colonna
  209.                 idrogramma(ieto%, z%, i%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata + matrice2!(ieto%, z%, i%, n%)
  210.  
  211.             NEXT n%
  212.             idrogramma(ieto%, z%, i%, 1).ore = matrice1(ieto%, z%, i%, 1).mdt
  213.             idrogramma(ieto%, z%, i%, 1).minuti = matrice1(ieto%, z%, i%, 1).tminuti
  214.         NEXT i%
  215.         '-------------------------------Massimi-----------------------------------------------------
  216.         i% = 1
  217.         'massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, 1, 1).portata
  218.         DO
  219.             IF massimi1(ieto%, z%, 1).portata < idrogramma(ieto%, z%, i%, 1).portata THEN
  220.                 massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata
  221.                 massimi1(ieto%, z%, 1).ore = idrogramma(ieto%, z%, i%, 1).ore
  222.                 massimi1(ieto%, z%, 1).minuti = idrogramma(ieto%, z%, i%, 1).minuti
  223.             END IF
  224.             i% = i% + 1
  225.         LOOP UNTIL i% = 50
  226.         ' IF massimi2(ieto%).ore < massimi1(visualizzaieto%, z%, 1).ore THEN massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  227.         IF massimi2(ieto%).portata < massimi1(visualizzaieto%, z%, 1).portata THEN
  228.             massimi2(ieto%).portata = massimi1(visualizzaieto%, z%, 1).portata
  229.             massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  230.         END IF
  231.     LOOP UNTIL z% = UBOUND(coefficienti)
  232. '---------------------------------------------------------------------------------------------------------------------------------------------------
  233. 'Questa subroutine crea gli ietogrammi chicago per ogni iterazione z%.
  234. 'Ad ogni nuovo dt! pone l'ultimo valore di pioggia come ultimo, il penultimo come primo, il terzultimo come penultimo, il quartultimo come secondo e così via.
  235. 'Quando vi è un valore di z% che ha un dt! non nuovo, cerca la precedente iterazione z% con lo stesso dt! e copia i suoi valori dello ietogramma chicago in quello dell'iterazione z% in corso. I valori rimanenti sono riempiti
  236. 'procedendo come prima.
  237. 'Quindi per esempio l'iterazione z%=1 corrisponde a d=1tc con passo temporale dt!. L'iterazione z%=2 corrisponde a d=2tc con il medesimo passo temporale. Per cui lo ietogramma chicago per d=2tc e' dato dallo stesso ietogramma
  238. 'chicago che si ha per d=1tc, con l'aggiunta, ai suoi estremi, dei nuovi valori. Il meccanismo si ripete per z%=3, che corrisponde a d=3tc, con il medesimo dt!. Per z%=4, corrispondente a d=4tc, invece, il passo temporale dt!
  239. 'cambia.
  240. 'Quanto detto e' necessario per evitare piccole discrepanze che potrebbero comportare il fatto che alcuni massimi risultino localmente poco piu' bassi del precedente, anche quando il trend generale e' chiaramente di aumento dei
  241. 'massimi all'aumentare della durata della pioggia. In questo modo si fa l'ipotesi che all'aumentare della durata della pioggia, discretizzata con uno stesso passo temporale dt!, ogni ietogramma contenga a sua volta il precedente.
  242. 'In tal modo, se si condiera per esempio d=2tc, si assume che l'altezza di pioggia corrispondente a 1tc, segua lo ietogramma relativo a d=1tc, cosi' che l'altezza di pioggia rimamente sia eclusivamente dovuta ai nuovi valori.
  243. SUB chicago ()
  244.     DIM test%
  245.     DIM k%
  246.     n% = 1
  247.     DO
  248.         IF z% = 1 THEN test% = 0: EXIT DO 'permette il calcolo dello ietogramma chicago della prima iterazione. test%=0
  249.         IF dt!(ieto%, z%) = dt!(ieto%, z% - n%) THEN ' se trova un'iterazione z% precedente con lo stesso dt! di quella in corso, esegue i comandi successivi
  250.             test% = 1
  251.             k% = m%(ieto%, z%)
  252.             i% = 0
  253.             DO 'inserisce i nuovi valori dello ietogramma chicago dell'iterazione z% in corso.
  254.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  255.                 k% = k% - 1
  256.                 IF k% = m%(ieto%, z% - n%) THEN EXIT DO 'se ha completato l'inserimento dei nuovi valori, passa oltre.
  257.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  258.                 k% = k% - 1
  259.                 i% = i% + 1
  260.             LOOP UNTIL k% = m%(ieto%, z% - n%)
  261.             IF matrice1(ieto%, z%, i%, 1).i2 = 0 THEN i% = i% - 1
  262.             k% = 1
  263.             DO 'inserisce lo ietogramma chicago dell'iterazione z% precedente con lo stesso dt!, nello ietogramma dell'iterazione z% in corso.
  264.                 i% = i% + 1
  265.                 matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z% - n%, k%, 1).i2
  266.                 k% = k% + 1
  267.             LOOP UNTIL k% > m%(ieto%, z% - n%)
  268.             EXIT DO 'siccome ha completato lo ietogramma dell'iterazione z% in corso, non serve incrementare n%, quindi passa oltre. test%=1.
  269.         ELSE ' se non trova l'iterazione z% precedente con lo stesso dt! di quella in corso, incrementa n% e ripete la ricerca.
  270.             test% = 0
  271.             n% = n% + 1
  272.         END IF
  273.     LOOP UNTIL n% = z% - 1 'se non ha trovato iterazioni z% precedenti con lo stesso dt!, allora passa oltre e test%=0.
  274.     SELECT CASE test%
  275.         CASE IS = 1 'esce dalla subroutine, in quanto lo ietogramma e' definito.
  276.             EXIT SUB
  277.         CASE IS = 0 'calcola ex-novo lo ietogramma relativo all'iterazione z% in corso in quanto non vi e' un'iterazioni z% precedente con lo stesso dt! dell'iterazione z% in corso.
  278.             k% = m%(ieto%, z%)
  279.             i% = 0
  280.             DO
  281.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  282.                 k% = k% - 1
  283.                 IF k% = 0 THEN EXIT DO
  284.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  285.                 k% = k% - 1
  286.                 i% = i% + 1
  287.             LOOP UNTIL k% = 0
  288.     END SELECT
  289. '-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  290. SUB grafici (ore!, oreM!, QM!)
  291.     'ore!: ore corrispondenti al massimo maggiore.
  292.     'oreM!: ore corrispondenti alla portata massima.
  293.     'QM!: portata massima.
  294.  
  295.     CONST R& = _RGB32(255, 0, 0)
  296.     CONST G& = _RGB32(0, 255, 0)
  297.     CONST B& = _RGB32(0, 0, 255)
  298.     CONST bianco& = _RGB32(255, 255, 255)
  299.     CONST giallo& = _RGB32(255, 255, 0)
  300.  
  301.     DIM L%, H% 'dimensioni del grafico.
  302.     DIM grafico&, colore&
  303.  
  304.     DIM dx%, dy% 'origine degli assi dentro SCREEN.
  305.     DIM dx!, dy! 'posizione dell'origine degli assi dentro WINDOW.
  306.     DIM taccaX%, taccaY%
  307.     DIM x%, y% 'conversione nelle coordinate di SCREEN delle coordinate dentro WINDOW corrispondenti a determinati valori.
  308.  
  309.     H% = _DESKTOPHEIGHT * 2 / 3 ' imposta l'altezza dello SCREEN pari ai 2/3 dello schermo visualizzabile, cosi' che su ogni PC sia visualizzabile.
  310.     L% = H% * 1.62 'imposta la larghezza dello SCREEN in modo che L%xH% sia un rettangolo aureo.
  311.     dx% = 39
  312.     dy% = H% - 1 - dx%
  313.     taccaX% = ore! \ 5 ': PRINT taccaX%: SLEEP
  314.     taccaY% = QM! \ 5
  315.     grafico& = _NEWIMAGE(L%, H%, 32)
  316.  
  317.     _DEST grafico&
  318.     ' SCREEN grafico&
  319.     LINE (0, 0)-(L% - 1, H% - 1), R, B
  320.     WINDOW (0, 0)-(ore! * 1.15, QM! * 1.15) 'scala ascisse e ordinate in base alle ore e alla portata, estendendole del 15%.
  321.     dx! = PMAP(dx%, 2)
  322.     dy! = PMAP(dy%, 3)
  323.     LINE (dx!, QM! * 1.1)-(dx!, dy!): LINE -(ore! * 1.1, dy!), bianco& 'disegna gli assi in modo che si estendano del 10% oltre valori massimi, ma senza arrivare alla massima estensione delle coordinate impostate da WINDOW: cosi' si ha che gli assi non toccano la cornice rossa e i valori massimi che non arrivano al limite degli assi.
  324.     PSET (dx!, QM! * 1.1!), bianco&: DRAW "F20": PSET (dx!, QM! * 1.1), bianco&: DRAW "G20"
  325.     PSET (ore! * 1.1, dy!), bianco&: DRAW "G20": PSET (ore! * 1.1, dy!), bianco&: DRAW "H20"
  326.     _PRINTSTRING (dx%, PMAP(QM! * 1.1, 1) - dx% \ 2), "mc/s"
  327.     _PRINTSTRING (PMAP(ore! * 1.1, 0), dy%), "ore"
  328.     _PRINTSTRING (dx% \ 4, dy% - 7), "0"
  329.     FOR z% = 1 TO 24
  330.         SELECT CASE z% MOD 3
  331.             CASE IS = 1
  332.                 colore& = R&
  333.             CASE IS = 2
  334.                 colore& = G&
  335.             CASE IS = 0
  336.                 colore& = B&
  337.         END SELECT
  338.         CIRCLE (dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), PMAP(3, 2), R&
  339.         PAINT (dx! + massimi1(visualizzaieto%, z%, 1).ore + PMAP(0.5, 2), dy! + massimi1(visualizzaieto%, z%, 1).portata + PMAP(0.5, 2)), R&
  340.         FOR i% = 1 TO 50
  341.             '            _LIMIT limit
  342.             IF i% = 1 THEN
  343.                 LINE (dx!, dy!)-(dx! + idrogramma(visualizzaieto%, z%, i%, 1).ore, dy! + idrogramma(visualizzaieto%, z%, i%, 1).portata), colore&
  344.             ELSE
  345.                 LINE (dx! + idrogramma(visualizzaieto%, z%, i% - 1, 1).ore, dy! + idrogramma(visualizzaieto%, z%, i% - 1, 1).portata)-(dx! + idrogramma(visualizzaieto%, z%, i%, 1).ore, dy! + idrogramma(visualizzaieto%, z%, i%, 1).portata), colore&
  346.             END IF
  347.             '            _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  348.         NEXT i%
  349.         IF z% = 1 THEN
  350.             LINE (dx!, dy!)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), giallo&
  351.         ELSE
  352.             LINE (dx! + massimi1(visualizzaieto%, z% - 1, 1).ore, dy! + massimi1(visualizzaieto%, z% - 1, 1).portata)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), giallo&
  353.         END IF
  354.     NEXT z%
  355.     LINE (dx!, dy! + QM!)-(dx! + oreM!, dy! + QM!), bianco&, , 61440
  356.     LINE -(dx! + oreM!, dy!), bianco&, , 61440
  357.     x% = PMAP(dx! + oreM!, 0)
  358.     y% = PMAP(dy! + QM!, 1)
  359.     _PRINTSTRING (x% + 10, y% - dx%), "(" + _TRIM$(STR$(oreM!)) + ","
  360.     _PRINTSTRING (x% + 10, y% - dx% + 16), _TRIM$(STR$(QM!)) + ")"
  361.     i% = 1
  362.     WHILE i% * taccaX% <= ore!
  363.         LINE (dx! + i% * taccaX%, PMAP(dy% + 5, 3))-(dx! + i% * taccaX%, PMAP(dy% - 5, 3))
  364.         x% = PMAP(dx! + i% * taccaX%, 0)
  365.         _PRINTSTRING (x% - 4 * LEN(_TRIM$(STR$(i% * taccaX%))), H% - 1 - dx% / 1.5), _TRIM$(STR$(i% * taccaX%))
  366.         i% = i% + 1
  367.     WEND
  368.     i% = 1
  369.     WHILE i% * taccaY% <= QM!
  370.         LINE (PMAP(dx% - 5, 2), dy! + i% * taccaY%)-(PMAP(dx% + 5, 2), dy! + i% * taccaY%)
  371.         y% = PMAP(dy! + i% * taccaY%, 1)
  372.         _PRINTSTRING (dx% \ 4, y% - 7), _TRIM$(STR$(i% * taccaY%))
  373.         i% = i% + 1
  374.     WEND
  375.     _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  376.  
  377.     _DEST schermo&
  378.     VIEW PRINT 1 TO 10
  379.     '  DO
  380.     '  CLS 2
  381.     ' PRINT "Digitare le ore e i minuti (<= "; _TRIM$(STR$(INT(ore!))); " ore e "; _TRIM$(STR$(INT((ore! - INT(ore!)) * 60))); " minuti) di cui si vuole conoscere la portata di picco."
  382.     'INPUT "Ore: ", ore2!
  383.     'INPUT "Minuti: ", minuti%
  384.     'ore2! = ore2! + minuti% / 60
  385.     'LOOP WHILE ore2! > ore!
  386.     ore2! = 3
  387.     _DEST grafico&
  388.     x% = PMAP(dx! + ore2!, 0)
  389.     y% = PMAP(dy!, 1)
  390.     SCREEN grafico& '------------------------------------------------------------------------------------>?????????????????????????????????????
  391.     DO
  392.         IF POINT(dx! + ore2!, PMAP(y%, 3)) = giallo& THEN EXIT DO
  393.         y% = y% - 1
  394.     LOOP
  395.     ' _LIMIT limit
  396.     LINE (dx! + ore2!, dy!)-(dx! + ore2!, PMAP(y%, 3)), bianco&, , 65280
  397.     _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  398.     '   _FREEIMAGE grafico&
  399. '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  400. SUB risultati ()
  401.     FOR z% = 1 TO 24
  402.         CLS
  403.         PRINT "z%="; z%
  404.         PRINT "dt="; dt!(visualizzaieto%, z%); ";"; dt!(visualizzaieto%, z%) * 60
  405.         PRINT "visualizzaieto%="; visualizzaieto%
  406.         PRINT "m%="; m%(visualizzaieto%, z%)
  407.         PRINT "N="; coefficienti(z%).d / tc!
  408.         PRINT "n="; coefficienti(z%).tSUta
  409.         FOR i% = 1 TO 50
  410.             '  _LIMIT limit
  411.     PRINT _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).m)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).mdt)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tminuti)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).h1)),_
  412.      _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i1)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i2)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).DH)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).H2)),_
  413.       _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).he)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).Dhe)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUStSUta)),_
  414.        _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUSqSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tmSUta)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qmSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qm))
  415.         NEXT i%
  416.         SLEEP
  417.         CLS
  418.         FOR n% = 1 TO 50
  419.             '  _LIMIT limit
  420.             LOCATE 1,
  421.             FOR i% = 1 TO 50
  422.                 LOCATE , n% * 4 - 3
  423.                 PRINT matrice2!(visualizzaieto%, z%, i%, n%)
  424.             NEXT i%
  425.         NEXT n%
  426.         SLEEP
  427.     NEXT z%
  428.     CLS
  429.     FOR n% = 1 TO 24
  430.         ' _LIMIT limit
  431.         SELECT CASE n%
  432.             CASE IS <= 16
  433.                 FOR i% = 1 TO 50
  434.                     LOCATE i%, n% * 15 - 14
  435.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  436.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  437.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  438.  
  439.                 NEXT i%
  440.                 IF n% = 16 THEN SLEEP: CLS
  441.             CASE IS > 16
  442.                 FOR i% = 1 TO 50
  443.                     LOCATE i%, (n% - 16) * 15 - 14
  444.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  445.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  446.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  447.                 NEXT i%
  448.         END SELECT
  449.     NEXT n%
  450.     SLEEP
  451.     CLS
  452.     FOR z% = 1 TO 24
  453.         ' _LIMIT limit
  454.         PRINT massimi1(visualizzaieto%, z%, 1).ore, massimi1(visualizzaieto%, z%, 1).minuti, massimi1(visualizzaieto%, z%, 1).portata
  455.     NEXT z%
  456.     SLEEP
  457.     PRINT
  458.     PRINT massimi2(visualizzaieto%).ore; massimi2(visualizzaieto%).portata
  459.  
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 22, 2021, 11:21:31 am
Because of math rounding errors in a Window a point might not be exactly where you'd expect down to the pixel.

Use of Point to verify you are on yellow seems smart to me. It's not perfect but we do not live in perfect world.

Maybe I don't understand the problem. Do you want to work on the side and show results on main screen?

Do you know about setting up a separate drawing area and working in that, then use _Putimage of final result for main screen?


You do know that. :)

When using POINT you have to set SOURCE for it. This tells it where you want to read colors from. I bet that might be it.
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 22, 2021, 11:39:42 am
@bartok

Yes I just scanned your code and no sign of Source.  So when working in an image on the side set _Source to that just like _Dest and them back when you are done and exiting that part of code. _Source is to let POINT know you are reading point locations in the side thing instead or main screen.

With _Source you can read POINT out of main screen or other images on the side.
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 22, 2021, 12:14:06 pm
Perfect. And once again the computer was right!

Thanks!
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 25, 2021, 06:41:05 am
Hi, I am in trouble again.
Below, there are 2 codes, that have to do the same thing. Code 1, with a subroutine, and it works. Code 2, splitting the subroutine of Code 1, obteining also a sub-subroutine: it doesn't work.

In the code 1, the line 135 calls the subroutine "grafici".

The subroutine "grafici" starts at line 301 and goes to SYSTEM at line 433 before the end of the subroutine. This code, as said, works fine.

In code 1, I have highlighted a part of the subroutine "grafici" (lines between 396 and 434), because it is the part that in Code 2 will became a sub-subroutine, and that is the core of my problem in the Code 2.

In fact, in the Code 2, I have aptempted to transform the lines between 396 and 434 (of Code 1) in a sub-subroutine, called "idrogrammaprogetto".

Speaking about the Code 2, it is egual to the Code 1 until the line 395, then the sub-subroutine "idrogrammaprogetto" is called.

the sub-subroutine "idrogrammaprogetto" starts at line 444, but the program, this time, goes in loop and never goes to system, as intended in line 399.

With "vwatch.exe", I have seen that, in code 2, the problem is the DO cicle of lines 468 to 472, corresponding to the lines 416 to 419 of code 1.

Similarly to one of my preview problems, this DO cicle searches a yellow pixel and, if it is succeeds, the program have to do something: in this case, it should go ahead and go to SYSTEM, as in Code 1. The other time, the program didn't exit the DO cicle, as none yellow pixel was found, because no _SOURCE was specified. Specyfing the _SOURCE, the problem was solved.

In this case, the problem is apparently the same: the program goes in loop in the DO cicle, because it doesn't match the yellow pixel. But this time, the _SOURCE is specified at line 459.

Futhermore, all the required variables for the sub-subroutine are passed by reference. for example: it is not possible that the DO cicle doesn't find the yellow pixel because the yellow variable is not passed. In fact, it is passed in lines 396 and 444: "giallo&". Similarly, is not possible that the yellow pixel is not found because the image with the graphics is not passed: it is "grafico&". So, I have finished the ideas. To conclude, the problem is not even matter of coordinates.

CODE 1.
Code: QB64: [Select]
  1.  
  2. mockus: 'dati dell'idrogramma unitario di Mockus
  3. DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  4. DATA 0.030,0.100,0.190,0.310,0.470,0.660,0.820,0.930,0.990,1.000,0.990,0.930,0.860,0.780,0.680,0.560,0.460,0.390,0.330,0.280,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.040,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0.000: ' t/tp
  5.  
  6. coefficienti:
  7. DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32: 'N volte tc!.
  8. DATA 0.1,0.1,0.1,0.2,0.3,0.2,0.3,0.3,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,1,1,1,1,1,1,1: 'discretizzazione dei coeff. di Mockus.
  9.  
  10. TYPE mockus
  11.     MOCKUStSUta AS SINGLE
  12.     MOCKUSqSUqp AS SINGLE
  13.  
  14. TYPE matrice1
  15.     m AS INTEGER '[numero naturale] conta il numero di interazioni fino al raggiungimento di "d".
  16.     mdt AS SINGLE '[ore] conta la progessione delle ore fino al raggiungimento di "d".
  17.     tminuti AS SINGLE '[minuti] trasforma mdt in minuti.
  18.     h1 AS SINGLE '[mm] valore h della curva di possibilità climatica.
  19.     i1 AS SINGLE '[mm/ora] intensità di pioggia.
  20.     i2 AS SINGLE '[mm/ora] intensità di pioggia secondo lo ietogramma Chicago o costante.
  21.     DH AS SINGLE '[mm] pioggia in ogni istante temporale dt.
  22.     H2 AS SINGLE '[mm] pioggia cumulata ad ogni istante temporale.
  23.     he AS SINGLE '[mm] piggia efficace cumulata ad ogni istante temporale.
  24.     Dhe AS SINGLE '[mm] pioggia efficace ad ogni istante temporale.
  25.     MOCKUStSUta AS SINGLE
  26.     MOCKUSqSUqp AS SINGLE
  27.     tmSUta AS SINGLE '[-].
  28.     qmSUqp AS SINGLE '[-] il valore di qm/qp corrispondente a tm/ta e' = al valore di q/qp che corrisponde a t/ta=tm/ta.
  29.     qm AS SINGLE '[mc/s].
  30.  
  31. TYPE coefficienti
  32.     d AS SINGLE
  33.     tSUta AS SINGLE
  34.  
  35. TYPE idrogramma
  36.     ore AS SINGLE
  37.     minuti AS SINGLE
  38.     portata AS SINGLE
  39.  
  40. CONST limit = 200 '50
  41.  
  42. DIM SHARED mockus(50) AS mockus
  43. DIM SHARED dt!(2, 24)
  44. DIM SHARED matrice1(2, 24, 50, 1) AS matrice1
  45. DIM SHARED coefficienti(24) AS coefficienti
  46. DIM SHARED matrice2!(2, 24, 50, 50)
  47. DIM SHARED idrogramma(2, 24, 50, 1) AS idrogramma
  48. DIM SHARED massimi1(2, 24, 1) AS idrogramma
  49. DIM SHARED massimi2(2) AS idrogramma
  50. DIM SHARED i%, n%, z%, ieto%
  51. DIM SHARED m%(2, 24)
  52. DIM SHARED S2! '[mm] contenuto idrico massimo del terreno.
  53. DIM SHARED Ia! '[mm] perdite iniziali.
  54. DIM SHARED tc! '[ore] tempo di corrivazione
  55. DIM SHARED ta! '[ore] tempo di picco.
  56. DIM SHARED qp! '[mc/s] portata al colmo dell'idrogramma unitario.
  57. DIM SHARED k! '[-] coeff. della curva di possibilità climatica tado dal sito della Regione.
  58. DIM SHARED a2! '[mm/d^n] coeff. della curva di possibilità climatica.
  59. DIM SHARED n1! '[-] coeff. della curva di possibilità climatica.
  60. DIM SHARED visualizzaieto%
  61. DIM schermo&
  62. DIM A1! '[mq] superficie bacino idrografico.
  63. DIM L! '[m] lunghezza asta principale.
  64. DIM HmaxL! '[m] punto più alto dell'astra principale.
  65. DIM HminL! '[m] punto più basso dell'asta principale.
  66. DIM s1! '[-] pendenza media del bacino non espressa in percentuale ma come 0,x.
  67. DIM CNII! '[-] tabellato.
  68. DIM CNIII '[-] discende da CNII.
  69. DIM tl! '[ore] tempo di ritardo.
  70. DIM keypress$
  71.  
  72. SCREEN schermo&
  73.  
  74. A1! = 2641902
  75. k! = 2.34
  76. a2! = 14.6653
  77. n1! = 0.45596
  78. L! = 3300
  79. HmaxL! = 1981
  80. HminL! = 1062
  81. s1! = 0.415
  82. CNII! = 70
  83.  
  84. 'INPUT A1!
  85. 'INPUT k!
  86. 'INPUT a2!
  87. 'INPUT n1!
  88. 'INPUT L!
  89. 'INPUT HmaxL!
  90. 'INPUT HminL!
  91. 'INPUT s1!
  92. 'INPUT CNII!
  93. 'INPUT d1!
  94.  
  95. CNIII! = (23 * CNII!) / (10 + 0.13 * CNII!)
  96. tl! = 0.342 * ((L! / 1000) ^ 0.8 / (100 * s1!) ^ 0.5) * (1000 / CNIII! - 9) ^ 0.7 'formula di Mockus.
  97. S2! = 25.4 * (1000 / CNIII! - 10)
  98. Ia! = 0.1 * S2! 'coeff.=0.03-0.2.
  99. tc! = tl! / 0.6
  100. ta! = tl! / 0.9
  101. qp! = 0.208 * ((A1! / 1000000) / ta!)
  102.  
  103. RESTORE mockus
  104. FOR i% = 1 TO 100
  105.     IF i% <= 50 THEN READ mockus(i%).MOCKUStSUta
  106.     IF i% > 50 THEN READ mockus(i% - 50).MOCKUSqSUqp
  107. NEXT i%
  108.  
  109. RESTORE coefficienti
  110. FOR i% = 1 TO 48
  111.     IF i% <= 24 THEN READ coefficienti(i%).d: coefficienti(i%).d = coefficienti(i%).d * tc!
  112.     IF i% > 24 THEN READ coefficienti(i% - 24).tSUta
  113. NEXT i%
  114.  
  115. PRINT "Ietogramma Chicago/costante: 1/2> "
  116. 'DO
  117. '_LIMIT 60 'limit
  118. 'keypress$ = INKEY$
  119. 'LOOP UNTIL keypress$ = "1" OR keypress$ = "2"
  120. visualizzaieto% = 1
  121.  
  122. FOR ieto% = 1 TO 2
  123.     CALL creamatrici
  124. NEXT ieto%
  125.  
  126. CALL grafici(massimi1(visualizzaieto%, 24, 1).ore, massimi2(visualizzaieto%).ore, massimi2(visualizzaieto%).portata) 'valori passati per disegnare il grafico.
  127. 'CALL risultati
  128.  
  129. '-----------------------------------------matrice1---------------------------------------------------------------------------------------------------------------------------------
  130. SUB creamatrici ()
  131.     z% = 0
  132.     DO
  133.         z% = z% + 1
  134.         dt!(ieto%, z%) = coefficienti(z%).tSUta * ta!
  135.         m%(ieto%, z%) = coefficienti(z%).d / (coefficienti(z%).tSUta * ta!) 'determina il numero di passi temporali necessari ad arrivare allla durata d considerata con il paso temporale dt!.
  136.         FOR i% = 1 TO 50
  137.             matrice1(ieto%, z%, i%, 1).MOCKUStSUta = mockus(i%).MOCKUStSUta
  138.             matrice1(ieto%, z%, i%, 1).MOCKUSqSUqp = mockus(i%).MOCKUSqSUqp
  139.             matrice1(ieto%, z%, i%, 1).m = i%
  140.             matrice1(ieto%, z%, i%, 1).mdt = matrice1(ieto%, z%, i%, 1).m * dt!(ieto%, z%)
  141.             matrice1(ieto%, z%, i%, 1).tminuti = matrice1(ieto%, z%, i%, 1).mdt * 60
  142.             SELECT CASE (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 'crea il vettore dell'idrogramma unitario di Mockus con i multipli del coeff. z% considerato (0.1,0.2,0.3,0.5,1).
  143.                 CASE IS <= 5 'valore massimo di t/ta di Mockus
  144.                     matrice1(ieto%, z%, i%, 1).tmSUta = (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 '=matrice1(i%).m *  matrice1(i%).mdt / ta!
  145.                 CASE ELSE
  146.                     matrice1(ieto%, z%, i%, 1).tmSUta = 0
  147.             END SELECT
  148.         NEXT i%
  149.         FOR i% = 1 TO 50
  150.             n% = 1
  151.             DO 'crea il vettore dell'idrogramma unitario Mockus prendendo i valori corrispondenti di ai coefficienti.
  152.                 IF matrice1(ieto%, z%, i%, 1).tmSUta = matrice1(ieto%, z%, n%, 1).MOCKUStSUta THEN
  153.                     matrice1(ieto%, z%, i%, 1).qmSUqp = matrice1(ieto%, z%, n%, 1).MOCKUSqSUqp
  154.                     EXIT DO
  155.                 ELSE
  156.                     n% = n% + 1
  157.                 END IF
  158.             LOOP UNTIL n% = 50
  159.             matrice1(ieto%, z%, i%, 1).qm = matrice1(ieto%, z%, i%, 1).qmSUqp * qp!
  160.         NEXT i%
  161.         FOR i% = 1 TO m%(ieto%, z%)
  162.             matrice1(ieto%, z%, i%, 1).h1 = k! * a2! * matrice1(ieto%, z%, i%, 1).mdt ^ n1!
  163.             IF i% = 1 THEN
  164.                 matrice1(ieto%, z%, i%, 1).i1 = matrice1(ieto%, z%, i%, 1).h1 / dt!(ieto%, z%)
  165.             ELSE
  166.                 matrice1(ieto%, z%, i%, 1).i1 = (matrice1(ieto%, z%, i%, 1).h1 - matrice1(ieto%, z%, i% - 1, 1).h1) / dt!(ieto%, z%)
  167.             END IF
  168.         NEXT i%
  169.         SELECT CASE ieto%
  170.             CASE 1 'Chicago.
  171.                 CALL chicago
  172.             CASE 2 'costante
  173.                 FOR i% = 1 TO m%(ieto%, z%)
  174.                     matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z%, m%(ieto%, z%), 1).h1 / matrice1(ieto%, z%, m%(ieto%, z%), 1).mdt
  175.                 NEXT i%
  176.         END SELECT
  177.         FOR i% = 1 TO m%(ieto%, z%)
  178.             matrice1(ieto%, z%, i%, 1).DH = matrice1(ieto%, z%, i%, 1).i2 * dt!(ieto%, z%)
  179.             IF i% = 1 THEN
  180.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH
  181.             ELSE
  182.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH + matrice1(ieto%, z%, i% - 1, 1).H2
  183.             END IF
  184.             SELECT CASE matrice1(ieto%, z%, i%, 1).H2 - Ia!
  185.                 CASE IS < 0
  186.                     matrice1(ieto%, z%, i%, 1).he = 0
  187.                 CASE IS >= 0
  188.                     matrice1(ieto%, z%, i%, 1).he = (matrice1(ieto%, z%, i%, 1).H2 - Ia!) ^ 2 / (matrice1(ieto%, z%, i%, 1).H2 - Ia! + S2!)
  189.             END SELECT
  190.             IF i% = 1 THEN
  191.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he
  192.             ELSE
  193.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he - matrice1(ieto%, z%, i% - 1, 1).he
  194.             END IF
  195.         NEXT i%
  196.  
  197.         '-------------------------------matrice2-------------------------------------------------------------------------------------------------------------------------
  198.  
  199.         FOR n% = 1 TO 50 'colonna
  200.             FOR i% = n% TO 50 ' riga
  201.                 matrice2!(ieto%, z%, i%, n%) = matrice1(ieto%, z%, i% - n% + 1, 1).Dhe * matrice1(ieto%, z%, n%, 1).qm
  202.             NEXT i%
  203.         NEXT n%
  204.         '-------------------------------idrogramma------------------------------------------------------------------------------------------------------------------
  205.         FOR i% = 1 TO 50 'riga
  206.             FOR n% = 1 TO 50 'colonna
  207.                 idrogramma(ieto%, z%, i%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata + matrice2!(ieto%, z%, i%, n%)
  208.  
  209.             NEXT n%
  210.             idrogramma(ieto%, z%, i%, 1).ore = matrice1(ieto%, z%, i%, 1).mdt
  211.             idrogramma(ieto%, z%, i%, 1).minuti = matrice1(ieto%, z%, i%, 1).tminuti
  212.         NEXT i%
  213.         '-------------------------------Massimi-----------------------------------------------------
  214.         i% = 1
  215.         'massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, 1, 1).portata
  216.         DO
  217.             IF massimi1(ieto%, z%, 1).portata < idrogramma(ieto%, z%, i%, 1).portata THEN
  218.                 massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata
  219.                 massimi1(ieto%, z%, 1).ore = idrogramma(ieto%, z%, i%, 1).ore
  220.                 massimi1(ieto%, z%, 1).minuti = idrogramma(ieto%, z%, i%, 1).minuti
  221.             END IF
  222.             i% = i% + 1
  223.         LOOP UNTIL i% = 50
  224.         ' IF massimi2(ieto%).ore < massimi1(visualizzaieto%, z%, 1).ore THEN massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  225.         IF massimi2(ieto%).portata < massimi1(visualizzaieto%, z%, 1).portata THEN
  226.             massimi2(ieto%).portata = massimi1(visualizzaieto%, z%, 1).portata
  227.             massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  228.         END IF
  229.     LOOP UNTIL z% = UBOUND(coefficienti)
  230. '---------------------------------------------------------------------------------------------------------------------------------------------------
  231. 'Questa subroutine crea gli ietogrammi chicago per ogni iterazione z%.
  232. 'Ad ogni nuovo dt! pone l'ultimo valore di pioggia come ultimo, il penultimo come primo, il terzultimo come penultimo, il quartultimo come secondo e così via.
  233. 'Quando vi è un valore di z% che ha un dt! non nuovo, cerca la precedente iterazione z% con lo stesso dt! e copia i suoi valori dello ietogramma chicago in quello dell'iterazione z% in corso. I valori rimanenti sono riempiti
  234. 'procedendo come prima.
  235. 'Quindi per esempio l'iterazione z%=1 corrisponde a d=1tc con passo temporale dt!. L'iterazione z%=2 corrisponde a d=2tc con il medesimo passo temporale. Per cui lo ietogramma chicago per d=2tc e' dato dallo stesso ietogramma
  236. 'chicago che si ha per d=1tc, con l'aggiunta, ai suoi estremi, dei nuovi valori. Il meccanismo si ripete per z%=3, che corrisponde a d=3tc, con il medesimo dt!. Per z%=4, corrispondente a d=4tc, invece, il passo temporale dt!
  237. 'cambia.
  238. 'Quanto detto e' necessario per evitare piccole discrepanze che potrebbero comportare il fatto che alcuni massimi risultino localmente poco piu' bassi del precedente, anche quando il trend generale e' chiaramente di aumento dei
  239. 'massimi all'aumentare della durata della pioggia. In questo modo si fa l'ipotesi che all'aumentare della durata della pioggia, discretizzata con uno stesso passo temporale dt!, ogni ietogramma contenga a sua volta il precedente.
  240. 'In tal modo, se si condiera per esempio d=2tc, si assume che l'altezza di pioggia corrispondente a 1tc, segua lo ietogramma relativo a d=1tc, cosi' che l'altezza di pioggia rimamente sia eclusivamente dovuta ai nuovi valori.
  241. SUB chicago ()
  242.     DIM test%
  243.     DIM k%
  244.     n% = 1
  245.     DO
  246.         IF z% = 1 THEN test% = 0: EXIT DO 'permette il calcolo dello ietogramma chicago della prima iterazione. test%=0
  247.         IF dt!(ieto%, z%) = dt!(ieto%, z% - n%) THEN ' se trova un'iterazione z% precedente con lo stesso dt! di quella in corso, esegue i comandi successivi
  248.             test% = 1
  249.             k% = m%(ieto%, z%)
  250.             i% = 0
  251.             DO 'inserisce i nuovi valori dello ietogramma chicago dell'iterazione z% in corso.
  252.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  253.                 k% = k% - 1
  254.                 IF k% = m%(ieto%, z% - n%) THEN EXIT DO 'se ha completato l'inserimento dei nuovi valori, passa oltre.
  255.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  256.                 k% = k% - 1
  257.                 i% = i% + 1
  258.             LOOP UNTIL k% = m%(ieto%, z% - n%)
  259.             IF matrice1(ieto%, z%, i%, 1).i2 = 0 THEN i% = i% - 1
  260.             k% = 1
  261.             DO 'inserisce lo ietogramma chicago dell'iterazione z% precedente con lo stesso dt!, nello ietogramma dell'iterazione z% in corso.
  262.                 i% = i% + 1
  263.                 matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z% - n%, k%, 1).i2
  264.                 k% = k% + 1
  265.             LOOP UNTIL k% > m%(ieto%, z% - n%)
  266.             EXIT DO 'siccome ha completato lo ietogramma dell'iterazione z% in corso, non serve incrementare n%, quindi passa oltre. test%=1.
  267.         ELSE ' se non trova l'iterazione z% precedente con lo stesso dt! di quella in corso, incrementa n% e ripete la ricerca.
  268.             test% = 0
  269.             n% = n% + 1
  270.         END IF
  271.     LOOP UNTIL n% = z% - 1 'se non ha trovato iterazioni z% precedenti con lo stesso dt!, allora passa oltre e test%=0.
  272.     SELECT CASE test%
  273.         CASE IS = 1 'esce dalla subroutine, in quanto lo ietogramma e' definito.
  274.             EXIT SUB
  275.         CASE IS = 0 'calcola ex-novo lo ietogramma relativo all'iterazione z% in corso in quanto non vi e' un'iterazioni z% precedente con lo stesso dt! dell'iterazione z% in corso.
  276.             k% = m%(ieto%, z%)
  277.             i% = 0
  278.             DO
  279.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  280.                 k% = k% - 1
  281.                 IF k% = 0 THEN EXIT DO
  282.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  283.                 k% = k% - 1
  284.                 i% = i% + 1
  285.             LOOP UNTIL k% = 0
  286.     END SELECT
  287. '-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  288. SUB grafici (ore!, oreM!, QM!)
  289.     'ore!: ore corrispondenti al massimo maggiore.
  290.     'oreM!: ore corrispondenti alla portata massima.
  291.     'QM!: portata massima.
  292.  
  293.     CONST R& = _RGB32(255, 0, 0)
  294.     CONST G& = _RGB32(0, 255, 0)
  295.     CONST B& = _RGB32(0, 0, 255)
  296.     CONST bianco& = _RGB32(255, 255, 255)
  297.     CONST giallo& = _RGB32(255, 255, 0)
  298.     CONST grigio& = _RGB32(127, 127, 127)
  299.  
  300.     DIM L%, H% 'dimensioni del grafico.
  301.     DIM grafico&, graficoNERO&, graficoCOPIA&
  302.     DIM colore&
  303.  
  304.     DIM dx%, dy% 'origine degli assi dentro SCREEN.
  305.     DIM dx!, dy! 'posizione dell'origine degli assi dentro WINDOW.
  306.     DIM taccaX%, taccaY%
  307.     DIM portata!(2)
  308.     DIM soglia!
  309.     REDIM x%(1), y%(1) 'conversione nelle coordinate di SCREEN delle coordinate dentro WINDOW corrispondenti a determinati valori.
  310.  
  311.     H% = _DESKTOPHEIGHT * 2 / 3 ' imposta l'altezza dello SCREEN pari ai 2/3 dello schermo visualizzabile, cosi' che su ogni PC sia visualizzabile.
  312.     L% = H% * 1.62 'imposta la larghezza dello SCREEN in modo che L%xH% sia un rettangolo aureo.
  313.     dx% = 39
  314.     dy% = H% - 1 - dx%
  315.     taccaX% = ore! \ 5 ': PRINT taccaX%: SLEEP
  316.     taccaY% = QM! \ 5
  317.     grafico& = _NEWIMAGE(L%, H%, 32)
  318.     graficoNERO& = _NEWIMAGE(L%, H%, 32) 'crea un'immagine della stessa dimensione di grafico& che sarà colorata di nero.
  319.  
  320.     _DEST graficoNERO&
  321.     CLS ' colora di nero l'immagine graficoNERO&.
  322.     _DEST grafico&
  323.     LINE (0, 0)-(L% - 1, H% - 1), R, B
  324.     WINDOW (0, 0)-(ore! * 1.15, QM! * 1.15) 'scala ascisse e ordinate in base alle ore e alla portata, estendendole del 15%.
  325.     dx! = PMAP(dx%, 2)
  326.     dy! = PMAP(dy%, 3)
  327.     LINE (dx!, QM! * 1.1)-(dx!, dy!): LINE -(ore! * 1.1, dy!), bianco& 'disegna gli assi in modo che si estendano del 10% oltre valori massimi, ma senza arrivare alla massima estensione delle coordinate impostate da WINDOW: cosi' si ha che gli assi non toccano la cornice rossa e i valori massimi che non arrivano al limite degli assi.
  328.     PSET (dx!, QM! * 1.1!), bianco&: DRAW "F20": PSET (dx!, QM! * 1.1), bianco&: DRAW "G20"
  329.     PSET (ore! * 1.1, dy!), bianco&: DRAW "G20": PSET (ore! * 1.1, dy!), bianco&: DRAW "H20"
  330.     _PRINTSTRING (dx%, PMAP(QM! * 1.1, 1) - dx% \ 2), "mc/s"
  331.     _PRINTSTRING (PMAP(ore! * 1.1, 0), dy%), "ore"
  332.     _PRINTSTRING (dx% \ 4, dy% - 7), "0"
  333.     i% = 1
  334.     WHILE i% * taccaX% <= ore!
  335.         LINE (dx! + i% * taccaX%, PMAP(dy% + 5, 3))-(dx! + i% * taccaX%, PMAP(dy% - 5, 3))
  336.         x%(1) = PMAP(dx! + i% * taccaX%, 0)
  337.         _PRINTSTRING (x%(1) - 4 * LEN(_TRIM$(STR$(i% * taccaX%))), H% - 1 - dx% / 1.5), _TRIM$(STR$(i% * taccaX%))
  338.         i% = i% + 1
  339.     WEND
  340.     i% = 1
  341.     WHILE i% * taccaY% <= QM!
  342.         LINE (PMAP(dx% - 5, 2), dy! + i% * taccaY%)-(PMAP(dx% + 5, 2), dy! + i% * taccaY%)
  343.         y%(1) = PMAP(dy! + i% * taccaY%, 1)
  344.         _PRINTSTRING (dx% \ 4, y%(1) - 7), _TRIM$(STR$(i% * taccaY%))
  345.         i% = i% + 1
  346.     WEND
  347.     FOR z% = 1 TO 24
  348.         SELECT CASE z% MOD 3
  349.             CASE IS = 1
  350.                 colore& = R&
  351.             CASE IS = 2
  352.                 colore& = G&
  353.             CASE IS = 0
  354.                 colore& = B&
  355.         END SELECT
  356.         CIRCLE (dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), PMAP(3, 2), R&
  357.         PAINT (dx! + massimi1(visualizzaieto%, z%, 1).ore + PMAP(0.5, 2), dy! + massimi1(visualizzaieto%, z%, 1).portata + PMAP(0.5, 2)), R&
  358.         FOR i% = 1 TO 50
  359.             '            _LIMIT limit
  360.             IF i% = 1 THEN
  361.                 LINE (dx!, dy!)-(dx! + idrogramma(visualizzaieto%, z%, i%, 1).ore, dy! + idrogramma(visualizzaieto%, z%, i%, 1).portata), colore&
  362.             ELSE
  363.                 LINE (dx! + idrogramma(visualizzaieto%, z%, i% - 1, 1).ore, dy! + idrogramma(visualizzaieto%, z%, i% - 1, 1).portata)-(dx! + idrogramma(visualizzaieto%, z%, i%, 1).ore, dy! + idrogramma(visualizzaieto%, z%, i%, 1).portata), colore&
  364.             END IF
  365.             '            _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  366.         NEXT i%
  367.         IF z% = 1 THEN
  368.             LINE (dx!, dy!)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), giallo&
  369.         ELSE
  370.             LINE (dx! + massimi1(visualizzaieto%, z% - 1, 1).ore, dy! + massimi1(visualizzaieto%, z% - 1, 1).portata)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), giallo&
  371.         END IF
  372.     NEXT z%
  373.     PSET (dx!, dy!), giallo&
  374.     LINE (dx!, dy! + QM!)-(dx! + oreM!, dy! + QM!), R&, , 65520
  375.     LINE -(dx! + oreM!, dy!), R&, , 65520
  376.     x%(1) = PMAP(dx! + oreM!, 0)
  377.     y%(1) = PMAP(dy! + QM!, 1)
  378.     _PRINTSTRING (x%(1) + 10, y%(1) - dx%), "(" + _TRIM$(STR$(oreM!)) + ","
  379.     _PRINTSTRING (x%(1) + 10, y%(1) - dx% + 16), _TRIM$(STR$(QM!)) + ")"
  380.     _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  381.     graficoCOPIA& = _COPYIMAGE(grafico&) 'crea una copia di grafico& prima che venga effettuato il tratteggio grigio: INSERIRE POI NUOVA RICHIESTA.
  382.  
  383.     '---------------------------------------------------------------------------------------------------------------
  384.     _DEST schermo&
  385.     VIEW PRINT 1 TO 10
  386.     SELECT CASE visualizzaieto%
  387.         CASE IS = 1
  388.             ' INPUT "Inserire percentuale soglia per portata progetto (numero intero senza simbolo %: ", soglia!
  389.             soglia! = 0.1 'soglia! / 100
  390.             grafico& = _COPYIMAGE(graficoCOPIA&) ' grafico& torna ad ed essere senza il tratteggio grigio.
  391.             _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), graficoNERO&, schermo& 'incollando grafico& (senza il tratteggio) su schermo&, si vedrebbe comunque il tratteggio in quanto la precedente versione di grafico& (che era con il tratteggio), era stata incollata su schermo&. Quindi prima incollo l'immagine graficoNERO& su schermo&.
  392.             _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo& 'copia grafico& (senza tratteggio) su schermo&, che era stato ripulito alla linea precedente.
  393.             _DEST grafico&
  394.             _SOURCE grafico&
  395.             i% = 0
  396.             ore2! = 0
  397.  
  398.             y%(1) = PMAP(dy!, 1)
  399.             DO
  400.                 i% = i% + 1
  401.                 ore2! = ore2! + 1
  402.                 REDIM _PRESERVE y%(i%)
  403.                 DO
  404.                     IF POINT(dx! + ore2!, PMAP(y%(i%), 3)) = giallo& THEN EXIT DO
  405.                     y%(i%) = y%(i%) - 1
  406.                 LOOP
  407.                 IF i% > 1 THEN
  408.                     IF PMAP(y%(i%), 3) - dy! < (1 + soglia!) * (PMAP(y%(i% - 1), 3) - dy!) THEN EXIT DO
  409.                 END IF
  410.             LOOP
  411.             ore2! = ore2! - 1
  412.             REDIM _PRESERVE y%(1 TO UBOUND(y%) - 1)
  413.             portata!(1) = PMAP(y%(UBOUND(y%)), 3) - dy!
  414.             _DEST schermo&
  415.             PRINT "Portata progetto:"; portata!(1); "mc/s, all'ora n."; ore2!
  416.         CASE IS = 2
  417.             PRINT "La portata di progetto e' quella visualizzata."
  418.     END SELECT
  419.     SLEEP
  420.     SYSTEM
  421.     '--------------------------------------------------------------------------------------------------------------------------------------------------
  422.  
  423.     DO
  424.         '  CLS 2
  425.         PRINT "Digitare le ore e i minuti (<= "; _TRIM$(STR$(INT(ore!))); " ore e "; _TRIM$(STR$(INT((ore! - INT(ore!)) * 60))); " minuti) di cui si vuole conoscere la portata di picco."
  426.         INPUT "Ore: ", ore2!
  427.         INPUT "Minuti: ", minuti%
  428.         ore2! = ore2! + minuti% / 60
  429.     LOOP WHILE ore2! > ore!
  430.     _DEST grafico&
  431.     _SOURCE grafico&
  432.     y%(1) = PMAP(dy!, 1)
  433.     i% = 2
  434.     DO
  435.         REDIM _PRESERVE y%(i%)
  436.         y%(i%) = y%(i% - 1) - 1
  437.         IF POINT(dx! + ore2!, PMAP(y%(i% - 1), 3)) = giallo& THEN EXIT DO
  438.         i% = i% + 1
  439.     LOOP
  440.     REDIM _PRESERVE y%(1 TO UBOUND(y%) - 1)
  441.     portata!(2) = PMAP(y%(UBOUND(y%)), 3) - dy!
  442.     FOR i% = 1 TO UBOUND(y%)
  443.         LINE (dx! + ore2!, dy!)-(dx! + ore2!, PMAP(y%(i%), 3)), grigio&, , 65280
  444.         _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  445.     NEXT i%
  446.     x%(1) = PMAP(dx! + ore2!, 0)
  447.     i% = 2
  448.     DO
  449.         REDIM _PRESERVE x%(i%)
  450.         x%(i%) = x%(i% - 1) - 1
  451.         IF POINT(PMAP(x%(i% - 1), 2), PMAP(y%(UBOUND(y%)), 3)) = bianco& THEN EXIT DO
  452.         i% = i% + 1
  453.     LOOP
  454.     REDIM _PRESERVE x%(1 TO UBOUND(x%) - 1)
  455.     FOR i% = 1 TO UBOUND(x%)
  456.         LINE (dx! + ore2!, PMAP(y%(UBOUND(y%)), 3))-(PMAP(x%(i%), 2), PMAP(y%(UBOUND(y%)), 3)), grigio&, , 65280
  457.         _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  458.     NEXT i%
  459.     _DEST schermo&
  460.     PRINT "Portata:"; portata!(2); "mc/s"
  461.     _FREEIMAGE grafico&
  462.     _FREEIMAGE graficoNERO&
  463.     _FREEIMAGE graficoCOPIA&
  464. '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  465. SUB risultati ()
  466.     FOR z% = 1 TO 24
  467.         CLS
  468.         PRINT "z%="; z%
  469.         PRINT "dt="; dt!(visualizzaieto%, z%); ";"; dt!(visualizzaieto%, z%) * 60
  470.         PRINT "visualizzaieto%="; visualizzaieto%
  471.         PRINT "m%="; m%(visualizzaieto%, z%)
  472.         PRINT "N="; coefficienti(z%).d / tc!
  473.         PRINT "n="; coefficienti(z%).tSUta
  474.         FOR i% = 1 TO 50
  475.             '  _LIMIT limit
  476.     PRINT _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).m)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).mdt)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tminuti)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).h1)),_
  477.      _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i1)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i2)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).DH)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).H2)),_
  478.       _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).he)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).Dhe)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUStSUta)),_
  479.        _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUSqSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tmSUta)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qmSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qm))
  480.         NEXT i%
  481.         SLEEP
  482.         CLS
  483.         FOR n% = 1 TO 50
  484.             '  _LIMIT limit
  485.             LOCATE 1,
  486.             FOR i% = 1 TO 50
  487.                 LOCATE , n% * 4 - 3
  488.                 PRINT matrice2!(visualizzaieto%, z%, i%, n%)
  489.             NEXT i%
  490.         NEXT n%
  491.         SLEEP
  492.     NEXT z%
  493.     CLS
  494.     FOR n% = 1 TO 24
  495.         ' _LIMIT limit
  496.         SELECT CASE n%
  497.             CASE IS <= 16
  498.                 FOR i% = 1 TO 50
  499.                     LOCATE i%, n% * 15 - 14
  500.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  501.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  502.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  503.  
  504.                 NEXT i%
  505.                 IF n% = 16 THEN SLEEP: CLS
  506.             CASE IS > 16
  507.                 FOR i% = 1 TO 50
  508.                     LOCATE i%, (n% - 16) * 15 - 14
  509.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  510.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  511.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  512.                 NEXT i%
  513.         END SELECT
  514.     NEXT n%
  515.     SLEEP
  516.     CLS
  517.     FOR z% = 1 TO 24
  518.         ' _LIMIT limit
  519.         PRINT massimi1(visualizzaieto%, z%, 1).ore, massimi1(visualizzaieto%, z%, 1).minuti, massimi1(visualizzaieto%, z%, 1).portata
  520.     NEXT z%
  521.     SLEEP
  522.     PRINT
  523.     PRINT massimi2(visualizzaieto%).ore; massimi2(visualizzaieto%).portata
  524.  

CODE 2.
Code: QB64: [Select]
  1.  
  2. mockus: 'dati dell'idrogramma unitario di Mockus
  3. DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  4. DATA 0.030,0.100,0.190,0.310,0.470,0.660,0.820,0.930,0.990,1.000,0.990,0.930,0.860,0.780,0.680,0.560,0.460,0.390,0.330,0.280,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.040,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0.000: ' t/tp
  5.  
  6. coefficienti:
  7. DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32: 'N volte tc!.
  8. DATA 0.1,0.1,0.1,0.2,0.3,0.2,0.3,0.3,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,1,1,1,1,1,1,1: 'discretizzazione dei coeff. di Mockus.
  9.  
  10. TYPE mockus
  11.     MOCKUStSUta AS SINGLE
  12.     MOCKUSqSUqp AS SINGLE
  13.  
  14. TYPE matrice1
  15.     m AS INTEGER '[numero naturale] conta il numero di interazioni fino al raggiungimento di "d".
  16.     mdt AS SINGLE '[ore] conta la progessione delle ore fino al raggiungimento di "d".
  17.     tminuti AS SINGLE '[minuti] trasforma mdt in minuti.
  18.     h1 AS SINGLE '[mm] valore h della curva di possibilità climatica.
  19.     i1 AS SINGLE '[mm/ora] intensità di pioggia.
  20.     i2 AS SINGLE '[mm/ora] intensità di pioggia secondo lo ietogramma Chicago o costante.
  21.     DH AS SINGLE '[mm] pioggia in ogni istante temporale dt.
  22.     H2 AS SINGLE '[mm] pioggia cumulata ad ogni istante temporale.
  23.     he AS SINGLE '[mm] piggia efficace cumulata ad ogni istante temporale.
  24.     Dhe AS SINGLE '[mm] pioggia efficace ad ogni istante temporale.
  25.     MOCKUStSUta AS SINGLE
  26.     MOCKUSqSUqp AS SINGLE
  27.     tmSUta AS SINGLE '[-].
  28.     qmSUqp AS SINGLE '[-] il valore di qm/qp corrispondente a tm/ta e' = al valore di q/qp che corrisponde a t/ta=tm/ta.
  29.     qm AS SINGLE '[mc/s].
  30.  
  31. TYPE coefficienti
  32.     d AS SINGLE
  33.     tSUta AS SINGLE
  34.  
  35. TYPE idrogramma
  36.     ore AS SINGLE
  37.     minuti AS SINGLE
  38.     portata AS SINGLE
  39.  
  40. CONST limit = 200 '50
  41.  
  42. DIM SHARED mockus(50) AS mockus
  43. DIM SHARED dt!(2, 24)
  44. DIM SHARED matrice1(2, 24, 50, 1) AS matrice1
  45. DIM SHARED coefficienti(24) AS coefficienti
  46. DIM SHARED matrice2!(2, 24, 50, 50)
  47. DIM SHARED idrogramma(2, 24, 50, 1) AS idrogramma
  48. DIM SHARED massimi1(2, 24, 1) AS idrogramma
  49. DIM SHARED massimi2(2) AS idrogramma
  50. DIM SHARED i%, n%, z%, ieto%
  51. DIM SHARED m%(2, 24)
  52. DIM SHARED S2! '[mm] contenuto idrico massimo del terreno.
  53. DIM SHARED Ia! '[mm] perdite iniziali.
  54. DIM SHARED tc! '[ore] tempo di corrivazione
  55. DIM SHARED ta! '[ore] tempo di picco.
  56. DIM SHARED qp! '[mc/s] portata al colmo dell'idrogramma unitario.
  57. DIM SHARED k! '[-] coeff. della curva di possibilità climatica tado dal sito della Regione.
  58. DIM SHARED a2! '[mm/d^n] coeff. della curva di possibilità climatica.
  59. DIM SHARED n1! '[-] coeff. della curva di possibilità climatica.
  60. DIM SHARED visualizzaieto%
  61. DIM SHARED schermo&
  62. DIM A1! '[mq] superficie bacino idrografico.
  63. DIM L! '[m] lunghezza asta principale.
  64. DIM HmaxL! '[m] punto più alto dell'astra principale.
  65. DIM HminL! '[m] punto più basso dell'asta principale.
  66. DIM s1! '[-] pendenza media del bacino non espressa in percentuale ma come 0,x.
  67. DIM CNII! '[-] tabellato.
  68. DIM CNIII '[-] discende da CNII.
  69. DIM tl! '[ore] tempo di ritardo.
  70. DIM keypress$
  71.  
  72. SCREEN schermo&
  73.  
  74. A1! = 2641902
  75. k! = 2.34
  76. a2! = 14.6653
  77. n1! = 0.45596
  78. L! = 3300
  79. HmaxL! = 1981
  80. HminL! = 1062
  81. s1! = 0.415
  82. CNII! = 70
  83.  
  84. 'INPUT A1!
  85. 'INPUT k!
  86. 'INPUT a2!
  87. 'INPUT n1!
  88. 'INPUT L!
  89. 'INPUT HmaxL!
  90. 'INPUT HminL!
  91. 'INPUT s1!
  92. 'INPUT CNII!
  93. 'INPUT d1!
  94.  
  95. CNIII! = (23 * CNII!) / (10 + 0.13 * CNII!)
  96. tl! = 0.342 * ((L! / 1000) ^ 0.8 / (100 * s1!) ^ 0.5) * (1000 / CNIII! - 9) ^ 0.7 'formula di Mockus.
  97. S2! = 25.4 * (1000 / CNIII! - 10)
  98. Ia! = 0.1 * S2! 'coeff.=0.03-0.2.
  99. tc! = tl! / 0.6
  100. ta! = tl! / 0.9
  101. qp! = 0.208 * ((A1! / 1000000) / ta!)
  102.  
  103. RESTORE mockus
  104. FOR i% = 1 TO 100
  105.     IF i% <= 50 THEN READ mockus(i%).MOCKUStSUta
  106.     IF i% > 50 THEN READ mockus(i% - 50).MOCKUSqSUqp
  107. NEXT i%
  108.  
  109. RESTORE coefficienti
  110. FOR i% = 1 TO 48
  111.     IF i% <= 24 THEN READ coefficienti(i%).d: coefficienti(i%).d = coefficienti(i%).d * tc!
  112.     IF i% > 24 THEN READ coefficienti(i% - 24).tSUta
  113. NEXT i%
  114.  
  115. PRINT "Ietogramma Chicago/costante: 1/2> "
  116. 'DO
  117. '_LIMIT 60 'limit
  118. 'keypress$ = INKEY$
  119. 'LOOP UNTIL keypress$ = "1" OR keypress$ = "2"
  120. visualizzaieto% = 1 'VAL(keypress$)
  121.  
  122. FOR ieto% = 1 TO 2
  123.     CALL creamatrici
  124. NEXT ieto%
  125.  
  126. CALL grafici(massimi1(visualizzaieto%, 24, 1).ore, massimi2(visualizzaieto%).ore, massimi2(visualizzaieto%).portata) 'valori passati per disegnare il grafico.
  127. 'CALL risultati
  128.  
  129. '-----------------------------------------matrice1---------------------------------------------------------------------------------------------------------------------------------
  130. SUB creamatrici ()
  131.     z% = 0
  132.     DO
  133.         z% = z% + 1
  134.         dt!(ieto%, z%) = coefficienti(z%).tSUta * ta!
  135.         m%(ieto%, z%) = coefficienti(z%).d / (coefficienti(z%).tSUta * ta!) 'determina il numero di passi temporali necessari ad arrivare allla durata d considerata con il paso temporale dt!.
  136.         FOR i% = 1 TO 50
  137.             matrice1(ieto%, z%, i%, 1).MOCKUStSUta = mockus(i%).MOCKUStSUta
  138.             matrice1(ieto%, z%, i%, 1).MOCKUSqSUqp = mockus(i%).MOCKUSqSUqp
  139.             matrice1(ieto%, z%, i%, 1).m = i%
  140.             matrice1(ieto%, z%, i%, 1).mdt = matrice1(ieto%, z%, i%, 1).m * dt!(ieto%, z%)
  141.             matrice1(ieto%, z%, i%, 1).tminuti = matrice1(ieto%, z%, i%, 1).mdt * 60
  142.             SELECT CASE (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 'crea il vettore dell'idrogramma unitario di Mockus con i multipli del coeff. z% considerato (0.1,0.2,0.3,0.5,1).
  143.                 CASE IS <= 5 'valore massimo di t/ta di Mockus
  144.                     matrice1(ieto%, z%, i%, 1).tmSUta = (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 '=matrice1(i%).m *  matrice1(i%).mdt / ta!
  145.                 CASE ELSE
  146.                     matrice1(ieto%, z%, i%, 1).tmSUta = 0
  147.             END SELECT
  148.         NEXT i%
  149.         FOR i% = 1 TO 50
  150.             n% = 1
  151.             DO 'crea il vettore dell'idrogramma unitario Mockus prendendo i valori corrispondenti di ai coefficienti.
  152.                 IF matrice1(ieto%, z%, i%, 1).tmSUta = matrice1(ieto%, z%, n%, 1).MOCKUStSUta THEN
  153.                     matrice1(ieto%, z%, i%, 1).qmSUqp = matrice1(ieto%, z%, n%, 1).MOCKUSqSUqp
  154.                     EXIT DO
  155.                 ELSE
  156.                     n% = n% + 1
  157.                 END IF
  158.             LOOP UNTIL n% = 50
  159.             matrice1(ieto%, z%, i%, 1).qm = matrice1(ieto%, z%, i%, 1).qmSUqp * qp!
  160.         NEXT i%
  161.         FOR i% = 1 TO m%(ieto%, z%)
  162.             matrice1(ieto%, z%, i%, 1).h1 = k! * a2! * matrice1(ieto%, z%, i%, 1).mdt ^ n1!
  163.             IF i% = 1 THEN
  164.                 matrice1(ieto%, z%, i%, 1).i1 = matrice1(ieto%, z%, i%, 1).h1 / dt!(ieto%, z%)
  165.             ELSE
  166.                 matrice1(ieto%, z%, i%, 1).i1 = (matrice1(ieto%, z%, i%, 1).h1 - matrice1(ieto%, z%, i% - 1, 1).h1) / dt!(ieto%, z%)
  167.             END IF
  168.         NEXT i%
  169.         SELECT CASE ieto%
  170.             CASE 1 'Chicago.
  171.                 CALL chicago
  172.             CASE 2 'costante
  173.                 FOR i% = 1 TO m%(ieto%, z%)
  174.                     matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z%, m%(ieto%, z%), 1).h1 / matrice1(ieto%, z%, m%(ieto%, z%), 1).mdt
  175.                 NEXT i%
  176.         END SELECT
  177.         FOR i% = 1 TO m%(ieto%, z%)
  178.             matrice1(ieto%, z%, i%, 1).DH = matrice1(ieto%, z%, i%, 1).i2 * dt!(ieto%, z%)
  179.             IF i% = 1 THEN
  180.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH
  181.             ELSE
  182.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH + matrice1(ieto%, z%, i% - 1, 1).H2
  183.             END IF
  184.             SELECT CASE matrice1(ieto%, z%, i%, 1).H2 - Ia!
  185.                 CASE IS < 0
  186.                     matrice1(ieto%, z%, i%, 1).he = 0
  187.                 CASE IS >= 0
  188.                     matrice1(ieto%, z%, i%, 1).he = (matrice1(ieto%, z%, i%, 1).H2 - Ia!) ^ 2 / (matrice1(ieto%, z%, i%, 1).H2 - Ia! + S2!)
  189.             END SELECT
  190.             IF i% = 1 THEN
  191.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he
  192.             ELSE
  193.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he - matrice1(ieto%, z%, i% - 1, 1).he
  194.             END IF
  195.         NEXT i%
  196.  
  197.         '-------------------------------matrice2-------------------------------------------------------------------------------------------------------------------------
  198.  
  199.         FOR n% = 1 TO 50 'colonna
  200.             FOR i% = n% TO 50 ' riga
  201.                 matrice2!(ieto%, z%, i%, n%) = matrice1(ieto%, z%, i% - n% + 1, 1).Dhe * matrice1(ieto%, z%, n%, 1).qm
  202.             NEXT i%
  203.         NEXT n%
  204.         '-------------------------------idrogramma------------------------------------------------------------------------------------------------------------------
  205.         FOR i% = 1 TO 50 'riga
  206.             FOR n% = 1 TO 50 'colonna
  207.                 idrogramma(ieto%, z%, i%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata + matrice2!(ieto%, z%, i%, n%)
  208.  
  209.             NEXT n%
  210.             idrogramma(ieto%, z%, i%, 1).ore = matrice1(ieto%, z%, i%, 1).mdt
  211.             idrogramma(ieto%, z%, i%, 1).minuti = matrice1(ieto%, z%, i%, 1).tminuti
  212.         NEXT i%
  213.         '-------------------------------Massimi-----------------------------------------------------
  214.         i% = 1
  215.         'massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, 1, 1).portata
  216.         DO
  217.             IF massimi1(ieto%, z%, 1).portata < idrogramma(ieto%, z%, i%, 1).portata THEN
  218.                 massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata
  219.                 massimi1(ieto%, z%, 1).ore = idrogramma(ieto%, z%, i%, 1).ore
  220.                 massimi1(ieto%, z%, 1).minuti = idrogramma(ieto%, z%, i%, 1).minuti
  221.             END IF
  222.             i% = i% + 1
  223.         LOOP UNTIL i% = 50
  224.         ' IF massimi2(ieto%).ore < massimi1(visualizzaieto%, z%, 1).ore THEN massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  225.         IF massimi2(ieto%).portata < massimi1(visualizzaieto%, z%, 1).portata THEN
  226.             massimi2(ieto%).portata = massimi1(visualizzaieto%, z%, 1).portata
  227.             massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  228.         END IF
  229.     LOOP UNTIL z% = UBOUND(coefficienti)
  230. '---------------------------------------------------------------------------------------------------------------------------------------------------
  231. 'Questa subroutine crea gli ietogrammi chicago per ogni iterazione z%.
  232. 'Ad ogni nuovo dt! pone l'ultimo valore di pioggia come ultimo, il penultimo come primo, il terzultimo come penultimo, il quartultimo come secondo e così via.
  233. 'Quando vi è un valore di z% che ha un dt! non nuovo, cerca la precedente iterazione z% con lo stesso dt! e copia i suoi valori dello ietogramma chicago in quello dell'iterazione z% in corso. I valori rimanenti sono riempiti
  234. 'procedendo come prima.
  235. 'Quindi per esempio l'iterazione z%=1 corrisponde a d=1tc con passo temporale dt!. L'iterazione z%=2 corrisponde a d=2tc con il medesimo passo temporale. Per cui lo ietogramma chicago per d=2tc e' dato dallo stesso ietogramma
  236. 'chicago che si ha per d=1tc, con l'aggiunta, ai suoi estremi, dei nuovi valori. Il meccanismo si ripete per z%=3, che corrisponde a d=3tc, con il medesimo dt!. Per z%=4, corrispondente a d=4tc, invece, il passo temporale dt!
  237. 'cambia.
  238. 'Quanto detto e' necessario per evitare piccole discrepanze che potrebbero comportare il fatto che alcuni massimi risultino localmente poco piu' bassi del precedente, anche quando il trend generale e' chiaramente di aumento dei
  239. 'massimi all'aumentare della durata della pioggia. In questo modo si fa l'ipotesi che all'aumentare della durata della pioggia, discretizzata con uno stesso passo temporale dt!, ogni ietogramma contenga a sua volta il precedente.
  240. 'In tal modo, se si condiera per esempio d=2tc, si assume che l'altezza di pioggia corrispondente a 1tc, segua lo ietogramma relativo a d=1tc, cosi' che l'altezza di pioggia rimamente sia eclusivamente dovuta ai nuovi valori.
  241. SUB chicago ()
  242.     DIM test%
  243.     DIM k%
  244.     n% = 1
  245.     DO
  246.         IF z% = 1 THEN test% = 0: EXIT DO 'permette il calcolo dello ietogramma chicago della prima iterazione. test%=0
  247.         IF dt!(ieto%, z%) = dt!(ieto%, z% - n%) THEN ' se trova un'iterazione z% precedente con lo stesso dt! di quella in corso, esegue i comandi successivi
  248.             test% = 1
  249.             k% = m%(ieto%, z%)
  250.             i% = 0
  251.             DO 'inserisce i nuovi valori dello ietogramma chicago dell'iterazione z% in corso.
  252.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  253.                 k% = k% - 1
  254.                 IF k% = m%(ieto%, z% - n%) THEN EXIT DO 'se ha completato l'inserimento dei nuovi valori, passa oltre.
  255.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  256.                 k% = k% - 1
  257.                 i% = i% + 1
  258.             LOOP UNTIL k% = m%(ieto%, z% - n%)
  259.             IF matrice1(ieto%, z%, i%, 1).i2 = 0 THEN i% = i% - 1
  260.             k% = 1
  261.             DO 'inserisce lo ietogramma chicago dell'iterazione z% precedente con lo stesso dt!, nello ietogramma dell'iterazione z% in corso.
  262.                 i% = i% + 1
  263.                 matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z% - n%, k%, 1).i2
  264.                 k% = k% + 1
  265.             LOOP UNTIL k% > m%(ieto%, z% - n%)
  266.             EXIT DO 'siccome ha completato lo ietogramma dell'iterazione z% in corso, non serve incrementare n%, quindi passa oltre. test%=1.
  267.         ELSE ' se non trova l'iterazione z% precedente con lo stesso dt! di quella in corso, incrementa n% e ripete la ricerca.
  268.             test% = 0
  269.             n% = n% + 1
  270.         END IF
  271.     LOOP UNTIL n% = z% - 1 'se non ha trovato iterazioni z% precedenti con lo stesso dt!, allora passa oltre e test%=0.
  272.     SELECT CASE test%
  273.         CASE IS = 1 'esce dalla subroutine, in quanto lo ietogramma e' definito.
  274.             EXIT SUB
  275.         CASE IS = 0 'calcola ex-novo lo ietogramma relativo all'iterazione z% in corso in quanto non vi e' un'iterazioni z% precedente con lo stesso dt! dell'iterazione z% in corso.
  276.             k% = m%(ieto%, z%)
  277.             i% = 0
  278.             DO
  279.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  280.                 k% = k% - 1
  281.                 IF k% = 0 THEN EXIT DO
  282.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  283.                 k% = k% - 1
  284.                 i% = i% + 1
  285.             LOOP UNTIL k% = 0
  286.     END SELECT
  287. '-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  288. SUB grafici (ore!, oreM!, QM!)
  289.     'ore!: ore corrispondenti al massimo maggiore.
  290.     'oreM!: ore corrispondenti alla portata massima.
  291.     'QM!: portata massima.
  292.  
  293.     CONST R& = _RGB32(255, 0, 0)
  294.     CONST G& = _RGB32(0, 255, 0)
  295.     CONST B& = _RGB32(0, 0, 255)
  296.     CONST bianco& = _RGB32(255, 255, 255)
  297.     CONST giallo& = _RGB32(255, 255, 0)
  298.     CONST grigio& = _RGB32(127, 127, 127)
  299.  
  300.     DIM L%, H% 'dimensioni del grafico.
  301.     SHARED grafico&
  302.     DIM graficoNERO&, graficoCOPIA&
  303.     DIM colore&
  304.  
  305.     DIM dx%, dy% 'origine degli assi dentro SCREEN.
  306.     DIM dx!, dy! 'posizione dell'origine degli assi dentro WINDOW.
  307.     DIM taccaX%, taccaY%
  308.     DIM portata!(2)
  309.     '  DIM soglia!
  310.     REDIM x%(1), y%(1) 'conversione nelle coordinate di SCREEN delle coordinate dentro WINDOW corrispondenti a determinati valori.
  311.  
  312.     H% = _DESKTOPHEIGHT * 2 / 3 ' imposta l'altezza dello SCREEN pari ai 2/3 dello schermo visualizzabile, cosi' che su ogni PC sia visualizzabile.
  313.     L% = H% * 1.62 'imposta la larghezza dello SCREEN in modo che L%xH% sia un rettangolo aureo.
  314.     dx% = 39
  315.     dy% = H% - 1 - dx%
  316.     taccaX% = ore! \ 5 ': PRINT taccaX%: SLEEP
  317.     taccaY% = QM! \ 5
  318.     grafico& = _NEWIMAGE(L%, H%, 32)
  319.     graficoNERO& = _NEWIMAGE(L%, H%, 32) 'crea un'immagine della stessa dimensione di grafico& che sarà colorata di nero.
  320.  
  321.     _DEST graficoNERO&
  322.     CLS ' colora di nero l'immagine graficoNERO&.
  323.     _DEST grafico&
  324.     LINE (0, 0)-(L% - 1, H% - 1), R, B
  325.     WINDOW (0, 0)-(ore! * 1.15, QM! * 1.15) 'scala ascisse e ordinate in base alle ore e alla portata, estendendole del 15%.
  326.     dx! = PMAP(dx%, 2)
  327.     dy! = PMAP(dy%, 3)
  328.     LINE (dx!, QM! * 1.1)-(dx!, dy!): LINE -(ore! * 1.1, dy!), bianco& 'disegna gli assi in modo che si estendano del 10% oltre valori massimi, ma senza arrivare alla massima estensione delle coordinate impostate da WINDOW: cosi' si ha che gli assi non toccano la cornice rossa e i valori massimi che non arrivano al limite degli assi.
  329.     PSET (dx!, QM! * 1.1!), bianco&: DRAW "F20": PSET (dx!, QM! * 1.1), bianco&: DRAW "G20"
  330.     PSET (ore! * 1.1, dy!), bianco&: DRAW "G20": PSET (ore! * 1.1, dy!), bianco&: DRAW "H20"
  331.     _PRINTSTRING (dx%, PMAP(QM! * 1.1, 1) - dx% \ 2), "mc/s"
  332.     _PRINTSTRING (PMAP(ore! * 1.1, 0), dy%), "ore"
  333.     _PRINTSTRING (dx% \ 4, dy% - 7), "0"
  334.     i% = 1
  335.     WHILE i% * taccaX% <= ore!
  336.         LINE (dx! + i% * taccaX%, PMAP(dy% + 5, 3))-(dx! + i% * taccaX%, PMAP(dy% - 5, 3))
  337.         x%(1) = PMAP(dx! + i% * taccaX%, 0)
  338.         _PRINTSTRING (x%(1) - 4 * LEN(_TRIM$(STR$(i% * taccaX%))), H% - 1 - dx% / 1.5), _TRIM$(STR$(i% * taccaX%))
  339.         i% = i% + 1
  340.     WEND
  341.     i% = 1
  342.     WHILE i% * taccaY% <= QM!
  343.         LINE (PMAP(dx% - 5, 2), dy! + i% * taccaY%)-(PMAP(dx% + 5, 2), dy! + i% * taccaY%)
  344.         y%(1) = PMAP(dy! + i% * taccaY%, 1)
  345.         _PRINTSTRING (dx% \ 4, y%(1) - 7), _TRIM$(STR$(i% * taccaY%))
  346.         i% = i% + 1
  347.     WEND
  348.     FOR z% = 1 TO 24
  349.         SELECT CASE z% MOD 3
  350.             CASE IS = 1
  351.                 colore& = R&
  352.             CASE IS = 2
  353.                 colore& = G&
  354.             CASE IS = 0
  355.                 colore& = B&
  356.         END SELECT
  357.         CIRCLE (dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), PMAP(3, 2), R&
  358.         PAINT (dx! + massimi1(visualizzaieto%, z%, 1).ore + PMAP(0.5, 2), dy! + massimi1(visualizzaieto%, z%, 1).portata + PMAP(0.5, 2)), R&
  359.         FOR i% = 1 TO 50
  360.             '            _LIMIT limit
  361.             IF i% = 1 THEN
  362.                 LINE (dx!, dy!)-(dx! + idrogramma(visualizzaieto%, z%, i%, 1).ore, dy! + idrogramma(visualizzaieto%, z%, i%, 1).portata), colore&
  363.             ELSE
  364.                 LINE (dx! + idrogramma(visualizzaieto%, z%, i% - 1, 1).ore, dy! + idrogramma(visualizzaieto%, z%, i% - 1, 1).portata)-(dx! + idrogramma(visualizzaieto%, z%, i%, 1).ore, dy! + idrogramma(visualizzaieto%, z%, i%, 1).portata), colore&
  365.             END IF
  366.             '            _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  367.         NEXT i%
  368.         IF z% = 1 THEN
  369.             LINE (dx!, dy!)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), giallo&
  370.         ELSE
  371.             LINE (dx! + massimi1(visualizzaieto%, z% - 1, 1).ore, dy! + massimi1(visualizzaieto%, z% - 1, 1).portata)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), giallo&
  372.         END IF
  373.     NEXT z%
  374.     PSET (dx!, dy!), giallo&
  375.     LINE (dx!, dy! + QM!)-(dx! + oreM!, dy! + QM!), R&, , 65520
  376.     LINE -(dx! + oreM!, dy!), R&, , 65520
  377.     x%(1) = PMAP(dx! + oreM!, 0)
  378.     y%(1) = PMAP(dy! + QM!, 1)
  379.     _PRINTSTRING (x%(1) + 10, y%(1) - dx%), "(" + _TRIM$(STR$(oreM!)) + ","
  380.     _PRINTSTRING (x%(1) + 10, y%(1) - dx% + 16), _TRIM$(STR$(QM!)) + ")"
  381.     _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  382.     graficoCOPIA& = _COPYIMAGE(grafico&) 'crea una copia di grafico& prima che venga effettuato il tratteggio grigio: INSERIRE POI NUOVA RICHIESTA.
  383.     CALL idrogrammaprogetto(L%, H%, grafico&, graficoCOPIA&, graficoNERO&, portata!(), x%(), y%(), dx!, dy!, giallo&)
  384.     SLEEP
  385.  
  386.     SYSTEM
  387.  
  388.     DO
  389.         '  CLS 2
  390.         PRINT "Digitare le ore e i minuti (<= "; _TRIM$(STR$(INT(ore!))); " ore e "; _TRIM$(STR$(INT((ore! - INT(ore!)) * 60))); " minuti) di cui si vuole conoscere la portata di picco."
  391.         INPUT "Ore: ", ore2!
  392.         INPUT "Minuti: ", minuti%
  393.         ore2! = ore2! + minuti% / 60
  394.     LOOP WHILE ore2! > ore!
  395.     _DEST grafico&
  396.     _SOURCE grafico&
  397.     y%(1) = PMAP(dy!, 1)
  398.     i% = 2
  399.     DO
  400.         REDIM _PRESERVE y%(i%)
  401.         y%(i%) = y%(i% - 1) - 1
  402.         IF POINT(dx! + ore2!, PMAP(y%(i% - 1), 3)) = giallo& THEN EXIT DO
  403.         i% = i% + 1
  404.     LOOP
  405.     REDIM _PRESERVE y%(1 TO UBOUND(y%) - 1)
  406.     portata!(2) = PMAP(y%(UBOUND(y%)), 3) - dy!
  407.     FOR i% = 1 TO UBOUND(y%)
  408.         LINE (dx! + ore2!, dy!)-(dx! + ore2!, PMAP(y%(i%), 3)), grigio&, , 65280
  409.         _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  410.     NEXT i%
  411.     x%(1) = PMAP(dx! + ore2!, 0)
  412.     i% = 2
  413.     DO
  414.         REDIM _PRESERVE x%(i%)
  415.         x%(i%) = x%(i% - 1) - 1
  416.         IF POINT(PMAP(x%(i% - 1), 2), PMAP(y%(UBOUND(y%)), 3)) = bianco& THEN EXIT DO
  417.         i% = i% + 1
  418.     LOOP
  419.     REDIM _PRESERVE x%(1 TO UBOUND(x%) - 1)
  420.     FOR i% = 1 TO UBOUND(x%)
  421.         LINE (dx! + ore2!, PMAP(y%(UBOUND(y%)), 3))-(PMAP(x%(i%), 2), PMAP(y%(UBOUND(y%)), 3)), grigio&, , 65280
  422.         _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  423.     NEXT i%
  424.     _DEST schermo&
  425.     PRINT "Portata:"; portata!(2); "mc/s"
  426.     _FREEIMAGE grafico&
  427.     _FREEIMAGE graficoNERO&
  428.     _FREEIMAGE graficoCOPIA&
  429. '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  430. SUB idrogrammaprogetto (L%, H%, grafico&, graficoCOPIA&, graficoNERO&, portata!(), x%(), y%(), dx!, dy!, giallo&)
  431.  
  432.     DIM ore2!
  433.     DIM soglia!
  434.  
  435.     _DEST schermo&
  436.     VIEW PRINT 1 TO 10
  437.     SELECT CASE visualizzaieto%
  438.         CASE IS = 1
  439.             '   INPUT "Inserire percentuale soglia per portata progetto (numero intero senza simbolo %: ", soglia!
  440.             soglia! = 0.1
  441.             grafico& = _COPYIMAGE(graficoCOPIA&) ' grafico& torna ad ed essere senza il tratteggio grigio.
  442.             _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), graficoNERO&, schermo& 'incollando grafico& (senza il tratteggio) su schermo&, si vedrebbe comunque il tratteggio in quanto la precedente versione di grafico& (che era con il tratteggio), era stata incollata su schermo&. Quindi prima incollo l'immagine graficoNERO& su schermo&.
  443.             _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo& 'copia grafico& (senza tratteggio) su schermo&, che era stato ripulito alla linea precedente.
  444.             _DEST grafico&
  445.             _SOURCE grafico&
  446.             i% = 0
  447.             ore2! = 0
  448.             REDIM x%(1), y%(1)
  449.             y%(1) = PMAP(dy!, 1)
  450.             DO
  451.                 i% = i% + 1
  452.                 ore2! = ore2! + 1
  453.                 REDIM _PRESERVE y%(i%)
  454.                 DO
  455.                     IF POINT(dx! + ore2!, PMAP(y%(i%), 3)) = giallo& THEN EXIT DO
  456.                     y%(i%) = y%(i%) - 1
  457.                     'LINE (dx! + ore2!, PMAP(y%(i%), 3))-(dx! + ore2!, PMAP(y%(i%), 3)): SLEEP
  458.                 LOOP
  459.                 IF i% > 1 THEN
  460.                     IF PMAP(y%(i%), 3) - dy! < (1 + soglia!) * (PMAP(y%(i% - 1), 3) - dy!) THEN EXIT DO
  461.                 END IF
  462.             LOOP
  463.             ore2! = ore2! - 1
  464.             REDIM _PRESERVE y%(1 TO UBOUND(y%) - 1)
  465.             portata!(1) = PMAP(y%(UBOUND(y%)), 3) - dy!
  466.             _DEST schermo&
  467.             PRINT "Portata progetto:"; portata!(1); "mc/s, all'ora n."; ore2!
  468.         CASE IS = 2
  469.             PRINT "La portata di progetto e' quella visualizzata."
  470.     END SELECT
  471. '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  472. SUB risultati ()
  473.     FOR z% = 1 TO 24
  474.         CLS
  475.         PRINT "z%="; z%
  476.         PRINT "dt="; dt!(visualizzaieto%, z%); ";"; dt!(visualizzaieto%, z%) * 60
  477.         PRINT "visualizzaieto%="; visualizzaieto%
  478.         PRINT "m%="; m%(visualizzaieto%, z%)
  479.         PRINT "N="; coefficienti(z%).d / tc!
  480.         PRINT "n="; coefficienti(z%).tSUta
  481.         FOR i% = 1 TO 50
  482.             '  _LIMIT limit
  483.     PRINT _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).m)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).mdt)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tminuti)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).h1)),_
  484.      _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i1)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i2)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).DH)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).H2)),_
  485.       _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).he)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).Dhe)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUStSUta)),_
  486.        _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUSqSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tmSUta)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qmSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qm))
  487.         NEXT i%
  488.         SLEEP
  489.         CLS
  490.         FOR n% = 1 TO 50
  491.             '  _LIMIT limit
  492.             LOCATE 1,
  493.             FOR i% = 1 TO 50
  494.                 LOCATE , n% * 4 - 3
  495.                 PRINT matrice2!(visualizzaieto%, z%, i%, n%)
  496.             NEXT i%
  497.         NEXT n%
  498.         SLEEP
  499.     NEXT z%
  500.     CLS
  501.     FOR n% = 1 TO 24
  502.         ' _LIMIT limit
  503.         SELECT CASE n%
  504.             CASE IS <= 16
  505.                 FOR i% = 1 TO 50
  506.                     LOCATE i%, n% * 15 - 14
  507.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  508.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  509.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  510.  
  511.                 NEXT i%
  512.                 IF n% = 16 THEN SLEEP: CLS
  513.             CASE IS > 16
  514.                 FOR i% = 1 TO 50
  515.                     LOCATE i%, (n% - 16) * 15 - 14
  516.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  517.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  518.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  519.                 NEXT i%
  520.         END SELECT
  521.     NEXT n%
  522.     SLEEP
  523.     CLS
  524.     FOR z% = 1 TO 24
  525.         ' _LIMIT limit
  526.         PRINT massimi1(visualizzaieto%, z%, 1).ore, massimi1(visualizzaieto%, z%, 1).minuti, massimi1(visualizzaieto%, z%, 1).portata
  527.     NEXT z%
  528.     SLEEP
  529.     PRINT
  530.     PRINT massimi2(visualizzaieto%).ore; massimi2(visualizzaieto%).portata
  531.  

Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 25, 2021, 11:19:03 am
@bartok

Well I understand your motivation to take working code and refactor it to make it better in some way. Last night I overhauled SB1 to do customized splits and only if the program line needed it, instead of one split for all whether it needs it or not and whether or not the right delimiter :p So clearly I am cutting wasted time, and redundant codes where I have to re-split with correct delimiter.

So what is reason to make a separate sub, load it up with a ton of parameters and do something on the side?
My guess is you are missing one or more values passed to the added sub routine.

Do you know, you can put GOSUBs inside your SUB's?
This would save you all the trouble of loading up another sub with a bunch of values to work out some calculation or do some task.

Doing that, using a GOSUB instead of full-fledged SUB,  all the variables in the SUB are available free of charge in the GOSUB routine and no worries if you forgot something or are in the wrong _Source or _Dest handle. Put the GOSUB at the bottom of your SUB and make sure you exit sub before reaching GOSUB in exec flow.


Code: QB64: [Select]
  1. SUB idrogrammaprogetto (L%, H%, grafico&, graficoCOPIA&, graficoNERO&, portata!(), x%(), y%(), dx!, dy!, giallo&)
Is it likely you will need all these parameter / arguments or most of them in other parts of your program present or future?

If no, then go with GoSUB, instead of using another SUB.

If so, then set up a Type for passing all this stuff under a single an UDT (= User Defined Type) it will make passing this stuff off a breeze (maybe not but this > ) or better Shared the Typed variable or array.

You have the problem narrowed down to 4 or so lines in a Do Loop, something is not changing correctly in there. I would suspect a _dest or _source handle missing, but I don't want to dive into detail someone else code and find which variable was mis-typed or missing. :p  This reminds me of Turings problem, "How to get a program to realize it's in an infinite loop and Halt", I suspect it's possible with a map of program and table of variables and a ton of analysis, specially for particular programs if not for "In General" which is what Mathematicians are always after.  I recently saw Internet thing where some lady solved Conway knot that had all the mathematicians tied up, she said, (paraphased) "But it was just one knot" with a tone of what's the Big Deal?  But I digress...

I would set up my own watch by printing the variables in question at the bottom of the loop and then put an input line at bottom with prompt "Ready... press enter"; ready$ 

I label such private watches with ' Debug =============================================
so I know what to remove when problem is discovered.

Sometimes I have to watch a number of places I REDIM SHARED Debug
and turn it on or off at top of main code section
Debug = 0 or -1

Then I start private watches with lines:
If Debug then
   REDIM ready$  ' I just thought of this, private dim of ready$ variable
   print the watch stuff
   input "ready? ... press enter'; ready$
   If ready$ = enoughAlready$ then Debug = 0 ' I just thought of this! turn off debug when you've had enough
end if

You could even output this stuff in a console window so it's out of the way of your program screen, yes you can run two windows in Qb64! But I never tried.
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bartok on February 25, 2021, 01:26:30 pm
bplus,
Quote
So what is reason to make a separate sub, load it up with a ton of parameters and do something on the side?

it is a philosophical question. In general, if I have an idea to do something, I enter a DO cicle until I have found the way to do it. Regardless of the original reason of the idea, the fact is that if I don't solve the problem, I go in loop, and I am too annoyed to go ahead.


Quote
Is it likely you will need all these parameter / arguments or most of them in other parts of your program present or future?

No, I don't. This sub have to be used only at this point of the code. However, the idea to do a separate sub is intended to make a more readable code. In fact, at the moment, I am just building a kind of structure of the program I have in mind, that goes from the start to the end, doing all have to be done, without possibility to navigate into the program or exit it. But finally, I want to implement this capacity. So, for example, at the moment the program flow passes this subroutine only one time and goes ahead, but in the future I want to make the possibility to repeate the procedure if the user want it. So, finally, there will be probably a DO-LOOP cicle or a IF condition. Well, with the simply CALL of the subroutine, the DO-LOOP cicle will be easy to understand what is intended to do. Without the subroutine, the DO-LOOP cicle will be very long and plenty of stuff an less easy to read. So, if I write a part of code that does something very definite, I want that it is a subroutine, so that, at the end, the code will be, as far as possible, a sequence of explicit commands that are evident what are intended to do, without the necessity to read and understand the pure code. I know that the same result can be reached with REM statements, but if the code is self-explaining, is better.

Quote
I would set up my own watch by printing the variables in question at the bottom of the loop and then put an input line at bottom with prompt "Ready... press enter"; ready$ 

I do something similar: I use PRINT (some variable) and SLEEP. I also use LINE or PSET. For example, I know that the problem is not a matter of coordinates passing from the sub-routine to the sub-subroutine, because in the LOOP cicle I have put the command to draw a pixel as the count goes ahead, interspersed by a SLEEP. And in fact the pixels were drawn exactly. Finally, the line of all these pixels met a yellow pixel of the yellow line. Using this method debugging CODE 1 (the one working), when the line met the yellow pixel, nothing happened, because PSET, couloring each pixel at time, never met a yellow pixel. Removing PSET, CODE 1 worked, CODE 2 not, but in this way was clear that the problem wasn't the coordinates.

Quote
Do you know, you can put GOSUBs inside your SUB's?

no, I didn't!

Quote
If no, then go with GoSUB, instead of using another SUB.

Your advice to use GOSUB, is one more time very usefull, because, in this way, I have solved the problem! And the solution is better of the original idea to use a full-fledged SUB for the reasons you said. Thanks you!
Title: Re: Problem to print values on the axis inside and outside WINDOW.
Post by: bplus on February 25, 2021, 10:39:09 pm
@bartok  glad to see :)