⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xptransf.m

📁 GPS TOOLBOX包含以下内容: 1、GPS相关常量和转换因子; 2、角度变换; 3、坐标系转换: &#61656 点变换; &#61656 矩阵变换; &#61656 向量变换
💻 M
字号:
%                             xptransf.m
%  Scope:   This MATLAB program performs the following coordinate transforma-
%           tions:
%           1) from ECEF to Geodetic coordinates
%           2) from Geodetic to ECEF coordinates
%           WGS-84 constants are used.
%  Usage:   xptransf
%  Inputs:  - name of the output file if selected (the default is the screen)
%           - input data from the keyboard as follows:
%           1) For the ECEF to Geodetic transformation:
%              - x-component of the ECEF position, in meters 
%              - y-component of the ECEF position, in meters 
%              - z-component of the ECEF position, in meters 
%              The ECEF coordinates can be entered from keyboard or from a
%              specified file (in this case each row/record contains the
%              x, y, and z components)
%           2) For the Geodetic to ECEF transformation:
%              - latitude, in radians or degrees/minutes/seconds
%              - longitude, in radians or degrees/minutes/seconds 
%              - altitude (above ellipsoid) of the position, in meters 
%              The Geodetic coordinates can be entered from keyboard or from 
%              a specified file (in this case each row/record contains the
%              latitude, longitude and altitude of a specific point) with 3 or
%              7 columns when latitude/longitude is entered in radians or in
%              degrees/minutes/seconds, respectively.
%  Outputs: - input/output data stored into the specified output file or
%              displayed on screen
%  External Matlab macros used:  tadmsrad, taraddms, tecefgd2, tgdecef, 
%                                wgs84con
%  Last update:  08/28/00
%  Copyright (C) 1996-00 by LL Consulting. All Rights Reserved.

clear  

yes = 'y';
answer2 = 'y';

disp('  ');
answer1 = input('Do you want to save the results? (y/n)[n] --> ','s');
if isempty(answer1)
   answer1 = 'n';
end   
disp('  ');
if (strcmp(answer1,yes) == 1)
   f2 = input('Specify the output filename (with extension) -->  ','s');
   disp('  ');
else
   f2 = 1;      %  output to the screen
end

disp('   Select :  1  -->  ECEF to Geodetic Transformation');
disp('             2  -->  Geodetic to ECEF Transformation');
disp('  ');
select = input('Make the selection -->  ');
disp('  ');

if (select == 1)                       % ECEF to Geodetic Transformation

   while (strcmp(answer2,yes) == 1)     

      answer3 = input('Enter data from keyboard? (y/n)[y] --> ','s');
      if isempty(answer3)
         answer3 = yes;
      end   
      disp('  ');
      if (strcmp(answer3,yes) == 1)
         pecef(1,1) = input('Enter ECEF x-component, in meters --> ');   
         pecef(1,2) = input('Enter ECEF y-component, in meters --> ');   
         pecef(1,3) = input('Enter ECEF z-component, in meters --> ');   
         nrow = 1;
         disp('  ');
      else   
         clear tt
         f1 = input('Specify input filename (with extension) --> ','s');
         disp('  ');

%     Read the input data file

         tt = load(f1);
         [nrow,ncol] = size(tt);

         if  ncol ~= 3
            disp('Error - XPTRANSF; check the input data file');
            disp('  ');
            disp('End of the program  XPTRANSF');
            disp('  ');
            return
         end
   
         pecef(:,1) = tt(:,1);
         pecef(:,2) = tt(:,2);
         pecef(:,3) = tt(:,3);

      end

%  Compute Geodetic coordinates

      for k = 1:nrow
         [temp1,temp2,temp3] = tecefgd2(pecef(k,:));
         lat(k) = temp1;
         lon(k) = temp2;
         alt(k) = temp3;
         [adeg,amin,asec] = taraddms(temp1);
         lat_deg(k) = adeg;
         lat_min(k) = amin;
         lat_sec(k) = asec;
         [adeg,amin,asec] = taraddms(temp2);
         lon_deg(k) = adeg;
         lon_min(k) = amin;
         lon_sec(k) = asec;
      end

%  Save the results if the output file is specified or display on screen

      fprintf(f2,'\n**************************************************');
      fprintf(f2,'******************************\n');
      fprintf(f2,'\n*****   ECEF coordinates   *****\n');
      fprintf(f2,'      x - component (m.)    y - component (m.)');
      fprintf(f2,'    z - component (m.) \n');
      for k = 1:nrow
         fprintf(f2,'%20.6f  %20.6f  %20.6f\n',...
                     pecef(k,1),pecef(k,2),pecef(k,3));
      end
      fprintf(f2,'\n*****   Geodetic coordinates   *****\n');
      fprintf(f2,'      latitude              longitude       ');
      fprintf(f2,'      altitude   \n');
      fprintf(f2,'      (radians)             (radians)       ');
      fprintf(f2,'      (meters)   \n');
      for k = 1:nrow
         fprintf(f2,'%18.12f  %18.12f     %18.6f\n',...
                     lat(k),lon(k),alt(k));
      end
      fprintf(f2,'   (deg. min. sec.)       (deg. min. sec.)   ');
      fprintf(f2,'     (meters)   \n');
      for k = 1:nrow
         fprintf(f2,'  %4.0f %3.0f %8.3f    ', lat_deg(k),lat_min(k),lat_sec(k));
         fprintf(f2,'  %4.0f %3.0f %8.3f %18.6f\n', ... 
                 lon_deg(k),lon_min(k),lon_sec(k),alt(k) );
      end
      fprintf(f2,'\n**************************************************');
      fprintf(f2,'******************************\n');

