accosin.m

来自「zemax与matlab调用程序」· M 代码 · 共 869 行 · 第 1/4 页

M
869
字号
function Status = ACCOSin(varargin)
% ACCOSin - Read an ACCOS .len file into ZEMAX.
%
% Usage : Status = ACCOSin
%
% The following return values are possible
%
%  0 : Success
% -1 : User Canceled operation or file not found
%
% If there are multiple .len files seperated with 'LIB PUT' commands as for a library dump, then
% each lens is saved as a .zmx file, and given the name in the lens idendification line of the input.
% In this case, ACCOSin will ask for the directory in which to store the library dump.

% MZDDE - The ZEMAX DDE Toolbox for Matlab.
% Copyright (C) 2002-2004 Defencetek, CSIR
% Contact : dgriffith@csir.co.za
% 
% This file is part of MZDDE.
% 
%  MZDDE is free software; you can redistribute it and/or modify
%  it under the terms of the GNU General Public License as published by
%  the Free Software Foundation; either version 2 of the License, or
%  (at your option) any later version.
%
%  MZDDE is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%  GNU General Public License for more details.
%
%  You should have received a copy of the GNU General Public License
%  along with MZDDE (COPYING.html); if not, write to the Free Software
%  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
%

% $Revision: 1.7 $

% Still to implement and fix
% --------------------------
% Plain SCY (not FANG) in multi-config.
% CVX, RDX etc - all cylindrical components.
% COCY and other solves.
% Investigate why so many YD pikups are being ignored. Seems to be for good reason ie. target of
% pikup has no tilts or decenters, therefore safe to ignore.
% Create log file with copy of narrative. Include surface numbers for both ACCOS and ZEMAX files.
% Look at FNBY, FNBX

Revision = '$Revision: 1.7 $';
RevDate = '$Date: 2005-04-22 09:36:02+02 $';
Revision = Revision(11:(size(Revision,2)-1));
RevDate = RevDate(7:(size(RevDate,2)-1));
disp(['ACCOS Leno Importer for ZEMAX. Version' Revision]);
disp(['Derek Griffith,' RevDate]);

Status = zDDEInit;
if (Status)
    uiwait(msgbox('ZEMAX is not Running.', 'ZEMAX Error', 'error', 'modal'));
    return;
end;

oldPWD = PWD;
DefaultDir = 'c:\popdist';
if (~exist(DefaultDir, 'dir')), DefaultDir = 'c:\'; end;


ACCDir = getenv('ACCOS');
if (strcmp(ACCDir, '')), ACCDir = DefaultDir; end;
cd(ACCDir);

zWindowMinimize(0);
FilterSpec = {'cpfile', 'ACCOS CPFILE'; '*.len;*.leno', 'ACCOS Leno Files'; '*.*', 'All Files' }; 
[iFile, iPath] = uigetfile(FilterSpec, 'Open ACCOS File');
if (iFile) % Seem to have a file to read ACCOS input from
    Status = ReadACCOSFile(fullfile(iPath, iFile));    
else
    Status = -1; zddeclose; cd(oldPWD); return;
end

cd(oldPWD);


function Status = ReadACCOSFile(Filename)
% Read in the ACCOS LEN File
global ACCOSMaterials ZEMAXMaterials
LibDumpPath = '';
% Here are the known ACCOS materials
ACCOSMaterials = {...
'GERM','ARTRI','SILICN','SAPHIR','BAF','SILICA','IRT2','IRT4',...
'CAFL','NAF','LIF','NACL','KI','KCL','KBR','AMTIR1',...
'RZNSE','RZNS','WAT20C','IRT1','PBF2','CDF2','GAAS','ZNS',...
'ZNSE','CDTE','SCGERM','MGF2','KRS-5','LIFX','KBRX','KCLX',...
'KIX','NACLX','CALX-O','CALX-E','CSBRX','CSIX','IRGN6X','IRG11X',...
'MGFX-O','MGFX-E','KDPX-O','KDPX-E','AGCLX','STRTIX','KRS5X','IRGN6X',...
'IRG11X','QRZX-O','QRZX-E','MGALO'...
'SF56', 'LAF21', 'LASF30', 'KZFSN7', 'SF56', 'KZSF4', 'LAF11', 'F11'...
}';

