[futurebasic] Re: [FB] FB5 data file conversion help

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2012 : Group Archive : Group : All Groups

From: Deep <Info@...>
Date: Fri, 17 Feb 2012 19:05:59 +0000
 > Originally there was no plan to support PPC.

Best to use the routines Brian suggested even if there is no need to 
support PPC.

You do not know in future if the processor changes again, and is then 
different Endian to the current Intel range, the problem will appear 
again. Unless the conversion utilities are used to cover such possibilities.

If rumours are to be believed, the future processor roadmap is certainly 
not set in stone...!



On 17/02/2012 18:55, Steve wrote:
>
> Originally there was no plan to support PPC.
>
> However, we continue to get requests for a PPC version and customers who
> want to update, but want to keep their aging PPC Mac.
>
> All other data is in XML format, negating this endian issue., except for
> one layout file that is used for receipts for storing RECT parameters.
>
> Thanks Brian, I will try the CFSwapInt16LittleToHost but it is not
> defined in the headers.
>
>
> On Feb 17, 2012, at 11:50 AM, Brian S wrote:
>
>>
>> On Feb 17, 2012, at 7:38 AM, Steve wrote:
>>
>>> If a variable of type short is written out from an Intel Mac and the
>>> CFSwapInt was not used, how do I read/convert it back correctly on a
>>> PowerPC?
>>
>> A typical strategy for dealing with data that could be on either a
>> PowerPC or Intel is to keep all data big endian:
>>
>> (1) /_After_/ READing the data make a call to convert all data to host
>> endian ( i.e. CFSwapInt16BigToHost ). On an Intel this does the
>> conversion and on a PowerPC it does essentially nothing.
>>
>> (2) /_Before_/ WRITING the data make a call to convert all the data to
>> big endian ( i.e. CFSwapInt16HostToBig )
>>
>>
>> However, in the case cited of writing from an Intel it sounds like
>> little endian ( the host format of Intel machines ) was written
>> because there was no swap to big endian ( many FB runtime already
>> write as big endian but the OP didn’t specify how the data was written
>> from the Intel Mac ). In that case it would need to be converted to
>> host endian on the PowerPC machine ( i.e. CFSwapInt16LittleToHost )
>>
>>>
>>> The CFSwapBigtoHost does not produce the correct results unless it
>>> was swapped when writing using HosttoBig, but it wasn't
>>>
>>> If I write the files from an Intel, using HostToBig, it works as
>>> expected on PPC with BigtoHost
>>>
>>> On Jun 4, 2011, at 9:21 PM, Robert Purves wrote:
>>>
>>>>
>>>> Douglas Stemen wrote:
>>>>
>>>>> Are double precision (decimal number) 32 bit?
>>>>
>>>> They are 64 bits. To swap double variables:
>>>> include "Subs FloatByteSwapping.incl"
>>>> and use SwapDoubleBigToHost() and SwapDoubleHostToBig()
>>>>
>>>>> I am concerned about speed.
>>>>
>>>> CFSwapXxxxx() takes literally no time on PPC, a few nanoseconds on
>>>> Intel. Negligible.
>>>>
>>>> Below is a suggested way to organise the byte-swapping code. You
>>>> will need a set of those utilities for each record type that you
>>>> read and write.
>>>>
>>>> Robert P.
>>>>
>>>> '----------------
>>>> BEGIN RECORD paramRecord
>>>> DIM 13 gtaxaccount$
>>>> DIM DETAILNUM2%
>>>> DIM maxaccounts2%
>>>> DIM CLIENTNUM2%
>>>> DIM INVENNUM2%
>>>> DIM PREPAYNUM2%
>>>> DIM GRAINBANKNUM2%
>>>> DIM 13 MinSC$
>>>> END RECORD
>>>>
>>>>
>>>> local fn MakeParamRecordBigEndian( ioParam as ^paramRecord )
>>>> '~'1
>>>> ioParam.DETAILNUM2% = fn CFSwapInt16HostToBig( ioParam.DETAILNUM2% )
>>>> ioParam.maxaccounts2% = fn CFSwapInt16HostToBig( ioParam.maxaccounts2% )
>>>> ioParam.CLIENTNUM2% = fn CFSwapInt16HostToBig( ioParam.CLIENTNUM2% )
>>>> ioParam.INVENNUM2% = fn CFSwapInt16HostToBig( ioParam.INVENNUM2% )
>>>> ioParam.PREPAYNUM2% = fn CFSwapInt16HostToBig( ioParam.PREPAYNUM2% )
>>>> ioParam.GRAINBANKNUM2% = fn CFSwapInt16HostToBig(
>>>> ioParam.GRAINBANKNUM2% )
>>>> end fn
>>>>
>>>> local fn MakeParamRecordHostEndian( ioParam as ^paramRecord )
>>>> '~'1
>>>> ioParam.DETAILNUM2% = fn CFSwapInt16BigToHost( ioParam.DETAILNUM2% )
>>>> ioParam.maxaccounts2% = fn CFSwapInt16BigToHost( ioParam.maxaccounts2% )
>>>> ioParam.CLIENTNUM2% = fn CFSwapInt16BigToHost( ioParam.CLIENTNUM2% )
>>>> ioParam.INVENNUM2% = fn CFSwapInt16BigToHost( ioParam.INVENNUM2% )
>>>> ioParam.PREPAYNUM2% = fn CFSwapInt16BigToHost( ioParam.PREPAYNUM2% )
>>>> ioParam.GRAINBANKNUM2% = fn CFSwapInt16BigToHost(
>>>> ioParam.GRAINBANKNUM2% )
>>>> end fn
>>>>
>>>> local fn SaveParamRecordToFile( iParamRec as ^paramRecord, dest as
>>>> ^FSSpec )
>>>> '~'1
>>>> dim as paramRecord tempParamRec
>>>>
>>>> tempParamRec = iParamRec // local copy
>>>> fn MakeParamRecordBigEndian( @tempParamRec ) // big endian on disk
>>>> //...write tempParamRec to disk file...
>>>> end fn
>>>>
>>>> local fn ReadParamRecordFromFile( oParamRec as ^paramRecord, source
>>>> as ^FSSpec )
>>>> '~'1
>>>> //...read big endian file into oParamRec...
>>>> fn MakeParamRecordHostEndian( oParamRec ) // host endian for use in
>>>> program
>>>> end fn
>>>>
>>>>
>>>>
>>>> dim as paramRecord aParamRec
>>>> dim as FSSpec aFSSpec
>>>> //...set aFSSpec
>>>> fn ReadParamRecordFromFile( @aParamRec, @aFSSpec )
>>>> aParamRec.INVENNUM2% = 42
>>>> fn SaveParamRecordToFile( @aParamRec, @aFSSpec )
>>>> '----------------
>>>>
>>>>
>>>>
>>>> --
>>>> To unsubscribe, send ANY message to:
>>>> futurebasic-unsubscribe@...
>>>> <mailto:futurebasic-unsubscribe@...>
>>>> To access the list archives, go to:
>>>> http://freegroups.net/groups/futurebasic/
>>>>
>>>
>>>
>>> --
>>> To unsubscribe, send ANY message to:
>>> futurebasic-unsubscribe@...
>>> <mailto:futurebasic-unsubscribe@...>
>>> To access the list archives, go to:
>>> http://freegroups.net/groups/futurebasic/
>>>
>>
>> Brian S
>>
>>
>>
>>
>>
>>
>>
>> --
>> To unsubscribe, send ANY message to:
>> futurebasic-unsubscribe@...
>> <mailto:futurebasic-unsubscribe@...> To access the list
>> archives, go to: http://freegroups.net/groups/futurebasic/
>>
>>
>
>
> --
> To unsubscribe, send ANY message to:
> futurebasic-unsubscribe@...
> <mailto:futurebasic-unsubscribe@...> To access the list
> archives, go to: http://freegroups.net/groups/futurebasic/
>
>