Author Topic: create a temporary file  (Read 5421 times)

0 Members and 1 Guest are viewing this topic.

monliv

  • Newbie
  • *
  • Posts: 30
    • View Profile
create a temporary file
« on: September 01, 2020, 07:04:05 PM »
greetings to all.
I try to ask for help to solve a problem on a module we would like to create.

the problem is not selecting a database and scrolling through the data
but temporarily stores the resulting data from each theme on a temporary array / file.
increasing a total to snap to the detected aspect string
example
sun at 13 ° from mercury I would like to write
0 (sun), 13 (asp), 3 (mercury), 1 (total readings)
obviously if the data is already present
0 (sun), 13 (asp), 3 (mercury), 2 (total readings)

at the end of the reading, obviously sort the table and
put everything on a file.

This last part we should be able to do it ourselves.
with other languages ​​I would use an indexed file which
I would increase as I add data.

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 1291
    • View Profile
Re: create a temporary file
« Reply #1 on: September 01, 2020, 07:21:13 PM »
Hey Livio, great to see you posting here.

This part of your question i don't understand, you want to search for an aspect string, what do you mean?

Quote
increasing a total to snap to the detected aspect string

for creating plain text files there is linewrite() see c:\planetdance\ab\excel.ab for an example.
Code: [Select]
char s[99];
for (i < count)
  {
  strset(s, "blabla", arg arg);
  linewrite("mytmp.txt", s);
  }

But maybe even better is strlist(), you can sort the list, save it to a file, etc. It has an example in the help.

I'm not really sure what you want to do, maybe you can explain it some more?
Greetings from Groningen Netherlands.

monliv

  • Newbie
  • *
  • Posts: 30
    • View Profile
search quickly a string
« Reply #2 on: September 07, 2020, 01:31:30 PM »
the linewrite command is fine to manage a file,
we also tried strlist () with the birtdays example, but we don't solve.
we need to search quickly for a string in a file or in memory.
If we find it, we add 1 in a numeric field that we call
counter and rewrite, otherwise we append the string, and write 1 in the same counter.
in the 'find' program use the command strcmp (t, s) = 1

All this is useful, because we do not start from pre-established aspects,
but we will count the frequencies that are gradually formed in the themes, that we are going to deepen.

monliv

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: create a temporary file
« Reply #3 on: September 07, 2020, 04:54:19 PM »
Here I'm going to look for a string in memory.
if the searched string is already present i add 1 to counted
and rewrite it
otherwise I simply write it.

example

ii = 0; for (ii < count)
           {
            memval(0, ii, &s);
            nm = split(s, s1, ',');
            c1b   =  numstr(s1[1]);
            c2b   =  numstr(s1[2]);
            c3b   =  numstr(s1[3]);
            c4b   =  numstr(s1[4]);
            strset(pr1, "%d,%d,%d,%d",c1b,c2b,c3b,c4b);
            if (TRUE = strcmp(p1, pr1))
            {
             contati   =  numstr(s1[5])+ 1;
             div =  numstr(s1[6]);
             strset(s, "%9s,%d,%d,%d,%d,%8d,%d",chi2s,c1,c2,c3,c4,contati,div);
             memwrite(0, ii, &s);
             ii = count;`if found rewrite and exit
             return;
            }}
`if not found write and exit
   contati = 1;
   strset(s, "%9s,%d,%d,%d,%d,%8d,%d",chi2s,c1,c2,c3,c4,contati,div);
   memwrite(0, count, &s);
   count += 1;
return;

Already with 50 themes it becomes very very slow
in reading and writing.
maybe there is a search function or a index on file
that speeds up a lot ?

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 1291
    • View Profile
Re: create a temporary file
« Reply #4 on: September 07, 2020, 05:03:27 PM »
Sorry, i see this only now.
You code is very confusing to me, please describe what you want.
I see a memval() but i don't see how you filled that memory.

If you want to search for a string in memory, this is an example using strlist().
You need to update for this!

Code: [Select]
window(555, 555);
char s[99];

strlist(0, s, 0); ` create the list
int n, i = 0; for (i < 16)
  strlist(3, planetname[i], i); ` add planetnames

strcpy(s, "blabla");
n = strlist(12, s, 0);           ` is it in the list?
if (n > 0)
  say(s, "found");
else
  say(s, "not found");

strcpy(s, "Mars");
n = strlist(12, s, 0);
if (n > 0)
  say(s, "found");
else
  say(s, "not found");
run;

I moved the other message, please keep things in one place, thank you.
Greetings from Groningen Netherlands.

monliv

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: create a temporary file
« Reply #5 on: September 07, 2020, 05:59:49 PM »
The record consists of 4 fields.
a) 0-9 chi2 (numeric)
b) 10-20 string (alphanumeric) that collects 4 numbers (for example: planet 1 + planet2 + aspect + other number)
c) 31-10 counted
d) 41-10 expected
So I compose these values taken from the reading of a theme.
reading the next record I go to see if this value already exists.
If I find I add 1 to the counted field otherwise I write
a new line in the file.

monliv

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: create a temporary file
« Reply #6 on: September 07, 2020, 06:20:39 PM »
I've only seen now, that you have added a new function to strlist.
12 search the list for 's', returns -1 when not found, else the index.

I try it.
Thanks

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 1291
    • View Profile
Re: create a temporary file
« Reply #7 on: September 07, 2020, 06:28:53 PM »
Yes indeed, try something like this.

Code: [Select]
window(555, 555);
real planet[PLANETS];
char s[999];

int i, n = readopen("jean.db", 0);
strlist(0, s, 0);
for (i < n)
  {
  readrecord(0, i);
  getplanets(0, planet);
  strset(s, "%d", planet[0]); ` etc
  if (strlist(12, s, 0) = -1)
    strlist(3, s, 0);` not found, add it
  else
    {
    ` found
    i=i;
    }
  }