% and the best known equivalent ZEMAX materials
% There may still be errors in this list
ZEMAXMaterials = {...
'GERMANIUM','ARTRI','SILICON','SAPPHIRE','BAF','F_SILICA','IRT2','IRT4',...
'CAF2','NAF','LIF','NACL','KI','KCL','KBR','AMTIR1',...
'ZNSE','CLEARTRAN','WATER','IRT1','PBF2','CDF2','GAAS','ZNS_BROAD',...
'ZNSE','CDTE','SCGERM','MGF2','KRS5','LIF','KBR','KCL',...
'KI','NACL','CALCITE','CALCITE-E','CSBR','CSI','IRGN6','IRG11',...
'MGF2','MGF2-E','KDP','KDP-E','AGCL','STRTI','KRS5','IRGN6',...
'IRG11','QUARTZ','QUARTZ-E','MGALO'...
'N-SF56', 'LAFN21', 'LASFN30', 'KZFS7A', 'SF56A', 'KZFSN4', 'LAFN11', 'FN11'...
}';

UnknownDirectives = {};
UnknownPikups = {};
Status = 0;
UseCoordBreaks = 1;  % Will use ZEMAX Coordinate break surfaces for tilts and decentres if this is set, otherwise surface tilts and decenters are used
                     % Note that pikups of surface tilts and decenters are only honoured if this
                     % flag is set.

