Home > src > main > matlab > make_card.m

make_card

PURPOSE ^

MAKE_CARD turns a set of strings into a valid FITS card

SYNOPSIS ^

function card=make_card(keyword,value)

DESCRIPTION ^

MAKE_CARD turns a set of strings into a valid FITS card
Make keyword field 8 bytes long

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function card=make_card(keyword,value)
0002 %MAKE_CARD turns a set of strings into a valid FITS card
0003 %Make keyword field 8 bytes long
0004 lk=length(keyword);
0005 if (lk > 8) & (nargin>1)
0006     error('Keyword must be less than or equal to 8 characters!')
0007 elseif (lk < 8 )
0008     keyword=[keyword,setstr(ones(1,8-lk)*32)];
0009 end;
0010 
0011 %Deal with both straight keyword and keyword/value pair
0012 if (nargin==1)
0013     %Keyword without a value
0014     card=keyword;    
0015 else
0016     %Key/value pair has an equal sign and space at bytes 9 and 10
0017     card=[keyword,'= '];
0018 
0019     %Now output the value. The FITS standard wants things to start
0020     %in different columns depending on what type of data the
0021     %value holds, according to the following rules:
0022     %
0023     %  Logical: T or F in column 30
0024     %
0025     %  Character string: A beginning quote in column 11 and an
0026     %  ending quote between columns 20 and 80.
0027     %
0028     %  Real part of an integer or floating point number: right
0029     %  justified, ending in column 30.
0030     %
0031     %  Imaginary part: right justified, ending in
0032     %  column 50, starting after column 30 (NB. I won't bother
0033     %  to support an imaginary part in this M-file, and will
0034     %  let some radio astronomer who needs it add it if they want).
0035 
0036     if isstr(value)
0037           %Test for logical. If logical it goes in column 30
0038         if (length(value)==1) & (strmatch(upper(value),'T') | strmatch(upper(value),'F'))
0039              card=[card,setstr(ones(1,19)*32),value];    
0040         else    
0041             %Value must be a character string. Pad if less than 8
0042             %characters long.
0043             lv=length(value);
0044             if (lv > 70)
0045            error('Value must be less than 70 characters long!')
0046             elseif (lv < 10 )
0047              value=[value,setstr(ones(1,8-lv)*32)];
0048             end;
0049             card=[card,'''',value,''''];
0050         end;    
0051     else
0052         %Value must be a number. Convert to a string. Maximum
0053         %precision is set to 10 digits
0054         value=num2str(value,10);
0055         lv=length(value);
0056     
0057         %Write this out so it will end on column 30
0058         card=[card,setstr(ones(1,20-lv)*32),value];    
0059     end;
0060 end;
0061 
0062 %Now pad the output to make it exactly 80 bytes long
0063 card=[card,setstr(ones(1,80-length(card))*32)];

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