    % read a SPIDER image and display it.
    im = readSPIDERfile('img001.dat');

    % the resulting matix is type double. To display using
    % imshow or imtool, rescale to (0..1) with mat2gray :
    imshow(mat2gray(im));
    pause(2);
    close

    % display images from a stack using Matlab's montage:
    s = readSPIDERfile('stk001.hcc');
    t = mat2gray(s);

    % For some reason, montage wants an extra singleton dimension.
    % Create it by reshaping the array.
    [ix iy iz] = size(t);
    montage(reshape(t, [ix,iy,1,iz]));
    pause(2);
    close

    % Extract some slices from a volume
    v = readSPIDERfile('vol001.hcc');
    [ix iy iz] = size(v);
    k = round(ix/2);
    imx =  squeeze(v(k,:,:));   % extract a slice from the x plane
    imy =  squeeze(v(:,k,:));   % extract a slice from the y plane
    imz =  squeeze(v(:,:,k));   % extract a slice from the z plane
    % squeeze removes the extra singleton dimension, giving 2D images

    % display them as subimages
    subplot(1,3,1), subimage(mat2gray(imx))
    subplot(1,3,2), subimage(mat2gray(imy))
    subplot(1,3,3), subimage(mat2gray(imz))
    pause(2);
    close

    % concatenate the images and write out as an image stack
    C = cat(3,imx,imy,imz);
    writeSPIDERfile('mystack.dat', C, 'stack')
    disp('data written to mystack.dat')

    % Display some slices through the volume
    h = slice(double(v),k,k,k);
    set(h,'FaceColor','interp','EdgeColor','none')
    colormap gray
    pause(3)
    close

    %----------------------------------------------
    % document file functions

    docfile = 'doc001.txt';
    disp(sprintf('The contents of %s:', docfile))
    type(docfile)
    q = readSPIDERdoc(docfile) % read the entire file
    x  = q(:,1);  % the first column
    y1 = q(:,2);  % the second column
    y2 = q(:,3);  % third column
    plot(x,y1,x,y2)
    pause(2)
    close

    % create some arrays and write them out
    c1 = [1:10]       % c1, c2 are row vectors,use transpose (')
    c2 = [1:10:100]   % to turn them into columns.
    b2 = [c1' c2'];    % [ ] concatenates columns horizontally
    outdoc = 'newdoc.txt';
    writeSPIDERdoc(outdoc, b2, {'ones'; 'tens'});
    disp(sprintf('data written to %s', outdoc))
    type(outdoc)

    data written to mystack.dat
    The contents of doc001.txt:

     ;spl/txt   01-FEB-2009 AT 12:46:13   doc001.txt
     ; /          micros     defocus       astig
        1  3           1       36797      88.661
        2  3           7       31989     -77.546
        3  3          14       23748      53.213
        4  3          16       21499     -74.223
        5  3          27       14098      33.008

    q =

      1.0e+004 *

        0.0001    3.6797    0.0089
        0.0007    3.1989   -0.0078
        0.0014    2.3748    0.0053
        0.0016    2.1499   -0.0074
        0.0027    1.4098    0.0033

    c1 =

      Columns 1 through 9

         1     2     3     4     5     6     7     8     9

      Column 10

        10

    c2 =

      Columns 1 through 9

         1    11    21    31    41    51    61    71    81

      Column 10

        91

    data written to newdoc.txt

     ;mat/txt   05-Feb-2009 AT 11:13:57   newdoc.txt
     ; /           ones       tens
        1  2          1          1
        2  2          2         11
        3  2          3         21
        4  2          4         31
        5  2          5         41
        6  2          6         51
        7  2          7         61
        8  2          8         71
        9  2          9         81
       10  2         10         91