Slowing Down is the Key…..

slow down

Slowing down is the key to increased speed.

Past couple of months I was dabbing with fortran GUI and trying pgplot graphics library. I have produced gui’s in c, vb and then integrated them with fortran, but creating GUIs from fortran was new to me.

As the exploration began I took the fire aim adjust approach!! Dived deep into the tutorials and anything that I could lay my hands on.

Quickly from tutorials I graduated to actually creating my own little programs. This went on for a couple of months.

In the beginning I was sprinting as hard as possible. Learning, doing, getting stuck, reading and then doing again. The pace was fast.

But as I become comfortable, my approach shifted. I slowed.

I wrote a program and pondered how and what am I actually doing. This slowing down and pondering doubled my learning. It felt like I was learning at greater pace with this slowdown.

So the technique I want to advocate to anyone learning a new programming language, a new analysis tool or cad software, is to sprint in the first few weeks. Race and learn as much as you are able to handle. Dive deep and continue the pace as long as you are able to.

When exhaustion, sense of acheivement begins to creep in, slow down. Become deliberate in what you do? Question why and what you are doing?

I hope applying this method will help you as much as it has helped me.

What are your views, do let it out in the comments.

Advertisement

How to Create PGPLOT Fortran Programs With Intel Fortran Compiler ? An animated Journey…

How to create PGPLOT P\programs with Intel Compiler?

How to create PGPLOT programs with Intel Compiler?

How to create PGPLOT Fortran programs with Intel compiler is one of the popular post on this blog and every few days I get a request to share the powerpoint, so here’s the animated version of the powerpoint for quick reference..

Using PGPLOT, then you should visit and see these pages. Want the make file shown in the above animation, visit  How to use pgplot in windows with intel fortran. to download it!

Hermite Polynomials.

Hermite Polynomials are showing up in all most all the technical papers that I am reading these days.

Their constant appearance lead me to investigate them further. After a couple of hour of digging, I have this fortran module ready to get and evaluate hermite Polynomials.

The figure shows Pgplot output of these polynomials. Click the image to enlarge.

Here’s the fortran module to handle Hermite Polynomials.

On Wasting time and inefficiency

From the new rules blog

Wasting time and inefficiencies are the way to discovery. When Condé Nast’s editorial director Alexander Liberman was challenged on his inefficiencies in producing world-class magazines such The New Yorker, Vanity Fair, and Architectural Digest, he said it best: “I believe in waste. Waste is very important in creativity.”

Out of many things, inefficiencies have helped me learn java and pgplot at a faster rate.

Trying things, creating silly programs has produced so many wasteful programs, but each has sharpened the skills.

Animating Heart using pgplot with fortran

Here’s the code for the heart animation written in fortran, using pgplot and quickwin.

Not an optimized code but mashed quickly to get something up and running.

Find the story and code in action at the following post Did i miss the valentine’s day?

      MODULE DATAitem

      TYPE thedata
        REAL x0,y0,xf,yf,dx,dy,speed
        CHARACTER(len=1) schar
      END TYPE

      INTEGER,parameter :: isteps=15,iinum=2000
      INTEGER inum
      LOGICAL :: direction
      END MODULE

      PROGRAM heart

