在Scheme语言中,如何在与外部do循环连接的内部do循环中分配变量计数器? [英] In Scheme language, how to assign a variable counter in an inner do-loop connected with the outer do-loop?

查看:127
本文介绍了在Scheme语言中,如何在与外部do循环连接的内部do循环中分配变量计数器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Ansys Fluent中读取10个案例文件,每个案例文件有10个数据文件要读取. Ansys Fluent使用Scheme编程语言. 我必须设法在此处的代码(用Scheme语言评估浮点变量)中获得一些针对个别问题的答案,并且这里 (如何在Scheme语言中的do-loop中增加计数器?),但是在收集单个答案时,我意识到我需要用于计数器的新代码,该代码用于通过do循环读取数据文件. 这是包含来自其他问题的解决方案的代码:

I want to read 10 case files in Ansys Fluent and for each case file there are 10 data files to be read. Ansys Fluent uses Scheme programming language. I have to managed to get some answers to individual problems in the code here (Evaluating a floating point variable in Scheme language) and here (How to increase counter in a do-loop within Scheme language?), but when collecting the individual answers I realized that I need a new code for the counter which is used to read the data files through do-loop. Here is the code with solutions from from other question included:

(do ((i 10 (+ i 1))
     (j 5  (+ j 1)))
    ((>= i 20) 'my-return-value)
  (ti-menu-load-string 
   (format #f "/file/read-case \"C:/DataProcessing/Case~a-time~a-sec/test/Case~a-time~a-sec.cas\"" i j i j))
  (do ((datafilenum 5.100 (+ datafilenum 0.100)))
      ((>= datafilenum 6.000))
    (ti-menu-load-string (format #f "/file/read-data \"C:/DataProcessing/Case~a-time~a-sec/test/Case~a-time~a-sec-~.3f.dat\"" i j i j datafilenum))
    (ti-menu-load-string (format #f "/plot plot n \"C:/DataProcessing/Case~a-time~a-sec/test/water-vof/column-water-vof-at-~.3fs.txt\" y n n water vof y 0 1 0 16 ()" i j datafilenum))))

我想在这里实现的是: 读取案例文件

What I'm trying to achieve here is: read the case file

Case10-time5-sec.cas

然后读取10个数据文件并绘制答案

then it reads the 10 data files and plot the answer

Case10-time5-sec-5.100.dat
Case10-time5-sec-5.200.dat
...
Case10-time5-sec-6.000.dat

下一个循环:

Case11-time6-sec.cas

读取10个数据文件并绘制答案

read the 10 data files and plot answer

Case11-time6-sec-6.100.dat
Case11-time6-sec-6.200.dat
...
Case11-time6-sec-7.000.dat

下一个循环...

因此,如何在此代码中以5.100开头的datafilenum更改为6.1007.1007.100等.当j在上层循环中更改值时,例如j.100和将此值附加到导出的文本文件column-water-vof-at-~.3fs.txt.而且,当然可以将6.000更改为7.0008.000 ...,例如j+1.000吗?这让我非常困惑,因为我使用了反复试验来实现它!

So, how to change datafilenum starting with 5.100 in this code to 6.100, 7.100, 7.100 etc. when j changes value in the upper loop, something like j.100 and append this value to the exported text file column-water-vof-at-~.3fs.txt. And, of course change, 6.000 to 7.000, 8.000..., something like j+1.000? This got me very confused as I have used trial and error to achieve it!

推荐答案

如何获取电话号码.如果j是6,并且您想要6.1,则可以使用标准数学运算将1/10添加到其中.

How to get the number. If j is 6 and you want 6.1 you add 1/10 to it using standard math operations.

(define j 6)
(+ j 1/10)
; ==> 61/10 (aka 6.1 exact)

函数format非标准,因此存在许多相互竞争的实现.在 SRFI-48中间格式字符串中,您可以执行以下操作: c16>显示为6.100:

The function format is not standard and thus there are many competing implementations. In SRFI-48 Intermediate Format Strings you can do this to get 61/10 to be displayed as 6.100:

(format #f "~0,3F" (+ j 1/10)) 
; ==> "6.100"

因此将它们放在一起:

(do ((i 10 (+ i 1))
     (j 5  (+ j 1)))
    ((>= i 20))
  (ti-menu-load-string 
   (format #f "/file/read-case \"C:/DataProcessing/Case~a-time~a-sec/test/Case~a-time~a-sec.cas\"" i j i j))
  (do ((datafilenum (+ j 1/10) (+ datafilenum 1/10)))
      ((>= datafilenum (+ j 1)))
    (ti-menu-load-string (format #f "/file/read-data \"C:/DataProcessing/Case~a-time~a-sec/test/Case~a-time~a-sec-~0,3F.dat\"" i j i j datafilenum))
    (ti-menu-load-string (format #f "/plot plot n \"C:/DataProcessing/Case~a-time~a-sec/test/water-vof/column-water-vof-at-~0,3Fs.txt\" y n n water vof y 0 1 0 16 ()" i j datafilenum))))

如果这不起作用,则需要编辑所使用的实现.例如. Racket的format有所不同,但它也支持SRFI-48,因此我用(require srfi/48)进行了测试.我更喜欢使用SRFI而非实现版本,因为稍后移植到RNRS的不同实现或修订版本会更容易.

If this isn't working you need to edit in which implementation you are using. eg. Racket has format which is different, but it also supports SRFI-48 so I tested this with (require srfi/48). I prefer to use a SRFI rather than the implementations version since porting to a different implementation or revision of RNRS later will be easier.

这篇关于在Scheme语言中,如何在与外部do循环连接的内部do循环中分配变量计数器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