void tick() { float elapsed = (utGetTimer() - startTime) / 1000.0f; numFrames++; utBeginFrame(); utClear(0.2f, 0.0f, 0.2f, 1.0f); /* Set up a 3D projection */ float matrix[16]; utMatrix4Perspective(matrix, 1.0f, (640.0f / 480.0f), 0.1f, 100.0f); utSetRenderMatrix(UT_MATRIX_PROJECTION, matrix); /* Push the model back a bit */ utMatrix4Translation(matrix, 0.0f, 0.0f, -2.5f); utSetRenderMatrix(UT_MATRIX_VIEW, matrix); /* Spin it slowly */ utMatrix4RotationFromAngleAxis(matrix, elapsed, 0.8944f, 0.4472f, 0.0f); utSetRenderMatrix(UT_MATRIX_MODEL, matrix); utSetTexture(0, tex); utDraw(vbuf, vfmt, ibuf, 0, UT_DRAW_ALL); utEndFrame(); utSwapRenderTarget(target); }
NCdsHandle_t *NCdsHandleCreate (const char *pattern, const char *name, int dncid, NCtimeStep tsMode, utUnit *tUnitIn, double sTime, double eTime) { size_t i, j, strLen, strOffset, ncNum = 0, index; char *str [] = { "{year}", "{month}", "{day}", "{hour}", "{minute}", "{second}" }; char *searchStr, *subStr, **fileNames = (char **) NULL, tsUnitStr [NCsizeString]; int *ncids = (int *) NULL, tvarid, status; int endYear, endMonth, year, month, day, hour, minute; float second; double time = 0.0, scale, offset; utUnit tUnitOut; NCdsHandle_t *dsh; if ((searchStr = malloc (strlen (pattern) + 1)) == (char *) NULL) { CMmsgPrint (CMmsgSysError, "Memory allocation error in: NCdsHandleCreate ()!"); return ((NCdsHandle_t *) NULL); } if ((utCalendar (eTime,tUnitIn,&endYear,&endMonth,&day,&hour,&minute,&second) != 0) || (utCalendar (sTime,tUnitIn,&year, &month, &day,&hour,&minute,&second) != 0)) { CMmsgPrint (CMmsgAppError, "Calender scanning error in:%s %d",__FILE__,__LINE__); goto ABORT; } switch (tsMode) { case NCtimeYear: sprintf (tsUnitStr,"years since %04d-01-01 00:00 0.0",year); break; case NCtimeMonth: sprintf (tsUnitStr,"months since %04d-%02d-01 00:00 0.0",year, month); break; case NCtimeDay: sprintf (tsUnitStr,"days since %04d-%02d-%02d 00:00 0.0",year, month, day); break; case NCtimeHour: sprintf (tsUnitStr,"hours since %04d-%02d-%02d %02d:00 0.0",year, month, day, hour); break; case NCtimeMinute: sprintf (tsUnitStr,"minutes since %04d-%02d-%02d %02d:%02d 0.0", year, month, day, hour, minute); break; case NCtimeSecond: sprintf (tsUnitStr,"seconds since %04d-%02d-%02d %02d:%02d %.1f", year, month, day, hour, minute, second); break; } if (tsMode > NCtimeMonth) { if ((utScan (tsUnitStr, &tUnitOut) != 0) || (utConvert (tUnitIn, &tUnitOut, &scale, &offset) != 0)) { CMmsgPrint (CMmsgAppError, "Time unit scanning error in: %s %d",__FILE__,__LINE__); goto ABORT; } sTime = sTime * scale + offset; eTime = eTime * scale + offset; } else { sTime = 0.0; eTime = tsMode > NCtimeYear ? (endYear - year) * 12 + (endMonth - month + 1) : (double) (year - endYear); } do { if (tsMode > NCtimeMonth) { if (utCalendar (sTime + time,&tUnitOut,&year,&month,&day,&hour,&minute,&second) != 0) { CMmsgPrint (CMmsgAppError, "Time unit scaning error in: %s %d",__FILE__,__LINE__); goto ABORT; } } strcpy (searchStr, pattern); for (i = 0;i < tsMode; ++i) if ((subStr = strstr (searchStr,str [i])) == (char *) NULL) break; else { strOffset = strlen (str [i]); strLen = strlen (subStr) - strOffset; switch (i) { case NCtimeYear: sprintf (subStr,"%04d", year); subStr += 4; strOffset -= 4; break; case NCtimeMonth: sprintf (subStr,"%02d", month); subStr += 2; strOffset -= 2; break; case NCtimeDay: sprintf (subStr,"%02d", day); subStr += 2; strOffset -= 2; break; case NCtimeHour: sprintf (subStr,"%02d", hour); subStr += 2; strOffset -= 2; break; case NCtimeMinute: sprintf (subStr,"%02d", minute); subStr += 2; strOffset -= 2; break; case NCtimeSecond: sprintf (subStr,"%04.1f",second); subStr += 4; strOffset -= 4; break; } for (j = 0;j <= strLen; j++) subStr [j] = subStr [j + strOffset]; } if ((ncNum == 0) || (strcmp (fileNames [ncNum - 1], searchStr) != 0)) { if (((fileNames = (char **) realloc (fileNames, (ncNum + 1) * sizeof (char *))) == (char **) NULL) || ((ncids = (int *) realloc (ncids, (ncNum + 1) * sizeof (int))) == (int *) NULL)) { CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); goto ABORT; } else ncNum++; if ((fileNames [ncNum - 1] = (char *) malloc (strlen (searchStr) + 1)) == (char *) NULL) { CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); goto ABORT; } strcpy (fileNames [ncNum - 1], searchStr); if (((ncids [ncNum - 1] = NCfileCreate (fileNames [ncNum - 1], dncid)) == NCfailed) || (NCfileVarAdd (ncids [ncNum - 1], name, NC_FLOAT, NC_DOUBLE, NC_FLOAT) == NCfailed) || (NCfileSetTimeUnit (ncids [ncNum - 1], tsUnitStr) == NCfailed) || (NCfileSetMissingVal (ncids [ncNum - 1], -9999.0) == NCfailed) || ((tvarid = NCdataGetTVarId (ncids [ncNum - 1])) == NCfailed)) goto ABORT; index = 0; } if ((status = nc_put_var1_double (ncids [ncNum - 1],tvarid,&index, &time)) != NC_NOERR) { NCprintNCError (status,"NCdsHandleCreate"); goto ABORT; } index++; if (tsMode == NCtimeMonth) { month++; if (month > 12) { month = 1; year++;} } if (tsMode == NCtimeYear) { year++; } time = time + 1.0; } while ((sTime + time) < eTime); for (i = 0;i < ncNum; i++) nc_sync (ncids [i]); if ((dsh = NCdsHandleOpenByIds (ncids, ncNum)) == (NCdsHandle_t *) NULL) goto ABORT; for (i = 0;i < ncNum; i++) free (fileNames [i]); utClear (&tUnitOut); free (fileNames); free (ncids); free (searchStr); return (dsh); ABORT: for (i = 0;i < ncNum;i++) { nc_abort (ncids [i]); unlink (fileNames [i]); if (fileNames [i] != (char *) NULL) free (fileNames [i]); } utClear (&tUnitOut); if (fileNames != (char **) NULL) free (fileNames); free (searchStr); return ((NCdsHandle_t *) NULL); }