Home > matutils > j2000coord.m

j2000coord

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function [ra, dec] = j2000coord(source, raType, decType)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  function [ra, dec] = j2000coord(source, raType, decType)

    inputs:  source - the source name
             raType -  either 'str', 'hr', 'deg'
             decType - either 'str', 'deg'

    searches through the source catalogs to find the source

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ra, dec] = j2000coord(source, raType, decType)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function [ra, dec] = j2000coord(source, raType, decType)
0006 %
0007 %    inputs:  source - the source name
0008 %             raType -  either 'str', 'hr', 'deg'
0009 %             decType - either 'str', 'deg'
0010 %
0011 %    searches through the source catalogs to find the source
0012 %
0013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0014 
0015 % check the inputs
0016 if(nargin == 1)
0017   raType = 'string';
0018   decType = 'string';
0019 elseif(nargin == 3)
0020     if~(strcmp(raType, 'str') | strcmp(raType, 'hr') | strcmp(raType,'deg'))
0021       error('raType not a valid input');
0022     end
0023     if~(strcmp(decType, 'str') | strcmp(decType, 'deg'))
0024       error('decType not a valid input');
0025     end
0026 else
0027   error('Needs either 1 or 3 inputs');
0028 end
0029 
0030 currDir = pwd;
0031 cd /home/szadaq/sza/array/ephem
0032 [status, result] = unix('ls *.cat');
0033 remainder = result;
0034 index=0;
0035 while(~isempty(remainder))
0036   index=index+1;
0037   [file{index} remainder] = strtok(remainder);
0038 end
0039 for m=1:index-1
0040   txt = sprintf('egrep --binary-files=text \"J2000 %s\" %s', source, ...
0041         file{m});
0042   [status found] = unix(sprintf('%s',txt));
0043   if(status == 0)
0044     pattern = source;
0045     locs = strfind(found, pattern);
0046     for n=1:length(locs)
0047       found = found(locs(n):length(found));
0048       thisSource = strtok(found);
0049       thisIt = strcmp(thisSource, source);
0050       if(thisIt)
0051     [source rem] = strtok(found);
0052     [ra     rem] = strtok(rem);
0053     [dec    rem] = strtok(rem);
0054     break;
0055       end
0056     end
0057     if(thisIt)
0058       break;
0059     end
0060   end
0061 end
0062 
0063 % first we need to check what kind of format it is in, whether it
0064 % is decimal or a string (HH:MM:SS or HH.HHHHH);
0065 
0066 if(~isempty(strfind(ra, ':')))
0067   ra = ra;
0068 else
0069   raVal = str2num(ra);
0070   hr = floor(raVal);
0071   if(hr<10)
0072     hrStr = sprintf('0%d', hr);
0073   else
0074     hrStr = num2str(hr);
0075   end
0076   min = floor((raVal-hr)*60);
0077   if(min<10)
0078     minStr = sprintf('0%d', min);
0079   else
0080     minStr = num2str(min);
0081   end
0082   sec = ((raVal-hr)*60 - min)*60;
0083   if(sec<10)
0084     secStr = sprintf('0%d', sec);
0085   else
0086     secStr = num2str(sec);
0087   end
0088   ra = sprintf('%s:%s:%s', hrStr, minStr, secStr);
0089 end
0090 
0091 
0092 if(~isempty(strfind(dec, ':')))
0093   if(strfind(dec, '+') | strfind(dec, '-'))
0094     dec = dec(2:length(dec));
0095   end
0096   dec = dec;
0097 else
0098   decVal = str2num(dec);
0099   deg = floor(decVal);
0100   if(deg<10)
0101     degStr = sprintf('0%d', deg);
0102   else
0103     degStr = num2str(deg);
0104   end
0105   min = floor((decVal-deg)*60);
0106   if(min<10)
0107     minStr = sprintf('0%d', min);
0108   else
0109     minStr = num2str(min);
0110   end
0111   sec = ((decVal-deg)*60 - min)*60;
0112   if(sec<10)
0113     secStr = sprintf('0%d', sec);
0114   else
0115     secStr = num2str(sec);
0116   end
0117   dec = sprintf('%s:%s:%s', degStr, minStr, secStr);
0118 end
0119 
0120 
0121 % now we prep the output
0122 raStr = ra;
0123 decStr = dec;
0124 
0125 if(strcmp(raType, 'str'))
0126   ra = raStr;
0127 elseif(strcmp(raType, 'hr'))
0128   [ra decJunk] = str2deg(raStr, decStr);
0129   ra = ra/15;
0130 elseif(strcmp(raType, 'deg'))
0131   [ra decJunk]= str2deg(raStr, decStr);
0132 end
0133 
0134 if(strcmp(decType, 'str'))
0135   dec = decStr;
0136 elseif(strcmp(decType, 'deg'))
0137   [raJunk dec] = str2deg(raStr, decStr);
0138 end
0139 
0140 %change to previous directory
0141 
0142 eval(sprintf('cd %s;', currDir));
0143 
0144 return;
0145 
0146 
0147

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005