From 82d02357afb10801d6800c426ae1d9a15d6a1925 Mon Sep 17 00:00:00 2001 From: Chris Piker Date: Wed, 7 Aug 2024 17:14:51 -0500 Subject: [PATCH] das3_cdf unittest passes on Windows --- buildfiles/Windows.mak | 93 ++++++++++++++++++++------------- notes/install_visual_studio.txt | 88 +++++++++++++++++++++++++++---- utilities/das3_cdf.c | 31 ++++++----- 3 files changed, 156 insertions(+), 56 deletions(-) diff --git a/buildfiles/Windows.mak b/buildfiles/Windows.mak index ccc039a..933de38 100644 --- a/buildfiles/Windows.mak +++ b/buildfiles/Windows.mak @@ -12,7 +12,8 @@ TARG=das3.0 # Put wisdom file for this computer in %CommonProgramFiles%\fftw\wisdom.dat INC=/I . /I $(LIBRARY_INC) -CFLAGS=$(CFLAGS) /DEBUG /DWISDOM_FILE=C:/ProgramData/fftw3/wisdom.dat $(INC) +CFLAGS=$(CFLAGS) /Z7 /DWISDOM_FILE=C:/ProgramData/fftw3/wisdom.dat $(INC) +LFLAGS=/link /DEBUG # Deal with differences from building under anaconda ED=$(LIBRARY_LIB) @@ -30,50 +31,50 @@ BD=build.windows SRCS=$(SD)\das1.c $(SD)\array.c $(SD)\buffer.c $(SD)\builder.c $(SD)\cli.c \ $(SD)\codec.c $(SD)\credentials.c $(SD)\dataset.c $(SD)\datum.c $(SD)\descriptor.c \ $(SD)\dft.c $(SD)\dimension.c $(SD)\dsdf.c $(SD)\encoding.c $(SD)\frame.c \ - $(SD)\http.c $(SD)\io.c $(SD)\json.c $(SD)\log.c $(SD)\node.c $(SD)\oob.c \ - $(SD)\operator.c $(SD)\packet.c $(SD)\plane.c $(SD)\processor.c $(SD)\property.c \ - $(SD)\send.c $(SD)\serial.c $(SD)\stream.c $(SD)\time.c $(SD)\tt2000.c \ - $(SD)\units.c $(SD)\utf8.c $(SD)\util.c $(SD)\value.c $(SD)\variable.c \ - $(SD)\vector.c + $(SD)\http.c $(SD)\io.c $(LD)\iterator.c $(SD)\json.c $(SD)\log.c $(SD)\node.c \ + $(SD)\oob.c $(SD)\operator.c $(SD)\packet.c $(SD)\plane.c $(SD)\processor.c \ + $(SD)\property.c $(SD)\send.c $(SD)\serial2.c $(SD)\serial3.c $(SD)\stream.c \ + $(SD)\time.c $(SD)\tt2000.c $(SD)\units.c $(SD)\utf8.c $(SD)\util.c $(SD)\value.c \ + $(SD)\variable.c $(SD)\vector.c LD=$(BD)\static STATIC_OBJS=$(LD)\das1.obj $(LD)\array.obj $(LD)\buffer.obj $(LD)\builder.obj \ $(LD)\cli.obj $(LD)\codec.obj $(LD)\credentials.obj $(LD)\dataset.obj $(LD)\datum.obj \ $(LD)\descriptor.obj $(LD)\dft.obj $(LD)\dimension.obj $(LD)\dsdf.obj \ - $(LD)\encoding.obj $(LD)\frame.obj $(LD)\http.obj $(LD)\io.obj $(LD)\json.obj \ - $(LD)\log.obj $(LD)\node.obj $(LD)\oob.obj $(LD)\operator.obj $(LD)\packet.obj \ - $(LD)\plane.obj $(LD)\processor.obj $(LD)\property.obj $(LD)\send.obj \ - $(LD)\serial.obj $(LD)\stream.obj $(LD)\time.obj $(LD)\tt2000.obj \ - $(LD)\units.obj $(LD)\utf8.obj $(LD)\util.obj $(LD)\value.obj \ - $(LD)\variable.obj $(LD)\vector.obj + $(LD)\encoding.obj $(LD)\frame.obj $(LD)\http.obj $(LD)\io.obj $(LD)\iterator.obj \ + $(LD)\json.obj $(LD)\log.obj $(LD)\node.obj $(LD)\oob.obj $(LD)\operator.obj \ + $(LD)\packet.obj $(LD)\plane.obj $(LD)\processor.obj $(LD)\property.obj \ + $(LD)\send.obj $(LD)\serial2.obj $(LD)\serial3.obj $(LD)\stream.obj \ + $(LD)\time.obj $(LD)\tt2000.obj $(LD)\units.obj $(LD)\utf8.obj $(LD)\util.obj \ + $(LD)\value.obj $(LD)\variable.obj $(LD)\vector.obj DD=$(BD)\shared DLL_OBJS=$(DD)\das1.obj $(DD)\array.obj $(DD)\buffer.obj $(DD)\builder.obj \ $(DD)\cli.obj $(DD)\codec.obj $(DD)\credentials.obj $(DD)\dataset.obj $(DD)\datum.obj \ $(DD)\descriptor.obj $(DD)\dft.obj $(DD)\dimension.obj $(DD)\dsdf.obj \ - $(DD)\encoding.obj $(DD)\frame.obj $(DD)\http.obj $(DD)\io.obj $(DD)\json.obj \ - $(DD)\log.obj $(DD)\node.obj $(DD)\oob.obj $(DD)\operator.obj $(DD)\packet.obj \ - $(DD)\plane.obj $(DD)\processor.obj $(DD)\property.obj $(DD)\send.obj \ - $(DD)\serial.obj $(DD)\stream.obj $(DD)\time.obj $(DD)\tt2000.obj \ - $(DD)\units.obj $(DD)\utf8.obj $(DD)\util.obj $(DD)\value.obj \ - $(DD)\variable.obj $(DD)\vector.obj + $(DD)\encoding.obj $(DD)\frame.obj $(DD)\http.obj $(DD)\io.obj $(DD)\iterator.obj \ + $(DD)\json.obj $(DD)\log.obj $(DD)\node.obj $(DD)\oob.obj $(DD)\operator.obj \ + $(DD)\packet.obj $(DD)\plane.obj $(DD)\processor.obj $(DD)\property.obj \ + $(DD)\send.obj $(DD)\serial2.obj $(DD)\serial3.obj $(DD)\stream.obj \ + $(DD)\time.obj $(DD)\tt2000.obj $(DD)\units.obj $(DD)\utf8.obj $(DD)\util.obj \ + $(DD)\value.obj $(DD)\variable.obj $(DD)\vector.obj HDRS=$(SD)\das1.h $(SD)\array.h $(SD)\buffer.h $(SD)\builder.h $(SD)\core.h \ - $(SD)\codec.h $(SD)\cli.h $(SD)\credentials.h $(SD)\dataset.h $(SD)\datum.h $(SD)\descriptor.h \ - $(SD)\defs.h $(SD)\dft.h $(SD)\dimension.h $(SD)\dsdf.h $(SD)\encoding.h \ - $(SD)\frame.h $(SD)\http.h $(SD)\io.h $(SD)\json.h $(SD)\log.h $(SD)\node.h \ - $(SD)\oob.h $(SD)\operator.h $(SD)\packet.h $(SD)\plane.h $(SD)\processor.h \ - $(SD)\property.h $(SD)\send.h $(SD)\stream.h $(SD)\time.h $(SD)\tt2000.h \ - $(SD)\units.h $(SD)\utf8.h $(SD)\util.h $(SD)\value.h $(SD)\variable.h \ - $(SD)\vector.h + $(SD)\codec.h $(SD)\cli.h $(SD)\credentials.h $(SD)\dataset.h $(SD)\datum.h \ + $(SD)\descriptor.h $(SD)\defs.h $(SD)\dft.h $(SD)\dimension.h $(SD)\dsdf.h \ + $(SD)\encoding.h $(SD)\frame.h $(SD)\http.h $(SD)\io.h $(SD)\iterator.h \ + $(SD)\json.h $(SD)\log.h $(SD)\node.h $(SD)\oob.h $(SD)\operator.h $(SD)\packet.h \ + $(SD)\plane.h $(SD)\processor.h $(SD)\property.h $(SD)\send.h $(SD)\stream.h \ + $(SD)\time.h $(SD)\tt2000.h $(SD)\units.h $(SD)\utf8.h $(SD)\util.h $(SD)\value.h \ + $(SD)\variable.h $(SD)\vector.h UTIL_PROGS=$(BD)\das1_inctime.exe $(BD)\das2_prtime.exe $(BD)\das1_fxtime.exe \ $(BD)\das2_ascii.exe $(BD)\das2_bin_avg.exe $(BD)\das2_bin_avgsec.exe \ $(BD)\das2_bin_peakavgsec.exe $(BD)\das2_cache_rdr.exe $(BD)\das2_from_das1.exe \ $(BD)\das2_from_tagged_das1.exe $(BD)\das1_ascii.exe $(BD)\das1_bin_avg.exe \ $(BD)\das2_bin_ratesec.exe $(BD)\das2_psd.exe $(BD)\das2_hapi.exe \ - $(BD)\das2_histo.exe $(BD)\das3_node.exe + $(BD)\das2_histo.exe $(BD)\das3_node.exe $(BD)\das3_csv.exe TEST_PROGS=$(BD)\TestUnits.exe $(BD)\TestArray.exe $(BD)\LoadStream.exe \ $(BD)\TestBuilder.exe $(BD)\TestAuth.exe $(BD)\TestCatalog.exe $(BD)\TestTT2000.exe \ @@ -82,7 +83,7 @@ TEST_PROGS=$(BD)\TestUnits.exe $(BD)\TestArray.exe $(BD)\LoadStream.exe \ # Add in cspice error handling functions if SPICE = yes !if defined(SPICE) ! if ! defined(CSPICE_INC) -! error set CSPICE_INC to the absoute path to CSpice headers directory first +! error set CSPICE_INC to the absoute path of the CSpice headers directory first ! endif CFLAGS=$(CFLAGS) /I $(CSPICE_INC) ! if ! defined(CSPICE_LIB) @@ -95,9 +96,24 @@ STATIC_OBJS=$(STATIC_OBJS) $(LD)\spice.obj DLL_OBJS=$(DLL_OBJS) $(DD)\spice.obj HDR=$(HDRS) $(SD)\spice.h TEST_PROGS=$(TEST_PROGS) $(BD)\TestSpice.exe +UTIL_PROGS=$(UTIL_PROGS) $(BD)\das3_spice.exe ! endif !endif - + +# Add in CDF error handling functions if CDF = yes +!if defined(CDF) +! if ! defined(CDF_INC) +! error set CDF_INC to the absoute path of the CDF headers directory first +! endif +! if ! defined(CDF_LIB) +! error set CDF_LIB to the absolute path to the file libcdf.lib first +! endif +! if "$(CDF)"=="yes" +UTIL_PROGS=$(UTIL_PROGS) $(BD)\das3_cdf.exe +! endif +!endif + + build: static shared progs static: $(LD) $(BD)\lib$(TARG).lib @@ -117,11 +133,15 @@ run_test: $(BD)\TestCredMngr.exe $(BD) $(BD)\TestV3Read.exe -run_test_spice: run_test +test_spice: $(BD)\TestSpice.exe -run_test3: - $(BD)\TestV3Read +# Can't test CDF creation this way due to stupide embedded time stamps +# cmp $(BD)/ex12_sounder_xyz.cdf test/ex12_sounder_xyz.cdf +test_cdf: + @echo "INFO: Testing CDF creation" + $(BD)\das3_cdf -l warning -i test\ex12_sounder_xyz.d3t -o $(BD) -r + @echo "INFO: CDF was created" $(LD): @@ -153,10 +173,13 @@ install: # Override rule for utility programs that need more than one source file $(BD)\das2_bin_ratesec.exe:utilities\das2_bin_ratesec.c utilities\via.c - $(CC) $(CFLAGS) /Fe:$@ $** $(EX_LIBS) $(BD)\lib$(TARG).lib + $(CC) $(CFLAGS) /Fe:$@ $** $(EX_LIBS) $(BD)\lib$(TARG).lib $(LFLAGS) $(BD)\das2_psd.exe:utilities\das2_psd.c utilities\send.c - $(CC) $(CFLAGS) /Fe:$@ $** $(EX_LIBS) $(BD)\lib$(TARG).lib + $(CC) $(CFLAGS) /Fe:$@ $** $(EX_LIBS) $(BD)\lib$(TARG).lib $(LFLAGS) + +$(BD)\das3_cdf.exe:utilities\das3_cdf.c + $(CC) $(CFLAGS) /I $(CDF_INC) /Fe:$@ $** $(EX_LIBS) $(BD)\lib$(TARG).lib $(CDF_LIB) $(LFLAGS) # Inference rule for static lib {$(SD)\}.c{$(LD)\}.obj: @@ -168,11 +191,11 @@ $(BD)\das2_psd.exe:utilities\das2_psd.c utilities\send.c # Inference rule for test programs {test\}.c{$(BD)\}.exe: - $(CC) $(CFLAGS) /Fe:$@ $< $(EX_LIBS) $(BD)\lib$(TARG).lib + $(CC) $(CFLAGS) /Fe:$@ $< $(EX_LIBS) $(BD)\lib$(TARG).lib $(LFLAGS) # Inference rule for util programs {utilities\}.c{$(BD)\}.exe: - $(CC) $(CFLAGS) /Fe:$@ $< $(EX_LIBS) $(BD)\lib$(TARG).lib + $(CC) $(CFLAGS) /Fe:$@ $< $(EX_LIBS) $(BD)\lib$(TARG).lib $(LFLAGS) clean: del *.obj diff --git a/notes/install_visual_studio.txt b/notes/install_visual_studio.txt index aa453dc..ebc8da9 100644 --- a/notes/install_visual_studio.txt +++ b/notes/install_visual_studio.txt @@ -142,19 +142,89 @@ This variable determines where the output will be installed: Then build, test and install the software... -nmake.exe /nologo /f makefiles\Windows.mak build -nmake.exe /nologo /f makefiles\Windows.mak run_test + nmake.exe /nologo /f makefiles\Windows.mak build + nmake.exe /nologo /f makefiles\Windows.mak run_test + +# See what's going to be install first, then install + + set INSTALL_PREIFX=C:\opt # for example + +nmake.exe /nologo /f makefiles\Windows.mak /n install nmake.exe /nologo /f makefiles\Windows.mak install - - ********************************************************************** - ** Visual Studio 2019 Developer Command Prompt v16.4.4 - ** Copyright (c) 2019 Microsoft Corporation - ********************************************************************** - [vcvarsall.bat] Environment initialized for: 'x64' + +4 Building in SPICE tools +========================= +This essentially boils down to: + + * Getting the CSPICE toolkit + * Setting evironment variables + * Build/install + +NAIF does not allow C-SPICE to be hosted in a pubilc get repository. To get cspice go to: + + https://naif.jpl.nasa.gov/naif/toolkit_C.html + +and get the "PC, Windows, MS Visual C, 64bit" version. Unpack it and put the header +files and the cspice.lib file somewhere, I selected: + + C:\opt\cspice\include + C:\opt\cspice\lib\cspice.lib + +by unzipping the files into C:\opt. + +Next set up your environment + + SET CSPICE_INC= your cspice include directory + SET CSPICE_LIB= full path to cspice.lib + +for example: + + SET CSPICE_INC=C:\opt\cspice\include + SET CSPICE_LIB=C:\opt\cspice\lib\cspice.lib + +and then running make with an extra switch: + +nmake.exe /nologo /f makefiles\Windows.mak SPICE=yes build +nmake.exe /nologo /f makefiles\Windows.mak SPICE=yes run_test +nmake.exe /nologo /f makefiles\Windows.mak SPICE=yes install + + +5 Building in CDF tools +======================= +This is vary similar to the SPICE section above. To add CDF support: + + * Download and unpack the CDF libs + * Set some environment variable + * Add an extra switch to the make commands + +The CDF library is also not hosted on github, or equivalent. To get the CDF lib go to: + + https://spdf.gsfc.nasa.gov/pub/software/cdf/dist/latest/windows/ + +get the 64-bit zip file, for example: + + cdf3.9.0_64bit_WinZip_Installer.zip + +unpack it somewhere, I selected C:\opt\cdf. You get a bunch of stuff you don't need +but it won't be included in the resulting executables so that's probably okay. + +Next setup the environment: + + set CDF_INC=C:\opt\cdf\include + set CDF_LIB=C:\opt\cdf\lib\libcdf.lib + +and run nmake with CDF utilities toggeled on: + + nmake.exe /nologo /f makefiles\Windows.mak CDF=yes build + nmake.exe /nologo /f makefiles\Windows.mak CDF=yes run_test + nmake.exe /nologo /f makefiles\Windows.mak CDF=yes install + +NOTE: It's perfectly fine to toggle both SPICE and CDF at the same time, provide the +required environment variables have been set for each. + - diff --git a/utilities/das3_cdf.c b/utilities/das3_cdf.c index ce49539..45dda64 100644 --- a/utilities/das3_cdf.c +++ b/utilities/das3_cdf.c @@ -35,6 +35,7 @@ #define strncasecmp _strnicmp #else #include +#define NEW_FILE_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH #endif #include @@ -44,8 +45,6 @@ #define PROG "das3_cdf" #define PERR 63 -#define NEW_FILE_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH - #define DEF_AUTH_FILE ".dasauth" #define DEF_TEMP_DIR ".dastmp" @@ -318,14 +317,14 @@ int parseArgs(int argc, char** argv, popts_t* pOpts) /* Set a few defaults */ snprintf( - pOpts->aCredFile, FIELD_SZ(popts_t, aCredFile) - 1, "%s" DAS_DSEPS DEF_AUTH_FILE, + pOpts->aCredFile, DAS_FIELD_SZ(popts_t, aCredFile) - 1, "%s" DAS_DSEPS DEF_AUTH_FILE, das_userhome() ); strcpy(pOpts->aLevel, "info"); snprintf( - pOpts->aTmpDir, FIELD_SZ(popts_t, aTmpDir) - 1, "%s" DAS_DSEPS ".cdftmp", + pOpts->aTmpDir, DAS_FIELD_SZ(popts_t, aTmpDir) - 1, "%s" DAS_DSEPS ".cdftmp", das_userhome() ); @@ -1078,7 +1077,11 @@ DasErrCode onStream(StreamDesc* pSd, void* pUser){ /* Open the file since we have something to write */ if(pCtx->sTpltFile[0] != '\0'){ /* Copy in skeleton and open that or... */ +#ifndef _WIN32 if(!das_copyfile(pCtx->sTpltFile, pCtx->sWriteTo, NEW_FILE_MODE)){ +#else + if(!das_copyfile(pCtx->sTpltFile, pCtx->sWriteTo)){ +#endif das_error(PERR, "Couldn't open copy '%s' --to--> '%s'", pCtx->sTpltFile, pCtx->sWriteTo ); @@ -2198,7 +2201,7 @@ DasErrCode _writeRecVaryAry(struct context* pCtx, DasVar* pVar, DasAry* pAry) return DAS_OKAY; } -DasErrCode putAllData(CDFid nCdfId, int nDsRank, ptrdiff_t* pDsShape, DasVar* pVar) +DasErrCode putAllData(struct context* pCtx, int nDsRank, ptrdiff_t* pDsShape, DasVar* pVar) { /* Take a short cut for array variables */ if(DasVar_type(pVar) == D2V_ARRAY){ @@ -2206,7 +2209,7 @@ DasErrCode putAllData(CDFid nCdfId, int nDsRank, ptrdiff_t* pDsShape, DasVar* pV DasAry* pAry = DasVarAry_getArray(pVar); /* Does not copy data */ assert(pAry != NULL); - if(_writeRecVaryAry(nCdfId, pVar, pAry) != DAS_OKAY) + if(_writeRecVaryAry(pCtx, pVar, pAry) != DAS_OKAY) return PERR; } else{ @@ -2233,7 +2236,7 @@ DasErrCode putAllData(CDFid nCdfId, int nDsRank, ptrdiff_t* pDsShape, DasVar* pV /* A potentially long calculation.... */ DasAry* pAry = DasVar_subset(pVar, nDsRank, aMin, aMax); - if(_writeRecVaryAry(nCdfId, pVar, pAry) != DAS_OKAY) + if(_writeRecVaryAry(pCtx, pVar, pAry) != DAS_OKAY) return PERR; dec_DasAry(pAry); /* Delete the temporary array */ @@ -2267,7 +2270,7 @@ DasErrCode writeAndClearData(DasDs* pDs, struct context* pCtx) if(DasVar_degenerate(pVar, 0)) /* var is not record varying */ continue; - if(putAllData(pCtx->nCdfId, nDsRank, aDsShape, pVar) != DAS_OKAY) + if(putAllData(pCtx, nDsRank, aDsShape, pVar) != DAS_OKAY) return PERR; } } @@ -2324,6 +2327,12 @@ DasErrCode onExcept(OobExcept* pExcept, void* pUser) return DAS_OKAY; } +DasErrCode onComment(OobComment* pComment, void* pUser) +{ + /* Don't care about comments, for now */ + return DAS_OKAY; +} + /* ************************************************************************* */ DasErrCode onClose(StreamDesc* pSd, void* pUser) { @@ -2513,7 +2522,7 @@ int main(int argc, char** argv) return das_error(DASERR_HTTP, "Uncatorize error: %s", res.sError); } - char sUrl[ FIELD_SZ(popts_t,aSource) ] = {'\0'}; + char sUrl[ DAS_FIELD_SZ(popts_t,aSource) ] = {'\0'}; das_url_toStr(&(res.url), sUrl, sizeof(sUrl) - 1); if(strcmp(sUrl, opts.aSource) != 0) @@ -2565,6 +2574,7 @@ int main(int argc, char** argv) handler.dsDescHandler = onDataSet; handler.dsDataHandler = onData; handler.exceptionHandler = onExcept; + handler.commentHandler = onComment; handler.closeHandler = onClose; handler.userData = &ctx; @@ -2575,9 +2585,6 @@ int main(int argc, char** argv) if(ctx.nCdfId != 0) CDFclose(ctx.nCdfId); - daslog_info_v("") - if(opts.) - if(pInFile) fclose(pInFile);