!
! Animating heart.
! by sukhbinder
! date: 27th Feb 2012
!

      USE DATAitem
      USE IFqwin

      TYPE(qwinfo) :: winfo
      INTEGER(4)   :: RESULT

      INTEGER  :: pgopen,pgcurs
      REAL xr(iinum),yr(iinum)
      TYPE(thedata) alpa(iinum)
      CHARACTER*1 ch

      winfo%TYPE=QWIN$MAX
      RESULT= setwsizeqq(qwin$framewindow,winfo)

      RESULT=aboutboxqq("Heart animation IN PGPLOT\rSukhbinder SINgh\rVersion 1.0\r15Feb2012"C)

      direction =.true.

      IF(pgopen('/w9') .LE. 0) STOP

      CALL pgenv(-2.0,2.0,-2.0,1.5,1,-2)

      DO iii=100,2000,200
         INum=iii
         CALL INit
         CALL mydelay(500)
         CALL ani

      END DO

      CALL pgclos

      CONTAINS

      SUBROUTINE ani

       DO i=1,isteps
         CALL pgbbuf()

          CALL pgsci(0)

            CALL pgpt(inum,alpa%xf,alpa%yf,1)

          CALL pgsci(2)
          DO j=1,inum
            IF(direction) THEN

              alpa(j)%xf=alpa(j)%xf-alpa(j)%dx
              alpa(j)%yf=alpa(j)%yf-alpa(j)%dy
            ELSE
              alpa(j)%xf=alpa(j)%xf+alpa(j)%dx
              alpa(j)%yf=alpa(j)%yf+alpa(j)%dy
            END IF

          END DO
          CALL pgpt(inum,alpa%xf,alpa%yf,1)
          CALL mydelay(400)

         CALL pgebuf()
       END DO

       IF(direction) THEN
         direction = .FALSE.
       ELSE
         direction = .TRUE.
       END IF

       END SUBROUTINE ani

      SUBROUTINE init

      REAL xxx(3)

      xr(1)=-2.0
      xinc=real(4.0/inum)
      yr(1)=(cos(xr(1)))**0.5 * cos(200*xr(1)) + (abs(xr(1)))**0.5 -0.7 &
	  * (4.0 -xr(1) * xr(1))**0.01
      DO i=2,inum
       xr(i)=xr(i-1)+xinc
       yr(i)=(cos(xr(i)))**0.5 * cos(200*xr(i)) +  (abs(xr(i)))**0.5 -0.7 &
	   * (4.0 -xr(i) * xr(i))**0.01
      END DO

       CALL RANDOM_SEED
       DO i=1,inum
         alpa(i)%x0=xr(i)
         alpa(i)%y0=yr(i)
         CALL RANDOM_NUMBER(xxx)
         xxx(1)=-20.0 + xxx(1)*40.0
         xxx(2)=-20.0 + xxx(2)*40.0

         xxx(3)=xxx(1)
         alpa(i)%xf=xxx(1)
         alpa(i)%yf=xxx(2)
         alpa(i)%speed=xxx(3)
         alpa(i)%dx=(alpa(i)%xf-alpa(i)%x0)/isteps
         alpa(i)%dy=(alpa(i)%yf-alpa(i)%y0)/isteps
       END DO

        CALL pgsci(2)
       CALL pgpt(inum,alpa%xf,alpa%yf,1)

      END SUBROUTINE
      END PROGRAM

      SUBROUTINE mydelay(nnsec)
      INTEGER :: COUNT, count_rate, count_max,nnsec,icount

      CALL SYSTEM_CLOCK(count, count_rate, count_max)
      icount = count+nnsec
      DO
        CALL SYSTEM_CLOCK(count, count_rate, count_max)
        IF(count .GE. icount) EXIT

      END DO

      END SUBROUTINE

Did I Miss Valentine’s Day?

Did I miss valentine’s day? Actually no. But was super busy at office. And at home busy with my daughter and a sport meet that i was help organizing.

Now the sports meet is over and yesterday i saw and completed this animation in fortran.

Actually i was lazy and used the code from previous”Heart In fortran” code and created this animation.

The video do not do justice, you need to download the exe and see it for yourself. Will post the source code little latter.

By the way. Happy Valentine’s Day.

Neutron Collisions, Stanislaw Ulam , Solitares and my Pgplot practice.

The year was 1946. Physicists at Los Alamos Scientific Lab were investigating radiation shielding and distance neutrons would travel in various materials. Despite having the data, the problem could not be solved with analytical calculations.

At the very same time, Stanislaw Ulam was convalescing from an illness and playing solitaires and thinking. His thoughts meandered around what are the chances that a Canfield solitaire laid out with 52 cards will come out successfully?

Stanislaw says “After spending a lot of time trying to estimate them by pure combinatorial calculations, I wondered whether a more practical method than “abstract thinking” might not be to lay it out say one hundred times and simply observe and count the number of successful plays. This was already possible to envisage with the beginning of the new era of fast computers, and I immediately thought of problems of neutron diffusion and other questions of mathematical physics, and more generally how to change processes described by certain differential equations into an equivalent form interpretable as a succession of random operations. Later, I described the idea to John von Neumann, and we began to plan actual calculations”

Thus the Monte Carlo Method was born.

Monte Carlo methods are a class of computational algorithms that rely on repeated random sampling to compute their results. These methods are most suited to calculation by a computer and tend to be used when it is infeasible to compute an exact result with a deterministic algorithm. Source wikipedia

