⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpe_graphics.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 3 页
字号:
@*/int MPE_Make_color_array( handle, ncolors, array )MPE_XGraph handle;int        ncolors;MPE_Color  array[];{  int    i;  PixVal white;    if (handle->Cookie != MPE_G_COOKIE) {    fprintf( stderr, "Handle argument is incorrect or corrupted\n" );    return MPE_ERR_BAD_ARGS;  }  XBUniformHues( handle->xwin, ncolors + 2 );    /* XBUniformHues creates a spectrum like:     BLACK red->yellow->blue->purple WHITE     We want something like:     WHITE BLACK red->yellow->blue->purple          So I shifted things around a little.     */    /* here's the original code: */  /*     for (i=0; i<ncolors; i++)      array[i] = handle->xwin->cmapping[i + 2];     */    /* here's something that works: */  white = handle->xwin->cmapping[ncolors+1];  for (i=0; i<ncolors; i++) {    array[i] = (MPE_Color)(i+2);    handle->xwin->cmapping[ncolors+1-i] = handle->xwin->cmapping[ncolors-i];  }  handle->xwin->cmapping[MPE_BLACK] = handle->xwin->cmapping[0];  handle->xwin->cmapping[MPE_WHITE] = white;    return MPE_SUCCESS;}/*@  MPE_Num_colors - Gets the number of available colors  Input Parameter:. handle - MPE graphics handle  Output Parameter:. nc - Number of colors available on the display..N XGRAPHICS_FORTRAN@*/int MPE_Num_colors( handle, nc )MPE_XGraph handle;int        *nc;{  if (handle->Cookie != MPE_G_COOKIE) {    fprintf( stderr, "Handle argument is incorrect or corrupted\n" );    return MPE_ERR_BAD_ARGS;  }  *nc = handle->xwin->maxcolors;  return MPE_SUCCESS;}/*@   MPE_Draw_circle - Draws a circle  Input Parameters:+ graph - MPE graphics handle. centerx - horizontal center point of the circle. centery - vertical center point of the circle. radius - radius of the circle- color - color of the circle.N XGRAPHICS_FORTRAN@*/int MPE_Draw_circle( graph, centerx, centery, radius, color )MPE_XGraph graph;int centerx, centery, radius;MPE_Color color;{  int returnVal;  if (graph->Cookie != MPE_G_COOKIE) {    fprintf( stderr, "Handle argument is incorrect or corrupted\n" );    return MPE_ERR_BAD_ARGS;  }#if DEBUG  fprintf( stdout, "Drawing at (%d,%d) with radius %d and color %d\n",	   centerx, centery, radius, color );  fflush( stdout );#endif  XBSetPixVal( graph->xwin, graph->xwin->cmapping[color] );  XDrawArc( graph->xwin->disp, XBDrawable(graph->xwin),		        graph->xwin->gc.set, centerx-radius, centery-radius, 		        radius*2, radius*2, 0, 360*64 );  returnVal = 0;  return MPE_Xerror( returnVal, "MPE_DrawCircle" );}/*@   MPE_Fill_circle - Fills a circle  Input Parameters:+ graph - MPE graphics handle. centerx - horizontal center point of the circle. centery - vertical center point of the circle. radius - radius of the circle- color - color of the circle.N XGRAPHICS_FORTRAN@*/int MPE_Fill_circle( graph, centerx, centery, radius, color )MPE_XGraph graph;int centerx, centery, radius;MPE_Color color;{  int returnVal;  if (graph->Cookie != MPE_G_COOKIE) {    fprintf( stderr, "Handle argument is incorrect or corrupted\n" );    return MPE_ERR_BAD_ARGS;  }  XBSetPixVal( graph->xwin, graph->xwin->cmapping[color] );  XFillArc( graph->xwin->disp, XBDrawable(graph->xwin),		        graph->xwin->gc.set, centerx-radius, centery-radius, 		        radius*2, radius*2, 0, 360*64 );  returnVal = 0;  return MPE_Xerror( returnVal, "MPE_FillCircle" );}/*@   MPE_Draw_string - Draw a text string  Input Parameters:+ graph - MPE graphics handle. x - x-coordinate of the origin of the string. y - y-coordinate of the origin of the string. color - color of the text- string - text string to be drawn.N XGRAPHICS_FORTRAN    Additional Notes for Fortran Interface :    The trailing blanks in Fortran CHARACTER string argument will be    ignored.@*/int MPE_Draw_string( graph, x, y, color, string )MPE_XGraph graph;int x, y;MPE_Color color;char *string;{  int returnVal;  if (graph->Cookie != MPE_G_COOKIE) {    fprintf( stderr, "Handle argument is incorrect or corrupted\n" );    return MPE_ERR_BAD_ARGS;  }  printf("color = %d, string = %s\n",(int) color, string);  XBSetPixVal( graph->xwin, graph->xwin->cmapping[color] );  returnVal = XDrawString( graph->xwin->disp, XBDrawable(graph->xwin),		        graph->xwin->gc.set, x, y, string, strlen(string) );/* from mail  returnVal = XDrawString( graph->xwin->disp, graph->xwin->win,		        graph->xwin->gc.set, x, y, string, strlen(string) );*/  return MPE_Xerror( returnVal, "MPE_DrawString" );}/*@   MPE_Draw_logic - Sets logical operation for laying down new pixels  Input Parameters:+ graph - MPE graphics handle- function - integer specifying one of the following:.n            'MPE_LOGIC_COPY' - no logic, just copy the pixel.n	    'MPE_LOGIC_XOR'  - xor the new pixel with the existing one	     and many more... see 'mpe_graphics.h'.N XGRAPHICS_FORTRAN@*/int MPE_Draw_logic( graph, function )MPE_XGraph graph;int function;{  int returnVal;  if (graph->Cookie != MPE_G_COOKIE) {    fprintf( stderr, "Handle argument is incorrect or corrupted\n" );    return MPE_ERR_BAD_ARGS;  }  XSetFunction( graph->xwin->disp,			    graph->xwin->gc.set, function );  returnVal = 0;  MPE_Xerror( returnVal, "MPE_DrawLogic" );  return returnVal;}/*@   MPE_Line_thickness - Sets thickness of lines  Input Parameters:+ graph - MPE graphics handle- thickness - integer specifying how many pixels wide lines should be.N XGRAPHICS_FORTRAN@*/int MPE_Line_thickness( graph, thickness )MPE_XGraph graph;int thickness;{  XGCValues gcChanges;  gcChanges.line_width = thickness;  XChangeGC( graph->xwin->disp, graph->xwin->gc.set,	     GCLineWidth, &gcChanges );  return MPE_SUCCESS;}int MPE_Draw_dashes( graph, dashlen )MPE_XGraph graph;int dashlen;{  XGCValues gcChanges;  if (dashlen) {    gcChanges.line_style = LineDoubleDash;    gcChanges.dashes = dashlen;    gcChanges.dash_offset = 0;    XChangeGC( graph->xwin->disp, graph->xwin->gc.set,	       GCDashOffset | GCDashList | GCLineStyle, &gcChanges );  } else {    gcChanges.line_style = 0;    XChangeGC( graph->xwin->disp, graph->xwin->gc.set,	       GCLineStyle, &gcChanges );  }  return 0;}int MPE_Dash_offset( graph, offset )MPE_XGraph graph;int offset;{  XGCValues gcChanges;  gcChanges.dash_offset = offset;  XChangeGC( graph->xwin->disp, graph->xwin->gc.set,	     GCDashOffset, &gcChanges );  return 0;}/*@   MPE_Add_RGB_color - Adds a color to the colormap given its RGB values  Input Parameters:+ graph - MPE graphics handle- red, green, blue - color levels from 0 to 65535  Output Parameter:. mapping - index of the new color  Return Values:+ -1 - maxcolors too large (equal to numcolors). MPE_SUCCESS - successful- mapping - index of the new color  Notes:  This call adds a color cell to X11''s color table, increments maxcolors  (the index), and writes it to the mapping parameter..N XGRAPHICS_FORTRAN@*/int MPE_Add_RGB_color( graph, red, green, blue, mapping )MPE_XGraph graph;int red, green, blue;MPE_Color *mapping;{  XColor colordef;  if (graph->Cookie != MPE_G_COOKIE) {    fprintf( stderr, "Handle argument is incorrect or corrupted\n" );    return MPE_ERR_BAD_ARGS;  }  if (graph->xwin->maxcolors == graph->xwin->numcolors)    return -1;    colordef.red   = red;  colordef.green = green;  colordef.blue  = blue;  colordef.flags = DoRed | DoGreen | DoBlue;  if (!XAllocColor( graph->xwin->disp, graph->xwin->cmap, &colordef ))    return -1;  graph->xwin->cmapping[graph->xwin->maxcolors] = colordef.pixel;  *mapping = (MPE_Color) (graph->xwin->maxcolors++);  if (graph->xwin->maxcolors == 256)    graph->xwin->maxcolors = 255;  return MPE_SUCCESS;}int MPE_Xerror( returnVal, functionName )int returnVal;char *functionName;{  if (returnVal) {    switch (returnVal) {    case BadAccess:      fprintf( stderr, "'BadAccess' error in call to %s\n", functionName );      return returnVal;    case BadAlloc:      fprintf( stderr, "'BadAlloc' error in call to %s\n", functionName );      return returnVal;    case BadColor:      fprintf( stderr, "'BadColor' error in call to %s\n", functionName );      return returnVal;    case BadDrawable:      fprintf( stderr, "'BadDrawable' error in call to %s\n", functionName );      return returnVal;    case BadGC:      fprintf( stderr, "'BadGC' error in call to %s\n", functionName );      return returnVal;    case BadMatch:      fprintf( stderr, "'BadMatch' error in call to %s\n", functionName );      return returnVal;    case BadValue:      fprintf( stderr, "'BadValue' error in call to %s\n", functionName );      return returnVal;    default:/*      fprintf( stderr, "Unknown error %d in call to %s\n",	       returnVal, functionName );*/      return returnVal;    }  } else {    return MPE_SUCCESS;  }}static xpand_list_Int *Int_CreateList(initialLen)int initialLen;{  xpand_list_Int *tempPtr;  if (initialLen < 1) {    initialLen = 10;  }  tempPtr = (xpand_list_Int *) malloc(sizeof(xpand_list_Int));  if (tempPtr) {    tempPtr->list = (int *) malloc(sizeof(int) * initialLen);    if (!tempPtr->list) {      return 0;    }    tempPtr->nused = 0;    tempPtr->size = initialLen;  } else {    fprintf( stderr, "Could not allocate memory for expanding list\n");  }  return tempPtr;}static int Int_AddItem(listPtr, newItem)xpand_list_Int *listPtr;int newItem;{  int *tmp;  if (listPtr->nused == listPtr->size) {    if (listPtr->size < 1)      listPtr->size = 1;    listPtr->size *= 2;    tmp = (int *) malloc( sizeof(int) * listPtr->size);    if (!tmp) {      fprintf( stderr, "Ran out of memory packing pixels.\n" );      return 1;    } else {      memcpy( tmp, listPtr->list, sizeof(int) * listPtr->size / 2 );      free( listPtr->list );      listPtr->list = tmp;    }  }  listPtr->list[(listPtr->nused)++] = newItem;  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -