Combining data of different GCNs in a single file

As I said before (4 days ago)

  1. put rethrow() in your catch sequence in order to know what are the errors (exceptions) that were catched

  2. the 1st problem is there is no match for GRB so the m variable is not defined

  3. you should refactor the code so the regular expression is only done once, and replace all m.match by grb variable so it is already defined (even to nogrb in case of no match).

See « modified code » of 4 days ago.

Good luck!

Still it is not renaming Tmid-T0 and Limit columns. :worried:

Look code
using HTTP , CSV, DataFrames
function doanalysis()
                            dfg=nothing
                            for x in 34000:34146
                          print("\r peeking at GCN $x ")
                         try
                             url = "https://gcn.nasa.gov/circulars/$x/raw"
                             resp = HTTP.get(url) 
                             status=resp.status
                             print(" ",status," "); 
                             if status == 404 ; println("status=",status); continue; end          
                             txt = String(resp.body)
							 grb_rexp=r"GRB ?\d{6}([A-G]|(\.\d{2}))?"
							 m=match(grb_rexp,txt)
							 grb="nogrb"
                             if occursin(grb_rexp,txt)
				                  print(m.match)
								  grb=m.match
			                  end
			                 function dframe()
			                    df.GCN=[x for i in 1:nrow(df)]
                                df.GRB=[grb for i in 1:nrow(df)]
                                if isnothing(dfg) 
                                      dfg=df
                                else
                                      dfg=vcat(dfg,df,cols=:union)
                                end # if x is first
                             end  # dframe

                             if occursin("V. Lipunov", txt)
                                 println(" MASTER report")                                
                                 he=first(findfirst(r"^Tmid"im,txt))
                                 lr=first(findnext("\nFilter",txt,he))-1
                                 cltxt=txt[he:lr]                                 
                                 df=CSV.read(IOBuffer(cltxt), DataFrame, delim='|', skipto=3) 
                                 if "Limit" in names(df); rename!(df, "Limit" => "Mag"); end  
                                 if "Filt." in names(df); rename!(df, "Filt." => "Filter"); end 
                                 if "Tmid-T0" in names(df); rename!(df, "Tmid-T0" => "Time"); end
                                 #rename!(df,  "Filt." => "Filter", "Tmid-T0" => "Time")        
                                 dframe()
                                elseif occursin("report on behalf of the Swift/UVOT team",txt)
                                    println(" SWIFT/UVOT report")
                                    hb,he=findfirst(r"^Filter"im,txt)
			                        lr,_=findnext("\n\nThe",txt,he)
			                        cltxt=replace(txt[hb:lr], " +/- "=>s"\t", r"  +(\w)"=>s"\t\1" ,r"  +(>)"=>s"\t",r"\+/?- ?"=>s"\t",">"=>s"\t")
			                        df=CSV.read(IOBuffer(cltxt), DataFrame, delim='\t')
			                        if "Column6" in names(df); rename!(df, :Column6 => :Mag_err); end
			                        df.Time = (df."T_start(s)" .+ df."T_stop(s)") ./2
			                        dframe()
                             end # if occursin
                         catch e
                             println("error ")
                            #rethrow()
                         end # trycatch
                     end # for loop
                     println()
                     if !isnothing(dfg)
                         CSV.write("data-all.csv",dfg)
                     else
                         @info "no dfg to write"
                     end # !isnothing
                     end # function doanalysis
doanalysis()

but below code works if i provide renaming for every column.

 rename!(df,["Time","Date Time","Telescope","Coord (J2000)","Filter","Exp(s)","Mag","Comment"])