Index: README-blksz =================================================================== --- README-blksz (.../trunk) (revision 0) +++ README-blksz (.../branches/blksz_improvement) (revision 531) @@ -0,0 +1,27 @@ + Using environment variables to control buffering + ------------------------------------------------ + + This version of netCDF sets buffer sizes according to the +values of certain environment variables as follows: + + "NC_BLKSZ_filename" where "filename" is the prefix-part +of the netcdf file being opened, from the last "/" to the +first ".". For example, when opening "/home/me/MyFile.nc.001", +netCDF will look for an environment variable "NC_BLKSZ_MyFile". + + Next, netCDF looks for the generic "NC_BLKSZ". An earlier +implementation of this feature used "NC_BLOCKSIZE" instead, +so finally, if a blocksize has not been found, "NC_BLOCKSIZE" +is used. If none of these are set, netCDF uses the pagesize, +as per the earlier netCDF versions. + + The buffer size can be an integer, optionally suffixed +with "k", K", "m", "M", "kb", "MB" etc (case-insensitive) +for kilobytes and megabytes. Alternately, if the buffer size +is set to "FILE", and the file already exists, netCDF will +use the size of the existing file as a buffer size. + + A warning: the actual memory space allocated is roughly +twice the buffer size requested, this is an implementation +detail within netCDF. + Index: libsrc/posixio.c =================================================================== --- libsrc/posixio.c (.../trunk) (revision 531) +++ libsrc/posixio.c (.../branches/blksz_improvement) (revision 531) @@ -15,6 +15,7 @@ #include #include #include +#include #ifdef _MSC_VER /* Microsoft Compilers */ #include #else @@ -104,7 +105,84 @@ return (size_t) 2 * pagesize(); } +/* sjl: allow the user to specify buffer sizes via env vars */ +size_t decode_size(const char* path, const char* size_string) +{ + /* only should be called from get_user_chunk_size */ + size_t user_chunk_size = 0; + size_t len; + int i; + struct stat sb; + char *new_string = NULL; + + /* make case insensitive */ + len = strlen(size_string) + 1; + new_string = (char*) malloc(sizeof(char)*len); + for (i=0; i *sizehint) *sizehint = user_chunk_size; + + return; +} + /* * Sortof like ftruncate, except won't make the * file shorter. @@ -164,6 +242,7 @@ } return ENOERR; } + /* End OS */ /* Begin px */ @@ -1460,6 +1539,7 @@ } *((int *)&nciop->fd) = fd; /* cast away const */ + get_user_chunk_size(path, sizehintp); /* sjl: update sizehint wrt env vars */ if(*sizehintp < NCIO_MINBLOCKSIZE || *sizehintp > NCIO_MAXBLOCKSIZE) { /* Use default */ @@ -1584,6 +1664,7 @@ } *((int *)&nciop->fd) = fd; /* cast away const */ + get_user_chunk_size(path, sizehintp); /* sjl: update sizehint wrt env vars */ if(*sizehintp < NCIO_MINBLOCKSIZE || *sizehintp > NCIO_MAXBLOCKSIZE) { /* Use default */