OpenVMS Source-Code Demos

DEMO_DECIMAL_HACK2

1000	!=======================================================================
	! title  : demo_decimal_hack2.bas
	! author : Neil Rieck
	! created: 2016-07-29
	!=======================================================================
	option type=explicit							!
	option active=DECIMAL ROUNDING						!
	option size=(real double, integer long)					!
	!
	declare long		phase		,&
				my_error	,&
				i		,&
		decimal(7,2)	d72		,&
		decimal(7,1)	d71		,&
		decimal(6,2)	d62		,&
		string		j
	!
	map(xyz)string		a=1		,&
		decimal(7,2)	b		,&
		string		c=1		,&
		decimal(7,1)	d		,&
		string		e=1		,&
		decimal(6,2)	f		,&
		string		g=1		,&
		string		xyz_align=0	! enforce alignment check
	map(xyz)string		chunk=16	,&
		string		xyz_align=0	! enforce alignment check
	!=======================================================================
	d72	= 0.0								!
	d71	= 0.0								!
	d62	= 0.0								!
	!
	a	= "A"								!
	c	= "C"
	e	= "E"
	g	= "G"
	!
	!
	phase = 0								!
	when error in								!
	    !
	    print "open"							!
	    phase = phase + 1							!
	    open "demo_decimal_hack2.dat" as #2	&
		,organization relative		&
		,access modify			&
		,map xyz
	    !
	    print "put-1"							!
	    d72		= 0.0							!
	    d71		= 0.0							!
	    d62		= 0.0							!
	    b		= d72							!
	    d		= d71							!
	    f		= d62							!
	    gosub dump_chunk							!
	    phase = phase + 1							!
	    put #2, record 1							!
	    !
	    print "put-2"							!
	    d72		= 1.23							!
	    d71		= 1.2
	    d62		= 1.23
	    b		= d72							!
	    d		= d71							!
	    f		= d62							!
	    gosub dump_chunk							!
	    phase = phase + 1							!
	    put #2, record 2							!
	    !
	    print "close"
	    phase = phase + 1							!
	    close #2								!
	    my_error = 0
	use
	    my_error = err
	end when
	if my_error <> 0 then
	    print "error:";my_error;"during phase:";phase
	end if
	goto fini
	!
	dump_chunk:
	for i=1 to 16
	   j = mid$(chunk,i,1)
	   print "byte:"; format$(i,"###");" data:";asc(j)
	next i
	return
	!
	fini:
32000	end
	!======================================================================
	!		sample output
	!======================================================================
! Neil> r  DEMO_DECIMAL_HACK2
! open
! put-1
! byte:  1 data: 65
! byte:  2 data: 0
! byte:  3 data: 0
! byte:  4 data: 0
! byte:  5 data: 12
! byte:  6 data: 67
! byte:  7 data: 0
! byte:  8 data: 0
! byte:  9 data: 0
! byte: 10 data: 12
! byte: 11 data: 69
! byte: 12 data: 0
! byte: 13 data: 0
! byte: 14 data: 0
! byte: 15 data: 12
! byte: 16 data: 71
! put-2
! byte:  1 data: 65
! byte:  2 data: 0
! byte:  3 data: 0
! byte:  4 data: 18
! byte:  5 data: 60
! byte:  6 data: 67
! byte:  7 data: 0
! byte:  8 data: 0
! byte:  9 data: 1
! byte: 10 data: 44
! byte: 11 data: 69
! byte: 12 data: 0
! byte: 13 data: 0
! byte: 14 data: 18
! byte: 15 data: 60
! byte: 16 data: 71
! close
! Neil>
!Dump of file DISK$USER1:[CODE.DVLP._BASIC_DEMO]demo_decimal_hack2.dat;1 on 29-JUL-2016 11:26:56.77
!File ID (825,45,0)   End of file block 16 / Allocated 16
!
!Virtual block number 1 (00000001), 512 (0200) bytes
!
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000000
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000020
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000040
! 00000000 00000000 00000001 00000011 7FFFFFFF 00000002 00000000 00000000 ................................ 000060
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000080
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0000A0
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0000C0
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0000E0
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000100
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000120
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000140
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000160
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000180
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0001A0
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0001C0
! 80120000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0001E0
!
!Dump of file DISK$USER1:[CODE.DVLP._BASIC_DEMO]demo_decimal_hack2.dat;1 on 29-JUL-2016 11:26:56.77
!File ID (825,45,0)   End of file block 16 / Allocated 16
!
!Virtual block number 2 (00000002), 512 (0200) bytes
!
! 2C010000 433C1200 00410010 08470C00 0000450C 00000043 0C000000 41001008 ...A....C....E....G...A...<C..., 000000
! 00000000 00000000 00000000 00000000 00000000 00000000 0000473C 12000045 E...<G.......................... 000020
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000040
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000060
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000080
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0000A0
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0000C0
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0000E0
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000100
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000120
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000140
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000160
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 000180
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0001A0
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0001C0
! 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ................................ 0001E0
!