@@ -1026,6 +1026,25 @@ moordyn::MoorDyn::ReadInFile()
10261026 }
10271027 }
10281028
1029+ if ((i = findStartOfSection (in_txt, { " RODS" , " ROD LIST" , " ROD PROPERTIES" })) != -1 ) {
1030+ LOGDBG << " Reading rod list:" << endl;
1031+
1032+ // parse until the next header or the end of the file
1033+ while ((in_txt[i].find (" ---" ) == string::npos) &&
1034+ (i < (int )in_txt.size ())) {
1035+ Rod* obj = readRod (in_txt[i], i);
1036+
1037+ if (obj) {
1038+ RodList.push_back (obj);
1039+ } else {
1040+ delete obj;
1041+ return MOORDYN_INVALID_INPUT ;
1042+ }
1043+
1044+ i++;
1045+ }
1046+ }
1047+
10291048 if ((i = findStartOfSection (in_txt,
10301049 { " POINTS" ,
10311050 " POINT LIST" ,
@@ -1132,6 +1151,15 @@ moordyn::MoorDyn::ReadInFile()
11321151 << endl;
11331152 }
11341153
1154+ // Check point ID is sequential starting from 1
1155+ if (number != PointList.size () + 1 ) {
1156+ LOGERR << " Error in " << _filepath << " at line " << i + 1
1157+ << " :" << endl
1158+ << " '" << in_txt[i] << " '" << endl
1159+ << " Point ID must be sequential starting from 1" << endl;
1160+ return MOORDYN_INVALID_INPUT ;
1161+ }
1162+
11351163 LOGDBG << " \t '" << number << " '"
11361164 << " - of type " << Point::TypeName (type) << " with id "
11371165 << PointList.size () << endl;
@@ -1155,20 +1183,6 @@ moordyn::MoorDyn::ReadInFile()
11551183 }
11561184 }
11571185
1158- if ((i = findStartOfSection (
1159- in_txt, { " RODS" , " ROD LIST" , " ROD PROPERTIES" })) != -1 ) {
1160- LOGDBG << " Reading rod list:" << endl;
1161-
1162- // parse until the next header or the end of the file
1163- while ((in_txt[i].find (" ---" ) == string::npos) &&
1164- (i < (int )in_txt.size ())) {
1165- Rod* obj = readRod (in_txt[i], i);
1166- RodList.push_back (obj);
1167-
1168- i++;
1169- }
1170- }
1171-
11721186 if ((i = findStartOfSection (
11731187 in_txt, { " LINES" , " LINE LIST" , " LINE PROPERTIES" })) != -1 ) {
11741188 LOGDBG << " Reading line list: " << endl;
@@ -1226,6 +1240,15 @@ moordyn::MoorDyn::ReadInFile()
12261240 } else
12271241 outfiles.push_back (NULL );
12281242
1243+ // Check line ID is sequential starting from 1
1244+ if (number != LineList.size () + 1 ) {
1245+ LOGERR << " Error in " << _filepath << " at line " << i + 1
1246+ << " :" << endl
1247+ << " '" << in_txt[i] << " '" << endl
1248+ << " Line ID must be sequential starting from 1" << endl;
1249+ return MOORDYN_INVALID_INPUT ;
1250+ }
1251+
12291252 LOGDBG << " \t '" << number << " '"
12301253 << " - of class " << type << " (" << TypeNum << " )"
12311254 << " with id " << LineList.size () << endl;
@@ -2134,6 +2157,15 @@ moordyn::MoorDyn::readBody(string inputText, int lineNum)
21342157 return nullptr ;
21352158 }
21362159
2160+ // Check body ID is sequential starting from 1
2161+ if (number != BodyList.size () + 1 ) {
2162+ LOGERR << " Error in " << _filepath << " at line " << lineNum + 1
2163+ << " :" << endl
2164+ << " '" << inputText << " '" << endl
2165+ << " Body ID must be sequential starting from 1" << endl;
2166+ return nullptr ;
2167+ }
2168+
21372169 // id = size + 1 because of ground body, which has an Id of zero
21382170 Body* obj = new Body (_log, BodyList.size () + 1 );
21392171 LOGDBG << " \t '" << number << " '"
@@ -2260,6 +2292,15 @@ moordyn::MoorDyn::readRod(string inputText, int lineNum)
22602292 << " and type " << Rod::TypeName (type) << " with id "
22612293 << RodList.size () << endl;
22622294
2295+ // Check rod ID is sequential starting from 1
2296+ if (number != RodList.size () + 1 ) {
2297+ LOGERR << " Error in " << _filepath << " at line " << lineNum + 1
2298+ << " :" << endl
2299+ << " '" << inputText << " '" << endl
2300+ << " Rod ID must be sequential starting from 1" << endl;
2301+ return nullptr ;
2302+ }
2303+
22632304 Rod* obj = new Rod (_log, RodList.size ());
22642305 obj->setup (number,
22652306 type,
0 commit comments