As an architect we want to know how good the software is that we are developing. Its quality has an obvious external aspect, the software should be of value to its users, but there is also a more elusive internal aspect to quality, to do with the clarity of the design, the ease with which we can understand, maintain, and extend the software. When pressed for a definition, this is where we usually end up saying “I know it when I see it.” But how can we see quality?
In an architecture diagram little boxes represent entire systems and lines between them can mean anything: a dependency, the flow of data, or a shared resource such as a bus. These diagrams are a 30.000ft view, like a landscape seen from a plane. Typically the only other view available is the source code, which is comparable to a ground level view. Both views fail to convey much information about the quality of the software, one is too high level and the other provides so much information that we cannot see structure. Clearly, what is missing is a view in between, a 1000ft view.
This 1000ft view would provide information at the right level. It aggregates large amounts of data and multiple metrics, such as method count, class fan out, or cyclomatic complexity. The actual view very much depends on a specific aspect of quality. It can be a visual representation of a dependency graph, a bar chart that shows metrics at a class level, or a sophisticated polymetric view that correlates multiple input values.
Manually creating such views and keeping them in sync with the software is a hopeless endeavor. We need tools that create these views from the only true source, the source code. For some views, a design structure matrix for example, commercial tools exists but it is also surprisingly easy to create specialized views by combining small tools that extract data and metrics with generic visualization packages. A simple example would be to load the output from checkstyle, which is essentially a set of metrics on the class and method level, into a spreadsheet to render charts. The same metrics could also be shown as a tree-map using the InfoViz toolkit. A great tool to render complex dependency graphs is GraphViz.
Once a suitable view is available software quality becomes a little less subjective. It is possible to compare the software under development with a handful of similar systems. Comparing different revisions of the same system will give an indication of trends while comparing views of different subsystems can highlight outliers. Even with just a single diagram we can rely on our ability to spot patterns and perceive aesthetics. A well-balanced tree probably represents a successful class hierarchy, a harmonious set of boxes might show code that is organized into appropriately sized classes. Most of the time a very simple relationship holds: If it looks good it probably is good.
By Erik Doernenburg
Summary: This is a basic guide to writing mex files for MATLAB in C. This guide gives a simple background of some the MATLAB mex features so that learning to write mex files can be quick and easy.
Introduction
The MATLAB M-File is very good for putting together functions or scripts that run many of MATLAB’s fast Built-In functions. One nice thing about these files is that they are never compiled and will run on any system that is already running MATLAB. MATLAB achieves this by interpreting each line of the M-File every time it is run. This method of running the code can make processing time very slow for large and complicated functions, especially those with many loops because every line within the loop will be interpreted as a new line, each time through the loop. Good MATLAB code avoids these things by using as many Built-In features and array operations as possible (because these are fast and efficient). Sometimes this is not enough…
MATLAB has the capability of running functions written in C. The files which hold the source for these functions are called MEX-Files. The mexFunctions are not intended to be a substitue for MATLAB’s Built-In operations however if you need to code many loops and other things that MATLAB is not very good at, this is a good option. This feature also allows system-specific APIs to be called to extend MATLAB’s abilities (see the Serial Port Tutorial for an example of this).
This document is arranged in the following manner:
These are some of the basic topics that will allow you to create a MEX-file in a short time. There are many other features and abilities that MATLAB has which can be explored in the MATLAB documentation.
The MEX-Function: Interface to MATLAB
When writing programs in C, it is always assumed that the program will start execution from the main(). MEX -Files are similar in that they always start execution from a special function called the mexFunction. This function has return type void and is the “gateway” between the MATLAB function call, and your C code.
Example 1
//You can include any C libraries that you normally use
#include “math.h”
#include “mex.h” //–This one is required
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
//All code and internal function calls go in here!
return;
}
In order to make a mex-function, you must include the “mex.h” library. This library contains all of the APIs that MATLAB provides. There are four input parameters to the mexFunction which correspond to the way a function is called in MATLAB – (ex: [z0,z1] = jasonsFunction(x,y,z);)
Getting and Creating Data
The main MATLAB structure used for holding data in MEX-Files is the mxArray. This structure can hold real data, complex data, arrays, matrices, sparse-arrays, strings, and a whole host of other MATLAB data-structures. Using data from some of the basic structures is shown here, but refer to the MATLAB help for using other data structures.
Get that Data
Lets use my example from above (if you forgot: [z0,z1] = jasonsFunction(x,y,z);). Assume that x is a 2-D matrix, y is a string, and z is an integer. Here we wills ee how to extract and use these different types of data.
We have access to the input paramter x by a pointer held in the array prhs. In C, when referencing an array by index, the variable is automatically dereferenced (ie: you dont need to use a star). For clarity, I will copy the variable x over to an mxArray pointer named xData (This does not need to be done for the code to work).
Example 2
//—Inside mexFunction—
//Declarations
mxArray *xData;
double *xValues;
int i,j;
int rowLen, colLen;
double avg;
//Copy input pointer x
xData = prhs[0];
//Get matrix x
xValues = mxGetPr(xData);
rowLen = mxGetN(xData);
colLen = mxGetM(xData);
//Print the integer avg of each col to matlab console
for(i=0;i<rowLen;i++)
{
avg=0;
for(j=0;j<colLen;j++)
{
avg += xValues[(i*colLen)+j];
//Another Method:
//
//avg += *xValues++;
}
avg = avg/colLen;
printf(”The average of row %d, is %d”,i,(int)avg);
}
The function mxGetPr is used to get a pointer to the real data xData. This function takes a pointer to an mxArray as the intput paramter, and returns a pointer array of doubles. A similar function mxGetPi can be used for complex data. mxGetN and mxGetM return integers of the lengths of the row and column in the matrix. If this were an array of data, one of these return values would be zero. MATLAB gives the matrix as rows first, then columns (if you were to traverse the matrix linearly) so to jump by position, (x,y) maps to x*colLen+y. MATLAB organizes its arrays this way to reduce cache misses when the row traversal is on the outside loop. It is good to code it this way if you are working for efficiency. printf() will print out to the MATLAB command prompt.
Getting a string is very similar, but has its own method. The example below shows the procedure for getting a string. Again, I will copy the input to a pointer called yData.
Example 3
//—Inside mexFunction—
//Declarations
mxArray *yData;
int yLength;
char *TheString;
//Copy input pointer y
yData = prhs[1];
//Make “TheString” point to the string
yLength = mxGetN(yData)+1;
TheString = mxCalloc(yLength, sizeof(char)); //mxCalloc is similar to malloc in C
mxGetString(yData,TheString,yLength);
This last example shows how to get a simple integer. This is the method that has always worked for me, but it seems kind of strange so I imagine there is another way to do this.
Example 4
//—Inside mexFunction—
//Declarations
mxArray *zData;
int Num;
//Copy input pointer z
zData = prhs[2];
//Get the Integer
Num = (int)(mxGetScalar(zData));
//print it out on the screen
printf(”Your favorite integer is: %d”,Num);
Three data types have been shown here. There are several others and the MATLAB help as well as the MATLAB example code shows how to use them. Now to export the data….
Returning Data to MATLAB
Assigning return values and data to the left hand side parameters is very similar to getting the data from the last section. The difference here is that memory must be allocated for the data strucure being used on the output. Here is an example of how to return a 2-D matrix. This code will take the input x and return a copy of the matrix to z0 with every point in x multiplied by 2. Note that I am not copying the name of the output mxArray pointer into another variable.
Example 5
//—Inside mexFunction—
//Declarations
mxArray *xData;
double *xValues, *outArray;
int i,j;
int rowLen, colLen;
//Copy input pointer x
xData = prhs[0];
//Get matrix x
xValues = mxGetPr(xData);
rowLen = mxGetN(xData);
colLen = mxGetM(xData);
//Allocate memory and assign output pointer
plhs[0] = mxCreateDoubleMatrix(colLen, rowLen, mxREAL); //mxReal is our data-type
//Get a pointer to the data space in our newly allocated memory
outArray = mxGetPr(plhs[0]);
//Copy matrix while multiplying each point by 2
for(i=0;i<rowLen;i++)
{
for(j=0;j<colLen;j++)
{
outArray[(i*colLen)+j] = 2*xValues[(i*colLen)+j];
}
}
Calling Built-In Functions from a MEX-File
While it may be nice to write functions in C, there are so many useful and fast pre-written functions in MATLAB that it would be a crime if we could not use them. Luckily, The Mathworks (creators of MATLAB) has provided this capability. Built-In functions have a parameter list similar to the mexFunction itself. This example uses the built-in function z = conv(x,y);
Example 6
//—Inside mexFunction—
//Declarations
mxArray *result;
mxArray *arguments[2];
//Fill in the input parameters with some trash
arguments[0] = mxCreateDoubleMatrix(1, 20, mxREAL);
arguments[1] = mxCreateDoubleMatrix(1, 10, mxREAL);
//In the real world I imagine you would want to actually put
//some useful data into the arrays above, but for this example
//it doesnt seem neccesary.
//Call the Function
mexCallMATLAB(1,&result,2,arguments,”conv”);
//Now result points to an mxArray and you can extract the data as you please!
Compiling
Compiling the MEX-Files is similar to compiling with gcc or any other command line compiler. In the MATLAB command prompt, change your current directory to the location of the MEX source file. Type: mex filename.c into the MATLAB command window. MATLAB may ask you to choose a compiler. Choose the compiler with MATLAB in its directory path. Your function will be called with the same name as your file. (ex: mex jasonsFunction.c produces a function that can be called from MATLAB as [z0,z1] = jasonsFunction(x,y,z);)
After compiling MATLAB produces the actual MEX binary that can be called as a normal MATLAB function. To call this function, you must be in the same directory with the binary. The binary goes by different names depending what system you compiled the source on (ex: Windows=.dll MacOSX=.mexmac Solaris=.mexsol Linux=.mexlx). Your MEX-function will have to be compiled on each type of system that you want to run it on because the binaries are operating system specific.
Other Useful Functions
Here is a nice list of useful functions in the mex library that make life a lot easier. Most of these work in similar fashion to those functions described above. The full list can be found in the MATLAB help documentation with many examples. There are also some example files in the MATLAB extern directory (MATLAB/extern/examples/mx or mex).
Author:
Laska, Jason. Writing C Functions in MATLAB (MEX-Files). Connexions. 1 Aug. 2004 <http://cnx.org/content/m12348/1.2/>.
What is XML? XML, or eXtensible Markup Language, is a specification for storing information. It is also a specification for describing the structure of that information. And while XML is a markup language (just like HTML), XML has no tags of its own. It allows the person writing the XML to create whatever tags they need. The only condition is that these newly created tags adhere to the rules of the XML specification.

