FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
CFSTRDB_Film.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_Film 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_Film::LoadTypeName(int type) {
18  const char *pn[] = {"F0", "F1", "F2", "F3", "F4", "F5", "F6", "unknown"};
19 
20  if (type < 0 || type >= TypeNumber()) return "";
21 
22  return pn[type];
23 }
24 
26  amp1[0] = 0;
27  amp2[0] = 0;
28 }
29 
31 
33  ItemList.clear();
34  amp1[0] = 0;
35  amp2[0] = 0;
36 }
37 
39  char buff[256];
40 
41  if (ItemList.size() == 0) return;
42 
43  size_t len = snprintf(buff, sizeof(buff), "!FILM");
44 
45  if (amp1[0] != 0) {
46  len += snprintf(buff + len, sizeof(buff) - len, ",AMP1=%s", amp1);
47  }
48 
49  if (amp2[0] != 0) {
50  snprintf(buff + len, sizeof(buff) - len, ",AMP2=%s", amp2);
51  }
52 
53  hecd->WriteHeader(buff);
54  vector<CItem>::iterator iter;
55 
56  for (iter = ItemList.begin(); iter != ItemList.end(); iter++) {
57  hecd->WriteData("SSFF", iter->egrp, LoadTypeName(iter->type), iter->value,
58  iter->sink);
59  }
60 }
61 
62 bool CFSTRDB_Film::Read(CHECData *hecd, char *header_line) {
63  int rcode[10];
64  char s[256];
65  int type;
66  amp1[0] = 0;
67  amp2[0] = 0;
68 
69  if (!hecd->ParseHeader(header_line, rcode, "SS", "AMP1", amp1, "AMP2", amp2))
70  return false;
71 
72  while (1) {
73  CItem item;
74  bool fg =
75  hecd->ReadData(rcode, "SSFF", item.egrp, s, &item.value, &item.sink);
76 
77  if (!fg) break;
78 
79  cleanup_token(s);
80  toupper(s);
81 
82  for (type = 0; type < TypeNumber(); type++) {
83  if (strcmp(LoadTypeName(type), s) == 0) break;
84  }
85 
86  if (type == TypeNumber()) return false;
87 
88  item.type = type;
89  ItemList.push_back(item);
90  }
91 
92  return true;
93 }
@ FSTRDB_FILM
Definition: CFSTRDB.h:49
char egrp[hec_name_size]
Definition: CFSTRDB.h:498
static const char * LoadTypeName(int type)
virtual bool Read(class CHECData *hecd, char *header_line)
virtual void Clear()
virtual ~CFSTRDB_Film()
virtual void Write(class CHECData *hecd)
static int TypeNumber()
Definition: CFSTRDB.h:493
char amp1[hec_name_size]
Definition: CFSTRDB.h:515
std::vector< CItem > ItemList
Definition: CFSTRDB.h:520
char amp2[hec_name_size]
Definition: CFSTRDB.h:516
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