FORTRAN
Author | Topic: FORTRAN |
---|---|
Law Bringer
Member # 2984
|
written Monday, March 12 2007 05:23
Profile
Homepage
Since there are already threads for C++ and Java, I might as well add another language. However, this topic is primarily to show off my first working algorithm written entirely in Fortran. It finds the shortest path through a labyrinth. The labyrinth can look like this (using rogue-like dungeon notation). So the computer is trying to walk downward through a primitive Angband level, from stairway to stairway: This is the program: And the last lines of the output: [ Monday, March 12, 2007 05:27: Message edited by: Dr. Johann Georg Faust ] -------------------- Encyclopaedia Ermariana • Forum Archives • Forum Statistics • RSS [Topic / Forum] My Blog • Polaris • I eat novels for breakfast. Polaris is dead, long live Polaris. Look on my works, ye mighty, and despair. Posts: 8752 | Registered: Wednesday, May 14 2003 07:00 |
Guardian
Member # 6670
|
written Monday, March 12 2007 06:53
Profile
Homepage
Ah, FORTRAN. That explains it. GOTO is still a sign of a sick and twisted mind, though. It brings back horrid memories of the monstrosities I wrote in BASIC. -------------------- EDIT: Someone doesn't like me remote-loading pictures... [ Monday, March 12, 2007 08:40: Message edited by: Dintiradan ] Posts: 1509 | Registered: Tuesday, January 10 2006 08:00 |
Law Bringer
Member # 2984
|
written Monday, March 12 2007 08:38
Profile
Homepage
Well, I used the first one because I couldn't figure out how to elegantly leave those 4 nested loops all at once. And the second one... well, it's a simple decision of whether the algorithm succeeds or fails. I suppose I could have done it with a boolean too... In my defense, neither of those jump destinations were more than a screen away, and they're pretty unambiguous too. Although you should have seen our teacher use them. Very fond of them, especially for foot-oriented loops. Admittedly, sometimes a loop needs to have its condition at the end, but can it justify something like this? Edit: Heureka! I now know how to get the actual path - so far, I've only determined the length of the shortest path, not it's actual steps. But those can be found by following the trail backwards. Just start at the end point, take the lowest positive neighbour, then always find the neighbour that is one less than the current position. Even if there are several equivalent shortest paths, they will all be found this way. Edit2: Sorry, the above doesn't make any sense unless you understood the algorithm the program currently uses. [ Monday, March 12, 2007 08:43: Message edited by: Dr. Johann Georg Faust ] -------------------- Encyclopaedia Ermariana • Forum Archives • Forum Statistics • RSS [Topic / Forum] My Blog • Polaris • I eat novels for breakfast. Polaris is dead, long live Polaris. Look on my works, ye mighty, and despair. Posts: 8752 | Registered: Wednesday, May 14 2003 07:00 |
The Establishment
Member # 6
|
written Wednesday, March 14 2007 08:53
Profile
Although it really doesn't matter much, you could replace GOTO 10 with RETURN. They will do the same thing in this case and you avoid the use of gotos. Also, you can place the format specifiers in the WRITE statements themselves too. Minor style with Fortran (yes, it is lowercase for versions f90 and higher), is to have commands as UPPERCASE and variables and user defined functions as lowercase. WHERE is also an intrinsic in f90, so you should probably use a different variable. Also, you may want to have dynamic array bounds using the ALLOCATE statement. Just don't forget to DEALLOCATE or you will incur memory leakage. -------------------- Your flower power is no match for my glower power! Posts: 3726 | Registered: Tuesday, September 18 2001 07:00 |
Law Bringer
Member # 2984
|
written Wednesday, March 14 2007 10:06
Profile
Homepage
Memory leakage until the program closes, or permanently (until I restart my computer)? Thanks for the hint about ALLOCATE, I hadn't even thought of that... -------------------- Encyclopaedia Ermariana • Forum Archives • Forum Statistics • RSS [Topic / Forum] My Blog • Polaris • I eat novels for breakfast. Polaris is dead, long live Polaris. Look on my works, ye mighty, and despair. Posts: 8752 | Registered: Wednesday, May 14 2003 07:00 |
The Establishment
Member # 6
|
written Wednesday, March 14 2007 13:36
Profile
Memory leakage, it depends on the OS as far as I can tell. On Win XP, I had a program that took 90% of the available memory. I accidentally fed it some totally invalid input and it crashed. I had to restart to make things normal again. I've never had analogous problems in my LINUX box regarding this, leading me to believe the problem is handled a bit better in this OS. I haven't tried a lot with OS X, but I'd guess it would be similar. Basically, memory gets set aside for some purpose and if some other process does not tell it to put it back for general use, it is effectively "lost". -------------------- Your flower power is no match for my glower power! Posts: 3726 | Registered: Tuesday, September 18 2001 07:00 |
Law Bringer
Member # 2984
|
written Wednesday, March 14 2007 14:28
Profile
Homepage
By the way, one of the problems I've had with dynamic arrays was that I couldn't find a way to get their size back (as LEN() does for the string length). Do I have to store the number that was used in the ALLOCATE command separately, and pass it to any subroutine that needs it, or can I just pass the array and somehow get its length back with a function? -------------------- Encyclopaedia Ermariana • Forum Archives • Forum Statistics • RSS [Topic / Forum] My Blog • Polaris • I eat novels for breakfast. Polaris is dead, long live Polaris. Look on my works, ye mighty, and despair. Posts: 8752 | Registered: Wednesday, May 14 2003 07:00 |
The Establishment
Member # 6
|
written Wednesday, March 14 2007 18:09
Profile
The SIZE intrinsic will return the array dimensions. Between functions/subroutines you can, as a crude and dirty way, specifically pass the lengths as an arguments: Otherwise you can use INTERFACE blocks as well to perform these tasks with assumed shape arrays. -------------------- Your flower power is no match for my glower power! Posts: 3726 | Registered: Tuesday, September 18 2001 07:00 |
Guardian
Member # 6670
|
written Thursday, March 15 2007 13:46
Profile
Homepage
Using a language that keeps track of an array's size for you makes you weak. ;) -------------------- The poor d12. So maligned, so misunderstood. Shunned by its more popular d6 and d20 bretheren, even the d4 secretly laughs at the poor twelve-sider. The d3 gets more play, and it doesn't even exist. - Elan (OotS #121) Posts: 1509 | Registered: Tuesday, January 10 2006 08:00 |
Law Bringer
Member # 2984
|
written Wednesday, March 21 2007 06:23
Profile
Homepage
http://www.nytimes.com/2007/03/20/business/20backus.html?_r=1&oref=slogin :( [ Wednesday, March 21, 2007 06:24: Message edited by: Dr. Johann Georg Faust ] -------------------- Encyclopaedia Ermariana • Forum Archives • Forum Statistics • RSS [Topic / Forum] My Blog • Polaris • I eat novels for breakfast. Polaris is dead, long live Polaris. Look on my works, ye mighty, and despair. Posts: 8752 | Registered: Wednesday, May 14 2003 07:00 |