Roll & Rock
|
[
Roll & Rock ] [ Main Menu ] |
|
|
|
21805 |
|
|
Date: February 09, 2021 at 10:38:16
From: Skywise, [DNS_Address]
Subject: Roger's programming problem |
|
|
Starting new thread for this discussion.
OK, it's a CSV file. Still text. I presume this is from USGS. So for example,
2021-02-09T18:29:39.410Z,38.8251648,-122.7716675,0.11,0.65,md,10,83,0.005473,0.02,nc,nc73520821,2021-02-09T18:31:16.065Z,"4km W of Cobb, CA",earthquake,0.27,0.6,0.09,2,automatic,nc,nc
Which breaks down to: date: 2021-02-09T18:29:39.410Z lat: 38.8251648 lon: -122.7716675 depth: 0.11 mag: 0.65
I'm sure we can figure this out. Been reading these files for decades.
Can you post your code for parsing this line?
Brian
|
|
|
|
Responses:
[21806] [21807] [21808] [21809] [21810] [21811] [21812] [21813] [21821] [21822] [21823] [21830] [21831] [21832] |
|
21806 |
|
|
Date: February 09, 2021 at 10:52:01
From: Roger , [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
Brian;
No, I hand-edit it down to 10 comma-delimited numbers.
1976, 10, 12, 10, 45, 12.23, -23.345, 126.234, 2.34, 6.9
and the code is;
input #3: yr, mo, da, hr, mn, sec, lat, lon, dep, mag
so what could go wrong?
Roger
|
|
|
|
Responses:
[21807] [21808] [21809] [21810] [21811] [21812] [21813] [21821] [21822] [21823] [21830] [21831] [21832] |
|
21807 |
|
|
Date: February 09, 2021 at 11:13:41
From: Skywise, [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
You're still "hand editing" it?
Wouldn't it be better to write your code to read the USGS file directly? Then you don't have to edit anything.
Anyway...
Do the other variables fill with correct values? Only the mag is zero?
The code looks right. I'm reviewing TB documentation online.
So, it must be something elsewhere. I have had problems where it seem the error is in one spot but it is actually somewhere else. Run through the code line by line in your head and imagine what the values should be.
Brian
|
|
|
|
Responses:
[21808] [21809] [21810] [21811] [21812] [21813] [21821] [21822] [21823] [21830] [21831] [21832] |
|
21808 |
|
|
Date: February 09, 2021 at 15:11:09
From: Roger , [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
Brian;
Yes, it would be better to edit the full file but a lot more trouble.
Ideally one would read the whole line into a string and then do multiple searches to trim it down to what is needed.
Unfortunately that requires beginning and ending quote marks.
Roger
|
|
|
|
Responses:
[21809] [21810] [21811] [21812] [21813] [21821] [21822] [21823] [21830] [21831] [21832] |
|
21809 |
|
|
Date: February 09, 2021 at 15:22:07
From: Roger , [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
Brian;
Scratch that; TB has a LINE INPUT command I had forgotten all about.
I'll try that, thanks for jogging my failing mind!
Roger
|
|
|
|
Responses:
[21810] [21811] [21812] [21813] [21821] [21822] [21823] [21830] [21831] [21832] |
|
21810 |
|
|
Date: February 09, 2021 at 16:04:40
From: Roger , [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
brian
This is weird!
I told the PC to open the file, input a line and print it, then stop
Instead, it prints the whole file and stops.
I thought I was losing it but now I think the PC has problems.
Roger
|
|
|
|
Responses:
[21811] [21812] [21813] [21821] [21822] [21823] [21830] [21831] [21832] |
|
21811 |
|
|
Date: February 09, 2021 at 17:02:50
From: Skywise, [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
No, Roger. Sorry to say but that's not a hardware issue.
You're definitely doing something not quite right.
Got any previous code you know that works? Look at it and compare. I may be younger and a much better programmer but I still don't know everything and sometimes have to look to old code to remember how to do something.
That is in part why I now write my code into classes. That's a C++ thing. But in a sense that means I can treat it like a little library. If everything to do a certain function is contained within the class, then when I write a new program that needs to do those same things, I can just copy and paste that class code into my program and it JUST WORKS.
In fact, I just accomplished that very thing with my current program. Remember when I wrote that program to download data from the USGS server? I just cut & pasted several large chunks of that code into my new program and now my 3D globe program can download quakes and show them!!!
More on that in a bit....
But getting back to your problem. Maybe if you try to write a new program for testing, one that just does a very simple thing. Reads that file and displays the data.
Also, could it be possible the data file is somehow corrupted? I mean, maybe you goofed when you "hand edited" it?
Brian
|
|
|
|
Responses:
[21812] [21813] [21821] [21822] [21823] [21830] [21831] [21832] |
|
21812 |
|
|
Date: February 09, 2021 at 17:35:01
From: Roger , [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
Brian;
What you're calling classes are called subroutines in TB and yes I use them quite a lot. Every large program will have several.
Roger
|
|
|
|
Responses:
[21813] [21821] [21822] [21823] [21830] [21831] [21832] |
|
21813 |
|
|
Date: February 09, 2021 at 18:24:23
From: Skywise, [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
So, any luck with your program yet? I hate what seem like such simple problems. I run into that every now and then. Something just isn't working and you can't see the problem. Usually turns out to be something very subtle and not always in an obvious place.
Classes are totally different than subroutines. I was just simplifying for your benefit.
In reality they are completely self contained bits of code. A class can contain many different types of data, data structures, and functions. Basically, everything to do with a particular bit of functionality.
For example, I have a class that handles everything to do with drawing the latitude and longitude lines on my globe. It has several different functions (subroutines) that are called to do various things. There's an initialization function to get the class set up, functions to set the camera view, functions to set the grid size and resolution, a function for setting the grid color, and of course a function to actually draw the grid based on the current state of parameters. Within the class are other functions that are used only internally to the class, such as loading some small files that contain little programs that tell the graphics card how to draw the data (known as shader programs).
Point being, my latitude/longitude class contains all the code necessary to draw a latitude longitude grid on a sphere in OpenGL.
So, it's more than just a subroutine. It's almost a whole program unto itself.
Classes are part of Object Oriented Programming. The latitude/longitude class is an object. And my program actually has several instances of this same object. That is, the same class is used multiple times; four times to be exact, for grids of 15, 10, 5, and 1 degree in size, each a different color.
These are all separate objects. Each self contained. Changing settings for one instance does not affect any other instances of that class (there are exceptions). Yet, there's only one set of code. One class.
And to make things more fun, a class can contain instances of other classes. A whole hierarchy of classes depending on other classes. Objects built of smaller objects, all to make one large machine.
In reality, it's just a fancy way to organize code to make it easier to reuse things and to help the programmer from making stupid mistakes, which is easy to do with large programs.
Brian
|
|
|
|
Responses:
[21821] [21822] [21823] [21830] [21831] [21832] |
|
21821 |
|
|
Date: February 10, 2021 at 12:43:43
From: Roger , [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
Hi all;
Problem solved!!
After trying everything imaginable to fix the program (and failing) I realized the problem was not with the program at all.
It was the datafile! It had lots of trailing blanks and no eol marks.
Once that was corrected the program runs correctly!
Roger
|
|
|
|
Responses:
[21822] [21823] [21830] [21831] [21832] |
|
21822 |
|
|
Date: February 10, 2021 at 20:56:01
From: Skywise, [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
Classic case of garbage in, garbage out. I'm glad you finally got it figured out.
I still think it would be worth your while to write a routine that can parse the USGS CSV file directly. I've been doing that for years and it's not really that hard.
I parse the file and store the data I want into an array. Then the program works on the array data, which is faster as it's in memory.
In fact, you remember those C++ classes I mentioned? I have a class just for holding quake data. And it has routines for parsing various data formats.
Brian
|
|
|
|
Responses:
[21823] [21830] [21831] [21832] |
|
21823 |
|
|
Date: February 11, 2021 at 05:52:17
From: Roger , [DNS_Address]
Subject: Re: Roger's programming problem |
|
|
Brian;
Yes. I was beating the wrong horse for a day or so.
I'm working on that right now. Hand editing is ok for small files, especially with Crimson Editor, as it handles huge files easily but it's really not a good use of time when a program can do it so much faster.
Roger
|
|
|
|
Responses:
[21830] [21831] [21832] |
|
21830 |
|
|
Date: February 14, 2021 at 19:17:58
From: Roger , [DNS_Address]
Subject: Re: Roger's programming problem - solved |
|
|
Hi all;
After much effort I now have a program which will take a downloaded quake search file, extract the quakes and reformat them to add to my NEIC file.
Roger
|
|
|
|
Responses:
[21831] [21832] |
|
21831 |
|
|
Date: February 14, 2021 at 19:46:25
From: Skywise, [DNS_Address]
Subject: Re: Roger's programming problem - solved |
|
|
Awesome!!!! That should make your like much easier.
I do something similar, converting the CSV text format to a binary format that loads much faster.
Brian
|
|
|
|
Responses:
[21832] |
|
21832 |
|
|
Date: February 14, 2021 at 19:59:56
From: Roger , [DNS_Address]
Subject: Re: Roger's programming problem - solved |
|
|
Skywise;
Yes it will save a lot of time too. I can update the file more often too.
Should have done it long ago. The file is over 900,000 quakes now. Most done by hand using Crimson Editor which took forever because NEIC has a 20,000 quake limit.
Roger
|
|
|
|
Responses:
None |
|
[
Roll & Rock ] [ Main Menu ] |