Fortran source code file setup and column rules: SWAN - fortran

Im tring to understand sourceforge swan wave model fortran source code. One point of confusion is the different files in the source code folder (.edt,.ftn,.ftn90,.inc,.lst,.nml,.pl,.eps,.bat), now I know what sort most of these files are but the naming convention is a little boggling.
I look at swanmain.ftn and I can't understand: Is the compiler just read this file in order because there seems to be no initialization of SWMAIN like (eg "program SWMAIN") it just starts with IMLICIT NONE?? And it just has END then next line is a bunch of USE statements?? The only formal declaration of the start of SWMAIN is in a comment.
Another question i have is it seams that in columns 75:end there is a number eg 40.30 seams like a version number where that line was added or edited, yet there is no ! or c to initialize comment so are lines past 75 just assumed to be unused ( I know fortran has line format of those old punch cards but I thought it ended at column 80)?
Where should I start as far as understanding how this program is set out ie which file will give me the most insite into what all the other files do.. Should I understand makefile format?
Sorry for all the noob questions as I basically never studied programming just kinda learn while doing. Ive written a few programs in Java and C++ but mostly MATLAB.
Thanks

Most of the sources should be obvious: ftn and ftn90 are Fortran sources, nml is a Namelist file, pl is a Perl script, eps is a figure, bat is a Windows Batch file, inc is an "include" file (not language specific) and "lst" appears to be a list (not sure the relevance).
The code appear to be written primarily in FORTRAN 77 standard. As such, anything past line 72 (not 80) is truncated as a comment (gfortran will even warn you that it's doing so if you have -Wall enabled).
Fortran technically does not require a PROGRAM <name> declaration. Really the only thing required in a Fortran code is END to end it.
If you are trying to figure the program out, I would suggest:
Read the documentation at least twice.
Read relevant publications from the code (specifically the initial announcement of the code)
Start by looking at the main program and seeing where the calls go (this is probably a very slow and bad way to do it, since it looks to be a fairly long code)

Related

How to extract program code from ISO file

In the Xbox 360 game Project Sylpheed: Arc of Deception. There are secret sub objectives for each level. On stage 11 "Flaming Clouds" there are 4, I have found two sources claiming they know each of them, but is actually untrue. One is still hidden. This is a very unpopular game, and no one has investigated it, and I want to know what it is. I have a disk image file of the game (ISO file). How would I go about finding the level trigger for the sub objective? I have already attempted to extract the 7gb iso using 7zip and Winrar, but each yielded the same 12mb files that contain nothing relevant what so ever. Obviously the core of the information is hidden and remains unextracted. Please advise.
https://wincdemu.sysprogs.org/ or linux/mac mount -o loop /path/to/my-iso-image.iso /mnt/iso
from there you're going to need a reverse compiler probabably but I don't know what your game is written in. You might luck out and find the levels coded in lua or something though.
Something else that can be happening is 7zip is actually opening the iso right, and the 12mb could be instructions to go download the actual game code from somewhere else. That sometimes happens with consoles.

Extract comment written in Chinese and translate them into English using some script

I have a C++ project in which comments of source code are in Chinese language, now I want to convert them into English.
I tried to solve using google translator but got an Issue: Whole CPP files or header didn't get converted, also I have found the name of the struct, class etc gets changed. Sometimes code also gets modified.
Note: Each .cpp or .h file is less than 1000 lines of code.But there are multiple C++ projects each having around 10 files. Thus I have around 50 files for which I need to translate Chinese text to English.
Well, what did you expect? Google Translate doesn't know what a CPP file is and how to treat it. You'll have to write your own program that extracts comments from them (not that hard), runs just those through Google Translate, and then puts them back in.
Mind you, if there is commented out code, or the comments reference variable names, those will get translated too. Detecting and handling these cases is a lot harder already.
Extracting comments is a lexical issue, and mostly a quite simple one.
In a few hours, you could write (e.g. with flex) some simple command line program extracting them. And a good editor (such as GNU emacs) could even be configured to run that filter on selected code chunks.
(handling a few corner cases, such as raw string literals, might be slightly more difficult, but these don't happen often and you might handle them manually)
BTW, if you are assigned to work on that code, you'll need to understand it, and that takes much more time than copy&pasting or editing each comments manually.
At last, I am not sure of the quality of automatic translation of code comments. You might be disappointed. Also, the code names (of functions, of classes, of variables, etc...) matter a lot more.
Perhaps adding your comments in English could be wiser.
Don't forget to use some version control system. You really need one (e.g. git)
(I am not convinced that extracting comments for automatic translation would help your work)
First separate both comment and code part in different file using python script as below,
import sys
file=sys.argv[1]
f=open(file,"r")
lines=f.readlines()
f.close()
comment=open("comment.txt","w+")
code=open("code.txt","w+")
for l in lines:
if "//" in l:
comment.write(l)
code.write("\n")
else:
code.write(l)
comment.write("\n")
comment.close()
code.close()
Now translate comment.txt with google translator and then use
paste code.txt comment_en > source
where comment_en is translated comment in english.

Program I just made is apparently a virus? C++

Okay so I just made a C++ program that is basically a notebook,
you write stuff in it and it saves it to a .dat file and then you can
read it later.
I compiled it with Microsoft Visual C++ and now I sent it to a friend and it's
saying that it is a virus? I scan it online and it also says that it's a virus.
I don't know why this is happening, as I literally just used some if/else statements, created some strings and used a couple getlines. (and fstream to create the .dat files).
This is the virus report: https://www.virustotal.com/en/file/a1b72280a32915429607fd5abeef1aad4f8310867df1feb7707ea0f7a404026e/analysis/1455735299/
Here is my code. (Its 400+ lines). And I'm almost certain there's nothing wrong
with it. http://pastebin.com/ZwJZrRSu
Any idea why this is happening?
Most probably your PC is already infected by a virus, which adds itself to any executable it can find on your machine. That would easily explain this behavior. Try to compile the same program on PC that is clean for sure and check your PC by antivirus.
I am not sure but I think it because you imported kernel32.dll
Again, it is hard to tell without the source
Also take a look at the file detail in the report

TextWrangler not showing the correct column number when editing fixed-format Fortran

I am maintaining a program written mainly in fixed-format Fortran. I recently switched from a Windows PC to a Mac, and I'm now using TextWrangler to edit my code. I noticed that the indentation in the editor window does not always correspond to the actual structure of the code. For example, the following random lines are displayed like this by TextWrangler:
! The following lines start on column 5!
loadnam=dirstate(1:NN)//'updatestate.sav'
open (9876, file=loadnam, status='unknown', form='binary')
close (9876, status='delete')
if ((rank == root) .or. (doParallel == .false.))
* call messagerun (1,'Proceeding with updating!')
include 'updating_opt.inc'
end if
Clearly, this does not reflect the actual structure of the code, as fixed-format Fortran statements may not start before column 7 (with a few exceptions). However, the compiler does not complain, and when I open the file with another editor, the code appears in the correct format.
If I type in a new line, however, the compiler will abort compilation if it starts before column 7 (which is the normal behavior).
I don't really understand this behavior of TextWrangler. Is it intentional? TextWrangler did recognize the language automatically (as Fortran, not Fortran 9x), so I'm wondering why it doesn't take into account this important aspect of old Fortran code.
Is there a way to avoid this behavior (while maintaining the Fortran syntax highlighting)? As the program is quite long, I'd like to avoid rewriting it all to free-format Fortran.

Following the flow of code

I'm trying to learn the level format in one of my favourite games, which is almost totally undocumented. Basically the only document that describes the level format is simply by saying things like First 12 bytes: header 4 following bytes: number of materials x next bytes: array of materials, and things like that.
I'm very inexperienced in hex and don't completely understand what they're saying. However, there is a level editor, and the source is freely available on google code. I was thinking of adding this in to my visual studio and trying to learn the level format by reading how the level editor opens the files.
However, another problem, I don't know c++ (I know python). This means I probably won't be able to locate which part of the code reads the bytes and whatnot.
What I'm looking for, is something that will allow me to follow the flow of the code, in its execution. Essentially something that acts similar to setting a breakpoint on every line, and having it show me what specific portion of code is executing when reading the file contents.
However, obviously setting breakpoints on every line is very messy and slow. I'm looking for something that will simply show me what code is being run when I open the file in the editor.
Does anyone know what I could do? Thanks.
You're looking for a feature to step from one statement to the next; every debugger I know has such a feature. You start by setting a single breakpoint at the beginning of the interesting region, and starting from there you "step" through your code.
E.g. in Visual C++ 2010, the key F10 does one step; you can also "step into" the next statement (e.g. a method call) with F11.
In your case, set the breakpoint to where the reading of the level file starts, and continue from there. To find the place where the file is read can be a hard problem as well - depending on the clearness of the code; but if it's well written code, there should be a method with "read" in the name or "load" or something similar - you'll figure it out!
You might have to know at least some basic C++ syntax to be able to follow what's going, though.
I would also recommend reading up on Debugging HowTo's (e.g this one).
The document wich you find so obscure, is just the level format specifications, in most cases the specifications are all you need. You need as well some little extra experience with file reading.
When reading a file you have to warry about few things.
1) When reading byte by byte (8 bits) order is no changed.
2) When reading 32bits at a time byte order can change according to endianness of machine.
(for example 0x12345678 becomes 0x78563412 when endiannes changes)
There was a very old tutorial that can help you loading 3D models that helped me to start working with files:
http://www.spacesimulator.net/wiki/index.php?title=Tutorials:3ds_Loader
this is usefull because you have part of the specifications (like in original documentation) and it shows how you can create a loader just starting from specifications. That's all you need. That's C but there is no big difference from C++ in this case.
If you need some other simple file format specification with related file loader for making things clearer to you, you can also look at libktx and ktx specifications:
http://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/
If I remember correctly there's also a unofficial C++ KTX loader you can look at if you itend to write C++ oop code rather than C.