1 /***************************************************************************
5 ----------------------------------------------------------------------------
7 FUNCTION: Initializes simulation
9 ----------------------------------------------------------------------------
11 MODULE STATUS: incomplete
13 ----------------------------------------------------------------------------
15 GENEALOGY: Written 921230 by Bruce Jackson
17 ----------------------------------------------------------------------------
25 ----------------------------------------------------------------------------
31 950314 Added get_set, put_set, and init routines. EBJ
37 Revision 1.1 1997/05/29 00:09:57 curt
38 Initial Flight Gear revision.
40 * Revision 1.4 1995/03/15 12:15:23 bjax
41 * Added ls_init_get_set() and ls_init_put_set() and ls_init_init()
44 * Revision 1.3 1994/01/11 19:09:44 bjax
45 * Fixed header includes.
47 * Revision 1.2 1992/12/30 14:04:53 bjax
48 * Added call to ls_step(0, 1).
50 * Revision 1.1 92/12/30 14:02:19 bjax
53 * Revision 1.1 92/12/30 13:21:21 bjax
56 * Revision 1.3 93/12/31 10:34:11 bjax
57 * Added $Log marker as well.
60 ----------------------------------------------------------------------------
64 ----------------------------------------------------------------------------
68 ----------------------------------------------------------------------------
72 ----------------------------------------------------------------------------
76 ----------------------------------------------------------------------------
80 --------------------------------------------------------------------------*/
81 static char rcsid[] = "$Id$";
88 #define MAX_NUMBER_OF_CONTINUOUS_STATES 100
89 #define MAX_NUMBER_OF_DISCRETE_STATES 20
91 #define NIL_POINTER 0L
93 #define FACILITY_NAME_STRING "init"
94 #define CURRENT_VERSION 10
109 extern SCALAR Simtime;
111 static int Symbols_loaded = 0;
112 static int Number_of_Continuous_States = 0;
113 static int Number_of_Discrete_States = 0;
114 static cont_state_rec Continuous_States[ MAX_NUMBER_OF_CONTINUOUS_STATES ];
115 static disc_state_rec Discrete_States[ MAX_NUMBER_OF_DISCRETE_STATES ];
122 if (Number_of_Continuous_States == 0)
124 Number_of_Continuous_States = HARDWIRED;
126 for (i=0;i<HARDWIRED;i++)
127 strcpy( Continuous_States[i].Symbol.Mod_Name, "*" );
129 strcpy( Continuous_States[ 0].Symbol.Par_Name,
130 "generic_.geodetic_position_v[0]");
131 strcpy( Continuous_States[ 1].Symbol.Par_Name,
132 "generic_.geodetic_position_v[1]");
133 strcpy( Continuous_States[ 2].Symbol.Par_Name,
134 "generic_.geodetic_position_v[2]");
135 strcpy( Continuous_States[ 3].Symbol.Par_Name,
136 "generic_.v_local_v[0]");
137 strcpy( Continuous_States[ 4].Symbol.Par_Name,
138 "generic_.v_local_v[1]");
139 strcpy( Continuous_States[ 5].Symbol.Par_Name,
140 "generic_.v_local_v[2]");
141 strcpy( Continuous_States[ 6].Symbol.Par_Name,
142 "generic_.euler_angles_v[0]");
143 strcpy( Continuous_States[ 7].Symbol.Par_Name,
144 "generic_.euler_angles_v[1]");
145 strcpy( Continuous_States[ 8].Symbol.Par_Name,
146 "generic_.euler_angles_v[2]");
147 strcpy( Continuous_States[ 9].Symbol.Par_Name,
148 "generic_.omega_body_v[0]");
149 strcpy( Continuous_States[10].Symbol.Par_Name,
150 "generic_.omega_body_v[1]");
151 strcpy( Continuous_States[11].Symbol.Par_Name,
152 "generic_.omega_body_v[2]");
153 strcpy( Continuous_States[12].Symbol.Par_Name,
154 "generic_.earth_position_angle");
157 /* commented out by CLO
158 for (i=0;i<Number_of_Continuous_States;i++)
160 (void) ls_get_sym_val( &Continuous_States[i].Symbol, &error );
161 if (error) Continuous_States[i].Symbol.Addr = NIL_POINTER;
164 for (i=0;i<Number_of_Discrete_States;i++)
166 (void) ls_get_sym_val( &Discrete_States[i].Symbol, &error );
167 if (error) Discrete_States[i].Symbol.Addr = NIL_POINTER;
179 /* move the states to proper values */
181 /* commented out by CLO
182 for(i=0;i<Number_of_Continuous_States;i++)
183 if (Continuous_States[i].Symbol.Addr)
184 ls_set_sym_val( &Continuous_States[i].Symbol,
185 Continuous_States[i].value );
187 for(i=0;i<Number_of_Discrete_States;i++)
188 if (Discrete_States[i].Symbol.Addr)
189 ls_set_sym_val( &Discrete_States[i].Symbol,
190 (double) Discrete_States[i].value );
199 char *ls_init_get_set(char *buffer, char *eob)
200 /* This routine parses the settings file for "init" entries. */
203 static char *fac_name = FACILITY_NAME_STRING;
206 int n, ver, i, error, abrt;
208 enum {cont_states_header, cont_states, disc_states_header, disc_states, done } looking_for;
211 looking_for = cont_states_header;
213 n = sscanf(buffer, "%s", line);
214 if (n == 0) return 0L;
215 if (strncasecmp( fac_name, line, strlen(fac_name) )) return 0L;
217 bufptr = strtok( buffer+strlen(fac_name)+1, "\n");
218 if (bufptr == 0) return 0L;
220 sscanf( bufptr, "%d", &ver );
221 if (ver != CURRENT_VERSION) return 0L;
225 while( !abrt && (eob > bufptr))
227 bufptr = strtok( 0L, "\n");
228 if (bufptr == 0) return 0L;
229 if (strncasecmp( bufptr, "end", 3) == 0) break;
231 sscanf( bufptr, "%s", line );
232 if (line[0] != '#') /* ignore comments */
236 case cont_states_header:
238 if (strncasecmp( line, "continuous_states", 17) == 0)
240 n = sscanf( bufptr, "%s%d", line,
241 &Number_of_Continuous_States );
242 if (n != 2) abrt = 1;
243 looking_for = cont_states;
250 n = sscanf( bufptr, "%s%s%le",
251 Continuous_States[i].Symbol.Mod_Name,
252 Continuous_States[i].Symbol.Par_Name,
253 &Continuous_States[i].value );
254 if (n != 3) abrt = 1;
255 Continuous_States[i].Symbol.Addr = NIL_POINTER;
257 if (i >= Number_of_Continuous_States)
258 looking_for = disc_states_header;
261 case disc_states_header:
263 if (strncasecmp( line, "discrete_states", 15) == 0)
265 n = sscanf( bufptr, "%s%d", line,
266 &Number_of_Discrete_States );
267 if (n != 2) abrt = 1;
268 looking_for = disc_states;
275 n = sscanf( bufptr, "%s%s%ld",
276 Discrete_States[i].Symbol.Mod_Name,
277 Discrete_States[i].Symbol.Par_Name,
278 &Discrete_States[i].value );
279 if (n != 3) abrt = 1;
280 Discrete_States[i].Symbol.Addr = NIL_POINTER;
282 if (i >= Number_of_Discrete_States) looking_for = done;
293 Symbols_loaded = !abrt;
300 void ls_init_put_set( FILE *fp )
306 fprintf(fp, "#============================== %s\n", FACILITY_NAME_STRING);
308 fprintf(fp, FACILITY_NAME_STRING);
310 fprintf(fp, "%04d\n", CURRENT_VERSION);
311 fprintf(fp, " continuous_states: %d\n", Number_of_Continuous_States);
312 fprintf(fp, "# module parameter value\n");
313 for (i=0; i<Number_of_Continuous_States; i++)
314 fprintf(fp, " %s\t%s\t%E\n",
315 Continuous_States[i].Symbol.Mod_Name,
316 Continuous_States[i].Symbol.Par_Name,
317 Continuous_States[i].value );
319 fprintf(fp, " discrete_states: %d\n", Number_of_Discrete_States);
320 fprintf(fp, "# module parameter value\n");
321 for (i=0;i<Number_of_Discrete_States;i++)
322 fprintf(fp, " %s\t%s\t%ld\n",
323 Discrete_States[i].Symbol.Mod_Name,
324 Discrete_States[i].Symbol.Par_Name,
325 Discrete_States[i].value );
326 fprintf(fp, "end\n");
330 void ls_save_current_as_ic()
332 /* Save current states as initial conditions */
336 /* commented out by CLO
337 for(i=0;i<Number_of_Continuous_States;i++)
338 if (Continuous_States[i].Symbol.Addr)
339 Continuous_States[i].value =
340 ls_get_sym_val( &Continuous_States[i].Symbol, &error );
342 for(i=0;i<Number_of_Discrete_States;i++)
343 if (Discrete_States[i].Symbol.Addr)
344 Discrete_States[i].value = (long)
345 ls_get_sym_val( &Discrete_States[i].Symbol, &error );