/* code taken from a dev version of netcdfdataset.cpp, to show the implementation of history mechanism */ /* -------------------------------------------------------------------- */ CopyMetadata((void *) poSrcDS, fpImage, NC_GLOBAL ); #ifdef GDAL_GET_CMD_LINE_DEFINED if ( ! EQUAL(GDALGetCmdLine(TRUE), "" ) ) strcpy( szTemp, GDALGetCmdLine(TRUE) ); else sprintf( szTemp, "GDAL NCDFCreateCopy( %s, ... )",pszFilename ); #else sprintf( szTemp, "GDAL NCDFCreateCopy( %s, ... )",pszFilename ); #endif NCDFAddHistory( fpImage, szTemp, poSrcDS->GetMetadataItem("NC_GLOBAL#history","") ); [...] /* code taken from cdo and libcdi, used for writing the history attribute */ //void cdoDefHistory(int fileID, char *histstring) void NCDFAddHistory(int fpImage, const char *pszAddHist, const char *pszOldHist) { char strtime[32]; time_t tp; struct tm *ltime; char *pszNewHist = NULL; size_t nNewHistSize = 0; int disableHistory = FALSE; /* Check pszOldHist - as if there was no previous history, it will be a null pointer - if so set as empty. */ if (NULL == pszOldHist) { pszOldHist = ""; } tp = time(NULL); if ( tp != -1 ) { ltime = localtime(&tp); (void) strftime(strtime, sizeof(strtime), "%a %b %d %H:%M:%S %Y: ", ltime); } // status = nc_get_att_text( fpImage, NC_GLOBAL, // "history", pszOldHist ); // printf("status: %d pszOldHist: [%s]\n",status,pszOldHist); nNewHistSize = strlen(pszOldHist)+strlen(strtime)+strlen(pszAddHist)+2; pszNewHist = (char *) CPLMalloc(nNewHistSize * sizeof(char)); strcpy(pszNewHist, strtime); strcat(pszNewHist, pszAddHist); if ( disableHistory == FALSE && pszNewHist ) { if ( ! EQUAL(pszOldHist,"") ) strcat(pszNewHist, "\n"); strcat(pszNewHist, pszOldHist); } /* this would be replaced by SetMetadataItem() */ nc_put_att_text( fpImage, NC_GLOBAL, "history", nNewHistSize, pszNewHist ); CPLFree(pszNewHist); }