CODE V的API 之 ThirdAberration(初级像差的获取)数据的获取(4)

像差的变化数据提取



前言

在优化过程中,相差的观察非常重要,尤其是镜片变多以后哪一面的曲率,厚度以及非球面系数的变化对像差的影响需要总结,提炼以便后续更好的优化,此数据提出非常重要。

一、主要目标

将三级像差输出至相应的单元格。

二、主要代码

1.VBA代码

代码如下(示例):

Sub getTHirdabrr()

'定义接口
Dim Session As CVCommand

'102是CODEV的版本,即10.2
Set Session = CreateObject("CodeV.Command.102")
'设置打开文件的初始位置
Session.SetStartingDirectory ("c:\CVUSER")
Session.StartCodeV
'载入(dbgauss.lens),在命令处输入res cv_lens:dbgauss
result = Session.Command("res cv_lens:dbgauss;")

'提取三级像差至 abr.txt文件
result = Session.Command("in cv_macro:forder;")
result = Session.Command("buf del ba;buf yes;in cv_macro:thirdabrget 1 0 1;buf mov b1;buf cop b0 I3..14 J2..7;buf exp abr.txt;go")

 '转化字符为数据
Dim s As String
 i = 1
Open "C:\CVUSER\abr.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, s

        str_txt = Split(s, vbTab)
        For j = 0 To UBound(str_txt)
             str_num = CDbl(str_txt(j))
           Worksheets("Sheet1").Range(Cells(i, j + 1), Cells(i, j + 1)) = str_num
        Next j
i = i + 1
Loop
Close #1
 
'关闭CODEV实例
Session.StopCodeV
Set Session = Nothing

End Sub

2.CODE V macro

需要自定义一个宏

!**************************************************************************
! Sequence:     THIRDABRGET
!
! Purpose:      Prints a table for surface range i to j of third order
!               aberrations
!
!               This macro can be called stand-alone, but is intended to be
!               called by FORDER.
!
! Syntax:       in THIRDABRGET [start_surf [end_surf [zoom_pos]]]
!
! Inputs:       start_surf  - first surface of surface range (if -1,
!                             computes sums at image surface)
!               end_surf    - ending surface of surface range (if -1,
!                             only computes contributions for one surface;
!                             if 0, computes to image surface)
!               zoom_pos    - zoom position (default 1)
!               list_opd    - list OPDs (default: N)
!               list_pup    - list pupil aberrations (default: N)
!
! Notes:        Assumes FIFTHDEF has been run first.
!               Examples of usage are as follows:
!                 in THIRDABRGET 1 3    ! print contributions for surfaces 1 to 3
!                 in THIRDABRGET 5 0    ! print contributions from surface 5 to image
!                 in THIRDABRGET 5      ! print contributions for surface 5 only
!                 in THIRDABRGET        ! print totals only
!                 in THIRDABRGET 0 0 0 Y! print wave aberrations
!                 in THIRDABRGET 0 0 0 N Y! print transverse pupil aberrations
!
! Author:       YS       Date: 2024-02-08
!

!**************************************************************************
! ARG0 "Prints out a table of third and fifth order aberrations. Output"
! ARG0 "can be surface contributions for specified surfaces, or can "
! ARG0 "include aberration sums at the image (default)."
!
! ARG1 NAME     "Start surface"
! ARG1 TYPE     lit
! ARG1 DEFAULT  -1
! ARG1 HELP     "Starting surface (negative 1 gives sums at image only)"
!
! ARG2 NAME     "Ending surface"
! ARG2 TYPE     lit
! ARG2 DEFAULT  -1
! ARG2 HELP     "Ending surface (negative = starting surface only; 0 = image surface)"
!
! ARG3 NAME     "Zoom position"
! ARG3 TYPE     lit
! ARG3 DEFAULT  1
! ARG3 HELP     "Zoom position (default 1)"

! ARG4 NAME     "List wave aberrations"
! ARG4 TYPE     STR
! ARG4 DEFAULT  "N"
! ARG4 HELP     "List wave aberrations"

! ARG5 NAME     "List pupil aberrations"
! ARG5 TYPE     STR
! ARG5 DEFAULT  "N"
! ARG5 HELP     "List pupil aberrations"
!**************************************************************************

rfd -1 -1 1 N N

lcl num ^junk ^surface ^surface1 ^surface2 ^z
lcl num ^dum ^ref_wl

lcl str ^format2 ^format3 ^format4 ^format5 ^format6
lcl str ^format2w ^format3w ^format4w ^format5w ^format6w
lcl str ^errorMessage
lcl str ^tempString1
lcl str ^tempString2
lcl str ^tempString3
lcl str ^aber_type ^list_opd ^list_pup

