Using Read List to read FORTRAN output
- To: mathgroup at yoda.physics.unc.edu
- Subject: Using Read List to read FORTRAN output
- From: Cetin Cetinkaya <cetin at acm0.me.uiuc.edu>
- Date: Tue, 11 Jan 1994 00:32:08 -0600
Tue Jan 11 00:29:29 CST 1994 Dear Netters; I have a quick question. I have an input file which looks like as follows: Elem. No. S22 --------- ------------------------------------------------------- 1 Int. pt. 1 : -1.9419E+04 Int. pt. 2 : -3963.7 Int. pt. 3 : -1.1481E+04 Int. pt. 4 : 3973.9 3 Int. pt. 1 : 882.7 Int. pt. 2 : 3285.4 Int. pt. 3 : 5379.9 Int. pt. 4 : 7782.6 I am interested in reading this data file (test3.m) into MMA in a list form. For this file, what I want is something like this: {1, -1.9419E+04, -3963.7 , -1.1481E+04 , 3973.9 , 2, 882.7 , 3285.4 , 5379.9 , 7782.6 } that is to say, I want Elem. No. and corresponding four Int. pt. values. To do this, I have studied the section 2.10. Reading Data of the Manual. In In[79] below, I have shown the function which I developed for this purpose. Unfortunately, it does not give what it is suppposed to produce: Elem. No.'s are missing. In[79]:=ReadList["test3.m",Record , RecordSeparators->{{"/n ","1 :","2 :","3 :","4 :"}, {"Int. pt. 1 :","Int","Int","Int","\n"}} ] Out[79]= { -1.9419E+04 , -3963.7 , -1.1481E+04 , > 3973.9 , 882.7 , 3285.4 } The manual suggests (In13] in p.497) that InputForm of a ReadList command is helpful. The following is the InputForm - how MMA sees it internally: In[80]:= InputForm[ ReadList["test3.m",Record ,RecordSeparators->{}]] 0.0166667 Second 669.724 KByte Out[80]//InputForm= {" Elem. No. S22 \ \n --------- \ ------------------------------------------------------- \n \ 1 Int. pt. 1 : -1.9419E+04 Int. pt. 2 : -3963.7 \ \n Int. pt. 3 : -1.1481E+04 Int. pt. 4 : 3973.9 \ \n 3 Int. pt. 1 : 882.7 Int. pt. 2 : 3285.4\ \n"} >From Out[80], it is clear that Elem. No.'s 1 and 3 are between "\n" and "Int. pt. 1 :". But it is not given in the output line Out[79] above even though the right separator is used in the function. Now I would like to ask the following questions: 1- How come MMA do not recognize this separator? 2- What can I improve my function for the desired task? 3- Is there a better way to do what I am trying to do? Something similar to FORTRAN formats? Thanks in advance, CETIN CETINKAYA