In the seven years since the first edition of “XML: Visual QuickStart Guide” was published, XML has taken its place next to HTML as a foundational language on the Internet. XML has become a very popular method for storing data and the most popular method for transmitting data between all sorts of systems and applications. The reason being, where HTML was designed to display information, XML was designed to manage it.
This book begins by showing you the basics of the XML language. Then, by building on that knowledge, additional and supporting languages and systems will be discussed. To get the most out of this book, you should be somewhat familiar with HTML, although you don’t need to be an expert coder by any stretch. No other previous knowledge is required.
XML Visual QuickStart Guide 2nd Edition is divided into seven parts. Each part contains one or more chapters with step-by-step instructions that explain how to perform XML-related tasks. Wherever possible, examples of the concepts being discussed are displayed, and the parts of the examples on which to focus are highlighted.
Part 1: Introduction Chapter 1: Writing XML Part 2: XSL Chapter 2: XSLT Chapter 3: XPath Patterns and Expressions Chapter 4: XPath Functions Chapter 5: XSL-FO Part 3: DTD Chapter 6: Creating a DTD Chapter 7: Entities and Notations in DTDs Chapter 8: Validation and Using DTDs Part 4: XML Schema Chapter 9: XML Schema Basics Chapter 10: Defining Simple Types Chapter 11: Defining Complex Types Part 5: Namespaces Chapter 12: XML Namespaces Chapter 13: Using XML Namespaces Part 6: Recent W3C Recommendations Chapter 14: XSLT 2.0 Chapter 15: XPath 2.0 Chapter 16: XQuery 1.0 Part 7: XML in Practice Chapter 17: Ajax, RSS, SOAP and More
XML (eXtensible Markup Language) has become the medium to move data in efficient and predictable ways.
I highly recommend this book I have had some prior exposure to xml but by no means am an expert. The writing sytle is easy to follow and the book contains plenty of examples, and tips to provide.
Great resource Mr. Goldberg writes clearly and constructively. My XML knowledge before reading this book was fuzzy at best. Now, I’m an authority on the subject. Fantastic reference.
Dont waste your time searching for other XML Books… By far one of the best XML books on the market today!! As professionals, time is money.
Very Good Book on XML I am very impressed with the book so far (need to finish). It holds true to the previous Visual QuickStart Guides that I have read in that it has tons of examples that go along.
Finally! A GOOD Beginners Guide to XML that Delivers Truth be told, I do not work as a Web developer, but on a daily basis my job has me in contact with business clients and Web application developers.
The Best Introduction to XML I’ve Found Quite simply the best introduction to XML and all the related standards which I’ve found so far. Obviously it doesn’t have the breadth and depth of, say the O’Reilly books.
C# is a new language created by Microsoft and submitted to the ECMA for standardization. This new language was created by a team of people at Microsoft led by Anders Hejlsberg . Interestingly, Hejlsberg is a Microsoft Distinguished Engineer who has created other products and languages, including Borland Turbo C++ and Borland Delphi. With C#, they focused on taking what was right about existing languages and adding improvements to make something better.
Also search Google for the following C# Links
DeveloperLand, ASP Folks, C# Games, C# Information Portal, Dot Net Buzz, DOT.NET Solutions, Learn C#, C# Crawler, Visual C#, Visual C# Community Site, Dot Net Book Reviews, Lutz Roeder’s Programming .NET, C# Arena, C# Introduction and Overview, C# Reference, C# Index, Basic C# Info, C# Home, .Net (dotnet) Tips and Tutorials
The same question is asked in other words as follows.
Here is a sample code for reading microsoft excel (MS Excel) file using C# .net.
This is application a prototype that explains using Microsoft Excel 10.0 Object Library to read excel file. With the use of this library, you can load, read and write the excel file contents.
Note: Here, I have created test.xls file which will be copied to c:\ before run the application.
Application developed using sample console application under VC# projects.
Steps:
1. Include the following reference into the project : Microsoft Excel 10.0 Object Library Microsoft Office 10.0 Object Library 2. Include the name space i.e. using Excel. 3. Creating the ExcelApplicationClass,WorkBook and Range.
Find the complete code below:
using System;
using Excel;
namespace TestExcel
{
class ExcelApplication
{
[STAThread]
static void Main(string[] args)
{
string Path = @"c:\test.xls";
// initialize the Excel Application class
Excel.ApplicationClass app = new ApplicationClass();
// create the workbook object by opening the excel file.
Excel.Workbook workBook = app.Workbooks.Open(Path,
0,
true,
5,
"",
"",
true,
Excel.XlPlatform.xlWindows,
"\t",
false,
false,
0,
true,
1,
0);
// Get The Active Worksheet Using Sheet Name Or Active Sheet
Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
int index = 0;
// This row,column index should be changed as per your need.
// that is which cell in the excel you are interesting to read.
object rowIndex = 2;
object colIndex1 = 1;
object colIndex2 = 2;
try
{
while ( ((Excel.Range)workSheet.Cells[rowIndex,colIndex1]).Value2 != null )
{
rowIndex = 2+index;
string firstName = ((Excel.Range)workSheet.Cells[rowIndex,colIndex1]).Value2.ToString();
string lastName = ((Excel.Range)workSheet.Cells[rowIndex,colIndex2]).Value2.ToString();
Console.WriteLine("Name : {0},{1} ",firstName,lastName);
index++;
}
}
catch(Exception ex)
{
app.Quit();
Console.WriteLine(ex.Message);
}
}
}
}
The same question is applicable for all other dot net (.NET) languages. The question could be rephrased as:
When populating a combobox on form load with an arraylist that contains objects of the type ABC Now after combobox is filled with the valid values, I want to have the combobox in C# change the selected item to be a specific ABC object, how do I accomplish it ?You can select the combobox item by its ValueMember
You can use: combo1.SelectedValue = YourValue This will select the item with the value "YourValue" combo1.SelectedValue = YourValue ABC abc1 = (ABC) combo1.SelectedItem Combobox.FindByText(someText).Selected = true; or Combobox.FindByValue(someValue).Selected = true;
Use the first if you want the text displayed in the combobox to find the item you want selected, use the second if you want to use the items value (mostly the ID).
Combobox.FindByText(someText).Selected = true; or Combobox.FindByValue(someValue).Selected = true;
Use the first if you want the text displayed in the combobox to find the item you want selected, use the second if you want to use the items value (mostly the ID).
or
See This: abc1.SelectedIndex = x; where x = numbe of the item in the list. or else abc1.SelectedText = string; where string = value in the combobox that you want to be selected
How do I read an xml file from URL that requires username and password to login to the page.
Use the following Code in C#
//Include the following packages using System.Net; using System.IO;
//request the particular web page
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://sharpprogrammer.com/rss.xml");
//define the login credentials of the requested file/page
request.Credentials = new NetworkCredential(”User Name”, “Password”);
//get the response from the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//create a stream to hold the contents of the response (in this case it is the contents of the XML file
Stream receiveStream = response.GetResponseStream();
//create your XML document
XmlDocument mySourceDoc = new XmlDocument();
//load the file from the stream
mySourceDoc.Load(receiveStream);
//close the stream
receiveStream.Close()
How do I get Visual Studio debugger to show me the data in the arrays? I don’t want to see just one value at a time; I want to see the values contained in array indices [100] to [199] for example.
I don’t know about other versions, but right now I’m using VS2005, and I can see the values in an array while stopped in debug mode by right clicking on the variable and selecting “Quick Watch…”
That will produce a nice little window listing all the values in the array. I’m not sure if that’s exactly what you want, but that’s the closest thing that I’m aware of.
Personally, I have to use VS everyday, and I’m convinced it’s the biggest piece of trash IDE that I’ve ever used.
One way is to specify the index in your debugger. Like arrayname[105] – that should give you the exact value at that index.
If yours were fixed length arrays, getting the value of a range would not be difficult. The debugger would then provide a small + sign beside your array object in the quick watch, and you could expand it to see all the elements.
But with free pointers, the debugger cannot do that. Becasue it does not know the length of the array. And Microsoft has taken a very tight fisted approach towards accessing out of bounds values, even in read only mode by the debugger – so it does not take any risk.
If you are so hell bent on seeing the values of a range, you have to do some little extra work dude:
Option A: Use the managed framework and declare an arraylist object, load it using your native array specifying the length. Your debugger will instantly show all the elements of the array list object expandable/ collapsible with a + sign
Option B: Write them down to a file on the hard disk ([index]:[value] format), open and inspect the file while debugging.
Option C: Declare a test only fixed length array (that you can comment later on), copy the contents of the native pointer array to it, and let the debugger do the rest.
Option D, E, F, …: Give it up. There are better things to do in life.
This is a very dangerous topic. Everyone will likely tell you that the language they work with on a regular basis is the best one to use. Same with Mac vs PC or Oracle vs SQL Server.
To choose a language you should do an analysis of your needs (requirements of your applications) and your skill set (very important). And match them to the languages features. Just having a certain skill set available could be enough of a reason to go with any of the major languages.
Here are some questions to be asked
- Is this a commercial web application to be hosted in a space.
- Ability to spend on software licenses
- Ability to maintain.
- The decision of programming language should consider the clients ability to spend on infrastructure.
ASP.NET/C# is one of the best recommendation people would give. C# is the future language and programmers love it. It accelerates the development cycle, and the recommended language for the Web. There are plenty of examples.
Easiest tool for web app with MS SQL is ASP.Net with C# or VB.Net.But the catch is if the client ready to invest for Server license and mainintenance
The other option is to go for jsp which is open source and doesnt require server licenses but application development would be slow so as maintenance.
Also look at ColdFusion : http://www.adobe.com/products/coldfusion/
If you are comfortable with javascript syntax, it won’t be difficult to pickup C#. If you are comfortable with VBScript, then it won’t be difficult to pickup VB.Net. There is a higher demand for C# developers than VB.NET in the job market.
If you’re an experienced developer or a manager, it helps to consider these, when choosing a platform:
- Longetivity. How long is the technology valid?
- Development cycle time.
- Deployment time.
- Compatibility issues with other OS.
a minimum of these. If you go by that, asp.net/C# is the future.
Head First Java, 2nd Edition by Kathy Sierra, Bert Bates
Book Description
Learning a complex new language is no easy task especially when it s an object-oriented computer programming language like Java. You might think the problem is your brain. It seems to have a mind of its own, a mind that doesn’t always want to take in the dry, technical stuff you’re forced to study.

