subroutine sub_progress(dlg, id, callbacktype)
use dflogm
use dflib

!use dfwin	! for sleep()

type(dialog) dlg
integer id, callbacktype

include "resource.fd"

logical retlog
integer retint

integer percent
character(3) percent_char, text_char*6
character(12) text

common/max/imax


imin =10000


SELECT CASE(id)

CASE(idc_Edit1)
retlog =dlgGet(dlg, idc_Edit1, text)

read(text, '(I)') iEnd
retlog =dlgSet(dlg, idc_Button1, iend >imin, dlg_enable)


CASE(idc_Button1)

sum =0.0

if(iend <=1E5) then
iproc =20

elseif(iend<=1E6)then
iproc =10

else
iproc =5
endif

percent_ant =0

DO ii =1, iend
sum =sum +1./real(ii)


! Update Static & Progress bar:

x_progress =real(ii)/real(iend)
i_progress =nint(x_progress*imax)

percent =nint(x_progress*100)


if(mod(percent, iproc) ==0 .and. percent >percent_ant) then
write(percent_char, '(I3)') percent
text_char =percent_char//' %'


retlog =dlgSet(dlg, idc_progress1, i_progress)	!, dlg_position)
call dlgflush(dlg)

retlog =dlgSet(dlg, idc_Static_Percent, trim(text_char))


!call sleep(int4(300))	!~ok; nu updateaza Progress!
call sleepqq(int4(300))

percent_ant =percent
endif

ENDDO

END SELECT


end subroutine sub_progress
