0

我尝试用我的代码解决这个问题。当我编译时,我有以下错误消息:

% POINCARE: Ambiguous: POINCARE: Function not found: XT  or: POINCARE: Scalar subscript out of range [>].e
% Execution halted at: POINCARE            38 poincare.pro
%                      $MAIN$          

这很简单:

1)我打开文件并计算行数和列数,2)将文件保存在 ROWSxCOLUMNS 矩阵中,3)获取我想要的行并将它们保存为向量,

现在我想修改列如下:

A) 将第一列和第二列 (x 和 y) 的每个元素转换为常数因子 ( xc, yc....) B) 对这两个新列 ( xn, yn...) 的每个新元素进行一些操作 C) 如果值pyn大于 0。然后保存具有 , 的四个值的xnpxn

这里的代码:

pro poincare

file = "orbitm.txt"
rows =File_Lines(file) ; per le righe
openr,lun,file,/Get_lun ; per le colonne
line=""
readf,lun,line
cols = n_elements(StrSplit(line, /RegEx, /extract))

openr,1,"orbitm.txt" 
 data = dblarr(cols,rows)
 readf,1,data
close,1

x = data(0,*) ; colonne e righe
y = data(1,*)
px = data(2,*)
py = data(3,*)

mu =0.001

xc = 0.5-mu
yc = 0.5*sqrt(3.)

openw,3,"section.txt"

 for i=1, rows-2 do begin


   xt = x(i)-xc
   yt = y(i)-yc
   pxt = px(i)-yc
   pyt = py(i)+xc

  tau = y(i)/(y(i)-y(i+1))


  xn = xt(i) + (xt(i+1)-xt(i))*tau

  yn = yt(i) + (yt(i+1)-yt(i))*tau

  pxn = pxt(i) + (pxt(i+1)-pxt(i))*tau

  pyn = pyt(i) + (pyt(i+1)-pyt(i))*tau

   if (pyt(i) GT 0.) then begin
    printf,3, xt(i), pxt(i)
   endif
 endfor 
close,3


end

我还附上了我的输入 orbitm.txt 的第一行:

 0.73634     0.66957     0.66062    -0.73503    
 0.86769     0.54316     0.51413    -0.82823    
 0.82106     0.66553     0.60353    -0.74436    
 0.59526     0.88356     0.79569    -0.52813    
 0.28631      1.0193     0.92796    -0.24641    
-0.29229E-02  1.0458     0.96862     0.21874E-01
-0.21583      1.0090     0.95142     0.22650    
-0.33994     0.96091     0.92099     0.35144    
-0.38121     0.93413     0.90831     0.39745    
-0.34462     0.93959     0.92534     0.36561    
-0.22744     0.96833     0.96431     0.25054    
-0.24560E-01 0.99010     0.99480     0.45173E-01
 0.25324     0.95506     0.96459    -0.24000    
 0.55393     0.81943     0.82584    -0.54830    
 0.78756     0.61644     0.61023    -0.77367    
 0.88695     0.53076     0.50350    -0.82814    
4

1 回答 1

1

我可以看到一些显而易见的问题。首先是在 FOR 循环中将变量 XT、YT、PXT 和 PYT 定义为标量。不久之后,您尝试对它们进行索引,就好像它们是具有多个元素的数组一样。要么您对这些变量的定义需要更改,要么您需要更改您对 XN、YN、PXN 和 PYN 的定义。否则,这将无法按书面方式工作。我附上了您的代码的修改版本,其中包含一些建议和评论。

pro poincare

file = "orbitm.txt"
rows =File_Lines(file) ; per le righe
openr,lun,file,/Get_lun ; per le colonne
line=""
readf,lun,line
cols = n_elements(StrSplit(line, /RegEx, /extract))
free_lun,lun  ;; need to close this LUN

;; define data array
data = dblarr(cols,rows)
;;openr,1,"orbitm.txt" 
;;readf,1,data
;; data = dblarr(cols,rows)
;;close,1
openr,lun,"orbitm.txt",/get_lun
 readf,lun,data
free_lun,lun  ;; close this LUN

;;x = data(0,*) ; colonne e righe
;;y = data(1,*)
;;px = data(2,*)
;;py = data(3,*)
x  = data[0,*]  ;;  use []'s instead of ()'s in IDL
y  = data[1,*]
px = data[2,*]
py = data[3,*]
mu = 0.001
xc = 0.5 - mu       ;;  currently a scalar
yc = 0.5*sqrt(3.)   ;;  currently a scalar
;;  Perhaps you want to define XT, YT, PXT, and PYT as:
;;    xt  =  x - xc[0]
;;    yt  =  y - yc[0]
;;    pxt = px - yc[0]
;;    pyt = py + xc[0]
;;  Then you could index these inside the FOR loop and
;;  remove their definitions therein.

;;openw,3,"section.txt"
openw,lun,"section.txt",/get_lun
  for i=1L, rows[0] - 2L do begin
    xt  =   x[i] - xc   ;;  currently a scalar
    yt  =   y[i] - yc   ;;  currently a scalar
    pxt =  px[i] - yc   ;;  currently a scalar
    pyt =  py[i] + xc   ;;  currently a scalar
    tau =   y[i]/(y[i] - y[i+1])   ;;  currently a scalar
    ;;  In the following you are trying to index XT, YT, PXT, and PYT but
    ;;    each are scalars, not arrays!
    xn  =  xt[i] + (xt[i+1] - xt[i])*tau
    yn  =  yt[i] + (yt[i+1] - yt[i])*tau
    pxn = pxt[i] + (pxt[i+1] - pxt[i])*tau
    pyn = pyt[i] + (pyt[i+1] - pyt[i])*tau
    if (pyt[i] GT 0.) then begin
      printf,lun, xt[i], pxt[i]
    endif
  endfor 
free_lun,lun  ;; close this LUN
;;close,3

;;  Return
return
end

一般 IDL 注释: 您应该使用 [] 而不是 () 来索引数组以避免与函数混淆。通常让 IDL 定义一个逻辑单元号 (LUN) 然后释放 LUN 比使用 更好CLOSE

于 2014-09-26T15:31:09.187 回答