4383l1

Listing 1. Sample of a Complete SISAL Application

% heatflow - compute the temperature evolution in a rod

define heatflow

type onec = array[character];
type onei = array[integer];
type oner = array[real];

global cdfcreate(filename: onec; seq: integer; comment: onec; returns integer)
global cdfputdim(fh: integer; dimname: onec; dsize: integer;
  returns integer, integer)
global cdfputrvar(fh: integer; varname: onec; dimlist: onei;
  data: oner; returns integer)
global cdfclose(fh: integer; returns integer)

function heatflow(nx, nt: integer; returns integer)
  let

    % do loop over time
    temp := for initial
	it := 0;

	% initialize the temperature distribution
	temp0 := array_fill(0 ,nx, 0.);
	temp1 := temp0[nx/2: 1.];
      while (it < nt) repeat

	% time step the temperature
	otemp1 := old temp1;
	it := old it + 1;
	temp1 := for ix in 0,nx
	    temp2 := if (ix = 0 | ix = nx) then
		0.          % keep the rod at temp = 0 on ends
	      else
		0.5*otemp1[ix] + 0.25*(otemp1[ix - 1] + otemp1[ix + 1])
	      end if;
	  returns
	    array of temp2
	  end for;

      returns
	value of catenate temp1
      end for;

    % define x and time dimensions
    x := for ix in 0,nx
      returns
	array of real(ix)
      end for;
    time := for it in 0,nt
      returns
	array of real(it)
      end for;

    % write the NetCDF file -- x iterates most rapidly since
    % it is the inner loop, so x dimension should be last
    fh1 := cdfcreate("temp.nc", -1, "Temperature
distribution in rod\n");
    dhtime, fh2 := cdfputdim(fh1, "time", nt + 1);
    dhx, fh3 := cdfputdim(fh2, "x", nx + 1);
    fh4 := cdfputrvar(fh3, "time", array[0: dhtime], time);
    fh5 := cdfputrvar(fh4, "x", array[0: dhx], x);
    fh6 := cdfputrvar(fh5, "temperature", array[0: dhtime, dhx], temp);
    result := cdfclose(fh6);

  in
    result   % return the dummy result so the NetCDF routines will be run
  end let
end function