Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran read left to right

Status
Not open for further replies.

Travis260

Programmer
Oct 4, 2004
5
US
I need some help with a Fortran read statment. I have some files that I need to read data in from, the problem is that I need to read the data from left to right. I first tryied to do a read like this
READ(unit,100) x(i), x(i+1), x(i+2),........
The problem is that there is not the same amount of data in each file so some of my arrays have zero in them which is something I don't want. Can anybody tell me how I can get Fortran to read the data from left to right, here is an example of the data I am reading in.

131. 132. 133. 134. 135. 136.
137. 138. 139. 140. 141. 142.
143. 144. 145. 146. 147. 148.
149. 150. 151. 152. 153. 154.
155. 156. 157. 158. 159. 160.
161. 162. 163. 164. 165. 166.
167. 168. 169. 170. 171. 172.
173. 174. 175. 176. 177. 178.
179. 180. 181. 182. 183. 184.
185. 186. 187.
Thnaks in advance
 
Do you mean right to left or do you mean backwards?

In the example you have given, there are 6 numbers per line so you could read it backwards as
Code:
read (unit, 100) (x(i + j), j = 5, 0, -1)
Not really reading backwards but reading forwards with elements going backwards. If you want the whole file backwards, read the whole file forwards first then swap as follows
Code:
! assume maxx points
integer:: lo, hi
hi = maxx
do lo = 1, maxx / 2, 1
   swap = x(lo)
   x(lo) = x(hi)
   x(hi) = swap
   hi = hi - 1
enddo
[CODE]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top