Bug Summary

File:aimUtil.c
Warning:line 595, column 43
Assigned value is garbage or undefined

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name aimUtil.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -D REVISION=7.6 -I /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/ESP/LINUX64/include -I ../include -I /usr/include/udunits2 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-dangling-else -Wno-parentheses -Wno-unused-result -Wno-format-truncation -fdebug-compilation-dir /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/CAPS/src -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/scanCAPS/2022-09-05-132820-125676-1 -x c aimUtil.c
1/*
2 * CAPS: Computational Aircraft Prototype Syntheses
3 *
4 * AIM Utility Functions
5 *
6 * Copyright 2014-2022, Massachusetts Institute of Technology
7 * Licensed under The GNU Lesser General Public License, version 2.1
8 * See http://www.opensource.org/licenses/lgpl-2.1.php
9 *
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <errno(*__errno_location ()).h>
16
17#ifdef WIN32
18/* needs Advapi32.lib & Ws2_32.lib */
19#include <Windows.h>
20#include <direct.h>
21#define strcasecmp stricmp
22#define snprintf _snprintf
23#define access _access
24#define F_OK0 0
25#define SLASH'/' '\\'
26#else
27#include <unistd.h>
28#include <dirent.h>
29#include <dlfcn.h>
30//#include <limits.h>
31#include <sys/stat.h>
32#define SLASH'/' '/'
33#endif
34
35
36#include "capsTypes.h"
37#include "udunits.h"
38#include "capsAIM.h"
39#include "aimUtil.h"
40
41/* OpenCSM Defines & Includes */
42#include "common.h"
43#include "OpenCSM.h"
44
45
46#define EBUFSIZE4096 4096
47#define UNIT_BUFFER_MAX257 257
48
49/*@-incondefs@*/
50extern void ut_free(/*@only@*/ ut_unit* const unit);
51extern void cv_free(/*@only@*/ cv_converter* const converter);
52/*@+incondefs@*/
53
54
55#ifdef WIN32
56static int aim_flipSlash(const char *src, char *back)
57{
58 int len, i;
59
60 len = strlen(src);
61 if (len >= PATH_MAX4096) return EGADS_INDEXERR-5;
62
63 for (i = 0; i <= len; i++)
64 if (src[i] == '/') {
65 back[i] = '\\';
66 } else {
67 back[i] = src[i];
68 }
69
70 return EGADS_SUCCESS0;
71}
72#endif
73
74
75void
76aim_capsRev(int *major, int *minor)
77{
78 *major = CAPSMAJOR1;
79 *minor = CAPSMINOR22;
80}
81
82
83int
84aim_getRootPath(void *aimStruc, const char **fullPath)
85{
86 aimInfo *aInfo;
87 capsProblem *problem;
88
89 aInfo = (aimInfo *) aimStruc;
90 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
91 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
92 problem = aInfo->problem;
93 *fullPath = problem->root;
94
95 return CAPS_SUCCESS0;
96}
97
98
99int
100aim_fileLink(void *aimStruc, /*@null@*/ char *srcPath)
101{
102 int i, len, status;
103 char aimFile[PATH_MAX4096], otherPhAIM[PATH_MAX4096];
104 aimInfo *aInfo;
105 capsAnalysis *analysis;
106 capsProblem *problem;
107 FILE *fp;
108
109 aInfo = (aimInfo *) aimStruc;
110 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
111 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
112 problem = aInfo->problem;
113 analysis = (capsAnalysis *) aInfo->analysis;
114
115 status = snprintf(aimFile, PATH_MAX4096, "%s.clnk", analysis->fullPath);
116 if (status >= PATH_MAX4096) {
117 AIM_ERROR(aimStruc, "File path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 117, __func__
, "File path exceeds max length!"); }
;
118 return CAPS_DIRERR-333;
119 }
120 if (access(aimFile, F_OK0) != 0) return CAPS_NOTFOUND-303;
121
122 if (srcPath != NULL((void*)0)) {
123 fp = fopen(aimFile, "r");
124 if (fp == NULL((void*)0)) {
125 AIM_ERROR(aimStruc, "Cannot open file: %s!", aimFile){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 125, __func__
, "Cannot open file: %s!", aimFile); }
;
126 return CAPS_DIRERR-333;
127 }
128 fscanf(fp, "%s", otherPhAIM);
129/*@-dependenttrans@*/
130 fclose(fp);
131/*@+dependenttrans@*/
132 len = strlen(problem->root) + 1;
133 for (i = 0; i < len; i++) aimFile[i] = problem->root[i];
134 for (i = len-1; i > 0; i--)
135 if (aimFile[i] == SLASH'/') break;
136 aimFile[i] = 0;
137 status = snprintf(srcPath, PATH_MAX4096, "%s%c%s", aimFile, SLASH'/', otherPhAIM);
138 if (status >= PATH_MAX4096) {
139 AIM_ERROR(aimStruc, "File path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 139, __func__
, "File path exceeds max length!"); }
;
140 return CAPS_DIRERR-333;
141 }
142 }
143
144 return CAPS_SUCCESS0;
145}
146
147
148int
149aim_file(void *aimStruc, const char *file, char *aimFile)
150{
151 int status;
152 aimInfo *aInfo;
153 capsAnalysis *analysis;
154 char srcPath[PATH_MAX4096];
155 const char *filename = file;
156#ifdef WIN32
157 char back[PATH_MAX4096];
158
159 status = aim_flipSlash(file, back);
160 if (status != CAPS_SUCCESS0) {
161 AIM_ERROR(aimStruc, "File path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 161, __func__
, "File path exceeds max length!"); }
;
162 return CAPS_DIRERR-333;
163 }
164 filename = back;
165#endif
166
167 aInfo = (aimInfo *) aimStruc;
168 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
169 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
170 analysis = (capsAnalysis *) aInfo->analysis;
171
172 status = aim_fileLink(aimStruc, srcPath);
173 if (status == CAPS_SUCCESS0) {
174 status = snprintf(aimFile, PATH_MAX4096, "%s%c%s",
175 srcPath, SLASH'/', filename);
176 if (status >= PATH_MAX4096) {
177 AIM_ERROR(aimStruc, "File path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 177, __func__
, "File path exceeds max length!"); }
;
178 return CAPS_DIRERR-333;
179 }
180 return CAPS_SUCCESS0;
181 } else if (status == CAPS_NOTFOUND-303) {
182 status = snprintf(aimFile, PATH_MAX4096, "%s%c%s",
183 analysis->fullPath, SLASH'/', filename);
184 if (status >= PATH_MAX4096) {
185 AIM_ERROR(aimStruc, "File path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 185, __func__
, "File path exceeds max length!"); }
;
186 return CAPS_DIRERR-333;
187 }
188 return CAPS_SUCCESS0;
189 }
190
191 return status;
192}
193
194
195static int
196aim_fileSP(void *aimStruc, const char *file, char *aimFile)
197{
198 int status;
199 aimInfo *aInfo;
200 capsAnalysis *analysis;
201 const char *filename = file;
202#ifdef WIN32
203 char back[PATH_MAX4096];
204
205 status = aim_flipSlash(file, back);
206 if (status != CAPS_SUCCESS0) {
207 AIM_ERROR(aimStruc, "File path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 207, __func__
, "File path exceeds max length!"); }
;
208 return CAPS_DIRERR-333;
209 }
210 filename = back;
211#endif
212
213 aInfo = (aimInfo *) aimStruc;
214 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
215 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
216 analysis = (capsAnalysis *) aInfo->analysis;
217
218 status = snprintf(aimFile, PATH_MAX4096, "\"%s%c\"%s",
219 analysis->fullPath, SLASH'/', filename);
220 if (status >= PATH_MAX4096) {
221 AIM_ERROR(aimStruc, "File path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 221, __func__
, "File path exceeds max length!"); }
;
222 return CAPS_DIRERR-333;
223 }
224
225 return CAPS_SUCCESS0;
226}
227
228
229int
230aim_isDir(void *aimStruc, const char *path)
231{
232 int status;
233 char aimDir[PATH_MAX4096];
234#ifdef WIN32
235 DWORD dwAttr;
236#else
237 DIR *dr = NULL((void*)0);
238#endif
239
240 status = aim_file(aimStruc, path, aimDir);
241 if (status != CAPS_SUCCESS0) return status;
242
243 /* are we a directory */
244#ifdef WIN32
245 dwAttr = GetFileAttributes(aimDir);
246 if ((dwAttr != (DWORD) -1) && ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0))
247 return CAPS_SUCCESS0;
248#else
249/*@-mustfreefresh@*/
250 dr = opendir(aimDir);
251 if (dr != NULL((void*)0)) {
252 closedir(dr);
253 return CAPS_SUCCESS0;
254 }
255/*@+mustfreefresh@*/
256#endif
257
258 return CAPS_NOTFOUND-303;
259}
260
261
262int
263aim_mkDir(void *aimStruc, const char *path)
264{
265 int status;
266 char aimDir[PATH_MAX4096];
267 aimInfo *aInfo;
268
269 aInfo = (aimInfo *) aimStruc;
270 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
271 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
272 if (aInfo->funID == AIM_UPDATESTATE1) return CAPS_STATEERR-329;
273
274 status = aim_fileLink(aimStruc, NULL((void*)0));
275 if (status == CAPS_SUCCESS0) {
276 AIM_ERROR(aimStruc, "Making a Directory in a CAPS link!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 276, __func__
, "Making a Directory in a CAPS link!"); }
;
277 return CAPS_FILELINKERR-344;
278 }
279
280 status = aim_file(aimStruc, path, aimDir);
281 if (status != CAPS_SUCCESS0) return status;
282
283#ifdef WIN32
284 status = _mkdir(aimDir);
285#else
286 status = mkdir(aimDir, S_IRWXU(0400|0200|0100));
287#endif
288
289 if (status != 0) {
290/*@-unrecog@*/
291 if (errno(*__errno_location ()) != EEXIST17) {
292/*@+unrecog@*/
293 AIM_ERROR(aimStruc, "Unable to make: %s", aimDir){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 293, __func__
, "Unable to make: %s", aimDir); }
;
294 return CAPS_DIRERR-333;
295 }
296 }
297
298 return CAPS_SUCCESS0;
299}
300
301
302int
303aim_rmDir(void *aimStruc, const char *path)
304{
305 int status;
306 size_t i, len;
307 char cmd[PATH_MAX4096+14];
308 char aimDir[PATH_MAX4096];
309 int wild = (int) false0;
310 aimInfo *aInfo;
311
312 aInfo = (aimInfo *) aimStruc;
313 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
314 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
315 if (aInfo->funID == AIM_UPDATESTATE1) return CAPS_STATEERR-329;
316
317 status = aim_fileLink(aimStruc, NULL((void*)0));
318 if (status == CAPS_SUCCESS0) {
319 AIM_ERROR(aimStruc, "Removing a Directory in a CAPS link!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 319, __func__
, "Removing a Directory in a CAPS link!"); }
;
320 return CAPS_FILELINKERR-344;
321 }
322
323 len = strlen(path);
324 for (i = 0; i < len; i++) {
325 if (path[i] == '*' || path[i] == '?') wild = (int) true1;
326 }
327 if (wild == (int) false0) {
328 status = aim_isDir(aimStruc, path);
329 if (status != CAPS_SUCCESS0) return status;
330 }
331 status = aim_fileSP(aimStruc, path, aimDir);
332 if (status != CAPS_SUCCESS0) return status;
333
334#ifdef WIN32
335 snprintf(cmd, PATH_MAX4096+14, "rmdir /Q /S %s", aimDir);
336 fflush(NULL((void*)0));
337#else
338 if (status != CAPS_SUCCESS0) return status;
339 snprintf(cmd, PATH_MAX4096+14, "rm -rf %s", aimDir);
340#endif
341 status = system(cmd);
342 if ((status == -1) || (status == 127)) return CAPS_DIRERR-333;
343
344 return CAPS_SUCCESS0;
345}
346
347
348int
349aim_isFile(void *aimStruc, const char *file)
350{
351 int status;
352 char aimFile[PATH_MAX4096];
353
354 status = aim_file(aimStruc, file, aimFile);
355 if (status != CAPS_SUCCESS0) return status;
356
357 if (access(aimFile, F_OK0) == 0) return CAPS_SUCCESS0;
358
359 return CAPS_NOTFOUND-303;
360}
361
362
363int
364aim_rmFile(void *aimStruc, const char *file)
365{
366 int status;
367 char aimFile[PATH_MAX4096];
368 aimInfo *aInfo;
369
370 aInfo = (aimInfo *) aimStruc;
371 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
372 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
373 if (aInfo->funID == AIM_UPDATESTATE1) return CAPS_STATEERR-329;
374
375 status = aim_fileLink(aimStruc, NULL((void*)0));
376 if (status == CAPS_SUCCESS0) {
377 AIM_ERROR(aimStruc, "Removing a file in a CAPS link!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 377, __func__
, "Removing a file in a CAPS link!"); }
;
378 return CAPS_FILELINKERR-344;
379 }
380
381 status = aim_file(aimStruc, file, aimFile);
382 if (status != CAPS_SUCCESS0) return status;
383
384 remove(aimFile);
385
386 return CAPS_SUCCESS0;
387}
388
389
390int aim_cpFile(void *aimStruc, const char *src, const char *dst)
391{
392 int status;
393 char cmd[2*PATH_MAX4096+14], aimDst[PATH_MAX4096];
394 aimInfo *aInfo;
395#ifdef WIN32
396 char sback[PATH_MAX4096], dback[PATH_MAX4096];
397#endif
398
399 aInfo = (aimInfo *) aimStruc;
400 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
401 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
402 if (aInfo->funID == AIM_UPDATESTATE1) return CAPS_STATEERR-329;
403
404 status = aim_fileLink(aimStruc, NULL((void*)0));
405 if (status == CAPS_SUCCESS0) {
406 AIM_ERROR(aimStruc, "Copying a file into a CAPS link!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 406, __func__
, "Copying a file into a CAPS link!"); }
;
407 return CAPS_FILELINKERR-344;
408 }
409
410 if (strlen(src) > PATH_MAX4096) {
411 AIM_ERROR(aimStruc, "File src path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 411, __func__
, "File src path exceeds max length!"); }
;
412 return CAPS_IOERR-332;
413 }
414 if (strlen(dst) > PATH_MAX4096) {
415 AIM_ERROR(aimStruc, "File dst path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 415, __func__
, "File dst path exceeds max length!"); }
;
416 return CAPS_IOERR-332;
417 }
418
419 status = aim_file(aimStruc, dst, aimDst);
420 if (status != CAPS_SUCCESS0) return status;
421
422#ifdef WIN32
423 status = aim_flipSlash(src, sback);
424 if (status != EGADS_SUCCESS0) return status;
425 status = aim_flipSlash(aimDst, dback);
426 if (status != EGADS_SUCCESS0) return status;
427 snprintf(cmd, 2*PATH_MAX4096+14, "copy /Y \"%s\" \"%s\"", sback, dback);
428 fflush(NULL((void*)0));
429#else
430 snprintf(cmd, 2*PATH_MAX4096+14, "cp '%s' '%s'", src, aimDst);
431#endif
432 status = system(cmd);
433 if (status != 0) {
434 AIM_ERROR(aimStruc, "Could not execute: %s", cmd){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 434, __func__
, "Could not execute: %s", cmd); }
;
435 return CAPS_IOERR-332;
436 }
437
438 return CAPS_SUCCESS0;
439}
440
441
442int aim_relPath(void *aimStruc, const char *src,
443 /*@null@*/ const char *dst, char *relPath)
444{
445 int i, j, k, len, lsrc, ldst, ndst, status;
446 char aimDst[PATH_MAX4096];
447 aimInfo *aInfo;
448 capsProblem *problem;
449
450 aInfo = (aimInfo *) aimStruc;
451 if (aInfo
13.1
'aInfo' is not equal to NULL
== NULL((void*)0)) return CAPS_NULLOBJ-309;
14
Taking false branch
452 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
15
Assuming field 'magicnumber' is equal to CAPSMAGIC
16
Taking false branch
453 problem = aInfo->problem;
454
455 if (src
16.1
'src' is not equal to NULL
== NULL((void*)0)) {
17
Taking false branch
456 AIM_ERROR(aimStruc, "NULL src!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 456, __func__
, "NULL src!"); }
;
457 return CAPS_IOERR-332;
458 }
459 if (strlen(src) > PATH_MAX4096) {
18
Taking false branch
460 AIM_ERROR(aimStruc, "File src path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 460, __func__
, "File src path exceeds max length!"); }
;
461 return CAPS_IOERR-332;
462 }
463 if (relPath
18.1
'relPath' is not equal to NULL
== NULL((void*)0)) {
19
Taking false branch
464 AIM_ERROR(aimStruc, "NULL relPath!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 464, __func__
, "NULL relPath!"); }
;
465 return CAPS_IOERR-332;
466 }
467 relPath[0] = '\0';
468
469 /* get the destination file */
470 if (dst != NULL((void*)0)) {
20
Assuming 'dst' is equal to NULL
21
Taking false branch
471 if (strlen(dst) > PATH_MAX4096) {
472 AIM_ERROR(aimStruc, "File dst path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 472, __func__
, "File dst path exceeds max length!"); }
;
473 return CAPS_IOERR-332;
474 }
475 if (strlen(dst) > 0) {
476 status = aim_file(aimStruc, dst, aimDst);
477 } else {
478 status = aim_file(aimStruc, ".", aimDst);
479 }
480 } else {
481 status = aim_file(aimStruc, ".", aimDst);
482 }
483 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimUtil.c", 483
, __func__, 0); goto cleanup; }
;
22
Taking false branch
484
485 /* get Problem path */
486 len = strlen(problem->root);
487 for (k = len-1; k > 0; k--)
23
Assuming 'k' is <= 0
24
Loop condition is false. Execution continues on line 489
488 if (problem->root[k] == SLASH'/') break;
489 if ((k >= strlen(src)) || (k >= strlen(aimDst))) {
25
Assuming the condition is false
26
Assuming the condition is false
27
Taking false branch
490 AIM_ERROR(aimStruc, "File not in rootPath!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 490, __func__
, "File not in rootPath!"); }
;
491 return CAPS_IOERR-332;
492 }
493 for (i = 0; i
27.1
'i' is >= 'k'
< k; i++)
28
Loop condition is false. Execution continues on line 499
494 if ((problem->root[i] != src[i]) || (problem->root[i] != aimDst[i])) {
495 AIM_ERROR(aimStruc, "Problem path mismatch!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 495, __func__
, "Problem path mismatch!"); }
;
496 return CAPS_IOERR-332;
497 }
498
499 if (strcmp(src, aimDst) == 0) {
29
Assuming the condition is true
30
Taking true branch
500 relPath[0] = '.';
501 relPath[1] = '\0';
502 return CAPS_SUCCESS0;
503 }
504
505 /* find the level */
506 lsrc = strlen(src);
507 ldst = strlen(aimDst);
508 ndst = 0;
509 for (i = k+1; i < ldst; i++)
510 if (aimDst[i] == SLASH'/') ndst++;
511 j = ldst;
512 if (j > lsrc) j = lsrc;
513 for (i = k+1; i < j; i++)
514 if (src[i] == aimDst[i]) {
515 if (src[i] == SLASH'/') {
516 ndst--;
517 k = i;
518 }
519 } else {
520 break;
521 }
522
523 /* construct the relative path */
524 j = 0;
525 for (i = 0; i < ndst; i++) {
526 relPath[j++] = '.';
527 relPath[j++] = '.';
528 relPath[j++] = SLASH'/';
529 }
530 for (i = k+1; i <= lsrc; i++, j++) relPath[j] = src[i];
531
532cleanup:
533 return status;
534}
535
536
537int aim_symLink(void *aimStruc, const char *src, /*@null@*/ const char *dst)
538{
539#ifdef WIN32
540 if (dst == NULL((void*)0)) return aim_cpFile(aimStruc, src, ".");
541 return aim_cpFile(aimStruc, src, dst);
542#else
543 int i, j, k, m, len, status;
544 char cmd[2*PATH_MAX4096+14], aimDst[PATH_MAX4096], relSrc[PATH_MAX4096];
545 aimInfo *aInfo;
546
547 aInfo = (aimInfo *) aimStruc;
548 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1
Assuming 'aInfo' is not equal to NULL
2
Taking false branch
549 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
3
Assuming field 'magicnumber' is equal to CAPSMAGIC
4
Taking false branch
550 if (aInfo->funID == AIM_UPDATESTATE1) return CAPS_STATEERR-329;
5
Assuming field 'funID' is not equal to AIM_UPDATESTATE
6
Taking false branch
551
552 if (strlen(src) > PATH_MAX4096) {
7
Assuming the condition is false
8
Taking false branch
553 AIM_ERROR(aimStruc, "File src path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 553, __func__
, "File src path exceeds max length!"); }
;
554 return CAPS_IOERR-332;
555 }
556 if (access(src, F_OK0) != 0) {
9
Assuming the condition is false
10
Taking false branch
557 AIM_ERROR(aimStruc, "%s Not a File!", src){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 557, __func__
, "%s Not a File!", src); }
;
558 return CAPS_IOERR-332;
559 }
560
561 status = aim_fileLink(aimStruc, NULL((void*)0));
562 if (status == CAPS_SUCCESS0) {
11
Assuming 'status' is not equal to CAPS_SUCCESS
12
Taking false branch
563 AIM_ERROR(aimStruc, "Making a symLink in a CAPS link!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 563, __func__
, "Making a symLink in a CAPS link!"); }
;
564 return CAPS_FILELINKERR-344;
565 }
566
567 /* convert the absolute src path to a relative path */
568 status = aim_relPath(aimStruc, src, dst, relSrc);
13
Calling 'aim_relPath'
31
Returning from 'aim_relPath'
569 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimUtil.c", 569
, __func__, 0); goto cleanup; }
;
32
Taking false branch
570
571 /* get the destination file */
572 if (dst
32.1
'dst' is equal to NULL
!= NULL((void*)0)) {
33
Taking false branch
573 if (strlen(dst) > PATH_MAX4096) {
574 AIM_ERROR(aimStruc, "File dst path exceeds max length!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 574, __func__
, "File dst path exceeds max length!"); }
;
575 return CAPS_IOERR-332;
576 }
577 if (strlen(dst) > 0) {
578 status = aim_file(aimStruc, dst, aimDst);
579 } else {
580 status = aim_file(aimStruc, ".", aimDst);
581 }
582 } else {
583 status = aim_file(aimStruc, ".", aimDst);
584 }
585 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimUtil.c", 585
, __func__, 0); goto cleanup; }
;
34
Taking false branch
586
587 /* remove any old links */
588 len = strlen(aimDst);
589 if ((aimDst[len-1] == '.') && (aimDst[len-2] == '/')) {
35
Assuming the condition is true
36
Assuming the condition is true
37
Taking true branch
590 for (i = strlen(relSrc); i > 0; i--)
38
Assuming 'i' is > 0
39
Loop condition is true. Entering loop body
42
Assuming 'i' is > 0
43
Loop condition is true. Entering loop body
46
Assuming 'i' is > 0
47
Loop condition is true. Entering loop body
50
Assuming 'i' is <= 0
51
Loop condition is false. Execution continues on line 592
591 if (relSrc[i] == '/') break;
40
Assuming the condition is false
41
Taking false branch
44
Assuming the condition is false
45
Taking false branch
48
Assuming the condition is false
49
Taking false branch
592 m = len-2;
593 if ((i
51.1
'i' is equal to 0
== 0) && (relSrc[0] != '/')) m = len-1;
52
Taking true branch
594 j = strlen(relSrc);
595 for (k = i; k
52.1
'k' is < 'j'
< j; k++) aimDst[m+k-i] = relSrc[k];
53
Loop condition is true. Entering loop body
54
Loop condition is true. Entering loop body
55
The value 2 is assigned to 'k'
56
Loop condition is true. Entering loop body
57
Assigned value is garbage or undefined
596 aimDst[m+j-i] = 0;
597 }
598 unlink(aimDst);
599
600 snprintf(cmd, 2*PATH_MAX4096+14, "ln -s '%s' '%s'", relSrc, aimDst);
601 status = system(cmd);
602 if (status != 0) {
603 AIM_ERROR(aimStruc, "Could not execute: %s", cmd){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 603, __func__
, "Could not execute: %s", cmd); }
;
604 return CAPS_IOERR-332;
605 }
606
607cleanup:
608 return status;
609#endif
610}
611
612
613/*@null@*/ /*@out@*/ /*@only@*/ FILE *
614aim_fopen(void *aimStruc, const char *path, const char *mode)
615{
616 int i, status, len;
617 char fullPath[PATH_MAX4096], srcPath[PATH_MAX4096];
618 aimInfo *aInfo;
619 capsAnalysis *analysis;
620
621 aInfo = (aimInfo *) aimStruc;
622 if (mode == NULL((void*)0)) return NULL((void*)0);
623 if (aInfo == NULL((void*)0)) return NULL((void*)0);
624 if (aInfo->magicnumber != CAPSMAGIC1234321) return NULL((void*)0);
625 analysis = (capsAnalysis *) aInfo->analysis;
626
627 if (aInfo->funID == AIM_UPDATESTATE1) {
628 len = strlen(mode);
629 for (i = 0; i < len; i++)
630 if ((mode[i] == 'w') || (mode[i] == 'a') || (mode[i] == '+')) return NULL((void*)0);
631 }
632
633 status = aim_fileLink(aimStruc, srcPath);
634 if (status == CAPS_SUCCESS0) {
635 len = strlen(mode);
636 for (i = 0; i < len; i++)
637 if ((mode[i] == 'w') || (mode[i] == 'a') || (mode[i] == '+')) return NULL((void*)0);
638 status = snprintf(fullPath, PATH_MAX4096, "%s%c%s", srcPath, SLASH'/', path);
639 } else {
640 status = snprintf(fullPath, PATH_MAX4096, "%s%c%s", analysis->fullPath, SLASH'/',
641 path);
642 }
643 if (status >= PATH_MAX4096) return NULL((void*)0);
644
645/*@-dependenttrans@*/
646 return fopen(fullPath, mode);
647/*@+dependenttrans@*/
648}
649
650
651int
652aim_system(void *aimStruc, /*@null@*/ const char *rpath, const char *command)
653{
654 size_t status;
655 char *fullcommand;
656 size_t len;
657 aimInfo *aInfo;
658 capsProblem *problem;
659 capsAnalysis *analysis;
660
661 aInfo = (aimInfo *) aimStruc;
662 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
663 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
664 if (aInfo->funID == AIM_UPDATESTATE1) return CAPS_STATEERR-329;
665 problem = aInfo->problem;
666 analysis = (capsAnalysis *) aInfo->analysis;
667
668 status = aim_fileLink(aimStruc, NULL((void*)0));
669 if (status == CAPS_SUCCESS0) {
670 AIM_ERROR(aimStruc, "Running a command in a CAPS link!"){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 670, __func__
, "Running a command in a CAPS link!"); }
;
671 return CAPS_FILELINKERR-344;
672 }
673
674 len = 9 + strlen(problem->root) + 1 + strlen(analysis->path) +
675 4 + strlen(command) + 3;
676 if (rpath == NULL((void*)0)) {
677 fullcommand = EG_alloc(len*sizeof(char));
678 if (fullcommand == NULL((void*)0)) return EGADS_MALLOC-4;
679#ifdef WIN32
680 status = snprintf(fullcommand, len, "%c: && cd \"%s\\%s\" && %s",
681 problem->root[0], &problem->root[2], analysis->path,
682 command);
683#else
684 status = snprintf(fullcommand, len, "cd '%s/%s' && %s",
685 problem->root, analysis->path, command);
686#endif
687 } else {
688 len += strlen(rpath) + 1;
689 fullcommand = EG_alloc(len*sizeof(char));
690 if (fullcommand == NULL((void*)0)) return EGADS_MALLOC-4;
691#ifdef WIN32
692 status = snprintf(fullcommand, len, "%c: && cd \"%s\\%s\\%s\" && %s",
693 problem->root[0], &problem->root[2], analysis->path,
694 rpath, command);
695#else
696 status = snprintf(fullcommand, len, "cd '%s/%s/%s' && %s",
697 problem->root, analysis->path, rpath, command);
698#endif
699 }
700 if (status >= len) {
701 EG_free(fullcommand);
702 return CAPS_BADVALUE-311;
703 }
704
705 status = system(fullcommand);
706 EG_free(fullcommand);
707 return status == 0 ? CAPS_SUCCESS0 : CAPS_EXECERR-335;
708}
709
710
711int
712aim_getUnitSys(void *aimStruc, char **unitSys)
713{
714 aimInfo *aInfo;
715 capsAnalysis *analysis;
716
717 aInfo = (aimInfo *) aimStruc;
718 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
719 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
720 analysis = (capsAnalysis *) aInfo->analysis;
721
722 *unitSys = analysis->unitSys;
723 return CAPS_SUCCESS0;
724}
725
726
727int
728aim_getBodies(void *aimStruc, const char **intents, int *nBody, ego **bodies)
729{
730 aimInfo *aInfo;
731 capsAnalysis *analysis;
732
733 *nBody = 0;
734 *bodies = NULL((void*)0);
735 aInfo = (aimInfo *) aimStruc;
736 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
737 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
738 analysis = (capsAnalysis *) aInfo->analysis;
739
740 *intents = analysis->intents;
741 *nBody = analysis->nBody;
742 *bodies = analysis->bodies;
743 return CAPS_SUCCESS0;
744}
745
746
747int
748aim_newGeometry(void *aimStruc)
749{
750 aimInfo *aInfo;
751 capsProblem *problem;
752 capsAnalysis *analysis;
753
754 aInfo = (aimInfo *) aimStruc;
755 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
756 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
757 problem = aInfo->problem;
758 analysis = (capsAnalysis *) aInfo->analysis;
759
760 if (problem->geometry.sNum < analysis->pre.sNum) return CAPS_CLEAN-336;
761 return CAPS_SUCCESS0;
762}
763
764
765int
766aim_newAnalysisIn(void *aimStruc, int index)
767{
768 aimInfo *aInfo;
769 capsAnalysis *analysis;
770
771 aInfo = (aimInfo *) aimStruc;
772 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
773 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
774 analysis = (capsAnalysis *) aInfo->analysis;
775 if (index <= 0 || index > analysis->nAnalysisIn) return CAPS_RANGEERR-326;
776
777 if (analysis->analysisIn[index-1]->last.sNum < analysis->pre.sNum)
778 return CAPS_CLEAN-336;
779 return CAPS_SUCCESS0;
780}
781
782
783int
784aim_numInstance(void *aimStruc)
785{
786 int i;
787 aimInfo *aInfo;
788 capsProblem *problem;
789 capsAnalysis *analysis;
790
791 aInfo = (aimInfo *) aimStruc;
792 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
793 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
794 problem = aInfo->problem;
795 analysis = (capsAnalysis *) aInfo->analysis;
796
797 for (i = 0; i < problem->aimFPTR.aim_nAnal; i++)
798 if (strcasecmp(analysis->loadName, problem->aimFPTR.aimName[i]) == 0) break;
799 if (i == problem->aimFPTR.aim_nAnal) return CAPS_BADINIT-338;
800
801 return problem->aimFPTR.aim_nInst[i];
802}
803
804
805int
806aim_getInstance(void *aimStruc)
807{
808 aimInfo *aInfo;
809
810 aInfo = (aimInfo *) aimStruc;
811 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
812 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
813
814 return aInfo->instance;
815}
816
817
818int
819aim_convert(void *aimStruc, const int count,
820 /*@null@*/ const char *inUnits, double *inValue,
821 /*@null@*/ const char *outUnits, double *outValue)
822{
823 int i;
824 aimInfo *aInfo;
825 capsProblem *problem;
826 ut_unit *utunit1, *utunit2;
827 cv_converter *converter;
828
829 if (inValue == NULL((void*)0)) return CAPS_NULLVALUE-307;
830 if (outValue == NULL((void*)0)) return CAPS_NULLVALUE-307;
831
832 /* check for simple equality */
833 if ((inUnits == NULL((void*)0)) && (outUnits == NULL((void*)0))) {
834 for (i = 0; i < count; i++) outValue[i] = inValue[i];
835 return CAPS_SUCCESS0;
836 }
837 if (inUnits == NULL((void*)0)) return CAPS_UNITERR-320;
838 if (outUnits == NULL((void*)0)) return CAPS_UNITERR-320;
839 if (strcmp(outUnits, inUnits) == 0) {
840 for (i = 0; i < count; i++) outValue[i] = inValue[i];
841 return CAPS_SUCCESS0;
842 }
843
844 aInfo = (aimInfo *) aimStruc;
845 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
846 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
847 problem = aInfo->problem;
848
849 utunit1 = ut_parse((ut_system *) problem->utsystem, inUnits, UT_ASCII);
850 utunit2 = ut_parse((ut_system *) problem->utsystem, outUnits, UT_ASCII);
851 converter = ut_get_converter(utunit1, utunit2);
852 if (converter == NULL((void*)0)) {
853 ut_free(utunit1);
854 ut_free(utunit2);
855 AIM_ERROR(aimStruc, "Cannot convert units '%s' to '%s'", inUnits, outUnits){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 855, __func__
, "Cannot convert units '%s' to '%s'", inUnits, outUnits); }
;
856 return CAPS_UNITERR-320;
857 }
858
859 (void)cv_convert_doubles(converter, inValue, count, outValue);
860 cv_free(converter);
861 ut_free(utunit1);
862 ut_free(utunit2);
863
864 if (ut_get_status() != UT_SUCCESS) {
865 AIM_ERROR(aimStruc, "Cannot convert units '%s' to '%s'", inUnits, outUnits){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 865, __func__
, "Cannot convert units '%s' to '%s'", inUnits, outUnits); }
;
866 return CAPS_UNITERR-320;
867 }
868
869 return CAPS_SUCCESS0;
870}
871
872
873int
874aim_unitMultiply(void *aimStruc, const char *inUnits1, const char *inUnits2,
875 char **outUnits)
876{
877 int status;
878 aimInfo *aInfo;
879 capsProblem *problem;
880 ut_unit *utunit1, *utunit2, *utunit;
881 char buffer[UNIT_BUFFER_MAX257];
882
883 if ((inUnits1 == NULL((void*)0)) ||
884 (inUnits2 == NULL((void*)0)) || (outUnits == NULL((void*)0))) return CAPS_NULLNAME-308;
885 aInfo = (aimInfo *) aimStruc;
886 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
887 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
888 problem = aInfo->problem;
889
890 *outUnits = NULL((void*)0);
891
892 utunit1 = ut_parse((ut_system *) problem->utsystem, inUnits1, UT_ASCII);
893 utunit2 = ut_parse((ut_system *) problem->utsystem, inUnits2, UT_ASCII);
894 utunit = ut_multiply(utunit1, utunit2);
895 if (ut_get_status() != UT_SUCCESS) {
896 ut_free(utunit1);
897 ut_free(utunit2);
898 ut_free(utunit);
899 return CAPS_UNITERR-320;
900 }
901
902 status = ut_format(utunit, buffer, UNIT_BUFFER_MAX257, UT_ASCII);
903
904 ut_free(utunit1);
905 ut_free(utunit2);
906 ut_free(utunit);
907
908 if (status < UT_SUCCESS) {
909 return CAPS_UNITERR-320;
910 } else {
911 *outUnits = EG_strdup(buffer);
912 if (*outUnits == NULL((void*)0)) return EGADS_MALLOC-4;
913 return CAPS_SUCCESS0;
914 }
915}
916
917
918int
919aim_unitDivide(void *aimStruc, const char *inUnits1, const char *inUnits2,
920 char **outUnits)
921{
922 int status;
923 aimInfo *aInfo;
924 capsProblem *problem;
925 ut_unit *utunit1, *utunit2, *utunit;
926 char buffer[UNIT_BUFFER_MAX257];
927
928 if ((inUnits1 == NULL((void*)0)) ||
929 (inUnits2 == NULL((void*)0)) || (outUnits == NULL((void*)0))) return CAPS_NULLNAME-308;
930 aInfo = (aimInfo *) aimStruc;
931 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
932 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
933 problem = aInfo->problem;
934
935 *outUnits = NULL((void*)0);
936
937 utunit1 = ut_parse((ut_system *) problem->utsystem, inUnits1, UT_ASCII);
938 utunit2 = ut_parse((ut_system *) problem->utsystem, inUnits2, UT_ASCII);
939 utunit = ut_divide(utunit1, utunit2);
940 if (ut_get_status() != UT_SUCCESS) {
941 ut_free(utunit1);
942 ut_free(utunit2);
943 ut_free(utunit);
944 return CAPS_UNITERR-320;
945 }
946
947 status = ut_format(utunit, buffer, UNIT_BUFFER_MAX257, UT_ASCII);
948
949 ut_free(utunit1);
950 ut_free(utunit2);
951 ut_free(utunit);
952
953 if (ut_get_status() != UT_SUCCESS || status >= UNIT_BUFFER_MAX257) {
954 return CAPS_UNITERR-320;
955 } else {
956 *outUnits = EG_strdup(buffer);
957 if (*outUnits == NULL((void*)0)) return EGADS_MALLOC-4;
958 return CAPS_SUCCESS0;
959 }
960}
961
962
963int
964aim_unitInvert(void *aimStruc, const char *inUnit, char **outUnits)
965{
966 int status;
967 aimInfo *aInfo;
968 capsProblem *problem;
969 ut_unit *utunit1, *utunit;
970 char buffer[UNIT_BUFFER_MAX257];
971
972 if ((inUnit == NULL((void*)0)) || (outUnits == NULL((void*)0))) return CAPS_NULLNAME-308;
973 aInfo = (aimInfo *) aimStruc;
974 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
975 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
976 problem = aInfo->problem;
977
978 *outUnits = NULL((void*)0);
979
980 utunit1 = ut_parse((ut_system *) problem->utsystem, inUnit, UT_ASCII);
981 utunit = ut_invert(utunit1);
982 if (ut_get_status() != UT_SUCCESS) {
983 ut_free(utunit1);
984 ut_free(utunit);
985 return CAPS_UNITERR-320;
986 }
987
988 status = ut_format(utunit, buffer, UNIT_BUFFER_MAX257, UT_ASCII);
989
990 ut_free(utunit1);
991 ut_free(utunit);
992
993 if (ut_get_status() != UT_SUCCESS || status >= UNIT_BUFFER_MAX257) {
994 return CAPS_UNITERR-320;
995 } else {
996 *outUnits = EG_strdup(buffer);
997 if (*outUnits == NULL((void*)0)) return EGADS_MALLOC-4;
998 return CAPS_SUCCESS0;
999 }
1000}
1001
1002
1003int
1004aim_unitRaise(void *aimStruc, const char *inUnit, const int power,
1005 char **outUnits)
1006{
1007 int status;
1008 aimInfo *aInfo;
1009 capsProblem *problem;
1010 ut_unit *utunit1, *utunit;
1011 char buffer[UNIT_BUFFER_MAX257];
1012
1013 if ((inUnit == NULL((void*)0)) || (outUnits == NULL((void*)0))) return CAPS_NULLNAME-308;
1014 aInfo = (aimInfo *) aimStruc;
1015 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1016 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1017 problem = aInfo->problem;
1018
1019 *outUnits = NULL((void*)0);
1020
1021 utunit1 = ut_parse((ut_system *) problem->utsystem, inUnit, UT_ASCII);
1022 utunit = ut_raise(utunit1, power);
1023 if (ut_get_status() != UT_SUCCESS) {
1024 ut_free(utunit1);
1025 ut_free(utunit);
1026 return CAPS_UNITERR-320;
1027 }
1028
1029 status = ut_format(utunit, buffer, UNIT_BUFFER_MAX257, UT_ASCII);
1030
1031 ut_free(utunit1);
1032 ut_free(utunit);
1033
1034 if (ut_get_status() != UT_SUCCESS || status >= UNIT_BUFFER_MAX257) {
1035 return CAPS_UNITERR-320;
1036 } else {
1037 *outUnits = EG_strdup(buffer);
1038 if (*outUnits == NULL((void*)0)) return EGADS_MALLOC-4;
1039 return CAPS_SUCCESS0;
1040 }
1041}
1042
1043
1044int
1045aim_unitOffset(void *aimStruc, const char *inUnit, const double offset,
1046 char **outUnits)
1047{
1048 int status;
1049 aimInfo *aInfo;
1050 capsProblem *problem;
1051 ut_unit *utunit1, *utunit;
1052 char buffer[UNIT_BUFFER_MAX257];
1053
1054 if ((inUnit == NULL((void*)0)) || (outUnits == NULL((void*)0))) return CAPS_NULLNAME-308;
1055 aInfo = (aimInfo *) aimStruc;
1056 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1057 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1058 problem = aInfo->problem;
1059
1060 *outUnits = NULL((void*)0);
1061
1062 utunit1 = ut_parse((ut_system *) problem->utsystem, inUnit, UT_ASCII);
1063 utunit = ut_offset(utunit1, offset);
1064 if (ut_get_status() != UT_SUCCESS) {
1065 ut_free(utunit1);
1066 ut_free(utunit);
1067 return CAPS_UNITERR-320;
1068 }
1069
1070 status = ut_format(utunit, buffer, UNIT_BUFFER_MAX257, UT_ASCII);
1071
1072 ut_free(utunit1);
1073 ut_free(utunit);
1074
1075 if (ut_get_status() != UT_SUCCESS || status >= UNIT_BUFFER_MAX257) {
1076 return CAPS_UNITERR-320;
1077 } else {
1078 *outUnits = EG_strdup(buffer);
1079 if (*outUnits == NULL((void*)0)) return EGADS_MALLOC-4;
1080 return CAPS_SUCCESS0;
1081 }
1082}
1083
1084
1085int
1086aim_getIndex(void *aimStruc, /*@null@*/ const char *name,
1087 enum capssType subtype)
1088{
1089 int i, nobj;
1090 aimInfo *aInfo;
1091 capsProblem *problem;
1092 capsAnalysis *analysis;
1093 capsObject **objs;
1094
1095 aInfo = (aimInfo *) aimStruc;
1096 if ((subtype != GEOMETRYIN) && (subtype != GEOMETRYOUT) &&
1097 (subtype != ANALYSISIN) && (subtype != ANALYSISOUT) &&
1098 (subtype != ANALYSISDYNO)) return CAPS_BADTYPE-306;
1099 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1100 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1101 problem = aInfo->problem;
1102 analysis = (capsAnalysis *) aInfo->analysis;
1103 if (subtype == GEOMETRYIN) {
1104 nobj = problem->nGeomIn;
1105 objs = problem->geomIn;
1106 } else if (subtype == GEOMETRYOUT) {
1107 nobj = problem->nGeomOut;
1108 objs = problem->geomOut;
1109 } else if (subtype == ANALYSISIN) {
1110 nobj = analysis->nAnalysisIn;
1111 objs = analysis->analysisIn;
1112 } else if (subtype == ANALYSISOUT) {
1113 nobj = analysis->nAnalysisOut;
1114 objs = analysis->analysisOut;
1115 } else {
1116 nobj = analysis->nAnalysisDynO;
1117 objs = analysis->analysisDynO;
1118 }
1119 if (name == NULL((void*)0)) return nobj;
1120
1121 for (i = 0; i < nobj; i++) {
1122 if (objs[i]->name == NULL((void*)0)) {
1123 printf(" aimUtil Info: object %d with NULL name!\n", i+1);
1124 continue;
1125 }
1126 if (strcmp(objs[i]->name, name) == 0) return i+1;
1127 }
1128
1129 return CAPS_NOTFOUND-303;
1130}
1131
1132
1133int
1134aim_getValue(void *aimStruc, int index, enum capssType subtype,
1135 capsValue **value)
1136{
1137 int nobj;
1138 aimInfo *aInfo;
1139 capsProblem *problem;
1140 capsAnalysis *analysis;
1141 capsObject **objs;
1142 const char *objName = "";
1143
1144 aInfo = (aimInfo *) aimStruc;
1145 if ((subtype != GEOMETRYIN) && (subtype != GEOMETRYOUT) &&
1146 (subtype != ANALYSISIN) && (subtype != ANALYSISOUT) &&
1147 (subtype != ANALYSISDYNO)) return CAPS_BADTYPE-306;
1148 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1149 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1150 if (index <= 0) return CAPS_BADINDEX-304;
1151 problem = aInfo->problem;
1152 analysis = (capsAnalysis *) aInfo->analysis;
1153 if (subtype == GEOMETRYIN) {
1154 nobj = problem->nGeomIn;
1155 objs = problem->geomIn;
1156 objName = "GEOMETRYIN";
1157 } else if (subtype == GEOMETRYOUT) {
1158 nobj = problem->nGeomOut;
1159 objs = problem->geomOut;
1160 objName = "GEOMETRYOUT";
1161 } else if (subtype == ANALYSISIN) {
1162 nobj = analysis->nAnalysisIn;
1163 objs = analysis->analysisIn;
1164 objName = "ANALYSISIN";
1165 } else if (subtype == ANALYSISOUT) {
1166 nobj = analysis->nAnalysisOut;
1167 objs = analysis->analysisOut;
1168 objName = "ANALYSISOUT";
1169 } else {
1170 nobj = analysis->nAnalysisDynO;
1171 objs = analysis->analysisDynO;
1172 objName = "ANALYSISDYNO";
1173 }
1174 if (index > nobj) {
1175 AIM_ERROR(aimStruc, "%s Index (%d > %d) out-of-range!", objName, index, nobj){ aim_message(aimStruc, CERROR, 0 , "aimUtil.c", 1175, __func__
, "%s Index (%d > %d) out-of-range!", objName, index, nobj
); }
;
1176 return CAPS_BADINDEX-304;
1177 }
1178
1179 *value = (capsValue *) objs[index-1]->blind;
1180 return CAPS_SUCCESS0;
1181}
1182
1183
1184int
1185aim_initValue(capsValue *value)
1186{
1187 if (value == NULL((void*)0)) return CAPS_NULLVALUE-307;
1188
1189 value->length = value->nrow = value->ncol = 1;
1190 value->type = Integer;
1191 value->dim = value->pIndex = value->index = 0;
1192 value->lfixed = value->sfixed = Fixed;
1193 value->nullVal = NotAllowed;
1194 value->lims = NULL((void*)0);
1195 value->units = NULL((void*)0);
1196 value->meshWriter = NULL((void*)0);
1197 value->link = NULL((void*)0);
1198 value->vals.reals = NULL((void*)0);
1199 value->limits.dlims[0] = value->limits.dlims[1] = 0.0;
1200 value->linkMethod = Copy;
1201 value->gInType = 0;
1202 value->partial = NULL((void*)0);
1203 value->nderiv = 0;
1204 value->derivs = NULL((void*)0);
1205
1206 return CAPS_SUCCESS0;
1207}
1208
1209
1210int
1211aim_copyValue(capsValue *value, capsValue *copy)
1212{
1213 int i, j, len, *ilims, *isrcs;
1214 double *dlims, *dsrcs;
1215
1216 if (value == NULL((void*)0)) return CAPS_NULLVALUE-307;
1217 if (copy == NULL((void*)0)) return CAPS_NULLVALUE-307;
1218
1219 aim_initValue(copy);
1220
1221 copy->length = value->length;
1222 copy->nrow = value->nrow;
1223 copy->ncol = value->ncol;
1224 copy->type = value->type;
1225 copy->dim = value->dim;
1226 copy->pIndex = value->pIndex;
1227 copy->index = value->index;
1228 copy->lfixed = value->lfixed;
1229 copy->sfixed = value->sfixed;
1230 copy->nullVal = value->nullVal;
1231 copy->lims = NULL((void*)0);
1232 copy->units = EG_strdup(value->units);
1233 copy->meshWriter = value->meshWriter;
1234 copy->link = value->link;
1235
1236 if (copy->type == Double || copy->type == DoubleDeriv) {
1237 if (value->length > 1) {
1238 copy->vals.reals = (double *) EG_alloc(value->length*sizeof(double));
1239 if (copy->vals.reals == NULL((void*)0)) return EGADS_MALLOC-4;
1240 for (i = 0; i < value->length; i++)
1241 copy->vals.reals[i] = value->vals.reals[i];
1242 if (value->lims != NULL((void*)0)) {
1243 dsrcs = (double *) value->lims;
1244 dlims = (double *) EG_alloc(2*value->length*sizeof(double));
1245 if (dlims == NULL((void*)0)) return EGADS_MALLOC-4;
1246 for (i = 0; i < 2*value->length; i++) dlims[i] = dsrcs[i];
1247 copy->lims = dlims;
1248 }
1249 } else {
1250 copy->vals.real = value->vals.real;
1251 }
1252 } else if (copy->type == Integer) {
1253 if (value->length > 1) {
1254 copy->vals.integers = (int *) EG_alloc(value->length*sizeof(int));
1255 if (copy->vals.integers == NULL((void*)0)) return EGADS_MALLOC-4;
1256 for (i = 0; i < value->length; i++)
1257 copy->vals.integers[i] = value->vals.integers[i];
1258 if (value->lims != NULL((void*)0)) {
1259 isrcs = (int *) value->lims;
1260 ilims = (int *) EG_alloc(2*value->length*sizeof(int));
1261 if (ilims == NULL((void*)0)) return EGADS_MALLOC-4;
1262 for (i = 0; i < 2*value->length; i++) ilims[i] = isrcs[i];
1263 copy->lims = ilims;
1264 }
1265 } else {
1266 copy->vals.integer = value->vals.integer;
1267 }
1268 } else if (copy->type == String) {
1269 if (value->length > 1) {
1270 len = 0;
1271 for (i = 0; i < value->length; i++)
1272 len += strlen(&value->vals.string[len])+1;
1273
1274 copy->vals.string = (char *) EG_alloc(len*sizeof(char));
1275 if (copy->vals.string == NULL((void*)0)) return EGADS_MALLOC-4;
1276 for (i = 0; i < len; i++)
1277 copy->vals.string[i] = value->vals.string[i];
1278 } else {
1279 copy->vals.string = EG_strdup(value->vals.string);
1280 }
1281 } else if (copy->type == Tuple) {
1282
1283 copy->vals.tuple = (capsTuple *) EG_alloc(value->length*sizeof(capsTuple));
1284 if (copy->vals.tuple == NULL((void*)0)) return EGADS_MALLOC-4;
1285 for (i = 0; i < value->length; i++) {
1286 copy->vals.tuple[i].name = EG_strdup(value->vals.tuple[i].name);
1287 copy->vals.tuple[i].value = EG_strdup(value->vals.tuple[i].value);
1288 }
1289 } else {
1290 return CAPS_NOTIMPLEMENT-334;
1291 }
1292
1293 copy->limits.dlims[0] = value->limits.dlims[0];
1294 copy->limits.dlims[1] = value->limits.dlims[1];
1295 copy->linkMethod = value->linkMethod;
1296 copy->gInType = value->gInType;
1297 if (value->partial != NULL((void*)0)) {
1298 copy->partial = (int *) EG_alloc(value->length*sizeof(int));
1299 if (copy->partial == NULL((void*)0)) return EGADS_MALLOC-4;
1300
1301 for (i = 0; i < value->length; i++)
1302 copy->partial[i] = value->partial[i];
1303 }
1304 copy->nderiv = value->nderiv;
1305 if (value->derivs != NULL((void*)0)) {
1306
1307 copy->derivs = (capsDeriv *) EG_alloc(value->nderiv*sizeof(capsDeriv));
1308 if (copy->derivs == NULL((void*)0)) return EGADS_MALLOC-4;
1309
1310 for (i = 0; i < value->length; i++) {
1311 copy->derivs[i].len_wrt = value->derivs[i].len_wrt;
1312 copy->derivs[i].name = EG_strdup(copy->derivs[i].name);
1313
1314 len = value->length*value->derivs[i].len_wrt;
1315 copy->derivs[i].deriv = (double *) EG_alloc(len*sizeof(double));
1316 for (j = 0; j < len; j++) {
1317 copy->derivs[i].deriv[j] = value->derivs[i].deriv[j];
1318 }
1319 }
1320 }
1321
1322 return CAPS_SUCCESS0;
1323}
1324
1325
1326void
1327aim_freeValue(capsValue *value)
1328{
1329 int i;
1330
1331 if (value == NULL((void*)0)) return;
1332
1333 EG_free(value->units);
1334
1335 if (value->length > 1) {
1336 if (value->type == Double || value->type == DoubleDeriv) {
1337 EG_free(value->vals.reals);
1338 } else if (value->type == Integer) {
1339 EG_free(value->vals.integers);
1340 } else if (value->type == String) {
1341 EG_free(value->vals.string);
1342 } else if (value->type == Tuple) {
1343 for (i = 0; i < value->length; i++) {
1344 EG_free(value->vals.tuple[i].name);
1345 EG_free(value->vals.tuple[i].value);
1346 }
1347 EG_free(value->vals.tuple);
1348 }
1349 }
1350 EG_free(value->partial);
1351 if (value->derivs != NULL((void*)0)) {
1352 for (i = 0; i < value->nderiv; i++) {
1353 EG_free(value->derivs[i].name);
1354 EG_free(value->derivs[i].deriv);
1355 }
1356 EG_free(value->derivs);
1357 }
1358
1359 aim_initValue(value);
1360}
1361
1362
1363int
1364aim_makeDynamicOutput(void *aimStruc, const char *dynObjName, capsValue *value)
1365{
1366 int i;
1367 aimInfo *aInfo;
1368 capsAnalysis *analysis;
1369 capsProblem *problem;
1370 capsValue *val;
1371 capsObject *obj, **tmp, *pobject;
1372
1373 aInfo = (aimInfo *) aimStruc;
1374 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1375 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1376 if (dynObjName == NULL((void*)0)) return CAPS_NULLNAME-308;
1377 if (value == NULL((void*)0)) return CAPS_NULLVALUE-307;
1378 if (aInfo->funID != AIM_POSTANALYSIS3) return CAPS_STATEERR-329;
1379 problem = aInfo->problem;
1380 pobject = problem->mySelf;
1381 analysis = (capsAnalysis *) aInfo->analysis;
1382
1383 for (i = 0; i < analysis->nAnalysisDynO; i++) {
1384 obj = analysis->analysisDynO[i];
1385 if (obj == NULL((void*)0)) continue;
1386 if (obj->name == NULL((void*)0)) continue;
1387 if (strcmp(obj->name, dynObjName) == 0) return CAPS_BADNAME-317;
1388 }
1389 for (i = 0; i < problem->nAnalysis; i++) {
1390 if (problem->analysis[i] == NULL((void*)0)) continue;
1391 if (problem->analysis[i]->blind == analysis) break;
1392 }
1393 if (i == problem->nAnalysis) return CAPS_NOTFOUND-303;
1394
1395 /* make the object and fill it in */
1396
1397 val = (capsValue *) EG_alloc(sizeof(capsValue));
1398 obj = (capsObject *) EG_alloc(sizeof(capsObject));
1399 if ((obj == NULL((void*)0)) || (val == NULL((void*)0))) {
1400 if (obj != NULL((void*)0)) EG_free(obj);
1401 if (val != NULL((void*)0)) EG_free(val);
1402 return EGADS_MALLOC-4;
1403 }
1404
1405 if (analysis->analysisDynO == NULL((void*)0)) {
1406 analysis->analysisDynO = (capsObject **) EG_alloc(sizeof(capsObject *));
1407 if (analysis->analysisDynO == NULL((void*)0)) {
1408 EG_free(obj);
1409 EG_free(val);
1410 return EGADS_MALLOC-4;
1411 }
1412 analysis->nAnalysisDynO = 0;
1413 } else {
1414 tmp = (capsObject **) EG_reall( analysis->analysisDynO,
1415 (analysis->nAnalysisDynO+1)*
1416 sizeof(capsObject *));
1417 if (tmp == NULL((void*)0)) {
1418 EG_free(obj);
1419 EG_free(val);
1420 return EGADS_MALLOC-4;
1421 }
1422 analysis->analysisDynO = tmp;
1423 }
1424 /* copy contents */
1425 (*val) = (*value);
1426 val->index = analysis->nAnalysisDynO+1;
1427
1428 obj->magicnumber = CAPSMAGIC1234321;
1429 obj->type = VALUE;
1430 obj->subtype = ANALYSISDYNO;
1431 obj->delMark = 0;
1432 obj->name = EG_strdup(dynObjName);
1433 obj->attrs = NULL((void*)0);
1434 obj->blind = val;
1435 obj->flist = NULL((void*)0);
1436 obj->parent = problem->analysis[i];
1437 obj->nHistory = 0;
1438 obj->history = NULL((void*)0);
1439 obj->last.index = -1;
1440 obj->last.pname = EG_strdup(pobject->last.pname);
1441 obj->last.pID = EG_strdup(pobject->last.pID);
1442 obj->last.user = EG_strdup(pobject->last.user);
1443 obj->last.sNum = pobject->last.sNum;
1444 for (i = 0; i < 6; i++)
1445 obj->last.datetime[i] = pobject->last.datetime[i];
1446
1447 analysis->analysisDynO[analysis->nAnalysisDynO] = obj;
1448 analysis->nAnalysisDynO++;
1449
1450 /* clear out the input value structure */
1451 (void) aim_initValue(value);
1452 return CAPS_SUCCESS0;
1453}
1454
1455
1456int
1457aim_getName(void *aimStruc, int index, enum capssType subtype,
1458 const char **name)
1459{
1460 int nobj;
1461 aimInfo *aInfo;
1462 capsProblem *problem;
1463 capsAnalysis *analysis;
1464 capsObject **objs;
1465
1466 aInfo = (aimInfo *) aimStruc;
1467 if ((subtype != GEOMETRYIN) && (subtype != GEOMETRYOUT) &&
1468 (subtype != ANALYSISIN) && (subtype != ANALYSISOUT) &&
1469 (subtype != ANALYSISDYNO)) return CAPS_BADTYPE-306;
1470 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1471 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1472 if (index <= 0) return CAPS_BADINDEX-304;
1473 problem = aInfo->problem;
1474 analysis = (capsAnalysis *) aInfo->analysis;
1475 if (subtype == GEOMETRYIN) {
1476 nobj = problem->nGeomIn;
1477 objs = problem->geomIn;
1478 } else if (subtype == GEOMETRYOUT) {
1479 nobj = problem->nGeomOut;
1480 objs = problem->geomOut;
1481 } else if (subtype == ANALYSISIN) {
1482 nobj = analysis->nAnalysisIn;
1483 objs = analysis->analysisIn;
1484 } else if (subtype == ANALYSISOUT) {
1485 nobj = analysis->nAnalysisOut;
1486 objs = analysis->analysisOut;
1487 } else {
1488 nobj = analysis->nAnalysisDynO;
1489 objs = analysis->analysisDynO;
1490 }
1491 if (index > nobj) return CAPS_BADINDEX-304;
1492
1493 *name = objs[index-1]->name;
1494 return CAPS_SUCCESS0;
1495}
1496
1497
1498int
1499aim_getGeomInType(void *aimStruc, int index)
1500{
1501 aimInfo *aInfo;
1502 capsObject *vobj;
1503 capsValue *value;
1504 capsProblem *problem;
1505
1506 aInfo = (aimInfo *) aimStruc;
1507 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1508 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1509 if (index <= 0) return CAPS_BADINDEX-304;
1510 problem = aInfo->problem;
1511 if (index > problem->nGeomIn) return CAPS_BADINDEX-304;
1512 vobj = problem->geomIn[index-1];
1513 if (vobj->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1514 if (vobj->type != VALUE) return CAPS_BADTYPE-306;
1515 if (vobj->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1516 value = (capsValue *) vobj->blind;
1517
1518 return value->gInType;
1519}
1520
1521
1522int
1523aim_newTess(void *aimStruc, ego tess)
1524{
1525 int stat, i, state, npts;
1526 aimInfo *aInfo;
1527 capsAnalysis *analysis;
1528 ego body, tbody;
1529
1530 aInfo = (aimInfo *) aimStruc;
1531 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1532 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1533 if (tess == NULL((void*)0)) return EGADS_NULLOBJ-2;
1534 if (tess->magicnumber != MAGIC98789) return EGADS_NOTOBJ-3;
1535 analysis = (capsAnalysis *) aInfo->analysis;
1536
1537 /* allocate tessellation storage if it does not exist */
1538 if (analysis->tess == NULL((void*)0)) {
1539 analysis->tess = (ego *) EG_alloc(analysis->nBody*sizeof(ego));
1540 if (analysis->tess == NULL((void*)0)) return EGADS_MALLOC-4;
1541 analysis->nTess = analysis->nBody;
1542 for (i = 0; i < analysis->nBody; i++) analysis->tess[i] = NULL((void*)0);
1543 }
1544
1545 /* associate a tessellation object */
1546 stat = EG_statusTessBody(tess, &body, &state, &npts);
1547 if (stat < EGADS_SUCCESS0) return stat;
1548 if (stat == EGADS_OUTSIDE1) return CAPS_SOURCEERR-330;
1549
1550 for (i = 0; i < analysis->nBody; i++) {
1551 if (body != analysis->bodies[i]) continue;
1552 if (analysis->tess[i] != NULL((void*)0)) {
1553 EG_deleteObject(analysis->tess[i]);
1554 }
1555 analysis->tess[i] = tess;
1556 return CAPS_SUCCESS0;
1557 }
1558
1559 /* look for AIM created bodies */
1560 for (i = analysis->nBody-1; i < analysis->nTess; i++) {
1561 stat = EG_statusTessBody(analysis->tess[i], &tbody, &state, &npts);
1562 if (stat < EGADS_SUCCESS0) return stat;
1563 if (stat == EGADS_OUTSIDE1) return CAPS_SOURCEERR-330;
1564 if (tbody != body) continue;
1565 if (analysis->tess[i] != NULL((void*)0)) {
1566 EG_deleteObject(analysis->tess[i]);
1567 }
1568 analysis->tess[i] = tess;
1569 return CAPS_SUCCESS0;
1570 }
1571
1572 /* not in the Body list -- extend the list of tessellations */
1573 analysis->tess = (ego *) EG_reall(analysis->tess, (analysis->nTess+1)*sizeof(ego));
1574 if (analysis->tess == NULL((void*)0)) return EGADS_MALLOC-4;
1575 analysis->tess[analysis->nTess] = tess;
1576 analysis->nTess++;
1577
1578 return CAPS_SUCCESS0;
1579}
1580
1581
1582int
1583aim_getDiscr(void *aimStruc, const char *bname, capsDiscr **discr)
1584{
1585 int i, j;
1586 aimInfo *aInfo;
1587 capsProblem *problem;
1588 capsBound *bound;
1589 capsAnalysis *analysis, *analy;
1590 capsVertexSet *vertexset;
1591
1592 *discr = NULL((void*)0);
1593 aInfo = (aimInfo *) aimStruc;
1594 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1595 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1596 problem = aInfo->problem;
1597 analysis = (capsAnalysis *) aInfo->analysis;
1598
1599 /* find bound with same name */
1600 for (i = 0; i < problem->nBound; i++) {
1601 if (problem->bounds[i] == NULL((void*)0)) continue;
1602 if (problem->bounds[i]->name == NULL((void*)0)) continue;
1603 if (strcmp(bname, problem->bounds[i]->name) != 0) continue;
1604 /* find our analysis in the Bound */
1605 bound = (capsBound *) problem->bounds[i]->blind;
1606 if (bound == NULL((void*)0)) return CAPS_NULLOBJ-309;
1607 for (j = 0; j < bound->nVertexSet; j++) {
1608 if (bound->vertexSet[j] == NULL((void*)0)) continue;
1609 if (bound->vertexSet[j]->magicnumber != CAPSMAGIC1234321) continue;
1610 if (bound->vertexSet[j]->type != VERTEXSET) continue;
1611 if (bound->vertexSet[j]->blind == NULL((void*)0)) continue;
1612 vertexset = (capsVertexSet *) bound->vertexSet[j]->blind;
1613 if (vertexset == NULL((void*)0)) continue;
1614 if (vertexset->analysis == NULL((void*)0)) continue;
1615 analy = (capsAnalysis *) vertexset->analysis->blind;
1616 if (analy != analysis) continue;
1617 *discr = vertexset->discr;
1618 return CAPS_SUCCESS0;
1619 }
1620 }
1621
1622 return CAPS_NOTFOUND-303;
1623}
1624
1625
1626int
1627aim_getDiscrState(void *aimStruc, const char *bname)
1628{
1629 int i;
1630 aimInfo *aInfo;
1631 capsProblem *problem;
1632 capsObject *bobject;
1633 capsBound *bound;
1634
1635 aInfo = (aimInfo *) aimStruc;
1636 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1637 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1638 problem = aInfo->problem;
1639
1640 /* find bound with same name */
1641 for (i = 0; i < problem->nBound; i++) {
1642 if (problem->bounds[i] == NULL((void*)0)) continue;
1643 if (problem->bounds[i]->name == NULL((void*)0)) continue;
1644 if (strcmp(bname, problem->bounds[i]->name) != 0) continue;
1645 bobject = problem->bounds[i];
1646 bound = (capsBound *) bobject->blind;
1647 if (bound == NULL((void*)0)) return CAPS_NULLOBJ-309;
1648 if (bobject->last.sNum < problem->geometry.sNum) return CAPS_DIRTY-327;
1649 return CAPS_SUCCESS0;
1650 }
1651
1652 return CAPS_NOTFOUND-303;
1653}
1654
1655
1656int
1657aim_getDataSet(capsDiscr *discr, const char *dname, enum capsdMethod *method,
1658 int *npts, int *rank, double **data, char **units)
1659{
1660 int i, j, k;
1661 aimInfo *aInfo;
1662 capsObject *link, *dobject;
1663 capsProblem *problem;
1664 capsBound *bound;
1665 capsAnalysis *analysis, *analy;
1666 capsVertexSet *vertexset;
1667 capsDataSet *dataset;
1668
1669 *method = Interpolate;
1670 *npts = *rank = 0;
1671 *data = NULL((void*)0);
1672 if (discr == NULL((void*)0)) return CAPS_NULLOBJ-309;
1673 aInfo = discr->aInfo;
1674 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1675 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1676 if (aInfo->funID != AIM_PREANALYSIS2) return CAPS_STATEERR-329;
1677 problem = aInfo->problem;
1678 analysis = (capsAnalysis *) aInfo->analysis;
1679
1680 /* find dataset in discr */
1681 for (i = 0; i < problem->nBound; i++) {
1682 if (problem->bounds[i] == NULL((void*)0)) continue;
1683 bound = (capsBound *) problem->bounds[i]->blind;
1684 if (bound == NULL((void*)0)) continue;
1685 for (j = 0; j < bound->nVertexSet; j++) {
1686 if (bound->vertexSet[j] == NULL((void*)0)) continue;
1687 if (bound->vertexSet[j]->magicnumber != CAPSMAGIC1234321) continue;
1688 if (bound->vertexSet[j]->type != VERTEXSET) continue;
1689 if (bound->vertexSet[j]->blind == NULL((void*)0)) continue;
1690 vertexset = (capsVertexSet *) bound->vertexSet[j]->blind;
1691 if (vertexset == NULL((void*)0)) continue;
1692 if (vertexset->analysis == NULL((void*)0)) continue;
1693 analy = (capsAnalysis *) vertexset->analysis->blind;
1694 if (analy != analysis) continue;
1695 if (vertexset->discr != discr) continue;
1696 for (k = 0; k < vertexset->nDataSets; k++) {
1697 if (vertexset->dataSets[k] == NULL((void*)0)) continue;
1698 if (vertexset->dataSets[k]->name == NULL((void*)0)) continue;
1699 if (strcmp(dname, vertexset->dataSets[k]->name) != 0) continue;
1700 dobject = vertexset->dataSets[k];
1701 dataset = (capsDataSet *) dobject->blind;
1702 if (dataset == NULL((void*)0)) return CAPS_NULLOBJ-309;
1703 /* are we dirty? */
1704 if (dataset->ftype == FieldIn) {
1705 /* check linked source DataSets */
1706 link = dataset->link;
1707 if (link == NULL((void*)0) ) return CAPS_SOURCEERR-330;
1708 if (link->magicnumber != CAPSMAGIC1234321) return CAPS_SOURCEERR-330;
1709 if (link->type != DATASET ) return CAPS_SOURCEERR-330;
1710 if ((link->last.sNum == 0) &&
1711 (dataset->startup != NULL((void*)0))) {
1712 /* special startup data */
1713 *method = dataset->linkMethod;
1714 *rank = dataset->rank;
1715 *npts = 1;
1716 *data = dataset->startup;
1717 return CAPS_SUCCESS0;
1718 }
1719 if ((link->last.sNum > dobject->last.sNum) ||
1720 (dataset->data == NULL((void*)0))) return CAPS_DIRTY-327;
1721 }
1722 *method = dataset->linkMethod;
1723 *rank = dataset->rank;
1724 *npts = dataset->npts;
1725 *data = dataset->data;
1726 *units = dataset->units;
1727 return CAPS_SUCCESS0;
1728 }
1729 }
1730 }
1731
1732 return CAPS_NOTFOUND-303;
1733}
1734
1735
1736int
1737aim_getBounds(void *aimStruc, int *nTname, char ***tnames)
1738{
1739 int i, j, k;
1740 char **names;
1741 aimInfo *aInfo;
1742 capsProblem *problem;
1743 capsBound *bound;
1744 capsAnalysis *analysis, *analy;
1745 capsVertexSet *vertexset;
1746
1747 *tnames = NULL((void*)0);
1748 *nTname = 0;
1749 aInfo = (aimInfo *) aimStruc;
1750 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1751 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1752 problem = aInfo->problem;
1753 analysis = (capsAnalysis *) aInfo->analysis;
1754
1755 if (problem->nBound == 0) return CAPS_SUCCESS0;
1756 names = (char **) EG_alloc(problem->nBound*sizeof(char *));
1757 if (names == NULL((void*)0)) return EGADS_MALLOC-4;
1758
1759 /* look at all bounds and find those with this analysis */
1760 for (k = i = 0; i < problem->nBound; i++) {
1761 if (problem->bounds[i] == NULL((void*)0)) continue;
1762 if (problem->bounds[i]->name == NULL((void*)0)) continue;
1763 /* find our analysis in the Bound */
1764 bound = (capsBound *) problem->bounds[i]->blind;
1765 if (bound == NULL((void*)0)) continue;
1766 for (j = 0; j < bound->nVertexSet; j++) {
1767 if (bound->vertexSet[j] == NULL((void*)0)) continue;
1768 if (bound->vertexSet[j]->magicnumber != CAPSMAGIC1234321) continue;
1769 if (bound->vertexSet[j]->type != VERTEXSET) continue;
1770 if (bound->vertexSet[j]->blind == NULL((void*)0)) continue;
1771 vertexset = (capsVertexSet *) bound->vertexSet[j]->blind;
1772 if (vertexset == NULL((void*)0)) continue;
1773 if (vertexset->analysis == NULL((void*)0)) continue;
1774 analy = (capsAnalysis *) vertexset->analysis->blind;
1775 if (analy != analysis) continue;
1776 names[k] = problem->bounds[i]->name;
1777 k++;
1778 break;
1779 }
1780 }
1781 if (k == 0) {
1782 EG_free(names);
1783 return CAPS_SUCCESS0;
1784 }
1785
1786 *nTname = k;
1787 *tnames = names;
1788 return CAPS_SUCCESS0;
1789}
1790
1791
1792static int
1793aim_fillAttrs(capsObject *object, int *n, char ***names, capsValue **values)
1794{
1795 int i, j, num, len, atype, slen;
1796 char **aName;
1797 capsValue *value;
1798
1799 num = object->attrs->nattrs;
1800 if (num <= 0) return CAPS_SUCCESS0;
1801 aName = (char **) EG_alloc(num*sizeof(char *));
1802 if (aName == NULL((void*)0)) return EGADS_MALLOC-4;
1803 value = (capsValue *) EG_alloc(num*sizeof(capsValue));
1804 if (value == NULL((void*)0)) {
1805 EG_free(aName);
1806 return EGADS_MALLOC-4;
1807 }
1808 for (i = 0; i < num; i++) {
1809 len = object->attrs->attrs[i].length;
1810 atype = object->attrs->attrs[i].type;
1811 value[i].length = 1;
1812 value[i].type = Integer;
1813 value[i].nrow = value[i].ncol = value[i].dim = 0;
1814 value[i].index = value[i].pIndex = 0;
1815 value[i].lfixed = value[i].sfixed = Fixed;
1816 value[i].nullVal = NotAllowed;
1817 value[i].lims = NULL((void*)0);
1818 value[i].units = NULL((void*)0);
1819 value[i].meshWriter = NULL((void*)0);
1820 value[i].link = NULL((void*)0);
1821 aName[i] = EG_strdup(object->attrs->attrs[i].name);
1822 if (aName[i] == NULL((void*)0)) goto bail;
1823 value[i].limits.dlims[0] = value[i].limits.dlims[1] = 0.0;
1824 value[i].linkMethod = Copy;
1825 value[i].gInType = 0;
1826 value[i].partial = NULL((void*)0);
1827 value[i].nderiv = 0;
1828 value[i].derivs = NULL((void*)0);
1829 if (atype == ATTRINT1) {
1830 if (len == 1) {
1831 value[i].vals.integer = object->attrs->attrs[i].vals.integer;
1832 } else {
1833 value[i].vals.integers = (int *) EG_alloc(len*sizeof(int));
1834 if (value[i].vals.integers == NULL((void*)0)) goto bail;
1835 for (j = 0; j < len; j++)
1836 value[i].vals.integers[j] = object->attrs->attrs[i].vals.integers[j];
1837 }
1838 } else if (atype == ATTRREAL2) {
1839 value[i].type = Double;
1840 if (len == 1) {
1841 value[i].vals.real = object->attrs->attrs[i].vals.real;
1842 } else {
1843 value[i].vals.reals = (double *) EG_alloc(len*sizeof(double));
1844 if (value[i].vals.reals == NULL((void*)0)) goto bail;
1845 for (j = 0; j < len; j++)
1846 value[i].vals.reals[j] = object->attrs->attrs[i].vals.reals[j];
1847 }
1848 } else {
1849 value[i].type = String;
1850 for (slen = j = 0; j < value[i].length; j++)
1851 slen += strlen(object->attrs->attrs[i].vals.string + slen) + 1;
1852 value[i].vals.string = (char*) EG_alloc(slen*sizeof(char));
1853 if (value[i].vals.string == NULL((void*)0)) goto bail;
1854 for (j = 0; j < slen; j++)
1855 value[i].vals.string[j] = object->attrs->attrs[i].vals.string[j];
1856 }
1857 value[i].length = len;
1858 }
1859
1860 *n = num;
1861 *names = aName;
1862 *values = value;
1863 return CAPS_SUCCESS0;
1864
1865bail:
1866 for (j = 0; j < i; j++) {
1867 EG_free(aName[j]);
1868 if (value[j].type == Integer) {
1869 if (value[j].length == 1) continue;
1870 EG_free(value[j].vals.integers);
1871 } else if (value[j].type == Double) {
1872 if (value[j].length == 1) continue;
1873 EG_free(value[j].vals.reals);
1874 } else {
1875 EG_free(value[j].vals.string);
1876 }
1877 }
1878/*@-dependenttrans@*/
1879 EG_free(aName);
1880 EG_free(value);
1881/*@+dependenttrans@*/
1882 return EGADS_MALLOC-4;
1883}
1884
1885
1886int
1887aim_valueAttrs(void *aimStruc, int index, enum capssType stype, int *nValue,
1888 char ***names, capsValue **values)
1889{
1890 aimInfo *aInfo;
1891 capsProblem *problem;
1892 capsAnalysis *analysis;
1893 capsObject *object = NULL((void*)0);
1894
1895 *nValue = 0;
1896 *names = NULL((void*)0);
1897 *values = NULL((void*)0);
1898 aInfo = (aimInfo *) aimStruc;
1899 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1900 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1901 if (index < 1) return CAPS_BADINDEX-304;
1902 problem = aInfo->problem;
1903 analysis = (capsAnalysis *) aInfo->analysis;
1904
1905 if (stype == GEOMETRYIN) {
1906 if (index > problem->nGeomIn) return CAPS_BADINDEX-304;
1907 object = problem->geomIn[index-1];
1908 } else if (stype == GEOMETRYOUT) {
1909 if (index > problem->nGeomOut) return CAPS_BADINDEX-304;
1910 object = problem->geomOut[index-1];
1911 } else if (stype == ANALYSISIN) {
1912 if (index > analysis->nAnalysisIn) return CAPS_BADINDEX-304;
1913 object = analysis->analysisIn[index-1];
1914 } else if (stype == ANALYSISOUT) {
1915 if (index > analysis->nAnalysisOut) return CAPS_BADINDEX-304;
1916 object = analysis->analysisOut[index-1];
1917 } else if (stype == ANALYSISDYNO) {
1918 if (index > analysis->nAnalysisDynO) return CAPS_BADINDEX-304;
1919 object = analysis->analysisDynO[index-1];
1920 } else {
1921 return CAPS_BADTYPE-306;
1922 }
1923 if (object == NULL((void*)0)) return CAPS_NULLOBJ-309;
1924 if (object->attrs == NULL((void*)0)) return CAPS_SUCCESS0;
1925
1926 return aim_fillAttrs(object, nValue, names, values);
1927}
1928
1929
1930int
1931aim_analysisAttrs(void *aimStruc, int *nValue, char ***names,
1932 capsValue **values)
1933{
1934 int i;
1935 aimInfo *aInfo;
1936 capsProblem *problem;
1937 capsAnalysis *analysis;
1938
1939 *nValue = 0;
1940 *names = NULL((void*)0);
1941 *values = NULL((void*)0);
1942 aInfo = (aimInfo *) aimStruc;
1943 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1944 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1945 problem = aInfo->problem;
1946 analysis = (capsAnalysis *) aInfo->analysis;
1947
1948 for (i = 0; i < problem->nAnalysis; i++) {
1949 if (problem->analysis[i] == NULL((void*)0)) continue;
1950 if (problem->analysis[i]->blind == analysis) break;
1951 }
1952 if (i == problem->nAnalysis) return CAPS_NOTFOUND-303;
1953
1954 return aim_fillAttrs(problem->analysis[i], nValue, names, values);
1955}
1956
1957
1958void
1959aim_freeAttrs(int nValue, char **names, capsValue *values)
1960{
1961 int i;
1962
1963 for (i = 0; i < nValue; i++) {
1964 EG_free(names[i]);
1965 if (values[i].type == Integer) {
1966 if (values[i].length == 1) continue;
1967 EG_free(values[i].vals.integers);
1968 } else if (values[i].type == Double) {
1969 if (values[i].length == 1) continue;
1970 EG_free(values[i].vals.reals);
1971 } else {
1972 EG_free(values[i].vals.string);
1973 }
1974 }
1975 EG_free(names);
1976 EG_free(values);
1977}
1978
1979
1980int
1981aim_setSensitivity(void *aimStruc, const char *GIname, int irow, int icol)
1982{
1983 int stat, i, j, k, m, n, ipmtr, nbrch, npmtr, nrow, ncol, type;
1984 int buildTo, builtTo, nbody, i_wrt, len_wrt, outLevel;
1985 char name[MAX_NAME_LEN64];
1986 double *reals;
1987 modl_T *MODL;
1988 aimInfo *aInfo;
1989 capsProblem *problem;
1990 capsValue *value;
1991
1992 aInfo = (aimInfo *) aimStruc;
1993 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1994 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1995 if (GIname == NULL((void*)0)) return CAPS_NULLNAME-308;
1996 if ((irow < 1) || (icol < 1)) return CAPS_BADINDEX-304;
1997 problem = aInfo->problem;
1998 MODL = (modl_T *) problem->modl;
1999 if (MODL == NULL((void*)0)) return CAPS_NOTPARMTRIC-314;
2000
2001 /* find the OpenCSM Parameter */
2002 stat = ocsmInfo(problem->modl, &nbrch, &npmtr, &nbody);
2003 if (stat != SUCCESS0) return stat;
2004 for (ipmtr = i = 0; i < npmtr; i++) {
2005 stat = ocsmGetPmtr(problem->modl, i+1, &type, &nrow, &ncol, name);
2006 if (stat != SUCCESS0) continue;
2007 if (type != OCSM_DESPMTR500) continue;
2008 if (strcmp(name, GIname) != 0) continue;
2009 ipmtr = i+1;
2010 break;
2011 }
2012 if (ipmtr == 0) return CAPS_NOSENSITVTY-340;
2013 if (irow > nrow) return CAPS_BADINDEX-304;
2014 if (icol > ncol) return CAPS_BADINDEX-304;
2015
2016 aInfo->pIndex = 0;
2017 aInfo->irow = 0;
2018 aInfo->icol = 0;
2019
2020 /* clear all then set */
2021 stat = ocsmSetDtime(problem->modl, 0);
2022 if (stat != SUCCESS0) return stat;
2023 stat = ocsmSetVelD(problem->modl, 0, 0, 0, 0.0);
2024 if (stat != SUCCESS0) return stat;
2025 stat = ocsmSetVelD(problem->modl, ipmtr, irow, icol, 1.0);
2026 if (stat != SUCCESS0) return stat;
2027 buildTo = 0;
2028 nbody = 0;
2029 outLevel = ocsmSetOutLevel(0);
2030 printf(" CAPS Info: Building sensitivity information for: %s[%d,%d]\n", name, irow, icol);
2031 stat = ocsmBuild(problem->modl, buildTo, &builtTo, &nbody, NULL((void*)0));
2032 fflush(stdoutstdout);
2033 if (stat != SUCCESS0) return stat;
2034 ocsmSetOutLevel(outLevel);
2035
2036 /* fill in GeometryOut Dot values -- same as caps_geomOutSensit */
2037 for (i = 0; i < problem->nRegGIN; i++) {
2038 if (problem->geomIn[problem->regGIN[i].index-1] == NULL((void*)0)) continue;
2039 value = (capsValue *) problem->geomIn[problem->regGIN[i].index-1]->blind;
2040 if (value == NULL((void*)0)) continue;
2041 if (value->pIndex != ipmtr) continue;
2042 if (problem->regGIN[i].irow != irow && problem->regGIN[i].irow > 0) continue;
2043 if (problem->regGIN[i].icol != icol && problem->regGIN[i].icol > 0) continue;
2044
2045 if ((problem->regGIN[i].irow == 0) &&
2046 (problem->regGIN[i].icol == 0))
2047 i_wrt = value->ncol*(irow-1) + (icol-1);
2048 else
2049 i_wrt = 0;
2050
2051 for (j = 0; j < problem->nGeomOut; j++) {
2052 if (problem->geomOut[j] == NULL((void*)0)) continue;
2053 value = (capsValue *) problem->geomOut[j]->blind;
2054 if (value == NULL((void*)0)) continue;
2055 if (value->derivs == NULL((void*)0)) continue;
2056
2057 len_wrt = value->derivs[i].len_wrt;
2058 if (value->derivs[i].deriv == NULL((void*)0))
2059 value->derivs[i].deriv = (double *) EG_alloc(value->length*len_wrt*sizeof(double));
2060 if (value->derivs[i].deriv == NULL((void*)0)) { return EGADS_MALLOC-4; }
2061
2062 reals = value->vals.reals;
2063 if (value->length == 1) reals = &value->vals.real;
2064 for (n = k = 0; k < value->nrow; k++)
2065 for (m = 0; m < value->ncol; m++, n++)
2066 ocsmGetValu(problem->modl, value->pIndex, k+1, m+1,
2067 &reals[n], &value->derivs[i].deriv[len_wrt*n + i_wrt]);
2068 }
2069 }
2070
2071 aInfo->pIndex = ipmtr;
2072 aInfo->irow = irow;
2073 aInfo->icol = icol;
2074 return CAPS_SUCCESS0;
2075}
2076
2077
2078int
2079aim_getSensitivity(void *aimStruc, ego tess, int ttype, int index, int *npts,
2080 double **dxyz)
2081{
2082 int i, stat, ibody, npt, ntri, type, outLevel;
2083 double *dsen;
2084 const int *ptype, *pindex, *tris, *tric;
2085 const double *xyzs, *parms;
2086 ego body, oldtess;
2087 egTessel *btess;
2088 modl_T *MODL;
2089 aimInfo *aInfo;
2090 capsProblem *problem;
2091
2092 aInfo = (aimInfo *) aimStruc;
2093 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
2094 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
2095 if (aInfo->pIndex == 0) return CAPS_STATEERR-329;
2096 if ((ttype < -2) || (ttype > 2)) return CAPS_RANGEERR-326;
2097 if (index < 1) return CAPS_BADINDEX-304;
2098 problem = aInfo->problem;
2099 MODL = (modl_T *) problem->modl;
2100 if (MODL == NULL((void*)0)) return CAPS_NOTPARMTRIC-314;
2101 if (tess == NULL((void*)0)) return EGADS_NULLOBJ-2;
2102 if (tess->magicnumber != MAGIC98789) return EGADS_NOTOBJ-3;
2103 if (tess->oclass != TESSELLATION2) return EGADS_NOTTESS-14;
2104 btess = (egTessel *) tess->blind;
2105 if (btess == NULL((void*)0)) return EGADS_NOTFOUND-1;
2106 body = btess->src;
2107 if (body == NULL((void*)0)) return EGADS_NULLOBJ-2;
2108 if (body->magicnumber != MAGIC98789) return EGADS_NOTOBJ-3;
2109 if (body->oclass != BODY25) return EGADS_NOTBODY-20;
2110
2111 for (ibody = 1; ibody <= MODL->nbody; ibody++) {
2112 if (MODL->body[ibody].onstack != 1) continue;
2113 if (MODL->body[ibody].botype == OCSM_NULL_BODY404) continue;
2114 if (MODL->body[ibody].ebody == body) break;
2115 }
2116 if (ibody > MODL->nbody) return CAPS_NOTFOUND-303;
2117
2118 /* set the OCSM tessellation to the one given & save the old */
2119 oldtess = MODL->body[ibody].etess;
2120 MODL->body[ibody].etess = tess;
2121
2122 /* get the length */
2123 if (ttype == 0) {
2124 type = OCSM_NODE600;
2125 npt = 1;
2126 } else if (abs(ttype) == 1) {
2127 type = OCSM_EDGE601;
2128 stat = EG_getTessEdge(MODL->body[ibody].etess, index, &npt, &xyzs, &parms);
2129 if (stat != EGADS_SUCCESS0) {
2130 MODL->body[ibody].etess = oldtess;
2131 return stat;
2132 }
2133 } else {
2134 type = OCSM_FACE602;
2135 stat = EG_getTessFace(MODL->body[ibody].etess, index, &npt, &xyzs, &parms,
2136 &ptype, &pindex, &ntri, &tris, &tric);
2137 if (stat != EGADS_SUCCESS0) {
2138 MODL->body[ibody].etess = oldtess;
2139 return stat;
2140 }
2141 }
2142 if (npt <= 0) {
2143 MODL->body[ibody].etess = oldtess;
2144 return CAPS_NULLVALUE-307;
2145 }
2146
2147 /* get the memory to store the sensitivity */
2148 dsen = (double *) EG_alloc(3*npt*sizeof(double));
2149 if (dsen == NULL((void*)0)) {
2150 MODL->body[ibody].etess = oldtess;
2151 return EGADS_MALLOC-4;
2152 }
2153
2154 /* get and return the requested sensitivity */
2155 if (ttype <= 0) {
2156 outLevel = ocsmSetOutLevel(0);
2157 stat = ocsmGetVel(problem->modl, ibody, type, index, npt, NULL((void*)0), dsen);
2158 ocsmSetOutLevel(outLevel);
2159 if (stat != SUCCESS0) {
2160 EG_free(dsen);
2161 MODL->body[ibody].etess = oldtess;
2162 return stat;
2163 }
2164 } else {
2165 outLevel = ocsmSetOutLevel(0);
2166 stat = ocsmGetTessVel(problem->modl, ibody, type, index, &xyzs);
2167 ocsmSetOutLevel(outLevel);
2168 if (stat != SUCCESS0) {
2169 EG_free(dsen);
2170 MODL->body[ibody].etess = oldtess;
2171 return stat;
2172 }
2173 for (i = 0; i < 3*npt; i++) dsen[i] = xyzs[i];
2174 }
2175 /* reset OCSMs tessellation */
2176 MODL->body[ibody].etess = oldtess;
2177 if (MODL->dtime != 0)
2178 printf(" CAPS Info: Sensitivity finite differenced\n");
2179
2180 *npts = npt;
2181 *dxyz = dsen;
2182 return CAPS_SUCCESS0;
2183}
2184
2185
2186int
2187aim_tessSensitivity(void *aimStruc, const char *GIname, int irow, int icol,
2188 ego tess, int *npts, double **dxyz)
2189{
2190 int i, j, ipmtr, ibody, stat, nbrch, npmtr, nbody, nrow, ncol, type;
2191 int npt, nface, np, ntris, global, outLevel;
2192 const int *ptype, *pindex, *tris, *tric;
2193 char name[MAX_NAME_LEN64];
2194 double *dsen;
2195 const double *xyzs, *xyz, *uv;
2196 ego body, oldtess;
2197 egTessel *btess;
2198 modl_T *MODL;
2199 aimInfo *aInfo;
2200 capsProblem *problem;
2201
2202 *npts = 0;
2203 *dxyz = NULL((void*)0);
2204 aInfo = (aimInfo *) aimStruc;
2205 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
2206 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
2207 if (GIname == NULL((void*)0)) return CAPS_NULLNAME-308;
2208 if ((irow < 1) || (icol < 1)) return CAPS_BADINDEX-304;
2209 problem = aInfo->problem;
2210 MODL = (modl_T *) problem->modl;
2211 if (MODL == NULL((void*)0)) return CAPS_NOTPARMTRIC-314;
2212 if (tess == NULL((void*)0)) return EGADS_NULLOBJ-2;
2213 if (tess->magicnumber != MAGIC98789) return EGADS_NOTOBJ-3;
2214 if (tess->oclass != TESSELLATION2) return EGADS_NOTTESS-14;
2215 stat = EG_statusTessBody(tess, &body, &i, &npt);
2216 if (stat == EGADS_OUTSIDE1) return EGADS_TESSTATE-31;
2217 if (body == NULL((void*)0)) return EGADS_NULLOBJ-2;
2218 if (body->magicnumber != MAGIC98789) return EGADS_NOTOBJ-3;
2219 if (body->oclass != BODY25) return EGADS_NOTBODY-20;
2220 stat = EG_getBodyTopos(body, NULL((void*)0), FACE23, &nface, NULL((void*)0));
2221 if (stat != EGADS_SUCCESS0) return stat;
2222
2223 for (ibody = 1; ibody <= MODL->nbody; ibody++) {
2224 if (MODL->body[ibody].onstack != 1) continue;
2225 if (MODL->body[ibody].botype == OCSM_NULL_BODY404) continue;
2226 if (MODL->body[ibody].ebody == body) break;
2227 }
2228 if (ibody > MODL->nbody) return CAPS_NOTFOUND-303;
2229
2230 /* find the OpenCSM Parameter */
2231 stat = ocsmInfo(problem->modl, &nbrch, &npmtr, &nbody);
2232 if (stat != SUCCESS0) return stat;
2233 for (ipmtr = i = 0; i < npmtr; i++) {
2234 stat = ocsmGetPmtr(problem->modl, i+1, &type, &nrow, &ncol, name);
2235 if (stat != SUCCESS0) continue;
2236 if (type != OCSM_DESPMTR500) continue;
2237 if (strcmp(name, GIname) != 0) continue;
2238 ipmtr = i+1;
2239 break;
2240 }
2241 if (ipmtr == 0) return CAPS_NOSENSITVTY-340;
2242 if (irow > nrow) return CAPS_BADINDEX-304;
2243 if (icol > ncol) return CAPS_BADINDEX-304;
2244
2245 /* set the Parameter if not already set */
2246 if ((aInfo->pIndex != ipmtr) || (aInfo->irow != irow) ||
2247 (aInfo->icol != icol)) {
2248 stat = aim_setSensitivity(aimStruc, GIname, irow, icol);
2249 if (stat != CAPS_SUCCESS0) return stat;
2250 }
2251
2252 dsen = (double *) EG_alloc(3*npt*sizeof(double));
2253 if (dsen == NULL((void*)0)) return EGADS_MALLOC-4;
2254 for (i = 0; i < 3*npt; i++) dsen[i] = 0.0;
2255
2256 /* return the requested sensitivity */
2257 oldtess = MODL->body[ibody].etess;
2258 MODL->body[ibody].etess = tess;
2259
2260 btess = (egTessel *) tess->blind;
2261 if (btess->nFace == 0) {
2262 for (i = 1; i <= btess->nEdge; i++) {
2263 stat = EG_getTessEdge(tess, i, &np, &xyz, &uv);
2264 if (stat != EGADS_SUCCESS0) {
2265 EG_free(dsen);
2266 return stat;
2267 }
2268 outLevel = ocsmSetOutLevel(0);
2269 stat = ocsmGetTessVel(problem->modl, ibody, OCSM_EDGE601, i, &xyzs);
2270 ocsmSetOutLevel(outLevel);
2271 if (stat != SUCCESS0) {
2272 EG_free(dsen);
2273 return stat;
2274 }
2275 for (j = 1; j <= np; j++) {
2276 stat = EG_localToGlobal(tess, -i, j, &global);
2277 if (stat != EGADS_SUCCESS0) {
2278 EG_free(dsen);
2279 return stat;
2280 }
2281 dsen[3*global-3] = xyzs[3*j-3];
2282 dsen[3*global-2] = xyzs[3*j-2];
2283 dsen[3*global-1] = xyzs[3*j-1];
2284 }
2285 }
2286 } else {
2287 for (i = 1; i <= nface; i++) {
2288 stat = EG_getTessFace(tess, i, &np, &xyz, &uv, &ptype, &pindex, &ntris,
2289 &tris, &tric);
2290 if (stat != EGADS_SUCCESS0) {
2291 EG_free(dsen);
2292 return stat;
2293 }
2294 outLevel = ocsmSetOutLevel(0);
2295 stat = ocsmGetTessVel(problem->modl, ibody, OCSM_FACE602, i, &xyzs);
2296 ocsmSetOutLevel(outLevel);
2297 if (stat != SUCCESS0) {
2298 EG_free(dsen);
2299 return stat;
2300 }
2301 for (j = 1; j <= np; j++) {
2302 stat = EG_localToGlobal(tess, i, j, &global);
2303 if (stat != EGADS_SUCCESS0) {
2304 EG_free(dsen);
2305 return stat;
2306 }
2307 dsen[3*global-3] = xyzs[3*j-3];
2308 dsen[3*global-2] = xyzs[3*j-2];
2309 dsen[3*global-1] = xyzs[3*j-1];
2310 }
2311 }
2312 }
2313 MODL->body[ibody].etess = oldtess;
2314 if (MODL->dtime != 0)
2315 printf(" CAPS Info: Sensitivity finite difference used for: %s[%d,%d]\n", name, irow, icol);
2316
2317 *npts = npt;
2318 *dxyz = dsen;
2319 return CAPS_SUCCESS0;
2320}
2321
2322
2323int
2324aim_isNodeBody(ego body, double *xyz)
2325{
2326 int status, oclass, mtype, nchild, *psens = NULL((void*)0);
2327 double data[4];
2328 ego *pchldrn, ref, loop, edge;
2329
2330 /* Determine of the body is a "node body", i.e. a degenerate wire body */
2331 status = EG_getTopology(body, &ref, &oclass, &mtype, data, &nchild, &pchldrn,
2332 &psens);
2333 if (status != EGADS_SUCCESS0) return status;
2334
2335 /* should be a body */
2336 if (oclass != BODY25) return EGADS_NOTBODY-20;
2337
2338 /* done if it's not a wire body */
2339 if (mtype != WIREBODY6) return EGADS_OUTSIDE1;
2340
2341 /* there should be only one child, and it is a loop */
2342 if (nchild != 1) return EGADS_OUTSIDE1;
2343
2344 loop = pchldrn[0];
2345
2346 /* get the edges */
2347 status = EG_getTopology(loop, &ref, &oclass, &mtype, data, &nchild, &pchldrn,
2348 &psens);
2349 if (status != CAPS_SUCCESS0) return status;
2350
2351 /* there should be only one child, and it is an edge */
2352 if (nchild != 1) return EGADS_OUTSIDE1;
2353
2354 edge = pchldrn[0];
2355
2356 /* get the node(s) of the edge */
2357 status = EG_getTopology(edge, &ref, &oclass, &mtype, data, &nchild, &pchldrn,
2358 &psens);
2359 if (status != CAPS_SUCCESS0) return status;
2360
2361 /* the edge should be degenerate */
2362 if (mtype != DEGENERATE5) return EGADS_OUTSIDE1;
2363
2364 /* something is really wrong if the edge does not have one node */
2365 if (nchild != 1) return EGADS_GEOMERR-21;
2366
2367 /* retrieve the coordinates of the node */
2368 status = EG_getTopology(pchldrn[0], &ref, &oclass, &mtype, xyz, &nchild,
2369 &pchldrn, &psens);
2370 if (status != EGADS_SUCCESS0) return status;
2371
2372 return EGADS_SUCCESS0;
2373}
2374
2375
2376static void
2377aim_addErrorLine(void *aimStruc, enum capseType etype, const char *line)
2378{
2379 int index, len, i;
2380 char **ltmp;
2381 capsError *etmp;
2382 aimInfo *aInfo;
2383 char buffer[EBUFSIZE4096] = {'\0'};
2384
2385 aInfo = (aimInfo *) aimStruc;
2386 if (aInfo == NULL((void*)0)) return;
2387 if (aInfo->magicnumber != CAPSMAGIC1234321) return;
2388
2389 if (etype == CONTINUATION) {
2390 if (aInfo->errs.nError == 0) {
2391 printf(" CAPS Internal: Continuation without a start!\n");
2392 return;
2393 }
2394 index = aInfo->errs.nError - 1;
2395 len = aInfo->errs.errors[index].nLines + 1;
2396 ltmp = (char **) EG_reall(aInfo->errs.errors[index].lines,
2397 len*sizeof(char *));
2398 if (ltmp == NULL((void*)0)) return;
2399 for (i = 0; i < 2; i++) buffer[i] = ' ';
2400 strncat(buffer + 2, line, EBUFSIZE4096-3);
2401 ltmp[len-1] = EG_strdup(buffer);
2402 aInfo->errs.errors[index].lines = ltmp;
2403 aInfo->errs.errors[index].nLines = len;
2404 return;
2405 }
2406
2407 index = aInfo->errs.nError;
2408 if (index == 0) {
2409 aInfo->errs.errors = (capsError *) EG_alloc(sizeof(capsError));
2410 if (aInfo->errs.errors == NULL((void*)0)) return;
2411 } else {
2412 etmp = (capsError *) EG_reall(aInfo->errs.errors,
2413 (index+1)*sizeof(capsError));
2414 if (etmp == NULL((void*)0)) return;
2415 aInfo->errs.errors = etmp;
2416 }
2417 aInfo->errs.errors[index].errObj = NULL((void*)0);
2418 aInfo->errs.errors[index].eType = etype;
2419 aInfo->errs.errors[index].index = 0;
2420 aInfo->errs.errors[index].nLines = 1;
2421 aInfo->errs.errors[index].lines = (char **) EG_alloc(sizeof(char *));
2422 if (aInfo->errs.errors[index].lines != NULL((void*)0))
2423 aInfo->errs.errors[index].lines[0] = EG_strdup(line);
2424
2425 aInfo->errs.nError = index+1;
2426}
2427
2428
2429void
2430aim_status(void *aimInfo, const int status, const char *file,
2431 const int line, const char *func, const int narg, ...)
2432{
2433 va_list args;
2434 char buffer[EBUFSIZE4096] = {'\0'}, buffer2[EBUFSIZE4096] = {'\0'};
2435 const char *format = NULL((void*)0);
2436
2437 snprintf(buffer2, EBUFSIZE4096, "%s:%d in %s(): Error status = %d",
2438 file, line, func, status);
2439 aim_addErrorLine(aimInfo, CSTAT, buffer2);
2440
2441 if (narg > 0) {
2442 va_start(args, narg)__builtin_va_start(args, narg);
2443 format = va_arg(args, const char *)__builtin_va_arg(args, const char *);
2444 vsnprintf(buffer, EBUFSIZE4096, format, args);
2445 va_end(args)__builtin_va_end(args);
2446
2447 snprintf(buffer2, EBUFSIZE4096, "%s", buffer);
2448 aim_addErrorLine(aimInfo, CONTINUATION, buffer2);
2449 }
2450}
2451
2452
2453void
2454aim_message(void *aimStruc, enum capseType etype, int index, const char *file,
2455 const int line, const char *func, const char *format, ...)
2456{
2457 int i;
2458 aimInfo *aInfo;
2459 capsAnalysis *analysis;
2460
2461 va_list args;
2462 char buffer[EBUFSIZE4096] = {'\0'}, buffer2[EBUFSIZE4096] = {'\0'};
2463 const char *eType[4] = {"Info",
2464 "Warning",
2465 "Error",
2466 "Possible Developer Error"};
2467
2468 // clang-analyzer
2469 if (etype == CONTINUATION) return;
2470
2471 snprintf(buffer2, EBUFSIZE4096, "%s:%d in %s():", file, line, func);
2472 aim_addErrorLine(aimStruc, etype, buffer2);
2473
2474 if (index > 0) {
2475 aInfo = (aimInfo *) aimStruc;
2476 if (aInfo == NULL((void*)0)) return;
2477 if (aInfo->magicnumber != CAPSMAGIC1234321) return;
2478
2479 analysis = (capsAnalysis *) aInfo->analysis;
2480 if (index <= analysis->nAnalysisIn) {
2481 snprintf(buffer, EBUFSIZE4096, "ANALYSISIN: %s",
2482 analysis->analysisIn[index-1]->name);
2483 aim_addErrorLine(aimStruc, CONTINUATION, buffer);
2484 }
2485 }
2486
2487 va_start(args, format)__builtin_va_start(args, format);
2488 vsnprintf(buffer, EBUFSIZE4096, format, args);
2489 va_end(args)__builtin_va_end(args);
2490
2491 snprintf(buffer2, EBUFSIZE4096, "%s: %s", eType[etype], buffer);
2492 aim_addErrorLine(aimStruc, CONTINUATION, buffer2);
2493
2494 if (index > 0) {
2495 i = aInfo->errs.nError-1;
2496 aInfo->errs.errors[i].index = index;
2497 }
2498}
2499
2500
2501void
2502aim_addLine(void *aimInfo, const char *format, ...)
2503{
2504 va_list args;
2505 char buffer[EBUFSIZE4096] = {'\0'};
2506
2507 va_start(args, format)__builtin_va_start(args, format);
2508 vsnprintf(buffer, EBUFSIZE4096, format, args);
2509 va_end(args)__builtin_va_end(args);
2510
2511 aim_addErrorLine(aimInfo, CONTINUATION, buffer);
2512}
2513
2514
2515void
2516aim_setIndexError(void *aimStruc, int index)
2517{
2518 int i;
2519 aimInfo *aInfo;
2520
2521 aInfo = (aimInfo *) aimStruc;
2522 if (aInfo == NULL((void*)0)) return;
2523 if (aInfo->magicnumber != CAPSMAGIC1234321) return;
2524 if (aInfo->errs.nError == 0) return;
2525
2526 i = aInfo->errs.nError - 1;
2527 aInfo->errs.errors[i].index = index;
2528}
2529
2530
2531void
2532aim_removeError(void *aimStruc)
2533{
2534 int i, j, k;
2535 aimInfo *aInfo;
2536
2537 aInfo = (aimInfo *) aimStruc;
2538 if (aInfo == NULL((void*)0)) return;
2539 if (aInfo->magicnumber != CAPSMAGIC1234321) return;
2540
2541 for (j = i = 0; i < aInfo->errs.nError; i++)
2542 if (aInfo->errs.errors[i].eType == CERROR ||
2543 aInfo->errs.errors[i].eType == CSTAT) {
2544 for (k = 0; k < aInfo->errs.errors[i].nLines; k++)
2545 EG_free(aInfo->errs.errors[i].lines[k]);
2546 EG_free(aInfo->errs.errors[i].lines);
2547 } else {
2548 aInfo->errs.errors[j] = aInfo->errs.errors[i];
2549 j++;
2550 }
2551
2552 if (j == 0) {
2553 EG_free(aInfo->errs.errors);
2554 aInfo->errs.errors = NULL((void*)0);
2555 }
2556 aInfo->errs.nError = j;
2557}