示例#1
0
文件: cfio.c 项目: CFIO/CFIO
int cfio_put_vara_int(
	int ncid, int varid, int dim,
	size_t *start, size_t *count, int *fp)
{
    if(start == NULL || count == NULL || fp == NULL)
    {
	error("args should not be NULL.");
	return CFIO_ERROR_ARG_NULL;
    }

    cfio_msg_t *msg;

	//times_start();
    debug(DEBUG_CFIO, "start :(%lu, %lu), count :(%lu, %lu)", 
	    start[0], start[1], count[0], count[1]);

    //head_size = 6 * sizeof(int) + 2 * dim * sizeof(size_t);

    //_put_vara(io_proc_id, ncid, varid, dim,
    //        start, count, CFIO_DOUBLE, fp, head_size, dim - 1);
    cfio_send_put_vara(ncid, varid, dim, 
	    start, count, CFIO_INT, fp);

    debug_mark(DEBUG_CFIO);

	//debug(DEBUG_TIME, "%f ms", times_end());

    return CFIO_ERROR_NONE;
}
示例#2
0
文件: cfio.c 项目: hxmhuang/CFIO2
int cfio_put_vara_text(
        int ncid, int varid, int dim,
        size_t *start, size_t *count, char *fp)
{
    if(start == NULL || count == NULL || fp == NULL)
    {
        error("args should not be NULL.");
        return CFIO_ERROR_ARG_NULL;
    }

    cfio_send_put_vara(ncid, varid, dim,
            start, count, CFIO_CHAR, fp);

    debug_mark(DEBUG_CFIO);

    return CFIO_ERROR_NONE;
}
示例#3
0
文件: cfio.c 项目: hxmhuang/CFIO2
int cfio_put_vara_double(
        int ncid, int varid, int dim,
        size_t *start, size_t *count, double *fp)
{
    if(start == NULL || count == NULL || fp == NULL)
    {
        error("args should not be NULL.");
        return CFIO_ERROR_ARG_NULL;
    }

    cfio_msg_t *msg;

    debug(DEBUG_CFIO, "start :(%lu, %lu), count :(%lu, %lu)", 
            start[0], start[1], count[0], count[1]);

    cfio_send_put_vara(ncid, varid, dim, 
            start, count, CFIO_DOUBLE, fp);

    debug_mark(DEBUG_CFIO);

    return CFIO_ERROR_NONE;
}
示例#4
0
文件: func_test.c 项目: hxmhuang/CFIO
int main(int argc, char** argv)
{
    int rank, size;
    char *path = "test";
    int ncidp;
    int dim1,var1,i;

    size_t len = 10;
    char *test="test";
    MPI_Comm comm = MPI_COMM_WORLD;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &size);

    //assert(size == LAT_PROC * LON_PROC);
    //set_debug_mask(DEBUG_IO); 
    size_t start[2],count[2];
    start[0] = (rank % LAT_PROC) * (LAT / LAT_PROC);
    start[1] = (rank / LAT_PROC) * (LON / LON_PROC);
    count[0] = LAT / LAT_PROC;
    count[1] = LON / LON_PROC;
    float *fp = malloc(count[0] * count[1] *sizeof(float));

    for( i = 0; i< count[0] * count[1]; i++)
    {
	fp[i] = i + rank * count[0] * count[1];
    }


    cfio_init( LAT_PROC, LON_PROC, ratio);
    CFIO_START();

    char fileName[100];
    memset(fileName, 0, sizeof(fileName));
    sprintf(fileName,"%s.nc",path);
    int dimids[2];
    cfio_create(fileName, 0, &ncidp);
    debug_mark(DEBUG_USER);
    int lat = LAT;
    cfio_def_dim(ncidp, "lat", LAT,&dimids[0]);
    cfio_def_dim(ncidp, "lon", LON,&dimids[1]);
    cfio_def_dim(ncidp, "lat", LAT,&dimids[0]);

    int a = 3;
    double b= 4.0;
    cfio_put_att(ncidp, NC_GLOBAL, "test", CFIO_INT, 1, &a);
    cfio_put_att(ncidp, NC_GLOBAL, "test", CFIO_FLOAT, 1, &b);

    cfio_def_var(ncidp,"time_v", CFIO_FLOAT, 2, dimids, start, count, &var1);
    cfio_put_att(ncidp, var1, "test", CFIO_CHAR, strlen(test), test);
    cfio_enddef(ncidp);
    cfio_put_vara_float(ncidp,var1, 2,start, count,fp); 

    cfio_close(ncidp);
    cfio_io_end();
    free(fp);

    CFIO_END();
    cfio_finalize();
    MPI_Finalize();
    return 0;
}