ver n
^format2 == "STO'4d.6d''4d.6d''4d.6d''4d.6d''4d.6d''4d.6d'"
^format3 == "'3d''4d.6d''4d.6d''4d.6d''4d.6d''4d.6d''4d.6d'"
^format4 == "SUM'4d.6d''4d.6d''4d.6d''4d.6d''4d.6d''4d.6d'"
^format5 == "   '4d.6d''4d.6d''4d.6d''4d.6d''4d.6d''4d.6d'"
^format6 == "   '4d.6d''4d.6d''4d.6d''4d.6d'"
^format2w == "STO'6d.4d''6d.4d''6d.4d''6d.4d''6d.4d'"
^format3w == "'3d''6d.4d''6d.4d''6d.4d''6d.4d''6d.4d'"
^format4w == "SUM'6d.4d''6d.4d''6d.4d''6d.4d''6d.4d'"
^format5w == "   '6d.4d''6d.4d''6d.4d''6d.4d''6d.4d'"
^format6w == "   '6d.4d''6d.4d''6d.4d''6d.4d''6d.4d'"

^surface1 == str_to_num(rfstr(1))

^surface2 == str_to_num(rfstr(2))

^z == str_to_num(rfstr(3))
^z == roundf(absf(^z))

^list_opd == upcase(rfstr(4))
if ^list_opd <> "Y"
  ^list_opd == "N"
end if
^aber_type == upcase(rfstr(5))
if ^aber_type <> "Y"
  ^aber_type == "IMAGE"
else
  ^aber_type == "PUPIL"
end if

if (num z) > 1
  if (^z < 1) or ^z > (num z)
    ^tempString1 == 'The specified zoom position, '
    ^tempString2 == NUM_TO_STR(^z)
    ^tempString3 == CONCAT(^tempString1,^tempString2)
    ^tempString1 == ', is not a valid input.'
    ^errorMessage == CONCAT(^tempString3,^tempString1)
    ^dum == cverror(^errorMessage,0)
    rtn
  end if
end if

if ^surface1 = -1
  ^surface1 == (FOC z^z)
else
  if ^surface1 = 0
    ^surface1 == 1
  else if ^surface1 > (FOC z^z)
    ^tempString1 == 'The specified starting surface, '
    ^tempString2 == NUM_TO_STR(^surface1)
    ^tempString3 == CONCAT(^tempString1,^tempString2)
    ^tempString1 == ', is not a valid input.'
    ^errorMessage == CONCAT(^tempString3,^tempString1)
    ^dum == cverror(^errorMessage,0)
    rtn
  end if
end if

if ^surface2 = -1
  ^surface2 == ^surface1
else if ^surface2 = 0
  ^surface2 == (FOC z^z)
else
  if ^surface2 < ^surface1
    ^surface2 == ^surface1
  else if ^surface2 > (FOC z^z)
    ^tempString1 == 'The specified ending surface, '
    ^tempString2 == NUM_TO_STR(^surface2)
    ^tempString3 == CONCAT(^tempString1,^tempString2)
    ^tempString1 == ', is not a valid input.'
    ^errorMessage == CONCAT(^tempString3,^tempString1)
    ^dum == cverror(^errorMessage,0)
    rtn
  end if
end if

! When ^surface is 0, the variables are initialized, when ^surface is (NUM S)
! the final sums are converted to aberrations, otherwise the surface
! contributions are calculated.

! This is to force a warning message for a zero last field
^dummy == (hcy si)

for ^surface 0 ^surface2
  out n
  ^junk == @FORDER(^surface,^z, ^aber_type)  ! Evaluate aberrations (dummy variable)
  out

! Output aberrations

  if ^list_opd = "N"

   if ^surface = 0

