FrontISTR  5.2.0
Large-scale structural analysis program with finit element method
CFSTRDB_DLoad.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 /*
6  CFSTRDB_DLoad Ver.1.0
7 */
8 
9 #include "CFSTRDB.h"
10 #include "CHECData.h"
11 
12 using namespace std;
13 using namespace hecd_util;
14 
15 // static method
17  const int pn[] = {
18  1, // TYPE_P0
19  1, // TYPE_P1
20  1, // TYPE_P2
21  1, // TYPE_P3
22  1, // TYPE_P4
23  1, // TYPE_P5
24  1, // TYPE_P6
25  1, // TYPE_BX
26  1, // TYPE_BY
27  1, // TYPE_BZ
28  4, // TYPE_GRAV
29  7, // TYPE_CENT
30  0 // TYPE_UNKNOWN
31  };
32 
33  if (type < 0 || type >= TypeNumber()) return 0;
34 
35  return pn[type];
36 }
37 
38 const char *CFSTRDB_DLoad::LoadTypeName(int type) {
39  const char *pn[] = {"P0", "P1", "P2", "P3", "P4", "P5", "P6",
40  "BX", "BY", "BZ", "GRAV", "CENT", "unknown"};
41 
42  if (type < 0 || type >= TypeNumber()) return "";
43 
44  return pn[type];
45 }
46 
48 
50 
51 void CFSTRDB_DLoad::Clear() { ItemList.clear(); }
52 
54  if (ItemList.size() == 0) return;
55 
56  hecd->WriteHeader("!DLOAD");
57  vector<CItem>::iterator iter;
58 
59  for (iter = ItemList.begin(); iter != ItemList.end(); iter++) {
60  hecd->ClearDataLineBuffer();
61  hecd->AddDataLineItems("SS", iter->egrp, LoadTypeName(iter->type));
62  int n = ParamNumber(iter->type);
63 
64  for (int i = 0; i < n; i++) {
65  hecd->AddDataLineItems("F", iter->param[i]);
66  }
67 
68  hecd->WriteDataLine();
69  }
70 }
71 
72 bool CFSTRDB_DLoad::Read(CHECData *hecd, char *header_line) {
73  int rcode[10];
74  char s[256];
75  int type;
76 
77  while (1) {
78  CItem item;
79  bool fg = hecd->ReadData(rcode, "SSFFFFFFF", item.egrp, s, &item.param[0],
80  &item.param[1], &item.param[2], &item.param[3],
81  &item.param[4], &item.param[5], &item.param[6]);
82 
83  if (!fg) break;
84 
85  cleanup_token(s);
86  toupper(s);
87 
88  for (type = 0; type < TypeNumber(); type++) {
89  if (strcmp(LoadTypeName(type), s) == 0) break;
90  }
91 
92  if (type == TypeNumber()) return false;
93 
94  item.type = type;
95  ItemList.push_back(item);
96  }
97 
98  return true;
99 }
@ FSTRDB_DLOAD
Definition: CFSTRDB.h:38
double param[7]
Definition: CFSTRDB.h:243
char egrp[hec_name_size]
Definition: CFSTRDB.h:241
static const char * LoadTypeName(int type)
static int TypeNumber()
Definition: CFSTRDB.h:235
virtual void Clear()
virtual ~CFSTRDB_DLoad()
std::vector< CItem > ItemList
Definition: CFSTRDB.h:270
virtual void Write(class CHECData *hecd)
static int ParamNumber(int type)
virtual bool Read(class CHECData *hecd, char *header_line)
virtual void WriteDataLine()
Definition: CHECData.cpp:234
virtual bool ReadData(int *rcode, const char *fmt,...)
Definition: CHECData.cpp:548
virtual void WriteHeader(const char *name, const char *fmt="",...)
Definition: CHECData.cpp:68
virtual void ClearDataLineBuffer()
Definition: CHECData.cpp:199
virtual void AddDataLineItems(const char *fmt,...)
Definition: CHECData.cpp:201
void toupper(char *s)
Definition: hecd_util.cpp:37
void cleanup_token(char *s)
Definition: hecd_util.cpp:13