a_rad=0.5 a_deg=a_rad*180./!pibut that's not very neat. If you use this a lot you will have to type a lot and maybe make mistakes.
We can define a small program that does this for us. Open a file called rad_to_deg.pro
Put the lines below in it.
Function rad_to_deg,input_rad ;Function to convert radians to degrees output_deg=input_rad*180./!pi return,output_deg endNote that the ``;'' symbol is a comment and ignored by IDL and you should always put a comment at the start of a program saying what it does.
We can use our program by for example typing,
.compile rad_to_deg degrees=rad_to_deg(!pi/2.) print,degreesIDL puts ``!pi/2.'' into the function (the input parameter), and converts it to degress and outputs this (the returned variable).