Append files together using windows command line

In the command prompt, an easy way to append files together is to use the “type” command and pipe it to an output file.

type Results_* > Results_combined.txt

To call this from a piece of C# code, I have been using the command line with the /c parameter, which makes it execute the attached command.

cmd /c type Results_* > Results_combined.txt

C# Example usage:

using (Process RunProc = new Process()) {
    string s = "cmd.exe";  
    string p = "/c type Results_* > Results_combined.txt";
    RunProc.StartInfo = new ProcessStartInfo(s, p);
    RunProc.Start();    
    RunProc.WaitForExit();
}

Getting autoincremented version numbers in Visual Studio

On C# projects, in the “AssemblyInfo.cs” file, you can set the Assembly Version to contain *, which sets the version automatically to the build date and time.

If you comment out the AssemblyFileVersion, then you can see it in the Windows explorer. If you don’t then Windows Explorer will always report the AssemblyFileVersion which does not support the * notation.

[assembly: AssemblyVersion("1.0.*")]

Making Fortran DLLs to interface with VBA in Excel

Note to self, Remember:
  • When working with Intel visual fortran, always perform a static link (/MT) in the command line options so that you don’t dependent on a DLL being present on the target machine.
  • DLLs need Kernel32.lib to be added to the dependencies
  • ByVal in VBA doesn’t always mean ByVal, when calling a DLL it means “Copy then give a Ref”, so on the Fortran side, get the address by reference.

Python – CSV handling

If you are going to process CSV’s in Python, you must really use the csv module. It makes life very easy on you and has extensive possibilities. By default, It creates a dictionary containing the header rows as key (eg: “Header 1”), which makes processing a charm.

import csv

coordinates_file = open("data.csv", "rU")
coordinates_data = csv.DictReader(coordinates_file)

for coord in coordinates_data:
    print (coord["Header 1"])

coordinates_file.close()

In the open statement, the “rU” is for universal read, meaning python will figure out line endings. (\r\n or \n or something other).

Another little trick, is once you have loaded a csv file, you can for example make a indexed array by indexing the input with one of the information in the row (assume here patrols is loaded with all the patrols, either from a DB or a CSV file):

patrols_dict = {} #Init to empty
for patrol in patrols:
     patrols_dict[patrol["PatrolID"]] = patrol

#And now we can access a patrol directly by it's patrol ID
#eg. patrols_dict["1000"] to access patrol 1000.