[inherit('sys$share:starlet','mdalib')]
program mdatest(output);
type
    b  = boolean;
    i  = integer;
    v  = PACKED ARRAY [1..10] OF INTEGER;
    sf = PACKED ARRAY [1..10] OF CHAR;
    sv = VARYING [20] OF CHAR;
    w  = [WORD] 0..65535;
    wa = PACKED ARRAY [1..10] OF w;
    q  = [QUAD,UNSAFE] RECORD L0:UNSIGNED; L1:INTEGER END;
    c  = RECORD
	    composite_1: i;
	    composite_2: v;
	    composite_3: wa
         END;
var
    is : b;
    j,k,l : i;
    jn : w;
    filename, defaultfile, queuename, jobname : sv;
    readbuf : sf;
    long_array : v;
    word_array, another_word_array : wa;
    feb_2001 : q;
    comp : c;
BEGIN
(* is it in batch mode *)
is := loc_batch; writeln( 'In batch mode :',is);
is := loc_inter; writeln( 'Interactive   :',is);
is := loc_network; writeln('Network       :',is);
writeln;

(* swap byties *)
for j := 1 to 10 do word_array[j] := j;
writeln('Ordered lsbyte first');
for j := 1 to 10 do write( HEX(word_array[j],5,4) ); writeln;
loc_bswap( word_array, 10 );
writeln('Ordered lsbyte last');
for j := 1 to 10 do write( HEX(word_array[j],5,4) ); writeln;
writeln;

(* zero arrays *)
for j := 1 to 10 do another_word_array[j] := j*3+1;
writeln('Is this array zero');
for j := 1 to 10 do write( HEX(another_word_array[j],5,4) ); writeln;
loc_zeroarray( another_word_array, 10*2 );
for j := 1 to 10 do write( HEX(another_word_array[j],5,4) ); writeln;
with comp do begin
    composite_1 := 3;
    for j := 1 to 10 do composite_2[j] := 3*j+1;
    for j := 1 to 10 do composite_3[j] := 3*j+2;
    writeln('Is this composite zero');
    writeln( composite_1 );
    for j := 1 to 10 do write( composite_2[j]:4 );
    for j := 1 to 10 do write( composite_3[j]:4 );
    loc_zeroarray( composite_1, 64 );
    writeln( composite_1 );
    for j := 1 to 10 do write( composite_2[j]:4 );
    for j := 1 to 10 do write( composite_3[j]:4 )
    end;
writeln;

(* copy arrays *)
writeln('Copy something into this array');
for j := 1 to 10 do write( HEX(another_word_array[j],5,4) ); writeln;
loc_copyarray( word_array, another_word_array, 10*2 );
for j := 1 to 10 do write( HEX(another_word_array[j],5,4) ); writeln;
writeln;

(* How many arguments passed to main program *)
(*writeln( loc_nargs(0), 'Arguments passed to me.' );
writeln; *)


(* open mdatest.pas and read it until error *)
writeln('Try out MDATEST.PAS as a file' );
filename := 'MDATEST'; defaultfile := 'SYS$DISK:[].PAS';
l := loc_iofast$open( 2, filename, defaultfile );
writeln( HEX(l,9) );
    while ODD(l) do
      begin
	l := loc_iofast$get( 2, readbuf, j );
	writeln( readbuf, j );
	writeln( HEX(l,9) )
      end;
l := loc_iofast$close(2);
writeln( HEX(l,9) );
writeln;

(* submit MDATEST.COM for printing in feb 2001 *)
writeln('print mdatest.com in feb 2001 ');
$BINTIM( '2-FEB-2001 19:37:00', feb_2001 );
filename := 'mdatest.com'; queuename := 'TXA2'; jobname := 'mdatest';
l := loc_print( filename, queuename, jobname,
     feb_2001, 2, , 3, true, jn );
writeln( HEX(l,9) );
writeln(' job number ',jn );
writeln;

(* submit mdatest.com as a batch job on LATE$BATCH after feb 2001 *)
writeln( 'Submit mdatest.com in feb 2001' );
queuename := 'LATE$BATCH'; 
l := loc_jobsubmit( filename, queuename, jobname,
    feb_2001, 'mdatest11.lll', , , jn, ,,,,,,, );
writeln( HEX(l,9) );
writeln( ' job number ',jn );
writeln

END.