If you read through the above Wikipedia article, it explains a method to estimate the value of Pi approximately using Monte Carlo Method. So here’s the Fortran program just doing that.

It uses PGPLOT as the graphics engine and you can see graphically see how the program estimates the value of Pi.

This slideshow requires JavaScript.

Really cool!! But not as cool as neutron collisions!

Download the program and Download the source

Let It Snow in Fortran – the code

So here’s the code to do “let it snow” with Fortran.

If you are looking for developing graphics application with Intel Fortran compiler using pgplot and quickwin, then this small program can get you started.

The snow module is generic and creates the snow, while the main program deals with actually driving the snow.

You can download the program here and see the snow in action here

Have a look.

      MODULE SNOW
!———————————————————————–
! Inspired from Google’s let it snow
! Developed by Sukhbinder Singh

! 30th December 2011
!
!———————————————————————–
      INTEGER, PARAMETER :: NUM=200
      INTEGER, PARAMETER :: ITIME=50
      INTEGER, PARAMETER :: ISPEED=700
      REAL :: Y(NUM),X(NUM),FALL(NUM)
      REAL :: SFS(NUM),STEP(NUM),CURRSTEP(NUM)
      REAL :: H,W,R
      CONTAINS

!
!———————————————————————–
      SUBROUTINE INIT()
      DOUBLE PRECISION :: XX
      CALL RANDOM_SEED

      W=600.0
      H=600.0
      DO I=1,NUM
       CALL RANDOM_NUMBER(XX)
       SFS(I)=INT(1.0D0+XX*1.0D0)
       CURRSTEP(I)=0
       IF(SFS(I) .EQ. 1) THEN
        CALL RANDOM_NUMBER(XX)
        FALL(I)=INT(2.0D0+XX*2.0D0)
        CALL RANDOM_NUMBER(XX)
        STEP(I)=0.050D0+XX*0.1D0
       ELSE

        CALL RANDOM_NUMBER(XX)
        FALL(I)=INT(3.0D0+XX*2.0D0)
        CALL RANDOM_NUMBER(XX)
        STEP(I)=0.050D0+XX*0.050D0
       END IF
       CALL RANDOM_NUMBER(XX)
       XX=XX*W
       X(I)= XX

       CALL RANDOM_NUMBER(XX)
       XX=XX*H
       Y(I)= XX

!
      END DO
      END SUBROUTINE
!
!———————————————————————–
      SUBROUTINE SNOWING
      DOUBLE PRECISION :: DX,DY,XX

      CALL RANDOM_SEED

      DO I=1,NUM
      DY=FALL(I)
      DX = FALL(I)*COS(CURRSTEP(I))
      Y(I)=Y(I)-DY
      X(I)=X(I)-DX
!
      IF((X(I) .LE. 0.0) .OR. (Y(I) .LE. 0.0)) THEN

      CALL RANDOM_NUMBER(XX)
      Y(I)=H*XX
      CALL RANDOM_NUMBER(XX)
      X(I)=XX*W
!
      IF(SFS(I) .EQ. 1) THEN

       CALL RANDOM_NUMBER(XX)
       FALL(I)=INT(2.0D0+XX*2.0D0)
!
       CALL RANDOM_NUMBER(XX)
       STEP(I)=0.050D0+XX*0.1D0
      ELSE
       CALL RANDOM_NUMBER(XX)
       FALL(I)=INT(3.0D0+XX*2.0D0)
       CALL RANDOM_NUMBER(XX)
       STEP(I)=0.050D0+XX*0.050D0
      END IF

      END IF
      CURRSTEP(I)=CURRSTEP(I)+STEP(I)
      END DO

      END SUBROUTINE

!
!———————————————————————–
      SUBROUTINE MYDELAY(NNSEC)
      INTEGER :: COUNT, COUNT_RATE, COUNT_MAX,NNSEC,ICOUNT
      CALL SYSTEM_CLOCK(COUNT, COUNT_RATE, COUNT_MAX)
      ICOUNT = COUNT+NNSEC
      DO

       CALL SYSTEM_CLOCK(COUNT, COUNT_RATE, COUNT_MAX)
       IF(COUNT .GE. ICOUNT) EXIT
      END DO

      END SUBROUTINE
      END MODULE
