[proFit-list] Reading binary files
pro Fit Support
profit at quansoft.com
Thu Oct 30 00:58:08 CDT 2008
Dear Davide
You need to create a plug-in to import binary files. The sources of
the importers that come with pro Fit are not public, so we cannot
share them. But you can start from the example plug-in that comes with
pro Fit (Example Files/Programming 7 - plug-ins/Sources/C/Example
Plugin).
You proceed basically as follows:
1. Duplicate the Example Plugin directory. Rename the directory as it
suits you (e.g. MyImporter)
2. Modify MyImporter:
2a) In main.c, change the function SetUp to return isProgram in
*moduleKind and to return a good name for your plug-in
2b) In main.c, change the function Run to import the file. It could
e.g. look like this:
Boolean mustCloseFile=false; // true if we have opened file
short refNum; // file reference number
FSRef fileRef;
ByteCount size;
HFSUniStr255 dataForkName; // the name of the data fork, to be used
when opening a file with FSRefOpenFork
// let the user choose the file
if (!MyGetFileRef(&fileRef, '****', '****'))
goto done; // if user hit cancel or some other evil thing happened.
// open the file
FSGetDataForkName(&dataForkName);
if (FSOpenFork(&fileRef, dataForkName.length, dataForkName.unicode,
fsRdPerm, &refNum) != noErr) goto done;
mustCloseFile = true;
// create a new data window, e.g.
BeginCommand("\pNewDataWindow");
AddDoubleParam("\pnrRows", 1000);
AddDoubleParam("\pnrCols", 3);
EndCommand();
// read your file, e.g. an 8 byte double and write it to cell 1/1 of
the data window
double d;
if (FSReadFork(refNum, fsAtMark, 0, 8, &d, &size) != noErr) goto done;
SetData(1, 1, d);
done:
if (mustCloseFile) FSCloseFork(refNum);
The function MyGetFileRef is defined in the file ModuleUtilities.c,
which can be found at Example Files/Programming 7 - plug-ins/Utilities/
C/. You need to at that and its header file to the project.
Note: I have not tried to compile the above, so it may need some minor
corrections. But I hope that this will help you to get started.
Regards
Kurt
On 30.10.2008, at 05:56, Davide Guarisco wrote:
> Hello,
> I need to read data files in binary format. How can I do this in
> pro Fit? Do I need to write a plug-in or is there some programming
> functions that I can use?
>
> I looked at the pro Fit plug-ins>Plug-Ins written in C>Data import
> folder, and there are some plug-ins that do import binary files. The
> problem is that there is no source code for these plug-ins.
>
> Thanks,
> Davide
> --
> Davide Guarisco_______________________________________________
> proFit-list mailing list
> proFit-list at quantum-soft.com
> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com
Best regards
Kurt Sutter
QuantumSoft
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://quantum-soft.com/pipermail/profit-list_quantum-soft.com/attachments/20081030/35efacf5/attachment.html>
More information about the proFit-list
mailing list