Fortran Wiki
Reading Ansys Sub Structure analysis file

For more info visit here


     
     program test
     
     double precision mass_mat(25,25)
     integer itype
     ! itype = 0 Extract Mass matrix 
     ! itype /= 0  extract STIFFNESS MATRIX
     itype=1
     call extract_mass("fby4splate.txt",25,mass_mat,itype)
     
     read *,i 
     end program
     
     subroutine extract_mass(fname,ip,mas_m,itype)
     
!
! Routine to read ansys file
! programmed by Sukhbinder Singh
!
! 18th August 2012
!

     character(len=*) :: fname
     character(len=200) :: tline
     double precision mas_m(ip,ip)
     integer ip,itype
     
     ! itype = 0 Extract Mass matrix 
     ! itype /= 0  extract STIFFNESS MATRIX
     
     inum=ip
     open(unit=14, file=fname,status='old')
     
     imm=mod(inum,4)
     iline=(inum - imm)/4
     
     do
       read(14,'(a)',end=100) tline
       iz=0
       if(itype .eq. 0) then
         iz =  INDEX (tline, 'MASS MATRIX' )  
       else
         iz =  INDEX (tline, 'STIFFNESS MATRIX' )  
       end if
       if ( iz .ne. 0) then
         read(14,'(a)',end=100) tline
         read(14,'(a)',end=100) tline
         jj=1;
         do
             iz =  INDEX (tline, 'DEG.' ) 
             if( iz .eq. 0) exit
               read(14,'(a)',end=100) tline
               read(14,'(a)',end=100) tline
               do  i =1,iline
                 mas_m(jj,4*i-3)=str2num(tline(6:20));
                 mas_m(jj,4*i-2)=str2num(tline(26:40));
                 mas_m(jj,4*i-1)=str2num(tline(46:60));
                 mas_m(jj,4*i)=str2num(tline(66:80));  
                 read(14,'(a)',end=100) tline
               end do
             
               if (imm >=1) then
                 ii2=iline*4+1
                 mas_m(jj,ii2)=str2num(tline(6:20))
               end if
             
               if (imm >=2) then
                 ii2=iline*4+2
                 mas_m(jj,ii2)=str2num(tline(26:40))
               end if
             
               if (imm >=3) then
                 ii2=iline*4+3
                 mas_m(jj,ii2)=str2num(tline(46:60))
               end if
             
               if (imm ==0) then
                  read(14,'(a)',end=100) tline           
               else
                  read(14,'(a)',end=100) tline
                  read(14,'(a)',end=100) tline
               end if
             jj=jj+1
  
         end do
       end if      
     end do
 100 continue      
     write(*,*) ' Reading complete'
     close(14);
  
   
     contains
     
     function str2num(text)
     character(len=*) ::text
     double precision :: str2num
       read(text,*) str2num
     return
     
     end function
     
     
     
     
    
     end subroutine


~~~~~