The fact is your brain craves novelty. It’s constantly searching, scanning, waiting for something unusual to happen. After all, that’s the way
it was built to help you stay alive. It takes all the routine, ordinary, dull stuff and filters it to the background so it won’t interfere with your brain’s real work–recording things that matter. How does your brain know what matters? It’s like the creators of the Head First approach say, suppose you’re out for a hike and a tiger jumps in front of you, what happens in your brain? Neurons fire. Emotions crank up. Chemicals surge.
That’s how your brain knows.
And that’s how your brain will learn Java. Head First Java combines puzzles, strong visuals, mysteries, and soul-searching interviews with famous Java objects to engage you in many different ways. It’s fast, it’s fun, and it’s effective. And, despite its playful appearance, Head First Java is serious stuff: a complete introduction to object-oriented programming and Java. You’ll learn everything from the fundamentals to advanced topics, including threads, network sockets, and distributed programming with RMI. And the new. second edition focuses on Java 5.0, the latest version of the Java language and development platform. Because Java 5.0 is a major update to the platform, with deep, code-level changes, even more careful study and implementation is required. So learning the Head First way is more important than ever.
If you’ve read a Head First book, you know what to expect–a visually rich format designed for the way your brain works. If you haven’t, you’re in for a treat. You’ll see why people say it’s unlike any other Java book you’ve ever read.
By exploiting how your brain works, Head First Java compresses the time it takes to learn and retain–complex information. Its unique approach not only shows you what you need to know about Java syntax, it teaches you to think like a Java programmer. If you want to be bored, buy some other book. But if you want to understand Java, this book’s for you.
An Amazing Achievment
Who do Kathy Sierra and Bert Bates think they are? Don’t they know that learning a programming language is supposed to be hard? Don’t they know that it is supposed to involve suffering? Apparently not, as they have written a complete introduction to Java that is fun to read and easy to understand. If we don’t stamp this out now, students will start expecting their teachers to be entertaining!
The book is an excellent introduction to Java. It covers all the typical topics of a basic introductory text and some extra including serialization, networking, and distributed computing. Each topic is covered in a fun way with important information highlighted. The authors use stories, fake interviews, pictures, and assorted other clever techniques to catch your imagination and make the topics memorable. There are plenty of exercises (with answers) to help you check to be sure you understood each chapter. And there are plenty of fun programs to code including a cool music machine instead of the typical “reverse a String” exercises.