I just...

Talk about anything in here.
Post Reply
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

I just...

Post by EcazS »

I just spent three hours trying to fix a form issue.
Basically I have two forms, one to create a static page and one to create a dynamic page; I create the dynamic page form first and then simply copied the code and made the static page form but when I submitted the static form I didn't get any errors in case I left some fields out (I did get errors on the dynamic form).

So I spent three consecutive hours trying to figure out what the problem was, everything had been renamed properly and the code was exactly identical except for certain form-names. It turns out this was the problem;
Static form, the one that WAS NOT working
<form action="pages.php" method="post" id="c_form">
a bunch of fields
</form>
Dynamic form, the one that WAS working
<form action="#" method="post" id="c_form">
a bunch of fields
</form>
CAN YOU SPOT THE ERROR IN LESS THAN THREE HOURS?!
I am so fucking angry right now......
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: I just...

Post by Temor »

the difference I can spot is pages.php instead of #

Was that it? :P

I know the feeling. I struggled with a typo for 45 minutes today.
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: I just...

Post by EcazS »

Yep! That was the issue!
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: I just...

Post by Temor »

Haha. Ouch! :)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: I just...

Post by jacek »

I spend three hours on this code yesterday

Here is the wrong one
pro plot_solar_wind

openr, file, 'files/solar_wind.dat', /get_lun

header = ''

for i = 0, 60 do readf, file, header

month_hours = fltarr(31 * 24)
Vsw = fltarr(31 * 24)
Nsw = fltarr(31 * 24)
Psw = fltarr(31 * 24)
Rmp = fltarr(31 * 24)

day = 0
hour = 0
Vsw_in = 0.0
Nsq_in = 0.0
pts = 0

while not eof(file) do begin
	
	readf, file, day, hour, Nsw_in, Vsw_in, format = '(i2, 9x, i2, 10x, d14.5, d14.3)'
	
	month_hours[pts] = (day - 1) * 24 + hour
	
	Vsw[pts] = Vsw_in
	Nsw[pts] = Nsw_in
	
;	print, Vsw_in
	
	pts += 1
	
endwhile

free_lun, file

openw, file, 'files/some_kind_of_data.dat', /get_lun

for i = 0, pts - 1 do begin
	
	if Vsw le 0 then Vsw = !Values.F_NaN
	if Nsw le 0 then Nsw = !Values.F_NaN
	
	if Vsw gt 0 and Nsw gt 0 then begin
		
		Vsw *= 1E+3
		Nsw *= 1E-6
		
;		print, Vsw, Nsw
		
		Psw[i] = (1.67262E-27 * Nsw[i]) * (Vsw[i] ^ 2)
		
		Rmp[i] = ((31000E-9)^2 / (1.2566E-6 * Psw[i]))^(1 / 6.0)
		
		print, Vsw[i], Nsw[i], Psw[i], Rmp[i]
		
		if Rmp[i] gt 6.6 then begin
			
			printf, file, i, Vsw[i], Rmp[i], ' Magnetosphere'
			
		endif else begin
			
			printf, file, i, Vsw[i], Rmp[i], ' Solar wind'
			
		endelse
		
	endif else begin
		
		Psw[i] = !Values.F_NaN
		Rmp[i] = !Values.F_NaN
		
		printf, file, i, Vsw[i], Rmp[i], ' No data'
		
	endelse
	
endfor

free_lun, file

window, 1
plot, Vsw, ytitle = 'Speed (m/s)', min = 0

window, 2
plot, Nsw, ytitle = 'Density (#/m^3)', min = 0

window, 3
plot, Psw, ytitle = 'Pressure (#/m^3)', min = 0

end


And here is the right one
pro plot_solar_wind

openr, file, 'files/solar_wind.dat', /get_lun

header = ''

for i = 0, 60 do readf, file, header

month_hours = fltarr(31 * 24)
Vsw = fltarr(31 * 24)
Nsw = fltarr(31 * 24)
Psw = fltarr(31 * 24)
Rmp = fltarr(31 * 24)

day = 0
hour = 0
Vsw_in = 0.0
Nsq_in = 0.0
pts = 0

while not eof(file) do begin
	
	readf, file, day, hour, Nsw_in, Vsw_in, format = '(i2, 9x, i2, 10x, d14.5, d14.3)'
	
	month_hours[pts] = (day - 1) * 24 + hour
	
	Vsw[pts] = Vsw_in
	Nsw[pts] = Nsw_in
	
