This is my code with lines 4-6 asking for the input file:
import numpy as np
from matplotlib import pyplot as plt
infile = input('Enter input file name:')
mags = open( infile ,'r')
cluster = input('Enter the name of the cluster:')
vmag=[]
imag=[]
for line in mags:
column = line.split()
flag=int(float(column[0]))
RA=(column[14])
DEC=(column[15])
RA = int(float(RA.split(':')[2]))
DEC = int(float(DEC.split(':')[2]))
a = input('Enter flag lower range value')
b = input('Enter flag higher range value')
c = input('Enter RA lower range value:')
d = input('Enter RA higher range value:')
e = input('Enter DEC lower range value:')
f = input('Enter DEC higher range value:')
if flag in range (a,b):
#if flag == 0:
if RA in range (c,d):
if DEC in range (e,f):
vmag.append(float(column[1]))
imag.append(float(column[4]))
vmag = np.array(vmag)
imag = np.array(imag)
plt.scatter(vmag-imag, vmag, lw=0, s=5)
plt.ylim(27, 21)
plt.xlim(-0.5, 3.0)
plt.title('Colour Magnitude Diagram', cluster)
plt.ylabel('F555 mag')
plt.xlabel('F555-F814')
plt.grid(b=True)
plt.savefig(cluster, '.pdf')
plt.show()
But when I run it and enter the input file 'ngc185_u3kl01.txt'(which is in the same directory) I get the following error:
Enter input file name:ngc185_u3kl01
Traceback (most recent call last):
File "<ipython-input-2-917781cbe168>", line 1, in <module>
runfile('C:/Users/Keith/.spyder2/CMD.py', wdir='C:/Users/Keith/.spyder2')
File "C:\Users\Keith\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 585, in runfile
execfile(filename, namespace)
File "C:/Users/Keith/.spyder2/CMD.py", line 5, in <module>
infile = input('Enter input file name:')
File "C:\Users\Keith\Anaconda\lib\site-packages\IPython\kernel\zmq\ipkernel.py", line 364, in <lambda>
input = lambda prompt='': eval(raw_input(prompt))
File "<string>", line 1, in <module>
NameError: name 'ngc185_u3kl01' is not defined
I have checked and double checked the name of the file matches what I type, even copied and pasted the input file name but still no success. I have also tried it with and without '.txt' on the end.
name 'ngc185_u3kl01' issurelynot defined, butname 'ngc185_u3kl01.txt' issurelydefined. I mean to say that you should input the name asngc185_u3kl01.txt