visualdatatools.com Forum Index visualdatatools.com
Discussion for DataTank and DataGraph
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

progress indicator

 
Post new topic   Reply to topic    visualdatatools.com Forum Index -> Using External Programs
View previous topic :: View next topic  
Author Message
Adam



Joined: 01 Dec 2006
Posts: 61
Location: Sequim, WA

PostPosted: Wed Jun 13, 2007 1:01 pm    Post subject: progress indicator Reply with quote

How does the progress indicator determine its duration? I'm running an external program that converts the GSHHS to a 2D path, but the progress indicator in DataTank seems to be somewhat random (or maybe based on the last time that task was run?). Is there a way to update it via DTProgress?
Back to top
View user's profile Send private message
stschiff



Joined: 04 Mar 2009
Posts: 34
Location: Cologne, Germany

PostPosted: Fri Jan 08, 2010 7:37 am    Post subject: Reply with quote

was there an answer to that question? Is there a way of controlling the progress indicator during program execution?

Stephan
Back to top
View user's profile Send private message
Adam



Joined: 01 Dec 2006
Posts: 61
Location: Sequim, WA

PostPosted: Fri Jan 08, 2010 1:27 pm    Post subject: Reply with quote

I never found a way to control it; I think it's just based off of the last time a task was run, unless you use a Task Group (which has a DTProgress you can update).
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1940
Location: Chapel Hill, NC

PostPosted: Sat Jan 09, 2010 2:01 am    Post subject: Reply with quote

The beta should do this now.

David
Back to top
View user's profile Send private message Send e-mail
stschiff



Joined: 04 Mar 2009
Posts: 34
Location: Cologne, Germany

PostPosted: Sat Jan 09, 2010 7:34 am    Post subject: Reply with quote

Hmm, OK, I appreciate that the module uses past runs, this should already do it for me. But I did not quite get the DTProgress-thing... is that a file? where should that be located and in which format?

Thanks,

Stephan


P.S. I realize that using DTSource would save me some of these questions, but using C++ is not an option for me. My programs use Frameworks written in C and Obj-C, and once I start using C++ in only the last step I still have to recompile everything in Obj-C++, which results in several incompatibilities.
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1940
Location: Chapel Hill, NC

PostPosted: Sat Jan 09, 2010 10:20 am    Post subject: Reply with quote

DTProgress is simple. Just create a file called "DTProgress" in the working directory and write to it. DataTank looks at how many characters are in that file and uses that as percent. The simplest approach is to open a file and append an "x" every time you get one percent further along. The DTProgress class just does that and is part of DTSource.

Regarding your code. Are you using XCode? Putting C++ calls into your C/Objective-C calls does require you to convert to C++ and there can be issues there. If nothing else a lot of extern "C" declarations that can be tricky to chase down. But if you are using XCode to compile your project this is not that hard. In particular if you are using Objective-C, since that allows you to define objects. I've thought about adding other interfaces than DTSource, in particular for Python and Objective-C since they will allow objects. I am hesitant to support raw C, and personally I advocate that your top level be in an object oriented language (Objetive-C/Objective-C++/C++/Python) and the low level in C. This is how DataTank and DataGraph are designed.

So let me know if you are using Objective-C for the code that wants to save data to a file.

David
Back to top
View user's profile Send private message Send e-mail
Adam



Joined: 01 Dec 2006
Posts: 61
Location: Sequim, WA

PostPosted: Sat Jan 09, 2010 5:23 pm    Post subject: Reply with quote

David wrote:

I've thought about adding other interfaces than DTSource, in particular for Python and Objective-C since they will allow objects. I am hesitant to support raw C, and personally I advocate that your top level be in an object oriented language (Objetive-C/Objective-C++/C++/Python) and the low level in C. This is how DataTank and DataGraph are designed.
David


I typically use Obj-C++ with DTSource, and haven't had any problems other than my weak C++-fu. That lets me mix CoreFoundation, CoreGraphics, and Cocoa easily with DTSource. I also link against C libraries for geospatial stuff (libgeotiff, libgdal) and mix with DTSource plugins.

Python bindings for DTSource would be way cool. I looked at doing that with swig once upon a time, but it was beyond my knowledge...I ended up writing Matlab v4 files from python with the DataTank naming conventions. Writing netCDF from python is also a good option, if you don't need the DTSource objects. But this is probably for a new thread Smile.
Back to top
View user's profile Send private message
stschiff



Joined: 04 Mar 2009
Posts: 34
Location: Cologne, Germany

PostPosted: Sat Jan 09, 2010 11:34 pm    Post subject: Reply with quote

OK, thanks for explaining the DTProgress thing. Seems to be fairly easy.

About Objective-C:
David wrote:
But if you are using XCode to compile your project this is not that hard. In particular if you are using Objective-C, since that allows you to define objects. I've thought about adding other interfaces than DTSource, in particular for Python and Objective-C since they will allow objects. I am hesitant to support raw C, and personally I advocate that your top level be in an object oriented language (Objetive-C/Objective-C++/C++/Python) and the low level in C. This is how DataTank and DataGraph are designed.


