#Include Once "Newton.bi"



Declare Sub Save_Object_Configuration( Byref Object As Object_Struct )
Declare Sub Load_Object_Configuration( Byref Object As Object_Struct )



Sub Save_Object_Configuration( Byref Object As Object_Struct )
    Dim As Integer i, i2
    Dim As Integer File_ID = Freefile
    
    Open "Test_Format.nsf" For Binary As #File_ID
    'Put #File_ID,,Object.Max_Models
    Write #File_ID,Object.Max_Models
    
    'For i = 0 To 15
    'Put #File_ID,,Object.Matrix[i]
    'Write #File_ID, Object.Matrix[i]
    'Next
    
    For i = 0 To Object.Max_Models - 1
        Write #File_ID,Object.Model_ID[i]
    Next
    
    For i = 0 To Object.Max_Models - 1
        For i2 = 0 To 15
            Write #File_ID,Object.Sub_Matrix[i][i2]
        Next
    Next
    
    Close #File_ID
End Sub
''
''
''
Sub Load_Object_Configuration( Byref Object As Object_Struct )
    Dim As Integer i, i2
    Dim As Integer File_ID = Freefile
    
    If Object.Matrix Then Deallocate(Object.Matrix)
    For i = 0 To Object.Max_Models - 1
        If Object.Sub_Matrix[i][0] Then 
            Deallocate( Object.Sub_Matrix[i] )
            Object.Sub_Matrix[i] = 0
        End If
    Next
    If Object.Sub_Matrix Then 
        Deallocate( Object.Sub_Matrix )
        Object.Sub_Matrix = 0
    End If
    
    
    Open "Test_Format.nsf" For Binary As #File_ID
    Input #File_ID, Object.Max_Models
    Object.Model_ID = Callocate( Object.Max_Models * Sizeof( Uinteger ) )
    
    For i = 0 To Object.Max_Models - 1
        Input #File_ID,Object.Model_ID[i]
    Next
    
    
    If Not Object.Matrix Then 
        Object.Matrix = Callocate( Matrix_Copy_Size )
    End If
    
    If Not Object.Sub_Matrix Then
        Object.Sub_Matrix = Callocate( Object.Max_Models * Matrix_Copy_Size )
        For i = 0 To Object.Max_Models - 1
            If Not Object.Sub_Matrix[i] Then Object.Sub_Matrix[i] = Callocate( Matrix_Copy_Size )
        Next
    End If
    
    
    For i = 0 To Object.Max_Models - 1
        For i2 = 0 To 15
            Input #File_ID,Object.Sub_Matrix[i][i2]
        Next
    Next
    
    Close #File_ID
End Sub
