Patch for netcdf-3.4/src to remove restrictive name checking ================================== This patch is for the 3 files libsrc/string.c nc_test/test_write.c nf_test/test_write.F It removes the current checking for valid characters in names of variables, dimensions, and attributes, to make sure such names are consistent with the CDL name restrictions that permit only alphanumeric characters and `_', `-', and `.' in names. If you apply this patch, you will be able to create netCDF files for which the ncgen utility will no longer work on the CDL output from ncdump. To apply, invoke the following command from the netcdf-3.4/src/ directory, where you should replace PATCHFILE by the name for this file: patch < PATCHFILE Then rebuild with "make all". Test with "make test". Install with "make install". Index: libsrc/string.c =================================================================== RCS file: /upc/share/CVS/netcdf-3/libsrc/string.c,v retrieving revision 1.57 diff -c -r1.57 string.c *** 1.57 1997/09/02 18:27:32 --- string.c 1998/04/28 22:24:15 *************** *** 28,56 **** /* ! * Verify that a name string is valid * CDL syntax, eg, all the characters are * alphanumeric, '-', '_', or '.'. */ int NC_check_name(const char *name) { - const char *cp = name; assert(name != NULL); if(*name == 0) return NC_EBADNAME; /* empty names disallowed */ ! for(; *cp != 0; cp++) ! { ! int ch = *cp; ! if(!isalnum(ch)) ! { ! if(ch != '_' && ch != '-' && ch != '.') ! return NC_EBADNAME; ! } ! } ! if(cp - name > NC_MAX_NAME) return NC_EMAXNAME; return NC_NOERR; --- 28,47 ---- /* ! * Modified to relax the ! * verification that a name string is valid * CDL syntax, eg, all the characters are * alphanumeric, '-', '_', or '.'. */ int NC_check_name(const char *name) { assert(name != NULL); if(*name == 0) return NC_EBADNAME; /* empty names disallowed */ ! if(strlen(name) + 1 > NC_MAX_NAME) return NC_EMAXNAME; return NC_NOERR; Index: nc_test/test_write.c =================================================================== RCS file: /upc/share/CVS/netcdf-3/nc_test/test_write.c,v retrieving revision 1.19 diff -c -r1.19 test_write.c *** 1.19 1997/10/17 18:21:44 --- test_write.c 1998/04/28 22:26:12 *************** *** 461,469 **** err = nc_def_dim(ncid, dim_name[i-1], dim_len[i], &dimid); IF (err != NC_ENAMEINUSE) error("duplicate name: status = %d", err); - err = nc_def_dim(ncid, BAD_NAME, dim_len[i], &dimid); - IF (err != NC_EBADNAME) - error("bad name: status = %d", err); err = nc_def_dim(ncid, dim_name[i], NC_UNLIMITED-1, &dimid); IF (err != NC_EINVAL) error("bad size: status = %d", err); --- 461,466 ---- *************** *** 590,598 **** error("Unexpected datatype"); IF (ndims != 0) error("Unexpected rank"); - err = nc_def_var(ncid, BAD_NAME, NC_SHORT, 0, NULL, &varid); - IF (err != NC_EBADNAME) - error("bad name: status = %d", err); err = nc_def_var(ncid, "abc", NC_SHORT, 0, NULL, &varid); IF (err != NC_ENAMEINUSE) error("duplicate name: status = %d", err); --- 587,592 ---- *************** *** 1273,1281 **** err = nc_put_att(BAD_ID, varid, name, datatype, length, buf); IF (err != NC_EBADID) error("bad ncid: status = %d", err); - err = nc_put_att(ncid, varid, BAD_NAME, datatype, length, buf); - IF (err != NC_EBADNAME) - error("bad name: status = %d", err); err = nc_put_att(ncid, BAD_VARID, name, datatype, length, buf); IF (err != NC_ENOTVAR) error("bad var id: status = %d", err); --- 1267,1272 ---- Index: nf_test/test_write.F =================================================================== RCS file: /upc/share/CVS/netcdf-3/nf_test/test_write.F,v retrieving revision 1.7 diff -c -r1.7 test_write.F *** 1.7 1997/06/11 19:38:01 --- test_write.F 1998/04/28 22:27:30 *************** *** 453,461 **** + dimid) if (err .ne. NF_ENAMEINUSE) + call errore('duplicate name: ', err) - err = nf_def_dim(ncid, BAD_NAME, dim_len(i), dimid) - if (err .ne. NF_EBADNAME) - + call errore('bad name: ', err) err = nf_def_dim(ncid, dim_name(i), NF_UNLIMITED-1, + dimid) if (err .ne. NF_EINVAL) --- 453,458 ---- *************** *** 582,590 **** + call error('Unexpected datatype') if (ndims .ne. 0) + call error('Unexpected rank') - err = nf_def_var(ncid, BAD_NAME, NF_SHORT, 0, dimids, vid) - if (err .ne. NF_EBADNAME) - + call errore('bad name: ', err) err = nf_def_var(ncid, 'abc', NF_SHORT, 0, dimids, vid) if (err .ne. NF_ENAMEINUSE) + call errore('duplicate name: ', err) --- 579,584 ----