波哥的学术乐园分享 http://blog.sciencenet.cn/u/ChenboBlog 这是个充满机会,需要努力奋斗的时代!

博文

随便说说2

已有 3614 次阅读 2011-5-16 17:56 |系统分类:科研笔记| idarc

   程序终于写成了,其实就花了两个小时写,但前前后后找思路,组织架构就花了两天时间。对我这个matlab盲来说自我感觉已经相当不错了,幸亏自己有fortran的底子,哈哈。。。
   写的时候也出了不少问题:主要就是数组定义和文本写入输出。
   数组方面主要是,由于matlab比较自由,可以不用提前定义数组大小和类型,这个“自由”给了些方便,也给我造成了不少麻烦。在循环过程中,如果前一个循环得到的数组大于后一个循环的数组,由于在循环中无法使用“clear”,后循环的数组就无法完全覆盖前一数组的内容,这样后循环数组中的内容肯定就是不可用的。解决办法:在前一循环结束,就把数组清空。
    写入和输出,其实并不难,主要就是要注意格式。
    下面是一段程序,自我感觉写的比较繁琐,过两天再改改。。
     %This program is written for computer the maximum interstory ratio
%automaticly by idarc 2d
clc;
clear;
gm=3;    %the number of ground motions
sm=20;   %the number of times for one ground motions
load fac1.txt  %this text for gm property
load fac2.txt  %this text for amplitude ratio
for i=1:350   %define an empty 2d array as large as possible
    for j=1:200
        c(i,j)=' ';
    end
end

   
for gmn=1:gm    %the cycle for ground motion
    for smn=1:sm  % the cycle for the computer time for one ground motion with the amplitude ratio
        fid=fopen('S8L8.dat','r');  %open the input file
        for i=1:331
            tline=fgetl(fid);
            len=length(tline);
            for j=1:len
                c(i,j)=tline(j);
            end
        end
        fclose(fid);
       tc1=str2num(c(241,:));  %the program follow for modify the input file
       tc1(1)=fac2(smn,gmn);
       tc1(3)=fac1(gmn,4);
       tc1(4)=fac1(gmn,2);
       len=length(num2str(tc1));
       c(241,1:len)=num2str(tc1);
     
      
      
       tc2=str2num(c(243,:));
       tc2(2)=fac1(gmn,5);
       tc2(3)=fac1(gmn,4);
       len=length(num2str(tc2));
       c(243,1:len)=num2str(tc2);
        
      
      
       tc3=str2num(c(245,:));
       len=length(num2str(tc3));
       c(245,1:len)=' ';
       tc3(1)=fac1(gmn,1);
       len=length(num2str(tc3));
       c(245,1:len)=num2str(tc3);
     
      
       fid=fopen('S8L8.dat','wt');   %written the input file into the origin file
       for i=1:350
          for j=1:200
              fprintf(fid,'%s',c(i,j));
          end
          fprintf(fid,'n');
       end
       fclose(fid);
       !new.exe;
      
      
       for i=1:2500
           for j=1:250
               out(i,j)=' ';
           end
       end
      
       %the follow is written for deal with the output file
       fid=fopen('1.out','r');  
       for i=1:2500
            tline=fgets(fid);
            len=length(tline);
            for j=1:len
                out(i,j)=tline(j);
            end
        end
        fclose(fid);
       
       
        b=0;
        for i=1:2500
            if out(i,22:37)=='MAXIMUM RESPONSE'
                b=i;
            end
        end
       
       if b==0
           for i=1:8
              re(8,8)=0;
           end
       else
      
        for i=1:8
            ree(i,:)=out(b+8+i,:);
            re(i,:)=str2num(out(b+8+i,:));
        end
       end
      
    maxinter(gmn,smn)=max(re(:,3));  
    end
end


https://wap.sciencenet.cn/blog-419879-444788.html

上一篇:随便说说
下一篇:STEP
收藏 IP: 124.17.4.*| 热度|

0

发表评论 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-16 01:45

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部