📄 lbio.c
字号:
{//printf("spy_bmp() -- Turning periodic_y off at ( %d, %d).\n",// (int)floor((double)i/3.), j); lattice->periodic_y = 0; } } } if( ( (b&0xff) == 0) &&( (g&0xff) == 255) &&( (r&0xff) == 0) ) { // Green ==> Outflow, Pressure boundaries. //bcs[j][(int)floor((double)i/3.)] = 12;//printf("spy_bmp() -- Outflow at ( %d, %d).\n",// (int)floor((double)i/3.), j); if( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1 ) { if( !( j==0 || j == lattice->param.LY-1)) {//printf("spy_bmp() -- Turning periodic_x off at ( %d, %d).\n",// (int)floor((double)i/3.), j); lattice->periodic_x = 0; } } if( j == 0 || j == lattice->param.LY-1 ) { if( !( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1)) {//printf("spy_bmp() -- Turning periodic_y off at ( %d, %d).\n",// (int)floor((double)i/3.), j); lattice->periodic_y = 0; } } }#endif } i++; break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", *bitcount_ptr); exit(1); break; } /* switch(*(bmih.biBitCount)) */ if( !(n%(bytes_per_row+pad))) { m++; i=0; j++;} n+=( k = fread( &b, 1, 1, in )); } /* while( !feof(in)) */ if( (bytes_per_row+pad)*m!=n) { printf("WARNING: Num bytes read = %d versus num bytes predicted = %d .\n", n, (bytes_per_row+pad)*m); } if( m != *height_ptr) { printf("WARNING: m (%d) != bmih.biHeight (%d).\n", m, *height_ptr); } fclose(in); printf("spy_bmp() -- Bye!\n"); printf("\n");} /* spy_bmp( char *filename, int **spy) */// void read_bcs( char *filename, int **bcs)//##############################################################################//// R E A D B C S//// - Read boundary condition information from file.//void read_bcs( char *filename, lattice_ptr lattice, int **bcs){ FILE *in; int i, j, n, m; int ei, ej; int pad, bytes_per_row; char k; char b, g, r; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; printf("read_bcs() -- Hi!\n"); // Clear the bcs array. for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { bcs[j][i] = 0; } } if( !( in = fopen( filename, "r"))) { printf("read_bcs() -- Error opening file \"%s\".\n", filename); exit(1); } // Read the headers. n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; if( *height_ptr != lattice->param.LY) { printf("ERROR: Lattice height does not match " "soil matrix data \"%s\". (%d!=%d) Exiting!\n", filename, lattice->param.LY, *height_ptr ); printf("\n"); exit(1); } if( *width_ptr != lattice->param.LX) { printf("ERROR: Lattice width does not match " "soil matrix data \"%s\". (%d!=%d) Exiting!\n", filename, lattice->param.LX, *width_ptr ); printf("\n"); exit(1); } // Read the palette, if necessary. if( *bitcount_ptr < 24) { n = (double)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); exit(1); } } } // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; n = 0; m = 0; n+=( k = fread( &b, 1, 1, in )); i = 0; //j = *height_ptr-1; j = 0;//*height_ptr-1; while( !feof(in)) { switch(*bitcount_ptr) { case 1: // Monochrome. printf("read_bcs() -- " "Support for Monochrome BMPs is pending. " "Exiting!\n"); exit(1); if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x80) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x40) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x20) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x10) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x08) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x04) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x02) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x01) == 0); } i++; break; case 4: // 16 colors. printf("read_bcs() -- " "Support for 16 color BMPs is pending. " "Exiting!\n"); exit(1); if( i < *width_ptr) { (bcs)[j][i] = ( (b&0xf0)>>4 != 15); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b&0x0f) != 15); } i++; break; case 8: // 256 colors. printf("read_bcs() -- " "Support for 256 color BMPs is pending. " "Exiting!\n"); exit(1); if( i < *width_ptr) { (bcs)[j][i] = ( (b&0xff) != 255); } i++; break; case 24: // 24-bit colors. if( i < 3*(*width_ptr)) { i++; n+=( k = fread( &g, 1, 1, in )); i++; n+=( k = fread( &r, 1, 1, in ));//printf( "read_bcs() -- ( %d, %d), (r,g,b) = ( %d, %d, %d)\n",// (int)floor((double)i/3.), j, r&0xff, g&0xff, b&0xff); if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 255) ) { // Red ==> Inflow, Pressure boundaries. bcs[j][(int)floor((double)i/3.)] = 1;//printf( "read_bcs() -- Red at ( %d, %d).\n", (int)floor((double)i/3.), j); } if( ( (b&0xff) == 0) &&( (g&0xff) == 255) &&( (r&0xff) == 0) ) { // Green ==> Outflow, Pressure boundaries. bcs[j][(int)floor((double)i/3.)] = 2;//printf( "read_bcs() -- Green at ( %d, %d).\n", (int)floor((double)i/3.), j); } } i++; break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", *bitcount_ptr); exit(1); break; } /* switch(*(bmih.biBitCount)) */ if( !(n%(bytes_per_row+pad))) { m++; i=0; j++;} n+=( k = fread( &b, 1, 1, in )); } /* while( !feof(in)) */ if( (bytes_per_row+pad)*m!=n) { printf("WARNING: Num bytes read = %d versus num bytes predicted = %d .\n", n, (bytes_per_row+pad)*m); } if( m != *height_ptr) { printf("WARNING: m (%d) != bmih.biHeight (%d).\n", m, *height_ptr); } fclose(in); ei = lattice->param.LX-1; ej = lattice->param.LY-1; for( n=0; n<lattice->NumNodes; n++) { i = lattice->node[n].i; j = lattice->node[n].j; if( bcs[ j][ i] != 0) {//printf("read_bcs() -- n = %d, ( %d, %d) of ( %d, %d).\n", n, i, j, ei, ej);#if 0 if( ( i==0 && j==0 ) || ( i==ei && j==0 ) || ( i==ei && j==ej) || ( i==0 && j==ej) ) { // Skip corners for now. printf("read_bcs() -- WARNING: Skipping corner ( %d, %d).", i, j); } else {#endif#if 0 if( i==0) { // West if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_W_IN; //lattice->periodic_x = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_W_OUT; //lattice->periodic_x = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); exit(1); } } else if( i==ei) { // East if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_E_IN; //lattice->periodic_x = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_E_OUT; //lattice->periodic_x = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); exit(1); } } else #endif if( j==0) {//printf("read_bcs() -- South at i=%d\n", i); // South if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_S_IN; //lattice->periodic_y = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_S_OUT; //lattice->periodic_y = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); exit(1); } } else if( j==ej) {//printf("read_bcs() -- North at i=%d\n", i); // North if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_N_IN; //lattice->periodic_y = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_N_OUT; //lattice->periodic_y = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); exit(1); } } else { // Unhandled case. printf("read_bcs() -- WARNING: " "Support for interior flow bcs is pending! " "Skipping ( i, j) = ( %d, %d).\n", i, j); }#if 0 }#endif } } printf("read_bcs() -- Bye!\n"); printf("\n");} /* read_bcs( char *filename, int ***bcs, int *height, int *width) */// void rho2bmp( char *filename, int time)//##############################################################################//// R H O 2 B M P //void rho2bmp( lattice_ptr lattice, int time){ FILE *in, *o; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -