Major back-end changes, with front-end tweaks to keep up. 1) Data frames are now...
[openmx:openmx.git] / src / omxState.c
1 /*
2  *  Copyright 2007-2009 The OpenMx Project
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 /***********************************************************
18
19 *  omxState.cc
20 *
21 *  Created: Timothy R. Brick    Date: 2009-06-05
22 *
23 *       omxStates carry the current optimization state
24 *
25 **********************************************************/
26
27 #include "omxState.h"
28
29 /* Initialize and Destroy */
30         void omxInitState(omxState* state) {
31                 state->numMats = 0;
32                 state->numAlgs = 0;
33                 state->numData = 0;
34                 state->matrixList = NULL;       
35                 state->algebraList = NULL;
36                 state->dataList = NULL;
37                 state->objectiveMatrix = NULL;
38                 state->conList = NULL;
39                 state->freeVarList = NULL;
40                 state->optimizerState;                  
41
42                 state->computeCount = 0;
43                 state->currentRow = 0;
44
45                 state->statusCode = 0;
46                 strncpy(state->statusMsg, "", 1);
47         }
48
49         void omxFillState(omxState* state, /*omxOptimizer *oo,*/ omxMatrix** matrixList, omxMatrix** algebraList, omxData** dataList, omxMatrix* objective) {
50                 error("NYI: Can't fill a state from outside yet.  Besides, do you really need a single function to do this?");
51         }
52         
53         void omxFreeState(omxState *oo) {
54                 int k;
55                 if(OMX_DEBUG) { Rprintf("Freeing Algebras.\n");}
56                 for(k = 0; k < oo->numAlgs; k++) {
57                         if(OMX_DEBUG) { Rprintf("Freeing Algebra %d.\n", k); }
58                         omxFreeAllMatrixData(oo->algebraList[k]);
59                 }
60
61                 if(OMX_DEBUG) { Rprintf("Freeing Matrices.\n");}
62                 for(k = 0; k < oo->numMats; k++) {
63                         omxFreeAllMatrixData(oo->matrixList[k]);
64                 }
65                 
66                 if(OMX_DEBUG) { Rprintf("Freeing Data.\n");}
67                 for(k = 0; k < oo->numData; k++) {
68                         omxFreeData(oo->dataList[k]);
69                 }
70                 
71         }
72         
73         void omxRaiseError(omxState *oo, int errorCode, char* errorMsg) {
74                 oo->statusCode = errorCode;
75                 strncpy(oo->statusMsg, errorMsg, 249);
76                 oo->statusMsg[249] = '\0';
77         }
78         
79         void omxStateNextRow(omxState *oo) { 
80                 oo->currentRow++; 
81         };
82         void omxStateNextEvaluation(omxState *oo) { 
83                 oo->currentRow = 0;
84                 oo->computeCount++; 
85         };
86