コード例 #1
0
ファイル: tst_string_data.c プロジェクト: mmase/wgrib2
int
main(int argc, char **argv)
{
   int ncid;
   int dimid, varid;
   char name_in[NC_MAX_NAME+1];
   int class_in;
   size_t size_in;
   char *value_in;
   nc_type att_type;
   size_t att_len;

   int i;

   int var_dims[VAR4_RANK];
   const char *desc_data[DIM4_LEN] = {
       "first string", "second string", "third string", "", "last string"
   };
   const char *missing_val[ATT4_LEN] = {""};
   char *strings_in[DIM4_LEN];
   
#ifdef USE_PARALLEL
   MPI_Init(&argc, &argv);
#endif

#ifdef EXTRA_TESTS
   printf("*** creating strings test file %s...", FILE4_NAME);
   if (nc_create(FILE4_NAME, NC_CLOBBER | NC_NETCDF4, &ncid)) ERR;
   
   /* Declare a line dimension */
   if (nc_def_dim(ncid, DIM4_NAME, DIM4_LEN, &dimid)) ERR;
   
   /* Declare a string variable */
   var_dims[0] = dimid;
   if (nc_def_var(ncid, VAR4_NAME, NC_STRING, VAR4_RANK, var_dims, &varid)) ERR;
   
   /* Create and write a variable attribute of string type */
   if (nc_put_att_string(ncid, varid, ATT4_NAME, ATT4_LEN, missing_val)) ERR;
   if (nc_enddef(ncid)) ERR;
   
   /* Store some data of string type */
   if(nc_put_var(ncid, varid, desc_data)) ERR;
   
   /* Write the file. */
   if (nc_close(ncid)) ERR;
   
   /* Check it out. */
   if (nc_open(FILE4_NAME, NC_NOWRITE, &ncid)) ERR;
   if (nc_inq_varid(ncid, VAR4_NAME, &varid)) ERR;
   if (nc_inq_att(ncid, varid, ATT4_NAME, &att_type, &att_len)) ERR;
   if (att_type != NC_STRING || att_len != ATT4_LEN) ERR;
   if (nc_get_att_string(ncid, varid, ATT4_NAME, strings_in)) ERR;
   
   if (strcmp(strings_in[0], *missing_val) != 0) ERR;
   /* string atts should be explicitly freed when done with them */
   nc_free_string(ATT4_LEN, strings_in);
   
   if(nc_get_var_string(ncid, varid, strings_in)) ERR;
   for (i = 0; i < DIM4_LEN; i++) {
       if (strcmp(strings_in[i], desc_data[i]) != 0) ERR;
   }
   nc_free_string(DIM4_LEN, strings_in);

   /* Try reading strings in with typeless generic interface also */
   if(nc_get_var(ncid, varid, strings_in)) ERR;

   for (i = 0; i < DIM4_LEN; i++) {
       if (strcmp(strings_in[i], desc_data[i]) != 0) ERR;
   }
   nc_free_string(DIM4_LEN, strings_in);


   /* Try reading strings in with typeless generic array interface also */
   {
       size_t cor[VAR4_RANK], edg[VAR4_RANK];
       cor[0] = 0;
       edg[0] = DIM4_LEN;
       if(nc_get_vara(ncid, varid, cor, edg, strings_in)) ERR;

       for (i = 0; i < DIM4_LEN; i++) {
	   if (strcmp(strings_in[i], desc_data[i]) != 0) ERR;
       }
       nc_free_string(DIM4_LEN, strings_in);
   }

   if (nc_close(ncid)) ERR; 

   SUMMARIZE_ERR;
#endif /* EXTRA_TESTS */
   FINAL_RESULTS;
#ifdef USE_PARALLEL
   MPI_Finalize();
#endif   
}
コード例 #2
0
int
main(int argc, char **argv)
{
    printf("\n*** Testing netcdf-4 string type.\n");
    printf("*** testing string attribute...");
    {
#define ATT_LEN_1 1
#define MOUNTAIN_RANGE "mountain_range"
        size_t att_len;
        int ndims, nvars, natts, unlimdimid;
        nc_type att_type;
        int ncid, i;
        char *data_in[ATT_LEN_1] = {NULL};
        char *data[ATT_LEN_1] = {"R"};

        if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
        if (nc_put_att(ncid, NC_GLOBAL, MOUNTAIN_RANGE, NC_STRING, ATT_LEN_1, data)) ERR;
        if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
        if (ndims != 0 || nvars != 0 || natts != 1 || unlimdimid != -1) ERR;
        if (nc_inq_att(ncid, NC_GLOBAL, MOUNTAIN_RANGE, &att_type, &att_len)) ERR;
        if (att_type != NC_STRING || att_len != ATT_LEN_1) ERR;
        if (nc_close(ncid)) ERR;

        /* Check it out. */
        if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
        if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
        if (ndims != 0 || nvars != 0 || natts != 1 || unlimdimid != -1) ERR;
        if (nc_inq_att(ncid, NC_GLOBAL, MOUNTAIN_RANGE, &att_type, &att_len)) ERR;
        if (att_type != NC_STRING || att_len != ATT_LEN_1) ERR;
        if (nc_get_att(ncid, NC_GLOBAL, MOUNTAIN_RANGE, data_in)) ERR;
        for (i = 0; i < att_len; i++)
            if (strcmp(data_in[i], data[i])) ERR;
        if (nc_free_string(ATT_LEN_1, (char **)data_in)) ERR;
        if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;
    printf("*** testing string attribute...");
    {
#define ATT_LEN 9
        size_t att_len;
        int ndims, nvars, natts, unlimdimid;
        nc_type att_type;
        int ncid, i;
        char *data_in[ATT_LEN];
        char *data[ATT_LEN] = {"Let but your honour know",
                               "Whom I believe to be most strait in virtue",
                               "That, in the working of your own affections",
                               "Had time cohered with place or place with wishing",
                               "Or that the resolute acting of your blood",
                               "Could have attain'd the effect of your own purpose",
                               "Whether you had not sometime in your life",
                               "Err'd in this point which now you censure him",
                               "And pull'd the law upon you."
                              };

        if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
        if (nc_put_att(ncid, NC_GLOBAL, ATT_NAME, NC_STRING, ATT_LEN, data)) ERR;
        if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
        if (ndims != 0 || nvars != 0 || natts != 1 || unlimdimid != -1) ERR;
        if (nc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &att_type, &att_len)) ERR;
        if (att_type != NC_STRING || att_len != ATT_LEN) ERR;
        if (nc_close(ncid)) ERR;

        /* Check it out. */
        if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
        if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
        if (ndims != 0 || nvars != 0 || natts != 1 || unlimdimid != -1) ERR;
        if (nc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &att_type, &att_len)) ERR;
        if (att_type != NC_STRING || att_len != ATT_LEN) ERR;
        if (nc_get_att(ncid, NC_GLOBAL, ATT_NAME, data_in)) ERR;
        for (i = 0; i < att_len; i++)
            if (strcmp(data_in[i], data[i])) ERR;
        if (nc_free_string(att_len, (char **)data_in)) ERR;
        if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;
    printf("*** testing string var functions...");
    {
#define MOBY_LEN 16
        int ncid, varid, dimids[NDIMS];
        char *data[] = {"Perhaps a very little thought will now enable you to account for ",
                        "those repeated whaling disasters--some few of which are casually ",
                        "chronicled--of this man or that man being taken out of the boat by ",
                        "the line, and lost.",
                        "For, when the line is darting out, to be seated then in the boat, ",
                        "is like being seated in the midst of the manifold whizzings of a ",
                        "steam-engine in full play, when every flying beam, and shaft, and wheel, ",
                        "is grazing you.",
                        "It is worse; for you cannot sit motionless in the heart of these perils, ",
                        "because the boat is rocking like a cradle, and you are pitched one way and ",
                        "the other, without the slightest warning;",
                        "But why say more?",
                        "All men live enveloped in whale-lines.",
                        "All are born with halters round their necks; but it is only when caught ",
                        "in the swift, sudden turn of death, that mortals realize the silent, subtle, ",
                        "ever-present perils of life."
                       };
        char *data_in[MOBY_LEN];
        int i;

        if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
        if (nc_def_dim(ncid, DIM_NAME, MOBY_LEN, dimids)) ERR;
        if (nc_def_var(ncid, VAR_NAME, NC_STRING, NDIMS, dimids, &varid)) ERR;
        if (nc_put_var_string(ncid, varid, (const char **)data)) ERR;
        if (nc_close(ncid)) ERR;

        /* Check it out. */
        if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
        if (nc_get_var_string(ncid, varid, data_in)) ERR;
        for (i=0; i<MOBY_LEN; i++)
            if (strcmp(data_in[i], data[i])) ERR;
        if (nc_free_string(MOBY_LEN, (char **)data_in)) ERR;
        if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;
    printf("*** testing string attributes...");
    {
#define SOME_PRES 16
#define NDIMS_PRES 1
#define ATT2_NAME "presidents"

        int ncid, i;
        char *data[SOME_PRES] = {"Washington", "Adams", "Jefferson", "Madison",
                                 "Monroe", "Adams", "Jackson", "VanBuren",
                                 "Harrison", "Tyler", "Polk", "Tayor",
                                 "Fillmore", "Peirce", "Buchanan", "Lincoln"
                                };
        char *data_in[SOME_PRES];

        /* Create a file with string attribute. */
        if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
        if (nc_put_att_string(ncid, NC_GLOBAL, ATT2_NAME, SOME_PRES, (const char **)data)) ERR;
        if (nc_close(ncid)) ERR;

        /* Check it out. */
        if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
        if (nc_get_att_string(ncid, NC_GLOBAL, ATT2_NAME, (char **)data_in)) ERR;
        for (i=0; i < SOME_PRES; i++)
            if (strcmp(data_in[i], data[i])) ERR;

        /* Must free your data! */
        if (nc_free_string(SOME_PRES, (char **)data_in)) ERR;

        if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;
    printf("*** testing string fill value...");
    {
#define NUM_PRES 43
#define SOME_PRES 16
#define NDIMS_PRES 1
#define VAR_NAME_P "presidents"
        int ncid, varid, i, dimids[NDIMS_PRES];
        size_t start[NDIMS_PRES], count[NDIMS_PRES];
        char *data[SOME_PRES] = {"Washington", "Adams", "Jefferson", "Madison",
                                 "Monroe", "Adams", "Jackson", "VanBuren",
                                 "Harrison", "Tyler", "Polk", "Tayor",
                                 "Fillmore", "Peirce", "Buchanan", "Lincoln"
                                };
        char *data_in[NUM_PRES];

        /* Create a file with NUM_PRES strings, and write SOME_PRES of
         * them. */
        if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
        if (nc_def_dim(ncid, DIM_NAME, NUM_PRES, dimids)) ERR;
        if (nc_def_var(ncid, VAR_NAME_P, NC_STRING, NDIMS_PRES, dimids, &varid)) ERR;
        start[0] = 0;
        count[0] = SOME_PRES;
        if (nc_put_vara_string(ncid, varid, start, count, (const char **)data)) ERR;
        if (nc_close(ncid)) ERR;

        /* Check it out. */
        if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
        if (nc_get_var_string(ncid, varid, data_in)) ERR;
        for (i = 0; i < NUM_PRES; i++)
        {
            if (i < SOME_PRES && strcmp(data_in[i], data[i])) ERR;
            if (i >= SOME_PRES && strcmp(data_in[i], "")) ERR;
        }

        /* Must free your data! */
        if (nc_free_string(NUM_PRES, (char **)data_in)) ERR;

        if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;
    printf("*** testing long string variable...");
    {
#define VAR_NAME2 "empty"
#define ATT_NAME2 "empty"
#define DHR_LEN 30
#define DIM_NAME1 "article"
#define VAR_NAME1 "universal_declaration_of_human_rights"
        int var_dimids[NDIMS];
        int ndims, nvars, natts, unlimdimid;
        nc_type var_type;
        char var_name[NC_MAX_NAME + 1];
        int var_natts, var_ndims;
        int ncid, varid, i, dimids[NDIMS], varid2;
        char *data_in[DHR_LEN];
        char *data[DHR_LEN] = {
            "All human beings are born free and equal in dignity and rights. "
            "They are endowed with reason and "
            "conscience and should act towards one another in a "
            "spirit of brotherhood.",
            "Everyone is entitled to all the rights and freedoms set "
            "forth in this Declaration, without distinction of "
            "any kind, such as race, colour, sex, language, religion, "
            "political or other opinion, national or social "
            "origin, property, birth or other status. Furthermore, no "
            "distinction shall be made on the basis of the "
            "political, jurisdictional or international status of the "
            "country or territory to which a person belongs, "
            "whether it be independent, trust, non-self-governing or "
            "under any other limitation of sovereignty.",
            "Everyone has the right to life, liberty and security of person.",
            "No one shall be held in slavery or servitude; slavery and the "
            "slave trade shall be prohibited in all their forms.",
            "No one shall be subjected to torture or to cruel, "
            "inhuman or degrading treatment or punishment.",
            "Everyone has the right to recognition everywhere as "
            "a person before the law.",
            "All are equal before the law and are entitled without "
            "any discrimination to equal protection of the law. All are "
            "entitled to equal protection against any discrimination in "
            "violation of this Declaration and against any incitement "
            "to such discrimination.",
            "Everyone has the right to an effective remedy by the "
            "competent national tribunals for acts violating the "
            "fundamental rights granted "
            "him by the constitution or by law.",
            "No one shall be subjected to arbitrary arrest, detention or exile.",
            "Everyone is entitled in full equality to a fair and public "
            "hearing by an independent and impartial tribunal, in the "
            "determination of his rights and obligations and of any "
            "criminal charge against him.",
            "(1) Everyone charged with a penal offence has the right "
            "to be presumed innocent until proved guilty according to law in a "
            "public trial at which he has had all the guarantees "
            "necessary for his defence."
            "(2) No one shall be held guilty of any penal offence "
            "on account of any act or omission which did not constitute a penal "
            "offence, under national or international law, at the time "
            "when it was committed. Nor shall a heavier penalty be imposed "
            "than the one that was applicable at the time the penal "
            "offence was committed.",
            "No one shall be subjected to arbitrary interference with "
            "his privacy, family, home or correspondence, nor to attacks upon "
            "his honour and reputation. Everyone has the right to the "
            "protection of the law against such interference or attacks.",
            "(1) Everyone has the right to freedom of movement and "
            "residence within the borders of each state."
            "(2) Everyone has the right to leave any country, "
            "including his own, and to return to his country.",
            "(1) Everyone has the right to seek and to enjoy in "
            "other countries asylum from persecution. "
            "(2) This right may not be invoked in the case of prosecutions "
            "genuinely arising from non-political crimes or from acts "
            "contrary to the purposes and principles of the United Nations.",
            "(1) Everyone has the right to a nationality. (2) No one shall "
            "be arbitrarily deprived of his nationality nor denied the "
            "right to change his nationality.",
            "(1) Men and women of full age, without any limitation "
            "due to race, nationality or religion, have the right "
            "to marry and to found a family. "
            "They are entitled to equal rights as to marriage, "
            "during marriage and at its dissolution. (2) Marriage "
            "shall be entered into only with the free and full "
            "consent of the intending spouses. (3) The family is "
            "the natural and fundamental group unit of society and "
            "is entitled to protection by society and the State.",
            "(1) Everyone has the right to own property alone as "
            "well as in association with others. (2) No one shall "
            "be arbitrarily deprived of his property.",
            "Everyone has the right to freedom of thought, conscience "
            "and religion; this right includes freedom to change "
            "his religion or belief, and freedom, "
            "either alone or in community with others and in "
            "public or private, to manifest his religion or "
            "belief in teaching, practice, worship and observance.",
            "Everyone has the right to freedom of opinion and "
            "expression; this right includes freedom to hold "
            "opinions without interference and to seek, receive "
            "and impart information and ideas through any media "
            "and regardless of frontiers.",
            "(1) Everyone has the right to freedom of peaceful assembly "
            "and association. (2) No one may be compelled to belong to "
            "an association.",
            "(1) Everyone has the right to take part in the government "
            "of his country, directly or through freely chosen representatives. "
            "(2) Everyone has the right of equal access to public "
            "service in his country. (3) The will of the people "
            "shall be the basis of the authority of government; "
            "this will shall be expressed in periodic and genuine "
            "elections which shall be by universal and equal suffrage "
            "and shall be held by secret vote or by "
            "equivalent free voting procedures.",
            "Everyone, as a member of society, has the right to "
            "social security and is entitled to realization, "
            "through national effort and international co-operation "
            "and in accordance with the organization and resources of "
            "each State, of the economic, social and cultural rights "
            "indispensable for his dignity and the free "
            "development of his personality.",
            "(1) Everyone has the right to work, to free choice "
            "of employment, to just and favourable conditions of "
            "work and to protection against unemployment. "
            "(2) Everyone, without any discrimination, has the right "
            "to equal pay for equal work. (3) Everyone who works "
            "has the right to just and favourable "
            "remuneration ensuring for himself and his family an "
            "existence worthy of human dignity, and supplemented, "
            "if necessary, by other means of social protection."
            "(4) Everyone has the right to form and to join trade "
            "unions for the protection of his interests.",
            "Everyone has the right to rest and leisure, including "
            "reasonable limitation of working hours and periodic "
            "holidays with pay.",
            "(1) Everyone has the right to a standard of living "
            "adequate for the health and well-being of himself "
            "and of his family, including food, clothing, housing "
            "and medical care and necessary social services, and "
            "the right to security in the event of unemployment, "
            "sickness, disability, widowhood, old age or other lack "
            "of livelihood in circumstances beyond his control. "
            "(2) Motherhood and childhood are entitled to special "
            "care and assistance. All children, whether "
            "born in or out of wedlock, shall enjoy the same "
            "social protection.",
            "(1) Everyone has the right to education. Education "
            "shall be free, at least in the elementary and "
            "fundamental stages. Elementary education shall be compulsory. "
            "Technical and professional education shall be made generally "
            "available and higher education "
            "shall be equally accessible to all on the basis of merit. "
            "(2) Education shall be directed to the full development of "
            "the human personality and to the strengthening of respect for "
            "human rights and fundamental freedoms. "
            "It shall promote understanding, tolerance and friendship among "
            "all nations, racial or religious groups, and shall further the "
            "activities of the United Nations "
            "for the maintenance of peace. (3) Parents have a prior right to "
            "choose the kind of education that shall be given to their children.",
            "(1) Everyone has the right freely to participate in the cultural "
            "life of the community, to enjoy the arts and to share in scientific "
            "advancement and its benefits. "
            "(2) Everyone has the right to the protection of the moral "
            "and material interests resulting from any scientific, "
            "literary or artistic production of which he is the author.",
            "Everyone is entitled to a social and international order in "
            "which the rights and freedoms set forth in this Declaration "
            "can be fully realized.",
            "(1) Everyone has duties to the community in which alone "
            "the free and full development of his personality is possible. "
            "(2) In the exercise of his rights and "
            "freedoms, everyone shall be subject only to such limitations "
            "as are determined by law solely for the purpose "
            "of securing due recognition and respect for the rights "
            "and freedoms of others and of meeting the just requirements "
            "of morality, public order and the general welfare in a "
            "democratic society. (3) These rights and freedoms may in no "
            "case be exercised contrary to the purposes and "
            "principles of the United Nations.",
            "Nothing in this Declaration may be interpreted as implying "
            "for any State, group or person any right to engage in any "
            "activity or to perform any act aimed at the destruction of "
            "any of the rights and freedoms set forth herein."
        };
        char *empty_string[] = {""};

        if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

        /* Create an array of strings for the Universal Declaraion of Human Rights. */
        if (nc_def_dim(ncid, DIM_NAME1, DHR_LEN, dimids)) ERR;
        if (nc_def_var(ncid, VAR_NAME1, NC_STRING, NDIMS, dimids, &varid)) ERR;

        /* Create a scalar variable for the empty string. */
        if (nc_def_var(ncid, VAR_NAME2, NC_STRING, 0, NULL, &varid2)) ERR;

        /* Check some stuff. */
        if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
        if (ndims != NDIMS || nvars != 2 || natts != 0 || unlimdimid != -1) ERR;
        if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims,
                       var_dimids, &var_natts)) ERR;
        if (var_type != NC_STRING || strcmp(var_name, VAR_NAME1) || var_ndims != NDIMS ||
                var_dimids[0] != dimids[0]) ERR;

        /* Write the universal declaraion of human rights. */
        if (nc_put_var(ncid, varid, data)) ERR;

        /* Write an empty string with an empty attribute. */
        if (nc_put_var(ncid, varid2, empty_string)) ERR;
        if (nc_put_att(ncid, varid2, ATT_NAME2, NC_STRING, 0, empty_string)) ERR;

        /* Close the file. */
        if (nc_close(ncid)) ERR;

        /* Check it out. */
        if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
        if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
        if (ndims != NDIMS || nvars != 2 || natts != 0 || unlimdimid != -1) ERR;

        /* Check declaration. */
        if (nc_inq_varid(ncid, VAR_NAME1, &varid)) ERR;
        if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims,
                       var_dimids, &var_natts)) ERR;
        if (var_type != NC_STRING || strcmp(var_name, VAR_NAME1) || var_ndims != NDIMS ||
                var_dimids[0] != dimids[0]) ERR;
        if (nc_get_var(ncid, varid, data_in)) ERR;
        for (i = 0; i < DHR_LEN; i++)
            if (strcmp(data_in[i], data[i])) ERR;
        if (nc_free_string(DHR_LEN, data_in)) ERR;

        /* Check the empty var and att. */
        if (nc_inq_varid(ncid, VAR_NAME2, &varid)) ERR;
        if (nc_get_var(ncid, varid, data_in)) ERR;
        if (strcmp(data_in[0], empty_string[0])) ERR;
        if (nc_free_string(1, data_in)) ERR;
        if (nc_get_att(ncid, varid, ATT_NAME2, NULL)) ERR;
        if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;
    FINAL_RESULTS;
}
コード例 #3
0
ファイル: tst_strings.c プロジェクト: mmase/wgrib2
int
main(int argc, char **argv)
{
#ifdef USE_PARALLEL
   MPI_Init(&argc, &argv);
#endif

   printf("\n*** Testing netcdf-4 string type.\n");
   printf("*** testing string variable...");
   {
      int var_dimids[NDIMS];
      int ndims, nvars, natts, unlimdimid;
      nc_type var_type;
      char var_name[NC_MAX_NAME + 1];
      int var_natts, var_ndims;
      int ncid, varid, i, dimids[NDIMS];
      char *data_in[DIM_LEN];
      char *data[DIM_LEN] = {"Let but your honour know",
			     "Whom I believe to be most strait in virtue", 
			     "That, in the working of your own affections", 
			     "Had time cohered with place or place with wishing", 
			     "Or that the resolute acting of your blood",
			     "Could have attain'd the effect of your own purpose",
			     "Whether you had not sometime in your life",
			     "Err'd in this point which now you censure him", 
			     "And pull'd the law upon you."};
   
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM_NAME, DIM_LEN, dimids)) ERR;
      if (nc_def_var(ncid, VAR_NAME, NC_STRING, NDIMS, dimids, &varid)) ERR;
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
      if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims,
		     var_dimids, &var_natts)) ERR;
      if (var_type != NC_STRING || strcmp(var_name, VAR_NAME) || var_ndims != NDIMS ||
	  var_dimids[0] != dimids[0]) ERR;
      if (nc_put_var(ncid, varid, data)) ERR;
      if (nc_close(ncid)) ERR;
      
      /* Check it out. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
      if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims,
		     var_dimids, &var_natts)) ERR;
      if (var_type != NC_STRING || strcmp(var_name, VAR_NAME) || var_ndims != NDIMS ||
	  var_dimids[0] != dimids[0]) ERR;
      if (nc_get_var(ncid, varid, data_in)) ERR;
      for (i=0; i<DIM_LEN; i++)
	 if (strcmp(data_in[i], data[i])) ERR;
      for (i = 0; i < DIM_LEN; i++)
	 free(data_in[i]);
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** testing string attribute...");
   {
      
      size_t att_len;
      int ndims, nvars, natts, unlimdimid;
      nc_type att_type;
      int ncid, i;
      char *data_in[DIM_LEN];
      char *data[DIM_LEN] = {"Let but your honour know",
			     "Whom I believe to be most strait in virtue", 
			     "That, in the working of your own affections", 
			     "Had time cohered with place or place with wishing", 
			     "Or that the resolute acting of your blood",
			     "Could have attain'd the effect of your own purpose",
			     "Whether you had not sometime in your life",
			     "Err'd in this point which now you censure him", 
			     "And pull'd the law upon you."};
   

      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_put_att(ncid, NC_GLOBAL, ATT_NAME, NC_STRING, DIM_LEN, data)) ERR;
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != 0 || nvars != 0 || natts != 1 || unlimdimid != -1) ERR;
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &att_type, &att_len)) ERR;
      if (att_type != NC_STRING || att_len != DIM_LEN) ERR;
      if (nc_close(ncid)) ERR;
      
      /* Check it out. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != 0 || nvars != 0 || natts != 1 || unlimdimid != -1) ERR;
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &att_type, &att_len)) ERR;
      if (att_type != NC_STRING || att_len != DIM_LEN) ERR;
      if (nc_get_att(ncid, NC_GLOBAL, ATT_NAME, data_in)) ERR; 
      for (i = 0; i < att_len; i++)
	 if (strcmp(data_in[i], data[i])) ERR;
      if (nc_free_string(att_len, (char **)data_in)) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** testing string var functions...");

   {
#define MOBY_LEN 16
      int ncid, varid, i, dimids[NDIMS];
      char *data[] = {"Perhaps a very little thought will now enable you to account for ",
		      "those repeated whaling disasters--some few of which are casually ",
		      "chronicled--of this man or that man being taken out of the boat by ",
		      "the line, and lost.",
		      "For, when the line is darting out, to be seated then in the boat, ",
		      "is like being seated in the midst of the manifold whizzings of a ",
		      "steam-engine in full play, when every flying beam, and shaft, and wheel, ",
		      "is grazing you.",
		      "It is worse; for you cannot sit motionless in the heart of these perils, ",
		      "because the boat is rocking like a cradle, and you are pitched one way and ",
		      "the other, without the slightest warning;",
		      "But why say more?",
		      "All men live enveloped in whale-lines.",
		      "All are born with halters round their necks; but it is only when caught ",
		      "in the swift, sudden turn of death, that mortals realize the silent, subtle, ",
		      "ever-present perils of life."};
      char *data_in[MOBY_LEN];

      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM_NAME, MOBY_LEN, dimids)) ERR;
      if (nc_def_var(ncid, VAR_NAME, NC_STRING, NDIMS, dimids, &varid)) ERR;
      if (nc_put_var_string(ncid, varid, (const char **)data)) ERR;
      if (nc_close(ncid)) ERR;
      
      /* Check it out. */
     if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
     if (nc_get_var_string(ncid, varid, data_in)) ERR;
     for (i=0; i<MOBY_LEN; i++)
	if (strcmp(data_in[i], data[i])) ERR;
     if (nc_free_string(MOBY_LEN, (char **)data_in)) ERR;
     if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;

   printf("*** testing string attributes...");
   {
#define SOME_PRES 16
#define NDIMS_PRES 1
#define ATT2_NAME "presidents"

      int ncid, i;
      char *data[SOME_PRES] = {"Washington", "Adams", "Jefferson", "Madison",
			       "Monroe", "Adams", "Jackson", "VanBuren",
			       "Harrison", "Tyler", "Polk", "Tayor", 
			       "Fillmore", "Peirce", "Buchanan", "Lincoln"};
      char *data_in[SOME_PRES];

      /* Create a file with string attribute. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_put_att_string(ncid, NC_GLOBAL, ATT2_NAME, SOME_PRES, (const char **)data)) ERR;
      if (nc_close(ncid)) ERR;
      
      /* Check it out. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
      if (nc_get_att_string(ncid, NC_GLOBAL, ATT2_NAME, (char **)data_in)) ERR;
      for (i=0; i < SOME_PRES; i++)
	 if (strcmp(data_in[i], data[i])) ERR;
      
      /* Must free your data! */
      if (nc_free_string(SOME_PRES, (char **)data_in)) ERR;

      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** testing string fill value...");

   {
#define NUM_PRES 43
#define SOME_PRES 16
#define NDIMS_PRES 1

      int ncid, varid, i, dimids[NDIMS_PRES];
      size_t start[NDIMS_PRES], count[NDIMS_PRES];
      char *data[SOME_PRES] = {"Washington", "Adams", "Jefferson", "Madison",
			       "Monroe", "Adams", "Jackson", "VanBuren",
			       "Harrison", "Tyler", "Polk", "Tayor", 
			       "Fillmore", "Peirce", "Buchanan", "Lincoln"};
      char *data_in[NUM_PRES];

      /* Create a file with NUM_PRES strings, and write SOME_PRES of
       * them. */
      /*      nc_set_log_level(4);*/
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM_NAME, NUM_PRES, dimids)) ERR;
      if (nc_def_var(ncid, VAR_NAME, NC_STRING, NDIMS_PRES, dimids, &varid)) ERR;
      start[0] = 0;
      count[0] = SOME_PRES;
      if (nc_put_vara_string(ncid, varid, start, count, (const char **)data)) ERR;
      if (nc_close(ncid)) ERR;
      
      /* Check it out. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
      if (nc_get_var_string(ncid, varid, data_in)) ERR;
      for (i=0; i < NUM_PRES; i++)
      {
	 if (i < SOME_PRES && strcmp(data_in[i], data[i])) ERR;
	 if (i >= SOME_PRES && strcmp(data_in[i], "")) ERR;
      }
      
      /* Must free your data! */
      if (nc_free_string(SOME_PRES, (char **)data_in)) ERR;

      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   FINAL_RESULTS;
