The hoard of clutter within someone's memories

Some of it is useful

Any AI version of Marie Kondo should just give up!

The thing to beat the tedium of typing out things for computing is to create things that automate repeated actions. As the new big-ish project is designed to use XML, finding ways to ease the burden of creating XML files for the end user is always going to be appreciated. Although the examples used are small at the moment because everything is still at a 'proof of concept' phase, automating the production of XML files in this way will work when larger examples need to be created.

And it is not just the workload aspect. Minimising manual work for the user also reduces the scope for possible mistakes, the concept of poka-yoke.

There are many ways to do this, I am going to use bash for this example. The following script creates both an XML file and a dtd file from a number of text files containing input data. If the script automatically assignes an id number using a counter then files containing the details of joints within the framework need only define each joint using lines of x and y coordinates. Different types of joint can be defined using different text files. Again, if id numbers are allocated using a counter within the script then structural members need only be defined by the joint numbers that they are connected to. Forces are defined by joint id, magnitude and angle so each line will be three numbers.

The following bash script creates both xml and dtd files from defined user input files:


#!/usr/bin/env bash
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>">frameworktest.xml
echo "<!DOCTYPE framework SYSTEM \"frameworktest.dtd\">">>frameworktest.xml
echo "<framework>">>frameworktest.xml
echo "    <title>Test Framework 1</title>">>frameworktest.xml
echo "        <joints>">>frameworktest.xml
RJointfile=./rigidjoints.txt
SJointfile=./simplejoints.txt
Memberfile=./members.txt
Forcefile=./forces.txt
counter=-1
# Read the input file line by line using a for loop
IFS=$'\n' # set the Internal Field Separator to newline
for LINE in $(cat "$RJointfile")
do
echo "          <rigidjoint>">>frameworktest.xml
    counter=$((counter+1))
    IFS=$','; split=($LINE); unset IFS;
    echo "                <id>$counter</id>">>frameworktest.xml
    echo "                <xcoord>${split[0]}</xcoord>">>frameworktest.xml
    echo "                <ycoord>${split[1]}</ycoord>">>frameworktest.xml
echo "          </rigidjoint>">>frameworktest.xml
done
IFS=$'\n' # set the Internal Field Separator to newline
for LINE in $(cat "$SJointfile")
do
echo "          <simplejoint>">>frameworktest.xml
    counter=$((counter+1))
    IFS=$','; split=($LINE); unset IFS;
    echo "                <id>"$counter"</id>">>frameworktest.xml
    echo "                <xcoord>"${split[0]}"</xcoord>">>frameworktest.xml
    echo "                <ycoord>"${split[1]}"</ycoord>">>frameworktest.xml
echo "          </simplejoint>">>frameworktest.xml
done
echo "        </joints>">>frameworktest.xml
echo "        <strmems>">>frameworktest.xml
counter=-1
IFS=$'\n' # set the Internal Field Separator to newline
for LINE in $(cat "$Memberfile")
do
echo "          <strmem>">>frameworktest.xml
    counter=$((counter+1))
    IFS=$','; split=($LINE); unset IFS;
    echo "                <id>"$counter"</id>">>frameworktest.xml
    echo "                <startjoint>"${split[0]}"</startjoint>">>frameworktest.xml
    echo "                <endjoint>"${split[1]}"</endjoint>">>frameworktest.xml
echo "          </strmem>">>frameworktest.xml
done
echo "        </strmems>">>frameworktest.xml
echo "        <forces>">>frameworktest.xml
IFS=$'\n' # set the Internal Field Separator to newline
for LINE in $(cat "$Forcefile")
do
echo "          <force>">>frameworktest.xml
    IFS=$','; split=($LINE); unset IFS;
    echo "                <jointid>"${split[0]}"</jointid>">>frameworktest.xml
    echo "                <magnitude>"${split[1]}"</magnitude>">>frameworktest.xml
    echo "                <angle>"${split[2]}"</angle>">>frameworktest.xml
echo "          </force>">>frameworktest.xml
done
echo "        </forces>">>frameworktest.xml
echo "</framework>">>frameworktest.xml
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>">frameworktest.dtd
echo "<!ELEMENT framework (title, joints, strmems, forces)>">>frameworktest.dtd
echo "<!ELEMENT title (#PCDATA)>">>frameworktest.dtd
echo "<!ELEMENT joints (rigidjoint*, slidexjoint*, slideyjoint*, simplejoint+)>">>frameworktest.dtd
echo "<!ELEMENT rigidjoint (id?, xcoord?, ycoord?)>">>frameworktest.dtd
echo "<!ELEMENT slidexjoint (id?, xcoord?, ycoord?)>">>frameworktest.dtd
echo "<!ELEMENT slideyjoint (id?, xcoord?, ycoord?)>">>frameworktest.dtd
echo "<!ELEMENT simplejoint (id?, xcoord?, ycoord?)>">>frameworktest.dtd
echo "<!ELEMENT strmems (strmem+)>">>frameworktest.dtd
echo "<!ELEMENT strmem (id?, startjoint?, endjoint?)>">>frameworktest.dtd
echo "<!ELEMENT forces (force*)>">>frameworktest.dtd
echo "<!ELEMENT force (jointid?, magnitude?, angle?)>">>frameworktest.dtd
echo "<!ELEMENT id (#PCDATA)>">>frameworktest.dtd
echo "<!ELEMENT xcoord (#PCDATA)>">>frameworktest.dtd
echo "<!ELEMENT ycoord (#PCDATA)>">>frameworktest.dtd
echo "<!ELEMENT startjoint (#PCDATA)>">>frameworktest.dtd
echo "<!ELEMENT endjoint (#PCDATA)>">>frameworktest.dtd
echo "<!ELEMENT jointid (#PCDATA)>">>frameworktest.dtd
echo "<!ELEMENT magnitude (#PCDATA)>">>frameworktest.dtd
echo "<!ELEMENT angle (#PCDATA)>">>frameworktest.dtd

Any other type of joint, such as sliding joints, can be added with another do-loop routine which can be done with minor adjustment with a bit of copy and paste. This is what scripting is meant to do, provide small additional functionality that can have big impacts via automation. This little script will make creating XML files for input faster and easier with fewer opportunities to make mistakes.

Now back to the main feature.

About

This is where I place the very basic notes on programming from those starting at the very beginning using Linux or similar operating systems. It's set up to be understood by everyone. If you have an opinion as to how this page is done, then you are already and intermediate or advanced programmer and I don't care!