!       Get units
    if (dim) = "I"
      ^tempString1 == "inches"
    else if (dim) = "C"
      ^tempString1 == "centimeters"
    else if (dim) = "M"
      ^tempString1 == "millimeters"
    end if
    if (afc z^z) <> 0
      if (adm) = 'RAD'
        ^tempString1 == "radians"
      else if (adm) = 'MR'
        ^tempString1 == "milliradians"
      else if (adm) = 'UR'
        ^tempString1 == "microradians"
      else if (adm) = 'NR'
        ^tempString1 == "nanoradians"
      else if (adm) = 'DEG'
        ^tempString1 == "degrees"
      else if (adm) = 'MIN'
        ^tempString1 == "minutes"
      else if (adm) = 'SEC'
        ^tempString1 == "seconds"
      end if
    end if

    if ^aber_type = "IMAGE"
      ^tempString2 == CONCAT(CONCAT("THIRD AND FIFTH ORDER IMAGE ABERRATIONS (", ^tempString1), ")")
      !wri
      !wri "              " ^tempString2
      !wri
      !wri "         SA3        TCO        TAS        SAG        PTZ        DST"
      !wri "         SA5        TCO5       TAS5       SAG5       PTZ5       DST5"
      !wri "         SA7        ECOM       OTSA       OSSA"
    else
      ^tempString2 == CONCAT(CONCAT("THIRD AND FIFTH ORDER PUPIL ABERRATIONS (", ^tempString1), ")")
      !wri
      !wri "              " ^tempString2
      !wri
      !wri "         SA3P       TCOP       TASP       SAGP       PTZP       DSTP"
      !wri "         SA5P       TCO5P      TAS5P      SAG5P      PTZ5P      DST5P"
      !wri "         SA7P       ECOMP      OTSAP      OSSAP"
    end if

    !wri

   els if ^surface <= ^surface2 AND ^surface >= ^surface1
    if ^surface = (STO z^z)
      if ^aber_type = "IMAGE"
        write q^format2 ^SA3 ^TCO ^TAS ^SAG ^PTZ ^DST
        !write  q^format2 ^SA3 ^TCO ^TAS ^SAG ^PTZ ^DST
      else
        !write q^format2 ^SA3P ^TCOP ^TASP ^SAGP ^PTZP ^DSTP
      end if
    els if ^surface = (FOC z^z)
      !write
      if ^aber_type = "IMAGE"
        write q^format4 ^SA3 ^TCO ^TAS ^SAG ^PTZ ^DST
        !write  q^format4 ^SA3 ^TCO ^TAS ^SAG ^PTZ ^DST
      else
        !write q^format4 ^SA3P ^TCOP ^TASP ^SAGP ^PTZP ^DSTP
      end if
    els
      if ^aber_type = "IMAGE"
        write q^format3 ^surface ^SA3 ^TCO ^TAS ^SAG ^PTZ ^DST
        !write  q^format3 ^SA3 ^TCO ^TAS ^SAG ^PTZ ^DST
      else
        !write q^format3 ^surface ^SA3P ^TCOP ^TASP ^SAGP ^PTZP ^DSTP
      end if
    end if
    if ^aber_type = "IMAGE"
      !write q^format5 ^SA5 ^TCO5 ^TAS5 ^SAG5 ^PTZ5 ^DST5
      !write q^format6 ^SA7 ^ECOM ^OTSA ^OSSA
    else
      !write q^format5 ^SA5P ^TCO5P ^TAS5P ^SAG5P ^PTZ5P ^DST5P
      !write q^format6 ^SA7P ^ECOMP ^OTSAP ^OSSAP
    end if
    !write

   end if

  else

   if ^surface = 0

   ^ref_wl == (ref)

   ! wri
    if ^aber_type = "IMAGE"
      !wri q" '60c' '6d.4d' '4c'"  "           THIRD AND FIFTH ORDER IMAGE ABERRATIONS (Waves at " (wl w^ref_wl) "nm.)"
      !wri
      !wri "         W040       W131       W220       W222       W311"
      !wri "         W060       W151       W420       W422       W511"
      !wri "         W080       W331       W333       W240       W242"
    else
      !wri q" '60c' '6d.4d' '4c'"  "           THIRD AND FIFTH ORDER PUPIL ABERRATIONS (Waves at " (wl w^ref_wl) "nm.)"
     ! wri
      !wri "         W040P      W131P      W220P      W222P      W311P"
      !wri "         W060P      W151P      W420P      W422P      W511P"
      !wri "         W080P      W331P      W333P      W240P      W242P"
    end if
    !wri

   els if ^surface <= ^surface2 AND ^surface >= ^surface1
    if ^surface = (STO z^z)
      if ^aber_type = "IMAGE"
        !write q^format2w ^W040 ^W131 ^W220 ^W222 ^W311
      else
        !write q^format2w ^W040P ^W131P ^W220P ^W222P ^W311P
      end if
    els if ^surface = (FOC z^z)
      write
      if ^aber_type = "IMAGE"
        !write q^format4w ^W040 ^W131 ^W220 ^W222 ^W311
      else
        !write q^format4w ^W040P ^W131P ^W220P ^W222P ^W311P
      end if
    els
      if ^aber_type = "IMAGE"
        !write q^format3w ^surface ^W040 ^W131 ^W220 ^W222 ^W311
      else
        !write q^format3w ^surface ^W040P ^W131P ^W220P ^W222P ^W311P
      end if
    end if
    if ^aber_type = "IMAGE"
      !write q^format5w ^W060 ^W151 ^W420 ^W422 ^W511
      !write q^format6w ^W080 ^W331 ^W333 ^W240 ^W242
    else
      !write q^format5w ^W060P ^W151P ^W420P ^W422P ^W511P
      !write q^format6w ^W080P ^W331P ^W333P ^W240P ^W242P
    end if
    !write

   end if

  end if

end for
ver y


输出结果

code的输出
在这里插入图片描述
VBA输出

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值