#ifdef USE_PARALLEL
   MPI_Finalize();
#endif   
}
コード例 #4
0
ファイル: tst_h_strbug.c プロジェクト: dschwen/libmesh
int
main()
{
    char *vs    = "variable-length string";
    char fsdata[]   = "fixed-length string";
    char *v1ddata[DIM1] = {"strings","of","variable","length"};
    int i;

    printf("\n*** Creating file for checking fix to bugs in accessing strings from HDF5 non-netcdf-4 file.\n");
    {
	hid_t fileid, scalar_spaceid, vstypeid, fstypeid, vsattid, fsattid, vsdsetid, fsdsetid;
	size_t type_size = FSTR_LEN;
	hid_t v1ddsetid;
	hid_t v1dspaceid;
	hsize_t dims[1] = {DIM1};

	if ((scalar_spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
	if ((v1dspaceid = H5Screate_simple(RANK, dims, NULL)) < 0) ERR;
	
	/* Create variable-length and fixed-length string types. */
	if ((vstypeid =  H5Tcopy(H5T_C_S1)) < 0) ERR;
	if (H5Tset_size(vstypeid, H5T_VARIABLE) < 0) ERR;
	
	if ((fstypeid =  H5Tcopy(H5T_C_S1)) < 0) ERR;
	if (H5Tset_size(fstypeid, type_size) < 0) ERR;

	/* Create new file, using default properties. */
	if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
	
	/* Create scalar datasets of variable- and fixed-length strings. */
	if ((vsdsetid = H5Dcreate (fileid, VS_VAR_NAME, vstypeid, scalar_spaceid, 
				   H5P_DEFAULT)) < 0) ERR;
	if (H5Dwrite (vsdsetid, vstypeid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &vs)) ERR;
	if ((fsdsetid = H5Dcreate (fileid, FS_VAR_NAME, fstypeid, scalar_spaceid, 
				   H5P_DEFAULT)) < 0) ERR;
	if (H5Dwrite (fsdsetid, fstypeid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &fsdata)) ERR;

	/* Create 1D dataset of variable-length strings. */
	if ((v1ddsetid = H5Dcreate (fileid, V1D_VAR_NAME, vstypeid, v1dspaceid, 
				   H5P_DEFAULT)) < 0) ERR;
	if (H5Dwrite (v1ddsetid, vstypeid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &v1ddata)) ERR;
	
	/* Write scalar global attributes of these types. */
	if ((vsattid = H5Acreate(fileid, VS_ATT_NAME, vstypeid, scalar_spaceid, 
				 H5P_DEFAULT)) < 0) ERR;
	if (H5Awrite(vsattid, vstypeid, &vs) < 0) ERR;
	if ((fsattid = H5Acreate(fileid, FS_ATT_NAME, fstypeid, scalar_spaceid, 
				 H5P_DEFAULT)) < 0) ERR;
	if (H5Awrite(fsattid, fstypeid, &fsdata) < 0) ERR;
	
	/* Close up. */
	if (H5Aclose(vsattid) < 0) ERR;
	if (H5Aclose(fsattid) < 0) ERR;
	if (H5Sclose(scalar_spaceid) < 0) ERR;
	if (H5Sclose(v1dspaceid) < 0) ERR;
	if (H5Tclose(vstypeid) < 0) ERR;
	if (H5Tclose(fstypeid) < 0) ERR;
	if (H5Dclose(vsdsetid) < 0) ERR;
	if (H5Dclose(fsdsetid) < 0) ERR;
	if (H5Dclose(v1ddsetid) < 0) ERR;
	if (H5Fclose(fileid) < 0) ERR;
    }

    printf("*** Checking reading variable-length HDF5 string var through netCDF-4 API...");
    {
	int ncid, varid, ndims;
	nc_type type;
	char *data_in;
	if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
	if (nc_inq_varid(ncid, VS_VAR_NAME, &varid)) ERR;
	if (nc_inq_vartype(ncid, varid, &type)) ERR;
	if (type != NC_STRING) ERR;
	if (nc_inq_varndims(ncid, varid, &ndims )) ERR;
	if (ndims != 0) ERR;
	if (nc_get_var_string(ncid, varid, &data_in)) ERR;
	if (strcmp(vs, data_in)) ERR;
	if (nc_free_string(1, &data_in)) ERR;
	if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;

    printf("*** Checking reading fixed-length HDF5 string var through netCDF-4 API...");
    {
    	int ncid, varid, ndims;
    	nc_type type;
    	char *data_in;
    	if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
    	if (nc_inq_varid(ncid, FS_VAR_NAME, &varid)) ERR;
    	if (nc_inq_vartype(ncid, varid, &type)) ERR;
    	if (type != NC_STRING) ERR;
    	if (nc_inq_varndims(ncid, varid, &ndims )) ERR;
    	if (ndims != 0) ERR;
    	if (nc_get_var_string(ncid, varid, &data_in)) ERR;
    	if (strcmp(fsdata, data_in)) ERR;
	if (nc_free_string(1, &data_in)) ERR;
    	if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;

    printf("*** Checking reading variable-length HDF5 string att through netCDF-4 API...");
    {
	int ncid;
	nc_type type;
	size_t len;
	char *data_in;
	if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
	if (nc_inq_att(ncid, NC_GLOBAL, VS_ATT_NAME, &type, &len)) ERR;
	if (type != NC_STRING) ERR;
	if (len != 1) ERR;
        if (nc_get_att_string(ncid, NC_GLOBAL, VS_ATT_NAME, &data_in)) ERR;
	if (strcmp(vs, data_in)) ERR;
	if (nc_free_string(1, &data_in)) ERR;
	if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;

    printf("*** Checking reading fixed-length HDF5 string att through netCDF-4 API...");
    {
	int ncid;
	nc_type type;
	size_t len;
	char *data_in;
	if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
	if (nc_inq_att(ncid, NC_GLOBAL, FS_ATT_NAME, &type, &len)) ERR;
	if (type != NC_CHAR) ERR;
	if (len != FSTR_LEN) ERR;
	if (!(data_in = malloc(len))) ERR;
        /* if (nc_get_att_string(ncid, NC_GLOBAL, FS_ATT_NAME, &data_in)) ERR; */
        if (nc_get_att_text(ncid, NC_GLOBAL, FS_ATT_NAME, data_in)) ERR;
	if (strcmp(fsdata, data_in)) ERR;
	free(data_in);
	if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;

    printf("*** Checking reading variable-length HDF5 strings var through netCDF-4 API...");
    {
    	int ncid, varid, ndims;
    	nc_type type;
	int *dimids;
	size_t nstrings;
    	char **data_in;
    	if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
    	if (nc_inq_varid(ncid, V1D_VAR_NAME, &varid)) ERR;
    	if (nc_inq_vartype(ncid, varid, &type)) ERR;
    	if (type != NC_STRING) ERR;
    	if (nc_inq_varndims(ncid, varid, &ndims )) ERR;
    	if (ndims != RANK) ERR;
	if (!(dimids = malloc(ndims * sizeof(int)))) ERR;
    	if (nc_inq_vardimid(ncid, varid, dimids)) ERR;
	if (nc_inq_dimlen(ncid, dimids[0], &nstrings)) ERR;
	if (!(data_in = (char **)malloc(nstrings * sizeof(char *)))) ERR;
    	if (nc_get_var_string(ncid, varid, data_in)) ERR;
	for (i = 0; i < nstrings; i++) {
	    if(strcmp(v1ddata[i], data_in[i])) ERR;
	}
    	if (nc_free_string(nstrings, data_in)) ERR;
	free(data_in);
	free(dimids);
    	if (nc_close(ncid)) ERR;
    }
    SUMMARIZE_ERR;
    FINAL_RESULTS;
}
コード例 #5
0
ファイル: tst_fills.c プロジェクト: Federico2014/edg4x-rose
int
main(int argc, char **argv) 
{			/* create tst_classic_fills.nc */
   printf("\n*** Testing fill values.\n");
   printf("*** testing empty fill values of a string var...");
   {
#define STRING_VAR_NAME "The_String"
#define NDIMS_STRING 1
#define FILLVALUE_LEN 1 /* There is 1 string, the empty one. */
#define DATA_START 2 /* Real data here. */

      int  ncid, varid, dimid, varid_in;
      const char *missing_val[FILLVALUE_LEN] = {""};
      const char *missing_val_in[FILLVALUE_LEN];
      const char *data_out[1] = {"The evil that men do lives after them; "
				 "the good is oft interred with their bones."};
      char **data_in;
      size_t index = DATA_START;
      int i;

      /* Create file with a 1D string var. Set its fill value to the
       * empty string. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, "rec", NC_UNLIMITED, &dimid)) ERR;
      if (nc_def_var(ncid, STRING_VAR_NAME, NC_STRING, NDIMS_STRING, &dimid, &varid)) ERR;
      if (nc_put_att_string(ncid, varid, "_FillValue", FILLVALUE_LEN, missing_val)) ERR;

      /* Check it out. */
      if (nc_inq_varid(ncid, STRING_VAR_NAME, &varid_in)) ERR;
      if (nc_get_att_string(ncid, varid_in, "_FillValue", (char **)missing_val_in)) ERR;
      if (strcmp(missing_val[0], missing_val_in[0])) ERR;
      if (nc_free_string(FILLVALUE_LEN, (char **)missing_val_in)) ERR;

      /* Write one string, leaving some blank records which will then
       * get the fill value. */
      if (nc_put_var1_string(ncid, varid_in, &index, data_out)) ERR;

      /* Get all the data from the variable. */
      if (!(data_in = malloc((DATA_START + 1) * sizeof(char *)))) ERR;
      if (nc_get_var_string(ncid, varid_in, data_in)) ERR;

      /* First there should be fill values, then the data value we
       * wrote. */
      for (i = 0; i < DATA_START; i++)
	 if (strcmp(data_in[i], "")) ERR;
      if (strcmp(data_in[DATA_START], data_out[0])) ERR;

      /* Close everything up. */
      if (nc_close(ncid)) ERR;

      /* Now re-open file, read data, and check values again. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
      if (nc_inq_varid(ncid, STRING_VAR_NAME, &varid_in)) ERR;
      if (nc_get_att_string(ncid, varid_in, "_FillValue", (char **)missing_val_in)) ERR;
      if (strcmp(missing_val[0], missing_val_in[0])) ERR;
      if (nc_free_string(FILLVALUE_LEN, (char **)missing_val_in)) ERR;
      if (nc_close(ncid)) ERR;
      free(data_in);
   }

   SUMMARIZE_ERR;
   printf("*** testing non-empty fill values of a string var...");
   {
#define STRING_VAR_NAME2 "CASSIUS"
#define FILLVALUE_LEN2 1 /* There is 1 string in the fillvalue array. */
#define DATA_START2 9 /* Real data starts here. */

      int  ncid, varid, dimid, varid_in;
      const char *missing_val[FILLVALUE_LEN2] = {"I know that virtue to be in you, Brutus"};
      const char *missing_val_in[FILLVALUE_LEN2];
      const char *data_out[1] = {"The evil that men do lives after them; "
				 "the good is oft interred with their bones."};
      char **data_in;
      size_t index = DATA_START2;
      int i;

      /* Create file with a 1D string var. Set its fill value to the
       * a non-empty string. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, "rec", NC_UNLIMITED, &dimid)) ERR;
      if (nc_def_var(ncid, STRING_VAR_NAME2, NC_STRING, NDIMS_STRING, &dimid, &varid)) ERR;
      if (nc_put_att_string(ncid, varid, "_FillValue", FILLVALUE_LEN2, missing_val)) ERR;

      /* Check it out. */
      if (nc_inq_varid(ncid, STRING_VAR_NAME2, &varid_in)) ERR;
      if (nc_get_att_string(ncid, varid_in, "_FillValue", (char **)missing_val_in)) ERR;
      if (strcmp(missing_val[0], missing_val_in[0])) ERR;
      if (nc_free_string(FILLVALUE_LEN2, (char **)missing_val_in)) ERR;

      /* Write one string, leaving some blank records which will then
       * get the fill value. */
      if (nc_put_var1_string(ncid, varid_in, &index, data_out)) ERR;

      /* Get all the data from the variable. */
      if (!(data_in = malloc((DATA_START2 + 1) * sizeof(char *)))) ERR;
      if (nc_get_var_string(ncid, varid_in, data_in)) ERR;

      /* First there should be fill values, then the data value we
       * wrote. */
      for (i = 0; i < DATA_START2; i++)
	 if (strcmp(data_in[i], missing_val[0])) ERR;
      if (strcmp(data_in[DATA_START2], data_out[0])) ERR;

      /* Close everything up. */
      if (nc_close(ncid)) ERR;

      /* Now re-open file, read data, and check values again. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
      if (nc_inq_varid(ncid, STRING_VAR_NAME2, &varid_in)) ERR;
      if (nc_get_att_string(ncid, varid_in, "_FillValue", (char **)missing_val_in)) ERR;
      if (strcmp(missing_val[0], missing_val_in[0])) ERR;
      if (nc_free_string(FILLVALUE_LEN2, (char **)missing_val_in)) ERR;
      if (nc_close(ncid)) ERR;
      free(data_in);
   }

   SUMMARIZE_ERR;
   printf("*** testing fill values of one var...");
   {
#define V1_NAME "v1"
#define MAX_VALS 10
      int  ncid, varid, rec_id, dims[2];
      static int rec[1] = {1};
      size_t start[2] = {0, 0};
      size_t count[2] = {1, MAX_VALS};
      char vals[MAX_VALS];
      int i;

      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

      /* Define dimensions and two vars, a 1D coordinate var for
       * unlimited dimension, and a 2D var which uses the unlimited
       * dimension. */
      if (nc_def_dim(ncid, "rec", NC_UNLIMITED, &dims[0])) ERR;
      if (nc_def_dim(ncid, "len", MAX_VALS, &dims[1])) ERR;
      if (nc_def_var(ncid, "rec", NC_INT, 1, dims, &rec_id)) ERR;
      if (nc_def_var(ncid, V1_NAME, NC_CHAR, 2, dims, &varid)) ERR;

      /* Extend record dimension by 1. */
      if (nc_put_vara_int(ncid, rec_id, start, count, rec)) ERR;

      /* Read the other variable; it must have only fill values. */
      if (nc_get_vara_text(ncid, 1, start, count, vals)) ERR;
      for (i = 0; i < MAX_VALS; i++)
	 if(vals[i] != NC_FILL_CHAR) ERR;

      if (nc_close(ncid)) ERR;

      /* Now re-open file, read data, and check values again. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      /* Read the other variable; it must have only fill values. */
      if (nc_get_vara_text(ncid, 1, start, count, vals)) ERR;
      for (i = 0; i < MAX_VALS; i++)
	 if(vals[i] != NC_FILL_CHAR) ERR;

      if(nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** testing fill values of lots of vars...");

   {
      int  ncid;			/* netCDF id */

#define NVALS 10		/* values per fixed-size variable or record */
#define NFIXVARS 6		/* number of fixed-size vars, one of each type */
#define NRECVARS 6		/* number of record vars, one of each type */
#define RANK_REC 1
#define RANK_FIXVARS 1
#define RANK_RECVARS 2

      /* dimension ids */
      int rec_dim;
      int len_dim;

      /* dimension lengths */
      size_t rec_len = NC_UNLIMITED;
      size_t len_len = NVALS;

      /* variable ids */
      int rec_id;
      int fixvar_ids[NFIXVARS];
      int recvar_ids[NRECVARS];
      int rec_dims[RANK_REC];
      int fixvar_dims[RANK_FIXVARS];
      int recvar_dims[RANK_RECVARS];
      int fixvar, recvar, i;

      char *fnames[] = {"c", "b", "s", "i", "f", "d"};
      char *rnames[] = {"cr", "br", "sr", "ir", "fr", "dr"};
      nc_type types[] = {NC_CHAR, NC_BYTE, NC_SHORT, NC_INT, NC_FLOAT, NC_DOUBLE};

      /*if (nc_set_default_format(format + 1, NULL)) ERR;*/
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

      /* define dimensions */
      if (nc_def_dim(ncid, "rec", rec_len, &rec_dim)) ERR;
      if (nc_def_dim(ncid, "len", len_len, &len_dim)) ERR;

      rec_dims[0] = rec_dim;
      if (nc_def_var(ncid, "rec", NC_INT, RANK_REC, rec_dims, &rec_id)) ERR;

      /* define fixed and record variables of all 6 primitive types */
      fixvar_dims[0] = len_dim;
      for (fixvar = 0; fixvar < NFIXVARS; fixvar++)
	 if (nc_def_var(ncid, fnames[fixvar], types[fixvar], RANK_FIXVARS,
			fixvar_dims, &fixvar_ids[fixvar])) ERR;

      recvar_dims[0] = rec_dim;
      recvar_dims[1] = len_dim;
      for (recvar = 0; recvar < NRECVARS; recvar++)
	 if (nc_def_var(ncid, rnames[recvar], types[recvar], RANK_RECVARS,
			recvar_dims, &recvar_ids[recvar])) ERR;

      /* leave define mode */
      if (nc_enddef(ncid)) ERR;

      {			/* store rec */
	 static size_t rec_start[RANK_REC];
	 static size_t rec_count[RANK_REC];
	 static int rec[] = {1};
	 rec_len = 1;			/* number of records of rec data */
	 rec_start[0] = 0;
	 rec_count[0] = rec_len;
	 if (nc_put_vara_int(ncid, rec_id, rec_start, rec_count, rec)) ERR;
      }
      if (nc_close(ncid)) ERR;

      /* Now re-open file, read data, and check values */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      /* Check that fixed-size variables are full of fill values */
      for (fixvar = 0; fixvar < NFIXVARS; fixvar++) {
	 int varid;
	 nc_type type;

	 if (nc_inq_varid(ncid, fnames[fixvar], &varid)) ERR;
	 if (nc_inq_vartype(ncid, varid, &type)) ERR;
	 switch(type) {
	    case NC_CHAR:
	    {
	       char vals[NVALS];
	       if (nc_get_var_text(ncid, varid, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_CHAR) ERR;
	    }
	    break;
	    case NC_BYTE:
	    {
	       signed char vals[NVALS];
	       if (nc_get_var_schar(ncid, varid, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_BYTE) ERR;
	    }
	    break;
	    case NC_SHORT:
	    {
	       short vals[NVALS];
	       if (nc_get_var_short(ncid, varid, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_SHORT) ERR;
	    }
	    break;
	    case NC_INT:
	    {
	       int vals[NVALS];
	       if (nc_get_var_int(ncid, varid, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_INT) ERR;
	    }
	    break;
	    case NC_FLOAT:
	    {
	       float vals[NVALS];
	       if (nc_get_var_float(ncid, varid, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_FLOAT) ERR;
	    }
	    break;
	    case NC_DOUBLE:
	    {
	       double vals[NVALS];
	       if (nc_get_var_double(ncid, varid, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if (vals[i] != NC_FILL_DOUBLE) ERR;
	    }
	    break;
	    default:
	       ERR;
	 }
      }

      /* Read record, check record variables have only fill values */
      for (recvar = 0; recvar < NRECVARS; recvar++) {
	 int varid;
	 nc_type type;
	 size_t start[] = {0, 0};
	 size_t count[] = {1, NVALS};

	 if (nc_inq_varid(ncid, rnames[recvar], &varid)) ERR;
	 if (nc_inq_vartype(ncid, varid, &type)) ERR;
	 switch(type) {
	    case NC_CHAR:
	    {
	       char vals[NVALS];
	       if (nc_get_vara_text(ncid, varid, start, count, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_CHAR) ERR;
	    }
	    break;
	    case NC_BYTE:
	    {
	       signed char vals[NVALS];
	       if (nc_get_vara_schar(ncid, varid, start, count, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_BYTE) ERR;
	    }
	    break;
	    case NC_SHORT:
	    {
	       short vals[NVALS];
	       if (nc_get_vara_short(ncid, varid, start, count, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_SHORT) ERR;
	    }
	    break;
	    case NC_INT:
	    {
	       int vals[NVALS];
	       if (nc_get_vara_int(ncid, varid, start, count, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_INT) ERR;
	    }
	    break;
	    case NC_FLOAT:
	    {
	       float vals[NVALS];
	       if (nc_get_vara_float(ncid, varid, start, count, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_FLOAT) ERR;
	    }
	    break;
	    case NC_DOUBLE:
	    {
	       double vals[NVALS];
	       if (nc_get_vara_double(ncid, varid, start, count, vals)) ERR;
	       for (i = 0; i < NVALS; i++)
		  if(vals[i] != NC_FILL_DOUBLE) ERR;
	    }
	    break;
	    default:
	       ERR;
	 }
      }

      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   FINAL_RESULTS;

   return 0;
}