FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
CFSTRDB_Radiate.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_Radiate 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
16 
17 const char *CFSTRDB_Radiate::LoadTypeName(int type) {
18  const char *pn[] = {"R0", "R1", "R2", "R3", "R4", "R5", "R6", "unknown"};
19 
20  if (type < 0 || type >= TypeNumber()) return "";
21 
22  return pn[type];
23 }
24 
26  : CFSTRDataBlock(FSTRDB_RADIATE), ItemList() {
27  amp1[0] = 0;
28  amp2[0] = 0;
29 }
30 
32 
34  ItemList.clear();
35  amp1[0] = 0;
36  amp2[0] = 0;
37 }
38 
40  char buff[256];
41 
42  if (ItemList.size() == 0) return;
43 
44  size_t len = snprintf(buff, sizeof(buff), "!RADIATE");
45 
46  if (amp1[0] != 0) {
47  len += snprintf(buff + len, sizeof(buff) - len, ",AMP1=%s", amp1);
48  }
49 
50  if (amp2[0] != 0) {
51  snprintf(buff + len, sizeof(buff) - len, ",AMP2=%s", amp2);
52  }
53 
54  hecd->WriteHeader(buff);
55  vector<CItem>::iterator iter;
56 
57  for (iter = ItemList.begin(); iter != ItemList.end(); iter++) {
58  hecd->WriteData("SSFF", iter->egrp, LoadTypeName(iter->type), iter->value,
59  iter->sink);
60  }
61 }
62 
63 bool CFSTRDB_Radiate::Read(CHECData *hecd, char *header_line) {
64  int rcode[10];
65  char s[256];
66  int type;
67  amp1[0] = 0;
68  amp2[0] = 0;
69 
70  if (!hecd->ParseHeader(header_line, rcode, "SS", "AMP1", amp1, "AMP2", amp2))
71  return false;
72 
73  while (1) {
74  CItem item;
75  bool fg =
76  hecd->ReadData(rcode, "SSFF", item.egrp, s, &item.value, &item.sink);
77 
78  if (!fg) break;
79 
80  cleanup_token(s);
81  toupper(s);
82 
83  for (type = 0; type < TypeNumber(); type++) {
84  if (strcmp(LoadTypeName(type), s) == 0) break;
85  }
86 
87  if (type == TypeNumber()) return false;
88 
89  item.type = type;
90  ItemList.push_back(item);
91  }
92 
93  return true;
94 }
@ FSTRDB_RADIATE
Definition: CFSTRDB.h:51
char egrp[hec_name_size]
Definition: CFSTRDB.h:579
char amp2[hec_name_size]
Definition: CFSTRDB.h:597
std::vector< CItem > ItemList
Definition: CFSTRDB.h:601
virtual bool Read(class CHECData *hecd, char *header_line)
static const char * LoadTypeName(int type)
virtual void Write(class CHECData *hecd)
virtual void Clear()
static int TypeNumber()
Definition: CFSTRDB.h:574
char amp1[hec_name_size]
Definition: CFSTRDB.h:596
virtual ~CFSTRDB_Radiate()
virtual bool ReadData(int *rcode, const char *fmt,...)
Definition: CHECData.cpp:536
virtual bool ParseHeader(char *header_line, int *rcode, const char *fmt,...)
Definition: CHECData.cpp:494
virtual void WriteData(const char *fmt,...)
Definition: CHECData.cpp:151
virtual void WriteHeader(const char *name, const char *fmt="",...)
Definition: CHECData.cpp:68
void toupper(char *s)
Definition: hecd_util.cpp:38
void cleanup_token(char *s)
Definition: hecd_util.cpp:13