Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Saturday, August 22, 2009

Creating a shared library on various platforms

When applications get bigger and code needs to be shared among different applications, then shared libraries sound like a great idea. To get this done, a multi platform compilation sprint race begins.

Shared libraries are libraries that are loaded by programs when they start. When a shared library is installed properly, all programs that start afterwards automatically use the new shared library. It's actually much more flexible and sophisticated than this, because ... [read more]
The library had to be compiled for Linux, Windows, Mac OS X, AIX, HP-UX, Sun OS and Solaris. Internet search engines along with compiler man pages are the best tools for the job. By looking around, I found the following links useful:

Linux:
AIX:
Mac OS X:
Sun OS, Solaris
HP-UX:
Creation of the shared lib was done for a mid-sized project. The library's build process was based on gmake for Unix and gmake and nmake on Windows. The main application's build system also needed adjustments to use the new library. This is also described in the links above.

Sunday, July 19, 2009

femio - A python reader for Finite Element Models

femio is an application that allows you to read a Finite Element Model in one of the supported formats and provide tools and functions on the model's contents. Also, it provides the required functionality to allow the user to create tools and manipulate data. Such tools are: model statistics, model image view (screen shot), keyword removal or substitution, etc.

You can see the projects home page here: femio

Femio is based on an older project of mine: abq2img. Recently, I had the need of converting an ABAQUS input model containing *PARAMETER keywords. I used the abq2img codebase and with minimal work, I was able to achieve my goal. Based on that success, I decided to revive the project and extend its functionality and capabilities to over FEM formats.

Its main advantage is that it provides the low level parsing for FE models. This allows the user to manipulate model data while not having to parse the file and provide support for keywords. Thus creating model previews in PNG format is quite easy:


Saturday, April 18, 2009

Blogger Tag Cloud Widget

I wanted to have a Tab Cloud in my blog. However, blogger provides only the Label widget which gives only a list of the blog's labels.

I found this blog entry , which produced something very similar to what I wanted. I modified it so that:

  • it is more to my taste
  • allows for further development and easier modifications.

You can see the resulting Tag Cloud on this blog (collumn on the right) and also in http://www.papitsa.gr/

The installation instructions can be found in the original post.




<b:widget id='Label1' locked='false' title='Tags' type='Label'>
<b:includable id='main'>
<b:if cond='data:title'>
<h2><data:title/></h2>
</b:if>
<div class='widget-content' style='text-align: center;'>
<script type='text/javascript'>
/*
Simple Blogger Tag Cloud Widget
by Raymond May Jr.
http://www.compender.com
Released to the Public Domain
Modified by Michalis Giannakidis :
o) tune parameters to my likes
o) modifications to allow more flexibility in formatting of tags and
allow further development.
*/
//Variables:
var max = 130; //max css size (in percent)
var min = 70; //min css size (...)
var showCount = 1; // show counts? 1 for yes
var minCount = 1; // what is the minimum count for a Tag to be shown? 1 for all.

//Begin code:
var range = max - min;

function labelObj() {}

//Build label Array
var lb = new Array();

var most = 1;
<b:loop values='data:labels' var='label'>
var item = new labelObj();
item.label = (&quot;<data:label.name/>&quot;);
item.url = (&quot;<data:label.url/>&quot;);
item.count = (&quot;<data:label.count/>&quot;);
lb.push(item);

if ( most &lt; &quot;<data:label.count/>&quot; ) {
most = (&quot;<data:label.count/>&quot;);
}
</b:loop>


//Labels sort, ignore case
function sortLabels(a, b) {

aa = a.label.toLowerCase();
bb = b.label.toLowerCase();
if ( aa &lt; bb ) {
return -1;
} else if ( aa &gt; bb ) {
return 1;
} else {
return 0;
}
}
lb.sort(sortLabels);


//Begin HTML output
for (x in lb) {
if(x != &quot;peek&quot; &amp;&amp; x != &quot;forEach&quot;
&amp;&amp; lb[x].count &gt;= minCount){

//Calculate textSize
var textSize = min + Math.floor((lb[x].count/most) * range);
//Show counts?
if(showCount == 1) {
var count = &quot;(&quot; + lb[x].count + &quot;)&quot;;
}else{
var count = &quot;&quot;;
}
//Output
document.write(&quot;<span style='font-size:&quot; + textSize +
&quot;%'><a href='&quot; + lb[x].url + &quot;'>&quot; + lb[x].label +
count + &quot;</a></span> &quot; );
}

}
</script>
<b:include name='quickedit'/>
</div>
</b:includable>
</b:widget>

Thursday, May 01, 2008

Remove obsolete objects form a library archive using GNU make


The build system of an application I work on, stores each compilation object in a library archive (using GNU ar). With every project build, the contents of this archive are updated with new objects from the compilation. This is achieved by running ar -cru library.a $(OBJECTS)

Moreover, the archive needs also to be updated when files (and thus their objects) are removed from the project. The most convenient phase for this to happen is during the build.

The required archive updating, can be performed with the following part in the Makefile (consider this a template, since it cannot be used as is)

Makefile