%  Select another computation, if desired

      disp('  ');
      answer2 = input('Do you want another computation? (y/n)[n] --> ','s');
      if isempty(answer2)
         answer2 = 'n';
      end   
      disp('  ');
   end

elseif (select == 2)                   % Geodetic to ECEF Transformation

   while (strcmp(answer2,yes) == 1)

      answer3 = input('Enter data from keyboard? (y/n)[y] --> ','s');
      if isempty(answer3)
         answer3 = yes;
      end   
      disp('  ')
   
      disp('   Select : 1  -->  latitude/longitude in radians');
      disp('            2  -->  latitude/longitude in degrees/minutes/seconds');
      disp('  ');
      select2 = input('Make the selection -->  ');
      disp('  ');

      if (strcmp(answer2,yes) == 1)        %  in radians
         if  (select2 == 1)
            lat(1) = input('Enter latitude, in radians --> ');
            lon(1) = input('Enter longitude, in radians --> ');
         else
           lat_deg = input('Enter latitude (including sign) - degrees --> ');
           lat_min = input('Enter latitude - minutes --> ');
           lat_sec = input('Enter latitude - seconds --> ');
           lon_deg = input('Enter longitude (including sign) - degrees --> ');
           lon_min = input('Enter longitude - minutes --> ');
           lon_sec = input('Enter longitude - seconds --> ');
           lat(1) = tadmsrad(lat_deg,lat_min,lat_sec);
           lon(1) = tadmsrad(lon_deg,lon_min,lon_sec);
         end
         alt(1) = input('Enter altitude above elipsoid, in meters --> ');
         nrow = 1;
         disp('  ');
      else   
         clear tt
         f1 = input('Specify input filename (with extension) --> ','s');
         disp('  ');

%     Read the input data file

         tt = load(f1);
         [nrow,ncol] = size(tt);

         if  (select2 == 1)
            if  ncol ~= 3
               disp('Error - XPTRANSF; check the input data file');
               disp('  ');
               disp('End of the program  XPTRANSF');
               disp('  ');
               return
            end
            lat = tt(:,1);
            lon = tt(:,2);
            alt = tt(:,3);
         else
            if  ncol ~= 7
               disp('Error - XPTRANSF; check the input data file');
               disp('  ');
               disp('End of the program  XPTRANSF');
               disp('  ');
               return
            end
            lat_deg  = tt(:,1);
            lat_min  = tt(:,2);
            lat_sec  = tt(:,3);
            lon_deg  = tt(:,4);
            lon_min  = tt(:,5);
            lon_sec  = tt(:,6);
            alt = tt(:,7);
            for k = 1:nrow
               lat(k) = tadmsrad(lat_deg(k),lat_min(k),lat_sec(k));
               lon(k) = tadmsrad(lon_deg(k),lon_min(k),lon_sec(k));
            end
         end
      end

%  Compute ECEF coordinates

      for k = 1:nrow
         temp = tgdecef(lat(k),lon(k),alt(k));
         pecef(k,:) = temp';
      end

%  Save the results if the output file is specified or display on screen

      fprintf(f2,'\n**************************************************');
      fprintf(f2,'******************************\n');
      fprintf(f2,'\n*****   Geodetic coordinates   *****\n');
      fprintf(f2,'      latitude              longitude       ');
      fprintf(f2,'      altitude   \n');
      if (select2 == 1)
         fprintf(f2,'      (radians)             (radians)       ');
         fprintf(f2,'      (meters)   \n');
      else
         fprintf(f2,'   (deg. min. sec.)       (deg. min. sec.)');
         fprintf(f2,'        (meters)   \n');
      end
      for k = 1:nrow
         if (select2 == 1)
            fprintf(f2,'%18.12f  %18.12f  %18.6f\n',...
                        lat(k),lon(k),alt(k));
         else
            fprintf(f2,'  %4.0f %3.0f %8.3f    ',lat_deg(k),lat_min(k),lat_sec(k));
            fprintf(f2,'  %4.0f %3.0f %8.3f %18.6f\n', ... 
                    lon_deg(k),lon_min(k),lon_sec(k),alt(k) );
         end
      end
      fprintf(f2,'\n*****   ECEF coordinates   *****\n');
      fprintf(f2,'    x - component (m.)    y - component (m.)');
      fprintf(f2,'     z - component (m.) \n');
      for k = 1:nrow
         fprintf(f2,'%20.6f  %20.6f   %18.6f\n',...
                     pecef(k,1),pecef(k,2),pecef(k,3));
      end
      fprintf(f2,'\n**************************************************');
      fprintf(f2,'******************************\n');

%  Select another computation, if desired

      disp('  ');
      answer2 = input('Do you want another computation? (y/n)[n] --> ','s');
      if isempty(answer2)
         answer2 = 'n';
      end   
      disp('  ');

   end

else

   disp('Selection is not in the designated range');

end

disp('End of the program  XPTRANSF');
disp('  ');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -