/******************************************************************************
Eulero codice per il calcolo del flusso potenziale su un corpo generico 
non portante tridimensionale - dal metodo di Hess Smith 

Copyright (C) 1999 Matteo Lucarelli - matteo@matteolucarelli.net

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
******************************************************************************/

 /* routine di lettura file binari */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define TIPOD float

char nomein[30];
FILE *in ;
int n,nb,pb,i,j,scelta,neb;
TIPOD num;

void main(void)
{
   printf("nome del file da leggere \n(max 8 char + .ext):");
   scanf("%s",nomein);
   nomein[12]=0;

   if((in=fopen(nomein,"rb"))==NULL)
   {
      printf("errore apertura file");
      exit(1);
   }

   fread(&n,sizeof(int),1,in);
   printf("n' elementi :%d\n",n);

   printf("1:n\n2:n x 3\n3:n x n\n4:n x 3 x 3\n5:n x 4 x 3\n");
   printf("tipo file :");
   scanf("%d",&scelta);

   printf("posizione del primo blocco :");
   scanf("%d",&pb);
   printf("posizione relativa degli altri blocchi :");
   scanf("%d",&nb);

   switch (scelta)
   {
      case 1 : neb=1 ; break ;
      case 2 : neb=3 ; break ;
      case 3 : neb=n ; break ;
      case 4 : neb=9 ; break ;
      case 5 : neb=12 ; break ;
   }

   pb=pb*neb;
   nb=nb*neb;
   n=n*neb;

   for(i=0;i<(pb-neb);i++)
   {
      fread(&num,sizeof(TIPOD),1,in);
   }

   for(i=0;i<neb;i++)
   {
      fread(&num,sizeof(TIPOD),1,in);
      printf("%.6f\n",num);
   }

   scanf("%s",&nomein);

   for(i=1;i<(n+1-pb);i++)
   {
      fread(&num,sizeof(TIPOD),1,in);

      if (fmod((i+neb),nb)==0)
      {
         for(j=0;j<neb;j++)
         {
            i++;
            fread(&num,sizeof(TIPOD),1,in);
            printf("%+.6f\n",num);
         }
         scanf("%s",&nomein);
      }
   }
   scanf("%s",&nomein);

   fclose(in);
}