fID = fopen(Filename, 'rt');
% Now process the entire contents of the file
while 1
    LenLine = fgetl(fID);
    if ~ischar(LenLine), break, end; % End of file
    LenLine = upper(LenLine); % Convert to upper case
    [Directive, Rest] = strtok(LenLine, ' ,'); % Take the directive from the start of the line
    if (Directive)
    switch Directive
      case 'LENS', zNewLens; Title = Rest(2:size(Rest,2)); % Great, but currently no way to change the lens title in the DDE server !
                   ZEMAXSurface = 0; ACCOSSurface = 0;     % Maintain two pointers, because coordinate breaks will cause a mismatch
                   XObjectAngle = 0; YObjectAngle = 0; XObjectHeight = 0; YObjectHeight = 0;
                   Wavelengths = [0.5876; 0.48613; 0.65627; 0.43584; 0.70653]; NumWaves = 5;
                   WaveWeights = [1.0   ; 1.0    ; 1.0    ; 1.0    ; 1.0    ]; FieldType = 0;
                   zSetWaveMatrix([Wavelengths WaveWeights]); LensComments = {}; NumberComments = 0; LITitle = '';
                   StopSurface = 0; Fixups.Comments = {}; Fixups.ModelGlasses = {}; Fixups.NumberConfigs = 1;
                   Fixups.ConfigData = {}; Fixups.ConfigOperands = 0; TiltDec = zeros(1,7); Fixups.TiltDecBefore = {}; Fixups.TiltDecAfter = {};
                   zSetLabel(1,9999); zSetLabel(2,10000);   % Label these surfaces high for later fixup
      case 'LI',   LITitle = LenLine(4:size(LenLine,2));         % Same dilemma
                   disp(['Reading :' LITitle]); Fixups.Title = deblank(fliplr(deblank(fliplr(LITitle))));
      case 'LIC',  NumberComments = NumberComments + 1; LensComments{NumberComments} = Rest(2:size(Rest,2));
                   Fixups.Comments{NumberComments} = deblank(fliplr(deblank(fliplr(LensComments{NumberComments}))));
      case 'C',    Comment = LenLine(2:size(LenLine,2));
                   [Token, Rest] = strtok(Rest, ' ,');
                   switch Token
                       case 'SURFACE', CheckACCOSSurface = str2num(strtok(Rest, ' ,'));
                       otherwise,
                   end;
      case 'SAY', Token = strtok(Rest, ' ,'); PupilRadius = str2double(Token); zSetSystemAper(0, 1, 2*PupilRadius);
      case 'SCY', [Token, Rest] = strtok(Rest, ' ,'); 
                  if (strcmp(Token, 'FANG'))
                      [Token, Rest] = strtok(Rest, ' ,'); YObjectAngle = str2double(Token); YObjectHeight = 0.0; FieldType = 0;
                  else
                      YObjectHeight = str2double(Token); YObjectAngle = 0.0; FieldType = 1;
                  end;
      case 'SCX', [Token, Rest] = strtok(Rest, ' ,'); 
                  if (strcmp(Token, 'FANG'))
                      [Token, Rest] = strtok(Rest, ' ,'); XObjectAngle = str2double(Token); XObjectHeight = 0.0; FieldType = 0;
                  else
                      XObjectHeight = str2double(Token); XObjectAngle = 0.0; FieldType = 1;
                  end;
      case 'RD', Token = strtok(Rest, ' ,'); Radius = str2double(Token); if (Radius ~= 0), zSetSurfaceData(ZEMAXSurface, 2, 1/Radius); end;
      case 'CV', Token = strtok(Rest, ' ,'); if (Token), Curv = str2double(Token); else Curv = 0.0; end; zSetSurfaceData(ZEMAXSurface, 2, Curv);
      case 'APY',zSetSolve(ZEMAXSurface, 0, 7); % Aplanatic Solve
      case 'COCY',Token = strtok(Rest, ' ,');   % Concentric with surface solve - will only work with prior target surfaces.
                  if (Token), ConSurf =  str2num(Token); ConSurf = zFindLabel(ConSurf); 
                      if (ConSurf ~= -1), zSetSolve(ZEMAXSurface, 0, 9);
                      else disp(['COCY Solve Ignored at Surface ' num2str(ACCOSSurface)]);
                      end;
                  end;
      case 'CC', Token = strtok(Rest, ' ,'); if (Token), Conic = str2double(Token); else Conic = 0.0; end; zSetSurfaceData(ZEMAXSurface, 6, Conic);
      case 'ASPH', [Token, Rest] = strtok(Rest, ' ,'); 
                   if (Token)
                     switch (Token) 
                       case 'RSIRS', disp(['Rotationally Symmetric Spline Surface Definition Ignored at Surface ' num2str(ACCOSSurface)]);
                       case 'IRS'  , disp(['Asymmetric Spline Surface Definition Ignored at Surface ' num2str(ACCOSSurface)]);
                       otherwise   , if (Token), Ad = str2double(Token); else Ad = 0.0; end;
                                     [Token, Rest] = strtok(Rest, ' ,'); if (Token), Ae = str2double(Token); else Ae = 0.0; end;
                                     [Token, Rest] = strtok(Rest, ' ,'); if (Token), Af = str2double(Token); else Af = 0.0; end;
                                     [Token, Rest] = strtok(Rest, ' ,'); if (Token), Ag = str2double(Token); else Ag = 0.0; end;
                                     zSetSurfaceData(ZEMAXSurface, 0, 'EVENASPH'); zSetSurfaceParamVector(ZEMAXSurface, [0, 0, Ad, Ae, Af, Ag]);
                     end;
                   end;
      case 'AD', Token = strtok(Rest, ' ,'); if (Token), Ad = str2Double(Token); else Ad = 0.0; end; 
                 zSetSurfaceData(ZEMAXSurface, 0, 'EVENASPH'); zSetSurfaceParameter(ZEMAXSurface, 2, Ad);
      case 'AE', Token = strtok(Rest, ' ,'); if (Token), Ae = str2Double(Token); else Ae = 0.0; end; 
                 zSetSurfaceData(ZEMAXSurface, 0, 'EVENASPH'); zSetSurfaceParameter(ZEMAXSurface, 3, Ae);
      case 'AF', Token = strtok(Rest, ' ,'); if (Token), Af = str2Double(Token); else Af = 0.0; end; 
                 zSetSurfaceData(ZEMAXSurface, 0, 'EVENASPH'); zSetSurfaceParameter(ZEMAXSurface, 4, Af);
      case 'AG', Token = strtok(Rest, ' ,'); if (Token), Ag = str2Double(Token); else Ag = 0.0; end; 
                 zSetSurfaceData(ZEMAXSurface, 0, 'EVENASPH'); zSetSurfaceParameter(ZEMAXSurface, 5, Ag);
      case 'TH', Token = strtok(Rest, ' ,'); if (Token), Thick = str2Double(Token); else Thick = 0.0; end; zSetSurfaceData(ZEMAXSurface, 3, Thick);
                 if (ZEMAXSurface == 0) % Set the field angles depending on whether object distance is 'infinity'
                     if (Thick >= 1e10)
                       if (FieldType == 1), YObjectAngle = 360.0 * atan(YObjectHeight / Thick) / 6.283185308; FieldType = 0;
                                            XObjectAngle = 360.0 * atan(XObjectHeight / Thick) / 6.283185308; end;    
                     end;
                     switch (FieldType)
                         case 0, FieldPoints = [0, 0, 1; XObjectAngle, YObjectAngle, 1]; zSetFieldMatrix(0, FieldPoints);
                         case 1, FieldPoints = [0, 0, 1; XObjectHeight, YObjectHeight, 1]; zSetFieldMatrix(1, FieldPoints);
                     end;
                 end;
      case 'CLAP',   [Type, Rest] = strtok(Rest, ' ,'); [Token, Rest] = strtok(Rest, ' ,');  % Get all the numerical parameters of the command
                     Parms = [0 0 0 0 0];
                     ParmCount = 0; while (Token), ParmCount = ParmCount + 1; Parms(ParmCount) = str2double(Token); [Token, Rest] = strtok(Rest, ' ,'); end;
                     switch Type
                         case 'RECT', zSetAperture(ZEMAXSurface, 4, Parms(2), Parms(1), Parms(4), Parms(3), '');
                         case 'ELIP', zSetAperture(ZEMAXSurface, 6, Parms(2), Parms(1), Parms(4), Parms(3), '');
                         otherwise  , Aper = zGetAperture(ZEMAXSurface); if (Aper(1)==1), COBSRadius = Aper(2); else COBSRadius = 0; end;
                                      CLAPRadius = str2double(Type); zSetAperture(ZEMAXSurface, 1, COBSRadius, CLAPRadius, Parms(3), Parms(2), '');
                     end;
      case 'COBS',   [Type, Rest] = strtok(Rest, ' ,'); [Token, Rest] = strtok(Rest, ' ,');  % Get all the numerical parameters of the command
                     Parms = [0 0 0 0 0];
                     ParmCount = 0; while (Token), ParmCount = ParmCount + 1; Parms(ParmCount) = str2double(Token); [Token, Rest] = strtok(Rest, ' ,'); end;
                     switch Type
                         case 'RECT', zSetAperture(ZEMAXSurface, 5, Parms(2), Parms(1), Parms(4), Parms(3), '');
                         case 'ELIP', zSetAperture(ZEMAXSurface, 7, Parms(2), Parms(1), Parms(4), Parms(3), '');
                         otherwise  , Aper = zGetAperture(ZEMAXSurface); if (Aper(1)==1), CLAPRadius = Aper(3); else CLAPRadius = 10000; end;
                                      COBSRadius = str2double(Type); zSetAperture(ZEMAXSurface, 1, COBSRadius, CLAPRadius, Parms(3), Parms(2), '');
                     end;
      case 'AIR',    [ZEMAXSurface, ACCOSSurface] = NewSurface(ZEMAXSurface, ACCOSSurface); TiltDec = zeros(1,7);

⌨️ 快捷键说明

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