Burgers equation solution rapidly increasing - fortran

I got a problem implementing a simple subroutine for solving the Burgers
equation:
Boundary condition x=[0,5] t=[0,1]
The problem is that the code well predicts all the values of the resulting vector in function f(x,U(time,x)) if I change the time step, the size of domain and so on... the last 4 points of the vector (a columns of a matrix U) are out of range of the normal solution (generally rapidly increasing)
Here is the code (module subroutines and simple main):
MODULE PARAM
IMPLICIT NONE
INTEGER, PARAMETER :: SP = KIND(1.0)
INTEGER, PARAMETER :: DP = KIND(1.D0)
END MODULE
!-----------------------------------------------------------------------
MODULE BURGER_2
USE PARAM
IMPLICIT NONE
REAL(DP), PARAMETER :: x0=0. , xF= 5.
REAL(DP), PARAMETER :: t0=0. , tF= 1.0
REAL(DP), PARAMETER :: dx=0.01, dt=0.1
INTEGER , PARAMETER :: N= CEILING((xF-x0)/dx)
INTEGER , PARAMETER :: M= CEILING((tF-t0)/dt)
REAL(DP), PARAMETER :: nu = 1D-4
REAL(DP), PARAMETER :: pi=3.14159265358979323846
CONTAINS
!-----------------------------------------------------------------------
SUBROUTINE BURGER_EXPLICIT (x,t,u)
USE PARAM
REAL(DP), DIMENSION(N+1) :: x
REAL(DP), DIMENSION(M+1) :: t
REAL(DP), DIMENSION(N+1,M+1) :: U
REAL(DP) :: r,k
INTEGER :: i,j,stat
x(1:N+1) = (/ ( x0+dx*(i-1) , i=1,N+1 ) /)
t(1:M+1) = (/ (t0+ dt*(j-1) , j=1,M+1 ) /)
U(1:N+1,1:M+1) = RESHAPE((/(((sin(2*pi*(i-1)/N)), i=1,N+1), j=1,M+1)/),(/N+1,M+1/))
U(1,:) = x0
U(N+1,:) = xF
U(:,1) = t0
U(:,M+1) = tF
r = nu*DT/DX**2
k = DT/(2*DX)
DO J=2,M
DO I=2,N
U(i,j+1) = r*u(i+1,j)+(1-2*r)*u(i,j)+r*u(i-1,j) - k*u(i,j)*(u(i+1,j)-u(i-1,j))
END DO
END DO
!DO j=1,M+1
OPEN(10,file='bur1.dat',STATUS='UNKNOWN',IOSTAT=stat)
IF (STAT .NE. 0) THEN
WRITE(6,FMT='(A)')'Error opening File ''bur1.dat'' (EXIT1)'
STOP
ELSE
WRITE(10,FMT='(2F20.5)') (x(i), u(i,9), i=1,N) !((u(i,j) , i=1,N+1), J=1,M+1)
!WRITE(10,*)
!WRITE(10,FMT='(2F20.5)') (x(i), u(i,2), i=1,N) !((u(i,j) , i=1,N+1), J=1,M+1)
WRITE(6,'(50("-"))')
!END DO
END IF
RETURN
END SUBROUTINE
!-----------------------------------------------------------------------
!-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
END MODULE
the main program is :
PROGRAM main
USE BURGER_2
IMPLICIT NONE
REAL(DP) , DIMENSION (N+1) :: xx
REAL(DP) , DIMENSION (M+1) :: tt
REAL(DP) , DIMENSION (n+1,M+1) :: UU
CALL burger_EXPLICIT(xx,tt,UU)
STOP
END
I want obtain a matrix (write into a file) for plotting a 3d surface with gnuplot .. but I don't know the right way for write these data
here for exemple the vector that the program wrote for u(i,9) i=1,N+1
0.00000 0.00000
0.01000 0.00637
0.02000 0.01275
0.03000 0.01912
0.04000 0.02550
0.05000 0.03187
0.06000 0.03825
0.07000 0.04462
0.08000 0.05099
0.09000 0.05736
0.10000 0.06374
0.11000 0.07011
0.12000 0.07648
0.13000 0.08285
0.14000 0.08921
0.15000 0.09558
0.16000 0.10195
0.17000 0.10831
0.18000 0.11467
0.19000 0.12104
0.20000 0.12740
0.21000 0.13375
0.22000 0.14011
0.23000 0.14647
0.24000 0.15282
0.25000 0.15917
0.26000 0.16552
0.27000 0.17187
0.28000 0.17822
0.29000 0.18456
0.30000 0.19090
0.31000 0.19724
0.32000 0.20358
0.33000 0.20991
0.34000 0.21624
0.35000 0.22257
0.36000 0.22890
0.37000 0.23522
0.38000 0.24154
0.39000 0.24786
0.40000 0.25417
0.41000 0.26049
0.42000 0.26679
0.43000 0.27310
0.44000 0.27940
0.45000 0.28570
0.46000 0.29199
0.47000 0.29828
0.48000 0.30457
0.49000 0.31085
0.50000 0.31713
0.51000 0.32340
0.52000 0.32967
0.53000 0.33594
0.54000 0.34220
0.55000 0.34846
0.56000 0.35471
0.57000 0.36095
0.58000 0.36720
0.59000 0.37344
0.60000 0.37967
0.61000 0.38590
0.62000 0.39212
0.63000 0.39833
0.64000 0.40455
0.65000 0.41075
0.66000 0.41695
0.67000 0.42315
0.68000 0.42934
0.69000 0.43552
0.70000 0.44169
0.71000 0.44786
0.72000 0.45403
0.73000 0.46018
0.74000 0.46634
0.75000 0.47248
0.76000 0.47862
0.77000 0.48475
0.78000 0.49087
0.79000 0.49698
0.80000 0.50309
0.81000 0.50919
0.82000 0.51528
0.83000 0.52137
0.84000 0.52745
0.85000 0.53351
0.86000 0.53957
0.87000 0.54563
0.88000 0.55167
0.89000 0.55770
0.90000 0.56373
0.91000 0.56975
0.92000 0.57575
0.93000 0.58175
0.94000 0.58774
0.95000 0.59372
0.96000 0.59969
0.97000 0.60565
0.98000 0.61159
0.99000 0.61753
1.00000 0.62346
1.01000 0.62937
1.02000 0.63528
1.03000 0.64117
1.04000 0.64706
1.05000 0.65293
1.06000 0.65878
1.07000 0.66463
1.08000 0.67047
1.09000 0.67629
1.10000 0.68210
1.11000 0.68789
1.12000 0.69367
1.13000 0.69944
1.14000 0.70520
1.15000 0.71094
1.16000 0.71667
1.17000 0.72238
1.18000 0.72808
1.19000 0.73376
1.20000 0.73943
1.21000 0.74508
1.22000 0.75072
1.23000 0.75634
1.24000 0.76194
1.25000 0.76752
1.26000 0.77309
1.27000 0.77864
1.28000 0.78418
1.29000 0.78969
1.30000 0.79519
1.31000 0.80067
1.32000 0.80613
1.33000 0.81157
1.34000 0.81699
1.35000 0.82238
1.36000 0.82776
1.37000 0.83312
1.38000 0.83845
1.39000 0.84377
1.40000 0.84906
1.41000 0.85432
1.42000 0.85957
1.43000 0.86479
1.44000 0.86998
1.45000 0.87515
1.46000 0.88030
1.47000 0.88542
1.48000 0.89051
1.49000 0.89558
1.50000 0.90062
1.51000 0.90563
1.52000 0.91061
1.53000 0.91556
1.54000 0.92048
1.55000 0.92537
1.56000 0.93023
1.57000 0.93506
1.58000 0.93986
1.59000 0.94462
1.60000 0.94935
1.61000 0.95404
1.62000 0.95870
1.63000 0.96332
1.64000 0.96790
1.65000 0.97244
1.66000 0.97695
1.67000 0.98141
1.68000 0.98583
1.69000 0.99020
1.70000 0.99453
1.71000 0.99882
1.72000 1.00305
1.73000 1.00724
1.74000 1.01137
1.75000 1.01545
1.76000 1.01948
1.77000 1.02344
1.78000 1.02734
1.79000 1.03118
1.80000 1.03495
1.81000 1.03864
1.82000 1.04226
1.83000 1.04580
1.84000 1.04925
1.85000 1.05261
1.86000 1.05588
1.87000 1.05903
1.88000 1.06208
1.89000 1.06501
1.90000 1.06780
1.91000 1.07046
1.92000 1.07296
1.93000 1.07531
1.94000 1.07747
1.95000 1.07945
1.96000 1.08122
1.97000 1.08276
1.98000 1.08407
1.99000 1.08511
2.00000 1.08586
2.01000 1.08631
2.02000 1.08643
2.03000 1.08618
2.04000 1.08554
2.05000 1.08448
2.06000 1.08297
2.07000 1.08096
2.08000 1.07843
2.09000 1.07532
2.10000 1.07161
2.11000 1.06725
2.12000 1.06219
2.13000 1.05639
2.14000 1.04980
2.15000 1.04237
2.16000 1.03405
2.17000 1.02479
2.18000 1.01454
2.19000 1.00325
2.20000 0.99087
2.21000 0.97735
2.22000 0.96264
2.23000 0.94670
2.24000 0.92948
2.25000 0.91095
2.26000 0.89106
2.27000 0.86979
2.28000 0.84710
2.29000 0.82298
2.30000 0.79740
2.31000 0.77037
2.32000 0.74187
2.33000 0.71191
2.34000 0.68050
2.35000 0.64766
2.36000 0.61343
2.37000 0.57783
2.38000 0.54092
2.39000 0.50275
2.40000 0.46338
2.41000 0.42289
2.42000 0.38134
2.43000 0.33884
2.44000 0.29548
2.45000 0.25135
2.46000 0.20656
2.47000 0.16123
2.48000 0.11548
2.49000 0.06941
2.50000 0.02316
2.51000 -0.02316
2.52000 -0.06941
2.53000 -0.11548
2.54000 -0.16123
2.55000 -0.20656
2.56000 -0.25135
2.57000 -0.29548
2.58000 -0.33884
2.59000 -0.38134
2.60000 -0.42289
2.61000 -0.46338
2.62000 -0.50275
2.63000 -0.54092
2.64000 -0.57784
2.65000 -0.61343
2.66000 -0.64767
2.67000 -0.68050
2.68000 -0.71191
2.69000 -0.74187
2.70000 -0.77037
2.71000 -0.79740
2.72000 -0.82298
2.73000 -0.84710
2.74000 -0.86979
2.75000 -0.89106
2.76000 -0.91095
2.77000 -0.92948
2.78000 -0.94670
2.79000 -0.96264
2.80000 -0.97735
2.81000 -0.99087
2.82000 -1.00325
2.83000 -1.01454
2.84000 -1.02479
2.85000 -1.03405
2.86000 -1.04237
2.87000 -1.04980
2.88000 -1.05639
2.89000 -1.06219
2.90000 -1.06725
2.91000 -1.07161
2.92000 -1.07532
2.93000 -1.07843
2.94000 -1.08096
2.95000 -1.08297
2.96000 -1.08448
2.97000 -1.08554
2.98000 -1.08618
2.99000 -1.08643
3.00000 -1.08631
3.01000 -1.08586
3.02000 -1.08511
3.03000 -1.08407
3.04000 -1.08276
3.05000 -1.08122
3.06000 -1.07945
3.07000 -1.07747
3.08000 -1.07531
3.09000 -1.07296
3.10000 -1.07046
3.11000 -1.06780
3.12000 -1.06501
3.13000 -1.06208
3.14000 -1.05903
3.15000 -1.05588
3.16000 -1.05261
3.17000 -1.04925
3.18000 -1.04580
3.19000 -1.04226
3.20000 -1.03864
3.21000 -1.03495
3.22000 -1.03118
3.23000 -1.02734
3.24000 -1.02344
3.25000 -1.01948
3.26000 -1.01545
3.27000 -1.01137
3.28000 -1.00724
3.29000 -1.00305
3.30000 -0.99882
3.31000 -0.99453
3.32000 -0.99020
3.33000 -0.98583
3.34000 -0.98141
3.35000 -0.97695
3.36000 -0.97244
3.37000 -0.96790
3.38000 -0.96332
3.39000 -0.95870
3.40000 -0.95404
3.41000 -0.94935
3.42000 -0.94462
3.43000 -0.93986
3.44000 -0.93506
3.45000 -0.93023
3.46000 -0.92537
3.47000 -0.92048
3.48000 -0.91556
3.49000 -0.91061
3.50000 -0.90563
3.51000 -0.90062
3.52000 -0.89558
3.53000 -0.89051
3.54000 -0.88542
3.55000 -0.88030
3.56000 -0.87515
3.57000 -0.86998
3.58000 -0.86479
3.59000 -0.85957
3.60000 -0.85432
3.61000 -0.84906
3.62000 -0.84377
3.63000 -0.83845
3.64000 -0.83312
3.65000 -0.82776
3.66000 -0.82238
3.67000 -0.81699
3.68000 -0.81157
3.69000 -0.80613
3.70000 -0.80067
3.71000 -0.79519
3.72000 -0.78969
3.73000 -0.78418
3.74000 -0.77864
3.75000 -0.77309
3.76000 -0.76752
3.77000 -0.76194
3.78000 -0.75634
3.79000 -0.75072
3.80000 -0.74508
3.81000 -0.73943
3.82000 -0.73376
3.83000 -0.72808
3.84000 -0.72238
3.85000 -0.71667
3.86000 -0.71094
3.87000 -0.70520
3.88000 -0.69944
3.89000 -0.69367
3.90000 -0.68789
3.91000 -0.68210
3.92000 -0.67629
3.93000 -0.67047
3.94000 -0.66463
3.95000 -0.65878
3.96000 -0.65293
3.97000 -0.64706
3.98000 -0.64117
3.99000 -0.63528
4.00000 -0.62937
4.01000 -0.62346
4.02000 -0.61753
4.03000 -0.61159
4.04000 -0.60565
4.05000 -0.59969
4.06000 -0.59372
4.07000 -0.58774
4.08000 -0.58175
4.09000 -0.57575
4.10000 -0.56975
4.11000 -0.56373
4.12000 -0.55770
4.13000 -0.55167
4.14000 -0.54563
4.15000 -0.53957
4.16000 -0.53351
4.17000 -0.52745
4.18000 -0.52137
4.19000 -0.51528
4.20000 -0.50919
4.21000 -0.50309
4.22000 -0.49698
4.23000 -0.49087
4.24000 -0.48475
4.25000 -0.47862
4.26000 -0.47248
4.27000 -0.46634
4.28000 -0.46018
4.29000 -0.45403
4.30000 -0.44786
4.31000 -0.44169
4.32000 -0.43552
4.33000 -0.42934
4.34000 -0.42315
4.35000 -0.41695
4.36000 -0.41075
4.37000 -0.40455
4.38000 -0.39833
4.39000 -0.39212
4.40000 -0.38590
4.41000 -0.37967
4.42000 -0.37344
4.43000 -0.36720
4.44000 -0.36095
4.45000 -0.35471
4.46000 -0.34846
4.47000 -0.34220
4.48000 -0.33594
4.49000 -0.32967
4.50000 -0.32340
4.51000 -0.31713
4.52000 -0.31085
4.53000 -0.30457
4.54000 -0.29828
4.55000 -0.29199
4.56000 -0.28570
4.57000 -0.27940
4.58000 -0.27310
4.59000 -0.26679
4.60000 -0.26049
4.61000 -0.25417
4.62000 -0.24786
4.63000 -0.24154
4.64000 -0.23522
4.65000 -0.22890
4.66000 -0.22257
4.67000 -0.21624
4.68000 -0.20991
4.69000 -0.20358
4.70000 -0.19724
4.71000 -0.19090
4.72000 -0.18456
4.73000 -0.17822
4.74000 -0.17187
4.75000 -0.16552
4.76000 -0.15917
4.77000 -0.15282
4.78000 -0.14647
4.79000 -0.14011
4.80000 -0.13375
4.81000 -0.12740
4.82000 -0.12104
4.83000 -0.11467
4.84000 -0.10831
4.85000 -0.10195
4.86000 -0.09558
4.87000 -0.08921
4.88000 -0.08285
4.89000 -0.07648
4.90000 -0.07011
4.91000 -0.06374
4.92000 -0.05736
4.93000 -0.05099
4.94000 -0.04068
4.95000 -0.21859
4.96000 -539175687.87944
4.97000********************
4.98000********************
4.99000********************
5.00000********************
5.01000 5.00000
have a look to the last 6 point

