function num_lines = specobjid2deg(specobjid_filepath, deg_filepath, len_format

49 篇文章 0 订阅
17 篇文章 1 订阅
function num_lines = specobjid2deg(specobjid_filepath, deg_filepath, len_format)
%Author: shizhixin
%Email: szhixin@gmail.com
%Date: Dec 11,2011

%This function can change specobjid which is the form of hh mm ss.s+dd mm ss.s to degree
%ex: SDSSJ110851.04+065901.4 --> A1 167.212667 6.983722
%or  110851.04+065901.4 --> A1 167.212667 6.983722
%We do not care about the characters behind SDSSJ110851.04+065901.4 or 110851.04+065901.4
%so these input strings can also be handled like:
%SDSS110851.04+065901.4 0.1816 0.5 (1.5) 0.9 (2.7) Binary AGNa --> 
%A1 167.212667 6.983722
%or 110851.04+065901.4 0.1816 0.5 (1.5) 0.9 (2.7) Binary AGNa  --> 
%A1 167.212667 6.983722

% call this function:
% num_lines = specobjid2deg('specobjid.txt', 'deg.txt', 23)

%specobjid format like: SDSSJ110851.04+065901.4  or 110851.04+065901.4 
%len_format = 23(SDSSJ110851.04+065901.4) or len_format=18(110851.04+065901.4)
% hh mm ss.s
% dd:mm:ss.s

% specobjid_filepath = 'specobjid.txt';
% deg_filepath = 'deg.txt';
% len_format = 23;

if len_format == 23  %specobjid format like: SDSSJ000249.07+004504.8
    pos_start = 6;
elseif len_format == 18 %specobjid format like: 000249.07+004504.8
    pos_start = 1;
 else
    disp('read_len input error, it must be 23 or 18');
    return
end
        
fid = fopen(specobjid_filepath,'r');
if fid == -1
    disp('fopen cannot open the file');
    fclose(fid);
    return;
end


% name ra dec
% A1 167.212667 6.983722
fid_deg = fopen(deg_filepath,'wt');
fprintf(fid_deg,'%s %s %s\n','name','ra','dec');

num_lines=0;
read_line = fgetl(fid)

while (read_line)~=-1
    read_line = read_line(1:len_format)
    num_lines = num_lines+1;
    pos = pos_start;
    hh = str2num(read_line(pos:pos+1));
    pos = pos+2;
    mm = str2num(read_line(pos:pos+1));
    pos = pos+2;
    ss = str2num(read_line(pos:pos+4));
    pos = pos+5;
    
    if read_line(pos)== '-'
        d_sign = -1;
    else
        d_sign = 1;
    end
    pos = pos+1;
    dd = str2num(read_line(pos:pos+1));
    pos = pos+2;
    d_mm = str2num(read_line(pos:pos+1));
    pos = pos+2;
    d_ss = str2num(read_line(pos:pos+3));
 
    ra = (hh + mm/60 + ss/3600)*15;
    dec = (dd + d_mm/60 + d_ss/3600)*d_sign;
    
    fprintf(fid_deg,'A%d %f %f\n',num_lines,ra,dec);
    read_line = fgets(fid)
    
end

fclose(fid);
fclose(fid_deg);
end %function specobjid2deg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值