run;
Greetings from Groningen Netherlands.

monliv

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: create a temporary file
« Reply #8 on: September 11, 2020, 06:42:12 PM »
if (strlist(12, s, 0) = -1)
    strlist(3, s, 0);` not found, add it
  else
    {
    ` found
    i=i; <<<<<<<<<<<<
   
    to rewrite how it works? I do not understand.
i = i says nothing,
I prepare the string, then what do I do?
maybe it's very easy, but I need a complete example.

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 1291
    • View Profile
Re: create a temporary file
« Reply #9 on: September 11, 2020, 06:55:55 PM »
no it does nothing, sorry, i always use 'i=i' for debugging.

But at that place a duplicate is found and you can see which. What do you want to do with duplicates?

Code: [Select]
window(555, 555);
real planet[PLANETS];
char s[999];

int i, n = readopen("jean.db", 0);
strlist(0, s, 0);
for (i < n)
  {
  readrecord(0, i);
  getplanets(0, planet);
  strset(s, "%d", planet[0]); ` etc
  int m = strlist(12, s, 0);
  if (m = -1)
    strlist(3, s, 0);` not found, add it
  else
    {
    ` here a duplicate is found, it is number m in the stringlist
    }
  }
run;
Greetings from Groningen Netherlands.

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 1291
    • View Profile
Re: create a temporary file
« Reply #10 on: September 11, 2020, 09:18:12 PM »
if you prefer the memget/memread etc. functions because they are more powerful, i could make a function to search for data in a memory block fast. But i'm not gonna write your script for you, you have to design it yourself, i can only help with the functions. And please do communication about it here on the forum, i will not help via email, i have too much other work and things to do.
Greetings from Groningen Netherlands.

monliv

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: create a temporary file
« Reply #11 on: September 12, 2020, 11:34:04 AM »
Tell me if memget / memread etc.  is more powerful than strlist.
In that case, if you write a memsearch command, which looks for a string in memory could be very useful.
The script is already written.

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 1291
    • View Profile
Re: create a temporary file
« Reply #12 on: September 12, 2020, 12:59:59 PM »
memread/write is more powerfull because you can make structures.
I had a look at your code, you have

Code: [Select]
memget(0, 9999, 60); ` this will make a block with 9999 times 60 bytes
char s[99];
...
memwrite(0, i, &s);

The size of the parts in the block is 60 bytes but you are using a string of 99 bytes. So i hope you know what you are doing. Those functions are meant for things like this:

int a[10], b;
real c[6];
char s[100];

In total this 'structure' is 10 * 4 + 4 + 6 * 8 + 100 = 500 bytes, so you do memget(0, 9999, 500) and now you can do
memread(0, i, &a);
because the structure starts with int a.

Take a good look at this, i'\m not sure you understand these functions correct.
If you do maybe you can do something else in stead of just using one string with  strset(s, "%20s,%d,%d,%d,%d,%.2f,%.2f,0",jdx,aa,aaa,a,graf,p1,p2);

This is also why i can only help to a certain point, it is your work :).

I will make a memsearch()

Greetings from Groningen Netherlands.

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 1291
    • View Profile
Re: create a temporary file
« Reply #13 on: September 12, 2020, 01:34:56 PM »
Made a memsearch command, help:

memsearch

Syntax: memsearch(int blockno, int stringoffset, char searchstring[$]);
Action: searches blockno at stringoffset for searchstring, returns number in block or -1 if not found.

Example:

Code: [Select]
window(660,660);
int i, n = readopen("jean.db", 0);
real planet[PLANETS];

` this is the structure for memget/read/write, 69 bytes total
real sun;
char name[61];

memget(0, n, 69);     ` make a memblock with each record's sun and name

for (i < n)
  {
  readrecord(0, i);
  getplanets(0, planet);
  sun = planet[0];
  getname(0, name);
  memwrite(0, i, &sun);
  }
i = memsearch(0, 8, "Jean Cremers"); ` search for this name,  'name' comes after real 'sun' so it starts at 8 bytes from the start.
if (i < 0)
  say("", "Not found");
else
  say("", "found");
run;


Greetings from Groningen Netherlands.

monliv

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: create a temporary file
« Reply #14 on: September 13, 2020, 06:21:26 PM »
very very well, it's very fast thanks :)