Related

Apache Flink's Iterative Stream won't loop

I'm implementing the connected components algorithm using Flink's DataStream API, since there is not yet an implementation of it using this API.
For this algorithm, I'm separating the data by tumbling windows. So, for each window, I`m trying to compute the algorithm independently.
My problem comes from the iterative character of the algorithm. I implemented the data pipeline that I wanted for the interactions (the step data pipeline), which consists on FlatMaps, 1 Join, 1 ProcessWindow and 1 Filter. However, it seems that the stream I wanted to feedback the loop is not actually being fed back to the beginning of the loop, because the algorithm does not iterate. I suspect it is not possible to do it if the original iteration datastream was joined with another stream (even though the latter was originated by a flatMap on the former).
The code that I`m using is as follows:
//neigborsList = Datastream of <Vertex, [List of neighbors], label>
IterativeStream< Tuple3<Integer, ArrayList<Integer>, Integer> > beginning_loop = neigborsList.iterate(maxTimeout);
//Emits tuples Vertices and Labels for every vertex and its neighbors
DataStream<Tuple2<Integer,Integer> > labels = beginning_loop
//Datastream of <Vertex, label> for every neigborsList.f0 and element in neigborsList.f1
.flatMap( new EmitVertexLabel() )
.keyBy(0)
.window(TumblingEventTimeWindows.of(Time.milliseconds(windowSize)))
.minBy(1)
;
DataStream<Tuple4<Integer, ArrayList<Integer>, Integer, Integer>> updatedVertex = beginning_loop
//Update vertex label with the results from the labels reduction
.join(labels)
.where("vertex")
.equalTo("vertex")
.window(TumblingEventTimeWindows.of(Time.milliseconds(windowSize)))
.apply(new JoinFunction<Tuple3<Integer,ArrayList<Integer>,Integer>, Tuple2<Integer,Integer>, Tuple4<Integer,ArrayList<Integer>,Integer,Integer>>() {
#Override
public Tuple4<Integer,ArrayList<Integer>,Integer,Integer> join(
Tuple3<Integer, ArrayList<Integer>, Integer> arg0, Tuple2<Integer, Integer> arg1)
throws Exception {
int hasConverged = 1;
if(arg1.f1.intValue() < arg0.f2.intValue() )
{
arg0.f2 = arg1.f1;
hasConverged=0;
}
return new Tuple4<>(arg0.f0,arg0.f1,arg0.f2,new Integer(hasConverged));
}
})
//Disseminates the convergence flag if a change was made in the window
.windowAll(TumblingEventTimeWindows.of(Time.milliseconds(windowSize)))
.process(new ProcessAllWindowFunction<Tuple4<Integer,ArrayList<Integer>,Integer,Integer>,Tuple4<Integer, ArrayList<Integer>, Integer, Integer>,TimeWindow >() {
#Override
public void process(
ProcessAllWindowFunction<Tuple4<Integer, ArrayList<Integer>, Integer, Integer>, Tuple4<Integer, ArrayList<Integer>, Integer, Integer>, TimeWindow>.Context ctx,
Iterable<Tuple4<Integer, ArrayList<Integer>, Integer, Integer>> values,
Collector<Tuple4<Integer, ArrayList<Integer>, Integer, Integer>> out) throws Exception {
Iterator<Tuple4<Integer, ArrayList<Integer>, Integer, Integer>> iterator = values.iterator();
Tuple4<Integer, ArrayList<Integer>, Integer, Integer> element;
int hasConverged= 1;
while(iterator.hasNext())
{
element = iterator.next();
if(element.f3.intValue()>0)
{
hasConverged=0;
break;
}
}
//Re iterate and emit the values on the correct output
iterator = values.iterator();
Integer converged = new Integer(hasConverged);
while(iterator.hasNext())
{
element = iterator.next();
element.f3 = converged;
out.collect(element);
}
}
})
;
DataStream<Tuple3<Integer, ArrayList<Integer>, Integer>> feed_back = updatedVertex
.filter(new NotConvergedFilter())
//Remove the finished convergence flag
//Transforms the Tuples4 to Tuples3 so that it becomes compatible with beginning_loop
.map(new RemoveConvergeceFlag())
;
beginning_loop.closeWith(feed_back);
//Selects the windows that have already converged
DataStream<?> convergedWindows = updatedVertex
.filter(new ConvergedFilter() );
convergedWindows.print()
.setParallelism(1)
.name("Sink to stdout");
At the end of the execution convergedWindows does not receives any tupple (because the algorithm could not converge with only 1 iteration).
If I print the beginning_loop, I see the initial tupples and the tupples from feed_back resultant from the fist iteration. But, nothing else than that.
So, summarizing my question, could this be a limitation of Flink? If so, do you know a different way of updating the vertices labels after the initial reduction, one that is not based on joins?
PS. I'm using Flink 1.3.3

PureScript FFI & Aff Monad: Why does the effect never run?

I'm a total PureScript newbie and need a bit of help figuring out why a FFI function modeled with the Aff monad doesn't seem to be working for me.
The expected behavior is to log a message "keyMessage" to the console after 1000ms.
Instead, the program just hangs indefinitely after the following output:
Compiling Main
* Build successful.
Waiting for message...
Main.purs:
module Main where
import Prelude
import Control.Monad.Aff (Aff, Fiber, launchAff)
import Control.Monad.Aff.Console (log)
import Control.Monad.Eff (Eff, kind Effect)
import Control.Monad.Eff.Console (CONSOLE)
main :: forall e. Eff (console :: CONSOLE, to :: TIMEOUT | e) (Fiber (console :: CONSOLE, to :: TIMEOUT | e) Unit)
main = launchAff do
log "Waiting for message..."
m <- message "key"
log m
foreign import data TIMEOUT :: Effect
foreign import message :: forall e. String -> Aff (to :: TIMEOUT | e) String
Main.js:
'use strict';
exports.message = function(key) {
return function(errback, callback) {
var timeout = setTimeout(function() {
callback(key + 'Message');
}, 1000);
return function() {
return function (cancelErrback, cancelCallback) {
clearTimeout(timeout);
return cancelCallback();
};
};
};
};
Thanks in advance for your insights!
If you're using the latest major version of purescript-aff (v4 or later) then the runtime representation of Aff has changed, and you can't create it directly using the errback/callback function style anymore.
Take a look at the https://pursuit.purescript.org/packages/purescript-aff/4.0.2/docs/Control.Monad.Aff.Compat module, in particular the EffFnAff type / fromEffFnAff functions for an explanation of how the equivalent thing works now.
Alternatively you can also construct Affs with makeAff, but that would require reformulating your FFI code a bit.

FireMonkey drawing with tPath does not fill the shape

I want to use a TPathData to draw shapes and fill them with an arbitrary color. I'm using the following code, at Button1Click, wich I extracted from a sample at Embarcadero documentation:
procedure TformPathDrawing.Button1Click(Sender: TObject);
var path: TPathData;
begin
Image1.Bitmap.Canvas.Fill.Color := TAlphaColorRec.Blue;
path := TPathData.Create;
path.Data := 'M 01,00 L 02,01 L 01,02 L 00,01 L 01,00';
Image1.Bitmap.Clear ($FFFFFF);
Image1.Bitmap.Canvas.BeginScene;
Image1.Bitmap.Canvas.FillPath (path, 200);
Image1.Bitmap.Canvas.EndScene;
end;
When this code is executed, as expected, a romboid is rendered, but it is not filled up with the color set in the first command. Anyone knows what is wrong? Thanks.
Here is right code. You can find another details in FMX.Objects.pas procedure TCustomPath.UpdateCurrent and other; or just Debug TPath visual component.
{aPath - is vector path of image;
aStretch - how to draw vector data - true - stretch draw, false = fit to bitmap
aBitmap - must be created. In bitmap you should specify:
Width, Height, Bitmap.Canvas.Fill.Color, Bitmap.Canvas.Stroke.Color
and, if you need, another drawing stuff like Gradient, stroke thikness,
background texture) }
procedure TForm1.DrawVectorPath(const aPath: string; aBitmap: TBitmap; aStretch: boolean);
var
vPath: TPathData;
R: TRectF;
begin
Assert(aBitmap <> nil);
vPath := TPathData.Create;
try
vPath.Data := aPath;
aBitmap.Clear($FFFFFF);
if aStretch then
begin
R := vPath.GetBounds;
vPath.Translate(-R.Left, -R.Top);
vPath.Scale(aBitmap.Width / R.Width, aBitmap.Height / R.Height);
end
else // Fit image
begin
R := TRect.Create(0, 0, aBitmap.Width, aBitmap.Height);
vPath.FitToRect(R);
end;
aBitmap.Canvas.BeginScene;
aBitmap.Canvas.FillPath(vPath, 1);
aBitmap.Canvas.DrawPath(vPath, 1);
aBitmap.Canvas.EndScene;
finally
vPath.Free;
end;
end;
Because comments can't have code (at least not formatted). Here is my code, that works.
procedure TForm7.RadioButton6Click(Sender: TObject);
var path: TPathData;
begin
Image1.Bitmap.Canvas.Fill.Color := TAlphaColorRec.Blue;
Image1.Bitmap.Canvas.Stroke.Color := TAlphaColorRec.black;
path := TPathData.Create;
try
path.Data := 'M 01,00 L 20,01 L 10,20 L 00,10 L 01,00';
Image1.Bitmap.Clear ($FFFFFF);
Image1.Bitmap.Canvas.BeginScene;
Image1.Bitmap.Canvas.FillPath (path, 200);
Image1.Bitmap.Canvas.EndScene;
finally
path.Free;
end;
end;
Note that the stroke color is set as well. That's the only difference I can make out here.
Follows code that works (in my case):
procedure TformPathDrawing.Button1Click(Sender: TObject);
begin
Image1.Bitmap.Canvas.Fill.Color := TAlphaColorRec.Blue;
path.Clear;
path.Data := 'M 01,00 L 02,01 L 01,02 L 00,01 L 01,00';
Image1.Bitmap.Canvas.BeginScene;
Image1.Bitmap.Canvas.FillPath (path, 1);
Image1.Bitmap.Canvas.EndScene;
end;
In my code, variable path is created outside the painting code. Since path.Data; is additive, it is mandatory, before adding the current path.Data;, to place a path.Clear; statement, to clean out whatever remains into the point array. Hope this help other people.

Can't run OpenGL on Haskell [duplicate]

Here is my source code I'm trying to get to work:
In Main.hs:
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
import Bindings
import Data.IORef
main = do
(progname,_) <- getArgsAndInitialize
createWindow "Hello World"
reshapeCallback $= Just reshape
keyboardMouseCallback $= Just keyboardMouse
angle <- newIORef 0.0
displayCallback $= display
idleCallback $= Just idle
mouseWheelCallback $= Just mouseWheel
mainLoop
In Bindings.hs:
module Bindings where
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
display :: IO ()
display = return ()
overlayDisplay :: IO ()
overlayDisplay = return ()
visibility :: Visibility -> IO ()
visibility v = return ()
reshape :: Size -> IO ()
reshape s#(Size w h) = do
viewport $= (Position 0 0, s)
close :: IO ()
close = return ()
keyboardMouse :: Key -> KeyState -> Modifiers -> Position -> IO ()
keyboardMouse key state modifiers position = return ()
mouseWheel :: WheelNumber -> WheelDirection -> Position -> IO ()
mouseWheel wn wd p = return ()
idle :: IO ()
idle = return ()
It works if I use normal glut32.dll and none of the freeglut extensions in my code, but I want to use the freeglut extensions.
When I use freeglut.dll, rename it to glut32.dll, and put it in the same folder as my .exe, it gives me the error:
main: user error (unknown GLUT entry glutInit)
When I use the normal glut32.dll in the same way I get the error:
main: user error (unknown GLUT entry glutMouseWheelFunc)
download glut from http://www.transmissionzero.co.uk/software/freeglut-devel/. Be sure to download the MinGW version.
copy the file freeglut-MinGW-3.0.0-1.mp.zip\freeglut\bin\x64\freeglut.dll to C:\Windows\System32. Make sure you get the 64 bit version from the x64 folder.
rename it as glut32.dll
I just solved this problem and hope this could help others.
You have to use freeglut .lib/.dll from Mingw or compile it yourself.

gstreamer : audiosink to output stream of integers representing volume levels

I need a gstreamer audio sink that outputs integers that
represent volume level of an audio stream. The sampling rate
need not be the same as the incoming audio stream, it can be much
lower, ex.: one value per second would be sufficient.
Does such a sink exist ?
It seems that this one could be modified to do this :
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-volume.html
But if something already exists I'd prefer to avoid writing one !
there indeed is such an element, it's not a sink though but I don't think you need it to be for that task anyway :)
It is called level (http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-level.html), and as you can see there is an "interval" property that you can tweak.
We use this element in our video editor to draw waveforms, here take this simplified script :
from gi.repository import Gst
from gi.repository import GLib
import sys
mainloop = GLib.MainLoop()
def _messageCb(bus, message):
if str(type(message.src)) == "<class '__main__.__main__.GstLevel'>":
s = message.get_structure()
p = None
if s:
p = s.get_value("rms")
if p:
st = s.get_value("stream-time")
print "rms = " + str(p) + "; stream-time = " + str(st)
if message.type == Gst.MessageType.EOS:
mainloop.quit()
elif message.type == Gst.MessageType.ERROR:
bus.disconnect_by_func(_messageCb)
mainloop.quit()
if __name__=="__main__":
global mainloop
Gst.init([])
pipeline = Gst.parse_launch("uridecodebin name=decode uri=" + sys.argv[1] + " ! audioconvert ! level name=wavelevel interval=10000000 post-messages=true ! fakesink qos=false name=faked")
faked = pipeline.get_by_name("faked")
bus = pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message", _messageCb)
pipeline.set_state(Gst.State.PLAYING)
mainloop.run()
pipeline.set_state(Gst.State.NULL)
May I inquire about your use case ?