!———————————————————————–
! Main program calling the snow module
! uses quickwin and pgplot library.
!———————————————————————–

      PROGRAM SNOWFORTRAN
!
      USE SNOW
      USE IFQWIN
!Qwin
      INTEGER(4) RESULT

      INTEGER(2) numfonts, fontnum
      TYPE (qwinfo) winfo
!
      INTEGER N,NT
      REAL PI,A,B
      PARAMETER (NT = 2000)
      PARAMETER (PI=3.14159265359)
      PARAMETER (A = 2.0*PI/num)
      PARAMETER (B = 2.0*PI/NT)

! Variables:
      INTEGER I, T, L,ISYM
      CHARACTER*8 STR
      INTEGER PGBEG
!———————————————————————–

      IF (PGBEG(0,’/w9',1,1) .NE. 1) STOP

! Maximize frame window
      winfo%TYPE = QWIN$MAX
      RESULT = SETWSIZEQQ(QWIN$FRAMEWINDOW, winfo)
! Maximize child window
      RESULT = SETWSIZEQQ(0, winfo)

      CALL PGQINF(‘HARDCOPY’, STR, L)
      IF (STR(:L).NE.’NO’) WRITE (*,*) ‘Warning: device is not interactive’

      CALL INIT
      N=NUM
      ISYM=39
      CALL PGPAGE
      CALL PGVSIZ (-1.5, 10.5, -1.5, 8.0)
      CALL PGWNAD(0.0, W, 0.0, H)
      CALL PGBBUF
      CALL PGSCI(1)

!
      CALL PGPT (N, X, Y, ISYM)
      CALL PGEBUF
      CALL PGSCI(3)
      CALL PGSLS(5)
      CALL PGSLW (25)
      CALL PGSCH(5.0)
      CALL PGMTXT(‘B’, -1.7, 1.4, 1.5,’\frHAPPY NEW YEAR’)
      CALL PGSCH(1.0)
      CALL PGSLW (1)

      DO

       CALL PGBBUF
       CALL PGSCI(0)
       CALL MYDELAY(ISPEED)
       CALL PGPT (N, X, Y, ISYM)
       CALL PGSCI(1)
       CALL SNOWING
       CALL PGPT (N, X, Y, ISYM)
       CALL PGEBUF
      END DO

      CALL PGEND
      END

Let It Snow in Fortran

It all began with google’s “let it snow” ester egg.

As soon as I saw the snow tumbling down my browser, I wanted to do the same with fortran.

Snow animation in fortran.
Graphics is not fortrans strong point. But luckily it has help from pgplot and I was tinkering with it for some time, so creating snow with fortran was an interesting challenge.

The physics was simple, a vertical cos wave did the trick and then I just had to control the speed and viola I had snow in fortran.

I will admit, the video i posted for happy new year for that snow animation do not do full justice to the actual program. So here’s the actual executables for anyone to try on their windows system.

Download the executable

Go ahead try. They are awesome. In fact I love them more than google’s snow.

I did these animations in a hurry to meet the new year, so the code is still not fit for wider audience, please be patient, will post the code soon. Hopefully in a format that it can be used to actually snow. 😉

Till then, let it snow.

There’s something magical about seeing those white flakes tumble down!!

Download the programs here

How to create PGPLOT Fortran programs with Intel compiler

This post is sequel to the previous post titled How to use pgplot in windows with intel fortran.

 

 

The above PowerPoint explains the steps to use the previous libraries to create pgplot fortran programs.

This ppt uses the make file distributed in the previous post.

The intention for the post is to get the ball rolling for someone new to pgplot.

How to use pgplot in windows with Intel Fortran?

Using PGPLot library requires these steps.

  1. Download the Source code
  2. Create the binary font file
  3. Create the pgplot library
  4. Use the above two files to create pgplot programs.

This previous post titled Installing and using Pgplot in windows explains how to accomplish the first three tasks.

Now if you are using windows and want to just use these libraries to create graphs from your fortran program, then i have compiled the pgplot library and the font file for you to use.

You can download the same from this link . This is a pre compiled 32 bit windows pgplot library and the binary font file.

You can use these two files and get straight to creating Pgplot programs.

The zip file includes a make.bat which can be used to create the Pgplot programs.

Download the PgPLOT library