///////////////////////////////////////////////////////////////////// // (c) Gatan Inc. ///////////////////////////////////////////////////////////////////// // This script will let the user change the units that an image is calibrated in. // it handles km, m, cm, µm, nm, pm, and Å. It will take an image calibrated in // any of these units and convert the calibration (and thus the scale bar also) // to new units. // The script has two alternative main methods. A simple text-input version // and a method building a custom dialog for more convenience. ///////////////////////////////////////////////////////////////////// // last modified 08-July-2014 BS /* This method, as indicated by 'number' before the method name, returns a numerical value corresponding to the exponent of the input units when given a string as input. e.g. supplied with cm, the method returns -2 to denote the units are 10e-2m Note this method is called twice; once to calculate the old units and also the new units. Hence if either the entered units are not recognised or if the image calibration is not in known units then the routine will throw the unknown units error message. */ number GetUnitsExponent( string units ) { number exp if (units == "km") exp = 3 else if (units == "m") exp = 0 else if (units == "cm") exp = -2 else if (units == "mm") exp = -3 // Note the '||' is an OR operator else if (units == "µm" || units == "um" ) exp = -6 else if (units == "nm") exp = -9 else if (units == "Å" || units == "A") exp = -10 else if (units == "pm" ) exp = -12 else Throw( "Unknown units.\nEnsure the input and image calibration are in SI units.") return exp } /* This method, as indicated by 'string' before the method name, returns a string value. It replaces the 'easy' format of A and um by the nice Å or µm, respectively. Other unites are returned unchanged. */ string GetNiceUnit( string units ) { if (units == "um" ) return "µm" if (units == "A") return "Å" return units } /* This method changes the calibration units of image 'img' to the units specified by the string 'newunits' As indicated by the use of 'void', the method doesn't return anything */ void ChangeImageUnits( image img, string newunits ) { //NDimen is the number of dimensions of image img number nDimen = img.ImageGetNumDimensions() // Index is the dimension index number // Loop nDimen times, changing the units of each dimension. number index for (index=0; index simple version MenuChangeImageUnitsByDialog( ) // --> custom dialog version