首页/文章/ 详情

HyperWork必备知识-templex语言1-应用场景

27天前浏览333

hyperwork后处理的自动化,有两条技术路线,第一条就是通过tcl语言二次开发,可以满足基本上所有的需求。第二条就是通过tpl文件和PPT导出功能做到自动化。适用于固定规范,固定输入变量的情况,只需要操作一次,将当前会话保存为tpl文件即可。

在下一次面临相同后处理的情况下,通过tpl文件,我们只用重新指定文件名,即可在当前会话得到相同的结果。

tpl可以帮我们绘制结果,但是我们有时候还需要查询结果或者提取结果

怎么处理呢,那么就可以通过templex语言实现,我们可以来查询曲线的最大,最小值,对多根曲线进行数值计算,或者将结果写入到文本中等。

后处理,处处都是templex的应用实例,hyperview客户端的图形界面右上角显示的note,在编辑框中就是templex语言。

曲线的参数计算

查看曲线的最大值

将最大值写入到文件中

templex可以包含纯文本,数学表达式、常数和变量。

 temolex语句的、表达式和变量必须放在大括号 {} 之间才会执行运算。

在大括号外的文本被视为纯文本,不被处理,只会直接输出。

注释可以放在大括号内,通过引号标注即可。

输入

    The square root of 2 is approximately equal to {sqrt(2)}.

    显示

      The square root of 2 is approximately equal to 1.414213.

      输入

        {for (x=0; x<=5; x++)}  x={x}, Square root of x={sqrt(x)}{endloop}

        显示

          x=0, Square root of x = 0x=1, Square root of x = 1x=2, Square root of x = 1.41421x=3, Square root of x = 1.73205x=4, Square root of x = 2x=5, Square root of x = 2.23607

          输入

            {for (x=0; x<=5; x++)}x={x}, Square root of x={sqrt(x), %5.3f}{endloop}

            显示

              x=0, Square root of x = 0.000x=1, Square root of x = 1.000x=2, Square root of x = 1.414x=3, Square root of x = 1.732x=4, Square root of x = 2.000x=5, Square root of x = 2.236

              输入

                {'This template evaluates the square root of the}{'numbers 0 through 5 and prints the output when}{'the value of the square root is less than or}{'equal to 1.5}{for (x=0; x<=5; x++)}  {if (sqrt(x)<=1.5)}     x={x}, Square root of x={sqrt(x), %5.3f}  {endif}{endloop}

                显示

                  x=0, Square root of x = 0.000x=1, Square root of x = 1.000x=2, Square root of x = 1.414

                  输入

                    {ofile = {"st_sqr.out", "st_sqrt.out", "st_sine.out"}}{open ofile[0]}  {for (x=0; x<=5; x++)}     x={x}; Square of x= {x^2, %5.3f}  {endloop}{close}{open ofile[1]}  {for (x=0; x<=5; x++)}     x={x}; Square root of x= {sqrt(x), %5.3f}  {endloop}{close}{open ofile[2]}  {for (x=0; x<=5; x++)}     x={x}; Sine of x= {sin(x), %5.3f}  {endloop}{close}

                    将在当前路径下,创建三个文件,并写入结果。

                    本篇就到这里,了解上述知识是够用的了,后续的文章将对逻辑判断,循环结构,数学计算,文件IO,

                    来源:TodayCAEer
                    HyperView二次开发UGUM
                    著作权归作者所有,欢迎分享,未经许可,不得转载
                    首次发布时间:2024-08-14
                    最近编辑:27天前
                    TodayCAEer
                    本科 签名征集中
                    获赞 16粉丝 8文章 163课程 0
                    点赞
                    收藏
                    作者推荐

                    HyperWork必备知识-templex语言6-文本写入与解析pch文件

                    Example1记录当前日期{&#39;Createafilecontainingtoday&#39;sdate}{open&quot;date.fil&quot;}{date()}{close}Example2记录当前时间{file_name=&quot;time_stamp.out&quot;}{openfile_name}{date(&quot;%A&quot;)}:{time()}{close}Example3将曲线信息写入到文本中{&#39;Createafilecontainingtoday&#39;sdate}{open&quot;date.fil&quot;}{p1w1c1.x}{p1w1c1.y}{close}Example4将曲线信息格式化后写入到文本中{x=p1w1c1.x}{y=p1w1c1.y}{open&quot;date.fil&quot;}{table(x,y,&quot;%12.6f%12.6f&quot;,0,numpts(x)-1)}{close}Example5匹配foreach和if判断写入文件的文本{file_name=&quot;week_time_stamp.out&quot;}{openfile_name}{days={&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;,&quot;Sunday&quot;}}{foreach(day=days)}{date(&quot;%A&quot;,day)}:{time()}{if(day==&quot;Saturday&quot;||day==&quot;Sunday&quot;)}Note:It&#39;stheweekend!{endif}{endloop}{close}Example6将信息添加到文件末尾{&#39;Createafilecontainingtoday&#39;sdate}{append&quot;date.fil&quot;}{date()}{close}{file_name=&quot;time_stamp.out&quot;}{appendfile_name}{date(%A)}:{time()}{close}Example7读取文本文件{a=read(&quot;two.xy&quot;,0,0,0);b=read(&quot;two.xy&quot;,0,0,1);table(a,b,&quot;%8.2f%8.2f&quot;,0,5);}Example8解析pch文件{a=read(&quot;car.pch&quot;,&quot;GPForce&quot;,&quot;Pointid1130488Elemid1082288QUAD4&quot;,&quot;Frequency[Hz]-subcase2(modal_frequency_response_analysis)&quot;)b=read(&quot;car.pch&quot;,&quot;GPForce&quot;,&quot;Pointid1130488Elemid1082288QUAD4&quot;,&quot;REL|MY&quot;)table(a,b,&quot;%15.6f%8.6f&quot;,0,numpts(b)-1)}来源:TodayCAEer

                    未登录
                    还没有评论
                    课程
                    培训
                    服务
                    行家
                    VIP会员 学习 福利任务 兑换礼品
                    下载APP
                    联系我们
                    帮助与反馈