#include "slosh2.h" #include "type.h" #include "tclslosh.h" #include "time.h" #include "halo_out.h" #include #include #include "clock.h" #include "setup.h" /***************************************************************************** * :: Arthur Taylor TDL (run_SaveRexStep) * Purpose: * This procedure saves a frame to a rex file. * * Variables: (I=input) (O=output) (G=global) * clientData (I) A pointer to the basin data. * interp (I) The Tcl/Tk interpreter. * argv: * name The name of the rex file to save to. * f_Offset 1 set Offset to 0, 0 leave alone. * trk_name Name of 100 point track file. * bsn_abrev The 3/4 letter abrev for the basin. (ie pns and hbix) * f_env 1 if this is the envelope 0 otherwise. * Current Time * Current Date * 1 or 2 (currently) * * Returns: TCL_ERROR or TCL_OK * * History: * 4/1999 Arthur Taylor RSIS/TDL Created * * Notes: ****************************************************************************/ int SaveRexStepCmd (ClientData clientData, Tcl_Interp * interp, int argc, #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION <= 3) char *argv[]) #else const char *argv[]) #endif { global_type *gt = (global_type *) clientData; unsigned char hr, min, sec, day, mon; sInt4 year; char f_env, f_type, f_resetOffset; double clock; int f_tide; /* char buffer[200]; */ if (argc != 14) { sprintf (interp->result, "Usage: %s " " ", argv[0]); return TCL_ERROR; } f_resetOffset = atoi (argv[2]); f_env = (char) atoi (argv[5]); hr = (unsigned char) atoi (argv[6]); min = (unsigned char) atoi (argv[7]); sec = (unsigned char) atoi (argv[8]); day = (unsigned char) atoi (argv[9]); mon = (unsigned char) atoi (argv[10]); year = (sInt4) atoi (argv[11]); f_type = (char) atoi (argv[12]); f_tide = atoi (argv[13]); clock = 0; Clock_ScanDate (&clock, year, mon, day); /* printf ("%ld-%d-%d\n", year, mon, day); */ clock += 3600 * hr; clock += 60 * min; clock += sec; if (! f_env) { if (RexSaveStep (&(gt->rex), gt->st.storm_lat, gt->st.storm_lon, gt->st.wspeed, gt->st.wdirect, gt->st.delp, gt->st.size2, gt->st.hb, gt->st.zb, gt->bt->i, gt->bt->j, clock) != 0) { return TCL_ERROR; } } else { if (RexSaveEnv (&(gt->rex), argv[3], gt->st.hb, gt->st.zb, gt->bt->i, gt->bt->j, f_tide) != 0) { return TCL_ERROR; } } return TCL_OK; } /***************************************************************************** * :: Arthur Taylor TDL (run_C_LoopStep) * Purpose: * This procedure does the loops. * * Variables: (I=input) (O=output) (G=global) * clientData (I) A pointer to the basin data. * interp (I) The Tcl/Tk interpreter. * argv: * itime (I) The current time as an int * mhalt (I) The stop time as an int * csflag (I) Flag to do CS stuff usually 0. * f_smooth (I) Flag to do smoothing. * name (I) Name of the pixmap to draw to. * grid_pen * pen1 * pen2 * max_height * min_height * f_rude (I) -2 no Tcl/Tk update, -1 polite update, * otherwise is padding for "rude" display of pixmap. * f_graphics (I) 1 draw stuff, 2 copy stuff, 0 don't do anything with data. * f_passdata (I) 1 pass data from fortran to c, 0 don't. * * Returns: TCL_ERROR or TCL_OK * itime, mhalt, * del_t, The change in time per timestep * storm_lat, lon The position of the storm * delp The change in pressure * size2 The radius of max wind * wspeed Forward speed of the storm * wdirect Forward direction of the storm * * History: * 4/1999 Arthur Taylor RSIS/TDL Created * * Notes: * I broke up the old loopstep significantly. Refrence it. ****************************************************************************/ int RunLoopStepCmd (ClientData clientData, Tcl_Interp * interp, int argc, #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION <= 3) char *argv[]) #else const char *argv[]) #endif { global_type *gt = (global_type *) clientData; int itime, mhalt; short csflag, f_smooth, f_wantRex; int UID, pen1, pen2, grid_pen; int f_rude, f_graphics; float maxv, minv; char buffer[200]; char f_grid = 0, f_fill = 1, f_range = 1; double ratio; int f_tide; int f_first; double rextime; int f_stat; if (argc != 18) { sprintf (interp->result, "Usage: %s " " " " " " ", argv[0]); return TCL_ERROR; } if ((gt->st.hb == NULL) || (gt->st.zb == NULL)) { sprintf (interp->result, "Please call Run_C_Init first."); return TCL_ERROR; } itime = atoi (argv[1]); mhalt = atoi (argv[2]); csflag = (short) atoi (argv[3]); f_smooth = (short) atoi (argv[4]); UID = Halo_UID (argv[5]); grid_pen = atoi (argv[6]); pen1 = atoi (argv[7]); pen2 = atoi (argv[8]); maxv = atof (argv[9]); minv = atof (argv[10]); f_rude = atoi (argv[11]); f_graphics = atoi (argv[12]); f_wantRex = (short) atoi (argv[13]); rextime = atof (argv[14]); f_tide = atoi (argv[15]); f_first = atoi (argv[16]); f_stat = atoi (argv[17]); RunLoopStep (&(gt->st), gt->bt->i, gt->bt->j, &itime, &mhalt, csflag, f_smooth, f_wantRex, &(gt->modelClock), rextime, f_first, &(gt->tgrid), f_tide, f_stat); /* Compute the grid for the GUI. */ /* if (f_graphics == 2) { for (i = 0; i < gt->bt->i; i++) { for (j = 0; j < gt->bt->j; j++) { if ((gt->st.hb[j][i] + gt->st.zb[j][i]) == 0.0) { gt->bt->grid[i][j].depth = 99.9; } else { gt->bt->grid[i][j].depth = st->hb[j][i]; } } } } */ if (f_graphics == 1) { if (maxv == minv) { ratio = 0; } else { ratio = (pen2 - pen1) / (double) (maxv - minv); } #ifdef DOUBLE_FORTRAN Halo_DeltaBasinFillDouble (UID, gt->bt, gt->st.zb, gt->st.hb, minv, maxv, pen2, ratio, 0, f_grid, f_fill, f_range, grid_pen, -1, f_rude); #else Halo_DeltaBasinFill (UID, gt->bt, gt->st.zb, gt->st.hb, minv, maxv, pen2, ratio, 0, f_grid, f_fill, f_range, grid_pen, -1, f_rude); #endif } sprintf (buffer, "%d %d %f %f %f %f %f %f %f", itime, mhalt, gt->modelClock, gt->st.storm_lat, -1 * gt->st.storm_lon, gt->st.delp, gt->st.size2, gt->st.wspeed, gt->st.wdirect); sprintf (interp->result, buffer); return TCL_OK; } static int CleanUpCmd (ClientData clientData, Tcl_Interp * interp, int argc, #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION <= 3) char *argv[]) #else const char *argv[]) #endif { global_type *gt = (global_type *) clientData; int f_saveEnv = 1; int f_tide; float ht1, ht2; int i, j; char rexComment[201]; char envComment[161]; if (argc != 2) { sprintf (interp->result, "Usage: %s ", argv[0]); return TCL_ERROR; } f_tide = atoi (argv[1]); if (ReadTrkFile (gt->trk_name, rexComment, envComment, &ht1, &ht2) != 0) { return TCL_ERROR; } if (CleanUp (&(gt->st), gt->bt->i, gt->bt->j, f_saveEnv, f_tide, gt->xxx_name, envComment, ht1, ht2, &(gt->tgrid)) != 0) { return TCL_ERROR; } /* Compute the grid for the GUI. */ for (i = 0; i < gt->bt->i; i++) { for (j = 0; j < gt->bt->j; j++) { if ((gt->st.hb[j][i] + gt->st.zb[j][i]) == 0.0) { gt->bt->grid[i][j].depth = 99.9; } else { gt->bt->grid[i][j].depth = gt->st.hb[j][i]; } } } return TCL_OK; } double ColorTime214 (int timespan, sInt4 timeOffset) { double ad_time = 0, a_o, tOffset; if (timespan == 0) return ad_time; ad_time = difftime (time (NULL), 0); a_o = ad_time - timeOffset; tOffset = timeOffset; tOffset = tOffset / 3600.; a_o = a_o / 3600.; tOffset = tOffset / 24.; a_o = a_o / 24.; if (timespan == 1) { } else if (timespan == 2) { /* tOffset = tOffset / 7.; *//* convert to week */ a_o = a_o / 7.; } else if (timespan == 3) { /* tOffset = tOffset / 31.; *//* convert to month */ a_o = a_o / 31.; } else if (timespan == 4) { /* tOffset = tOffset / 365.; *//* convert to year */ a_o = a_o / 365.; } /* By not converting tOffset to timespan, it stays a unique number. */ /* So I think we might get some passwords good for an extra day or so, * but not for whole weeks. */ ad_time = floor (pow (tOffset, 1.1)) + floor (a_o); return ad_time; } int ColorMatch214 (const char *name, const char *id, int adjust, int timespan, sInt4 timeOffset) { double sum, sum2; int let, i; sum = adjust + ColorTime214 (timespan, timeOffset); sum = floor (pow (sum, 1.5)); for (i = 0; i < strlen (name); i++) { sum += (name[i] - 32 % (126 - 32) + 1) * (126 - 32) * (i + 1); } sum2 = 0; for (i = 0; i < strlen (id); i++) { if ((id[i] >= 'a') && (id[i] <= 'z')) { let = id[i] - 'a'; } else { let = 26 + id[i] - '2'; } sum2 += let * pow (34, i); } if (sum == 0) { return (sum != sum); } else { return (sum == sum2); } } /***************************************************************************** * :: Arthur Taylor TDL (run_C_Init) * Purpose: * To initialize the run. * * Variables: (I=input) (O=output) (G=global) * clientData (I) A pointer to the basin data. * interp (I) The Tcl/Tk interpreter. * argv: * trk_name (I) The file to read the track from * dta_name (I) The file to read the basin data from * xxx_name (I) The file to save the envelope to. * llx_name (I) The file to read the llx data from. * ft40_name (I) The file to read history points from. * * Returns: TCL_ERROR or TCL_OK * The start hour, min, sec, day, month, year, and ending int. * * History: * 4/1999 Arthur Taylor RSIS/TDL Created * * Notes: ****************************************************************************/ static int RunInitCmd (ClientData clientData, Tcl_Interp * interp, int argc, #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION <= 3) char *argv[]) #else const char *argv[]) #endif { global_type *gt = (global_type *) clientData; char dta_name[MY_MAX_PATH], f40_name[31]; Tcl_CmdInfo info; char buffer[200]; int mhalt; sInt4 year; int month, day, hour, min; double sec; int f_tide; char ft03_name[MY_MAX_PATH]; /* Name of annular constituent file. */ char bhc_name[MY_MAX_PATH]; /* Name of Binary Harmonic Constituent file */ char adj_name[MY_MAX_PATH]; /* Name of Datum Adjust. File (eg. MTL->NAVD88)*/ int spinUp; /* Seconds of tidal spinUp. */ int f_saveSpinUp; int imxb, jmxb; char bsnAbrev[5]; const char *bntDir; float ht1, ht2; char rexComment[201]; char envComment[161]; char rexVersion; char f_wantRex; int rexSaveMin; char *rexName; int tideThresh = 0; if (argc == 2) { if (strcmp (argv[1], "-V") == 0) { SloshAbout (buffer); Tcl_SetResult (interp, buffer, NULL); return TCL_OK; } } if (argc != 17) { sprintf (interp->result, "Usage: %s " " " " " " \n", argv[0]); return TCL_ERROR; } strncpy (gt->trk_name, argv[1], MY_MAX_PATH-1); strncpy (dta_name, argv[2], MY_MAX_PATH-1); strncpy (gt->xxx_name, argv[3], MY_MAX_PATH-1); strncpy (f40_name, argv[4], 30); f_tide = atoi (argv[5]); strncpy (ft03_name, argv[6], MY_MAX_PATH-1); strncpy (bhc_name, argv[7], MY_MAX_PATH-1); strncpy (adj_name, argv[8], MY_MAX_PATH-1); spinUp = atoi (argv[9]) * 3600; f_saveSpinUp = atoi (argv[10]); strncpy (bsnAbrev, argv[11], 5); bntDir = argv[12]; rexName = argv[13]; rexVersion = atoi (argv[14]); f_wantRex = atoi (argv[15]); rexSaveMin = atoi (argv[16]); if (SetBsnLatLon (bntDir, bsnAbrev, &imxb, &jmxb) != 0) { sprintf (interp->result, "ERROR: Problems initializing the model.\n"); return TCL_ERROR; } if (ReadTrkFile (gt->trk_name, rexComment, envComment, &ht1, &ht2) != 0) { return -1; } if (RexOpen (&(gt->rex), rexName, rexVersion) != 0) { return TCL_ERROR; } RexSaveHeader (&(gt->rex), imxb, jmxb, rexComment, bsnAbrev); if (RunInit (&(gt->st), gt->trk_name, dta_name, gt->xxx_name, f40_name, &mhalt, &(gt->modelClock), f_tide, tideThresh, ft03_name, bhc_name, &(gt->tgrid), adj_name, spinUp, f_saveSpinUp, &(gt->rex), f_wantRex, rexSaveMin) != 0) { sprintf (interp->result, "ERROR: Problems initializing the model.\n"); return TCL_ERROR; } Clock_PrintDate (gt->modelClock, &year, &month, &day, &hour, &min, &sec); sprintf (buffer, "%d %f", mhalt, gt->modelClock); /* Get a handle to the basin data... */ Tcl_GetCommandInfo (interp, "halo_bsnDraw", &info); if (info.isNativeObjectProc) { sprintf (interp->result, "ERROR: halo_bsnDraw should not be an Obj Proc\n"); return TCL_ERROR; } else { gt->bt = (basin_type *) info.clientData; } sprintf (interp->result, buffer); return TCL_OK; } /***************************************************************************** * Start of Generic dta file stuff. *****************************************************************************/ /* 0=0, 1=day, 2=week, 3=month, 4=year * most likely timeOffset will be "on the hour/min/sec", but not necessarily */ static int ColorMatch214Cmd (ClientData clientData, Tcl_Interp * interp, int argc, #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION <= 3) char *argv[]) #else const char *argv[]) #endif { int adjust, timespan; sInt4 timeOffset; if (argc != 6) { sprintf (interp->result, "usage: %s " " " "