Open main menu

Script to take any text file, and convert to be out in a systemtest

#!/bin/tcsh -f

# To replace start end ending of line for relax.
set s='$'
set t='"'
sed -e "s/^/            '/g" -e "s/$s/'+$t\\n$t\,/g" $1

Input

Example

file = CR72_point_1_N
points = 2
format = ascii
interleaving = field
field = locations, field0
structure = 3-vector, scalar
type = float, float

end

Output

            'file = CR72_point_1_N'+"\n",
            'points = 2'+"\n",
            'format = ascii'+"\n",
            'interleaving = field'+"\n",
            'field = locations, field0'+"\n",
            'structure = 3-vector, scalar'+"\n",
            'type = float, float'+"\n",
            ''+"\n",
            'end'+"\n",

To be used in systemtest

        # Set filepaths.
        map_general = ds.tmpdir+sep+file_name_map+".general"

        # Test the files exists.
        self.assert_(access(map_general, F_OK))

        print("\nChecking the dx map .general file.")
        res_file = [
            'file = CR72_map_1_N'+"\n",
            'grid = 5 x 5 x 5'+"\n",
            'format = ascii'+"\n",
            'interleaving = field'+"\n",
            'majority = row'+"\n",
            'field = data'+"\n",
            'structure = scalar'+"\n",
            'type = float'+"\n",
            'dependency = positions'+"\n",
            'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n",
            ''+"\n",
            'end'+"\n",
        ]
        file = open(map_general, 'r')
        lines = file.readlines()
        file.close()
        for i in range(len(res_file)):
            # Skip time point
            #if i == 2:
            #    continue
            self.assertEqual(res_file[i], lines[i])