diff --git a/VERSION b/VERSION index 1376da5e..caf43a00 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.3.449 +8.3.450 diff --git a/calma/CalmaRead.c b/calma/CalmaRead.c index 796ad013..d8db3fdf 100644 --- a/calma/CalmaRead.c +++ b/calma/CalmaRead.c @@ -114,8 +114,6 @@ extern bool CalmaDoLibrary; /* Also used by GDS write */ extern void calmaUnexpected(); extern int calmaWriteInitFunc(); -bool calmaParseUnits(); - /* * Scaling. * Multiply all coordinates by calmaReadScale1, then divide them @@ -351,6 +349,7 @@ calmaParseUnits() double metersPerDBUnit; double userUnitsPerDBUnit; double cuPerDBUnit; + bool compatible; READRH(nbytes, rtype); #ifdef lint @@ -369,6 +368,39 @@ calmaParseUnits() /* Read meters per database unit */ if (!calmaReadR8(&metersPerDBUnit)) return (FALSE); + /* Important! When CalmaReadOnly is TRUE, then this file will have its + * contents output verbatim. But if the database units don't match, + * then it will get output at the wrong scale. Setting a magnification + * factor on the instance when generating output might (?) work. For + * now, prohibiting a GDS read in read-only mode when the database units + * don't match. This forces the user either to reconsider the read-only + * status or to rewrite the GDS at a compatible scalefactor. + */ + compatible = TRUE; + if (CalmaReadOnly == TRUE) + { + if (CIFCurStyle->cs_flags & CWF_ANGSTROMS) + { + if ((int)(0.5 + metersPerDBUnit * 1e12) != 100) + { + CalmaReadError("Incompatible scale factor of %g, must be 1e-10.\n", + metersPerDBUnit); + TxError("Cannot read this file in read-only mode.\n"); + return FALSE; + } + } + else + { + if ((int)(0.5 + metersPerDBUnit * 1e11) != 100) + { + CalmaReadError("Incompatible scale factor of %g, must be 1e-9.\n", + metersPerDBUnit); + TxError("Cannot read this file in read-only mode.\n"); + return FALSE; + } + } + } + #ifdef notdef TxPrintf("1 database unit equals %e user units\n", userUnitsPerDBUnit); TxPrintf("1 database unit equals %e meters\n", metersPerDBUnit); diff --git a/calma/CalmaWrite.c b/calma/CalmaWrite.c index a1a2d931..70e027a8 100644 --- a/calma/CalmaWrite.c +++ b/calma/CalmaWrite.c @@ -706,7 +706,7 @@ calmaFullDump(def, fi, outf, filename) static int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS, CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE, - CALMA_STYPTABLE, CALMA_GENERATIONS, CALMA_UNITS, -1 }; + CALMA_STYPTABLE, CALMA_GENERATIONS, -1 }; static int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME, CALMA_LIBSECUR, -1 }; @@ -722,11 +722,17 @@ calmaFullDump(def, fi, outf, filename) calmaSkipSet(skipBeforeLib); if (!calmaReadStringRecord(CALMA_LIBNAME, &libname)) goto done; - // NOTE: CALMA_UNITS needs to be parsed to determine if units in - // the input file are compatible with units being used in the output - // file. calmaSkipSet(hdrSkip); + // CALMA_UNITS needs to be parsed to determine if units in the + // input file are compatible with units being used in the output + // file. + if (calmaParseUnits() == FALSE) + { + TxError("Error: Library %s has incompatible database units!\n", libname); + return; + } + // Record the GDS library so it will not be processed again. he = HashFind(&calmaLibHash, filename); if ((char *)HashGetValue(he) != NULL) diff --git a/calma/CalmaWriteZ.c b/calma/CalmaWriteZ.c index 66ef9245..3890ceb7 100644 --- a/calma/CalmaWriteZ.c +++ b/calma/CalmaWriteZ.c @@ -682,7 +682,7 @@ calmaFullDumpZ(def, fi, outf, filename) static int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS, CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE, - CALMA_STYPTABLE, CALMA_GENERATIONS, CALMA_UNITS, -1 }; + CALMA_STYPTABLE, CALMA_GENERATIONS, -1 }; static int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME, CALMA_LIBSECUR, -1 }; @@ -698,10 +698,14 @@ calmaFullDumpZ(def, fi, outf, filename) calmaSkipSet(skipBeforeLib); if (!calmaReadStringRecord(CALMA_LIBNAME, &libname)) goto done; - // NOTE: CALMA_UNITS needs to be parsed to determine if units in - // the input file are compatible with units being used in the output + // CALMA_UNITS needs to be parsed to determine if units in the + // input file are compatible with units being used in the output // file. - calmaSkipSet(hdrSkip); + if (calmaParseUnits() == FALSE) + { + TxError("Error: Library %s has incompatible database units!\n", libname); + return; + } // Record the GDS library so it will not be processed again. he = HashFind(&calmaLibHash, filename); diff --git a/calma/calmaInt.h b/calma/calmaInt.h index 4fb56a2f..fea4fb36 100644 --- a/calma/calmaInt.h +++ b/calma/calmaInt.h @@ -237,6 +237,7 @@ extern bool calmaIsContactCell; extern char *calmaRecordName(); extern void calmaSkipSet(); +extern bool calmaParseUnits(); extern int compport();