cino hilliard on Sat, 21 Jul 2007 23:41:12 +0200

 Re: how to read one line from a datafile at a time?

You can use
then

a[1] is the value of the first line, a[2] the value of the second line, etc.

Cheers,
Bill.

Why can't we get the typical gcc file I/O functions and the Win32 API built right in to the interpreter?


If I could get windows to compile the gp source, i would do this myself and I don't have the time nor desire to learn Linux but I can't. For example suppose I want to read a 300+ gig file of the first
1 trillion primes store 8byte wall to wall in a file on a server
Dell8200\\h8200\\sievedata\\prime2-1trill.bin".


Then say I want to read the 37,000,000,007-th prime. Here is how I do it now.

prime2(n) =   \\ the nth prime using c:\sieve\prime.exe calling
\\ Dell8200\\h8200\\sievedata\\prime2-1trill.bin"
{
local(x,s);
s=concat("c:/sieve/prime ",Str(n));

s=concat(s," > temp.txt"); \\Must save to a temp file for correct output
             system(s);
}

/*****gcc 3.4.4 command line code to read the n-th prime < 1 trillion.*****/

#include <windows.h>    // Win32 Header File
#include <stdio.h>
#define chr64(a) ulltoa(a,str,10)
static char    fil[50],fil2[50];
static HANDLE  H;
static int     recl;
static long     high;
static char     str[30];

int main(int argc, char *argv[])
{
unsigned long long n;
strcpy((char*)fil,"\\\\Dell8200\\f\\sievedata\\prime2-1trill.bin");
unsigned long long buffer,offset,b;
unsigned long long j;
n=atoll(argv[1]);
b=536870913;
recl=8;
high=n/b;
offset=recl*(n-1);
SetFilePointer(H,offset,&high,FILE_BEGIN);
printf("%s",chr64(buffer));
CloseHandle(H);
return 0;
}

This is awkward but it works pretty well.


Maybe someone out there who can compile gpcan build a set of functions to do this and offer the
compiled windows version for download as say, gpE or gp extended.


Maybe this feature along with typical gcc I/O functions could be built into the kernel?

Pest from the west,
Cino hilliard