Home > src > main > matlab > fitswrite.m

fitswrite

PURPOSE ^

Author: R. G. Abraham, Institute of Astronomy, Cambridge University

SYNOPSIS ^

function fitswrite(data, filename, parname, parval)

DESCRIPTION ^

Author: R. G. Abraham, Institute of Astronomy, Cambridge University
        abraham@ast.cam.ac.uk
Improved by Boris Leistedt bo be compatible with MW and HEALPIX maps

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function fitswrite(data, filename, parname, parval)
0002 %Author: R. G. Abraham, Institute of Astronomy, Cambridge University
0003 %        abraham@ast.cam.ac.uk
0004 %Improved by Boris Leistedt bo be compatible with MW and HEALPIX maps
0005 
0006 [nrow,ncol]=size(data);
0007 header_cards = [make_card('SIMPLE','T');       ...
0008       make_card('BITPIX',16);       ...
0009       make_card('NAXIS',0);          ...
0010       make_card('EXTEND','T');        ...
0011       make_card('END');];
0012   
0013 [nrowbis,ncolbis] = size(header_cards);
0014 n_blanks = 36 - rem(nrowbis,36);
0015 blank_line = setstr(ones(1,80)*32);
0016 header_cards2 = [header_cards; repmat(blank_line,n_blanks,1)];
0017 
0018 header_cards2 = [header_cards2;       ...
0019       make_card('XTENSION','BINTABLE');        ...
0020       make_card('BITPIX',8);        ...
0021       make_card('NAXIS',2);          ...
0022       make_card('NAXIS1',4);      ...
0023       make_card('NAXIS2',ncol);      ...
0024       make_card('PCOUNT',0);        ...
0025       make_card('GCOUNT',1);        ...
0026       make_card('TFIELDS',1);        ...
0027       make_card('TTYPE1','SIGNAL');        ...
0028       make_card('TFORM1','1E');        ...
0029       make_card('TUNIT1',' ');        ...
0030       make_card('EXTNAME','BINTABLE');        ...
0031       make_card(parname, parval);        ...
0032       make_card('END')];
0033 
0034 header_record = make_header_record(header_cards2);
0035 %[ncards,dummy]=size(header_cards);
0036 %fprintf(header_record(1,:));
0037 
0038 fid=fopen(filename,'W');
0039 fwrite(fid,header_record','char');
0040 
0041 % try to figure out if we need to swap bytes. This is
0042 % imperfect as I don't know the endian-ness of each
0043 % architecture, so I'm only looking for ones I know for
0044 % sure are big-endian.
0045 friend = computer;
0046 if strmatch(friend,'PCWIN')
0047    bswap = 'b';
0048 elseif strmatch(friend,'LNX86')
0049    bswap = 'b';   
0050 elseif strmatch(friend,'ALPHA')
0051    bswap = 'b';
0052 else
0053    bswap = 'l';
0054 end
0055 
0056 fwrite(fid, data, 'single', 0, 'B');
0057 %fwrite(fid,data,'single',bswap);
0058 fclose(fid);
0059 
0060 
0061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0062 
0063 
0064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0065 
0066 function hrec=make_header_record(card_matrix)
0067 
0068 [nrow,ncol] = size(card_matrix);
0069 n_blanks = 36 - rem(nrow,36);
0070 blank_line = setstr(ones(1,80)*32);
0071 hrec = [card_matrix; repmat(blank_line,n_blanks,1)];
0072

Generated on Fri 11-Nov-2016 11:50:36 by m2html © 2005