《ANSYS模型轉到MSC.MARC》是一篇陸新征寫的關於程式設計的文章。
!ANSYS命令流! 寫單元及節點數據檔案! 作者:陸新征,清華大學土木系!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !選中所有單元ALLSEL,ALL ! 得到當前模型中的總節點數*GET,NNode,NODE,,COUNT, , , , !輸出節點*CFOPEN,Node,txt*VWRITE('coordinates')*VWRITE,chrval(3),chrval(NNode),chrval(0),chrval(1)(4A5)*DO,I,1,NNode*VWRITE,I,NX(I),NY(I),NZ(I)(F8.0,3F13.5)*ENDDO*CFCLOS
!打開單元檔案 *CFOPEN,ELEM,txt!得到所有單元數ESEL,S,ENAME,,65 ALLSEL,ALL*GET,NElem,ELEM,,COUNT, , , , *VWRITE,chrval(NElem)('Number of Element: ', A8)!對單元集進行循環*DO,I,1,NElem!得到當前單元的類型*GET,ENAME,ELEM,I,ATTR,ENAM !如果是65號(65號單元)*IF,ENAME,EQ,65,THEN!得到該單元的節點編號*GET,EN1,ELEM,I,NODE,1 *GET,EN2,ELEM,I,NODE,2 *GET,EN3,ELEM,I,NODE,3 *GET,EN4,ELEM,I,NODE,4 *GET,EN5,ELEM,I,NODE,5 *GET,EN6,ELEM,I,NODE,6 *GET,EN7,ELEM,I,NODE,7 *GET,EN8,ELEM,I,NODE,8 *VWRITE,I,EN1,EN2,EN3,EN4,EN5,EN6,EN7,EN8(F8.0,8F8.0)*END IF*ENDDO*CFCLOS
!Fortran程式,把ansys結果轉換為MARC模型檔案格式program mainimplicit none;integer Key;write(*,*) "Input 1 for node, 2 for element"read(*,*) Keyif (Key==1) thencall Node_IO()end ifif (Key==2) thencall Elem_IO()end ifstopend program
subroutine Node_IO()implicit noneinteger NNode,I, Jreal*8,pointer :: Node(:,:)real*8 x;character :: filename*10;write(*,*) "Please input node filename"read(*,'(A10)') filenameopen(66,file=filename)read(66,*) NNodeallocate (Node(NNode,3))do I=1,NNoderead(66,*) x, (Node(I,J), J=1,3)end doclose (66)filename=filename//"NEW"open (66,file=filename)write(66,'(4I10)') 3, NNode, 0, 1do I=1, NNodewrite(66,'(I10, 3E20.8)') I, (Node(I,J), J=1,3)end doclose (66)returnend subroutine Node_IO
subroutine Elem_IO()implicit noneinteger NElem,NumNode,ElemTyp,I, Jinteger,pointer :: Elem(:,:)real*8 x;real*8,pointer :: y(:)character :: filename*10, outformat*11,CharEtype;write(*,*) "Please input node filename"read(*,'(A10)') filenamewrite(*,*) "Please input Element type & Number of Nodes per element"