obj: $(OBJECTS)
ifneq (,$(filter-out $(OBJECTS),$(wildcard $(OBJECT_DIR)*.o)))
$(warning "Deleting unused object files...")
ifeq (ar,$(firstword $(AR)))
-$(firstword $(AR)) -d $(LIBRARY) $(filter-out $(OBJECTS),$(wildcard $(OBJECT_DIR).o))
else
$(warning $(LIBRARY) may contain obsolete objects: $(filter-out $(OBJECTS),$(wildcard $(OBJECT_DIR)*.o)))
endif
rm -f $(filter-out $(OBJECTS),$(wildcard $(OBJECT_DIR)*.o))
rm -f $(filter-out $(OBJECTS:.o=.d),$(wildcard $(OBJECT_DIR)*.d))
endif


The above assumes that you are using GNU make and GNU ar. Also, dependencies are stored per source file, along with the objects and removed with them.

With the auto removal of objects, manual update or full rebuild of the archive is unnecessary. Also, headaches and hard to track errors, coming from doubly defined functions in the archive and obsolete code being used, are avoided.

Tuesday, April 22, 2008

Release cvsxxdiff v1.5

cvsxxdiff version 1.5 was released today.

In this release many significant changes are introduced, as you can see from the ChangeLog. At the moment, there are no plans for a new project version with major features.

Saturday, March 29, 2008

Αποστολή SMS από τη γραμμή εντολών

Από τα πρώτα προγράμματα που έγραψα σε C ήταν το mycosmos, ένα πρόγραμμα αποστολής SMS από τη γραμμή εντολών μέσω μιας web υπηρεσίας.

Όμως ο καιρός πέρασε, η web υπηρεσία άλλαξε και το mycosmos έπαψε να δουλεύει. Έτσι τον Δεκέμβριο του 2007 το ξαναέγραψα από την αρχή, δημιουργώντας αυτή τη φορά το climycosmos.

Η έκδοση 0.4 του climycosmos είναι αρκετά πλήρης. Είναι απολύτος αυτόνομη από εξωτερικές εξαρτήσεις και πλήρως παραμετροποιήσιμη για καθημερινή χρήση. Τις παράμετρους αποτελούν:
i) ο λογαριασμός χρήστη και οι κωδικοί εισόδου μέσω του οποίου θα αποσταλεί το μήνυμα
ii) ο ονομαστικός προσδιορισμός του παραλήπτη, μέσω ενός στοιχειώδους τηλεφωνικού ευρετηρίου
Τα παραπάνω αποτελόυν ιδιαίτερα σημαντικά γνωρίσματα, απαραίτητα κατά την γνώμη μου, που δίνουν μεγάλη ευχρηστία στην εφαρμογή.

Όλες οι παράμετροι του προγράμματος ορίζονται από τον χρήστη και αποθηκεύονται σε ένα αρχείο κειμένου με όνομα .climycosmos.ini Η μορφή του αρχείου είναι εξαιρετικά απλή και ξεκάθαρη:


[Default]
username: 69XXXXXXXX
password: XXXXXXXX

[account2]
username: 69XXXXXXXX
password: XXXXXXXX

[Phonebook]
contact1: 69XXXXXXXX
contact2: 69XXXXXXXX
contact3: 69XXXXXXXX

Μέσω αυτής της παραμετροποίησης καθίσταται δυνατή η αποστολή μυνημάτων από τη γραμμή εντολών με τις ελάχιστες δυνατές παραμέτρους, πχ:
climycosmos -t contact1 -m "Γεια σου". 
Ασφαλώς το σύνολο των παραμέτρων μπορούν να περάσουν και άμεσα από την γραμμή εντολών.

Το climycosmos διανέμεται δωρεάν, κάτω από την GPLv2 άδεια χρήσης.

Tuesday, March 11, 2008

Report compilation total time using GNU make


When working constantly on the same application, it is very useful to have an idea of the time it takes to compile. Having this information allows you to plan your work ahead, compare machines, developing environments, etc.

I have put together this Makefile, to print the total compilation time. It requires gmake and the UNIX shell utilities date, bc, echo and printf.


Makefile


# Time expressed as the seconds of the year. More portable than seconds since
# the epoch: `date +%s'
COMPILE_START_TIME := $(shell date +\(%j\*24\*60\*60+%H\*60\*60+%M\*60+%S\))
COMPILE_CURRENT_TIME = `date +\(%j\*24\*60\*60+%H\*60\*60+%M\*60+%S\)`


# Print the time difference between Tcurrent and Tstart. This function can be
# used after any target, as shown in the form: (see example)
# $(call print_timer,$(COMPILE_CURRENT_TIME),$(COMPILE_START_TIME))

# args: Tcurrent = $(1), Tstart = $(2)
define print_timer
@CT=$(1) && \
printf "Compilation total time: %.2d:%.2d (min:sec)\n" \
`echo "($$CT - $(2))/60" | bc` \
`echo "($$CT - $(2))%60" | bc`
endef


all: target

target:
@echo "Compiling for 2 seconds ..." && sleep 2 && echo Done
$(call print_timer,$(COMPILE_CURRENT_TIME),$(COMPILE_START_TIME))


Using this Makefile and running make, produces the following output:


Compiling for 2 seconds ...
Done
Compilation total time: 00:02 (min:sec)