/******************************************************************************
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,scelta;
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("dimensione del primo blocco :");
   scanf("%d",&pb);
   printf("dimensione degli altri blocchi :");
   scanf("%d",&nb);

   switch (scelta)
   {
      case 2 : n=n*3 ; break ;
      case 3 : n=n*n ; break ;
      case 4 : n=n*9 ; break ;
      case 5 : n=n*12 ; break ;
   }
   for(i=0;i<pb;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);
      printf("%+.6f\n",num);

      if (fmod(i,nb)==0) scanf("%s",&nomein);
   }
   scanf("%s",&nomein);

   fclose(in);
}