Of course I use object oriented design all along my programs. I even have classes for converting single numbers (double) and arrays (double *, i.e. NSData) to the dtascii-format. So I am already substituting C++-DTSource with a rudimentary object oriented ObjC-API. So far I support Real Numbers, NumberLists, Arrays and Plot1Ds, all time-dependent if necessary. This makes communication between my simulation and DataTank already fairly straight forward.

I could still use DTSource in C++, since I do indeed use XCode, and setting "compile sources as Objective-C++" in the build settings does make including C++ possible. But as I said, much of the numerical stuff resides in self-made frameworks written in Obj-C and C, and I just decided to keep these dependencies clean with respect to C++. This is probably very strict but I find it easier to stick with one paradigm of object-oriented language and design, and so far this attitude helped me in keeping my code simple and intuitive.

Stephan
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1940
Location: Chapel Hill, NC

PostPosted: Sat Jan 09, 2010 11:45 pm    Post subject: Reply with quote

Just specify the ending .mm for Objective-C++ files. I wouldn't compile everything as Objective-C++.

Here is a standard trick that I use
Code:

#ifdef __cplusplus
class DTDoubleArray;
#else
// Need this just so that Objective-C knows this is a pointer
@class DTDoubleArray;
#endif

@interface DoubleArrayContainer : NSObject
{
    DTDoubleArray *array;
}

#ifdef __cplusplus
// Need to be Objective-C++ to create the object
+ (DoubleArrayContainer *)createArrayWithObject:(DTDoubleArray)dArray;
#endif
- (int)m;

@end


The implementation is inside a .mm file, and with something like
Code:

- (id)initWithObject:(DTDoubleArray)dArray
{
    [super init];

    array = new DTDoubleArray(dArray);

    return self;
}

+ (DoubleArrayContainer *)createArrayWithObject:(DTDoubleArray)dArray
{
    return [[[DoubleArrayContainer alloc] initWithObject:dArray] autorelease];
}

- (int)m
{
    return array->m();
}


#endif


You can pass DTDoubleArray objects in and out but only in C++.

David
Back to top
View user's profile Send private message Send e-mail
stschiff



Joined: 04 Mar 2009
Posts: 34
Location: Cologne, Germany

PostPosted: Sun Jan 10, 2010 6:54 am    Post subject: Reply with quote

David wrote:
Just specify the ending .mm for Objective-C++ files. I wouldn't compile everything as Objective-C++.
David


Hmm, I don't quite understand.
I have a main.m file, which I could rename to main.mm. This file contains the main routine which links against several other frameworks written in Objective-C. So once I rename main.m to main.mm, it expects that all linked frameworks are also compiled as objective-C++. So then I do have to recompile all frameworks as Objective-C++, I guess this is also pointed out in the developer documentation. Apart from that, I also get a flood of compiler errors only due to declarations in imported headers, which result from several incompatibilities between the C-complex type and the C++-complex type. I would have to through my frameworks and change a lot of little things to make sure things are Objective-C++ compatible.

So how could I use your trick and change the ending to .mm without the need to change all the linked frameworks?

Stephan
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1940
Location: Chapel Hill, NC

PostPosted: Tue Jan 12, 2010 11:32 pm    Post subject: Reply with quote

You don't have to have everything as C++. If you include the header from a .m file (i.e. Objective-C) you need to hide the C++ classes and I do that with the #ifdef __cplusplus statement. I need however to make sure that the Objective-C part knows the size of the object in case Objective-C wants to use it as a base class. I hide completely the methods that take a C++ object as an argument or return a C++ class.


David
Back to top
View user's profile Send private message Send e-mail
David
Site Admin


Joined: 25 Nov 2006
Posts: 1940
Location: Chapel Hill, NC

PostPosted: Wed Jan 13, 2010 11:24 am    Post subject: Reply with quote

I made an example project
http://www.visualdatatools.com/DataTank/SupportFiles/ObjectiveCWrapper.zip
This is also on the help site. So go to the help page for the external program module either from an external module or by navigating to it:

External Program Module/XCode Examples/Objective-C/

David
Back to top
View user's profile Send private message Send e-mail
stschiff



Joined: 04 Mar 2009
Posts: 34
Location: Cologne, Germany

PostPosted: Wed Jan 13, 2010 1:39 pm    Post subject: Reply with quote

This is really great. Thanks for the helpful example.

Stephan
Back to top
View user's profile Send private message
stschiff



Joined: 04 Mar 2009
Posts: 34
Location: Cologne, Germany

PostPosted: Fri Jan 15, 2010 6:06 am    Post subject: Reply with quote

Why do you declare int main(...) as extern "C"?
as I can see, it works also without that extern "C"...

Stephan
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1940
Location: Chapel Hill, NC

PostPosted: Fri Jan 15, 2010 4:11 pm    Post subject: Reply with quote

You are right. It is already defined as extern, otherwise main.cpp would have to do that.

I will remove that. What I should instead say is that if you have a function defined using Objective-C++ you need to declare it using the extern C if you want to use it from Objective-C. But I don't have any functions like that in the project.

David
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    visualdatatools.com Forum Index -> Using External Programs All times are GMT - 3 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group