Hi,
I have changed the phdemo.c into Origin C code, which is now able to be compiled successfully. However, there is no data file in my hand, no testing yet. You can refer to it for the change of other two C code files.
#include <Origin.h>
#include <GetNBox.h>
#define DISPCURVES 8
#define MAXCURVES 512
#define MAXCHANNELS 65536
/* These are substructures used below */
typedef struct
{
float Start;
float Step;
float End;
} tParamStruct;
typedef struct
{
int MapTo;
int Show;
} tCurveMapping;
/* The following represents the readable ASCII file header portion */
#define TXTHDR_SIZE_IDENT 16
#define TXTHDR_SIZE_FORMAT_VERSION 6
#define TXTHDR_SIZE_CREATOR_NAME 18
#define TXTHDR_SIZE_CREATOR_VERSION 12
#define TXTHDR_SIZE_FILE_TIME 18
#define TXTHDR_SIZE_CRLF 2
#define TXTHDR_SIZE_COMMENT_FIELD 256
typedef struct
{
char Ident[TXTHDR_SIZE_IDENT]; //"PicoHarp 300"
char FormatVersion[TXTHDR_SIZE_FORMAT_VERSION]; //file format version
char CreatorName[TXTHDR_SIZE_CREATOR_NAME]; //name of creating software
char CreatorVersion[TXTHDR_SIZE_CREATOR_VERSION]; //version of creating software
char FileTime[TXTHDR_SIZE_FILE_TIME];
char CRLF[TXTHDR_SIZE_CRLF];
char CommentField[TXTHDR_SIZE_COMMENT_FIELD];
} _TxtHdr;
_TxtHdr TxtHdr;
/* The following is binary file header information */
#define BINHDR_SIZE_SCRIPT_NAME 20
typedef struct
{
int Curves;
int BitsPerHistoBin;
int RoutingChannels;
int NumberOfBoards;
int ActiveCurve;
int MeasMode;
int SubMode;
int RangeNo;
int Offset;
int Tacq; // in ms
int StopAt;
int StopOnOvfl;
int Restart;
int DispLinLog;
int DispTimeFrom; // 1ns steps
int DispTimeTo;
int DispCountsFrom;
int DispCountsTo;
tCurveMapping DispCurves[DISPCURVES];
tParamStruct Params[3];
int RepeatMode;
int RepeatsPerCurve;
int RepeatTime;
int RepeatWaitTime;
char ScriptName[BINHDR_SIZE_SCRIPT_NAME];
} _BinHdr;
_BinHdr BinHdr;
/* The next is a board specific header */
#define BOARDHDR_HARDWARE_IDENT 16
#define BOARDHDR_HARDWARE_VERSION 8
typedef struct
{
char HardwareIdent[BOARDHDR_HARDWARE_IDENT];
char HardwareVersion[BOARDHDR_HARDWARE_VERSION];
int HardwareSerial;
int SyncDivider;
int CFDZeroCross0;
int CFDLevel0;
int CFDZeroCross1;
int CFDLevel1;
float Resolution;
//below is new in format version 2.0
int RouterModelCode;
int RouterEnabled;
int RtChan1_InputType;
int RtChan1_InputLevel;
int RtChan1_InputEdge;
int RtChan1_CFDPresent;
int RtChan1_CFDLevel;
int RtChan1_CFDZeroCross;
int RtChan2_InputType;
int RtChan2_InputLevel;
int RtChan2_InputEdge;
int RtChan2_CFDPresent;
int RtChan2_CFDLevel;
int RtChan2_CFDZeroCross;
int RtChan3_InputType;
int RtChan3_InputLevel;
int RtChan3_InputEdge;
int RtChan3_CFDPresent;
int RtChan3_CFDLevel;
int RtChan3_CFDZeroCross;
int RtChan4_InputType;
int RtChan4_InputLevel;
int RtChan4_InputEdge;
int RtChan4_CFDPresent;
int RtChan4_CFDLevel;
int RtChan4_CFDZeroCross;
} _BoardHdr;
_BoardHdr BoardHdr;
/* The following are the curve headers */
#define CURVEHDR_HARDWARE_IDENT 16
#define CURVEHDR_HARDWARE_VERSION 8
typedef struct
{
int CurveIndex;
unsigned long TimeOfRecording; //this is a time_t
char HardwareIdent[CURVEHDR_HARDWARE_IDENT];
char HardwareVersion[CURVEHDR_HARDWARE_VERSION];
int HardwareSerial;
int SyncDivider;
int CFDZeroCross0;
int CFDLevel0;
int CFDZeroCross1;
int CFDLevel1;
int Offset;
int RoutingChannel;
int ExtDevices;
int MeasMode;
int SubMode;
float P1;
float P2;
float P3;
int RangeNo;
float Resolution;
int Channels;
int Tacq;
int StopAfter;
int StopReason;
int InpRate0;
int InpRate1;
int HistCountRate;
__int64 IntegralCount;
int reserved;
int DataOffset;
//below is new in format version 2.0
int RouterModelCode;
int RouterEnabled;
int RtChan_InputType;
int RtChan_InputLevel;
int RtChan_InputEdge;
int RtChan_CFDPresent;
int RtChan_CFDLevel;
int RtChan_CFDZeroCross;
} _CurveHdr;
_CurveHdr CurveHdr[MAXCURVES];
/* This is the count data of one curve */
unsigned int Counts[MAXCHANNELS];
void test_phdemo()
{
GETN_TREE(tr)
GETN_BUTTON(inputFile, "Input File", "")
GETN_OPTION_EVENT(inputFile_event)
GETN_BUTTON(outputFile, "Output File", "")
GETN_OPTION_EVENT(outputFile_event)
GetNBox(tr);
string strInputFile = tr.inputFile.strVal;
string strOutputFile = tr.outputFile.strVal;
if(phdemo(strInputFile, strOutputFile) == 0)
printf("\nsuccessful!\n");
}
bool inputFile_event(TreeNode& tr, int nRow, int nType, Dialog& dlg)
{
if(TRGP_STR_BUTTON == nType && nRow ==0)
{
string strFile;
vector<string> vsTypes = {"[Binary PicoHarp 300 Data File] *.*"};
if(!okutil_FileDialog(&strFile, false, &vsTypes))
{
return false;
}
tr.inputFile.strVal = strFile;
return true;
}
else
return false;
}
bool outputFile_event(TreeNode& tr, int nRow, int nType, Dialog& dlg)
{
if(TRGP_STR_BUTTON == nType && nRow == 1)
{
string strFile;
vector<string> vsTypes = {"[ASCII File] *.*"};
if(!okutil_FileDialog(&strFile, false, &vsTypes))
{
return false;
}
tr.outputFile.strVal = strFile;
return true;
}
else
return false;
}
int phdemo(string strInputFile, string strOutputFile)
{
FILE* fpin;
FILE* fpout;
int i, j, result;
printf("\nPicoHarp File Demo");
printf("\n~~~~~~~~~~~~~~~~~~");
if((fpin = fopen(strInputFile, "rb")) == NULL)
{
printf("\ncannot open input file\n");
return -1;
}
if((fpout = fopen(strOutputFile, "w")) == NULL)
{
closeFiles(fpin, fpout);
printf("\ncannot open output file\n");
return -1;
}
result = fread(&TxtHdr, 1, sizeof(TxtHdr), fpin);
if(result != sizeof(TxtHdr))
{
closeFiles(fpin, fpout);
printf("\nerror reading txt header, aborted.");
return -1;
}
fprintf(fpout, "Ident : %.*s\n", TXTHDR_SIZE_IDENT, TxtHdr.Ident);
fprintf(fpout, "Format Version : %.*s\n", TXTHDR_SIZE_FORMAT_VERSION, TxtHdr.FormatVersion);
fprintf(fpout, "Creator Name : %.*s\n", TXTHDR_SIZE_CREATOR_NAME, TxtHdr.CreatorName);
fprintf(fpout, "Creator Version : %.*s\n", TXTHDR_SIZE_CREATOR_VERSION, TxtHdr.CreatorVersion);
fprintf(fpout, "Time of Creation : %.*s\n", TXTHDR_SIZE_FILE_TIME, TxtHdr.FileTime);
fprintf(fpout, "File Comment : %.*s\n", TXTHDR_SIZE_COMMENT_FIELD, TxtHdr.CommentField);
if(strncmp(TxtHdr.FormatVersion, "2.0", 3))
{
closeFiles(fpin, fpout);
printf("\nError: File format version is %s. This program is for v. 2.0 only.", TxtHdr.FormatVersion);
return -1;
}
result = fread(&BinHdr, 1, sizeof(BinHdr), fpin);
if(result != sizeof(BinHdr))
{
closeFiles(fpin, fpout);
printf("\nerror reading bin header, aborted.");
return -1;
}
fprintf(fpout, "No of Curves : %ld\n", BinHdr.Curves);
fprintf(fpout, "Bits per HistoBin: %ld\n", BinHdr.BitsPerHistoBin);
fprintf(fpout, "RoutingChannels : %ld\n", BinHdr.RoutingChannels);
fprintf(fpout, "No of Boards : %ld\n", BinHdr.NumberOfBoards);
fprintf(fpout, "Active Curve : %ld\n", BinHdr.ActiveCurve);
fprintf(fpout, "Measurement Mode : %ld\n", BinHdr.MeasMode);
fprintf(fpout, "Sub-Mode : %ld\n", BinHdr.SubMode);
fprintf(fpout, "Range No : %ld\n", BinHdr.RangeNo);
fprintf(fpout, "Offset : %ld\n", BinHdr.Offset);
fprintf(fpout, "AcquisitionTime : %ld\n", BinHdr.Tacq);
fprintf(fpout, "Stop at : %ld\n", BinHdr.StopAt);
fprintf(fpout, "Stop on Ovfl. : %ld\n", BinHdr.StopOnOvfl);
fprintf(fpout, "Restart : %ld\n", BinHdr.Restart);
fprintf(fpout, "DispLinLog : %ld\n", BinHdr.DispLinLog);
fprintf(fpout, "DispTimeAxisFrom : %ld\n", BinHdr.DispTimeFrom);
fprintf(fpout, "DispTimeAxisTo : %ld\n", BinHdr.DispTimeTo);
fprintf(fpout, "DispCountAxisFrom: %ld\n", BinHdr.DispCountsFrom);
fprintf(fpout, "DispCountAxisTo : %ld\n", BinHdr.DispCountsTo);
for(i = 0; i < DISPCURVES; ++i)
{
fprintf(fpout, "---------------------\n");
fprintf(fpout, "Curve No %1d\n", i);
fprintf(fpout, " MapTo : %ld\n", BinHdr.DispCurves[i].MapTo);
if(BinHdr.DispCurves[i].Show != 0)
{
fprintf(fpout, " Show : true\n");
}
else
{
fprintf(fpout, " Show : false\n");
}
fprintf(fpout, "---------------------\n");
}
for(i = 0; i < 3; ++i)
{
fprintf(fpout, "---------------------\n");
fprintf(fpout, "Parameter No %1d\n", i);
fprintf(fpout, " Start : %f\n", BinHdr.Params[i].Start);
fprintf(fpout, " Step : %f\n", BinHdr.Params[i].Step);
fprintf(fpout, " End : %f\n", BinHdr.Params[i].End);
fprintf(fpout, "---------------------\n");
}
fprintf(fpout, "Repeat Mode : %ld\n", BinHdr.RepeatMode);
fprintf(fpout, "Repeats per Curve: %ld\n", BinHdr.RepeatsPerCurve);
fprintf(fpout, "Repeat Time : %ld\n", BinHdr.RepeatTime);
fprintf(fpout, "Repeat wait Time : %ld\n", BinHdr.RepeatWaitTime);
fprintf(fpout, "Script Name : %.*s\n", BINHDR_SIZE_SCRIPT_NAME, BinHdr.ScriptName);
for(i = 0; i < BinHdr.NumberOfBoards; ++i)
{
fprintf(fpout, "---------------------\n");
result = fread(&BoardHdr, 1, sizeof(BoardHdr), fpin);
if(result != sizeof(BoardHdr))
{
closeFiles(fpin, fpout);
printf("\nerror reading board header, aborted.");
return -1;
}
fprintf(fpout, "Board No %1d\n", i);
fprintf(fpout, " HardwareIdent : %.*s\n", BOARDHDR_HARDWARE_IDENT, BoardHdr.HardwareIdent);
fprintf(fpout, " HardwareVersion : %.*s\n", BOARDHDR_HARDWARE_VERSION, BoardHdr.HardwareVersion);
fprintf(fpout, " HardwareSerial : %ld\n", BoardHdr.HardwareSerial);
fprintf(fpout, " SyncDivider : %ld\n", BoardHdr.SyncDivider);
fprintf(fpout, " CFDZeroCross0 : %ld\n", BoardHdr.CFDZeroCross0);
fprintf(fpout, " CFDLevel0 : %ld\n", BoardHdr.CFDLevel0 );
fprintf(fpout, " CFDZeroCross1 : %ld\n", BoardHdr.CFDZeroCross1);
fprintf(fpout, " CFDLevel1 : %ld\n", BoardHdr.CFDLevel1);
fprintf(fpout, " Resolution : %lf\n", BoardHdr.Resolution);
if(BoardHdr.RouterModelCode > 0) //otherwise this information is meaningless
{
fprintf(fpout, " RouterModelCode : %ld\n", BoardHdr.RouterModelCode);
fprintf(fpout, " RouterEnabled : %ld\n", BoardHdr.RouterEnabled);
fprintf(fpout, " RtChan1_InputType : %ld\n", BoardHdr.RtChan1_InputType);
fprintf(fpout, " RtChan1_InputLevel : %ld\n", BoardHdr.RtChan1_InputLevel);
fprintf(fpout, " RtChan1_InputEdge : %ld\n", BoardHdr.RtChan1_InputEdge);
fprintf(fpout, " RtChan1_CFDPresent : %ld\n", BoardHdr.RtChan1_CFDPresent);
fprintf(fpout, " RtChan1_CFDLevel : %ld\n", BoardHdr.RtChan1_CFDLevel);
fprintf(fpout, " RtChan1_CFDZeroCross : %ld\n", BoardHdr.RtChan1_CFDZeroCross);
fprintf(fpout, " RtChan2_InputType : %ld\n", BoardHdr.RtChan2_InputType);
fprintf(fpout, " RtChan2_InputLevel : %ld\n", BoardHdr.RtChan2_InputLevel);
fprintf(fpout, " RtChan2_InputEdge : %ld\n", BoardHdr.RtChan2_InputEdge);
fprintf(fpout, " RtChan2_CFDPresent : %ld\n", BoardHdr.RtChan2_CFDPresent);
fprintf(fpout, " RtChan2_CFDLevel : %ld\n", BoardHdr.RtChan2_CFDLevel);
fprintf(fpout, " RtChan2_CFDZeroCross : %ld\n", BoardHdr.RtChan2_CFDZeroCross);
fprintf(fpout, " RtChan3_InputType : %ld\n", BoardHdr.RtChan3_InputType);
fprintf(fpout, " RtChan3_InputLevel : %ld\n", BoardHdr.RtChan3_InputLevel);
fprintf(fpout, " RtChan3_InputEdge : %ld\n", BoardHdr.RtChan3_InputEdge);
fprintf(fpout, " RtChan3_CFDPresent : %ld\n", BoardHdr.RtChan3_CFDPresent);
fprintf(fpout, " RtChan3_CFDLevel : %ld\n", BoardHdr.RtChan3_CFDLevel);
fprintf(fpout, " RtChan3_CFDZeroCross : %ld\n", BoardHdr.RtChan3_CFDZeroCross);
fprintf(fpout, " RtChan4_InputType : %ld\n", BoardHdr.RtChan4_InputType);
fprintf(fpout, " RtChan4_InputLevel : %ld\n", BoardHdr.RtChan4_InputLevel);
fprintf(fpout, " RtChan4_InputEdge : %ld\n", BoardHdr.RtChan4_InputEdge);
fprintf(fpout, " RtChan4_CFDPresent : %ld\n", BoardHdr.RtChan4_CFDPresent);
fprintf(fpout, " RtChan4_CFDLevel : %ld\n", BoardHdr.RtChan4_CFDLevel);
fprintf(fpout, " RtChan4_CFDZeroCross : %ld\n", BoardHdr.RtChan4_CFDZeroCross);
}
fprintf(fpout, "---------------------\n");
}
/*
The following is repeated here for all stored curves.
*/
/*
Read and display the curve headers.
*/
for(i=0; i < BinHdr.Curves; ++i)
{
fprintf(fpout, "---------------------\n");
result = fread(&CurveHdr[i], 1, sizeof(CurveHdr[i]) ,fpin);
if (result != sizeof(CurveHdr[i]))
{
closeFiles(fpin, fpout);
printf("\nerror reading curve header, aborted.");
return -1;
}
fprintf(fpout, "Curve Index : %ld\n", CurveHdr[i].CurveIndex);
TM tm1;
convert_time_to_tm((time_t*)&CurveHdr[i].TimeOfRecording, &tm1);
fprintf(fpout, "Time of Recording : %s\n", asctime(&tm1));
fprintf(fpout, "HardwareIdent : %.*s\n", CURVEHDR_HARDWARE_IDENT, CurveHdr[i].HardwareIdent);
fprintf(fpout, "HardwareVersion : %.*s\n", CURVEHDR_HARDWARE_VERSION, CurveHdr[i].HardwareVersion);
fprintf(fpout, "HardwareSerial : %ld\n", CurveHdr[i].HardwareSerial);
fprintf(fpout, "SyncDivider : %ld\n", CurveHdr[i].SyncDivider);
fprintf(fpout, "CFDZeroCross0 : %ld\n", CurveHdr[i].CFDZeroCross0);
fprintf(fpout, "CFDLevel0 : %ld\n", CurveHdr[i].CFDLevel0 );
fprintf(fpout, "CFDZeroCross1 : %ld\n", CurveHdr[i].CFDZeroCross1);
fprintf(fpout, "CFDLevel1 : %ld\n", CurveHdr[i].CFDLevel1);
fprintf(fpout, "Offset : %ld\n", CurveHdr[i].Offset);
fprintf(fpout, "RoutingChannel : %ld\n", CurveHdr[i].RoutingChannel);
fprintf(fpout, "ExtDevices : %ld\n", CurveHdr[i].ExtDevices);
fprintf(fpout, "Meas. Mode : %ld\n", CurveHdr[i].MeasMode);
fprintf(fpout, "Sub-Mode : %ld\n", CurveHdr[i].SubMode);
fprintf(fpout, "Par. 1 : %f\n", CurveHdr[i].P1);
fprintf(fpout, "Par. 2 : %f\n", CurveHdr[i].P2);
fprintf(fpout, "Par. 3 : %f\n", CurveHdr[i].P3);
fprintf(fpout, "Range No : %ld\n", CurveHdr[i].RangeNo);
fprintf(fpout, "Resolution : %f\n", CurveHdr[i].Resolution);
fprintf(fpout, "Channels : %ld\n", CurveHdr[i].Channels);
fprintf(fpout, "Acq. Time : %ld\n", CurveHdr[i].Tacq);
fprintf(fpout, "Stop after : %ld\n", CurveHdr[i].StopAfter);
fprintf(fpout, "Stop Reason : %ld\n", CurveHdr[i].StopReason);
fprintf(fpout, "InpRate0 : %ld\n", CurveHdr[i].InpRate0);
fprintf(fpout, "InpRate1 : %ld\n", CurveHdr[i].InpRate1);
fprintf(fpout, "HistCountRate : %ld\n", CurveHdr[i].HistCountRate);
fprintf(fpout, "IntegralCount : %I64d\n", CurveHdr[i].IntegralCount);
fprintf(fpout, "reserved : %ld\n", CurveHdr[i].reserved);
fprintf(fpout, "dataoffset : %ld\n", CurveHdr[i].DataOffset);
if(CurveHdr[i].RouterModelCode > 0)
{
fprintf(fpout, "RouterModelCode : %ld\n", CurveHdr[i].RouterModelCode);
fprintf(fpout, "RouterEnabled : %ld\n", CurveHdr[i].RouterEnabled);
fprintf(fpout, "RtChan_InputType : %ld\n", CurveHdr[i].RtChan_InputType);
fprintf(fpout, "RtChan_InputLevel : %ld\n", CurveHdr[i].RtChan_InputLevel);
fprintf(fpout, "RtChan_InputEdge : %ld\n", CurveHdr[i].RtChan_InputEdge);
fprintf(fpout, "RtChan_CFDPresent : %ld\n", CurveHdr[i].RtChan_CFDPresent);
fprintf(fpout, "RtChan_CFDLevel : %ld\n", CurveHdr[i].RtChan_CFDLevel);
fprintf(fpout, "RtChan_CFDZeroCross : %ld\n", CurveHdr[i].RtChan_CFDZeroCross);
}
}
/*
Read and display the actual curve data.
*/
fprintf(fpout, "---------------------\n");
fprintf(fpout, "Counts:\n");
for(i = 0; i < BinHdr.Curves; ++i)
{
fseek(fpin, CurveHdr[i].DataOffset, SEEK_SET);
result = fread(&Counts, 4, CurveHdr[i].Channels ,fpin);
if(result != CurveHdr[i].Channels)
{
closeFiles(fpin, fpout);
printf("\nerror reading count data, aborted. ");
return -1;
}
for(j = 0; j < CurveHdr[i].Channels; ++j)
fprintf(fpout, "%lu\n", Counts[j]);
fprintf(fpout, "---------------------\n");
}
return 0;
}
void closeFiles(FILE* fpin, FILE* fpout)
{
if(fpin != NULL)
fclose(fpin);
if(fpout != NULL)
fclose(fpout);
}
Penn