;	print, Vsw_in
	
	pts += 1
	
endwhile

free_lun, file

openw, file, 'files/some_kind_of_data.dat', /get_lun

for i = 0, pts - 1 do begin
	
	if Vsw[i] le 0 then Vsw[i] = !Values.F_NaN
	if Nsw[i] le 0 then Nsw[i] = !Values.F_NaN
	
	if Vsw[i] gt 0 and Nsw[i] gt 0 then begin
		
		Vsw[i] *= 1E+3
		Nsw[i] *= 1E+6
		
;		print, Vsw[i], Nsw[i]
		
		Psw[i] = (1.67262E-27 * Nsw[i]) * (Vsw[i] ^ 2)
		
		Rmp[i] = ((31000E-9)^2 / (1.2566E-6 * Psw[i]))^(1 / 6.0)
		
		print, Vsw[i], Nsw[i], Psw[i], Rmp[i]
		
		if Rmp[i] gt 6.6 then begin
			
			printf, file, i, Vsw[i], Rmp[i], ' Magnetosphere'
			
		endif else begin
			
			printf, file, i, Vsw[i], Rmp[i], ' Solar wind'
			
		endelse
		
	endif else begin
		
		Psw[i] = !Values.F_NaN
		Rmp[i] = !Values.F_NaN
		
		printf, file, i, Vsw[i], Rmp[i], ' No data'
		
	endelse
	
endfor

free_lun, file

window, 1
plot, Vsw, ytitle = 'Speed (m/s)', min = 0

window, 2
plot, Nsw, ytitle = 'Density (#/m^3)', min = 0

window, 3
plot, Psw, ytitle = 'Pressure (#/m^3)', min = 0

end


Who see the difference without cheating ;)
Image
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: I just...

Post by bowersbros »

Okay, i havent got a clue, hint? ;D
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: I just...

Post by Temor »

I spotted it!
**Spoiler**
/
/
/
/
line 48
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: I just...

Post by jacek »

Temor wrote:I spotted it!
It took me at least 2 hours to see that !

I almost cried :lol:
Image
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: I just...

Post by Temor »

jacek wrote:
Temor wrote:I spotted it!
It took me at least 2 hours to see that !

I almost cried :lol:
I can relate to the feeling. I spent a total of 4 hours debugging today. I wanted to punch something afterwards.
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: I just...

Post by EcazS »

I wish I could...not debug stuff... Just leave it and it would magically work, or at least not spend several hours on it :lol:
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: I just...

Post by jacek »

Ooo I have another good one

This one is wrong
function fill_gaps, in
	
	total = n_elements(in)
	
	i = -1
	
	while i lt total - 1 do begin
		
		++i
		
		if finite(in) eq 0 then begin
			
			gap_start = (i gt 0) ? i - 1 : 0
			
			for c = gap_start + 1, total - 1 do begin
				
				if finite(in[c]) eq 1 then begin
					
					gap_end = c
					
					diff = abs(gap_start - gap_end) + 1
					
					in[gap_start : gap_end] = in[gap_start] + (in[gap_end] - in[gap_start]) * findgen(diff) / (diff - 1)
					
					i = c
					
					break
					
				endif
				
			endfor
			
		endif
		
	endwhile
	
	return, in
	
end


And here is the correction

function fill_gaps, in
	
	total = n_elements(in)
	
	i = -1D
	
	while i lt total - 1 do begin
		
		++i
		
		if finite(in) eq 0 then begin
			
			gap_start = (i gt 0) ? i - 1 : 0
			
			for c = gap_start + 1, total - 1 do begin
				
				if finite(in[c]) eq 1 then begin
					
					gap_end = c
					
					diff = abs(gap_start - gap_end) + 1
					
					in[gap_start : gap_end] = in[gap_start] + (in[gap_end] - in[gap_start]) * findgen(diff) / (diff - 1)
					
					i = c
					
					break
					
				endif
				
			endfor
			
		endif
		
	endwhile
	
	return, in
	
end


anyone guess how long that took ?!
Image
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: I just...

Post by Temor »

I found it! line 5 :)

It took me around 10 seconds to spot it, but if it was me who wrote it it would probably take an hour and a half, so that's my guess :)
Post Reply